LCOV - code coverage report
Current view: top level - drivers/net/intel/fm10k - fm10k_ethdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 3 1273 0.2 %
Date: 2025-03-01 20:23:48 Functions: 3 74 4.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 668 0.3 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2013-2016 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <ethdev_driver.h>
       6                 :            : #include <ethdev_pci.h>
       7                 :            : #include <rte_malloc.h>
       8                 :            : #include <rte_memzone.h>
       9                 :            : #include <rte_string_fns.h>
      10                 :            : #include <dev_driver.h>
      11                 :            : #include <rte_spinlock.h>
      12                 :            : #include <rte_kvargs.h>
      13                 :            : #include <rte_vect.h>
      14                 :            : 
      15                 :            : #include "fm10k.h"
      16                 :            : #include "base/fm10k_api.h"
      17                 :            : 
      18                 :            : /* Default delay to acquire mailbox lock */
      19                 :            : #define FM10K_MBXLOCK_DELAY_US 20
      20                 :            : #define UINT64_LOWER_32BITS_MASK 0x00000000ffffffffULL
      21                 :            : 
      22                 :            : #define MAIN_VSI_POOL_NUMBER 0
      23                 :            : 
      24                 :            : /* Max try times to acquire switch status */
      25                 :            : #define MAX_QUERY_SWITCH_STATE_TIMES 10
      26                 :            : /* Wait interval to get switch status */
      27                 :            : #define WAIT_SWITCH_MSG_US    100000
      28                 :            : /* A period of quiescence for switch */
      29                 :            : #define FM10K_SWITCH_QUIESCE_US 100000
      30                 :            : /* Number of chars per uint32 type */
      31                 :            : #define CHARS_PER_UINT32 (sizeof(uint32_t))
      32                 :            : #define BIT_MASK_PER_UINT32 ((1 << CHARS_PER_UINT32) - 1)
      33                 :            : 
      34                 :            : /* default 1:1 map from queue ID to interrupt vector ID */
      35                 :            : #define Q2V(pci_dev, queue_id)                                                 \
      36                 :            :         (rte_intr_vec_list_index_get((pci_dev)->intr_handle, queue_id))
      37                 :            : 
      38                 :            : /* First 64 Logical ports for PF/VMDQ, second 64 for Flow director */
      39                 :            : #define MAX_LPORT_NUM    128
      40                 :            : #define GLORT_FD_Q_BASE  0x40
      41                 :            : #define GLORT_PF_MASK    0xFFC0
      42                 :            : #define GLORT_FD_MASK    GLORT_PF_MASK
      43                 :            : #define GLORT_FD_INDEX   GLORT_FD_Q_BASE
      44                 :            : 
      45                 :            : static void fm10k_close_mbx_service(struct fm10k_hw *hw);
      46                 :            : static int fm10k_dev_promiscuous_enable(struct rte_eth_dev *dev);
      47                 :            : static int fm10k_dev_promiscuous_disable(struct rte_eth_dev *dev);
      48                 :            : static int fm10k_dev_allmulticast_enable(struct rte_eth_dev *dev);
      49                 :            : static int fm10k_dev_allmulticast_disable(struct rte_eth_dev *dev);
      50                 :            : static inline int fm10k_glort_valid(struct fm10k_hw *hw);
      51                 :            : static int
      52                 :            : fm10k_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on);
      53                 :            : static void fm10k_MAC_filter_set(struct rte_eth_dev *dev,
      54                 :            :         const u8 *mac, bool add, uint32_t pool);
      55                 :            : static void fm10k_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
      56                 :            : static void fm10k_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
      57                 :            : static void fm10k_set_rx_function(struct rte_eth_dev *dev);
      58                 :            : static void fm10k_set_tx_function(struct rte_eth_dev *dev);
      59                 :            : static int fm10k_check_ftag(struct rte_devargs *devargs);
      60                 :            : static int fm10k_link_update(struct rte_eth_dev *dev, int wait_to_complete);
      61                 :            : 
      62                 :            : static int fm10k_dev_infos_get(struct rte_eth_dev *dev,
      63                 :            :                                struct rte_eth_dev_info *dev_info);
      64                 :            : static uint64_t fm10k_get_rx_queue_offloads_capa(struct rte_eth_dev *dev);
      65                 :            : static uint64_t fm10k_get_rx_port_offloads_capa(struct rte_eth_dev *dev);
      66                 :            : static uint64_t fm10k_get_tx_queue_offloads_capa(struct rte_eth_dev *dev);
      67                 :            : static uint64_t fm10k_get_tx_port_offloads_capa(struct rte_eth_dev *dev);
      68                 :            : 
      69                 :            : struct fm10k_xstats_name_off {
      70                 :            :         char name[RTE_ETH_XSTATS_NAME_SIZE];
      71                 :            :         unsigned offset;
      72                 :            : };
      73                 :            : 
      74                 :            : static const struct fm10k_xstats_name_off fm10k_hw_stats_strings[] = {
      75                 :            :         {"completion_timeout_count", offsetof(struct fm10k_hw_stats, timeout)},
      76                 :            :         {"unsupported_requests_count", offsetof(struct fm10k_hw_stats, ur)},
      77                 :            :         {"completer_abort_count", offsetof(struct fm10k_hw_stats, ca)},
      78                 :            :         {"unsupported_message_count", offsetof(struct fm10k_hw_stats, um)},
      79                 :            :         {"checksum_error_count", offsetof(struct fm10k_hw_stats, xec)},
      80                 :            :         {"vlan_dropped", offsetof(struct fm10k_hw_stats, vlan_drop)},
      81                 :            :         {"loopback_dropped", offsetof(struct fm10k_hw_stats, loopback_drop)},
      82                 :            :         {"rx_mbuf_allocation_errors", offsetof(struct fm10k_hw_stats,
      83                 :            :                 nodesc_drop)},
      84                 :            : };
      85                 :            : 
      86                 :            : #define FM10K_NB_HW_XSTATS (sizeof(fm10k_hw_stats_strings) / \
      87                 :            :                 sizeof(fm10k_hw_stats_strings[0]))
      88                 :            : 
      89                 :            : static const struct fm10k_xstats_name_off fm10k_hw_stats_rx_q_strings[] = {
      90                 :            :         {"packets", offsetof(struct fm10k_hw_stats_q, rx_packets)},
      91                 :            :         {"bytes", offsetof(struct fm10k_hw_stats_q, rx_bytes)},
      92                 :            :         {"dropped", offsetof(struct fm10k_hw_stats_q, rx_drops)},
      93                 :            : };
      94                 :            : 
      95                 :            : #define FM10K_NB_RX_Q_XSTATS (sizeof(fm10k_hw_stats_rx_q_strings) / \
      96                 :            :                 sizeof(fm10k_hw_stats_rx_q_strings[0]))
      97                 :            : 
      98                 :            : static const struct fm10k_xstats_name_off fm10k_hw_stats_tx_q_strings[] = {
      99                 :            :         {"packets", offsetof(struct fm10k_hw_stats_q, tx_packets)},
     100                 :            :         {"bytes", offsetof(struct fm10k_hw_stats_q, tx_bytes)},
     101                 :            : };
     102                 :            : 
     103                 :            : #define FM10K_NB_TX_Q_XSTATS (sizeof(fm10k_hw_stats_tx_q_strings) / \
     104                 :            :                 sizeof(fm10k_hw_stats_tx_q_strings[0]))
     105                 :            : 
     106                 :            : #define FM10K_NB_XSTATS (FM10K_NB_HW_XSTATS + FM10K_MAX_QUEUES_PF * \
     107                 :            :                 (FM10K_NB_RX_Q_XSTATS + FM10K_NB_TX_Q_XSTATS))
     108                 :            : static int
     109                 :            : fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev);
     110                 :            : 
     111                 :            : static void
     112                 :            : fm10k_mbx_initlock(struct fm10k_hw *hw)
     113                 :            : {
     114                 :          0 :         rte_spinlock_init(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back));
     115                 :            : }
     116                 :            : 
     117                 :            : static void
     118                 :            : fm10k_mbx_lock(struct fm10k_hw *hw)
     119                 :            :         __rte_acquire_capability(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back))
     120                 :            : {
     121   [ #  #  #  #  :          0 :         while (!rte_spinlock_trylock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)))
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     122                 :          0 :                 rte_delay_us(FM10K_MBXLOCK_DELAY_US);
     123                 :            : }
     124                 :            : 
     125                 :            : static void
     126                 :            : fm10k_mbx_unlock(struct fm10k_hw *hw)
     127                 :            :         __rte_release_capability(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back))
     128                 :            : {
     129                 :          0 :         rte_spinlock_unlock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back));
     130                 :          0 : }
     131                 :            : 
     132                 :            : #ifndef RTE_ARCH_X86
     133                 :            : /* Stubs for non x86 architectures. */
     134                 :            : int
     135                 :            : fm10k_rx_vec_condition_check(__rte_unused struct rte_eth_dev *dev)
     136                 :            : {
     137                 :            :         return -1;
     138                 :            : }
     139                 :            : 
     140                 :            : uint16_t
     141                 :            : fm10k_recv_pkts_vec(
     142                 :            :         __rte_unused void *rx_queue,
     143                 :            :         __rte_unused struct rte_mbuf **rx_pkts,
     144                 :            :         __rte_unused uint16_t nb_pkts)
     145                 :            : {
     146                 :            :         return 0;
     147                 :            : }
     148                 :            : 
     149                 :            : uint16_t
     150                 :            : fm10k_recv_scattered_pkts_vec(
     151                 :            :                 __rte_unused void *rx_queue,
     152                 :            :                 __rte_unused struct rte_mbuf **rx_pkts,
     153                 :            :                 __rte_unused uint16_t nb_pkts)
     154                 :            : {
     155                 :            :         return 0;
     156                 :            : }
     157                 :            : 
     158                 :            : int
     159                 :            : fm10k_rxq_vec_setup(__rte_unused struct fm10k_rx_queue *rxq)
     160                 :            : 
     161                 :            : {
     162                 :            :         return -1;
     163                 :            : }
     164                 :            : 
     165                 :            : void
     166                 :            : fm10k_rx_queue_release_mbufs_vec(
     167                 :            :                 __rte_unused struct fm10k_rx_queue *rxq)
     168                 :            : {
     169                 :            :         return;
     170                 :            : }
     171                 :            : 
     172                 :            : void
     173                 :            : fm10k_txq_vec_setup(__rte_unused struct fm10k_tx_queue *txq)
     174                 :            : {
     175                 :            :         return;
     176                 :            : }
     177                 :            : 
     178                 :            : int
     179                 :            : fm10k_tx_vec_condition_check(__rte_unused struct fm10k_tx_queue *txq)
     180                 :            : {
     181                 :            :         return -1;
     182                 :            : }
     183                 :            : 
     184                 :            : uint16_t
     185                 :            : fm10k_xmit_fixed_burst_vec(__rte_unused void *tx_queue,
     186                 :            :                            __rte_unused struct rte_mbuf **tx_pkts,
     187                 :            :                            __rte_unused uint16_t nb_pkts)
     188                 :            : {
     189                 :            :         return 0;
     190                 :            : }
     191                 :            : #endif /* RTE_ARCH_X86 */
     192                 :            : 
     193                 :            : /*
     194                 :            :  * reset queue to initial state, allocate software buffers used when starting
     195                 :            :  * device.
     196                 :            :  * return 0 on success
     197                 :            :  * return -ENOMEM if buffers cannot be allocated
     198                 :            :  * return -EINVAL if buffers do not satisfy alignment condition
     199                 :            :  */
     200                 :            : static inline int
     201                 :          0 : rx_queue_reset(struct fm10k_rx_queue *q)
     202                 :            : {
     203                 :            :         static const union fm10k_rx_desc zero = {{0} };
     204                 :            :         uint64_t dma_addr;
     205                 :            :         int i, diag;
     206                 :          0 :         PMD_INIT_FUNC_TRACE();
     207                 :            : 
     208         [ #  # ]:          0 :         diag = rte_mempool_get_bulk(q->mp, (void **)q->sw_ring, q->nb_desc);
     209         [ #  # ]:          0 :         if (diag != 0)
     210                 :            :                 return -ENOMEM;
     211                 :            : 
     212         [ #  # ]:          0 :         for (i = 0; i < q->nb_desc; ++i) {
     213                 :          0 :                 fm10k_pktmbuf_reset(q->sw_ring[i], q->port_id);
     214         [ #  # ]:          0 :                 if (!fm10k_addr_alignment_valid(q->sw_ring[i])) {
     215                 :          0 :                         rte_mempool_put_bulk(q->mp, (void **)q->sw_ring,
     216         [ #  # ]:          0 :                                                 q->nb_desc);
     217                 :          0 :                         return -EINVAL;
     218                 :            :                 }
     219                 :          0 :                 dma_addr = MBUF_DMA_ADDR_DEFAULT(q->sw_ring[i]);
     220                 :          0 :                 q->hw_ring[i].q.pkt_addr = dma_addr;
     221                 :          0 :                 q->hw_ring[i].q.hdr_addr = dma_addr;
     222                 :            :         }
     223                 :            : 
     224                 :            :         /* initialize extra software ring entries. Space for these extra
     225                 :            :          * entries is always allocated.
     226                 :            :          */
     227                 :          0 :         memset(&q->fake_mbuf, 0x0, sizeof(q->fake_mbuf));
     228         [ #  # ]:          0 :         for (i = 0; i < q->nb_fake_desc; ++i) {
     229                 :          0 :                 q->sw_ring[q->nb_desc + i] = &q->fake_mbuf;
     230                 :          0 :                 q->hw_ring[q->nb_desc + i] = zero;
     231                 :            :         }
     232                 :            : 
     233                 :          0 :         q->next_dd = 0;
     234                 :          0 :         q->next_alloc = 0;
     235                 :          0 :         q->next_trigger = q->alloc_thresh - 1;
     236                 :          0 :         FM10K_PCI_REG_WRITE(q->tail_ptr, q->nb_desc - 1);
     237                 :          0 :         q->rxrearm_start = 0;
     238                 :          0 :         q->rxrearm_nb = 0;
     239                 :            : 
     240                 :          0 :         return 0;
     241                 :            : }
     242                 :            : 
     243                 :            : /*
     244                 :            :  * clean queue, descriptor rings, free software buffers used when stopping
     245                 :            :  * device.
     246                 :            :  */
     247                 :            : static inline void
     248                 :          0 : rx_queue_clean(struct fm10k_rx_queue *q)
     249                 :            : {
     250                 :            :         union fm10k_rx_desc zero = {.q = {0, 0, 0, 0} };
     251                 :            :         uint32_t i;
     252                 :          0 :         PMD_INIT_FUNC_TRACE();
     253                 :            : 
     254                 :            :         /* zero descriptor rings */
     255         [ #  # ]:          0 :         for (i = 0; i < q->nb_desc; ++i)
     256                 :          0 :                 q->hw_ring[i] = zero;
     257                 :            : 
     258                 :            :         /* zero faked descriptors */
     259         [ #  # ]:          0 :         for (i = 0; i < q->nb_fake_desc; ++i)
     260                 :          0 :                 q->hw_ring[q->nb_desc + i] = zero;
     261                 :            : 
     262                 :            :         /* vPMD has a different way of releasing mbufs. */
     263         [ #  # ]:          0 :         if (q->rx_using_sse) {
     264                 :          0 :                 fm10k_rx_queue_release_mbufs_vec(q);
     265                 :            :                 return;
     266                 :            :         }
     267                 :            : 
     268                 :            :         /* free software buffers */
     269         [ #  # ]:          0 :         for (i = 0; i < q->nb_desc; ++i) {
     270         [ #  # ]:          0 :                 if (q->sw_ring[i]) {
     271                 :            :                         rte_pktmbuf_free_seg(q->sw_ring[i]);
     272                 :          0 :                         q->sw_ring[i] = NULL;
     273                 :            :                 }
     274                 :            :         }
     275                 :            : }
     276                 :            : 
     277                 :            : /*
     278                 :            :  * free all queue memory used when releasing the queue (i.e. configure)
     279                 :            :  */
     280                 :            : static inline void
     281                 :          0 : rx_queue_free(struct fm10k_rx_queue *q)
     282                 :            : {
     283                 :          0 :         PMD_INIT_FUNC_TRACE();
     284         [ #  # ]:          0 :         if (q) {
     285                 :          0 :                 PMD_INIT_LOG(DEBUG, "Freeing rx queue %p", q);
     286                 :          0 :                 rx_queue_clean(q);
     287         [ #  # ]:          0 :                 if (q->sw_ring) {
     288                 :          0 :                         rte_free(q->sw_ring);
     289                 :          0 :                         q->sw_ring = NULL;
     290                 :            :                 }
     291                 :          0 :                 rte_free(q);
     292                 :            :                 q = NULL;
     293                 :            :         }
     294                 :          0 : }
     295                 :            : 
     296                 :            : /*
     297                 :            :  * disable RX queue, wait until HW finished necessary flush operation
     298                 :            :  */
     299                 :            : static inline int
     300                 :          0 : rx_queue_disable(struct fm10k_hw *hw, uint16_t qnum)
     301                 :            : {
     302                 :            :         uint32_t reg, i;
     303                 :            : 
     304                 :          0 :         reg = FM10K_READ_REG(hw, FM10K_RXQCTL(qnum));
     305                 :          0 :         FM10K_WRITE_REG(hw, FM10K_RXQCTL(qnum),
     306                 :            :                         reg & ~FM10K_RXQCTL_ENABLE);
     307                 :            : 
     308                 :            :         /* Wait 100us at most */
     309         [ #  # ]:          0 :         for (i = 0; i < FM10K_QUEUE_DISABLE_TIMEOUT; i++) {
     310                 :          0 :                 rte_delay_us(1);
     311                 :          0 :                 reg = FM10K_READ_REG(hw, FM10K_RXQCTL(qnum));
     312         [ #  # ]:          0 :                 if (!(reg & FM10K_RXQCTL_ENABLE))
     313                 :            :                         break;
     314                 :            :         }
     315                 :            : 
     316         [ #  # ]:          0 :         if (i == FM10K_QUEUE_DISABLE_TIMEOUT)
     317                 :          0 :                 return -1;
     318                 :            : 
     319                 :            :         return 0;
     320                 :            : }
     321                 :            : 
     322                 :            : /*
     323                 :            :  * reset queue to initial state, allocate software buffers used when starting
     324                 :            :  * device
     325                 :            :  */
     326                 :            : static inline void
     327                 :          0 : tx_queue_reset(struct fm10k_tx_queue *q)
     328                 :            : {
     329                 :          0 :         PMD_INIT_FUNC_TRACE();
     330                 :          0 :         q->last_free = 0;
     331                 :          0 :         q->next_free = 0;
     332                 :          0 :         q->nb_used = 0;
     333                 :          0 :         q->nb_free = q->nb_desc - 1;
     334                 :          0 :         fifo_reset(&q->rs_tracker, (q->nb_desc + 1) / q->rs_thresh);
     335                 :          0 :         FM10K_PCI_REG_WRITE(q->tail_ptr, 0);
     336                 :          0 : }
     337                 :            : 
     338                 :            : /*
     339                 :            :  * clean queue, descriptor rings, free software buffers used when stopping
     340                 :            :  * device
     341                 :            :  */
     342                 :            : static inline void
     343                 :          0 : tx_queue_clean(struct fm10k_tx_queue *q)
     344                 :            : {
     345                 :            :         struct fm10k_tx_desc zero = {0, 0, 0, 0, 0, 0};
     346                 :            :         uint32_t i;
     347                 :          0 :         PMD_INIT_FUNC_TRACE();
     348                 :            : 
     349                 :            :         /* zero descriptor rings */
     350         [ #  # ]:          0 :         for (i = 0; i < q->nb_desc; ++i)
     351                 :          0 :                 q->hw_ring[i] = zero;
     352                 :            : 
     353                 :            :         /* free software buffers */
     354         [ #  # ]:          0 :         for (i = 0; i < q->nb_desc; ++i) {
     355         [ #  # ]:          0 :                 if (q->sw_ring[i]) {
     356                 :            :                         rte_pktmbuf_free_seg(q->sw_ring[i]);
     357                 :          0 :                         q->sw_ring[i] = NULL;
     358                 :            :                 }
     359                 :            :         }
     360                 :          0 : }
     361                 :            : 
     362                 :            : /*
     363                 :            :  * free all queue memory used when releasing the queue (i.e. configure)
     364                 :            :  */
     365                 :            : static inline void
     366                 :          0 : tx_queue_free(struct fm10k_tx_queue *q)
     367                 :            : {
     368                 :          0 :         PMD_INIT_FUNC_TRACE();
     369         [ #  # ]:          0 :         if (q) {
     370                 :          0 :                 PMD_INIT_LOG(DEBUG, "Freeing tx queue %p", q);
     371                 :          0 :                 tx_queue_clean(q);
     372         [ #  # ]:          0 :                 if (q->rs_tracker.list) {
     373                 :          0 :                         rte_free(q->rs_tracker.list);
     374                 :          0 :                         q->rs_tracker.list = NULL;
     375                 :            :                 }
     376         [ #  # ]:          0 :                 if (q->sw_ring) {
     377                 :          0 :                         rte_free(q->sw_ring);
     378                 :          0 :                         q->sw_ring = NULL;
     379                 :            :                 }
     380                 :          0 :                 rte_free(q);
     381                 :            :                 q = NULL;
     382                 :            :         }
     383                 :          0 : }
     384                 :            : 
     385                 :            : /*
     386                 :            :  * disable TX queue, wait until HW finished necessary flush operation
     387                 :            :  */
     388                 :            : static inline int
     389                 :          0 : tx_queue_disable(struct fm10k_hw *hw, uint16_t qnum)
     390                 :            : {
     391                 :            :         uint32_t reg, i;
     392                 :            : 
     393                 :          0 :         reg = FM10K_READ_REG(hw, FM10K_TXDCTL(qnum));
     394                 :          0 :         FM10K_WRITE_REG(hw, FM10K_TXDCTL(qnum),
     395                 :            :                         reg & ~FM10K_TXDCTL_ENABLE);
     396                 :            : 
     397                 :            :         /* Wait 100us at most */
     398         [ #  # ]:          0 :         for (i = 0; i < FM10K_QUEUE_DISABLE_TIMEOUT; i++) {
     399                 :          0 :                 rte_delay_us(1);
     400                 :          0 :                 reg = FM10K_READ_REG(hw, FM10K_TXDCTL(qnum));
     401         [ #  # ]:          0 :                 if (!(reg & FM10K_TXDCTL_ENABLE))
     402                 :            :                         break;
     403                 :            :         }
     404                 :            : 
     405         [ #  # ]:          0 :         if (i == FM10K_QUEUE_DISABLE_TIMEOUT)
     406                 :          0 :                 return -1;
     407                 :            : 
     408                 :            :         return 0;
     409                 :            : }
     410                 :            : 
     411                 :            : static int
     412                 :          0 : fm10k_check_mq_mode(struct rte_eth_dev *dev)
     413                 :            : {
     414                 :          0 :         enum rte_eth_rx_mq_mode rx_mq_mode = dev->data->dev_conf.rxmode.mq_mode;
     415                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     416                 :            :         struct rte_eth_vmdq_rx_conf *vmdq_conf;
     417                 :          0 :         uint16_t nb_rx_q = dev->data->nb_rx_queues;
     418                 :            : 
     419                 :            :         vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
     420                 :            : 
     421         [ #  # ]:          0 :         if (rx_mq_mode & RTE_ETH_MQ_RX_DCB_FLAG) {
     422                 :          0 :                 PMD_INIT_LOG(ERR, "DCB mode is not supported.");
     423                 :          0 :                 return -EINVAL;
     424                 :            :         }
     425                 :            : 
     426         [ #  # ]:          0 :         if (!(rx_mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG))
     427                 :            :                 return 0;
     428                 :            : 
     429         [ #  # ]:          0 :         if (hw->mac.type == fm10k_mac_vf) {
     430                 :          0 :                 PMD_INIT_LOG(ERR, "VMDQ mode is not supported in VF.");
     431                 :          0 :                 return -EINVAL;
     432                 :            :         }
     433                 :            : 
     434                 :            :         /* Check VMDQ queue pool number */
     435         [ #  # ]:          0 :         if (vmdq_conf->nb_queue_pools >
     436                 :          0 :                         sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT ||
     437         [ #  # ]:          0 :                         vmdq_conf->nb_queue_pools > nb_rx_q) {
     438                 :          0 :                 PMD_INIT_LOG(ERR, "Too many of queue pools: %d",
     439                 :            :                         vmdq_conf->nb_queue_pools);
     440                 :          0 :                 return -EINVAL;
     441                 :            :         }
     442                 :            : 
     443                 :            :         return 0;
     444                 :            : }
     445                 :            : 
     446                 :            : static const struct fm10k_txq_ops def_txq_ops = {
     447                 :            :         .reset = tx_queue_reset,
     448                 :            : };
     449                 :            : 
     450                 :            : static int
     451                 :          0 : fm10k_dev_configure(struct rte_eth_dev *dev)
     452                 :            : {
     453                 :            :         int ret;
     454                 :            : 
     455                 :          0 :         PMD_INIT_FUNC_TRACE();
     456                 :            : 
     457         [ #  # ]:          0 :         if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
     458                 :          0 :                 dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
     459                 :            : 
     460                 :            :         /* multiple queue mode checking */
     461                 :          0 :         ret  = fm10k_check_mq_mode(dev);
     462         [ #  # ]:          0 :         if (ret != 0) {
     463                 :          0 :                 PMD_DRV_LOG(ERR, "fm10k_check_mq_mode fails with %d.",
     464                 :            :                             ret);
     465                 :          0 :                 return ret;
     466                 :            :         }
     467                 :            : 
     468                 :          0 :         dev->data->scattered_rx = 0;
     469                 :            : 
     470                 :          0 :         return 0;
     471                 :            : }
     472                 :            : 
     473                 :            : static void
     474                 :          0 : fm10k_dev_vmdq_rx_configure(struct rte_eth_dev *dev)
     475                 :            : {
     476                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     477                 :            :         struct rte_eth_vmdq_rx_conf *vmdq_conf;
     478                 :            :         uint32_t i;
     479                 :            : 
     480                 :            :         vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
     481                 :            : 
     482         [ #  # ]:          0 :         for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
     483         [ #  # ]:          0 :                 if (!vmdq_conf->pool_map[i].pools)
     484                 :          0 :                         continue;
     485                 :            :                 fm10k_mbx_lock(hw);
     486                 :          0 :                 fm10k_update_vlan(hw, vmdq_conf->pool_map[i].vlan_id, 0, true);
     487                 :            :                 fm10k_mbx_unlock(hw);
     488                 :            :         }
     489                 :          0 : }
     490                 :            : 
     491                 :            : static void
     492                 :            : fm10k_dev_pf_main_vsi_reset(struct rte_eth_dev *dev)
     493                 :            : {
     494                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     495                 :            : 
     496                 :            :         /* Add default mac address */
     497                 :          0 :         fm10k_MAC_filter_set(dev, hw->mac.addr, true,
     498                 :            :                 MAIN_VSI_POOL_NUMBER);
     499                 :          0 : }
     500                 :            : 
     501                 :            : static void
     502                 :          0 : fm10k_dev_rss_configure(struct rte_eth_dev *dev)
     503                 :            : {
     504                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     505                 :            :         struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
     506                 :            :         uint32_t mrqc, *key, i, reta, j;
     507                 :            :         uint64_t hf;
     508                 :            : 
     509                 :            : #define RSS_KEY_SIZE 40
     510                 :            :         static uint8_t rss_intel_key[RSS_KEY_SIZE] = {
     511                 :            :                 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
     512                 :            :                 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
     513                 :            :                 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
     514                 :            :                 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
     515                 :            :                 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
     516                 :            :         };
     517                 :            : 
     518         [ #  # ]:          0 :         if (dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_RSS ||
     519         [ #  # ]:          0 :                 dev_conf->rx_adv_conf.rss_conf.rss_hf == 0) {
     520                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_MRQC(0), 0);
     521                 :          0 :                 return;
     522                 :            :         }
     523                 :            : 
     524                 :            :         /* random key is rss_intel_key (default) or user provided (rss_key) */
     525         [ #  # ]:          0 :         if (dev_conf->rx_adv_conf.rss_conf.rss_key == NULL)
     526                 :            :                 key = (uint32_t *)rss_intel_key;
     527                 :            :         else
     528                 :            :                 key = (uint32_t *)dev_conf->rx_adv_conf.rss_conf.rss_key;
     529                 :            : 
     530                 :            :         /* Now fill our hash function seeds, 4 bytes at a time */
     531         [ #  # ]:          0 :         for (i = 0; i < RSS_KEY_SIZE / sizeof(*key); ++i)
     532                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_RSSRK(0, i), key[i]);
     533                 :            : 
     534                 :            :         /*
     535                 :            :          * Fill in redirection table
     536                 :            :          * The byte-swap is needed because NIC registers are in
     537                 :            :          * little-endian order.
     538                 :            :          */
     539                 :            :         reta = 0;
     540         [ #  # ]:          0 :         for (i = 0, j = 0; i < FM10K_MAX_RSS_INDICES; i++, j++) {
     541         [ #  # ]:          0 :                 if (j == dev->data->nb_rx_queues)
     542                 :            :                         j = 0;
     543                 :          0 :                 reta = (reta << CHAR_BIT) | j;
     544         [ #  # ]:          0 :                 if ((i & 3) == 3)
     545         [ #  # ]:          0 :                         FM10K_WRITE_REG(hw, FM10K_RETA(0, i >> 2),
     546                 :            :                                         rte_bswap32(reta));
     547                 :            :         }
     548                 :            : 
     549                 :            :         /*
     550                 :            :          * Generate RSS hash based on packet types, TCP/UDP
     551                 :            :          * port numbers and/or IPv4/v6 src and dst addresses
     552                 :            :          */
     553                 :          0 :         hf = dev_conf->rx_adv_conf.rss_conf.rss_hf;
     554                 :            :         mrqc = 0;
     555                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_IPV4)              ? FM10K_MRQC_IPV4     : 0;
     556                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_IPV6)              ? FM10K_MRQC_IPV6     : 0;
     557                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_IPV6_EX)           ? FM10K_MRQC_IPV6     : 0;
     558                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)  ? FM10K_MRQC_TCP_IPV4 : 0;
     559                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP)  ? FM10K_MRQC_TCP_IPV6 : 0;
     560                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_IPV6_TCP_EX)       ? FM10K_MRQC_TCP_IPV6 : 0;
     561                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)  ? FM10K_MRQC_UDP_IPV4 : 0;
     562                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP)  ? FM10K_MRQC_UDP_IPV6 : 0;
     563                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_IPV6_UDP_EX)       ? FM10K_MRQC_UDP_IPV6 : 0;
     564                 :            : 
     565         [ #  # ]:          0 :         if (mrqc == 0) {
     566                 :          0 :                 PMD_INIT_LOG(ERR, "Specified RSS mode 0x%"PRIx64"is not"
     567                 :            :                         "supported", hf);
     568                 :          0 :                 return;
     569                 :            :         }
     570                 :            : 
     571                 :          0 :         FM10K_WRITE_REG(hw, FM10K_MRQC(0), mrqc);
     572                 :            : }
     573                 :            : 
     574                 :            : static void
     575                 :          0 : fm10k_dev_logic_port_update(struct rte_eth_dev *dev, uint16_t nb_lport_new)
     576                 :            : {
     577                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     578                 :            :         uint32_t i;
     579                 :            : 
     580         [ #  # ]:          0 :         for (i = 0; i < nb_lport_new; i++) {
     581                 :            :                 /* Set unicast mode by default. App can change
     582                 :            :                  * to other mode in other API func.
     583                 :            :                  */
     584                 :            :                 fm10k_mbx_lock(hw);
     585                 :          0 :                 hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map + i,
     586                 :            :                         FM10K_XCAST_MODE_NONE);
     587                 :            :                 fm10k_mbx_unlock(hw);
     588                 :            :         }
     589                 :          0 : }
     590                 :            : 
     591                 :            : static void
     592                 :          0 : fm10k_dev_mq_rx_configure(struct rte_eth_dev *dev)
     593                 :            : {
     594                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     595                 :            :         struct rte_eth_vmdq_rx_conf *vmdq_conf;
     596                 :            :         struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
     597                 :            :         struct fm10k_macvlan_filter_info *macvlan;
     598                 :            :         uint16_t nb_queue_pools = 0; /* pool number in configuration */
     599                 :            :         uint16_t nb_lport_new;
     600                 :            : 
     601                 :          0 :         macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
     602                 :            :         vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
     603                 :            : 
     604                 :          0 :         fm10k_dev_rss_configure(dev);
     605                 :            : 
     606                 :            :         /* only PF supports VMDQ */
     607         [ #  # ]:          0 :         if (hw->mac.type != fm10k_mac_pf)
     608                 :            :                 return;
     609                 :            : 
     610         [ #  # ]:          0 :         if (dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG)
     611                 :          0 :                 nb_queue_pools = vmdq_conf->nb_queue_pools;
     612                 :            : 
     613                 :            :         /* no pool number change, no need to update logic port and VLAN/MAC */
     614         [ #  # ]:          0 :         if (macvlan->nb_queue_pools == nb_queue_pools)
     615                 :            :                 return;
     616                 :            : 
     617                 :            :         nb_lport_new = nb_queue_pools ? nb_queue_pools : 1;
     618                 :          0 :         fm10k_dev_logic_port_update(dev, nb_lport_new);
     619                 :            : 
     620                 :            :         /* reset MAC/VLAN as it's based on VMDQ or PF main VSI */
     621         [ #  # ]:          0 :         memset(dev->data->mac_addrs, 0,
     622                 :            :                 RTE_ETHER_ADDR_LEN * FM10K_MAX_MACADDR_NUM);
     623                 :          0 :         rte_ether_addr_copy((const struct rte_ether_addr *)hw->mac.addr,
     624         [ #  # ]:          0 :                 &dev->data->mac_addrs[0]);
     625                 :            :         memset(macvlan, 0, sizeof(*macvlan));
     626                 :          0 :         macvlan->nb_queue_pools = nb_queue_pools;
     627                 :            : 
     628         [ #  # ]:          0 :         if (nb_queue_pools)
     629                 :          0 :                 fm10k_dev_vmdq_rx_configure(dev);
     630                 :            :         else
     631                 :            :                 fm10k_dev_pf_main_vsi_reset(dev);
     632                 :            : }
     633                 :            : 
     634                 :            : static int
     635                 :          0 : fm10k_dev_tx_init(struct rte_eth_dev *dev)
     636                 :            : {
     637                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     638                 :            :         int i, ret;
     639                 :            :         struct fm10k_tx_queue *txq;
     640                 :            :         uint64_t base_addr;
     641                 :            :         uint32_t size;
     642                 :            : 
     643                 :            :         /* Disable TXINT to avoid possible interrupt */
     644         [ #  # ]:          0 :         for (i = 0; i < hw->mac.max_queues; i++)
     645                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_TXINT(i),
     646                 :            :                                 3 << FM10K_TXINT_TIMER_SHIFT);
     647                 :            : 
     648                 :            :         /* Setup TX queue */
     649         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; ++i) {
     650                 :          0 :                 txq = dev->data->tx_queues[i];
     651                 :          0 :                 base_addr = txq->hw_ring_phys_addr;
     652                 :          0 :                 size = txq->nb_desc * sizeof(struct fm10k_tx_desc);
     653                 :            : 
     654                 :            :                 /* disable queue to avoid issues while updating state */
     655                 :          0 :                 ret = tx_queue_disable(hw, i);
     656         [ #  # ]:          0 :                 if (ret) {
     657                 :          0 :                         PMD_INIT_LOG(ERR, "failed to disable queue %d", i);
     658                 :          0 :                         return -1;
     659                 :            :                 }
     660                 :            :                 /* Enable use of FTAG bit in TX descriptor, PFVTCTL
     661                 :            :                  * register is read-only for VF.
     662                 :            :                  */
     663         [ #  # ]:          0 :                 if (fm10k_check_ftag(dev->device->devargs)) {
     664         [ #  # ]:          0 :                         if (hw->mac.type == fm10k_mac_pf) {
     665                 :          0 :                                 FM10K_WRITE_REG(hw, FM10K_PFVTCTL(i),
     666                 :            :                                                 FM10K_PFVTCTL_FTAG_DESC_ENABLE);
     667                 :          0 :                                 PMD_INIT_LOG(DEBUG, "FTAG mode is enabled");
     668                 :            :                         } else {
     669                 :          0 :                                 PMD_INIT_LOG(ERR, "VF FTAG is not supported.");
     670                 :          0 :                                 return -ENOTSUP;
     671                 :            :                         }
     672                 :            :                 }
     673                 :            : 
     674                 :            :                 /* set location and size for descriptor ring */
     675                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_TDBAL(i),
     676                 :            :                                 base_addr & UINT64_LOWER_32BITS_MASK);
     677                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_TDBAH(i),
     678                 :            :                                 base_addr >> (CHAR_BIT * sizeof(uint32_t)));
     679                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_TDLEN(i), size);
     680                 :            : 
     681                 :            :                 /* assign default SGLORT for each TX queue by PF */
     682         [ #  # ]:          0 :                 if (hw->mac.type == fm10k_mac_pf)
     683                 :          0 :                         FM10K_WRITE_REG(hw, FM10K_TX_SGLORT(i), hw->mac.dglort_map);
     684                 :            :         }
     685                 :            : 
     686                 :            :         /* set up vector or scalar TX function as appropriate */
     687                 :          0 :         fm10k_set_tx_function(dev);
     688                 :            : 
     689                 :          0 :         return 0;
     690                 :            : }
     691                 :            : 
     692                 :            : static int
     693                 :          0 : fm10k_dev_rx_init(struct rte_eth_dev *dev)
     694                 :            : {
     695                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     696                 :            :         struct fm10k_macvlan_filter_info *macvlan;
     697                 :          0 :         struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
     698                 :          0 :         struct rte_intr_handle *intr_handle = pdev->intr_handle;
     699                 :            :         int i, ret;
     700                 :            :         struct fm10k_rx_queue *rxq;
     701                 :            :         uint64_t base_addr;
     702                 :            :         uint32_t size;
     703                 :            :         uint32_t rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY;
     704                 :          0 :         uint32_t logic_port = hw->mac.dglort_map;
     705                 :            :         uint16_t buf_size;
     706                 :            :         uint16_t queue_stride = 0;
     707                 :            : 
     708                 :            :         /* enable RXINT for interrupt mode */
     709                 :            :         i = 0;
     710         [ #  # ]:          0 :         if (rte_intr_dp_is_en(intr_handle)) {
     711         [ #  # ]:          0 :                 for (; i < dev->data->nb_rx_queues; i++) {
     712                 :          0 :                         FM10K_WRITE_REG(hw, FM10K_RXINT(i), Q2V(pdev, i));
     713         [ #  # ]:          0 :                         if (hw->mac.type == fm10k_mac_pf)
     714                 :          0 :                                 FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, i)),
     715                 :            :                                         FM10K_ITR_AUTOMASK |
     716                 :            :                                         FM10K_ITR_MASK_CLEAR);
     717                 :            :                         else
     718                 :          0 :                                 FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, i)),
     719                 :            :                                         FM10K_ITR_AUTOMASK |
     720                 :            :                                         FM10K_ITR_MASK_CLEAR);
     721                 :            :                 }
     722                 :            :         }
     723                 :            :         /* Disable other RXINT to avoid possible interrupt */
     724         [ #  # ]:          0 :         for (; i < hw->mac.max_queues; i++)
     725                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_RXINT(i),
     726                 :            :                         3 << FM10K_RXINT_TIMER_SHIFT);
     727                 :            : 
     728                 :            :         /* Setup RX queues */
     729         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; ++i) {
     730                 :          0 :                 rxq = dev->data->rx_queues[i];
     731                 :          0 :                 base_addr = rxq->hw_ring_phys_addr;
     732                 :          0 :                 size = rxq->nb_desc * sizeof(union fm10k_rx_desc);
     733                 :            : 
     734                 :            :                 /* disable queue to avoid issues while updating state */
     735                 :          0 :                 ret = rx_queue_disable(hw, i);
     736         [ #  # ]:          0 :                 if (ret) {
     737                 :          0 :                         PMD_INIT_LOG(ERR, "failed to disable queue %d", i);
     738                 :          0 :                         return -1;
     739                 :            :                 }
     740                 :            : 
     741                 :            :                 /* Setup the Base and Length of the Rx Descriptor Ring */
     742                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_RDBAL(i),
     743                 :            :                                 base_addr & UINT64_LOWER_32BITS_MASK);
     744                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_RDBAH(i),
     745                 :            :                                 base_addr >> (CHAR_BIT * sizeof(uint32_t)));
     746                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_RDLEN(i), size);
     747                 :            : 
     748                 :            :                 /* Configure the Rx buffer size for one buff without split */
     749         [ #  # ]:          0 :                 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
     750                 :            :                         RTE_PKTMBUF_HEADROOM);
     751                 :            :                 /* As RX buffer is aligned to 512B within mbuf, some bytes are
     752                 :            :                  * reserved for this purpose, and the worst case could be 511B.
     753                 :            :                  * But SRR reg assumes all buffers have the same size. In order
     754                 :            :                  * to fill the gap, we'll have to consider the worst case and
     755                 :            :                  * assume 512B is reserved. If we don't do so, it's possible
     756                 :            :                  * for HW to overwrite data to next mbuf.
     757                 :            :                  */
     758                 :          0 :                 buf_size -= FM10K_RX_DATABUF_ALIGN;
     759                 :            : 
     760                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_SRRCTL(i),
     761                 :            :                                 (buf_size >> FM10K_SRRCTL_BSIZEPKT_SHIFT) |
     762                 :            :                                 FM10K_SRRCTL_LOOPBACK_SUPPRESS);
     763                 :            : 
     764                 :            :                 /* It adds dual VLAN length for supporting dual VLAN */
     765                 :          0 :                 if ((dev->data->mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN +
     766         [ #  # ]:          0 :                                 2 * RTE_VLAN_HLEN) > buf_size ||
     767         [ #  # ]:          0 :                         rxq->offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
     768                 :            :                         uint32_t reg;
     769                 :          0 :                         dev->data->scattered_rx = 1;
     770                 :          0 :                         reg = FM10K_READ_REG(hw, FM10K_SRRCTL(i));
     771                 :          0 :                         reg |= FM10K_SRRCTL_BUFFER_CHAINING_EN;
     772                 :          0 :                         FM10K_WRITE_REG(hw, FM10K_SRRCTL(i), reg);
     773                 :            :                 }
     774                 :            : 
     775                 :            :                 /* Enable drop on empty, it's RO for VF */
     776   [ #  #  #  # ]:          0 :                 if (hw->mac.type == fm10k_mac_pf && rxq->drop_en)
     777                 :            :                         rxdctl |= FM10K_RXDCTL_DROP_ON_EMPTY;
     778                 :            : 
     779                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_RXDCTL(i), rxdctl);
     780                 :          0 :                 FM10K_WRITE_FLUSH(hw);
     781                 :            :         }
     782                 :            : 
     783                 :            :         /* Configure VMDQ/RSS if applicable */
     784                 :          0 :         fm10k_dev_mq_rx_configure(dev);
     785                 :            : 
     786                 :            :         /* Decide the best RX function */
     787                 :          0 :         fm10k_set_rx_function(dev);
     788                 :            : 
     789                 :            :         /* update RX_SGLORT for loopback suppress*/
     790         [ #  # ]:          0 :         if (hw->mac.type != fm10k_mac_pf)
     791                 :            :                 return 0;
     792                 :          0 :         macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
     793         [ #  # ]:          0 :         if (macvlan->nb_queue_pools)
     794                 :          0 :                 queue_stride = dev->data->nb_rx_queues / macvlan->nb_queue_pools;
     795         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; ++i) {
     796   [ #  #  #  # ]:          0 :                 if (i && queue_stride && !(i % queue_stride))
     797                 :          0 :                         logic_port++;
     798                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_RX_SGLORT(i), logic_port);
     799                 :            :         }
     800                 :            : 
     801                 :            :         return 0;
     802                 :            : }
     803                 :            : 
     804                 :            : static int
     805                 :          0 : fm10k_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
     806                 :            : {
     807                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     808                 :            :         int err;
     809                 :            :         uint32_t reg;
     810                 :            :         struct fm10k_rx_queue *rxq;
     811                 :            : 
     812                 :          0 :         PMD_INIT_FUNC_TRACE();
     813                 :            : 
     814                 :          0 :         rxq = dev->data->rx_queues[rx_queue_id];
     815                 :          0 :         err = rx_queue_reset(rxq);
     816         [ #  # ]:          0 :         if (err == -ENOMEM) {
     817                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to alloc memory : %d", err);
     818                 :          0 :                 return err;
     819         [ #  # ]:          0 :         } else if (err == -EINVAL) {
     820                 :          0 :                 PMD_INIT_LOG(ERR, "Invalid buffer address alignment :"
     821                 :            :                         " %d", err);
     822                 :          0 :                 return err;
     823                 :            :         }
     824                 :            : 
     825                 :            :         /* Setup the HW Rx Head and Tail Descriptor Pointers
     826                 :            :          * Note: this must be done AFTER the queue is enabled on real
     827                 :            :          * hardware, but BEFORE the queue is enabled when using the
     828                 :            :          * emulation platform. Do it in both places for now and remove
     829                 :            :          * this comment and the following two register writes when the
     830                 :            :          * emulation platform is no longer being used.
     831                 :            :          */
     832                 :          0 :         FM10K_WRITE_REG(hw, FM10K_RDH(rx_queue_id), 0);
     833                 :          0 :         FM10K_WRITE_REG(hw, FM10K_RDT(rx_queue_id), rxq->nb_desc - 1);
     834                 :            : 
     835                 :            :         /* Set PF ownership flag for PF devices */
     836                 :          0 :         reg = FM10K_READ_REG(hw, FM10K_RXQCTL(rx_queue_id));
     837         [ #  # ]:          0 :         if (hw->mac.type == fm10k_mac_pf)
     838                 :          0 :                 reg |= FM10K_RXQCTL_PF;
     839                 :          0 :         reg |= FM10K_RXQCTL_ENABLE;
     840                 :            :         /* enable RX queue */
     841                 :          0 :         FM10K_WRITE_REG(hw, FM10K_RXQCTL(rx_queue_id), reg);
     842                 :          0 :         FM10K_WRITE_FLUSH(hw);
     843                 :            : 
     844                 :            :         /* Setup the HW Rx Head and Tail Descriptor Pointers
     845                 :            :          * Note: this must be done AFTER the queue is enabled
     846                 :            :          */
     847                 :          0 :         FM10K_WRITE_REG(hw, FM10K_RDH(rx_queue_id), 0);
     848                 :          0 :         FM10K_WRITE_REG(hw, FM10K_RDT(rx_queue_id), rxq->nb_desc - 1);
     849                 :          0 :         dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
     850                 :            : 
     851                 :          0 :         return 0;
     852                 :            : }
     853                 :            : 
     854                 :            : static int
     855                 :          0 : fm10k_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
     856                 :            : {
     857                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     858                 :            : 
     859                 :          0 :         PMD_INIT_FUNC_TRACE();
     860                 :            : 
     861                 :            :         /* Disable RX queue */
     862                 :          0 :         rx_queue_disable(hw, rx_queue_id);
     863                 :            : 
     864                 :            :         /* Free mbuf and clean HW ring */
     865                 :          0 :         rx_queue_clean(dev->data->rx_queues[rx_queue_id]);
     866                 :          0 :         dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
     867                 :            : 
     868                 :          0 :         return 0;
     869                 :            : }
     870                 :            : 
     871                 :            : static int
     872                 :          0 : fm10k_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
     873                 :            : {
     874                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     875                 :            :         /** @todo - this should be defined in the shared code */
     876                 :            : #define FM10K_TXDCTL_WRITE_BACK_MIN_DELAY       0x00010000
     877                 :            :         uint32_t txdctl = FM10K_TXDCTL_WRITE_BACK_MIN_DELAY;
     878                 :          0 :         struct fm10k_tx_queue *q = dev->data->tx_queues[tx_queue_id];
     879                 :            : 
     880                 :          0 :         PMD_INIT_FUNC_TRACE();
     881                 :            : 
     882                 :          0 :         q->ops->reset(q);
     883                 :            : 
     884                 :            :         /* reset head and tail pointers */
     885                 :          0 :         FM10K_WRITE_REG(hw, FM10K_TDH(tx_queue_id), 0);
     886                 :          0 :         FM10K_WRITE_REG(hw, FM10K_TDT(tx_queue_id), 0);
     887                 :            : 
     888                 :            :         /* enable TX queue */
     889                 :          0 :         FM10K_WRITE_REG(hw, FM10K_TXDCTL(tx_queue_id),
     890                 :            :                                 FM10K_TXDCTL_ENABLE | txdctl);
     891                 :          0 :         FM10K_WRITE_FLUSH(hw);
     892                 :          0 :         dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
     893                 :            : 
     894                 :          0 :         return 0;
     895                 :            : }
     896                 :            : 
     897                 :            : static int
     898                 :          0 : fm10k_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
     899                 :            : {
     900                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     901                 :            : 
     902                 :          0 :         PMD_INIT_FUNC_TRACE();
     903                 :            : 
     904                 :          0 :         tx_queue_disable(hw, tx_queue_id);
     905                 :          0 :         tx_queue_clean(dev->data->tx_queues[tx_queue_id]);
     906                 :          0 :         dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
     907                 :            : 
     908                 :          0 :         return 0;
     909                 :            : }
     910                 :            : 
     911                 :            : static inline int fm10k_glort_valid(struct fm10k_hw *hw)
     912                 :            : {
     913                 :          0 :         return ((hw->mac.dglort_map & FM10K_DGLORTMAP_NONE)
     914                 :            :                 != FM10K_DGLORTMAP_NONE);
     915                 :            : }
     916                 :            : 
     917                 :            : static int
     918                 :          0 : fm10k_dev_promiscuous_enable(struct rte_eth_dev *dev)
     919                 :            : {
     920                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     921                 :            :         int status;
     922                 :            : 
     923                 :          0 :         PMD_INIT_FUNC_TRACE();
     924                 :            : 
     925                 :            :         /* Return if it didn't acquire valid glort range */
     926   [ #  #  #  # ]:          0 :         if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
     927                 :            :                 return 0;
     928                 :            : 
     929                 :            :         fm10k_mbx_lock(hw);
     930                 :          0 :         status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
     931                 :            :                                 FM10K_XCAST_MODE_PROMISC);
     932                 :            :         fm10k_mbx_unlock(hw);
     933                 :            : 
     934         [ #  # ]:          0 :         if (status != FM10K_SUCCESS) {
     935                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to enable promiscuous mode");
     936                 :          0 :                 return -EAGAIN;
     937                 :            :         }
     938                 :            : 
     939                 :            :         return 0;
     940                 :            : }
     941                 :            : 
     942                 :            : static int
     943                 :          0 : fm10k_dev_promiscuous_disable(struct rte_eth_dev *dev)
     944                 :            : {
     945                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     946                 :            :         uint8_t mode;
     947                 :            :         int status;
     948                 :            : 
     949                 :          0 :         PMD_INIT_FUNC_TRACE();
     950                 :            : 
     951                 :            :         /* Return if it didn't acquire valid glort range */
     952   [ #  #  #  # ]:          0 :         if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
     953                 :            :                 return 0;
     954                 :            : 
     955         [ #  # ]:          0 :         if (dev->data->all_multicast == 1)
     956                 :            :                 mode = FM10K_XCAST_MODE_ALLMULTI;
     957                 :            :         else
     958                 :            :                 mode = FM10K_XCAST_MODE_NONE;
     959                 :            : 
     960                 :            :         fm10k_mbx_lock(hw);
     961                 :          0 :         status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
     962                 :            :                                 mode);
     963                 :            :         fm10k_mbx_unlock(hw);
     964                 :            : 
     965         [ #  # ]:          0 :         if (status != FM10K_SUCCESS) {
     966                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to disable promiscuous mode");
     967                 :          0 :                 return -EAGAIN;
     968                 :            :         }
     969                 :            : 
     970                 :            :         return 0;
     971                 :            : }
     972                 :            : 
     973                 :            : static int
     974                 :          0 : fm10k_dev_allmulticast_enable(struct rte_eth_dev *dev)
     975                 :            : {
     976                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     977                 :            :         int status;
     978                 :            : 
     979                 :          0 :         PMD_INIT_FUNC_TRACE();
     980                 :            : 
     981                 :            :         /* Return if it didn't acquire valid glort range */
     982   [ #  #  #  # ]:          0 :         if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
     983                 :            :                 return 0;
     984                 :            : 
     985                 :            :         /* If promiscuous mode is enabled, it doesn't make sense to enable
     986                 :            :          * allmulticast and disable promiscuous since fm10k only can select
     987                 :            :          * one of the modes.
     988                 :            :          */
     989         [ #  # ]:          0 :         if (dev->data->promiscuous) {
     990                 :          0 :                 PMD_INIT_LOG(INFO, "Promiscuous mode is enabled, "\
     991                 :            :                         "needn't enable allmulticast");
     992                 :          0 :                 return 0;
     993                 :            :         }
     994                 :            : 
     995                 :            :         fm10k_mbx_lock(hw);
     996                 :          0 :         status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
     997                 :            :                                 FM10K_XCAST_MODE_ALLMULTI);
     998                 :            :         fm10k_mbx_unlock(hw);
     999                 :            : 
    1000         [ #  # ]:          0 :         if (status != FM10K_SUCCESS) {
    1001                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to enable allmulticast mode");
    1002                 :          0 :                 return -EAGAIN;
    1003                 :            :         }
    1004                 :            : 
    1005                 :            :         return 0;
    1006                 :            : }
    1007                 :            : 
    1008                 :            : static int
    1009                 :          0 : fm10k_dev_allmulticast_disable(struct rte_eth_dev *dev)
    1010                 :            : {
    1011                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1012                 :            :         int status;
    1013                 :            : 
    1014                 :          0 :         PMD_INIT_FUNC_TRACE();
    1015                 :            : 
    1016                 :            :         /* Return if it didn't acquire valid glort range */
    1017   [ #  #  #  # ]:          0 :         if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
    1018                 :            :                 return 0;
    1019                 :            : 
    1020         [ #  # ]:          0 :         if (dev->data->promiscuous) {
    1021                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to disable allmulticast mode "\
    1022                 :            :                         "since promisc mode is enabled");
    1023                 :          0 :                 return -EINVAL;
    1024                 :            :         }
    1025                 :            : 
    1026                 :            :         fm10k_mbx_lock(hw);
    1027                 :            :         /* Change mode to unicast mode */
    1028                 :          0 :         status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
    1029                 :            :                                 FM10K_XCAST_MODE_NONE);
    1030                 :            :         fm10k_mbx_unlock(hw);
    1031                 :            : 
    1032         [ #  # ]:          0 :         if (status != FM10K_SUCCESS) {
    1033                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to disable allmulticast mode");
    1034                 :          0 :                 return -EAGAIN;
    1035                 :            :         }
    1036                 :            : 
    1037                 :            :         return 0;
    1038                 :            : }
    1039                 :            : 
    1040                 :            : static void
    1041                 :          0 : fm10k_dev_dglort_map_configure(struct rte_eth_dev *dev)
    1042                 :            : {
    1043                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1044                 :            :         uint32_t dglortdec, pool_len, rss_len, i, dglortmask;
    1045                 :            :         uint16_t nb_queue_pools;
    1046                 :            :         struct fm10k_macvlan_filter_info *macvlan;
    1047                 :            : 
    1048                 :            :         macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
    1049                 :          0 :         nb_queue_pools = macvlan->nb_queue_pools;
    1050   [ #  #  #  # ]:          0 :         pool_len = nb_queue_pools ? rte_fls_u32(nb_queue_pools - 1) : 0;
    1051         [ #  # ]:          0 :         rss_len = rte_fls_u32(dev->data->nb_rx_queues - 1) - pool_len;
    1052                 :            : 
    1053                 :            :         /* GLORT 0x0-0x3F are used by PF and VMDQ,  0x40-0x7F used by FD */
    1054                 :          0 :         dglortdec = (rss_len << FM10K_DGLORTDEC_RSSLENGTH_SHIFT) | pool_len;
    1055                 :          0 :         dglortmask = (GLORT_PF_MASK << FM10K_DGLORTMAP_MASK_SHIFT) |
    1056                 :          0 :                         hw->mac.dglort_map;
    1057                 :          0 :         FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(0), dglortmask);
    1058                 :            :         /* Configure VMDQ/RSS DGlort Decoder */
    1059                 :          0 :         FM10K_WRITE_REG(hw, FM10K_DGLORTDEC(0), dglortdec);
    1060                 :            : 
    1061                 :            :         /* Flow Director configurations, only queue number is valid. */
    1062         [ #  # ]:          0 :         dglortdec = rte_fls_u32(dev->data->nb_rx_queues - 1);
    1063                 :          0 :         dglortmask = (GLORT_FD_MASK << FM10K_DGLORTMAP_MASK_SHIFT) |
    1064                 :          0 :                         (hw->mac.dglort_map + GLORT_FD_Q_BASE);
    1065                 :          0 :         FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(1), dglortmask);
    1066                 :          0 :         FM10K_WRITE_REG(hw, FM10K_DGLORTDEC(1), dglortdec);
    1067                 :            : 
    1068                 :            :         /* Invalidate all other GLORT entries */
    1069         [ #  # ]:          0 :         for (i = 2; i < FM10K_DGLORT_COUNT; i++)
    1070                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(i),
    1071                 :            :                                 FM10K_DGLORTMAP_NONE);
    1072                 :          0 : }
    1073                 :            : 
    1074                 :            : #define BSIZEPKT_ROUNDUP ((1 << FM10K_SRRCTL_BSIZEPKT_SHIFT) - 1)
    1075                 :            : static int
    1076                 :          0 : fm10k_dev_start(struct rte_eth_dev *dev)
    1077                 :            : {
    1078                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1079                 :            :         int i, diag;
    1080                 :            : 
    1081                 :          0 :         PMD_INIT_FUNC_TRACE();
    1082                 :            : 
    1083                 :            :         /* stop, init, then start the hw */
    1084                 :          0 :         diag = fm10k_stop_hw(hw);
    1085         [ #  # ]:          0 :         if (diag != FM10K_SUCCESS) {
    1086                 :          0 :                 PMD_INIT_LOG(ERR, "Hardware stop failed: %d", diag);
    1087                 :          0 :                 return -EIO;
    1088                 :            :         }
    1089                 :            : 
    1090                 :          0 :         diag = fm10k_init_hw(hw);
    1091         [ #  # ]:          0 :         if (diag != FM10K_SUCCESS) {
    1092                 :          0 :                 PMD_INIT_LOG(ERR, "Hardware init failed: %d", diag);
    1093                 :          0 :                 return -EIO;
    1094                 :            :         }
    1095                 :            : 
    1096                 :          0 :         diag = fm10k_start_hw(hw);
    1097         [ #  # ]:          0 :         if (diag != FM10K_SUCCESS) {
    1098                 :          0 :                 PMD_INIT_LOG(ERR, "Hardware start failed: %d", diag);
    1099                 :          0 :                 return -EIO;
    1100                 :            :         }
    1101                 :            : 
    1102                 :          0 :         diag = fm10k_dev_tx_init(dev);
    1103         [ #  # ]:          0 :         if (diag) {
    1104                 :          0 :                 PMD_INIT_LOG(ERR, "TX init failed: %d", diag);
    1105                 :          0 :                 return diag;
    1106                 :            :         }
    1107                 :            : 
    1108         [ #  # ]:          0 :         if (fm10k_dev_rxq_interrupt_setup(dev))
    1109                 :            :                 return -EIO;
    1110                 :            : 
    1111                 :          0 :         diag = fm10k_dev_rx_init(dev);
    1112         [ #  # ]:          0 :         if (diag) {
    1113                 :          0 :                 PMD_INIT_LOG(ERR, "RX init failed: %d", diag);
    1114                 :          0 :                 return diag;
    1115                 :            :         }
    1116                 :            : 
    1117         [ #  # ]:          0 :         if (hw->mac.type == fm10k_mac_pf)
    1118                 :          0 :                 fm10k_dev_dglort_map_configure(dev);
    1119                 :            : 
    1120         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    1121                 :            :                 struct fm10k_rx_queue *rxq;
    1122                 :          0 :                 rxq = dev->data->rx_queues[i];
    1123                 :            : 
    1124         [ #  # ]:          0 :                 if (rxq->rx_deferred_start)
    1125                 :          0 :                         continue;
    1126                 :          0 :                 diag = fm10k_dev_rx_queue_start(dev, i);
    1127         [ #  # ]:          0 :                 if (diag != 0) {
    1128                 :            :                         int j;
    1129         [ #  # ]:          0 :                         for (j = 0; j < i; ++j)
    1130                 :          0 :                                 rx_queue_clean(dev->data->rx_queues[j]);
    1131                 :            :                         return diag;
    1132                 :            :                 }
    1133                 :            :         }
    1134                 :            : 
    1135         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    1136                 :            :                 struct fm10k_tx_queue *txq;
    1137                 :          0 :                 txq = dev->data->tx_queues[i];
    1138                 :            : 
    1139         [ #  # ]:          0 :                 if (txq->tx_deferred_start)
    1140                 :          0 :                         continue;
    1141                 :          0 :                 diag = fm10k_dev_tx_queue_start(dev, i);
    1142         [ #  # ]:          0 :                 if (diag != 0) {
    1143                 :            :                         int j;
    1144         [ #  # ]:          0 :                         for (j = 0; j < i; ++j)
    1145                 :          0 :                                 tx_queue_clean(dev->data->tx_queues[j]);
    1146         [ #  # ]:          0 :                         for (j = 0; j < dev->data->nb_rx_queues; ++j)
    1147                 :          0 :                                 rx_queue_clean(dev->data->rx_queues[j]);
    1148                 :            :                         return diag;
    1149                 :            :                 }
    1150                 :            :         }
    1151                 :            : 
    1152                 :            :         /* Update default vlan when not in VMDQ mode */
    1153         [ #  # ]:          0 :         if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG))
    1154                 :          0 :                 fm10k_vlan_filter_set(dev, hw->mac.default_vid, true);
    1155                 :            : 
    1156                 :          0 :         fm10k_link_update(dev, 0);
    1157                 :            : 
    1158                 :          0 :         return 0;
    1159                 :            : }
    1160                 :            : 
    1161                 :            : static int
    1162                 :          0 : fm10k_dev_stop(struct rte_eth_dev *dev)
    1163                 :            : {
    1164                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1165                 :          0 :         struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
    1166                 :          0 :         struct rte_intr_handle *intr_handle = pdev->intr_handle;
    1167                 :            :         int i;
    1168                 :            : 
    1169                 :          0 :         PMD_INIT_FUNC_TRACE();
    1170                 :          0 :         dev->data->dev_started = 0;
    1171                 :            : 
    1172         [ #  # ]:          0 :         if (dev->data->tx_queues)
    1173         [ #  # ]:          0 :                 for (i = 0; i < dev->data->nb_tx_queues; i++)
    1174                 :          0 :                         fm10k_dev_tx_queue_stop(dev, i);
    1175                 :            : 
    1176         [ #  # ]:          0 :         if (dev->data->rx_queues)
    1177         [ #  # ]:          0 :                 for (i = 0; i < dev->data->nb_rx_queues; i++)
    1178                 :          0 :                         fm10k_dev_rx_queue_stop(dev, i);
    1179                 :            : 
    1180                 :            :         /* Disable datapath event */
    1181         [ #  # ]:          0 :         if (rte_intr_dp_is_en(intr_handle)) {
    1182         [ #  # ]:          0 :                 for (i = 0; i < dev->data->nb_rx_queues; i++) {
    1183                 :          0 :                         FM10K_WRITE_REG(hw, FM10K_RXINT(i),
    1184                 :            :                                 3 << FM10K_RXINT_TIMER_SHIFT);
    1185         [ #  # ]:          0 :                         if (hw->mac.type == fm10k_mac_pf)
    1186                 :          0 :                                 FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, i)),
    1187                 :            :                                         FM10K_ITR_MASK_SET);
    1188                 :            :                         else
    1189                 :          0 :                                 FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, i)),
    1190                 :            :                                         FM10K_ITR_MASK_SET);
    1191                 :            :                 }
    1192                 :            :         }
    1193                 :            :         /* Clean datapath event and queue/vec mapping */
    1194                 :          0 :         rte_intr_efd_disable(intr_handle);
    1195                 :          0 :         rte_intr_vec_list_free(intr_handle);
    1196                 :            : 
    1197                 :          0 :         return 0;
    1198                 :            : }
    1199                 :            : 
    1200                 :            : static void
    1201                 :          0 : fm10k_dev_queue_release(struct rte_eth_dev *dev)
    1202                 :            : {
    1203                 :            :         int i;
    1204                 :            : 
    1205                 :          0 :         PMD_INIT_FUNC_TRACE();
    1206                 :            : 
    1207         [ #  # ]:          0 :         if (dev->data->tx_queues) {
    1208         [ #  # ]:          0 :                 for (i = 0; i < dev->data->nb_tx_queues; i++) {
    1209                 :          0 :                         struct fm10k_tx_queue *txq = dev->data->tx_queues[i];
    1210                 :            : 
    1211                 :          0 :                         tx_queue_free(txq);
    1212                 :            :                 }
    1213                 :            :         }
    1214                 :            : 
    1215         [ #  # ]:          0 :         if (dev->data->rx_queues) {
    1216         [ #  # ]:          0 :                 for (i = 0; i < dev->data->nb_rx_queues; i++)
    1217                 :          0 :                         fm10k_rx_queue_release(dev, i);
    1218                 :            :         }
    1219                 :          0 : }
    1220                 :            : 
    1221                 :            : static int
    1222                 :          0 : fm10k_link_update(struct rte_eth_dev *dev,
    1223                 :            :         __rte_unused int wait_to_complete)
    1224                 :            : {
    1225                 :            :         struct fm10k_dev_info *dev_info =
    1226                 :          0 :                 FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
    1227                 :          0 :         PMD_INIT_FUNC_TRACE();
    1228                 :            : 
    1229                 :          0 :         dev->data->dev_link.link_speed  = RTE_ETH_SPEED_NUM_50G;
    1230                 :          0 :         dev->data->dev_link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
    1231                 :          0 :         dev->data->dev_link.link_status =
    1232                 :          0 :                 dev_info->sm_down ? RTE_ETH_LINK_DOWN : RTE_ETH_LINK_UP;
    1233                 :          0 :         dev->data->dev_link.link_autoneg = RTE_ETH_LINK_FIXED;
    1234                 :            : 
    1235                 :          0 :         return 0;
    1236                 :            : }
    1237                 :            : 
    1238                 :          0 : static int fm10k_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
    1239                 :            :         struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned limit)
    1240                 :            : {
    1241                 :            :         unsigned i, q;
    1242                 :            :         unsigned count = 0;
    1243                 :            : 
    1244         [ #  # ]:          0 :         if (xstats_names != NULL) {
    1245                 :            :                 /* Note: limit checked in rte_eth_xstats_names() */
    1246                 :            : 
    1247                 :            :                 /* Global stats */
    1248         [ #  # ]:          0 :                 for (i = 0; i < FM10K_NB_HW_XSTATS; i++) {
    1249                 :          0 :                         snprintf(xstats_names[count].name,
    1250                 :            :                                 sizeof(xstats_names[count].name),
    1251                 :          0 :                                 "%s", fm10k_hw_stats_strings[count].name);
    1252                 :          0 :                         count++;
    1253                 :            :                 }
    1254                 :            : 
    1255                 :            :                 /* PF queue stats */
    1256         [ #  # ]:          0 :                 for (q = 0; q < FM10K_MAX_QUEUES_PF; q++) {
    1257         [ #  # ]:          0 :                         for (i = 0; i < FM10K_NB_RX_Q_XSTATS; i++) {
    1258                 :          0 :                                 snprintf(xstats_names[count].name,
    1259                 :            :                                         sizeof(xstats_names[count].name),
    1260                 :            :                                         "rx_q%u_%s", q,
    1261                 :          0 :                                         fm10k_hw_stats_rx_q_strings[i].name);
    1262                 :          0 :                                 count++;
    1263                 :            :                         }
    1264         [ #  # ]:          0 :                         for (i = 0; i < FM10K_NB_TX_Q_XSTATS; i++) {
    1265                 :          0 :                                 snprintf(xstats_names[count].name,
    1266                 :            :                                         sizeof(xstats_names[count].name),
    1267                 :            :                                         "tx_q%u_%s", q,
    1268                 :          0 :                                         fm10k_hw_stats_tx_q_strings[i].name);
    1269                 :          0 :                                 count++;
    1270                 :            :                         }
    1271                 :            :                 }
    1272                 :            :         }
    1273                 :          0 :         return FM10K_NB_XSTATS;
    1274                 :            : }
    1275                 :            : 
    1276                 :            : static int
    1277                 :          0 : fm10k_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
    1278                 :            :                  unsigned n)
    1279                 :            : {
    1280                 :          0 :         struct fm10k_hw_stats *hw_stats =
    1281                 :          0 :                 FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
    1282                 :            :         unsigned i, q, count = 0;
    1283                 :            : 
    1284         [ #  # ]:          0 :         if (n < FM10K_NB_XSTATS)
    1285                 :            :                 return FM10K_NB_XSTATS;
    1286                 :            : 
    1287                 :            :         /* Global stats */
    1288         [ #  # ]:          0 :         for (i = 0; i < FM10K_NB_HW_XSTATS; i++) {
    1289                 :          0 :                 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
    1290                 :          0 :                         fm10k_hw_stats_strings[count].offset);
    1291                 :          0 :                 xstats[count].id = count;
    1292                 :          0 :                 count++;
    1293                 :            :         }
    1294                 :            : 
    1295                 :            :         /* PF queue stats */
    1296         [ #  # ]:          0 :         for (q = 0; q < FM10K_MAX_QUEUES_PF; q++) {
    1297         [ #  # ]:          0 :                 for (i = 0; i < FM10K_NB_RX_Q_XSTATS; i++) {
    1298                 :          0 :                         xstats[count].value =
    1299                 :          0 :                                 *(uint64_t *)(((char *)&hw_stats->q[q]) +
    1300                 :          0 :                                 fm10k_hw_stats_rx_q_strings[i].offset);
    1301                 :          0 :                         xstats[count].id = count;
    1302                 :          0 :                         count++;
    1303                 :            :                 }
    1304         [ #  # ]:          0 :                 for (i = 0; i < FM10K_NB_TX_Q_XSTATS; i++) {
    1305                 :          0 :                         xstats[count].value =
    1306                 :          0 :                                 *(uint64_t *)(((char *)&hw_stats->q[q]) +
    1307                 :          0 :                                 fm10k_hw_stats_tx_q_strings[i].offset);
    1308                 :          0 :                         xstats[count].id = count;
    1309                 :          0 :                         count++;
    1310                 :            :                 }
    1311                 :            :         }
    1312                 :            : 
    1313                 :            :         return FM10K_NB_XSTATS;
    1314                 :            : }
    1315                 :            : 
    1316                 :            : static int
    1317                 :          0 : fm10k_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
    1318                 :            : {
    1319                 :            :         uint64_t ipackets, opackets, ibytes, obytes, imissed;
    1320                 :          0 :         struct fm10k_hw *hw =
    1321                 :          0 :                 FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1322                 :          0 :         struct fm10k_hw_stats *hw_stats =
    1323                 :            :                 FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
    1324                 :            :         int i;
    1325                 :            : 
    1326                 :          0 :         PMD_INIT_FUNC_TRACE();
    1327                 :            : 
    1328                 :          0 :         fm10k_update_hw_stats(hw, hw_stats);
    1329                 :            : 
    1330                 :            :         ipackets = opackets = ibytes = obytes = imissed = 0;
    1331         [ #  # ]:          0 :         for (i = 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) &&
    1332         [ #  # ]:          0 :                 (i < hw->mac.max_queues); ++i) {
    1333                 :          0 :                 stats->q_ipackets[i] = hw_stats->q[i].rx_packets.count;
    1334                 :          0 :                 stats->q_opackets[i] = hw_stats->q[i].tx_packets.count;
    1335                 :          0 :                 stats->q_ibytes[i]   = hw_stats->q[i].rx_bytes.count;
    1336                 :          0 :                 stats->q_obytes[i]   = hw_stats->q[i].tx_bytes.count;
    1337                 :          0 :                 stats->q_errors[i]   = hw_stats->q[i].rx_drops.count;
    1338                 :          0 :                 ipackets += stats->q_ipackets[i];
    1339                 :          0 :                 opackets += stats->q_opackets[i];
    1340                 :          0 :                 ibytes   += stats->q_ibytes[i];
    1341                 :          0 :                 obytes   += stats->q_obytes[i];
    1342                 :          0 :                 imissed  += stats->q_errors[i];
    1343                 :            :         }
    1344                 :          0 :         stats->ipackets = ipackets;
    1345                 :          0 :         stats->opackets = opackets;
    1346                 :          0 :         stats->ibytes = ibytes;
    1347                 :          0 :         stats->obytes = obytes;
    1348                 :          0 :         stats->imissed = imissed;
    1349                 :          0 :         return 0;
    1350                 :            : }
    1351                 :            : 
    1352                 :            : static int
    1353                 :          0 : fm10k_stats_reset(struct rte_eth_dev *dev)
    1354                 :            : {
    1355                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1356                 :          0 :         struct fm10k_hw_stats *hw_stats =
    1357                 :            :                 FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
    1358                 :            : 
    1359                 :          0 :         PMD_INIT_FUNC_TRACE();
    1360                 :            : 
    1361                 :            :         memset(hw_stats, 0, sizeof(*hw_stats));
    1362                 :          0 :         fm10k_rebind_hw_stats(hw, hw_stats);
    1363                 :            : 
    1364                 :          0 :         return 0;
    1365                 :            : }
    1366                 :            : 
    1367                 :            : static int
    1368                 :          0 : fm10k_dev_infos_get(struct rte_eth_dev *dev,
    1369                 :            :         struct rte_eth_dev_info *dev_info)
    1370                 :            : {
    1371                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1372                 :          0 :         struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
    1373                 :            : 
    1374                 :          0 :         PMD_INIT_FUNC_TRACE();
    1375                 :            : 
    1376                 :          0 :         dev_info->min_rx_bufsize     = FM10K_MIN_RX_BUF_SIZE;
    1377                 :          0 :         dev_info->max_rx_pktlen      = FM10K_MAX_PKT_SIZE;
    1378                 :          0 :         dev_info->max_rx_queues      = hw->mac.max_queues;
    1379                 :          0 :         dev_info->max_tx_queues      = hw->mac.max_queues;
    1380                 :          0 :         dev_info->max_mac_addrs      = FM10K_MAX_MACADDR_NUM;
    1381                 :          0 :         dev_info->max_hash_mac_addrs = 0;
    1382                 :          0 :         dev_info->max_vfs            = pdev->max_vfs;
    1383                 :          0 :         dev_info->vmdq_pool_base     = 0;
    1384                 :          0 :         dev_info->vmdq_queue_base    = 0;
    1385                 :          0 :         dev_info->max_vmdq_pools     = RTE_ETH_32_POOLS;
    1386                 :          0 :         dev_info->vmdq_queue_num     = FM10K_MAX_QUEUES_PF;
    1387                 :          0 :         dev_info->rx_queue_offload_capa = fm10k_get_rx_queue_offloads_capa(dev);
    1388                 :          0 :         dev_info->rx_offload_capa = fm10k_get_rx_port_offloads_capa(dev) |
    1389                 :            :                                     dev_info->rx_queue_offload_capa;
    1390                 :          0 :         dev_info->tx_queue_offload_capa = fm10k_get_tx_queue_offloads_capa(dev);
    1391                 :          0 :         dev_info->tx_offload_capa = fm10k_get_tx_port_offloads_capa(dev) |
    1392                 :            :                                     dev_info->tx_queue_offload_capa;
    1393                 :            : 
    1394                 :          0 :         dev_info->hash_key_size = FM10K_RSSRK_SIZE * sizeof(uint32_t);
    1395                 :          0 :         dev_info->reta_size = FM10K_MAX_RSS_INDICES;
    1396                 :          0 :         dev_info->flow_type_rss_offloads = RTE_ETH_RSS_IPV4 |
    1397                 :            :                                         RTE_ETH_RSS_IPV6 |
    1398                 :            :                                         RTE_ETH_RSS_IPV6_EX |
    1399                 :            :                                         RTE_ETH_RSS_NONFRAG_IPV4_TCP |
    1400                 :            :                                         RTE_ETH_RSS_NONFRAG_IPV6_TCP |
    1401                 :            :                                         RTE_ETH_RSS_IPV6_TCP_EX |
    1402                 :            :                                         RTE_ETH_RSS_NONFRAG_IPV4_UDP |
    1403                 :            :                                         RTE_ETH_RSS_NONFRAG_IPV6_UDP |
    1404                 :            :                                         RTE_ETH_RSS_IPV6_UDP_EX;
    1405                 :            : 
    1406                 :          0 :         dev_info->default_rxconf = (struct rte_eth_rxconf) {
    1407                 :            :                 .rx_thresh = {
    1408                 :            :                         .pthresh = FM10K_DEFAULT_RX_PTHRESH,
    1409                 :            :                         .hthresh = FM10K_DEFAULT_RX_HTHRESH,
    1410                 :            :                         .wthresh = FM10K_DEFAULT_RX_WTHRESH,
    1411                 :            :                 },
    1412                 :            :                 .rx_free_thresh = FM10K_RX_FREE_THRESH_DEFAULT(0),
    1413                 :            :                 .rx_drop_en = 0,
    1414                 :            :                 .offloads = 0,
    1415                 :            :         };
    1416                 :            : 
    1417                 :          0 :         dev_info->default_txconf = (struct rte_eth_txconf) {
    1418                 :            :                 .tx_thresh = {
    1419                 :            :                         .pthresh = FM10K_DEFAULT_TX_PTHRESH,
    1420                 :            :                         .hthresh = FM10K_DEFAULT_TX_HTHRESH,
    1421                 :            :                         .wthresh = FM10K_DEFAULT_TX_WTHRESH,
    1422                 :            :                 },
    1423                 :            :                 .tx_free_thresh = FM10K_TX_FREE_THRESH_DEFAULT(0),
    1424                 :            :                 .tx_rs_thresh = FM10K_TX_RS_THRESH_DEFAULT(0),
    1425                 :            :                 .offloads = 0,
    1426                 :            :         };
    1427                 :            : 
    1428                 :          0 :         dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
    1429                 :            :                 .nb_max = FM10K_MAX_RX_DESC,
    1430                 :            :                 .nb_min = FM10K_MIN_RX_DESC,
    1431                 :            :                 .nb_align = FM10K_MULT_RX_DESC,
    1432                 :            :         };
    1433                 :            : 
    1434                 :          0 :         dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
    1435                 :            :                 .nb_max = FM10K_MAX_TX_DESC,
    1436                 :            :                 .nb_min = FM10K_MIN_TX_DESC,
    1437                 :            :                 .nb_align = FM10K_MULT_TX_DESC,
    1438                 :            :                 .nb_seg_max = FM10K_TX_MAX_SEG,
    1439                 :            :                 .nb_mtu_seg_max = FM10K_TX_MAX_MTU_SEG,
    1440                 :            :         };
    1441                 :            : 
    1442                 :          0 :         dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_2_5G |
    1443                 :            :                         RTE_ETH_LINK_SPEED_10G | RTE_ETH_LINK_SPEED_25G |
    1444                 :            :                         RTE_ETH_LINK_SPEED_40G | RTE_ETH_LINK_SPEED_100G;
    1445                 :            : 
    1446                 :          0 :         return 0;
    1447                 :            : }
    1448                 :            : 
    1449                 :            : #ifdef RTE_LIBRTE_FM10K_RX_OLFLAGS_ENABLE
    1450                 :            : static const uint32_t *
    1451                 :          0 : fm10k_dev_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
    1452                 :            : {
    1453   [ #  #  #  # ]:          0 :         if (dev->rx_pkt_burst == fm10k_recv_pkts ||
    1454                 :            :             dev->rx_pkt_burst == fm10k_recv_scattered_pkts) {
    1455                 :            :                 static uint32_t ptypes[] = {
    1456                 :            :                         /* refers to rx_desc_to_ol_flags() */
    1457                 :            :                         RTE_PTYPE_L2_ETHER,
    1458                 :            :                         RTE_PTYPE_L3_IPV4,
    1459                 :            :                         RTE_PTYPE_L3_IPV4_EXT,
    1460                 :            :                         RTE_PTYPE_L3_IPV6,
    1461                 :            :                         RTE_PTYPE_L3_IPV6_EXT,
    1462                 :            :                         RTE_PTYPE_L4_TCP,
    1463                 :            :                         RTE_PTYPE_L4_UDP,
    1464                 :            :                 };
    1465                 :            : 
    1466                 :          0 :                 *no_of_elements = RTE_DIM(ptypes);
    1467                 :          0 :                 return ptypes;
    1468   [ #  #  #  # ]:          0 :         } else if (dev->rx_pkt_burst == fm10k_recv_pkts_vec ||
    1469                 :            :                    dev->rx_pkt_burst == fm10k_recv_scattered_pkts_vec) {
    1470                 :            :                 static uint32_t ptypes_vec[] = {
    1471                 :            :                         /* refers to fm10k_desc_to_pktype_v() */
    1472                 :            :                         RTE_PTYPE_L3_IPV4,
    1473                 :            :                         RTE_PTYPE_L3_IPV4_EXT,
    1474                 :            :                         RTE_PTYPE_L3_IPV6,
    1475                 :            :                         RTE_PTYPE_L3_IPV6_EXT,
    1476                 :            :                         RTE_PTYPE_L4_TCP,
    1477                 :            :                         RTE_PTYPE_L4_UDP,
    1478                 :            :                         RTE_PTYPE_TUNNEL_GENEVE,
    1479                 :            :                         RTE_PTYPE_TUNNEL_NVGRE,
    1480                 :            :                         RTE_PTYPE_TUNNEL_VXLAN,
    1481                 :            :                         RTE_PTYPE_TUNNEL_GRE,
    1482                 :            :                 };
    1483                 :            : 
    1484                 :          0 :                 *no_of_elements = RTE_DIM(ptypes_vec);
    1485                 :          0 :                 return ptypes_vec;
    1486                 :            :         }
    1487                 :            : 
    1488                 :            :         return NULL;
    1489                 :            : }
    1490                 :            : #else
    1491                 :            : static const uint32_t *
    1492                 :            : fm10k_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused,
    1493                 :            :                                size_t *no_of_elements)
    1494                 :            : {
    1495                 :            :         return NULL;
    1496                 :            : }
    1497                 :            : #endif
    1498                 :            : 
    1499                 :            : static int
    1500                 :          0 : fm10k_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
    1501                 :            : {
    1502                 :            :         s32 result;
    1503                 :            :         uint16_t mac_num = 0;
    1504                 :            :         uint32_t vid_idx, vid_bit, mac_index;
    1505                 :            :         struct fm10k_hw *hw;
    1506                 :            :         struct fm10k_macvlan_filter_info *macvlan;
    1507                 :          0 :         struct rte_eth_dev_data *data = dev->data;
    1508                 :            : 
    1509                 :          0 :         hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1510                 :            :         macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
    1511                 :            : 
    1512         [ #  # ]:          0 :         if (macvlan->nb_queue_pools > 0) { /* VMDQ mode */
    1513                 :          0 :                 PMD_INIT_LOG(ERR, "Cannot change VLAN filter in VMDQ mode");
    1514                 :          0 :                 return -EINVAL;
    1515                 :            :         }
    1516                 :            : 
    1517         [ #  # ]:          0 :         if (vlan_id > RTE_ETH_VLAN_ID_MAX) {
    1518                 :          0 :                 PMD_INIT_LOG(ERR, "Invalid vlan_id: must be < 4096");
    1519                 :          0 :                 return -EINVAL;
    1520                 :            :         }
    1521                 :            : 
    1522                 :          0 :         vid_idx = FM10K_VFTA_IDX(vlan_id);
    1523                 :          0 :         vid_bit = FM10K_VFTA_BIT(vlan_id);
    1524                 :            :         /* this VLAN ID is already in the VLAN filter table, return SUCCESS */
    1525   [ #  #  #  # ]:          0 :         if (on && (macvlan->vfta[vid_idx] & vid_bit))
    1526                 :            :                 return 0;
    1527                 :            :         /* this VLAN ID is NOT in the VLAN filter table, cannot remove */
    1528   [ #  #  #  # ]:          0 :         if (!on && !(macvlan->vfta[vid_idx] & vid_bit)) {
    1529                 :          0 :                 PMD_INIT_LOG(ERR, "Invalid vlan_id: not existing "
    1530                 :            :                         "in the VLAN filter table");
    1531                 :          0 :                 return -EINVAL;
    1532                 :            :         }
    1533                 :            : 
    1534                 :            :         fm10k_mbx_lock(hw);
    1535                 :          0 :         result = fm10k_update_vlan(hw, vlan_id, 0, on);
    1536                 :            :         fm10k_mbx_unlock(hw);
    1537         [ #  # ]:          0 :         if (result != FM10K_SUCCESS) {
    1538                 :          0 :                 PMD_INIT_LOG(ERR, "VLAN update failed: %d", result);
    1539                 :          0 :                 return -EIO;
    1540                 :            :         }
    1541                 :            : 
    1542                 :          0 :         for (mac_index = 0; (mac_index < FM10K_MAX_MACADDR_NUM) &&
    1543         [ #  # ]:          0 :                         (result == FM10K_SUCCESS); mac_index++) {
    1544         [ #  # ]:          0 :                 if (rte_is_zero_ether_addr(&data->mac_addrs[mac_index]))
    1545                 :          0 :                         continue;
    1546         [ #  # ]:          0 :                 if (mac_num > macvlan->mac_num - 1) {
    1547                 :          0 :                         PMD_INIT_LOG(ERR, "MAC address number "
    1548                 :            :                                         "not match");
    1549                 :          0 :                         break;
    1550                 :            :                 }
    1551                 :            :                 fm10k_mbx_lock(hw);
    1552                 :          0 :                 result = fm10k_update_uc_addr(hw, hw->mac.dglort_map,
    1553                 :          0 :                         data->mac_addrs[mac_index].addr_bytes,
    1554                 :            :                         vlan_id, on, 0);
    1555                 :            :                 fm10k_mbx_unlock(hw);
    1556                 :          0 :                 mac_num++;
    1557                 :            :         }
    1558         [ #  # ]:          0 :         if (result != FM10K_SUCCESS) {
    1559                 :          0 :                 PMD_INIT_LOG(ERR, "MAC address update failed: %d", result);
    1560                 :          0 :                 return -EIO;
    1561                 :            :         }
    1562                 :            : 
    1563         [ #  # ]:          0 :         if (on) {
    1564                 :          0 :                 macvlan->vlan_num++;
    1565                 :          0 :                 macvlan->vfta[vid_idx] |= vid_bit;
    1566                 :            :         } else {
    1567                 :          0 :                 macvlan->vlan_num--;
    1568                 :          0 :                 macvlan->vfta[vid_idx] &= ~vid_bit;
    1569                 :            :         }
    1570                 :            :         return 0;
    1571                 :            : }
    1572                 :            : 
    1573                 :            : static int
    1574                 :          0 : fm10k_vlan_offload_set(struct rte_eth_dev *dev __rte_unused,
    1575                 :            :                        int mask __rte_unused)
    1576                 :            : {
    1577                 :          0 :         return 0;
    1578                 :            : }
    1579                 :            : 
    1580                 :            : /* Add/Remove a MAC address, and update filters to main VSI */
    1581                 :          0 : static void fm10k_MAC_filter_set_main_vsi(struct rte_eth_dev *dev,
    1582                 :            :                 const u8 *mac, bool add, uint32_t pool)
    1583                 :            : {
    1584                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1585                 :            :         struct fm10k_macvlan_filter_info *macvlan;
    1586                 :            :         uint32_t i, j, k;
    1587                 :            : 
    1588                 :            :         macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
    1589                 :            : 
    1590         [ #  # ]:          0 :         if (pool != MAIN_VSI_POOL_NUMBER) {
    1591                 :          0 :                 PMD_DRV_LOG(ERR, "VMDQ not enabled, can't set "
    1592                 :            :                         "mac to pool %u", pool);
    1593                 :          0 :                 return;
    1594                 :            :         }
    1595         [ #  # ]:          0 :         for (i = 0, j = 0; j < FM10K_VFTA_SIZE; j++) {
    1596         [ #  # ]:          0 :                 if (!macvlan->vfta[j])
    1597                 :          0 :                         continue;
    1598         [ #  # ]:          0 :                 for (k = 0; k < FM10K_UINT32_BIT_SIZE; k++) {
    1599         [ #  # ]:          0 :                         if (!(macvlan->vfta[j] & (1 << k)))
    1600                 :          0 :                                 continue;
    1601         [ #  # ]:          0 :                         if (i + 1 > macvlan->vlan_num) {
    1602                 :          0 :                                 PMD_INIT_LOG(ERR, "vlan number not match");
    1603                 :          0 :                                 return;
    1604                 :            :                         }
    1605                 :            :                         fm10k_mbx_lock(hw);
    1606                 :          0 :                         fm10k_update_uc_addr(hw, hw->mac.dglort_map, mac,
    1607                 :          0 :                                 j * FM10K_UINT32_BIT_SIZE + k, add, 0);
    1608                 :            :                         fm10k_mbx_unlock(hw);
    1609                 :            :                         i++;
    1610                 :            :                 }
    1611                 :            :         }
    1612                 :            : }
    1613                 :            : 
    1614                 :            : /* Add/Remove a MAC address, and update filters to VMDQ */
    1615                 :          0 : static void fm10k_MAC_filter_set_vmdq(struct rte_eth_dev *dev,
    1616                 :            :                 const u8 *mac, bool add, uint32_t pool)
    1617                 :            : {
    1618                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1619                 :            :         struct fm10k_macvlan_filter_info *macvlan;
    1620                 :            :         struct rte_eth_vmdq_rx_conf *vmdq_conf;
    1621                 :            :         uint32_t i;
    1622                 :            : 
    1623                 :            :         macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
    1624                 :            :         vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
    1625                 :            : 
    1626         [ #  # ]:          0 :         if (pool > macvlan->nb_queue_pools) {
    1627                 :          0 :                 PMD_DRV_LOG(ERR, "Pool number %u invalid."
    1628                 :            :                         " Max pool is %u",
    1629                 :            :                         pool, macvlan->nb_queue_pools);
    1630                 :          0 :                 return;
    1631                 :            :         }
    1632         [ #  # ]:          0 :         for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
    1633         [ #  # ]:          0 :                 if (!(vmdq_conf->pool_map[i].pools & (1UL << pool)))
    1634                 :          0 :                         continue;
    1635                 :            :                 fm10k_mbx_lock(hw);
    1636                 :          0 :                 fm10k_update_uc_addr(hw, hw->mac.dglort_map + pool, mac,
    1637                 :          0 :                         vmdq_conf->pool_map[i].vlan_id, add, 0);
    1638                 :            :                 fm10k_mbx_unlock(hw);
    1639                 :            :         }
    1640                 :            : }
    1641                 :            : 
    1642                 :            : /* Add/Remove a MAC address, and update filters */
    1643                 :          0 : static void fm10k_MAC_filter_set(struct rte_eth_dev *dev,
    1644                 :            :                 const u8 *mac, bool add, uint32_t pool)
    1645                 :            : {
    1646                 :            :         struct fm10k_macvlan_filter_info *macvlan;
    1647                 :            : 
    1648                 :          0 :         macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
    1649                 :            : 
    1650         [ #  # ]:          0 :         if (macvlan->nb_queue_pools > 0) /* VMDQ mode */
    1651                 :          0 :                 fm10k_MAC_filter_set_vmdq(dev, mac, add, pool);
    1652                 :            :         else
    1653                 :          0 :                 fm10k_MAC_filter_set_main_vsi(dev, mac, add, pool);
    1654                 :            : 
    1655         [ #  # ]:          0 :         if (add)
    1656                 :          0 :                 macvlan->mac_num++;
    1657                 :            :         else
    1658                 :          0 :                 macvlan->mac_num--;
    1659                 :          0 : }
    1660                 :            : 
    1661                 :            : /* Add a MAC address, and update filters */
    1662                 :            : static int
    1663                 :          0 : fm10k_macaddr_add(struct rte_eth_dev *dev,
    1664                 :            :                 struct rte_ether_addr *mac_addr,
    1665                 :            :                 uint32_t index,
    1666                 :            :                 uint32_t pool)
    1667                 :            : {
    1668                 :            :         struct fm10k_macvlan_filter_info *macvlan;
    1669                 :            : 
    1670                 :          0 :         macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
    1671                 :          0 :         fm10k_MAC_filter_set(dev, mac_addr->addr_bytes, TRUE, pool);
    1672                 :          0 :         macvlan->mac_vmdq_id[index] = pool;
    1673                 :          0 :         return 0;
    1674                 :            : }
    1675                 :            : 
    1676                 :            : /* Remove a MAC address, and update filters */
    1677                 :            : static void
    1678                 :          0 : fm10k_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
    1679                 :            : {
    1680                 :          0 :         struct rte_eth_dev_data *data = dev->data;
    1681                 :            :         struct fm10k_macvlan_filter_info *macvlan;
    1682                 :            : 
    1683                 :          0 :         macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
    1684                 :          0 :         fm10k_MAC_filter_set(dev, data->mac_addrs[index].addr_bytes,
    1685                 :          0 :                         FALSE, macvlan->mac_vmdq_id[index]);
    1686                 :          0 :         macvlan->mac_vmdq_id[index] = 0;
    1687                 :          0 : }
    1688                 :            : 
    1689                 :            : static inline int
    1690                 :            : check_nb_desc(uint16_t min, uint16_t max, uint16_t mult, uint16_t request)
    1691                 :            : {
    1692   [ #  #  #  # ]:          0 :         if ((request < min) || (request > max) || ((request % mult) != 0))
    1693                 :            :                 return -1;
    1694                 :            :         else
    1695                 :            :                 return 0;
    1696                 :            : }
    1697                 :            : 
    1698                 :            : 
    1699                 :            : static inline int
    1700                 :            : check_thresh(uint16_t min, uint16_t max, uint16_t div, uint16_t request)
    1701                 :            : {
    1702   [ #  #  #  # ]:          0 :         if ((request < min) || (request > max) || ((div % request) != 0))
    1703                 :            :                 return -1;
    1704                 :            :         else
    1705                 :            :                 return 0;
    1706                 :            : }
    1707                 :            : 
    1708                 :            : static inline int
    1709                 :          0 : handle_rxconf(struct fm10k_rx_queue *q, const struct rte_eth_rxconf *conf)
    1710                 :            : {
    1711                 :            :         uint16_t rx_free_thresh;
    1712                 :            : 
    1713         [ #  # ]:          0 :         if (conf->rx_free_thresh == 0)
    1714                 :            :                 rx_free_thresh = FM10K_RX_FREE_THRESH_DEFAULT(q);
    1715                 :            :         else
    1716                 :            :                 rx_free_thresh = conf->rx_free_thresh;
    1717                 :            : 
    1718                 :            :         /* make sure the requested threshold satisfies the constraints */
    1719                 :          0 :         if (check_thresh(FM10K_RX_FREE_THRESH_MIN(q),
    1720                 :          0 :                         FM10K_RX_FREE_THRESH_MAX(q),
    1721         [ #  # ]:          0 :                         FM10K_RX_FREE_THRESH_DIV(q),
    1722                 :            :                         rx_free_thresh)) {
    1723                 :          0 :                 PMD_INIT_LOG(ERR, "rx_free_thresh (%u) must be "
    1724                 :            :                         "less than or equal to %u, "
    1725                 :            :                         "greater than or equal to %u, "
    1726                 :            :                         "and a divisor of %u",
    1727                 :            :                         rx_free_thresh, FM10K_RX_FREE_THRESH_MAX(q),
    1728                 :            :                         FM10K_RX_FREE_THRESH_MIN(q),
    1729                 :            :                         FM10K_RX_FREE_THRESH_DIV(q));
    1730                 :          0 :                 return -EINVAL;
    1731                 :            :         }
    1732                 :            : 
    1733                 :          0 :         q->alloc_thresh = rx_free_thresh;
    1734                 :          0 :         q->drop_en = conf->rx_drop_en;
    1735                 :          0 :         q->rx_deferred_start = conf->rx_deferred_start;
    1736                 :            : 
    1737                 :          0 :         return 0;
    1738                 :            : }
    1739                 :            : 
    1740                 :            : /*
    1741                 :            :  * Hardware requires specific alignment for Rx packet buffers. At
    1742                 :            :  * least one of the following two conditions must be satisfied.
    1743                 :            :  *  1. Address is 512B aligned
    1744                 :            :  *  2. Address is 8B aligned and buffer does not cross 4K boundary.
    1745                 :            :  *
    1746                 :            :  * As such, the driver may need to adjust the DMA address within the
    1747                 :            :  * buffer by up to 512B.
    1748                 :            :  *
    1749                 :            :  * return 1 if the element size is valid, otherwise return 0.
    1750                 :            :  */
    1751                 :            : static int
    1752                 :            : mempool_element_size_valid(struct rte_mempool *mp)
    1753                 :            : {
    1754                 :            :         uint32_t min_size;
    1755                 :            : 
    1756                 :            :         /* elt_size includes mbuf header and headroom */
    1757                 :          0 :         min_size = mp->elt_size - sizeof(struct rte_mbuf) -
    1758                 :            :                         RTE_PKTMBUF_HEADROOM;
    1759                 :            : 
    1760                 :            :         /* account for up to 512B of alignment */
    1761                 :            :         min_size -= FM10K_RX_DATABUF_ALIGN;
    1762                 :            : 
    1763                 :            :         /* sanity check for overflow */
    1764                 :          0 :         if (min_size > mp->elt_size)
    1765                 :            :                 return 0;
    1766                 :            : 
    1767                 :            :         /* size is valid */
    1768                 :            :         return 1;
    1769                 :            : }
    1770                 :            : 
    1771                 :            : static uint64_t fm10k_get_rx_queue_offloads_capa(struct rte_eth_dev *dev)
    1772                 :            : {
    1773                 :            :         RTE_SET_USED(dev);
    1774                 :            : 
    1775                 :            :         return (uint64_t)(RTE_ETH_RX_OFFLOAD_SCATTER);
    1776                 :            : }
    1777                 :            : 
    1778                 :            : static uint64_t fm10k_get_rx_port_offloads_capa(struct rte_eth_dev *dev)
    1779                 :            : {
    1780                 :            :         RTE_SET_USED(dev);
    1781                 :            : 
    1782                 :            :         return  (uint64_t)(RTE_ETH_RX_OFFLOAD_VLAN_STRIP  |
    1783                 :            :                            RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
    1784                 :            :                            RTE_ETH_RX_OFFLOAD_IPV4_CKSUM  |
    1785                 :            :                            RTE_ETH_RX_OFFLOAD_UDP_CKSUM   |
    1786                 :            :                            RTE_ETH_RX_OFFLOAD_TCP_CKSUM   |
    1787                 :            :                            RTE_ETH_RX_OFFLOAD_RSS_HASH);
    1788                 :            : }
    1789                 :            : 
    1790                 :            : static int
    1791                 :          0 : fm10k_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id,
    1792                 :            :         uint16_t nb_desc, unsigned int socket_id,
    1793                 :            :         const struct rte_eth_rxconf *conf, struct rte_mempool *mp)
    1794                 :            : {
    1795                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1796                 :            :         struct fm10k_dev_info *dev_info =
    1797                 :            :                 FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
    1798                 :            :         struct fm10k_rx_queue *q;
    1799                 :            :         const struct rte_memzone *mz;
    1800                 :            :         uint64_t offloads;
    1801                 :            : 
    1802                 :          0 :         PMD_INIT_FUNC_TRACE();
    1803                 :            : 
    1804         [ #  # ]:          0 :         offloads = conf->offloads | dev->data->dev_conf.rxmode.offloads;
    1805                 :            : 
    1806                 :            :         /* make sure the mempool element size can account for alignment. */
    1807                 :            :         if (!mempool_element_size_valid(mp)) {
    1808                 :          0 :                 PMD_INIT_LOG(ERR, "Error : Mempool element size is too small");
    1809                 :          0 :                 return -EINVAL;
    1810                 :            :         }
    1811                 :            : 
    1812                 :            :         /* make sure a valid number of descriptors have been requested */
    1813         [ #  # ]:          0 :         if (check_nb_desc(FM10K_MIN_RX_DESC, FM10K_MAX_RX_DESC,
    1814                 :            :                                 FM10K_MULT_RX_DESC, nb_desc)) {
    1815                 :          0 :                 PMD_INIT_LOG(ERR, "Number of Rx descriptors (%u) must be "
    1816                 :            :                         "less than or equal to %"PRIu32", "
    1817                 :            :                         "greater than or equal to %u, "
    1818                 :            :                         "and a multiple of %u",
    1819                 :            :                         nb_desc, (uint32_t)FM10K_MAX_RX_DESC, FM10K_MIN_RX_DESC,
    1820                 :            :                         FM10K_MULT_RX_DESC);
    1821                 :          0 :                 return -EINVAL;
    1822                 :            :         }
    1823                 :            : 
    1824                 :            :         /*
    1825                 :            :          * if this queue existed already, free the associated memory. The
    1826                 :            :          * queue cannot be reused in case we need to allocate memory on
    1827                 :            :          * different socket than was previously used.
    1828                 :            :          */
    1829         [ #  # ]:          0 :         if (dev->data->rx_queues[queue_id] != NULL) {
    1830                 :          0 :                 rx_queue_free(dev->data->rx_queues[queue_id]);
    1831                 :          0 :                 dev->data->rx_queues[queue_id] = NULL;
    1832                 :            :         }
    1833                 :            : 
    1834                 :            :         /* allocate memory for the queue structure */
    1835                 :          0 :         q = rte_zmalloc_socket("fm10k", sizeof(*q), RTE_CACHE_LINE_SIZE,
    1836                 :            :                                 socket_id);
    1837         [ #  # ]:          0 :         if (q == NULL) {
    1838                 :          0 :                 PMD_INIT_LOG(ERR, "Cannot allocate queue structure");
    1839                 :          0 :                 return -ENOMEM;
    1840                 :            :         }
    1841                 :            : 
    1842                 :            :         /* setup queue */
    1843                 :          0 :         q->mp = mp;
    1844                 :          0 :         q->nb_desc = nb_desc;
    1845                 :          0 :         q->nb_fake_desc = FM10K_MULT_RX_DESC;
    1846                 :          0 :         q->port_id = dev->data->port_id;
    1847                 :          0 :         q->queue_id = queue_id;
    1848                 :          0 :         q->tail_ptr = (volatile uint32_t *)
    1849                 :          0 :                 &((uint32_t *)hw->hw_addr)[FM10K_RDT(queue_id)];
    1850                 :          0 :         q->offloads = offloads;
    1851         [ #  # ]:          0 :         if (handle_rxconf(q, conf)) {
    1852                 :          0 :                 rte_free(q);
    1853                 :          0 :                 return -EINVAL;
    1854                 :            :         }
    1855                 :            :         /* allocate memory for the software ring */
    1856                 :          0 :         q->sw_ring = rte_zmalloc_socket("fm10k sw ring",
    1857                 :          0 :                         (nb_desc + q->nb_fake_desc) * sizeof(struct rte_mbuf *),
    1858                 :            :                         RTE_CACHE_LINE_SIZE, socket_id);
    1859         [ #  # ]:          0 :         if (q->sw_ring == NULL) {
    1860                 :          0 :                 PMD_INIT_LOG(ERR, "Cannot allocate software ring");
    1861                 :          0 :                 rte_free(q);
    1862                 :          0 :                 return -ENOMEM;
    1863                 :            :         }
    1864                 :            : 
    1865                 :            :         /*
    1866                 :            :          * allocate memory for the hardware descriptor ring. A memzone large
    1867                 :            :          * enough to hold the maximum ring size is requested to allow for
    1868                 :            :          * resizing in later calls to the queue setup function.
    1869                 :            :          */
    1870                 :          0 :         mz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_id,
    1871                 :            :                                       FM10K_MAX_RX_RING_SZ, FM10K_ALIGN_RX_DESC,
    1872                 :            :                                       socket_id);
    1873         [ #  # ]:          0 :         if (mz == NULL) {
    1874                 :          0 :                 PMD_INIT_LOG(ERR, "Cannot allocate hardware ring");
    1875                 :          0 :                 rte_free(q->sw_ring);
    1876                 :          0 :                 rte_free(q);
    1877                 :          0 :                 return -ENOMEM;
    1878                 :            :         }
    1879                 :          0 :         q->hw_ring = mz->addr;
    1880                 :          0 :         q->hw_ring_phys_addr = mz->iova;
    1881                 :            : 
    1882                 :            :         /* Check if number of descs satisfied Vector requirement */
    1883         [ #  # ]:          0 :         if (!rte_is_power_of_2(nb_desc)) {
    1884                 :          0 :                 PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Vector Rx "
    1885                 :            :                                     "preconditions - canceling the feature for "
    1886                 :            :                                     "the whole port[%d]",
    1887                 :            :                              q->queue_id, q->port_id);
    1888                 :          0 :                 dev_info->rx_vec_allowed = false;
    1889                 :            :         } else
    1890                 :          0 :                 fm10k_rxq_vec_setup(q);
    1891                 :            : 
    1892                 :          0 :         dev->data->rx_queues[queue_id] = q;
    1893                 :          0 :         return 0;
    1894                 :            : }
    1895                 :            : 
    1896                 :            : static void
    1897                 :          0 : fm10k_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
    1898                 :            : {
    1899                 :          0 :         PMD_INIT_FUNC_TRACE();
    1900                 :            : 
    1901                 :          0 :         rx_queue_free(dev->data->rx_queues[qid]);
    1902                 :          0 : }
    1903                 :            : 
    1904                 :            : static inline int
    1905                 :          0 : handle_txconf(struct fm10k_tx_queue *q, const struct rte_eth_txconf *conf)
    1906                 :            : {
    1907                 :            :         uint16_t tx_free_thresh;
    1908                 :            :         uint16_t tx_rs_thresh;
    1909                 :            : 
    1910                 :            :         /* constraint MACROs require that tx_free_thresh is configured
    1911                 :            :          * before tx_rs_thresh */
    1912         [ #  # ]:          0 :         if (conf->tx_free_thresh == 0)
    1913                 :            :                 tx_free_thresh = FM10K_TX_FREE_THRESH_DEFAULT(q);
    1914                 :            :         else
    1915                 :            :                 tx_free_thresh = conf->tx_free_thresh;
    1916                 :            : 
    1917                 :            :         /* make sure the requested threshold satisfies the constraints */
    1918                 :          0 :         if (check_thresh(FM10K_TX_FREE_THRESH_MIN(q),
    1919         [ #  # ]:          0 :                         FM10K_TX_FREE_THRESH_MAX(q),
    1920                 :            :                         FM10K_TX_FREE_THRESH_DIV(q),
    1921                 :            :                         tx_free_thresh)) {
    1922                 :          0 :                 PMD_INIT_LOG(ERR, "tx_free_thresh (%u) must be "
    1923                 :            :                         "less than or equal to %u, "
    1924                 :            :                         "greater than or equal to %u, "
    1925                 :            :                         "and a divisor of %u",
    1926                 :            :                         tx_free_thresh, FM10K_TX_FREE_THRESH_MAX(q),
    1927                 :            :                         FM10K_TX_FREE_THRESH_MIN(q),
    1928                 :            :                         FM10K_TX_FREE_THRESH_DIV(q));
    1929                 :          0 :                 return -EINVAL;
    1930                 :            :         }
    1931                 :            : 
    1932                 :          0 :         q->free_thresh = tx_free_thresh;
    1933                 :            : 
    1934         [ #  # ]:          0 :         if (conf->tx_rs_thresh == 0)
    1935                 :            :                 tx_rs_thresh = FM10K_TX_RS_THRESH_DEFAULT(q);
    1936                 :            :         else
    1937                 :            :                 tx_rs_thresh = conf->tx_rs_thresh;
    1938                 :            : 
    1939                 :          0 :         q->tx_deferred_start = conf->tx_deferred_start;
    1940                 :            : 
    1941                 :            :         /* make sure the requested threshold satisfies the constraints */
    1942                 :          0 :         if (check_thresh(FM10K_TX_RS_THRESH_MIN(q),
    1943         [ #  # ]:          0 :                         FM10K_TX_RS_THRESH_MAX(q),
    1944                 :            :                         FM10K_TX_RS_THRESH_DIV(q),
    1945                 :            :                         tx_rs_thresh)) {
    1946                 :          0 :                 PMD_INIT_LOG(ERR, "tx_rs_thresh (%u) must be "
    1947                 :            :                         "less than or equal to %u, "
    1948                 :            :                         "greater than or equal to %u, "
    1949                 :            :                         "and a divisor of %u",
    1950                 :            :                         tx_rs_thresh, FM10K_TX_RS_THRESH_MAX(q),
    1951                 :            :                         FM10K_TX_RS_THRESH_MIN(q),
    1952                 :            :                         FM10K_TX_RS_THRESH_DIV(q));
    1953                 :          0 :                 return -EINVAL;
    1954                 :            :         }
    1955                 :            : 
    1956                 :          0 :         q->rs_thresh = tx_rs_thresh;
    1957                 :            : 
    1958                 :          0 :         return 0;
    1959                 :            : }
    1960                 :            : 
    1961                 :            : static uint64_t fm10k_get_tx_queue_offloads_capa(struct rte_eth_dev *dev)
    1962                 :            : {
    1963                 :            :         RTE_SET_USED(dev);
    1964                 :            : 
    1965                 :            :         return 0;
    1966                 :            : }
    1967                 :            : 
    1968                 :            : static uint64_t fm10k_get_tx_port_offloads_capa(struct rte_eth_dev *dev)
    1969                 :            : {
    1970                 :            :         RTE_SET_USED(dev);
    1971                 :            : 
    1972                 :            :         return (uint64_t)(RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
    1973                 :            :                           RTE_ETH_TX_OFFLOAD_MULTI_SEGS  |
    1974                 :            :                           RTE_ETH_TX_OFFLOAD_IPV4_CKSUM  |
    1975                 :            :                           RTE_ETH_TX_OFFLOAD_UDP_CKSUM   |
    1976                 :            :                           RTE_ETH_TX_OFFLOAD_TCP_CKSUM   |
    1977                 :            :                           RTE_ETH_TX_OFFLOAD_TCP_TSO);
    1978                 :            : }
    1979                 :            : 
    1980                 :            : static int
    1981                 :          0 : fm10k_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id,
    1982                 :            :         uint16_t nb_desc, unsigned int socket_id,
    1983                 :            :         const struct rte_eth_txconf *conf)
    1984                 :            : {
    1985                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1986                 :            :         struct fm10k_tx_queue *q;
    1987                 :            :         const struct rte_memzone *mz;
    1988                 :            :         uint64_t offloads;
    1989                 :            : 
    1990                 :          0 :         PMD_INIT_FUNC_TRACE();
    1991                 :            : 
    1992                 :          0 :         offloads = conf->offloads | dev->data->dev_conf.txmode.offloads;
    1993                 :            : 
    1994                 :            :         /* make sure a valid number of descriptors have been requested */
    1995         [ #  # ]:          0 :         if (check_nb_desc(FM10K_MIN_TX_DESC, FM10K_MAX_TX_DESC,
    1996                 :            :                                 FM10K_MULT_TX_DESC, nb_desc)) {
    1997                 :          0 :                 PMD_INIT_LOG(ERR, "Number of Tx descriptors (%u) must be "
    1998                 :            :                         "less than or equal to %"PRIu32", "
    1999                 :            :                         "greater than or equal to %u, "
    2000                 :            :                         "and a multiple of %u",
    2001                 :            :                         nb_desc, (uint32_t)FM10K_MAX_TX_DESC, FM10K_MIN_TX_DESC,
    2002                 :            :                         FM10K_MULT_TX_DESC);
    2003                 :          0 :                 return -EINVAL;
    2004                 :            :         }
    2005                 :            : 
    2006                 :            :         /*
    2007                 :            :          * if this queue existed already, free the associated memory. The
    2008                 :            :          * queue cannot be reused in case we need to allocate memory on
    2009                 :            :          * different socket than was previously used.
    2010                 :            :          */
    2011         [ #  # ]:          0 :         if (dev->data->tx_queues[queue_id] != NULL) {
    2012                 :            :                 struct fm10k_tx_queue *txq = dev->data->tx_queues[queue_id];
    2013                 :            : 
    2014                 :          0 :                 tx_queue_free(txq);
    2015                 :          0 :                 dev->data->tx_queues[queue_id] = NULL;
    2016                 :            :         }
    2017                 :            : 
    2018                 :            :         /* allocate memory for the queue structure */
    2019                 :          0 :         q = rte_zmalloc_socket("fm10k", sizeof(*q), RTE_CACHE_LINE_SIZE,
    2020                 :            :                                 socket_id);
    2021         [ #  # ]:          0 :         if (q == NULL) {
    2022                 :          0 :                 PMD_INIT_LOG(ERR, "Cannot allocate queue structure");
    2023                 :          0 :                 return -ENOMEM;
    2024                 :            :         }
    2025                 :            : 
    2026                 :            :         /* setup queue */
    2027                 :          0 :         q->nb_desc = nb_desc;
    2028                 :          0 :         q->port_id = dev->data->port_id;
    2029                 :          0 :         q->queue_id = queue_id;
    2030                 :          0 :         q->offloads = offloads;
    2031                 :          0 :         q->ops = &def_txq_ops;
    2032                 :          0 :         q->tail_ptr = (volatile uint32_t *)
    2033                 :          0 :                 &((uint32_t *)hw->hw_addr)[FM10K_TDT(queue_id)];
    2034         [ #  # ]:          0 :         if (handle_txconf(q, conf)) {
    2035                 :          0 :                 rte_free(q);
    2036                 :          0 :                 return -EINVAL;
    2037                 :            :         }
    2038                 :            : 
    2039                 :            :         /* allocate memory for the software ring */
    2040                 :          0 :         q->sw_ring = rte_zmalloc_socket("fm10k sw ring",
    2041                 :            :                                         nb_desc * sizeof(struct rte_mbuf *),
    2042                 :            :                                         RTE_CACHE_LINE_SIZE, socket_id);
    2043         [ #  # ]:          0 :         if (q->sw_ring == NULL) {
    2044                 :          0 :                 PMD_INIT_LOG(ERR, "Cannot allocate software ring");
    2045                 :          0 :                 rte_free(q);
    2046                 :          0 :                 return -ENOMEM;
    2047                 :            :         }
    2048                 :            : 
    2049                 :            :         /*
    2050                 :            :          * allocate memory for the hardware descriptor ring. A memzone large
    2051                 :            :          * enough to hold the maximum ring size is requested to allow for
    2052                 :            :          * resizing in later calls to the queue setup function.
    2053                 :            :          */
    2054                 :          0 :         mz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_id,
    2055                 :            :                                       FM10K_MAX_TX_RING_SZ, FM10K_ALIGN_TX_DESC,
    2056                 :            :                                       socket_id);
    2057         [ #  # ]:          0 :         if (mz == NULL) {
    2058                 :          0 :                 PMD_INIT_LOG(ERR, "Cannot allocate hardware ring");
    2059                 :          0 :                 rte_free(q->sw_ring);
    2060                 :          0 :                 rte_free(q);
    2061                 :          0 :                 return -ENOMEM;
    2062                 :            :         }
    2063                 :          0 :         q->hw_ring = mz->addr;
    2064                 :          0 :         q->hw_ring_phys_addr = mz->iova;
    2065                 :            : 
    2066                 :            :         /*
    2067                 :            :          * allocate memory for the RS bit tracker. Enough slots to hold the
    2068                 :            :          * descriptor index for each RS bit needing to be set are required.
    2069                 :            :          */
    2070                 :          0 :         q->rs_tracker.list = rte_zmalloc_socket("fm10k rs tracker",
    2071                 :          0 :                                 ((nb_desc + 1) / q->rs_thresh) *
    2072                 :            :                                 sizeof(uint16_t),
    2073                 :            :                                 RTE_CACHE_LINE_SIZE, socket_id);
    2074         [ #  # ]:          0 :         if (q->rs_tracker.list == NULL) {
    2075                 :          0 :                 PMD_INIT_LOG(ERR, "Cannot allocate RS bit tracker");
    2076                 :          0 :                 rte_free(q->sw_ring);
    2077                 :          0 :                 rte_free(q);
    2078                 :          0 :                 return -ENOMEM;
    2079                 :            :         }
    2080                 :            : 
    2081                 :          0 :         dev->data->tx_queues[queue_id] = q;
    2082                 :          0 :         return 0;
    2083                 :            : }
    2084                 :            : 
    2085                 :            : static void
    2086                 :          0 : fm10k_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
    2087                 :            : {
    2088                 :          0 :         struct fm10k_tx_queue *q = dev->data->tx_queues[qid];
    2089                 :          0 :         PMD_INIT_FUNC_TRACE();
    2090                 :            : 
    2091                 :          0 :         tx_queue_free(q);
    2092                 :          0 : }
    2093                 :            : 
    2094                 :            : static int
    2095                 :          0 : fm10k_reta_update(struct rte_eth_dev *dev,
    2096                 :            :                         struct rte_eth_rss_reta_entry64 *reta_conf,
    2097                 :            :                         uint16_t reta_size)
    2098                 :            : {
    2099                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2100                 :            :         uint16_t i, j, idx, shift;
    2101                 :            :         uint8_t mask;
    2102                 :            :         uint32_t reta;
    2103                 :            : 
    2104                 :          0 :         PMD_INIT_FUNC_TRACE();
    2105                 :            : 
    2106         [ #  # ]:          0 :         if (reta_size > FM10K_MAX_RSS_INDICES) {
    2107                 :          0 :                 PMD_INIT_LOG(ERR, "The size of hash lookup table configured "
    2108                 :            :                         "(%d) doesn't match the number hardware can supported "
    2109                 :            :                         "(%d)", reta_size, FM10K_MAX_RSS_INDICES);
    2110                 :          0 :                 return -EINVAL;
    2111                 :            :         }
    2112                 :            : 
    2113                 :            :         /*
    2114                 :            :          * Update Redirection Table RETA[n], n=0..31. The redirection table has
    2115                 :            :          * 128-entries in 32 registers
    2116                 :            :          */
    2117         [ #  # ]:          0 :         for (i = 0; i < FM10K_MAX_RSS_INDICES; i += CHARS_PER_UINT32) {
    2118                 :          0 :                 idx = i / RTE_ETH_RETA_GROUP_SIZE;
    2119                 :          0 :                 shift = i % RTE_ETH_RETA_GROUP_SIZE;
    2120                 :          0 :                 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
    2121                 :            :                                 BIT_MASK_PER_UINT32);
    2122         [ #  # ]:          0 :                 if (mask == 0)
    2123                 :          0 :                         continue;
    2124                 :            : 
    2125                 :            :                 reta = 0;
    2126         [ #  # ]:          0 :                 if (mask != BIT_MASK_PER_UINT32)
    2127                 :          0 :                         reta = FM10K_READ_REG(hw, FM10K_RETA(0, i >> 2));
    2128                 :            : 
    2129         [ #  # ]:          0 :                 for (j = 0; j < CHARS_PER_UINT32; j++) {
    2130         [ #  # ]:          0 :                         if (mask & (0x1 << j)) {
    2131         [ #  # ]:          0 :                                 if (mask != 0xF)
    2132                 :          0 :                                         reta &= ~(UINT8_MAX << CHAR_BIT * j);
    2133                 :          0 :                                 reta |= reta_conf[idx].reta[shift + j] <<
    2134                 :          0 :                                                 (CHAR_BIT * j);
    2135                 :            :                         }
    2136                 :            :                 }
    2137                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_RETA(0, i >> 2), reta);
    2138                 :            :         }
    2139                 :            : 
    2140                 :            :         return 0;
    2141                 :            : }
    2142                 :            : 
    2143                 :            : static int
    2144                 :          0 : fm10k_reta_query(struct rte_eth_dev *dev,
    2145                 :            :                         struct rte_eth_rss_reta_entry64 *reta_conf,
    2146                 :            :                         uint16_t reta_size)
    2147                 :            : {
    2148                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2149                 :            :         uint16_t i, j, idx, shift;
    2150                 :            :         uint8_t mask;
    2151                 :            :         uint32_t reta;
    2152                 :            : 
    2153                 :          0 :         PMD_INIT_FUNC_TRACE();
    2154                 :            : 
    2155         [ #  # ]:          0 :         if (reta_size < FM10K_MAX_RSS_INDICES) {
    2156                 :          0 :                 PMD_INIT_LOG(ERR, "The size of hash lookup table configured "
    2157                 :            :                         "(%d) doesn't match the number hardware can supported "
    2158                 :            :                         "(%d)", reta_size, FM10K_MAX_RSS_INDICES);
    2159                 :          0 :                 return -EINVAL;
    2160                 :            :         }
    2161                 :            : 
    2162                 :            :         /*
    2163                 :            :          * Read Redirection Table RETA[n], n=0..31. The redirection table has
    2164                 :            :          * 128-entries in 32 registers
    2165                 :            :          */
    2166         [ #  # ]:          0 :         for (i = 0; i < FM10K_MAX_RSS_INDICES; i += CHARS_PER_UINT32) {
    2167                 :          0 :                 idx = i / RTE_ETH_RETA_GROUP_SIZE;
    2168                 :          0 :                 shift = i % RTE_ETH_RETA_GROUP_SIZE;
    2169                 :          0 :                 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
    2170                 :            :                                 BIT_MASK_PER_UINT32);
    2171         [ #  # ]:          0 :                 if (mask == 0)
    2172                 :          0 :                         continue;
    2173                 :            : 
    2174                 :          0 :                 reta = FM10K_READ_REG(hw, FM10K_RETA(0, i >> 2));
    2175         [ #  # ]:          0 :                 for (j = 0; j < CHARS_PER_UINT32; j++) {
    2176         [ #  # ]:          0 :                         if (mask & (0x1 << j))
    2177                 :          0 :                                 reta_conf[idx].reta[shift + j] = ((reta >>
    2178                 :          0 :                                         CHAR_BIT * j) & UINT8_MAX);
    2179                 :            :                 }
    2180                 :            :         }
    2181                 :            : 
    2182                 :            :         return 0;
    2183                 :            : }
    2184                 :            : 
    2185                 :            : static int
    2186                 :          0 : fm10k_rss_hash_update(struct rte_eth_dev *dev,
    2187                 :            :         struct rte_eth_rss_conf *rss_conf)
    2188                 :            : {
    2189                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2190                 :          0 :         uint32_t *key = (uint32_t *)rss_conf->rss_key;
    2191                 :            :         uint32_t mrqc;
    2192                 :          0 :         uint64_t hf = rss_conf->rss_hf;
    2193                 :            :         int i;
    2194                 :            : 
    2195                 :          0 :         PMD_INIT_FUNC_TRACE();
    2196                 :            : 
    2197   [ #  #  #  # ]:          0 :         if (key && (rss_conf->rss_key_len < FM10K_RSSRK_SIZE *
    2198                 :            :                                 FM10K_RSSRK_ENTRIES_PER_REG))
    2199                 :            :                 return -EINVAL;
    2200                 :            : 
    2201         [ #  # ]:          0 :         if (hf == 0)
    2202                 :            :                 return -EINVAL;
    2203                 :            : 
    2204                 :            :         mrqc = 0;
    2205                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_IPV4)              ? FM10K_MRQC_IPV4     : 0;
    2206                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_IPV6)              ? FM10K_MRQC_IPV6     : 0;
    2207                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_IPV6_EX)           ? FM10K_MRQC_IPV6     : 0;
    2208                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)  ? FM10K_MRQC_TCP_IPV4 : 0;
    2209                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP)  ? FM10K_MRQC_TCP_IPV6 : 0;
    2210                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_IPV6_TCP_EX)       ? FM10K_MRQC_TCP_IPV6 : 0;
    2211                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)  ? FM10K_MRQC_UDP_IPV4 : 0;
    2212                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP)  ? FM10K_MRQC_UDP_IPV6 : 0;
    2213                 :          0 :         mrqc |= (hf & RTE_ETH_RSS_IPV6_UDP_EX)       ? FM10K_MRQC_UDP_IPV6 : 0;
    2214                 :            : 
    2215                 :            :         /* If the mapping doesn't fit any supported, return */
    2216         [ #  # ]:          0 :         if (mrqc == 0)
    2217                 :            :                 return -EINVAL;
    2218                 :            : 
    2219         [ #  # ]:          0 :         if (key != NULL)
    2220         [ #  # ]:          0 :                 for (i = 0; i < FM10K_RSSRK_SIZE; ++i)
    2221                 :          0 :                         FM10K_WRITE_REG(hw, FM10K_RSSRK(0, i), key[i]);
    2222                 :            : 
    2223                 :          0 :         FM10K_WRITE_REG(hw, FM10K_MRQC(0), mrqc);
    2224                 :            : 
    2225                 :          0 :         return 0;
    2226                 :            : }
    2227                 :            : 
    2228                 :            : static int
    2229                 :          0 : fm10k_rss_hash_conf_get(struct rte_eth_dev *dev,
    2230                 :            :         struct rte_eth_rss_conf *rss_conf)
    2231                 :            : {
    2232                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2233                 :          0 :         uint32_t *key = (uint32_t *)rss_conf->rss_key;
    2234                 :            :         uint32_t mrqc;
    2235                 :            :         uint64_t hf;
    2236                 :            :         int i;
    2237                 :            : 
    2238                 :          0 :         PMD_INIT_FUNC_TRACE();
    2239                 :            : 
    2240   [ #  #  #  # ]:          0 :         if (key && (rss_conf->rss_key_len < FM10K_RSSRK_SIZE *
    2241                 :            :                                 FM10K_RSSRK_ENTRIES_PER_REG))
    2242                 :            :                 return -EINVAL;
    2243                 :            : 
    2244         [ #  # ]:          0 :         if (key != NULL)
    2245         [ #  # ]:          0 :                 for (i = 0; i < FM10K_RSSRK_SIZE; ++i)
    2246                 :          0 :                         key[i] = FM10K_READ_REG(hw, FM10K_RSSRK(0, i));
    2247                 :            : 
    2248                 :          0 :         mrqc = FM10K_READ_REG(hw, FM10K_MRQC(0));
    2249                 :            :         hf = 0;
    2250                 :          0 :         hf |= (mrqc & FM10K_MRQC_IPV4)     ? RTE_ETH_RSS_IPV4              : 0;
    2251                 :          0 :         hf |= (mrqc & FM10K_MRQC_IPV6)     ? RTE_ETH_RSS_IPV6              : 0;
    2252                 :          0 :         hf |= (mrqc & FM10K_MRQC_IPV6)     ? RTE_ETH_RSS_IPV6_EX           : 0;
    2253                 :          0 :         hf |= (mrqc & FM10K_MRQC_TCP_IPV4) ? RTE_ETH_RSS_NONFRAG_IPV4_TCP  : 0;
    2254                 :          0 :         hf |= (mrqc & FM10K_MRQC_TCP_IPV6) ? RTE_ETH_RSS_NONFRAG_IPV6_TCP  : 0;
    2255                 :          0 :         hf |= (mrqc & FM10K_MRQC_TCP_IPV6) ? RTE_ETH_RSS_IPV6_TCP_EX       : 0;
    2256                 :          0 :         hf |= (mrqc & FM10K_MRQC_UDP_IPV4) ? RTE_ETH_RSS_NONFRAG_IPV4_UDP  : 0;
    2257                 :          0 :         hf |= (mrqc & FM10K_MRQC_UDP_IPV6) ? RTE_ETH_RSS_NONFRAG_IPV6_UDP  : 0;
    2258                 :          0 :         hf |= (mrqc & FM10K_MRQC_UDP_IPV6) ? RTE_ETH_RSS_IPV6_UDP_EX       : 0;
    2259                 :            : 
    2260                 :          0 :         rss_conf->rss_hf = hf;
    2261                 :            : 
    2262                 :          0 :         return 0;
    2263                 :            : }
    2264                 :            : 
    2265                 :            : static void
    2266                 :          0 : fm10k_dev_enable_intr_pf(struct rte_eth_dev *dev)
    2267                 :            : {
    2268                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2269                 :            :         uint32_t int_map = FM10K_INT_MAP_IMMEDIATE;
    2270                 :            : 
    2271                 :            :         /* Bind all local non-queue interrupt to vector 0 */
    2272                 :            :         int_map |= FM10K_MISC_VEC_ID;
    2273                 :            : 
    2274                 :          0 :         FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_mailbox), int_map);
    2275                 :          0 :         FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_pcie_fault), int_map);
    2276                 :          0 :         FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_up_down), int_map);
    2277                 :          0 :         FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_event), int_map);
    2278                 :          0 :         FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_sram), int_map);
    2279                 :          0 :         FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_vflr), int_map);
    2280                 :            : 
    2281                 :            :         /* Enable misc causes */
    2282                 :          0 :         FM10K_WRITE_REG(hw, FM10K_EIMR, FM10K_EIMR_ENABLE(PCA_FAULT) |
    2283                 :            :                                 FM10K_EIMR_ENABLE(THI_FAULT) |
    2284                 :            :                                 FM10K_EIMR_ENABLE(FUM_FAULT) |
    2285                 :            :                                 FM10K_EIMR_ENABLE(MAILBOX) |
    2286                 :            :                                 FM10K_EIMR_ENABLE(SWITCHREADY) |
    2287                 :            :                                 FM10K_EIMR_ENABLE(SWITCHNOTREADY) |
    2288                 :            :                                 FM10K_EIMR_ENABLE(SRAMERROR) |
    2289                 :            :                                 FM10K_EIMR_ENABLE(VFLR));
    2290                 :            : 
    2291                 :            :         /* Enable ITR 0 */
    2292                 :          0 :         FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_AUTOMASK |
    2293                 :            :                                         FM10K_ITR_MASK_CLEAR);
    2294                 :          0 :         FM10K_WRITE_FLUSH(hw);
    2295                 :          0 : }
    2296                 :            : 
    2297                 :            : static void
    2298                 :          0 : fm10k_dev_disable_intr_pf(struct rte_eth_dev *dev)
    2299                 :            : {
    2300                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2301                 :            :         uint32_t int_map = FM10K_INT_MAP_DISABLE;
    2302                 :            : 
    2303                 :            :         int_map |= FM10K_MISC_VEC_ID;
    2304                 :            : 
    2305                 :          0 :         FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_mailbox), int_map);
    2306                 :          0 :         FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_pcie_fault), int_map);
    2307                 :          0 :         FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_up_down), int_map);
    2308                 :          0 :         FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_event), int_map);
    2309                 :          0 :         FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_sram), int_map);
    2310                 :          0 :         FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_vflr), int_map);
    2311                 :            : 
    2312                 :            :         /* Disable misc causes */
    2313                 :          0 :         FM10K_WRITE_REG(hw, FM10K_EIMR, FM10K_EIMR_DISABLE(PCA_FAULT) |
    2314                 :            :                                 FM10K_EIMR_DISABLE(THI_FAULT) |
    2315                 :            :                                 FM10K_EIMR_DISABLE(FUM_FAULT) |
    2316                 :            :                                 FM10K_EIMR_DISABLE(MAILBOX) |
    2317                 :            :                                 FM10K_EIMR_DISABLE(SWITCHREADY) |
    2318                 :            :                                 FM10K_EIMR_DISABLE(SWITCHNOTREADY) |
    2319                 :            :                                 FM10K_EIMR_DISABLE(SRAMERROR) |
    2320                 :            :                                 FM10K_EIMR_DISABLE(VFLR));
    2321                 :            : 
    2322                 :            :         /* Disable ITR 0 */
    2323                 :          0 :         FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_MASK_SET);
    2324                 :          0 :         FM10K_WRITE_FLUSH(hw);
    2325                 :          0 : }
    2326                 :            : 
    2327                 :            : static void
    2328                 :            : fm10k_dev_enable_intr_vf(struct rte_eth_dev *dev)
    2329                 :            : {
    2330                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2331                 :            :         uint32_t int_map = FM10K_INT_MAP_IMMEDIATE;
    2332                 :            : 
    2333                 :            :         /* Bind all local non-queue interrupt to vector 0 */
    2334                 :            :         int_map |= FM10K_MISC_VEC_ID;
    2335                 :            : 
    2336                 :            :         /* Only INT 0 available, other 15 are reserved. */
    2337                 :          0 :         FM10K_WRITE_REG(hw, FM10K_VFINT_MAP, int_map);
    2338                 :            : 
    2339                 :            :         /* Enable ITR 0 */
    2340                 :          0 :         FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_AUTOMASK |
    2341                 :            :                                         FM10K_ITR_MASK_CLEAR);
    2342                 :          0 :         FM10K_WRITE_FLUSH(hw);
    2343                 :          0 : }
    2344                 :            : 
    2345                 :            : static void
    2346                 :            : fm10k_dev_disable_intr_vf(struct rte_eth_dev *dev)
    2347                 :            : {
    2348                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2349                 :            :         uint32_t int_map = FM10K_INT_MAP_DISABLE;
    2350                 :            : 
    2351                 :            :         int_map |= FM10K_MISC_VEC_ID;
    2352                 :            : 
    2353                 :            :         /* Only INT 0 available, other 15 are reserved. */
    2354                 :          0 :         FM10K_WRITE_REG(hw, FM10K_VFINT_MAP, int_map);
    2355                 :            : 
    2356                 :            :         /* Disable ITR 0 */
    2357                 :          0 :         FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_MASK_SET);
    2358                 :          0 :         FM10K_WRITE_FLUSH(hw);
    2359                 :          0 : }
    2360                 :            : 
    2361                 :            : static int
    2362                 :          0 : fm10k_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
    2363                 :            : {
    2364                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2365                 :          0 :         struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
    2366                 :            : 
    2367                 :            :         /* Enable ITR */
    2368         [ #  # ]:          0 :         if (hw->mac.type == fm10k_mac_pf)
    2369                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, queue_id)),
    2370                 :            :                         FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR);
    2371                 :            :         else
    2372                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, queue_id)),
    2373                 :            :                         FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR);
    2374                 :          0 :         rte_intr_ack(pdev->intr_handle);
    2375                 :          0 :         return 0;
    2376                 :            : }
    2377                 :            : 
    2378                 :            : static int
    2379                 :          0 : fm10k_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
    2380                 :            : {
    2381                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2382                 :          0 :         struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
    2383                 :            : 
    2384                 :            :         /* Disable ITR */
    2385         [ #  # ]:          0 :         if (hw->mac.type == fm10k_mac_pf)
    2386                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, queue_id)),
    2387                 :            :                         FM10K_ITR_MASK_SET);
    2388                 :            :         else
    2389                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, queue_id)),
    2390                 :            :                         FM10K_ITR_MASK_SET);
    2391                 :          0 :         return 0;
    2392                 :            : }
    2393                 :            : 
    2394                 :            : static int
    2395                 :          0 : fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
    2396                 :            : {
    2397                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2398                 :          0 :         struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
    2399                 :          0 :         struct rte_intr_handle *intr_handle = pdev->intr_handle;
    2400                 :            :         uint32_t intr_vector, vec;
    2401                 :            :         uint16_t queue_id;
    2402                 :            :         int result = 0;
    2403                 :            : 
    2404                 :            :         /* fm10k needs one separate interrupt for mailbox,
    2405                 :            :          * so only drivers which support multiple interrupt vectors
    2406                 :            :          * e.g. vfio-pci can work for fm10k interrupt mode
    2407                 :            :          */
    2408         [ #  # ]:          0 :         if (!rte_intr_cap_multiple(intr_handle) ||
    2409         [ #  # ]:          0 :                         dev->data->dev_conf.intr_conf.rxq == 0)
    2410                 :            :                 return result;
    2411                 :            : 
    2412                 :          0 :         intr_vector = dev->data->nb_rx_queues;
    2413                 :            : 
    2414                 :            :         /* disable interrupt first */
    2415                 :          0 :         rte_intr_disable(intr_handle);
    2416         [ #  # ]:          0 :         if (hw->mac.type == fm10k_mac_pf)
    2417                 :          0 :                 fm10k_dev_disable_intr_pf(dev);
    2418                 :            :         else
    2419                 :            :                 fm10k_dev_disable_intr_vf(dev);
    2420                 :            : 
    2421         [ #  # ]:          0 :         if (rte_intr_efd_enable(intr_handle, intr_vector)) {
    2422                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to init event fd");
    2423                 :            :                 result = -EIO;
    2424                 :            :         }
    2425                 :            : 
    2426   [ #  #  #  # ]:          0 :         if (rte_intr_dp_is_en(intr_handle) && !result) {
    2427         [ #  # ]:          0 :                 if (!rte_intr_vec_list_alloc(intr_handle, "intr_vec",
    2428                 :          0 :                                                    dev->data->nb_rx_queues)) {
    2429                 :            :                         for (queue_id = 0, vec = FM10K_RX_VEC_START;
    2430         [ #  # ]:          0 :                                         queue_id < dev->data->nb_rx_queues;
    2431                 :          0 :                                         queue_id++) {
    2432                 :          0 :                                 rte_intr_vec_list_index_set(intr_handle,
    2433                 :            :                                                                 queue_id, vec);
    2434                 :            :                                 int nb_efd =
    2435                 :          0 :                                         rte_intr_nb_efd_get(intr_handle);
    2436         [ #  # ]:          0 :                                 if (vec < (uint32_t)nb_efd - 1 +
    2437                 :            :                                                         FM10K_RX_VEC_START)
    2438                 :          0 :                                         vec++;
    2439                 :            :                         }
    2440                 :            :                 } else {
    2441                 :          0 :                         PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
    2442                 :            :                                 " intr_vec", dev->data->nb_rx_queues);
    2443                 :          0 :                         rte_intr_efd_disable(intr_handle);
    2444                 :            :                         result = -ENOMEM;
    2445                 :            :                 }
    2446                 :            :         }
    2447                 :            : 
    2448         [ #  # ]:          0 :         if (hw->mac.type == fm10k_mac_pf)
    2449                 :          0 :                 fm10k_dev_enable_intr_pf(dev);
    2450                 :            :         else
    2451                 :            :                 fm10k_dev_enable_intr_vf(dev);
    2452                 :          0 :         rte_intr_enable(intr_handle);
    2453                 :          0 :         hw->mac.ops.update_int_moderator(hw);
    2454                 :          0 :         return result;
    2455                 :            : }
    2456                 :            : 
    2457                 :            : static int
    2458                 :          0 : fm10k_dev_handle_fault(struct fm10k_hw *hw, uint32_t eicr)
    2459                 :            : {
    2460                 :            :         struct fm10k_fault fault;
    2461                 :            :         int err;
    2462                 :            :         const char *estr = "Unknown error";
    2463                 :            : 
    2464                 :            :         /* Process PCA fault */
    2465         [ #  # ]:          0 :         if (eicr & FM10K_EICR_PCA_FAULT) {
    2466                 :          0 :                 err = fm10k_get_fault(hw, FM10K_PCA_FAULT, &fault);
    2467         [ #  # ]:          0 :                 if (err)
    2468                 :          0 :                         goto error;
    2469   [ #  #  #  #  :          0 :                 switch (fault.type) {
             #  #  #  # ]
    2470                 :            :                 case PCA_NO_FAULT:
    2471                 :            :                         estr = "PCA_NO_FAULT"; break;
    2472                 :          0 :                 case PCA_UNMAPPED_ADDR:
    2473                 :          0 :                         estr = "PCA_UNMAPPED_ADDR"; break;
    2474                 :          0 :                 case PCA_BAD_QACCESS_PF:
    2475                 :          0 :                         estr = "PCA_BAD_QACCESS_PF"; break;
    2476                 :          0 :                 case PCA_BAD_QACCESS_VF:
    2477                 :          0 :                         estr = "PCA_BAD_QACCESS_VF"; break;
    2478                 :          0 :                 case PCA_MALICIOUS_REQ:
    2479                 :          0 :                         estr = "PCA_MALICIOUS_REQ"; break;
    2480                 :          0 :                 case PCA_POISONED_TLP:
    2481                 :          0 :                         estr = "PCA_POISONED_TLP"; break;
    2482                 :          0 :                 case PCA_TLP_ABORT:
    2483                 :          0 :                         estr = "PCA_TLP_ABORT"; break;
    2484                 :          0 :                 default:
    2485                 :          0 :                         goto error;
    2486                 :            :                 }
    2487         [ #  # ]:          0 :                 PMD_INIT_LOG(ERR, "%s: %s(%d) Addr:0x%"PRIx64" Spec: 0x%x",
    2488                 :            :                         estr, fault.func ? "VF" : "PF", fault.func,
    2489                 :            :                         fault.address, fault.specinfo);
    2490                 :            :         }
    2491                 :            : 
    2492                 :            :         /* Process THI fault */
    2493         [ #  # ]:          0 :         if (eicr & FM10K_EICR_THI_FAULT) {
    2494                 :          0 :                 err = fm10k_get_fault(hw, FM10K_THI_FAULT, &fault);
    2495         [ #  # ]:          0 :                 if (err)
    2496                 :          0 :                         goto error;
    2497      [ #  #  # ]:          0 :                 switch (fault.type) {
    2498                 :            :                 case THI_NO_FAULT:
    2499                 :            :                         estr = "THI_NO_FAULT"; break;
    2500                 :          0 :                 case THI_MAL_DIS_Q_FAULT:
    2501                 :          0 :                         estr = "THI_MAL_DIS_Q_FAULT"; break;
    2502                 :          0 :                 default:
    2503                 :          0 :                         goto error;
    2504                 :            :                 }
    2505         [ #  # ]:          0 :                 PMD_INIT_LOG(ERR, "%s: %s(%d) Addr:0x%"PRIx64" Spec: 0x%x",
    2506                 :            :                         estr, fault.func ? "VF" : "PF", fault.func,
    2507                 :            :                         fault.address, fault.specinfo);
    2508                 :            :         }
    2509                 :            : 
    2510                 :            :         /* Process FUM fault */
    2511         [ #  # ]:          0 :         if (eicr & FM10K_EICR_FUM_FAULT) {
    2512                 :          0 :                 err = fm10k_get_fault(hw, FM10K_FUM_FAULT, &fault);
    2513         [ #  # ]:          0 :                 if (err)
    2514                 :          0 :                         goto error;
    2515   [ #  #  #  #  :          0 :                 switch (fault.type) {
          #  #  #  #  #  
             #  #  #  # ]
    2516                 :            :                 case FUM_NO_FAULT:
    2517                 :            :                         estr = "FUM_NO_FAULT"; break;
    2518                 :          0 :                 case FUM_UNMAPPED_ADDR:
    2519                 :          0 :                         estr = "FUM_UNMAPPED_ADDR"; break;
    2520                 :          0 :                 case FUM_POISONED_TLP:
    2521                 :          0 :                         estr = "FUM_POISONED_TLP"; break;
    2522                 :          0 :                 case FUM_BAD_VF_QACCESS:
    2523                 :          0 :                         estr = "FUM_BAD_VF_QACCESS"; break;
    2524                 :          0 :                 case FUM_ADD_DECODE_ERR:
    2525                 :          0 :                         estr = "FUM_ADD_DECODE_ERR"; break;
    2526                 :          0 :                 case FUM_RO_ERROR:
    2527                 :          0 :                         estr = "FUM_RO_ERROR"; break;
    2528                 :          0 :                 case FUM_QPRC_CRC_ERROR:
    2529                 :          0 :                         estr = "FUM_QPRC_CRC_ERROR"; break;
    2530                 :          0 :                 case FUM_CSR_TIMEOUT:
    2531                 :          0 :                         estr = "FUM_CSR_TIMEOUT"; break;
    2532                 :          0 :                 case FUM_INVALID_TYPE:
    2533                 :          0 :                         estr = "FUM_INVALID_TYPE"; break;
    2534                 :          0 :                 case FUM_INVALID_LENGTH:
    2535                 :          0 :                         estr = "FUM_INVALID_LENGTH"; break;
    2536                 :          0 :                 case FUM_INVALID_BE:
    2537                 :          0 :                         estr = "FUM_INVALID_BE"; break;
    2538                 :          0 :                 case FUM_INVALID_ALIGN:
    2539                 :          0 :                         estr = "FUM_INVALID_ALIGN"; break;
    2540                 :          0 :                 default:
    2541                 :          0 :                         goto error;
    2542                 :            :                 }
    2543         [ #  # ]:          0 :                 PMD_INIT_LOG(ERR, "%s: %s(%d) Addr:0x%"PRIx64" Spec: 0x%x",
    2544                 :            :                         estr, fault.func ? "VF" : "PF", fault.func,
    2545                 :            :                         fault.address, fault.specinfo);
    2546                 :            :         }
    2547                 :            : 
    2548                 :            :         return 0;
    2549                 :          0 : error:
    2550                 :          0 :         PMD_INIT_LOG(ERR, "Failed to handle fault event.");
    2551                 :          0 :         return err;
    2552                 :            : }
    2553                 :            : 
    2554                 :            : /**
    2555                 :            :  * PF interrupt handler triggered by NIC for handling specific interrupt.
    2556                 :            :  *
    2557                 :            :  * @param handle
    2558                 :            :  *  Pointer to interrupt handle.
    2559                 :            :  * @param param
    2560                 :            :  *  The address of parameter (struct rte_eth_dev *) registered before.
    2561                 :            :  *
    2562                 :            :  * @return
    2563                 :            :  *  void
    2564                 :            :  */
    2565                 :            : static void
    2566                 :          0 : fm10k_dev_interrupt_handler_pf(void *param)
    2567                 :            : {
    2568                 :            :         struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
    2569                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2570                 :            :         uint32_t cause, status;
    2571                 :            :         struct fm10k_dev_info *dev_info =
    2572                 :            :                 FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
    2573                 :            :         int status_mbx;
    2574                 :            :         s32 err;
    2575                 :            : 
    2576         [ #  # ]:          0 :         if (hw->mac.type != fm10k_mac_pf)
    2577                 :            :                 return;
    2578                 :            : 
    2579                 :          0 :         cause = FM10K_READ_REG(hw, FM10K_EICR);
    2580                 :            : 
    2581                 :            :         /* Handle PCI fault cases */
    2582         [ #  # ]:          0 :         if (cause & FM10K_EICR_FAULT_MASK) {
    2583                 :          0 :                 PMD_INIT_LOG(ERR, "INT: find fault!");
    2584                 :          0 :                 fm10k_dev_handle_fault(hw, cause);
    2585                 :            :         }
    2586                 :            : 
    2587                 :            :         /* Handle switch up/down */
    2588         [ #  # ]:          0 :         if (cause & FM10K_EICR_SWITCHNOTREADY)
    2589                 :          0 :                 PMD_INIT_LOG(ERR, "INT: Switch is not ready");
    2590                 :            : 
    2591         [ #  # ]:          0 :         if (cause & FM10K_EICR_SWITCHREADY) {
    2592                 :          0 :                 PMD_INIT_LOG(INFO, "INT: Switch is ready");
    2593         [ #  # ]:          0 :                 if (dev_info->sm_down == 1) {
    2594                 :            :                         fm10k_mbx_lock(hw);
    2595                 :            : 
    2596                 :            :                         /* For recreating logical ports */
    2597                 :          0 :                         status_mbx = hw->mac.ops.update_lport_state(hw,
    2598                 :          0 :                                         hw->mac.dglort_map, MAX_LPORT_NUM, 1);
    2599         [ #  # ]:          0 :                         if (status_mbx == FM10K_SUCCESS)
    2600                 :          0 :                                 PMD_INIT_LOG(INFO,
    2601                 :            :                                         "INT: Recreated Logical port");
    2602                 :            :                         else
    2603                 :          0 :                                 PMD_INIT_LOG(INFO,
    2604                 :            :                                         "INT: Logical ports weren't recreated");
    2605                 :            : 
    2606                 :          0 :                         status_mbx = hw->mac.ops.update_xcast_mode(hw,
    2607                 :          0 :                                 hw->mac.dglort_map, FM10K_XCAST_MODE_NONE);
    2608         [ #  # ]:          0 :                         if (status_mbx != FM10K_SUCCESS)
    2609                 :          0 :                                 PMD_INIT_LOG(ERR, "Failed to set XCAST mode");
    2610                 :            : 
    2611                 :            :                         fm10k_mbx_unlock(hw);
    2612                 :            : 
    2613                 :            :                         /* first clear the internal SW recording structure */
    2614         [ #  # ]:          0 :                         if (!(dev->data->dev_conf.rxmode.mq_mode &
    2615                 :            :                                                 RTE_ETH_MQ_RX_VMDQ_FLAG))
    2616                 :          0 :                                 fm10k_vlan_filter_set(dev, hw->mac.default_vid,
    2617                 :            :                                         false);
    2618                 :            : 
    2619                 :          0 :                         fm10k_MAC_filter_set(dev, hw->mac.addr, false,
    2620                 :            :                                         MAIN_VSI_POOL_NUMBER);
    2621                 :            : 
    2622                 :            :                         /*
    2623                 :            :                          * Add default mac address and vlan for the logical
    2624                 :            :                          * ports that have been created, leave to the
    2625                 :            :                          * application to fully recover Rx filtering.
    2626                 :            :                          */
    2627                 :          0 :                         fm10k_MAC_filter_set(dev, hw->mac.addr, true,
    2628                 :            :                                         MAIN_VSI_POOL_NUMBER);
    2629                 :            : 
    2630         [ #  # ]:          0 :                         if (!(dev->data->dev_conf.rxmode.mq_mode &
    2631                 :            :                                                 RTE_ETH_MQ_RX_VMDQ_FLAG))
    2632                 :          0 :                                 fm10k_vlan_filter_set(dev, hw->mac.default_vid,
    2633                 :            :                                         true);
    2634                 :            : 
    2635                 :          0 :                         dev_info->sm_down = 0;
    2636                 :          0 :                         rte_eth_dev_callback_process(dev,
    2637                 :            :                                         RTE_ETH_EVENT_INTR_LSC,
    2638                 :            :                                         NULL);
    2639                 :            :                 }
    2640                 :            :         }
    2641                 :            : 
    2642                 :            :         /* Handle mailbox message */
    2643                 :            :         fm10k_mbx_lock(hw);
    2644                 :          0 :         err = hw->mbx.ops.process(hw, &hw->mbx);
    2645                 :            :         fm10k_mbx_unlock(hw);
    2646                 :            : 
    2647         [ #  # ]:          0 :         if (err == FM10K_ERR_RESET_REQUESTED) {
    2648                 :          0 :                 PMD_INIT_LOG(INFO, "INT: Switch is down");
    2649                 :          0 :                 dev_info->sm_down = 1;
    2650                 :          0 :                 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
    2651                 :            :         }
    2652                 :            : 
    2653                 :            :         /* Handle SRAM error */
    2654         [ #  # ]:          0 :         if (cause & FM10K_EICR_SRAMERROR) {
    2655                 :          0 :                 PMD_INIT_LOG(ERR, "INT: SRAM error on PEP");
    2656                 :            : 
    2657                 :          0 :                 status = FM10K_READ_REG(hw, FM10K_SRAM_IP);
    2658                 :            :                 /* Write to clear pending bits */
    2659                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_SRAM_IP, status);
    2660                 :            : 
    2661                 :            :                 /* Todo: print out error message after shared code  updates */
    2662                 :            :         }
    2663                 :            : 
    2664                 :            :         /* Clear these 3 events if having any */
    2665                 :          0 :         cause &= FM10K_EICR_SWITCHNOTREADY | FM10K_EICR_MAILBOX |
    2666                 :            :                  FM10K_EICR_SWITCHREADY;
    2667         [ #  # ]:          0 :         if (cause)
    2668                 :          0 :                 FM10K_WRITE_REG(hw, FM10K_EICR, cause);
    2669                 :            : 
    2670                 :            :         /* Re-enable interrupt from device side */
    2671                 :          0 :         FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_AUTOMASK |
    2672                 :            :                                         FM10K_ITR_MASK_CLEAR);
    2673                 :            :         /* Re-enable interrupt from host side */
    2674                 :          0 :         rte_intr_ack(dev->intr_handle);
    2675                 :            : }
    2676                 :            : 
    2677                 :            : /**
    2678                 :            :  * VF interrupt handler triggered by NIC for handling specific interrupt.
    2679                 :            :  *
    2680                 :            :  * @param handle
    2681                 :            :  *  Pointer to interrupt handle.
    2682                 :            :  * @param param
    2683                 :            :  *  The address of parameter (struct rte_eth_dev *) registered before.
    2684                 :            :  *
    2685                 :            :  * @return
    2686                 :            :  *  void
    2687                 :            :  */
    2688                 :            : static void
    2689                 :          0 : fm10k_dev_interrupt_handler_vf(void *param)
    2690                 :            : {
    2691                 :            :         struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
    2692                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2693                 :            :         struct fm10k_mbx_info *mbx = &hw->mbx;
    2694                 :            :         struct fm10k_dev_info *dev_info =
    2695                 :            :                 FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
    2696                 :          0 :         const enum fm10k_mbx_state state = mbx->state;
    2697                 :            :         int status_mbx;
    2698                 :            : 
    2699         [ #  # ]:          0 :         if (hw->mac.type != fm10k_mac_vf)
    2700                 :            :                 return;
    2701                 :            : 
    2702                 :            :         /* Handle mailbox message if lock is acquired */
    2703                 :            :         fm10k_mbx_lock(hw);
    2704                 :          0 :         hw->mbx.ops.process(hw, &hw->mbx);
    2705                 :            :         fm10k_mbx_unlock(hw);
    2706                 :            : 
    2707   [ #  #  #  # ]:          0 :         if (state == FM10K_STATE_OPEN && mbx->state == FM10K_STATE_CONNECT) {
    2708                 :          0 :                 PMD_INIT_LOG(INFO, "INT: Switch has gone down");
    2709                 :            : 
    2710                 :            :                 fm10k_mbx_lock(hw);
    2711                 :          0 :                 hw->mac.ops.update_lport_state(hw, hw->mac.dglort_map,
    2712                 :            :                                 MAX_LPORT_NUM, 1);
    2713                 :            :                 fm10k_mbx_unlock(hw);
    2714                 :            : 
    2715                 :            :                 /* Setting reset flag */
    2716                 :          0 :                 dev_info->sm_down = 1;
    2717                 :          0 :                 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
    2718                 :            :         }
    2719                 :            : 
    2720         [ #  # ]:          0 :         if (dev_info->sm_down == 1 &&
    2721         [ #  # ]:          0 :                         hw->mac.dglort_map == FM10K_DGLORTMAP_ZERO) {
    2722                 :          0 :                 PMD_INIT_LOG(INFO, "INT: Switch has gone up");
    2723                 :            :                 fm10k_mbx_lock(hw);
    2724                 :          0 :                 status_mbx = hw->mac.ops.update_xcast_mode(hw,
    2725                 :          0 :                                 hw->mac.dglort_map, FM10K_XCAST_MODE_NONE);
    2726         [ #  # ]:          0 :                 if (status_mbx != FM10K_SUCCESS)
    2727                 :          0 :                         PMD_INIT_LOG(ERR, "Failed to set XCAST mode");
    2728                 :            :                 fm10k_mbx_unlock(hw);
    2729                 :            : 
    2730                 :            :                 /* first clear the internal SW recording structure */
    2731                 :          0 :                 fm10k_vlan_filter_set(dev, hw->mac.default_vid, false);
    2732                 :          0 :                 fm10k_MAC_filter_set(dev, hw->mac.addr, false,
    2733                 :            :                                 MAIN_VSI_POOL_NUMBER);
    2734                 :            : 
    2735                 :            :                 /*
    2736                 :            :                  * Add default mac address and vlan for the logical ports that
    2737                 :            :                  * have been created, leave to the application to fully recover
    2738                 :            :                  * Rx filtering.
    2739                 :            :                  */
    2740                 :          0 :                 fm10k_MAC_filter_set(dev, hw->mac.addr, true,
    2741                 :            :                                 MAIN_VSI_POOL_NUMBER);
    2742                 :          0 :                 fm10k_vlan_filter_set(dev, hw->mac.default_vid, true);
    2743                 :            : 
    2744                 :          0 :                 dev_info->sm_down = 0;
    2745                 :          0 :                 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
    2746                 :            :         }
    2747                 :            : 
    2748                 :            :         /* Re-enable interrupt from device side */
    2749                 :          0 :         FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_AUTOMASK |
    2750                 :            :                                         FM10K_ITR_MASK_CLEAR);
    2751                 :            :         /* Re-enable interrupt from host side */
    2752                 :          0 :         rte_intr_ack(dev->intr_handle);
    2753                 :            : }
    2754                 :            : 
    2755                 :            : /* Mailbox message handler in VF */
    2756                 :            : static const struct fm10k_msg_data fm10k_msgdata_vf[] = {
    2757                 :            :         FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
    2758                 :            :         FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_msg_mac_vlan_vf),
    2759                 :            :         FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
    2760                 :            :         FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
    2761                 :            : };
    2762                 :            : 
    2763                 :            : static int
    2764         [ #  # ]:          0 : fm10k_setup_mbx_service(struct fm10k_hw *hw)
    2765                 :            : {
    2766                 :            :         int err = 0;
    2767                 :            : 
    2768                 :            :         /* Initialize mailbox lock */
    2769                 :            :         fm10k_mbx_initlock(hw);
    2770                 :            : 
    2771                 :            :         /* Replace default message handler with new ones */
    2772         [ #  # ]:          0 :         if (hw->mac.type == fm10k_mac_vf)
    2773                 :          0 :                 err = hw->mbx.ops.register_handlers(&hw->mbx, fm10k_msgdata_vf);
    2774                 :            : 
    2775         [ #  # ]:          0 :         if (err) {
    2776                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to register mailbox handler.err:%d",
    2777                 :            :                                 err);
    2778                 :          0 :                 return err;
    2779                 :            :         }
    2780                 :            :         /* Connect to SM for PF device or PF for VF device */
    2781                 :          0 :         return hw->mbx.ops.connect(hw, &hw->mbx);
    2782                 :            : }
    2783                 :            : 
    2784                 :            : static void
    2785                 :            : fm10k_close_mbx_service(struct fm10k_hw *hw)
    2786                 :            : {
    2787                 :            :         /* Disconnect from SM for PF device or PF for VF device */
    2788                 :          0 :         hw->mbx.ops.disconnect(hw, &hw->mbx);
    2789                 :            : }
    2790                 :            : 
    2791                 :            : static int
    2792                 :          0 : fm10k_dev_close(struct rte_eth_dev *dev)
    2793                 :            : {
    2794                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2795                 :          0 :         struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
    2796                 :          0 :         struct rte_intr_handle *intr_handle = pdev->intr_handle;
    2797                 :            :         int ret;
    2798                 :            : 
    2799                 :          0 :         PMD_INIT_FUNC_TRACE();
    2800         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    2801                 :            :                 return 0;
    2802                 :            : 
    2803                 :            :         fm10k_mbx_lock(hw);
    2804                 :          0 :         hw->mac.ops.update_lport_state(hw, hw->mac.dglort_map,
    2805                 :            :                 MAX_LPORT_NUM, false);
    2806                 :            :         fm10k_mbx_unlock(hw);
    2807                 :            : 
    2808                 :            :         /* allow 100ms for device to quiesce */
    2809                 :          0 :         rte_delay_us(FM10K_SWITCH_QUIESCE_US);
    2810                 :            : 
    2811                 :            :         /* Stop mailbox service first */
    2812                 :            :         fm10k_close_mbx_service(hw);
    2813                 :            : 
    2814                 :          0 :         ret = fm10k_dev_stop(dev);
    2815                 :            : 
    2816                 :          0 :         fm10k_dev_queue_release(dev);
    2817                 :          0 :         fm10k_stop_hw(hw);
    2818                 :            : 
    2819                 :            :         /* disable uio/vfio intr */
    2820                 :          0 :         rte_intr_disable(intr_handle);
    2821                 :            : 
    2822                 :            :         /*PF/VF has different interrupt handling mechanism */
    2823         [ #  # ]:          0 :         if (hw->mac.type == fm10k_mac_pf) {
    2824                 :            :                 /* disable interrupt */
    2825                 :          0 :                 fm10k_dev_disable_intr_pf(dev);
    2826                 :            : 
    2827                 :            :                 /* unregister callback func to eal lib */
    2828                 :          0 :                 rte_intr_callback_unregister(intr_handle,
    2829                 :            :                         fm10k_dev_interrupt_handler_pf, (void *)dev);
    2830                 :            :         } else {
    2831                 :            :                 /* disable interrupt */
    2832                 :            :                 fm10k_dev_disable_intr_vf(dev);
    2833                 :            : 
    2834                 :          0 :                 rte_intr_callback_unregister(intr_handle,
    2835                 :            :                         fm10k_dev_interrupt_handler_vf, (void *)dev);
    2836                 :            :         }
    2837                 :            : 
    2838                 :            :         return ret;
    2839                 :            : }
    2840                 :            : 
    2841                 :            : static const struct eth_dev_ops fm10k_eth_dev_ops = {
    2842                 :            :         .dev_configure          = fm10k_dev_configure,
    2843                 :            :         .dev_start              = fm10k_dev_start,
    2844                 :            :         .dev_stop               = fm10k_dev_stop,
    2845                 :            :         .dev_close              = fm10k_dev_close,
    2846                 :            :         .promiscuous_enable     = fm10k_dev_promiscuous_enable,
    2847                 :            :         .promiscuous_disable    = fm10k_dev_promiscuous_disable,
    2848                 :            :         .allmulticast_enable    = fm10k_dev_allmulticast_enable,
    2849                 :            :         .allmulticast_disable   = fm10k_dev_allmulticast_disable,
    2850                 :            :         .stats_get              = fm10k_stats_get,
    2851                 :            :         .xstats_get             = fm10k_xstats_get,
    2852                 :            :         .xstats_get_names       = fm10k_xstats_get_names,
    2853                 :            :         .stats_reset            = fm10k_stats_reset,
    2854                 :            :         .xstats_reset           = fm10k_stats_reset,
    2855                 :            :         .link_update            = fm10k_link_update,
    2856                 :            :         .dev_infos_get          = fm10k_dev_infos_get,
    2857                 :            :         .dev_supported_ptypes_get = fm10k_dev_supported_ptypes_get,
    2858                 :            :         .vlan_filter_set        = fm10k_vlan_filter_set,
    2859                 :            :         .vlan_offload_set       = fm10k_vlan_offload_set,
    2860                 :            :         .mac_addr_add           = fm10k_macaddr_add,
    2861                 :            :         .mac_addr_remove        = fm10k_macaddr_remove,
    2862                 :            :         .rx_queue_start         = fm10k_dev_rx_queue_start,
    2863                 :            :         .rx_queue_stop          = fm10k_dev_rx_queue_stop,
    2864                 :            :         .tx_queue_start         = fm10k_dev_tx_queue_start,
    2865                 :            :         .tx_queue_stop          = fm10k_dev_tx_queue_stop,
    2866                 :            :         .rx_queue_setup         = fm10k_rx_queue_setup,
    2867                 :            :         .rx_queue_release       = fm10k_rx_queue_release,
    2868                 :            :         .tx_queue_setup         = fm10k_tx_queue_setup,
    2869                 :            :         .tx_queue_release       = fm10k_tx_queue_release,
    2870                 :            :         .rx_queue_intr_enable   = fm10k_dev_rx_queue_intr_enable,
    2871                 :            :         .rx_queue_intr_disable  = fm10k_dev_rx_queue_intr_disable,
    2872                 :            :         .reta_update            = fm10k_reta_update,
    2873                 :            :         .reta_query             = fm10k_reta_query,
    2874                 :            :         .rss_hash_update        = fm10k_rss_hash_update,
    2875                 :            :         .rss_hash_conf_get      = fm10k_rss_hash_conf_get,
    2876                 :            : };
    2877                 :            : 
    2878                 :          0 : static int ftag_check_handler(__rte_unused const char *key,
    2879                 :            :                 const char *value, __rte_unused void *opaque)
    2880                 :            : {
    2881         [ #  # ]:          0 :         if (strcmp(value, "1"))
    2882                 :          0 :                 return -1;
    2883                 :            : 
    2884                 :            :         return 0;
    2885                 :            : }
    2886                 :            : 
    2887                 :            : static int
    2888                 :          0 : fm10k_check_ftag(struct rte_devargs *devargs)
    2889                 :            : {
    2890                 :            :         struct rte_kvargs *kvlist;
    2891                 :            :         const char *ftag_key = "enable_ftag";
    2892                 :            : 
    2893         [ #  # ]:          0 :         if (devargs == NULL)
    2894                 :            :                 return 0;
    2895                 :            : 
    2896                 :          0 :         kvlist = rte_kvargs_parse(devargs->args, NULL);
    2897         [ #  # ]:          0 :         if (kvlist == NULL)
    2898                 :            :                 return 0;
    2899                 :            : 
    2900         [ #  # ]:          0 :         if (!rte_kvargs_count(kvlist, ftag_key)) {
    2901                 :          0 :                 rte_kvargs_free(kvlist);
    2902                 :          0 :                 return 0;
    2903                 :            :         }
    2904                 :            :         /* FTAG is enabled when there's key-value pair: enable_ftag=1 */
    2905         [ #  # ]:          0 :         if (rte_kvargs_process(kvlist, ftag_key,
    2906                 :            :                                 ftag_check_handler, NULL) < 0) {
    2907                 :          0 :                 rte_kvargs_free(kvlist);
    2908                 :          0 :                 return 0;
    2909                 :            :         }
    2910                 :          0 :         rte_kvargs_free(kvlist);
    2911                 :            : 
    2912                 :          0 :         return 1;
    2913                 :            : }
    2914                 :            : 
    2915                 :            : static uint16_t
    2916                 :          0 : fm10k_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
    2917                 :            :                     uint16_t nb_pkts)
    2918                 :            : {
    2919                 :            :         uint16_t nb_tx = 0;
    2920                 :            :         struct fm10k_tx_queue *txq = (struct fm10k_tx_queue *)tx_queue;
    2921                 :            : 
    2922         [ #  # ]:          0 :         while (nb_pkts) {
    2923                 :            :                 uint16_t ret, num;
    2924                 :            : 
    2925                 :          0 :                 num = (uint16_t)RTE_MIN(nb_pkts, txq->rs_thresh);
    2926                 :          0 :                 ret = fm10k_xmit_fixed_burst_vec(tx_queue, &tx_pkts[nb_tx],
    2927                 :            :                                                  num);
    2928                 :          0 :                 nb_tx += ret;
    2929                 :          0 :                 nb_pkts -= ret;
    2930         [ #  # ]:          0 :                 if (ret < num)
    2931                 :            :                         break;
    2932                 :            :         }
    2933                 :            : 
    2934                 :          0 :         return nb_tx;
    2935                 :            : }
    2936                 :            : 
    2937                 :            : static void __rte_cold
    2938                 :          0 : fm10k_set_tx_function(struct rte_eth_dev *dev)
    2939                 :            : {
    2940                 :            :         struct fm10k_tx_queue *txq;
    2941                 :            :         int i;
    2942                 :            :         int use_sse = 1;
    2943                 :            :         uint16_t tx_ftag_en = 0;
    2944                 :            : 
    2945         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
    2946                 :            :                 /* primary process has set the ftag flag and offloads */
    2947                 :          0 :                 txq = dev->data->tx_queues[0];
    2948   [ #  #  #  # ]:          0 :                 if (fm10k_tx_vec_condition_check(txq) ||
    2949                 :          0 :                                 rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128) {
    2950                 :          0 :                         dev->tx_pkt_burst = fm10k_xmit_pkts;
    2951                 :          0 :                         dev->tx_pkt_prepare = fm10k_prep_pkts;
    2952                 :          0 :                         PMD_INIT_LOG(DEBUG, "Use regular Tx func");
    2953                 :            :                 } else {
    2954                 :          0 :                         PMD_INIT_LOG(DEBUG, "Use vector Tx func");
    2955                 :          0 :                         dev->tx_pkt_burst = fm10k_xmit_pkts_vec;
    2956                 :          0 :                         dev->tx_pkt_prepare = NULL;
    2957                 :            :                 }
    2958                 :          0 :                 return;
    2959                 :            :         }
    2960                 :            : 
    2961         [ #  # ]:          0 :         if (fm10k_check_ftag(dev->device->devargs))
    2962                 :            :                 tx_ftag_en = 1;
    2963                 :            : 
    2964         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    2965                 :          0 :                 txq = dev->data->tx_queues[i];
    2966                 :          0 :                 txq->tx_ftag_en = tx_ftag_en;
    2967                 :            :                 /* Check if Vector Tx is satisfied */
    2968   [ #  #  #  # ]:          0 :                 if (fm10k_tx_vec_condition_check(txq) ||
    2969                 :          0 :                                 rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128)
    2970                 :            :                         use_sse = 0;
    2971                 :            :         }
    2972                 :            : 
    2973         [ #  # ]:          0 :         if (use_sse) {
    2974                 :          0 :                 PMD_INIT_LOG(DEBUG, "Use vector Tx func");
    2975         [ #  # ]:          0 :                 for (i = 0; i < dev->data->nb_tx_queues; i++) {
    2976                 :          0 :                         txq = dev->data->tx_queues[i];
    2977                 :          0 :                         fm10k_txq_vec_setup(txq);
    2978                 :            :                 }
    2979                 :          0 :                 dev->tx_pkt_burst = fm10k_xmit_pkts_vec;
    2980                 :          0 :                 dev->tx_pkt_prepare = NULL;
    2981                 :            :         } else {
    2982                 :          0 :                 dev->tx_pkt_burst = fm10k_xmit_pkts;
    2983                 :          0 :                 dev->tx_pkt_prepare = fm10k_prep_pkts;
    2984                 :          0 :                 PMD_INIT_LOG(DEBUG, "Use regular Tx func");
    2985                 :            :         }
    2986                 :            : }
    2987                 :            : 
    2988                 :            : static void __rte_cold
    2989                 :          0 : fm10k_set_rx_function(struct rte_eth_dev *dev)
    2990                 :            : {
    2991                 :            :         struct fm10k_dev_info *dev_info =
    2992                 :          0 :                 FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
    2993                 :            :         uint16_t i, rx_using_sse;
    2994                 :            :         uint16_t rx_ftag_en = 0;
    2995                 :            : 
    2996         [ #  # ]:          0 :         if (fm10k_check_ftag(dev->device->devargs))
    2997                 :            :                 rx_ftag_en = 1;
    2998                 :            : 
    2999                 :            :         /* In order to allow Vector Rx there are a few configuration
    3000                 :            :          * conditions to be met.
    3001                 :            :          */
    3002         [ #  # ]:          0 :         if (!fm10k_rx_vec_condition_check(dev) &&
    3003   [ #  #  #  #  :          0 :                         dev_info->rx_vec_allowed && !rx_ftag_en &&
                   #  # ]
    3004                 :          0 :                         rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
    3005         [ #  # ]:          0 :                 if (dev->data->scattered_rx)
    3006                 :          0 :                         dev->rx_pkt_burst = fm10k_recv_scattered_pkts_vec;
    3007                 :            :                 else
    3008                 :          0 :                         dev->rx_pkt_burst = fm10k_recv_pkts_vec;
    3009         [ #  # ]:          0 :         } else if (dev->data->scattered_rx)
    3010                 :          0 :                 dev->rx_pkt_burst = fm10k_recv_scattered_pkts;
    3011                 :            :         else
    3012                 :          0 :                 dev->rx_pkt_burst = fm10k_recv_pkts;
    3013                 :            : 
    3014                 :          0 :         rx_using_sse =
    3015   [ #  #  #  # ]:          0 :                 (dev->rx_pkt_burst == fm10k_recv_scattered_pkts_vec ||
    3016                 :            :                 dev->rx_pkt_burst == fm10k_recv_pkts_vec);
    3017                 :            : 
    3018         [ #  # ]:          0 :         if (rx_using_sse)
    3019                 :          0 :                 PMD_INIT_LOG(DEBUG, "Use vector Rx func");
    3020                 :            :         else
    3021                 :          0 :                 PMD_INIT_LOG(DEBUG, "Use regular Rx func");
    3022                 :            : 
    3023         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    3024                 :            :                 return;
    3025                 :            : 
    3026         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    3027                 :          0 :                 struct fm10k_rx_queue *rxq = dev->data->rx_queues[i];
    3028                 :            : 
    3029                 :          0 :                 rxq->rx_using_sse = rx_using_sse;
    3030                 :          0 :                 rxq->rx_ftag_en = rx_ftag_en;
    3031                 :            :         }
    3032                 :            : }
    3033                 :            : 
    3034                 :            : static void
    3035                 :            : fm10k_params_init(struct rte_eth_dev *dev)
    3036                 :            : {
    3037                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    3038                 :            :         struct fm10k_dev_info *info =
    3039                 :            :                 FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
    3040                 :            : 
    3041                 :            :         /* Initialize bus info. Normally we would call fm10k_get_bus_info(), but
    3042                 :            :          * there is no way to get link status without reading BAR4.  Until this
    3043                 :            :          * works, assume we have maximum bandwidth.
    3044                 :            :          * @todo - fix bus info
    3045                 :            :          */
    3046                 :          0 :         hw->bus_caps.speed = fm10k_bus_speed_8000;
    3047                 :          0 :         hw->bus_caps.width = fm10k_bus_width_pcie_x8;
    3048                 :          0 :         hw->bus_caps.payload = fm10k_bus_payload_512;
    3049                 :          0 :         hw->bus.speed = fm10k_bus_speed_8000;
    3050                 :          0 :         hw->bus.width = fm10k_bus_width_pcie_x8;
    3051                 :          0 :         hw->bus.payload = fm10k_bus_payload_256;
    3052                 :            : 
    3053                 :          0 :         info->rx_vec_allowed = true;
    3054                 :          0 :         info->sm_down = false;
    3055                 :            : }
    3056                 :            : 
    3057                 :            : static int
    3058                 :          0 : eth_fm10k_dev_init(struct rte_eth_dev *dev)
    3059                 :            : {
    3060                 :          0 :         struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    3061                 :          0 :         struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
    3062                 :          0 :         struct rte_intr_handle *intr_handle = pdev->intr_handle;
    3063                 :            :         int diag, i, ret;
    3064                 :            :         struct fm10k_macvlan_filter_info *macvlan;
    3065                 :            : 
    3066                 :          0 :         PMD_INIT_FUNC_TRACE();
    3067                 :            : 
    3068                 :          0 :         dev->dev_ops = &fm10k_eth_dev_ops;
    3069                 :          0 :         dev->rx_queue_count = fm10k_dev_rx_queue_count;
    3070                 :          0 :         dev->rx_descriptor_status = fm10k_dev_rx_descriptor_status;
    3071                 :          0 :         dev->tx_descriptor_status = fm10k_dev_tx_descriptor_status;
    3072                 :          0 :         dev->rx_pkt_burst = &fm10k_recv_pkts;
    3073                 :          0 :         dev->tx_pkt_burst = &fm10k_xmit_pkts;
    3074                 :          0 :         dev->tx_pkt_prepare = &fm10k_prep_pkts;
    3075                 :            : 
    3076                 :            :         /*
    3077                 :            :          * Primary process does the whole initialization, for secondary
    3078                 :            :          * processes, we just select the same Rx and Tx function as primary.
    3079                 :            :          */
    3080         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
    3081                 :          0 :                 fm10k_set_rx_function(dev);
    3082                 :          0 :                 fm10k_set_tx_function(dev);
    3083                 :          0 :                 return 0;
    3084                 :            :         }
    3085                 :            : 
    3086                 :          0 :         rte_eth_copy_pci_info(dev, pdev);
    3087                 :          0 :         dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
    3088                 :            : 
    3089         [ #  # ]:          0 :         macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
    3090                 :            :         memset(macvlan, 0, sizeof(*macvlan));
    3091                 :            :         /* Vendor and Device ID need to be set before init of shared code */
    3092                 :            :         memset(hw, 0, sizeof(*hw));
    3093                 :          0 :         hw->device_id = pdev->id.device_id;
    3094                 :          0 :         hw->vendor_id = pdev->id.vendor_id;
    3095                 :          0 :         hw->subsystem_device_id = pdev->id.subsystem_device_id;
    3096                 :          0 :         hw->subsystem_vendor_id = pdev->id.subsystem_vendor_id;
    3097                 :            :         hw->revision_id = 0;
    3098                 :          0 :         hw->hw_addr = (void *)pdev->mem_resource[0].addr;
    3099         [ #  # ]:          0 :         if (hw->hw_addr == NULL) {
    3100                 :          0 :                 PMD_INIT_LOG(ERR, "Bad mem resource."
    3101                 :            :                         " Try to refuse unused devices.");
    3102                 :          0 :                 return -EIO;
    3103                 :            :         }
    3104                 :            : 
    3105                 :            :         /* Store fm10k_adapter pointer */
    3106                 :          0 :         hw->back = dev->data->dev_private;
    3107                 :            : 
    3108                 :            :         /* Initialize the shared code */
    3109                 :          0 :         diag = fm10k_init_shared_code(hw);
    3110         [ #  # ]:          0 :         if (diag != FM10K_SUCCESS) {
    3111                 :          0 :                 PMD_INIT_LOG(ERR, "Shared code init failed: %d", diag);
    3112                 :          0 :                 return -EIO;
    3113                 :            :         }
    3114                 :            : 
    3115                 :            :         /* Initialize parameters */
    3116                 :            :         fm10k_params_init(dev);
    3117                 :            : 
    3118                 :            :         /* Initialize the hw */
    3119                 :          0 :         diag = fm10k_init_hw(hw);
    3120         [ #  # ]:          0 :         if (diag != FM10K_SUCCESS) {
    3121                 :          0 :                 PMD_INIT_LOG(ERR, "Hardware init failed: %d", diag);
    3122                 :          0 :                 return -EIO;
    3123                 :            :         }
    3124                 :            : 
    3125                 :            :         /* Initialize MAC address(es) */
    3126                 :          0 :         dev->data->mac_addrs = rte_zmalloc("fm10k",
    3127                 :            :                         RTE_ETHER_ADDR_LEN * FM10K_MAX_MACADDR_NUM, 0);
    3128         [ #  # ]:          0 :         if (dev->data->mac_addrs == NULL) {
    3129                 :          0 :                 PMD_INIT_LOG(ERR, "Cannot allocate memory for MAC addresses");
    3130                 :          0 :                 return -ENOMEM;
    3131                 :            :         }
    3132                 :            : 
    3133                 :          0 :         diag = fm10k_read_mac_addr(hw);
    3134                 :            : 
    3135                 :          0 :         rte_ether_addr_copy((const struct rte_ether_addr *)hw->mac.addr,
    3136         [ #  # ]:          0 :                         &dev->data->mac_addrs[0]);
    3137                 :            : 
    3138         [ #  # ]:          0 :         if (diag != FM10K_SUCCESS ||
    3139                 :            :                 !rte_is_valid_assigned_ether_addr(dev->data->mac_addrs)) {
    3140                 :            : 
    3141                 :            :                 /* Generate a random addr */
    3142                 :          0 :                 rte_eth_random_addr(hw->mac.addr);
    3143                 :          0 :                 memcpy(hw->mac.perm_addr, hw->mac.addr, ETH_ALEN);
    3144                 :          0 :                 rte_ether_addr_copy((const struct rte_ether_addr *)hw->mac.addr,
    3145                 :          0 :                 &dev->data->mac_addrs[0]);
    3146                 :            :         }
    3147                 :            : 
    3148                 :            :         /* Reset the hw statistics */
    3149                 :          0 :         diag = fm10k_stats_reset(dev);
    3150         [ #  # ]:          0 :         if (diag != 0) {
    3151                 :          0 :                 PMD_INIT_LOG(ERR, "Stats reset failed: %d", diag);
    3152                 :            :                 ret = diag;
    3153                 :          0 :                 goto err_stat;
    3154                 :            :         }
    3155                 :            : 
    3156                 :            :         /* Reset the hw */
    3157                 :          0 :         diag = fm10k_reset_hw(hw);
    3158         [ #  # ]:          0 :         if (diag != FM10K_SUCCESS) {
    3159                 :          0 :                 PMD_INIT_LOG(ERR, "Hardware reset failed: %d", diag);
    3160                 :            :                 ret = -EIO;
    3161                 :          0 :                 goto err_reset_hw;
    3162                 :            :         }
    3163                 :            : 
    3164                 :            :         /* Setup mailbox service */
    3165                 :          0 :         diag = fm10k_setup_mbx_service(hw);
    3166         [ #  # ]:          0 :         if (diag != FM10K_SUCCESS) {
    3167                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to setup mailbox: %d", diag);
    3168                 :            :                 ret = -EIO;
    3169                 :          0 :                 goto err_mbx;
    3170                 :            :         }
    3171                 :            : 
    3172                 :            :         /*PF/VF has different interrupt handling mechanism */
    3173         [ #  # ]:          0 :         if (hw->mac.type == fm10k_mac_pf) {
    3174                 :            :                 /* register callback func to eal lib */
    3175                 :          0 :                 rte_intr_callback_register(intr_handle,
    3176                 :            :                         fm10k_dev_interrupt_handler_pf, (void *)dev);
    3177                 :            : 
    3178                 :            :                 /* enable MISC interrupt */
    3179                 :          0 :                 fm10k_dev_enable_intr_pf(dev);
    3180                 :            :         } else { /* VF */
    3181                 :          0 :                 rte_intr_callback_register(intr_handle,
    3182                 :            :                         fm10k_dev_interrupt_handler_vf, (void *)dev);
    3183                 :            : 
    3184                 :            :                 fm10k_dev_enable_intr_vf(dev);
    3185                 :            :         }
    3186                 :            : 
    3187                 :            :         /* Enable intr after callback registered */
    3188                 :          0 :         rte_intr_enable(intr_handle);
    3189                 :            : 
    3190                 :          0 :         hw->mac.ops.update_int_moderator(hw);
    3191                 :            : 
    3192                 :            :         /* Make sure Switch Manager is ready before going forward. */
    3193         [ #  # ]:          0 :         if (hw->mac.type == fm10k_mac_pf) {
    3194                 :          0 :                 bool switch_ready = false;
    3195                 :            : 
    3196         [ #  # ]:          0 :                 for (i = 0; i < MAX_QUERY_SWITCH_STATE_TIMES; i++) {
    3197                 :            :                         fm10k_mbx_lock(hw);
    3198                 :          0 :                         hw->mac.ops.get_host_state(hw, &switch_ready);
    3199                 :            :                         fm10k_mbx_unlock(hw);
    3200         [ #  # ]:          0 :                         if (switch_ready == true)
    3201                 :            :                                 break;
    3202                 :            :                         /* Delay some time to acquire async LPORT_MAP info. */
    3203                 :          0 :                         rte_delay_us(WAIT_SWITCH_MSG_US);
    3204                 :            :                 }
    3205                 :            : 
    3206         [ #  # ]:          0 :                 if (switch_ready == false) {
    3207                 :          0 :                         PMD_INIT_LOG(ERR, "switch is not ready");
    3208                 :            :                         ret = -1;
    3209                 :          0 :                         goto err_switch_ready;
    3210                 :            :                 }
    3211                 :            :         }
    3212                 :            : 
    3213                 :            :         /*
    3214                 :            :          * Below function will trigger operations on mailbox, acquire lock to
    3215                 :            :          * avoid race condition from interrupt handler. Operations on mailbox
    3216                 :            :          * FIFO will trigger interrupt to PF/SM, in which interrupt handler
    3217                 :            :          * will handle and generate an interrupt to our side. Then,  FIFO in
    3218                 :            :          * mailbox will be touched.
    3219                 :            :          */
    3220                 :            :         fm10k_mbx_lock(hw);
    3221                 :            :         /* Enable port first */
    3222                 :          0 :         hw->mac.ops.update_lport_state(hw, hw->mac.dglort_map,
    3223                 :            :                                         MAX_LPORT_NUM, 1);
    3224                 :            : 
    3225                 :            :         /* Set unicast mode by default. App can change to other mode in other
    3226                 :            :          * API func.
    3227                 :            :          */
    3228                 :          0 :         hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
    3229                 :            :                                         FM10K_XCAST_MODE_NONE);
    3230                 :            : 
    3231                 :            :         fm10k_mbx_unlock(hw);
    3232                 :            : 
    3233                 :            :         /* Make sure default VID is ready before going forward. */
    3234         [ #  # ]:          0 :         if (hw->mac.type == fm10k_mac_pf) {
    3235         [ #  # ]:          0 :                 for (i = 0; i < MAX_QUERY_SWITCH_STATE_TIMES; i++) {
    3236         [ #  # ]:          0 :                         if (hw->mac.default_vid)
    3237                 :            :                                 break;
    3238                 :            :                         /* Delay some time to acquire async port VLAN info. */
    3239                 :          0 :                         rte_delay_us(WAIT_SWITCH_MSG_US);
    3240                 :            :                 }
    3241                 :            : 
    3242         [ #  # ]:          0 :                 if (!hw->mac.default_vid) {
    3243                 :          0 :                         PMD_INIT_LOG(ERR, "default VID is not ready");
    3244                 :            :                         ret = -1;
    3245                 :          0 :                         goto err_vid;
    3246                 :            :                 }
    3247                 :            :         }
    3248                 :            : 
    3249                 :            :         /* Add default mac address */
    3250                 :          0 :         fm10k_MAC_filter_set(dev, hw->mac.addr, true,
    3251                 :            :                 MAIN_VSI_POOL_NUMBER);
    3252                 :            : 
    3253                 :          0 :         return 0;
    3254                 :            : 
    3255                 :            : err_vid:
    3256                 :          0 : err_switch_ready:
    3257                 :          0 :         rte_intr_disable(intr_handle);
    3258                 :            : 
    3259         [ #  # ]:          0 :         if (hw->mac.type == fm10k_mac_pf) {
    3260                 :          0 :                 fm10k_dev_disable_intr_pf(dev);
    3261                 :          0 :                 rte_intr_callback_unregister(intr_handle,
    3262                 :            :                         fm10k_dev_interrupt_handler_pf, (void *)dev);
    3263                 :            :         } else {
    3264                 :            :                 fm10k_dev_disable_intr_vf(dev);
    3265                 :          0 :                 rte_intr_callback_unregister(intr_handle,
    3266                 :            :                         fm10k_dev_interrupt_handler_vf, (void *)dev);
    3267                 :            :         }
    3268                 :            : 
    3269                 :          0 : err_mbx:
    3270                 :          0 : err_reset_hw:
    3271                 :          0 : err_stat:
    3272                 :          0 :         rte_free(dev->data->mac_addrs);
    3273                 :          0 :         dev->data->mac_addrs = NULL;
    3274                 :            : 
    3275                 :          0 :         return ret;
    3276                 :            : }
    3277                 :            : 
    3278                 :            : static int
    3279                 :          0 : eth_fm10k_dev_uninit(struct rte_eth_dev *dev)
    3280                 :            : {
    3281                 :          0 :         PMD_INIT_FUNC_TRACE();
    3282                 :          0 :         fm10k_dev_close(dev);
    3283                 :          0 :         return 0;
    3284                 :            : }
    3285                 :            : 
    3286                 :          0 : static int eth_fm10k_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
    3287                 :            :         struct rte_pci_device *pci_dev)
    3288                 :            : {
    3289                 :          0 :         return rte_eth_dev_pci_generic_probe(pci_dev,
    3290                 :            :                 sizeof(struct fm10k_adapter), eth_fm10k_dev_init);
    3291                 :            : }
    3292                 :            : 
    3293                 :          0 : static int eth_fm10k_pci_remove(struct rte_pci_device *pci_dev)
    3294                 :            : {
    3295                 :          0 :         return rte_eth_dev_pci_generic_remove(pci_dev, eth_fm10k_dev_uninit);
    3296                 :            : }
    3297                 :            : 
    3298                 :            : /*
    3299                 :            :  * The set of PCI devices this driver supports. This driver will enable both PF
    3300                 :            :  * and SRIOV-VF devices.
    3301                 :            :  */
    3302                 :            : static const struct rte_pci_id pci_id_fm10k_map[] = {
    3303                 :            :         { RTE_PCI_DEVICE(FM10K_INTEL_VENDOR_ID, FM10K_DEV_ID_PF) },
    3304                 :            :         { RTE_PCI_DEVICE(FM10K_INTEL_VENDOR_ID, FM10K_DEV_ID_SDI_FM10420_QDA2) },
    3305                 :            :         { RTE_PCI_DEVICE(FM10K_INTEL_VENDOR_ID, FM10K_DEV_ID_VF) },
    3306                 :            :         { .vendor_id = 0, /* sentinel */ },
    3307                 :            : };
    3308                 :            : 
    3309                 :            : static struct rte_pci_driver rte_pmd_fm10k = {
    3310                 :            :         .id_table = pci_id_fm10k_map,
    3311                 :            :         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
    3312                 :            :         .probe = eth_fm10k_pci_probe,
    3313                 :            :         .remove = eth_fm10k_pci_remove,
    3314                 :            : };
    3315                 :            : 
    3316                 :        252 : RTE_PMD_REGISTER_PCI(net_fm10k, rte_pmd_fm10k);
    3317                 :            : RTE_PMD_REGISTER_PCI_TABLE(net_fm10k, pci_id_fm10k_map);
    3318                 :            : RTE_PMD_REGISTER_KMOD_DEP(net_fm10k, "* igb_uio | uio_pci_generic | vfio-pci");
    3319         [ -  + ]:        252 : RTE_LOG_REGISTER_SUFFIX(fm10k_logtype_init, init, NOTICE);
    3320         [ -  + ]:        252 : RTE_LOG_REGISTER_SUFFIX(fm10k_logtype_driver, driver, NOTICE);
    3321                 :            : #ifdef RTE_ETHDEV_DEBUG_RX
    3322                 :            : RTE_LOG_REGISTER_SUFFIX(fm10k_logtype_rx, rx, DEBUG);
    3323                 :            : #endif
    3324                 :            : #ifdef RTE_ETHDEV_DEBUG_TX
    3325                 :            : RTE_LOG_REGISTER_SUFFIX(fm10k_logtype_tx, tx, DEBUG);
    3326                 :            : #endif

Generated by: LCOV version 1.14