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

Generated by: LCOV version 1.14