LCOV - code coverage report
Current view: top level - drivers/net/txgbe - txgbe_ethdev_vf.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 1 513 0.2 %
Date: 2025-08-01 17:49:26 Functions: 1 47 2.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 200 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
       3                 :            :  * Copyright(c) 2010-2017 Intel Corporation
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <sys/queue.h>
       7                 :            : #include <stdio.h>
       8                 :            : #include <errno.h>
       9                 :            : #include <stdint.h>
      10                 :            : #include <string.h>
      11                 :            : #include <rte_log.h>
      12                 :            : #include <ethdev_pci.h>
      13                 :            : #include <rte_alarm.h>
      14                 :            : 
      15                 :            : #include "txgbe_logs.h"
      16                 :            : #include "base/txgbe.h"
      17                 :            : #include "txgbe_ethdev.h"
      18                 :            : #include "txgbe_rxtx.h"
      19                 :            : #include "txgbe_regs_group.h"
      20                 :            : 
      21                 :            : static const struct reg_info txgbevf_regs_general[] = {
      22                 :            :         {TXGBE_VFRST, 1, 1, "TXGBE_VFRST"},
      23                 :            :         {TXGBE_VFSTATUS, 1, 1, "TXGBE_VFSTATUS"},
      24                 :            :         {TXGBE_VFMBCTL, 1, 1, "TXGBE_VFMAILBOX"},
      25                 :            :         {TXGBE_VFMBX, 16, 4, "TXGBE_VFMBX"},
      26                 :            :         {TXGBE_VFPBWRAP, 1, 1, "TXGBE_VFPBWRAP"},
      27                 :            :         {0, 0, 0, ""}
      28                 :            : };
      29                 :            : 
      30                 :            : static const struct reg_info txgbevf_regs_interrupt[] = {
      31                 :            :         {0, 0, 0, ""}
      32                 :            : };
      33                 :            : 
      34                 :            : static const struct reg_info txgbevf_regs_rxdma[] = {
      35                 :            :         {0, 0, 0, ""}
      36                 :            : };
      37                 :            : 
      38                 :            : static const struct reg_info txgbevf_regs_tx[] = {
      39                 :            :         {0, 0, 0, ""}
      40                 :            : };
      41                 :            : 
      42                 :            : /* VF registers */
      43                 :            : static const struct reg_info *txgbevf_regs[] = {
      44                 :            :                                 txgbevf_regs_general,
      45                 :            :                                 txgbevf_regs_interrupt,
      46                 :            :                                 txgbevf_regs_rxdma,
      47                 :            :                                 txgbevf_regs_tx,
      48                 :            :                                 NULL};
      49                 :            : 
      50                 :            : static int txgbevf_dev_xstats_get(struct rte_eth_dev *dev,
      51                 :            :                                   struct rte_eth_xstat *xstats, unsigned int n);
      52                 :            : static int txgbevf_dev_info_get(struct rte_eth_dev *dev,
      53                 :            :                                  struct rte_eth_dev_info *dev_info);
      54                 :            : static int  txgbevf_dev_configure(struct rte_eth_dev *dev);
      55                 :            : static int  txgbevf_dev_start(struct rte_eth_dev *dev);
      56                 :            : static int txgbevf_dev_link_update(struct rte_eth_dev *dev,
      57                 :            :                                    int wait_to_complete);
      58                 :            : static int txgbevf_dev_stop(struct rte_eth_dev *dev);
      59                 :            : static int txgbevf_dev_close(struct rte_eth_dev *dev);
      60                 :            : static void txgbevf_intr_disable(struct rte_eth_dev *dev);
      61                 :            : static void txgbevf_intr_enable(struct rte_eth_dev *dev);
      62                 :            : static int txgbevf_dev_stats_reset(struct rte_eth_dev *dev);
      63                 :            : static int txgbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask);
      64                 :            : static void txgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on);
      65                 :            : static void txgbevf_configure_msix(struct rte_eth_dev *dev);
      66                 :            : static int txgbevf_dev_promiscuous_enable(struct rte_eth_dev *dev);
      67                 :            : static int txgbevf_dev_promiscuous_disable(struct rte_eth_dev *dev);
      68                 :            : static void txgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
      69                 :            : static void txgbevf_dev_interrupt_handler(void *param);
      70                 :            : 
      71                 :            : /*
      72                 :            :  * The set of PCI devices this driver supports (for VF)
      73                 :            :  */
      74                 :            : static const struct rte_pci_id pci_id_txgbevf_map[] = {
      75                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_SP1000_VF) },
      76                 :            :         { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_WX1820_VF) },
      77                 :            :         { .vendor_id = 0, /* sentinel */ },
      78                 :            : };
      79                 :            : 
      80                 :            : static const struct rte_eth_desc_lim rx_desc_lim = {
      81                 :            :         .nb_max = TXGBE_RING_DESC_MAX,
      82                 :            :         .nb_min = TXGBE_RING_DESC_MIN,
      83                 :            :         .nb_align = TXGBE_RXD_ALIGN,
      84                 :            : };
      85                 :            : 
      86                 :            : static const struct rte_eth_desc_lim tx_desc_lim = {
      87                 :            :         .nb_max = TXGBE_RING_DESC_MAX,
      88                 :            :         .nb_min = TXGBE_RING_DESC_MIN,
      89                 :            :         .nb_align = TXGBE_TXD_ALIGN,
      90                 :            :         .nb_seg_max = TXGBE_TX_MAX_SEG,
      91                 :            :         .nb_mtu_seg_max = TXGBE_TX_MAX_SEG,
      92                 :            : };
      93                 :            : 
      94                 :            : static const struct eth_dev_ops txgbevf_eth_dev_ops;
      95                 :            : 
      96                 :            : static const struct rte_txgbe_xstats_name_off rte_txgbevf_stats_strings[] = {
      97                 :            :         {"rx_multicast_packets_0",
      98                 :            :                         offsetof(struct txgbevf_hw_stats, qp[0].vfmprc)},
      99                 :            :         {"rx_multicast_packets_1",
     100                 :            :                         offsetof(struct txgbevf_hw_stats, qp[1].vfmprc)},
     101                 :            :         {"rx_multicast_packets_2",
     102                 :            :                         offsetof(struct txgbevf_hw_stats, qp[2].vfmprc)},
     103                 :            :         {"rx_multicast_packets_3",
     104                 :            :                         offsetof(struct txgbevf_hw_stats, qp[3].vfmprc)},
     105                 :            :         {"rx_multicast_packets_4",
     106                 :            :                         offsetof(struct txgbevf_hw_stats, qp[4].vfmprc)},
     107                 :            :         {"rx_multicast_packets_5",
     108                 :            :                         offsetof(struct txgbevf_hw_stats, qp[5].vfmprc)},
     109                 :            :         {"rx_multicast_packets_6",
     110                 :            :                         offsetof(struct txgbevf_hw_stats, qp[6].vfmprc)},
     111                 :            :         {"rx_multicast_packets_7",
     112                 :            :                         offsetof(struct txgbevf_hw_stats, qp[7].vfmprc)}
     113                 :            : };
     114                 :            : 
     115                 :            : #define TXGBEVF_NB_XSTATS (sizeof(rte_txgbevf_stats_strings) /  \
     116                 :            :                 sizeof(rte_txgbevf_stats_strings[0]))
     117                 :            : 
     118                 :            : /*
     119                 :            :  * Negotiate mailbox API version with the PF.
     120                 :            :  * After reset API version is always set to the basic one (txgbe_mbox_api_10).
     121                 :            :  * Then we try to negotiate starting with the most recent one.
     122                 :            :  * If all negotiation attempts fail, then we will proceed with
     123                 :            :  * the default one (txgbe_mbox_api_10).
     124                 :            :  */
     125                 :            : static void
     126                 :          0 : txgbevf_negotiate_api(struct txgbe_hw *hw)
     127                 :            : {
     128                 :            :         int32_t i;
     129                 :            : 
     130                 :            :         /* start with highest supported, proceed down */
     131                 :            :         static const int sup_ver[] = {
     132                 :            :                 txgbe_mbox_api_21,
     133                 :            :                 txgbe_mbox_api_13,
     134                 :            :                 txgbe_mbox_api_12,
     135                 :            :                 txgbe_mbox_api_11,
     136                 :            :                 txgbe_mbox_api_10,
     137                 :            :         };
     138                 :            : 
     139         [ #  # ]:          0 :         for (i = 0; i < ARRAY_SIZE(sup_ver); i++) {
     140         [ #  # ]:          0 :                 if (txgbevf_negotiate_api_version(hw, sup_ver[i]) == 0)
     141                 :            :                         break;
     142                 :            :         }
     143                 :          0 : }
     144                 :            : 
     145                 :            : static void
     146                 :          0 : generate_random_mac_addr(struct rte_ether_addr *mac_addr)
     147                 :            : {
     148                 :            :         uint64_t random;
     149                 :            : 
     150                 :            :         /* Set Organizationally Unique Identifier (OUI) prefix. */
     151                 :            :         mac_addr->addr_bytes[0] = 0x00;
     152                 :          0 :         mac_addr->addr_bytes[1] = 0x09;
     153                 :          0 :         mac_addr->addr_bytes[2] = 0xC0;
     154                 :            :         /* Force indication of locally assigned MAC address. */
     155                 :          0 :         mac_addr->addr_bytes[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;
     156                 :            :         /* Generate the last 3 bytes of the MAC address with a random number. */
     157                 :          0 :         random = rte_rand();
     158                 :          0 :         memcpy(&mac_addr->addr_bytes[3], &random, 3);
     159                 :          0 : }
     160                 :            : 
     161                 :            : int
     162                 :          0 : txgbevf_inject_5tuple_filter(struct rte_eth_dev *dev,
     163                 :            :                              struct txgbe_5tuple_filter *filter)
     164                 :            : {
     165                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
     166                 :            :         uint32_t mask = TXGBE_5TFCTL0_MASK;
     167                 :          0 :         uint16_t index = filter->index;
     168                 :            :         uint32_t msg[TXGBEVF_5T_MAX];
     169                 :            :         int err;
     170                 :            : 
     171                 :            :         memset(msg, 0, sizeof(*msg));
     172                 :            : 
     173                 :            :         /* 0 means compare */
     174                 :            :         mask &= ~TXGBE_5TFCTL0_MPOOL;
     175         [ #  # ]:          0 :         if (filter->filter_info.src_ip_mask == 0)
     176                 :            :                 mask &= ~TXGBE_5TFCTL0_MSADDR;
     177         [ #  # ]:          0 :         if (filter->filter_info.dst_ip_mask == 0)
     178                 :          0 :                 mask &= ~TXGBE_5TFCTL0_MDADDR;
     179         [ #  # ]:          0 :         if (filter->filter_info.src_port_mask == 0)
     180                 :          0 :                 mask &= ~TXGBE_5TFCTL0_MSPORT;
     181         [ #  # ]:          0 :         if (filter->filter_info.dst_port_mask == 0)
     182                 :          0 :                 mask &= ~TXGBE_5TFCTL0_MDPORT;
     183         [ #  # ]:          0 :         if (filter->filter_info.proto_mask == 0)
     184                 :          0 :                 mask &= ~TXGBE_5TFCTL0_MPROTO;
     185                 :            : 
     186                 :            :         msg[TXGBEVF_5T_CTRL0] = mask;
     187                 :          0 :         msg[TXGBEVF_5T_CTRL0] |= TXGBE_5TFCTL0_ENA;
     188                 :          0 :         msg[TXGBEVF_5T_CTRL0] |= TXGBE_5TFCTL0_PROTO(filter->filter_info.proto);
     189                 :          0 :         msg[TXGBEVF_5T_CTRL0] |= TXGBE_5TFCTL0_PRI(filter->filter_info.priority);
     190                 :          0 :         msg[TXGBEVF_5T_CTRL1] = TXGBE_5TFCTL1_QP(filter->queue);
     191         [ #  # ]:          0 :         msg[TXGBEVF_5T_PORT] = TXGBE_5TFPORT_DST(be_to_le16(filter->filter_info.dst_port));
     192         [ #  # ]:          0 :         msg[TXGBEVF_5T_PORT] |= TXGBE_5TFPORT_SRC(be_to_le16(filter->filter_info.src_port));
     193         [ #  # ]:          0 :         msg[TXGBEVF_5T_DA] = be_to_le32(filter->filter_info.dst_ip);
     194         [ #  # ]:          0 :         msg[TXGBEVF_5T_SA] = be_to_le32(filter->filter_info.src_ip);
     195                 :            : 
     196                 :          0 :         err = txgbevf_add_5tuple_filter(hw, msg, index);
     197         [ #  # ]:          0 :         if (err)
     198                 :          0 :                 PMD_DRV_LOG(ERR, "VF request PF to add 5tuple filters failed.");
     199                 :            : 
     200                 :          0 :         return err;
     201                 :            : }
     202                 :            : 
     203                 :            : void
     204                 :          0 : txgbevf_remove_5tuple_filter(struct rte_eth_dev *dev, u16 index)
     205                 :            : {
     206                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
     207                 :            :         int err;
     208                 :            : 
     209                 :          0 :         err = txgbevf_del_5tuple_filter(hw, index);
     210         [ #  # ]:          0 :         if (err)
     211                 :          0 :                 PMD_DRV_LOG(ERR, "VF request PF to delete 5tuple filters failed.");
     212                 :          0 : }
     213                 :            : 
     214                 :            : /*
     215                 :            :  * Virtual Function device init
     216                 :            :  */
     217                 :            : static int
     218                 :          0 : eth_txgbevf_dev_init(struct rte_eth_dev *eth_dev)
     219                 :            : {
     220                 :            :         int err;
     221                 :            :         uint32_t tc, tcs;
     222                 :          0 :         struct txgbe_adapter *ad = eth_dev->data->dev_private;
     223                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
     224                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
     225                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
     226                 :          0 :         struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(eth_dev);
     227                 :          0 :         struct txgbe_hwstrip *hwstrip = TXGBE_DEV_HWSTRIP(eth_dev);
     228                 :          0 :         struct rte_ether_addr *perm_addr =
     229                 :            :                         (struct rte_ether_addr *)hw->mac.perm_addr;
     230                 :          0 :         struct txgbe_filter_info *filter_info = TXGBE_DEV_FILTER(eth_dev);
     231                 :            : 
     232                 :          0 :         PMD_INIT_FUNC_TRACE();
     233                 :            : 
     234                 :          0 :         eth_dev->dev_ops = &txgbevf_eth_dev_ops;
     235                 :          0 :         eth_dev->rx_descriptor_status = txgbe_dev_rx_descriptor_status;
     236                 :          0 :         eth_dev->tx_descriptor_status = txgbe_dev_tx_descriptor_status;
     237                 :          0 :         eth_dev->rx_pkt_burst = &txgbe_recv_pkts;
     238                 :          0 :         eth_dev->tx_pkt_burst = &txgbe_xmit_pkts;
     239                 :            : 
     240                 :            :         /* for secondary processes, we don't initialise any further as primary
     241                 :            :          * has already done this work. Only check we don't need a different
     242                 :            :          * RX function
     243                 :            :          */
     244         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
     245                 :            :                 struct txgbe_tx_queue *txq;
     246                 :          0 :                 uint16_t nb_tx_queues = eth_dev->data->nb_tx_queues;
     247                 :            :                 /* TX queue function in primary, set by last queue initialized
     248                 :            :                  * Tx queue may not initialized by primary process
     249                 :            :                  */
     250         [ #  # ]:          0 :                 if (eth_dev->data->tx_queues) {
     251                 :          0 :                         txq = eth_dev->data->tx_queues[nb_tx_queues - 1];
     252                 :          0 :                         txgbe_set_tx_function(eth_dev, txq);
     253                 :            :                 } else {
     254                 :            :                         /* Use default TX function if we get here */
     255                 :          0 :                         PMD_INIT_LOG(NOTICE,
     256                 :            :                                      "No TX queues configured yet. Using default TX function.");
     257                 :            :                 }
     258                 :            : 
     259                 :          0 :                 txgbe_set_rx_function(eth_dev);
     260                 :            : 
     261                 :          0 :                 return 0;
     262                 :            :         }
     263                 :            : 
     264                 :          0 :         rte_atomic_store_explicit(&ad->link_thread_running, 0, rte_memory_order_seq_cst);
     265                 :          0 :         rte_eth_copy_pci_info(eth_dev, pci_dev);
     266                 :            : 
     267                 :          0 :         hw->device_id = pci_dev->id.device_id;
     268                 :          0 :         hw->vendor_id = pci_dev->id.vendor_id;
     269                 :          0 :         hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
     270                 :          0 :         hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
     271                 :          0 :         hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
     272                 :            : 
     273                 :            :         /* initialize the vfta */
     274                 :            :         memset(shadow_vfta, 0, sizeof(*shadow_vfta));
     275                 :            : 
     276                 :            :         /* initialize the hw strip bitmap*/
     277                 :            :         memset(hwstrip, 0, sizeof(*hwstrip));
     278                 :            : 
     279                 :            :         /* Initialize the shared code (base driver) */
     280                 :          0 :         err = txgbe_init_shared_code(hw);
     281         [ #  # ]:          0 :         if (err != 0) {
     282                 :          0 :                 PMD_INIT_LOG(ERR,
     283                 :            :                         "Shared code init failed for txgbevf: %d", err);
     284                 :          0 :                 return -EIO;
     285                 :            :         }
     286                 :            : 
     287                 :            :         /* init_mailbox_params */
     288                 :          0 :         hw->mbx.init_params(hw);
     289                 :            : 
     290                 :            :         /* Reset the hw statistics */
     291                 :          0 :         txgbevf_dev_stats_reset(eth_dev);
     292                 :            : 
     293                 :            :         /* Disable the interrupts for VF */
     294                 :          0 :         txgbevf_intr_disable(eth_dev);
     295                 :            : 
     296                 :          0 :         hw->mac.num_rar_entries = 128; /* The MAX of the underlying PF */
     297                 :          0 :         err = hw->mac.reset_hw(hw);
     298                 :            : 
     299                 :            :         /*
     300                 :            :          * The VF reset operation returns the TXGBE_ERR_INVALID_MAC_ADDR when
     301                 :            :          * the underlying PF driver has not assigned a MAC address to the VF.
     302                 :            :          * In this case, assign a random MAC address.
     303                 :            :          */
     304         [ #  # ]:          0 :         if (err != 0 && err != TXGBE_ERR_INVALID_MAC_ADDR) {
     305                 :          0 :                 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", err);
     306                 :            :                 /*
     307                 :            :                  * This error code will be propagated to the app by
     308                 :            :                  * rte_eth_dev_reset, so use a public error code rather than
     309                 :            :                  * the internal-only TXGBE_ERR_RESET_FAILED
     310                 :            :                  */
     311                 :          0 :                 return -EAGAIN;
     312                 :            :         }
     313                 :            : 
     314                 :            :         /* negotiate mailbox API version to use with the PF. */
     315                 :          0 :         txgbevf_negotiate_api(hw);
     316                 :            : 
     317                 :            :         /* Get Rx/Tx queue count via mailbox, which is ready after reset_hw */
     318                 :          0 :         txgbevf_get_queues(hw, &tcs, &tc);
     319                 :            : 
     320                 :            :         /* Allocate memory for storing MAC addresses */
     321                 :          0 :         eth_dev->data->mac_addrs = rte_zmalloc("txgbevf", RTE_ETHER_ADDR_LEN *
     322                 :          0 :                                                hw->mac.num_rar_entries, 0);
     323         [ #  # ]:          0 :         if (eth_dev->data->mac_addrs == NULL) {
     324                 :          0 :                 PMD_INIT_LOG(ERR,
     325                 :            :                              "Failed to allocate %u bytes needed to store "
     326                 :            :                              "MAC addresses",
     327                 :            :                              RTE_ETHER_ADDR_LEN * hw->mac.num_rar_entries);
     328                 :          0 :                 return -ENOMEM;
     329                 :            :         }
     330                 :            : 
     331                 :            :         /* Generate a random MAC address, if none was assigned by PF. */
     332         [ #  # ]:          0 :         if (rte_is_zero_ether_addr(perm_addr)) {
     333                 :          0 :                 generate_random_mac_addr(perm_addr);
     334                 :          0 :                 err = txgbe_set_rar_vf(hw, 1, perm_addr->addr_bytes, 0, 1);
     335         [ #  # ]:          0 :                 if (err) {
     336                 :          0 :                         rte_free(eth_dev->data->mac_addrs);
     337                 :          0 :                         eth_dev->data->mac_addrs = NULL;
     338                 :          0 :                         return err;
     339                 :            :                 }
     340                 :          0 :                 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
     341                 :          0 :                 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
     342                 :            :                              RTE_ETHER_ADDR_PRT_FMT,
     343                 :            :                                  RTE_ETHER_ADDR_BYTES(perm_addr));
     344                 :            :         }
     345                 :            : 
     346                 :            :         /* Copy the permanent MAC address */
     347                 :          0 :         rte_ether_addr_copy(perm_addr, &eth_dev->data->mac_addrs[0]);
     348                 :            : 
     349                 :            :         /* reset the hardware with the new settings */
     350                 :          0 :         err = hw->mac.start_hw(hw);
     351         [ #  # ]:          0 :         if (err) {
     352                 :          0 :                 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", err);
     353                 :          0 :                 rte_free(eth_dev->data->mac_addrs);
     354                 :          0 :                 eth_dev->data->mac_addrs = NULL;
     355                 :          0 :                 return -EIO;
     356                 :            :         }
     357                 :            : 
     358                 :            :         /* enter promiscuous mode */
     359                 :            :         txgbevf_dev_promiscuous_enable(eth_dev);
     360                 :            : 
     361                 :          0 :         rte_intr_callback_register(intr_handle,
     362                 :            :                                    txgbevf_dev_interrupt_handler, eth_dev);
     363                 :          0 :         rte_intr_enable(intr_handle);
     364                 :          0 :         txgbevf_intr_enable(eth_dev);
     365                 :            : 
     366                 :            :         /* initialize filter info */
     367                 :            :         memset(filter_info, 0,
     368                 :            :                sizeof(struct txgbe_filter_info));
     369                 :            : 
     370                 :            :         /* initialize 5tuple filter list */
     371                 :          0 :         TAILQ_INIT(&filter_info->fivetuple_list);
     372                 :            : 
     373                 :            :         /* initialize flow filter lists */
     374                 :          0 :         txgbe_filterlist_init();
     375                 :            : 
     376                 :          0 :         PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x mac.type=%s",
     377                 :            :                      eth_dev->data->port_id, pci_dev->id.vendor_id,
     378                 :            :                      pci_dev->id.device_id, "txgbe_mac_raptor_vf");
     379                 :            : 
     380                 :          0 :         return 0;
     381                 :            : }
     382                 :            : 
     383                 :            : /* Virtual Function device uninit */
     384                 :            : static int
     385                 :          0 : eth_txgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
     386                 :            : {
     387                 :          0 :         PMD_INIT_FUNC_TRACE();
     388                 :            : 
     389         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
     390                 :            :                 return 0;
     391                 :            : 
     392                 :          0 :         txgbevf_dev_close(eth_dev);
     393                 :            : 
     394                 :          0 :         return 0;
     395                 :            : }
     396                 :            : 
     397                 :          0 : static int eth_txgbevf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
     398                 :            :         struct rte_pci_device *pci_dev)
     399                 :            : {
     400                 :          0 :         return rte_eth_dev_pci_generic_probe(pci_dev,
     401                 :            :                 sizeof(struct txgbe_adapter), eth_txgbevf_dev_init);
     402                 :            : }
     403                 :            : 
     404                 :          0 : static int eth_txgbevf_pci_remove(struct rte_pci_device *pci_dev)
     405                 :            : {
     406                 :          0 :         return rte_eth_dev_pci_generic_remove(pci_dev, eth_txgbevf_dev_uninit);
     407                 :            : }
     408                 :            : 
     409                 :            : /*
     410                 :            :  * virtual function driver struct
     411                 :            :  */
     412                 :            : static struct rte_pci_driver rte_txgbevf_pmd = {
     413                 :            :         .id_table = pci_id_txgbevf_map,
     414                 :            :         .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
     415                 :            :         .probe = eth_txgbevf_pci_probe,
     416                 :            :         .remove = eth_txgbevf_pci_remove,
     417                 :            : };
     418                 :            : 
     419                 :          0 : static int txgbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
     420                 :            :         struct rte_eth_xstat_name *xstats_names, unsigned int limit)
     421                 :            : {
     422                 :            :         unsigned int i;
     423                 :            : 
     424         [ #  # ]:          0 :         if (limit < TXGBEVF_NB_XSTATS && xstats_names != NULL)
     425                 :            :                 return -ENOMEM;
     426                 :            : 
     427         [ #  # ]:          0 :         if (xstats_names != NULL)
     428         [ #  # ]:          0 :                 for (i = 0; i < TXGBEVF_NB_XSTATS; i++)
     429                 :          0 :                         snprintf(xstats_names[i].name,
     430                 :            :                                 sizeof(xstats_names[i].name),
     431                 :          0 :                                 "%s", rte_txgbevf_stats_strings[i].name);
     432                 :            :         return TXGBEVF_NB_XSTATS;
     433                 :            : }
     434                 :            : 
     435                 :            : static void
     436                 :          0 : txgbevf_update_stats(struct rte_eth_dev *dev)
     437                 :            : {
     438                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
     439                 :            :         struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
     440                 :            :                           TXGBE_DEV_STATS(dev);
     441                 :            :         unsigned int i;
     442                 :            : 
     443         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
     444                 :            :                 /* Good Rx packet, include VF loopback */
     445         [ #  # ]:          0 :                 TXGBE_UPDCNT32(TXGBE_QPRXPKT(i),
     446                 :            :                 hw_stats->qp[i].last_vfgprc, hw_stats->qp[i].vfgprc);
     447                 :            : 
     448                 :            :                 /* Good Rx octets, include VF loopback */
     449         [ #  # ]:          0 :                 TXGBE_UPDCNT36(TXGBE_QPRXOCTL(i),
     450                 :            :                 hw_stats->qp[i].last_vfgorc, hw_stats->qp[i].vfgorc);
     451                 :            : 
     452                 :            :                 /* Rx Multicst Packet */
     453         [ #  # ]:          0 :                 TXGBE_UPDCNT32(TXGBE_QPRXMPKT(i),
     454                 :            :                 hw_stats->qp[i].last_vfmprc, hw_stats->qp[i].vfmprc);
     455                 :            :         }
     456                 :          0 :         hw->rx_loaded = 0;
     457                 :            : 
     458         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
     459                 :            :                 /* Good Tx packet, include VF loopback */
     460         [ #  # ]:          0 :                 TXGBE_UPDCNT32(TXGBE_QPTXPKT(i),
     461                 :            :                 hw_stats->qp[i].last_vfgptc, hw_stats->qp[i].vfgptc);
     462                 :            : 
     463                 :            :                 /* Good Tx octets, include VF loopback */
     464         [ #  # ]:          0 :                 TXGBE_UPDCNT36(TXGBE_QPTXOCTL(i),
     465                 :            :                 hw_stats->qp[i].last_vfgotc, hw_stats->qp[i].vfgotc);
     466                 :            :         }
     467                 :          0 :         hw->offset_loaded = 0;
     468                 :          0 : }
     469                 :            : 
     470                 :            : static int
     471                 :          0 : txgbevf_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
     472                 :            :                        unsigned int n)
     473                 :            : {
     474                 :          0 :         struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
     475                 :          0 :                         TXGBE_DEV_STATS(dev);
     476                 :            :         unsigned int i;
     477                 :            : 
     478         [ #  # ]:          0 :         if (n < TXGBEVF_NB_XSTATS)
     479                 :            :                 return TXGBEVF_NB_XSTATS;
     480                 :            : 
     481                 :          0 :         txgbevf_update_stats(dev);
     482                 :            : 
     483         [ #  # ]:          0 :         if (!xstats)
     484                 :            :                 return 0;
     485                 :            : 
     486                 :            :         /* Extended stats */
     487         [ #  # ]:          0 :         for (i = 0; i < TXGBEVF_NB_XSTATS; i++) {
     488                 :          0 :                 xstats[i].id = i;
     489                 :          0 :                 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
     490                 :          0 :                         rte_txgbevf_stats_strings[i].offset);
     491                 :            :         }
     492                 :            : 
     493                 :            :         return TXGBEVF_NB_XSTATS;
     494                 :            : }
     495                 :            : 
     496                 :            : static int
     497                 :          0 : txgbevf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
     498                 :            : {
     499                 :            :         struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
     500                 :          0 :                           TXGBE_DEV_STATS(dev);
     501                 :            :         uint32_t i;
     502                 :            : 
     503                 :          0 :         txgbevf_update_stats(dev);
     504                 :            : 
     505         [ #  # ]:          0 :         if (stats == NULL)
     506                 :            :                 return -EINVAL;
     507                 :            : 
     508                 :          0 :         stats->ipackets = 0;
     509                 :          0 :         stats->ibytes = 0;
     510                 :          0 :         stats->opackets = 0;
     511                 :          0 :         stats->obytes = 0;
     512                 :            : 
     513         [ #  # ]:          0 :         for (i = 0; i < 8; i++) {
     514                 :          0 :                 stats->ipackets += hw_stats->qp[i].vfgprc;
     515                 :          0 :                 stats->ibytes += hw_stats->qp[i].vfgorc;
     516                 :          0 :                 stats->opackets += hw_stats->qp[i].vfgptc;
     517                 :          0 :                 stats->obytes += hw_stats->qp[i].vfgotc;
     518                 :            :         }
     519                 :            : 
     520                 :            :         return 0;
     521                 :            : }
     522                 :            : 
     523                 :            : static int
     524                 :          0 : txgbevf_dev_stats_reset(struct rte_eth_dev *dev)
     525                 :            : {
     526                 :            :         struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
     527                 :          0 :                         TXGBE_DEV_STATS(dev);
     528                 :            :         uint32_t i;
     529                 :            : 
     530                 :            :         /* Sync HW register to the last stats */
     531                 :            :         txgbevf_dev_stats_get(dev, NULL);
     532                 :            : 
     533                 :            :         /* reset HW current stats*/
     534         [ #  # ]:          0 :         for (i = 0; i < 8; i++) {
     535                 :          0 :                 hw_stats->qp[i].vfgprc = 0;
     536                 :          0 :                 hw_stats->qp[i].vfgorc = 0;
     537                 :          0 :                 hw_stats->qp[i].vfgptc = 0;
     538                 :          0 :                 hw_stats->qp[i].vfgotc = 0;
     539                 :            :         }
     540                 :            : 
     541                 :          0 :         return 0;
     542                 :            : }
     543                 :            : 
     544                 :            : static int
     545                 :          0 : txgbevf_dev_info_get(struct rte_eth_dev *dev,
     546                 :            :                      struct rte_eth_dev_info *dev_info)
     547                 :            : {
     548                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
     549                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
     550                 :            : 
     551                 :          0 :         dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
     552                 :          0 :         dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
     553                 :          0 :         dev_info->min_rx_bufsize = 1024;
     554                 :          0 :         dev_info->max_rx_pktlen = TXGBE_FRAME_SIZE_MAX;
     555                 :          0 :         dev_info->max_mac_addrs = hw->mac.num_rar_entries;
     556                 :          0 :         dev_info->max_hash_mac_addrs = TXGBE_VMDQ_NUM_UC_MAC;
     557                 :          0 :         dev_info->max_vfs = pci_dev->max_vfs;
     558                 :          0 :         dev_info->max_vmdq_pools = RTE_ETH_64_POOLS;
     559                 :          0 :         dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
     560                 :          0 :         dev_info->rx_queue_offload_capa = txgbe_get_rx_queue_offloads(dev);
     561                 :          0 :         dev_info->rx_offload_capa = (txgbe_get_rx_port_offloads(dev) |
     562                 :          0 :                                      dev_info->rx_queue_offload_capa);
     563                 :          0 :         dev_info->tx_queue_offload_capa = txgbe_get_tx_queue_offloads(dev);
     564                 :          0 :         dev_info->tx_offload_capa = txgbe_get_tx_port_offloads(dev);
     565                 :          0 :         dev_info->hash_key_size = TXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
     566                 :          0 :         dev_info->reta_size = RTE_ETH_RSS_RETA_SIZE_128;
     567                 :          0 :         dev_info->flow_type_rss_offloads = TXGBE_RSS_OFFLOAD_ALL;
     568                 :            : 
     569                 :          0 :         dev_info->default_rxconf = (struct rte_eth_rxconf) {
     570                 :            :                 .rx_thresh = {
     571                 :            :                         .pthresh = TXGBE_DEFAULT_RX_PTHRESH,
     572                 :            :                         .hthresh = TXGBE_DEFAULT_RX_HTHRESH,
     573                 :            :                         .wthresh = TXGBE_DEFAULT_RX_WTHRESH,
     574                 :            :                 },
     575                 :            :                 .rx_free_thresh = TXGBE_DEFAULT_RX_FREE_THRESH,
     576                 :            :                 .rx_drop_en = 0,
     577                 :            :                 .offloads = 0,
     578                 :            :         };
     579                 :            : 
     580                 :          0 :         dev_info->default_txconf = (struct rte_eth_txconf) {
     581                 :            :                 .tx_thresh = {
     582                 :            :                         .pthresh = TXGBE_DEFAULT_TX_PTHRESH,
     583                 :            :                         .hthresh = TXGBE_DEFAULT_TX_HTHRESH,
     584                 :            :                         .wthresh = TXGBE_DEFAULT_TX_WTHRESH,
     585                 :            :                 },
     586                 :            :                 .tx_free_thresh = TXGBE_DEFAULT_TX_FREE_THRESH,
     587                 :            :                 .offloads = 0,
     588                 :            :         };
     589                 :            : 
     590                 :          0 :         dev_info->rx_desc_lim = rx_desc_lim;
     591                 :          0 :         dev_info->tx_desc_lim = tx_desc_lim;
     592                 :            : 
     593                 :          0 :         dev_info->err_handle_mode = RTE_ETH_ERROR_HANDLE_MODE_PASSIVE;
     594                 :            : 
     595                 :          0 :         return 0;
     596                 :            : }
     597                 :            : 
     598                 :            : static int
     599                 :          0 : txgbevf_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
     600                 :            : {
     601                 :          0 :         return txgbe_dev_link_update_share(dev, wait_to_complete);
     602                 :            : }
     603                 :            : 
     604                 :            : /*
     605                 :            :  * Virtual Function operations
     606                 :            :  */
     607                 :            : static void
     608                 :          0 : txgbevf_intr_disable(struct rte_eth_dev *dev)
     609                 :            : {
     610                 :          0 :         struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
     611                 :            :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
     612                 :            : 
     613                 :          0 :         PMD_INIT_FUNC_TRACE();
     614                 :            : 
     615                 :            :         /* Clear interrupt mask to stop from interrupts being generated */
     616                 :            :         wr32(hw, TXGBE_VFIMS, TXGBE_VFIMS_MASK);
     617                 :            : 
     618                 :            :         txgbe_flush(hw);
     619                 :            : 
     620                 :            :         /* Clear mask value. */
     621                 :          0 :         intr->mask_misc = TXGBE_VFIMS_MASK;
     622                 :          0 : }
     623                 :            : 
     624                 :            : static void
     625                 :          0 : txgbevf_intr_enable(struct rte_eth_dev *dev)
     626                 :            : {
     627                 :          0 :         struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
     628                 :            :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
     629                 :            : 
     630                 :          0 :         PMD_INIT_FUNC_TRACE();
     631                 :            : 
     632                 :            :         /* VF enable interrupt autoclean */
     633                 :            :         wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
     634                 :            : 
     635                 :            :         txgbe_flush(hw);
     636                 :            : 
     637                 :          0 :         intr->mask_misc = 0;
     638                 :          0 : }
     639                 :            : 
     640                 :            : static int
     641                 :          0 : txgbevf_dev_configure(struct rte_eth_dev *dev)
     642                 :            : {
     643                 :          0 :         struct rte_eth_conf *conf = &dev->data->dev_conf;
     644                 :          0 :         struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
     645                 :            : 
     646                 :          0 :         PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
     647                 :            :                      dev->data->port_id);
     648                 :            : 
     649         [ #  # ]:          0 :         if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
     650                 :          0 :                 dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
     651                 :            : 
     652                 :            :         /*
     653                 :            :          * VF has no ability to enable/disable HW CRC
     654                 :            :          * Keep the persistent behavior the same as Host PF
     655                 :            :          */
     656                 :            : #ifndef RTE_LIBRTE_TXGBE_PF_DISABLE_STRIP_CRC
     657         [ #  # ]:          0 :         if (conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
     658                 :          0 :                 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
     659                 :          0 :                 conf->rxmode.offloads &= ~RTE_ETH_RX_OFFLOAD_KEEP_CRC;
     660                 :            :         }
     661                 :            : #else
     662                 :            :         if (!(conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)) {
     663                 :            :                 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
     664                 :            :                 conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_KEEP_CRC;
     665                 :            :         }
     666                 :            : #endif
     667                 :            : 
     668                 :            :         /*
     669                 :            :          * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
     670                 :            :          * allocation or vector Rx preconditions we will reset it.
     671                 :            :          */
     672                 :          0 :         adapter->rx_bulk_alloc_allowed = true;
     673                 :          0 :         adapter->rx_vec_allowed = true;
     674                 :            : 
     675                 :          0 :         return 0;
     676                 :            : }
     677                 :            : 
     678                 :            : static int
     679                 :          0 : txgbevf_dev_start(struct rte_eth_dev *dev)
     680                 :            : {
     681                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
     682                 :            :         uint32_t intr_vector = 0;
     683                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
     684                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
     685                 :            : 
     686                 :            :         int err, mask = 0;
     687                 :            : 
     688                 :          0 :         PMD_INIT_FUNC_TRACE();
     689                 :            : 
     690                 :            :         /* Stop the link setup handler before resetting the HW. */
     691                 :          0 :         txgbe_dev_wait_setup_link_complete(dev, 0);
     692                 :            : 
     693                 :          0 :         err = hw->mac.reset_hw(hw);
     694         [ #  # ]:          0 :         if (err) {
     695                 :          0 :                 PMD_INIT_LOG(ERR, "Unable to reset vf hardware (%d)", err);
     696                 :          0 :                 return err;
     697                 :            :         }
     698                 :          0 :         hw->mac.get_link_status = true;
     699                 :          0 :         hw->dev_start = true;
     700                 :            : 
     701                 :            :         /* negotiate mailbox API version to use with the PF. */
     702                 :          0 :         txgbevf_negotiate_api(hw);
     703                 :            : 
     704                 :          0 :         txgbevf_dev_tx_init(dev);
     705                 :            : 
     706                 :            :         /* This can fail when allocating mbufs for descriptor rings */
     707                 :          0 :         err = txgbevf_dev_rx_init(dev);
     708                 :            : 
     709                 :            :         /**
     710                 :            :          * In this case, reuses the MAC address assigned by VF
     711                 :            :          * initialization.
     712                 :            :          */
     713         [ #  # ]:          0 :         if (err != 0 && err != TXGBE_ERR_INVALID_MAC_ADDR) {
     714                 :          0 :                 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware (%d)", err);
     715                 :          0 :                 txgbe_dev_clear_queues(dev);
     716                 :          0 :                 return err;
     717                 :            :         }
     718                 :            : 
     719                 :            :         /* Set vfta */
     720                 :          0 :         txgbevf_set_vfta_all(dev, 1);
     721                 :            : 
     722                 :            :         /* Set HW strip */
     723                 :            :         mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
     724                 :            :                 RTE_ETH_VLAN_EXTEND_MASK;
     725                 :          0 :         err = txgbevf_vlan_offload_config(dev, mask);
     726         [ #  # ]:          0 :         if (err) {
     727                 :          0 :                 PMD_INIT_LOG(ERR, "Unable to set VLAN offload (%d)", err);
     728                 :          0 :                 txgbe_dev_clear_queues(dev);
     729                 :          0 :                 return err;
     730                 :            :         }
     731                 :            : 
     732                 :          0 :         txgbevf_dev_rxtx_start(dev);
     733                 :            : 
     734                 :            :         /* check and configure queue intr-vector mapping */
     735         [ #  # ]:          0 :         if (rte_intr_cap_multiple(intr_handle) &&
     736         [ #  # ]:          0 :             dev->data->dev_conf.intr_conf.rxq) {
     737                 :            :                 /* According to datasheet, only vector 0/1/2 can be used,
     738                 :            :                  * now only one vector is used for Rx queue
     739                 :            :                  */
     740                 :            :                 intr_vector = 1;
     741         [ #  # ]:          0 :                 if (rte_intr_efd_enable(intr_handle, intr_vector)) {
     742                 :          0 :                         txgbe_dev_clear_queues(dev);
     743                 :          0 :                         return -1;
     744                 :            :                 }
     745                 :            :         }
     746                 :            : 
     747         [ #  # ]:          0 :         if (rte_intr_dp_is_en(intr_handle)) {
     748         [ #  # ]:          0 :                 if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
     749                 :          0 :                                                    dev->data->nb_rx_queues)) {
     750                 :          0 :                         PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
     751                 :            :                                      " intr_vec", dev->data->nb_rx_queues);
     752                 :          0 :                         txgbe_dev_clear_queues(dev);
     753                 :          0 :                         return -ENOMEM;
     754                 :            :                 }
     755                 :            :         }
     756                 :          0 :         txgbevf_configure_msix(dev);
     757                 :            : 
     758                 :            :         /* When a VF port is bound to VFIO-PCI, only miscellaneous interrupt
     759                 :            :          * is mapped to VFIO vector 0 in eth_txgbevf_dev_init( ).
     760                 :            :          * If previous VFIO interrupt mapping setting in eth_txgbevf_dev_init( )
     761                 :            :          * is not cleared, it will fail when following rte_intr_enable( ) tries
     762                 :            :          * to map Rx queue interrupt to other VFIO vectors.
     763                 :            :          * So clear uio/vfio intr/evevnfd first to avoid failure.
     764                 :            :          */
     765                 :          0 :         rte_intr_disable(intr_handle);
     766                 :            : 
     767                 :          0 :         rte_intr_enable(intr_handle);
     768                 :            : 
     769                 :            :         /* Re-enable interrupt for VF */
     770                 :          0 :         txgbevf_intr_enable(dev);
     771                 :            : 
     772                 :            :         /*
     773                 :            :          * Update link status right before return, because it may
     774                 :            :          * start link configuration process in a separate thread.
     775                 :            :          */
     776                 :            :         txgbevf_dev_link_update(dev, 0);
     777                 :            : 
     778                 :          0 :         hw->adapter_stopped = false;
     779                 :            : 
     780                 :          0 :         return 0;
     781                 :            : }
     782                 :            : 
     783                 :            : static int
     784                 :          0 : txgbevf_dev_stop(struct rte_eth_dev *dev)
     785                 :            : {
     786                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
     787                 :            :         struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
     788                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
     789                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
     790                 :            : 
     791         [ #  # ]:          0 :         if (hw->adapter_stopped)
     792                 :            :                 return 0;
     793                 :            : 
     794                 :          0 :         PMD_INIT_FUNC_TRACE();
     795                 :            : 
     796                 :          0 :         txgbe_dev_wait_setup_link_complete(dev, 0);
     797                 :            : 
     798                 :          0 :         txgbevf_intr_disable(dev);
     799                 :            : 
     800                 :          0 :         hw->adapter_stopped = 1;
     801                 :          0 :         hw->mac.stop_hw(hw);
     802                 :            : 
     803                 :            :         /*
     804                 :            :          * Clear what we set, but we still keep shadow_vfta to
     805                 :            :          * restore after device starts
     806                 :            :          */
     807                 :          0 :         txgbevf_set_vfta_all(dev, 0);
     808                 :            : 
     809                 :            :         /* Clear stored conf */
     810                 :          0 :         dev->data->scattered_rx = 0;
     811                 :            : 
     812                 :          0 :         txgbe_dev_clear_queues(dev);
     813                 :            : 
     814                 :            :         /* Clean datapath event and queue/vec mapping */
     815                 :          0 :         rte_intr_efd_disable(intr_handle);
     816                 :          0 :         rte_intr_vec_list_free(intr_handle);
     817                 :            : 
     818                 :          0 :         adapter->rss_reta_updated = 0;
     819                 :          0 :         hw->dev_start = false;
     820                 :            : 
     821                 :          0 :         return 0;
     822                 :            : }
     823                 :            : 
     824                 :            : static int
     825                 :          0 : txgbevf_dev_close(struct rte_eth_dev *dev)
     826                 :            : {
     827                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
     828                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
     829                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
     830                 :            :         int ret;
     831                 :            : 
     832                 :          0 :         PMD_INIT_FUNC_TRACE();
     833         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
     834                 :            :                 return 0;
     835                 :            : 
     836                 :          0 :         hw->mac.reset_hw(hw);
     837                 :            : 
     838                 :          0 :         ret = txgbevf_dev_stop(dev);
     839                 :            : 
     840                 :          0 :         txgbe_dev_free_queues(dev);
     841                 :            : 
     842                 :            :         /**
     843                 :            :          * Remove the VF MAC address ro ensure
     844                 :            :          * that the VF traffic goes to the PF
     845                 :            :          * after stop, close and detach of the VF
     846                 :            :          **/
     847                 :          0 :         txgbevf_remove_mac_addr(dev, 0);
     848                 :            : 
     849                 :          0 :         dev->rx_pkt_burst = NULL;
     850                 :          0 :         dev->tx_pkt_burst = NULL;
     851                 :            : 
     852                 :            :         /* Disable the interrupts for VF */
     853                 :          0 :         txgbevf_intr_disable(dev);
     854                 :            : 
     855                 :          0 :         rte_free(dev->data->mac_addrs);
     856                 :          0 :         dev->data->mac_addrs = NULL;
     857                 :            : 
     858                 :          0 :         rte_intr_disable(intr_handle);
     859                 :          0 :         rte_intr_callback_unregister(intr_handle,
     860                 :            :                                      txgbevf_dev_interrupt_handler, dev);
     861                 :            : 
     862                 :            :         /* Remove all ntuple filters of the device */
     863                 :          0 :         txgbe_ntuple_filter_uninit(dev);
     864                 :            : 
     865                 :            :         /* clear all the filters list */
     866                 :          0 :         txgbe_filterlist_flush();
     867                 :            : 
     868                 :          0 :         return ret;
     869                 :            : }
     870                 :            : 
     871                 :            : /*
     872                 :            :  * Reset VF device
     873                 :            :  */
     874                 :            : static int
     875                 :          0 : txgbevf_dev_reset(struct rte_eth_dev *dev)
     876                 :            : {
     877                 :            :         int ret;
     878                 :            : 
     879                 :          0 :         ret = eth_txgbevf_dev_uninit(dev);
     880         [ #  # ]:          0 :         if (ret)
     881                 :            :                 return ret;
     882                 :            : 
     883                 :          0 :         ret = eth_txgbevf_dev_init(dev);
     884                 :            : 
     885                 :          0 :         return ret;
     886                 :            : }
     887                 :            : 
     888                 :          0 : static void txgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
     889                 :            : {
     890                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
     891                 :            :         struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(dev);
     892                 :            :         int i = 0, j = 0, vfta = 0, mask = 1;
     893                 :            : 
     894         [ #  # ]:          0 :         for (i = 0; i < TXGBE_VFTA_SIZE; i++) {
     895                 :          0 :                 vfta = shadow_vfta->vfta[i];
     896         [ #  # ]:          0 :                 if (vfta) {
     897                 :            :                         mask = 1;
     898         [ #  # ]:          0 :                         for (j = 0; j < 32; j++) {
     899         [ #  # ]:          0 :                                 if (vfta & mask)
     900                 :          0 :                                         hw->mac.set_vfta(hw, (i << 5) + j, 0,
     901                 :            :                                                        on, false);
     902                 :          0 :                                 mask <<= 1;
     903                 :            :                         }
     904                 :            :                 }
     905                 :            :         }
     906                 :          0 : }
     907                 :            : 
     908                 :            : static int
     909                 :          0 : txgbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
     910                 :            : {
     911                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
     912                 :            :         struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(dev);
     913                 :            :         uint32_t vid_idx = 0;
     914                 :            :         uint32_t vid_bit = 0;
     915                 :            :         int ret = 0;
     916                 :            : 
     917                 :          0 :         PMD_INIT_FUNC_TRACE();
     918                 :            : 
     919                 :            :         /* vind is not used in VF driver, set to 0, check txgbe_set_vfta_vf */
     920                 :          0 :         ret = hw->mac.set_vfta(hw, vlan_id, 0, !!on, false);
     921         [ #  # ]:          0 :         if (ret) {
     922                 :          0 :                 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
     923                 :          0 :                 return ret;
     924                 :            :         }
     925                 :          0 :         vid_idx = (uint32_t)((vlan_id >> 5) & 0x7F);
     926                 :          0 :         vid_bit = (uint32_t)(1 << (vlan_id & 0x1F));
     927                 :            : 
     928                 :            :         /* Save what we set and restore it after device reset */
     929         [ #  # ]:          0 :         if (on)
     930                 :          0 :                 shadow_vfta->vfta[vid_idx] |= vid_bit;
     931                 :            :         else
     932                 :          0 :                 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
     933                 :            : 
     934                 :            :         return 0;
     935                 :            : }
     936                 :            : 
     937                 :            : static void
     938                 :          0 : txgbevf_vlan_strip_q_set(struct rte_eth_dev *dev, uint16_t queue, int on)
     939                 :            : {
     940                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
     941                 :            :         uint32_t ctrl;
     942                 :            : 
     943                 :          0 :         PMD_INIT_FUNC_TRACE();
     944                 :            : 
     945         [ #  # ]:          0 :         if (queue >= hw->mac.max_rx_queues)
     946                 :            :                 return;
     947                 :            : 
     948                 :          0 :         ctrl = rd32(hw, TXGBE_RXCFG(queue));
     949         [ #  # ]:          0 :         if (on)
     950                 :          0 :                 ctrl |= TXGBE_RXCFG_VLAN;
     951                 :            :         else
     952                 :          0 :                 ctrl &= ~TXGBE_RXCFG_VLAN;
     953                 :            :         wr32(hw, TXGBE_RXCFG(queue), ctrl);
     954                 :            : 
     955                 :          0 :         txgbe_vlan_hw_strip_bitmap_set(dev, queue, on);
     956                 :            : }
     957                 :            : 
     958                 :            : static void
     959                 :          0 : txgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
     960                 :            : {
     961                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
     962                 :            : 
     963         [ #  # ]:          0 :         if (!hw->adapter_stopped) {
     964                 :          0 :                 PMD_DRV_LOG(ERR, "Please stop port first");
     965                 :          0 :                 return;
     966                 :            :         }
     967                 :            : 
     968                 :          0 :         txgbevf_vlan_strip_q_set(dev, queue, on);
     969                 :            : }
     970                 :            : 
     971                 :            : static int
     972                 :          0 : txgbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask)
     973                 :            : {
     974                 :            :         struct txgbe_rx_queue *rxq;
     975                 :            :         uint16_t i;
     976                 :            :         int on = 0;
     977                 :            : 
     978                 :            :         /* VF function only support hw strip feature, others are not support */
     979         [ #  # ]:          0 :         if (mask & RTE_ETH_VLAN_STRIP_MASK) {
     980         [ #  # ]:          0 :                 for (i = 0; i < dev->data->nb_rx_queues; i++) {
     981                 :          0 :                         rxq = dev->data->rx_queues[i];
     982                 :          0 :                         on = !!(rxq->offloads &  RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
     983                 :          0 :                         txgbevf_vlan_strip_q_set(dev, i, on);
     984                 :            :                 }
     985                 :            :         }
     986                 :            : 
     987                 :          0 :         return 0;
     988                 :            : }
     989                 :            : 
     990                 :            : static int
     991                 :          0 : txgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
     992                 :            : {
     993                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
     994                 :            : 
     995   [ #  #  #  # ]:          0 :         if (!hw->adapter_stopped && (mask & RTE_ETH_VLAN_STRIP_MASK)) {
     996                 :          0 :                 PMD_DRV_LOG(ERR, "Please stop port first");
     997                 :          0 :                 return -EPERM;
     998                 :            :         }
     999                 :            : 
    1000                 :          0 :         txgbe_config_vlan_strip_on_all_queues(dev, mask);
    1001                 :            : 
    1002                 :          0 :         txgbevf_vlan_offload_config(dev, mask);
    1003                 :            : 
    1004                 :          0 :         return 0;
    1005                 :            : }
    1006                 :            : 
    1007                 :            : static int
    1008                 :          0 : txgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
    1009                 :            : {
    1010                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    1011                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    1012                 :          0 :         struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
    1013                 :            :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    1014                 :            :         uint32_t vec = TXGBE_MISC_VEC_ID;
    1015                 :            : 
    1016         [ #  # ]:          0 :         if (rte_intr_allow_others(intr_handle))
    1017                 :            :                 vec = TXGBE_RX_VEC_START;
    1018                 :          0 :         intr->mask_misc &= ~(1 << vec);
    1019                 :            :         RTE_SET_USED(queue_id);
    1020                 :          0 :         wr32(hw, TXGBE_VFIMC, ~intr->mask_misc);
    1021                 :            : 
    1022                 :          0 :         rte_intr_enable(intr_handle);
    1023                 :            : 
    1024                 :          0 :         return 0;
    1025                 :            : }
    1026                 :            : 
    1027                 :            : static int
    1028                 :          0 : txgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
    1029                 :            : {
    1030                 :          0 :         struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
    1031                 :            :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    1032                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    1033                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    1034                 :            :         uint32_t vec = TXGBE_MISC_VEC_ID;
    1035                 :            : 
    1036         [ #  # ]:          0 :         if (rte_intr_allow_others(intr_handle))
    1037                 :            :                 vec = TXGBE_RX_VEC_START;
    1038                 :          0 :         intr->mask_misc |= (1 << vec);
    1039                 :            :         RTE_SET_USED(queue_id);
    1040                 :            :         wr32(hw, TXGBE_VFIMS, intr->mask_misc);
    1041                 :            : 
    1042                 :          0 :         return 0;
    1043                 :            : }
    1044                 :            : 
    1045                 :            : static void
    1046                 :          0 : txgbevf_set_ivar_map(struct txgbe_hw *hw, int8_t direction,
    1047                 :            :                      uint8_t queue, uint8_t msix_vector)
    1048                 :            : {
    1049                 :            :         uint32_t tmp, idx;
    1050                 :            : 
    1051         [ #  # ]:          0 :         if (direction == -1) {
    1052                 :            :                 /* other causes */
    1053                 :          0 :                 msix_vector |= TXGBE_VFIVAR_VLD;
    1054                 :            :                 tmp = rd32(hw, TXGBE_VFIVARMISC);
    1055                 :          0 :                 tmp &= ~0xFF;
    1056                 :          0 :                 tmp |= msix_vector;
    1057                 :            :                 wr32(hw, TXGBE_VFIVARMISC, tmp);
    1058                 :            :         } else {
    1059                 :            :                 /* rx or tx cause */
    1060                 :          0 :                 msix_vector |= TXGBE_VFIVAR_VLD; /* Workaround for ICR lost */
    1061                 :          0 :                 idx = ((16 * (queue & 1)) + (8 * direction));
    1062                 :          0 :                 tmp = rd32(hw, TXGBE_VFIVAR(queue >> 1));
    1063                 :          0 :                 tmp &= ~(0xFF << idx);
    1064                 :          0 :                 tmp |= (msix_vector << idx);
    1065                 :            :                 wr32(hw, TXGBE_VFIVAR(queue >> 1), tmp);
    1066                 :            :         }
    1067                 :          0 : }
    1068                 :            : 
    1069                 :            : static void
    1070                 :          0 : txgbevf_configure_msix(struct rte_eth_dev *dev)
    1071                 :            : {
    1072                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    1073                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    1074                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    1075                 :            :         uint32_t q_idx;
    1076                 :            :         uint32_t vector_idx = TXGBE_MISC_VEC_ID;
    1077                 :            :         uint32_t base = TXGBE_MISC_VEC_ID;
    1078                 :            : 
    1079                 :            :         /* Configure VF other cause ivar */
    1080                 :            :         txgbevf_set_ivar_map(hw, -1, 1, vector_idx);
    1081                 :            : 
    1082                 :            :         /* won't configure msix register if no mapping is done
    1083                 :            :          * between intr vector and event fd.
    1084                 :            :          */
    1085         [ #  # ]:          0 :         if (!rte_intr_dp_is_en(intr_handle))
    1086                 :            :                 return;
    1087                 :            : 
    1088         [ #  # ]:          0 :         if (rte_intr_allow_others(intr_handle)) {
    1089                 :            :                 base = TXGBE_RX_VEC_START;
    1090                 :            :                 vector_idx = TXGBE_RX_VEC_START;
    1091                 :            :         }
    1092                 :            : 
    1093                 :            :         /* Configure all RX queues of VF */
    1094         [ #  # ]:          0 :         for (q_idx = 0; q_idx < dev->data->nb_rx_queues; q_idx++) {
    1095                 :            :                 /* Force all queue use vector 0,
    1096                 :            :                  * as TXGBE_VF_MAXMSIVECTOR = 1
    1097                 :            :                  */
    1098                 :          0 :                 txgbevf_set_ivar_map(hw, 0, q_idx, vector_idx);
    1099                 :          0 :                 rte_intr_vec_list_index_set(intr_handle, q_idx,
    1100                 :            :                                                    vector_idx);
    1101                 :          0 :                 if (vector_idx < base + rte_intr_nb_efd_get(intr_handle)
    1102         [ #  # ]:          0 :                     - 1)
    1103                 :          0 :                         vector_idx++;
    1104                 :            :         }
    1105                 :            : 
    1106                 :            :         /* As RX queue setting above show, all queues use the vector 0.
    1107                 :            :          * Set only the ITR value of TXGBE_MISC_VEC_ID.
    1108                 :            :          */
    1109                 :            :         wr32(hw, TXGBE_ITR(TXGBE_MISC_VEC_ID),
    1110                 :            :                 TXGBE_ITR_IVAL(TXGBE_QUEUE_ITR_INTERVAL_DEFAULT)
    1111                 :            :                 | TXGBE_ITR_WRDSA);
    1112                 :            : }
    1113                 :            : 
    1114                 :            : static int
    1115                 :          0 : txgbevf_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
    1116                 :            :                      __rte_unused uint32_t index,
    1117                 :            :                      __rte_unused uint32_t pool)
    1118                 :            : {
    1119                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    1120                 :            :         int err;
    1121                 :            : 
    1122                 :            :         /*
    1123                 :            :          * On a VF, adding again the same MAC addr is not an idempotent
    1124                 :            :          * operation. Trap this case to avoid exhausting the [very limited]
    1125                 :            :          * set of PF resources used to store VF MAC addresses.
    1126                 :            :          */
    1127         [ #  # ]:          0 :         if (memcmp(hw->mac.perm_addr, mac_addr,
    1128                 :            :                         sizeof(struct rte_ether_addr)) == 0)
    1129                 :            :                 return -1;
    1130                 :          0 :         err = txgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
    1131         [ #  # ]:          0 :         if (err != 0)
    1132                 :          0 :                 PMD_DRV_LOG(ERR, "Unable to add MAC address "
    1133                 :            :                             RTE_ETHER_ADDR_PRT_FMT " - err=%d",
    1134                 :            :                             RTE_ETHER_ADDR_BYTES(mac_addr), err);
    1135                 :            :         return err;
    1136                 :            : }
    1137                 :            : 
    1138                 :            : static void
    1139                 :          0 : txgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
    1140                 :            : {
    1141                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    1142                 :          0 :         struct rte_ether_addr *perm_addr =
    1143                 :            :                         (struct rte_ether_addr *)hw->mac.perm_addr;
    1144                 :            :         struct rte_ether_addr *mac_addr;
    1145                 :            :         uint32_t i;
    1146                 :            :         int err;
    1147                 :            : 
    1148                 :            :         /*
    1149                 :            :          * The TXGBE_VF_SET_MACVLAN command of the txgbe-pf driver does
    1150                 :            :          * not support the deletion of a given MAC address.
    1151                 :            :          * Instead, it imposes to delete all MAC addresses, then to add again
    1152                 :            :          * all MAC addresses with the exception of the one to be deleted.
    1153                 :            :          */
    1154                 :          0 :         (void)txgbevf_set_uc_addr_vf(hw, 0, NULL);
    1155                 :            : 
    1156                 :            :         /*
    1157                 :            :          * Add again all MAC addresses, with the exception of the deleted one
    1158                 :            :          * and of the permanent MAC address.
    1159                 :            :          */
    1160                 :          0 :         for (i = 0, mac_addr = dev->data->mac_addrs;
    1161         [ #  # ]:          0 :              i < hw->mac.num_rar_entries; i++, mac_addr++) {
    1162                 :            :                 /* Skip the deleted MAC address */
    1163         [ #  # ]:          0 :                 if (i == index)
    1164                 :          0 :                         continue;
    1165                 :            :                 /* Skip NULL MAC addresses */
    1166         [ #  # ]:          0 :                 if (rte_is_zero_ether_addr(mac_addr))
    1167                 :          0 :                         continue;
    1168                 :            :                 /* Skip the permanent MAC address */
    1169         [ #  # ]:          0 :                 if (memcmp(perm_addr, mac_addr,
    1170                 :            :                                 sizeof(struct rte_ether_addr)) == 0)
    1171                 :          0 :                         continue;
    1172                 :          0 :                 err = txgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
    1173         [ #  # ]:          0 :                 if (err != 0)
    1174                 :          0 :                         PMD_DRV_LOG(ERR,
    1175                 :            :                                     "Adding again MAC address "
    1176                 :            :                                     RTE_ETHER_ADDR_PRT_FMT " failed "
    1177                 :            :                                     "err=%d",
    1178                 :            :                                     RTE_ETHER_ADDR_BYTES(mac_addr), err);
    1179                 :            :         }
    1180                 :          0 : }
    1181                 :            : 
    1182                 :            : static int
    1183                 :          0 : txgbevf_set_default_mac_addr(struct rte_eth_dev *dev,
    1184                 :            :                 struct rte_ether_addr *addr)
    1185                 :            : {
    1186                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    1187                 :            : 
    1188                 :          0 :         hw->mac.set_rar(hw, 0, (void *)addr, 0, 0);
    1189                 :            : 
    1190                 :          0 :         return 0;
    1191                 :            : }
    1192                 :            : 
    1193                 :            : static int
    1194                 :          0 : txgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
    1195                 :            : {
    1196                 :            :         struct txgbe_hw *hw;
    1197                 :          0 :         uint32_t max_frame = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
    1198                 :          0 :         struct rte_eth_dev_data *dev_data = dev->data;
    1199                 :            : 
    1200                 :          0 :         hw = TXGBE_DEV_HW(dev);
    1201                 :            : 
    1202                 :          0 :         if (mtu < RTE_ETHER_MIN_MTU ||
    1203         [ #  # ]:          0 :                         max_frame > RTE_ETHER_MAX_JUMBO_FRAME_LEN)
    1204                 :            :                 return -EINVAL;
    1205                 :            : 
    1206                 :            :         /* If device is started, refuse mtu that requires the support of
    1207                 :            :          * scattered packets when this feature has not been enabled before.
    1208                 :            :          */
    1209         [ #  # ]:          0 :         if (dev_data->dev_started && !dev_data->scattered_rx &&
    1210                 :          0 :             (max_frame + 2 * RTE_VLAN_HLEN >
    1211         [ #  # ]:          0 :              dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
    1212                 :          0 :                 PMD_INIT_LOG(ERR, "Stop port first.");
    1213                 :          0 :                 return -EINVAL;
    1214                 :            :         }
    1215                 :            : 
    1216                 :            :         /*
    1217                 :            :          * When supported by the underlying PF driver, use the TXGBE_VF_SET_MTU
    1218                 :            :          * request of the version 2.0 of the mailbox API.
    1219                 :            :          * For now, use the TXGBE_VF_SET_LPE request of the version 1.0
    1220                 :            :          * of the mailbox API.
    1221                 :            :          */
    1222         [ #  # ]:          0 :         if (txgbevf_rlpml_set_vf(hw, max_frame))
    1223                 :          0 :                 return -EINVAL;
    1224                 :            : 
    1225                 :            :         return 0;
    1226                 :            : }
    1227                 :            : 
    1228                 :            : static int
    1229                 :            : txgbevf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
    1230                 :            : {
    1231                 :            :         int count = 0;
    1232                 :            :         int g_ind = 0;
    1233                 :            :         const struct reg_info *reg_group;
    1234                 :            : 
    1235   [ #  #  #  # ]:          0 :         while ((reg_group = txgbevf_regs[g_ind++]))
    1236                 :          0 :                 count += txgbe_regs_group_count(reg_group);
    1237                 :            : 
    1238                 :            :         return count;
    1239                 :            : }
    1240                 :            : 
    1241                 :            : static int
    1242                 :          0 : txgbevf_get_regs(struct rte_eth_dev *dev,
    1243                 :            :                 struct rte_dev_reg_info *regs)
    1244                 :            : {
    1245                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    1246                 :          0 :         uint32_t *data = regs->data;
    1247                 :            :         int g_ind = 0;
    1248                 :            :         int count = 0;
    1249                 :            :         const struct reg_info *reg_group;
    1250                 :            : 
    1251         [ #  # ]:          0 :         if (data == NULL) {
    1252                 :          0 :                 regs->length = txgbevf_get_reg_length(dev);
    1253                 :          0 :                 regs->width = sizeof(uint32_t);
    1254                 :          0 :                 return 0;
    1255                 :            :         }
    1256                 :            : 
    1257                 :            :         /* Support only full register dump */
    1258         [ #  # ]:          0 :         if (regs->length == 0 ||
    1259         [ #  # ]:          0 :             regs->length == (uint32_t)txgbevf_get_reg_length(dev)) {
    1260                 :          0 :                 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
    1261                 :          0 :                         hw->device_id;
    1262         [ #  # ]:          0 :                 while ((reg_group = txgbevf_regs[g_ind++]))
    1263                 :          0 :                         count += txgbe_read_regs_group(dev, &data[count],
    1264                 :            :                                                       reg_group);
    1265                 :            :                 return 0;
    1266                 :            :         }
    1267                 :            : 
    1268                 :            :         return -ENOTSUP;
    1269                 :            : }
    1270                 :            : 
    1271                 :            : static int
    1272                 :          0 : txgbevf_dev_promiscuous_enable(struct rte_eth_dev *dev)
    1273                 :            : {
    1274                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    1275                 :            :         int ret;
    1276                 :            : 
    1277      [ #  #  # ]:          0 :         switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_PROMISC)) {
    1278                 :            :         case 0:
    1279                 :            :                 ret = 0;
    1280                 :            :                 break;
    1281                 :          0 :         case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
    1282                 :            :                 ret = -ENOTSUP;
    1283                 :          0 :                 break;
    1284                 :          0 :         default:
    1285                 :            :                 ret = -EAGAIN;
    1286                 :          0 :                 break;
    1287                 :            :         }
    1288                 :            : 
    1289                 :          0 :         return ret;
    1290                 :            : }
    1291                 :            : 
    1292                 :            : static int
    1293                 :          0 : txgbevf_dev_promiscuous_disable(struct rte_eth_dev *dev)
    1294                 :            : {
    1295                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    1296                 :            :         int mode = TXGBEVF_XCAST_MODE_NONE;
    1297                 :            :         int ret;
    1298                 :            : 
    1299         [ #  # ]:          0 :         if (dev->data->all_multicast)
    1300                 :            :                 mode = TXGBEVF_XCAST_MODE_ALLMULTI;
    1301                 :            : 
    1302      [ #  #  # ]:          0 :         switch (hw->mac.update_xcast_mode(hw, mode)) {
    1303                 :            :         case 0:
    1304                 :            :                 ret = 0;
    1305                 :            :                 break;
    1306                 :          0 :         case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
    1307                 :            :                 ret = -ENOTSUP;
    1308                 :          0 :                 break;
    1309                 :          0 :         default:
    1310                 :            :                 ret = -EAGAIN;
    1311                 :          0 :                 break;
    1312                 :            :         }
    1313                 :            : 
    1314                 :          0 :         return ret;
    1315                 :            : }
    1316                 :            : 
    1317                 :            : static int
    1318                 :          0 : txgbevf_dev_allmulticast_enable(struct rte_eth_dev *dev)
    1319                 :            : {
    1320                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    1321                 :            :         int ret;
    1322                 :            : 
    1323         [ #  # ]:          0 :         if (dev->data->promiscuous)
    1324                 :            :                 return 0;
    1325                 :            : 
    1326      [ #  #  # ]:          0 :         switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_ALLMULTI)) {
    1327                 :            :         case 0:
    1328                 :            :                 ret = 0;
    1329                 :            :                 break;
    1330                 :          0 :         case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
    1331                 :            :                 ret = -ENOTSUP;
    1332                 :          0 :                 break;
    1333                 :          0 :         default:
    1334                 :            :                 ret = -EAGAIN;
    1335                 :          0 :                 break;
    1336                 :            :         }
    1337                 :            : 
    1338                 :            :         return ret;
    1339                 :            : }
    1340                 :            : 
    1341                 :            : static int
    1342                 :          0 : txgbevf_dev_allmulticast_disable(struct rte_eth_dev *dev)
    1343                 :            : {
    1344                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    1345                 :            :         int ret;
    1346                 :            : 
    1347         [ #  # ]:          0 :         if (dev->data->promiscuous)
    1348                 :            :                 return 0;
    1349                 :            : 
    1350      [ #  #  # ]:          0 :         switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_MULTI)) {
    1351                 :            :         case 0:
    1352                 :            :                 ret = 0;
    1353                 :            :                 break;
    1354                 :          0 :         case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
    1355                 :            :                 ret = -ENOTSUP;
    1356                 :          0 :                 break;
    1357                 :          0 :         default:
    1358                 :            :                 ret = -EAGAIN;
    1359                 :          0 :                 break;
    1360                 :            :         }
    1361                 :            : 
    1362                 :            :         return ret;
    1363                 :            : }
    1364                 :            : 
    1365                 :          0 : static void txgbevf_mbx_process(struct rte_eth_dev *dev)
    1366                 :            : {
    1367                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    1368                 :          0 :         u32 in_msg = 0;
    1369                 :            : 
    1370                 :            :         /* peek the message first */
    1371                 :          0 :         in_msg = rd32(hw, TXGBE_VFMBX);
    1372                 :            : 
    1373                 :            :         /* PF reset VF event */
    1374         [ #  # ]:          0 :         if (in_msg == TXGBE_PF_CONTROL_MSG) {
    1375                 :            :                 /* dummy mbx read to ack pf */
    1376         [ #  # ]:          0 :                 if (txgbe_read_mbx(hw, &in_msg, 1, 0))
    1377                 :          0 :                         return;
    1378                 :          0 :                 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
    1379                 :            :                                               NULL);
    1380                 :            :         }
    1381                 :            : }
    1382                 :            : 
    1383                 :            : static int
    1384                 :          0 : txgbevf_dev_interrupt_get_status(struct rte_eth_dev *dev)
    1385                 :            : {
    1386                 :            :         uint32_t eicr;
    1387                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    1388                 :            :         struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
    1389                 :          0 :         txgbevf_intr_disable(dev);
    1390                 :            : 
    1391                 :            :         /* read-on-clear nic registers here */
    1392                 :            :         eicr = rd32(hw, TXGBE_VFICR);
    1393                 :            :         intr->flags = 0;
    1394                 :            : 
    1395                 :            :         /* only one misc vector supported - mailbox */
    1396                 :            :         eicr &= TXGBE_VFICR_MASK;
    1397                 :            :         /* Workaround for ICR lost */
    1398                 :          0 :         intr->flags |= TXGBE_FLAG_MAILBOX;
    1399                 :            : 
    1400                 :            :         /* To avoid compiler warnings set eicr to used. */
    1401                 :            :         RTE_SET_USED(eicr);
    1402                 :            : 
    1403                 :          0 :         return 0;
    1404                 :            : }
    1405                 :            : 
    1406                 :            : static int
    1407                 :          0 : txgbevf_dev_interrupt_action(struct rte_eth_dev *dev)
    1408                 :            : {
    1409                 :          0 :         struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
    1410                 :            : 
    1411         [ #  # ]:          0 :         if (intr->flags & TXGBE_FLAG_MAILBOX) {
    1412                 :          0 :                 txgbevf_mbx_process(dev);
    1413                 :          0 :                 intr->flags &= ~TXGBE_FLAG_MAILBOX;
    1414                 :            :         }
    1415                 :            : 
    1416                 :          0 :         txgbevf_intr_enable(dev);
    1417                 :            : 
    1418                 :          0 :         return 0;
    1419                 :            : }
    1420                 :            : 
    1421                 :            : static void
    1422                 :          0 : txgbevf_dev_interrupt_handler(void *param)
    1423                 :            : {
    1424                 :            :         struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
    1425                 :            : 
    1426                 :          0 :         txgbevf_dev_interrupt_get_status(dev);
    1427                 :          0 :         txgbevf_dev_interrupt_action(dev);
    1428                 :          0 : }
    1429                 :            : 
    1430                 :            : static int
    1431                 :          0 : txgbevf_dev_flow_ops_get(__rte_unused struct rte_eth_dev *dev,
    1432                 :            :                          const struct rte_flow_ops **ops)
    1433                 :            : {
    1434                 :          0 :         *ops = &txgbe_flow_ops;
    1435                 :          0 :         return 0;
    1436                 :            : }
    1437                 :            : 
    1438                 :            : /*
    1439                 :            :  * dev_ops for virtual function, bare necessities for basic vf
    1440                 :            :  * operation have been implemented
    1441                 :            :  */
    1442                 :            : static const struct eth_dev_ops txgbevf_eth_dev_ops = {
    1443                 :            :         .dev_configure        = txgbevf_dev_configure,
    1444                 :            :         .dev_start            = txgbevf_dev_start,
    1445                 :            :         .dev_stop             = txgbevf_dev_stop,
    1446                 :            :         .link_update          = txgbevf_dev_link_update,
    1447                 :            :         .stats_get            = txgbevf_dev_stats_get,
    1448                 :            :         .xstats_get           = txgbevf_dev_xstats_get,
    1449                 :            :         .stats_reset          = txgbevf_dev_stats_reset,
    1450                 :            :         .xstats_reset         = txgbevf_dev_stats_reset,
    1451                 :            :         .xstats_get_names     = txgbevf_dev_xstats_get_names,
    1452                 :            :         .dev_close            = txgbevf_dev_close,
    1453                 :            :         .dev_reset            = txgbevf_dev_reset,
    1454                 :            :         .promiscuous_enable   = txgbevf_dev_promiscuous_enable,
    1455                 :            :         .promiscuous_disable  = txgbevf_dev_promiscuous_disable,
    1456                 :            :         .allmulticast_enable  = txgbevf_dev_allmulticast_enable,
    1457                 :            :         .allmulticast_disable = txgbevf_dev_allmulticast_disable,
    1458                 :            :         .dev_infos_get        = txgbevf_dev_info_get,
    1459                 :            :         .dev_supported_ptypes_get = txgbe_dev_supported_ptypes_get,
    1460                 :            :         .mtu_set              = txgbevf_dev_set_mtu,
    1461                 :            :         .vlan_filter_set      = txgbevf_vlan_filter_set,
    1462                 :            :         .vlan_strip_queue_set = txgbevf_vlan_strip_queue_set,
    1463                 :            :         .vlan_offload_set     = txgbevf_vlan_offload_set,
    1464                 :            :         .rx_queue_setup       = txgbe_dev_rx_queue_setup,
    1465                 :            :         .rx_queue_release     = txgbe_dev_rx_queue_release,
    1466                 :            :         .tx_queue_setup       = txgbe_dev_tx_queue_setup,
    1467                 :            :         .tx_queue_release     = txgbe_dev_tx_queue_release,
    1468                 :            :         .rx_queue_intr_enable = txgbevf_dev_rx_queue_intr_enable,
    1469                 :            :         .rx_queue_intr_disable = txgbevf_dev_rx_queue_intr_disable,
    1470                 :            :         .mac_addr_add         = txgbevf_add_mac_addr,
    1471                 :            :         .mac_addr_remove      = txgbevf_remove_mac_addr,
    1472                 :            :         .set_mc_addr_list     = txgbe_dev_set_mc_addr_list,
    1473                 :            :         .rxq_info_get         = txgbe_rxq_info_get,
    1474                 :            :         .txq_info_get         = txgbe_txq_info_get,
    1475                 :            :         .mac_addr_set         = txgbevf_set_default_mac_addr,
    1476                 :            :         .get_reg              = txgbevf_get_regs,
    1477                 :            :         .reta_update          = txgbe_dev_rss_reta_update,
    1478                 :            :         .reta_query           = txgbe_dev_rss_reta_query,
    1479                 :            :         .rss_hash_update      = txgbe_dev_rss_hash_update,
    1480                 :            :         .rss_hash_conf_get    = txgbe_dev_rss_hash_conf_get,
    1481                 :            :         .tx_done_cleanup      = txgbe_dev_tx_done_cleanup,
    1482                 :            :         .flow_ops_get         = txgbevf_dev_flow_ops_get,
    1483                 :            : };
    1484                 :            : 
    1485                 :        253 : RTE_PMD_REGISTER_PCI(net_txgbe_vf, rte_txgbevf_pmd);
    1486                 :            : RTE_PMD_REGISTER_PCI_TABLE(net_txgbe_vf, pci_id_txgbevf_map);
    1487                 :            : RTE_PMD_REGISTER_KMOD_DEP(net_txgbe_vf, "* igb_uio | vfio-pci");

Generated by: LCOV version 1.14