LCOV - code coverage report
Current view: top level - drivers/net/intel/ixgbe - ixgbe_pf.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 406 0.0 %
Date: 2025-03-01 20:23:48 Functions: 0 21 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 156 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2016 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : #include <errno.h>
       7                 :            : #include <stdint.h>
       8                 :            : #include <stdlib.h>
       9                 :            : #include <unistd.h>
      10                 :            : #include <stdarg.h>
      11                 :            : #include <inttypes.h>
      12                 :            : 
      13                 :            : #include <rte_interrupts.h>
      14                 :            : #include <rte_log.h>
      15                 :            : #include <rte_debug.h>
      16                 :            : #include <rte_eal.h>
      17                 :            : #include <rte_ether.h>
      18                 :            : #include <ethdev_driver.h>
      19                 :            : #include <rte_memcpy.h>
      20                 :            : #include <rte_malloc.h>
      21                 :            : #include <rte_random.h>
      22                 :            : 
      23                 :            : #include "base/ixgbe_common.h"
      24                 :            : #include "ixgbe_ethdev.h"
      25                 :            : #include "rte_pmd_ixgbe.h"
      26                 :            : 
      27                 :            : #define IXGBE_MAX_VFTA     (128)
      28                 :            : #define IXGBE_VF_MSG_SIZE_DEFAULT 1
      29                 :            : #define IXGBE_VF_GET_QUEUE_MSG_SIZE 5
      30                 :            : #define IXGBE_ETHERTYPE_FLOW_CTRL 0x8808
      31                 :            : 
      32                 :            : static inline uint16_t
      33                 :            : dev_num_vf(struct rte_eth_dev *eth_dev)
      34                 :            : {
      35                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
      36                 :            : 
      37                 :          0 :         return pci_dev->max_vfs;
      38                 :            : }
      39                 :            : 
      40                 :            : static inline
      41                 :          0 : int ixgbe_vf_perm_addr_gen(struct rte_eth_dev *dev, uint16_t vf_num)
      42                 :            : {
      43                 :            :         unsigned char vf_mac_addr[RTE_ETHER_ADDR_LEN];
      44                 :          0 :         struct ixgbe_vf_info *vfinfo =
      45                 :          0 :                 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
      46                 :            :         uint16_t vfn;
      47                 :            : 
      48         [ #  # ]:          0 :         for (vfn = 0; vfn < vf_num; vfn++) {
      49                 :          0 :                 rte_eth_random_addr(vf_mac_addr);
      50                 :            :                 /* keep the random address as default */
      51                 :          0 :                 memcpy(vfinfo[vfn].vf_mac_addresses, vf_mac_addr,
      52                 :            :                            RTE_ETHER_ADDR_LEN);
      53                 :            :         }
      54                 :            : 
      55                 :          0 :         return 0;
      56                 :            : }
      57                 :            : 
      58                 :            : static inline int
      59                 :            : ixgbe_mb_intr_setup(struct rte_eth_dev *dev)
      60                 :            : {
      61                 :            :         struct ixgbe_interrupt *intr =
      62                 :          0 :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
      63                 :            : 
      64                 :          0 :         intr->mask |= IXGBE_EICR_MAILBOX;
      65                 :            : 
      66                 :            :         return 0;
      67                 :            : }
      68                 :            : 
      69                 :          0 : int ixgbe_pf_host_init(struct rte_eth_dev *eth_dev)
      70                 :            : {
      71                 :            :         struct ixgbe_vf_info **vfinfo =
      72                 :          0 :                 IXGBE_DEV_PRIVATE_TO_P_VFDATA(eth_dev->data->dev_private);
      73                 :          0 :         struct ixgbe_uta_info *uta_info =
      74                 :            :         IXGBE_DEV_PRIVATE_TO_UTA(eth_dev->data->dev_private);
      75                 :          0 :         struct ixgbe_hw *hw =
      76                 :            :                 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
      77                 :            :         uint16_t vf_num;
      78                 :            :         uint8_t nb_queue;
      79                 :            :         int ret = 0;
      80                 :            :         size_t i;
      81                 :            : 
      82                 :          0 :         PMD_INIT_FUNC_TRACE();
      83                 :            : 
      84                 :          0 :         RTE_ETH_DEV_SRIOV(eth_dev).active = 0;
      85                 :            :         vf_num = dev_num_vf(eth_dev);
      86         [ #  # ]:          0 :         if (vf_num == 0)
      87                 :            :                 return ret;
      88                 :            : 
      89                 :          0 :         *vfinfo = rte_zmalloc("vf_info", sizeof(struct ixgbe_vf_info) * vf_num, 0);
      90         [ #  # ]:          0 :         if (*vfinfo == NULL) {
      91                 :          0 :                 PMD_INIT_LOG(ERR,
      92                 :            :                         "Cannot allocate memory for private VF data");
      93                 :          0 :                 return -ENOMEM;
      94                 :            :         }
      95                 :            : 
      96                 :          0 :         ret = rte_eth_switch_domain_alloc(&(*vfinfo)->switch_domain_id);
      97         [ #  # ]:          0 :         if (ret) {
      98                 :          0 :                 PMD_INIT_LOG(ERR,
      99                 :            :                         "failed to allocate switch domain for device %d", ret);
     100                 :          0 :                 rte_free(*vfinfo);
     101                 :          0 :                 *vfinfo = NULL;
     102                 :          0 :                 return ret;
     103                 :            :         }
     104                 :            : 
     105                 :            :         memset(uta_info, 0, sizeof(struct ixgbe_uta_info));
     106                 :          0 :         hw->mac.mc_filter_type = 0;
     107                 :            : 
     108         [ #  # ]:          0 :         if (vf_num >= RTE_ETH_32_POOLS) {
     109                 :            :                 nb_queue = 2;
     110                 :          0 :                 RTE_ETH_DEV_SRIOV(eth_dev).active = RTE_ETH_64_POOLS;
     111         [ #  # ]:          0 :         } else if (vf_num >= RTE_ETH_16_POOLS) {
     112                 :            :                 nb_queue = 4;
     113                 :          0 :                 RTE_ETH_DEV_SRIOV(eth_dev).active = RTE_ETH_32_POOLS;
     114                 :            :         } else {
     115                 :            :                 nb_queue = 8;
     116                 :          0 :                 RTE_ETH_DEV_SRIOV(eth_dev).active = RTE_ETH_16_POOLS;
     117                 :            :         }
     118                 :            : 
     119                 :          0 :         RTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool = nb_queue;
     120                 :          0 :         RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx = vf_num;
     121                 :          0 :         RTE_ETH_DEV_SRIOV(eth_dev).def_pool_q_idx = (uint16_t)(vf_num * nb_queue);
     122                 :            : 
     123                 :          0 :         ixgbe_vf_perm_addr_gen(eth_dev, vf_num);
     124                 :            : 
     125                 :            :         /* init_mailbox_params */
     126         [ #  # ]:          0 :         for (i = 0; i < vf_num; i++)
     127                 :          0 :                 hw->mbx.ops[i].init_params(hw);
     128                 :            : 
     129                 :            :         /* set mb interrupt mask */
     130                 :            :         ixgbe_mb_intr_setup(eth_dev);
     131                 :            : 
     132                 :          0 :         return ret;
     133                 :            : }
     134                 :            : 
     135                 :          0 : void ixgbe_pf_host_uninit(struct rte_eth_dev *eth_dev)
     136                 :            : {
     137                 :            :         struct ixgbe_vf_info **vfinfo;
     138                 :            :         uint16_t vf_num;
     139                 :            :         int ret;
     140                 :            : 
     141                 :          0 :         PMD_INIT_FUNC_TRACE();
     142                 :            : 
     143                 :          0 :         RTE_ETH_DEV_SRIOV(eth_dev).active = 0;
     144                 :          0 :         RTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool = 0;
     145                 :          0 :         RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx = 0;
     146                 :          0 :         RTE_ETH_DEV_SRIOV(eth_dev).def_pool_q_idx = 0;
     147                 :            : 
     148                 :            :         vf_num = dev_num_vf(eth_dev);
     149         [ #  # ]:          0 :         if (vf_num == 0)
     150                 :            :                 return;
     151                 :            : 
     152                 :          0 :         vfinfo = IXGBE_DEV_PRIVATE_TO_P_VFDATA(eth_dev->data->dev_private);
     153         [ #  # ]:          0 :         if (*vfinfo == NULL)
     154                 :            :                 return;
     155                 :            : 
     156                 :          0 :         ret = rte_eth_switch_domain_free((*vfinfo)->switch_domain_id);
     157         [ #  # ]:          0 :         if (ret)
     158                 :          0 :                 PMD_INIT_LOG(WARNING, "failed to free switch domain: %d", ret);
     159                 :            : 
     160                 :          0 :         rte_free(*vfinfo);
     161                 :          0 :         *vfinfo = NULL;
     162                 :            : }
     163                 :            : 
     164                 :            : static void
     165                 :          0 : ixgbe_add_tx_flow_control_drop_filter(struct rte_eth_dev *eth_dev)
     166                 :            : {
     167                 :          0 :         struct ixgbe_hw *hw =
     168                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
     169                 :            :         struct ixgbe_filter_info *filter_info =
     170                 :            :                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
     171                 :            :         uint16_t vf_num;
     172                 :            :         int i;
     173                 :            :         struct ixgbe_ethertype_filter ethertype_filter;
     174                 :            : 
     175         [ #  # ]:          0 :         if (!hw->mac.ops.set_ethertype_anti_spoofing) {
     176                 :          0 :                 PMD_DRV_LOG(INFO, "ether type anti-spoofing is not supported.");
     177                 :          0 :                 return;
     178                 :            :         }
     179                 :            : 
     180                 :            :         i = ixgbe_ethertype_filter_lookup(filter_info,
     181                 :            :                                           IXGBE_ETHERTYPE_FLOW_CTRL);
     182         [ #  # ]:          0 :         if (i >= 0) {
     183                 :          0 :                 PMD_DRV_LOG(ERR, "A ether type filter entity for flow control already exists!");
     184                 :          0 :                 return;
     185                 :            :         }
     186                 :            : 
     187                 :            :         ethertype_filter.ethertype = IXGBE_ETHERTYPE_FLOW_CTRL;
     188                 :            :         ethertype_filter.etqf = IXGBE_ETQF_FILTER_EN |
     189                 :            :                                 IXGBE_ETQF_TX_ANTISPOOF |
     190                 :            :                                 IXGBE_ETHERTYPE_FLOW_CTRL;
     191                 :            :         ethertype_filter.etqs = 0;
     192                 :            :         ethertype_filter.conf = TRUE;
     193                 :            :         i = ixgbe_ethertype_filter_insert(filter_info,
     194                 :            :                                           &ethertype_filter);
     195         [ #  # ]:          0 :         if (i < 0) {
     196                 :          0 :                 PMD_DRV_LOG(ERR, "Cannot find an unused ether type filter entity for flow control.");
     197                 :          0 :                 return;
     198                 :            :         }
     199                 :            : 
     200                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_ETQF(i),
     201                 :            :                         (IXGBE_ETQF_FILTER_EN |
     202                 :            :                         IXGBE_ETQF_TX_ANTISPOOF |
     203                 :            :                         IXGBE_ETHERTYPE_FLOW_CTRL));
     204                 :            : 
     205                 :            :         vf_num = dev_num_vf(eth_dev);
     206         [ #  # ]:          0 :         for (i = 0; i < vf_num; i++)
     207                 :          0 :                 hw->mac.ops.set_ethertype_anti_spoofing(hw, true, i);
     208                 :            : }
     209                 :            : 
     210                 :          0 : int ixgbe_pf_host_configure(struct rte_eth_dev *eth_dev)
     211                 :            : {
     212                 :            :         uint32_t vtctl, fcrth;
     213                 :            :         uint32_t vfre_slot, vfre_offset;
     214                 :            :         uint16_t vf_num;
     215                 :            :         const uint8_t VFRE_SHIFT = 5;  /* VFRE 32 bits per slot */
     216                 :            :         const uint8_t VFRE_MASK = (uint8_t)((1U << VFRE_SHIFT) - 1);
     217                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
     218                 :            :         uint32_t gpie, gcr_ext;
     219                 :            :         uint32_t vlanctrl;
     220                 :            :         int i;
     221                 :            : 
     222                 :            :         vf_num = dev_num_vf(eth_dev);
     223         [ #  # ]:          0 :         if (vf_num == 0)
     224                 :            :                 return -1;
     225                 :            : 
     226                 :            :         /* enable VMDq and set the default pool for PF */
     227                 :          0 :         vtctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
     228                 :            :         vtctl |= IXGBE_VMD_CTL_VMDQ_EN;
     229                 :          0 :         vtctl &= ~IXGBE_VT_CTL_POOL_MASK;
     230                 :          0 :         vtctl |= RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx
     231                 :          0 :                 << IXGBE_VT_CTL_POOL_SHIFT;
     232                 :          0 :         vtctl |= IXGBE_VT_CTL_REPLEN;
     233                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vtctl);
     234                 :            : 
     235                 :          0 :         vfre_offset = vf_num & VFRE_MASK;
     236                 :          0 :         vfre_slot = (vf_num >> VFRE_SHIFT) > 0 ? 1 : 0;
     237                 :            : 
     238                 :            :         /* Enable pools reserved to PF only */
     239                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VFRE(vfre_slot), (~0U) << vfre_offset);
     240                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VFRE(vfre_slot ^ 1), vfre_slot - 1);
     241                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VFTE(vfre_slot), (~0U) << vfre_offset);
     242                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VFTE(vfre_slot ^ 1), vfre_slot - 1);
     243                 :            : 
     244                 :            :         /* PFDMA Tx General Switch Control Enables VMDQ loopback */
     245                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
     246                 :            : 
     247                 :            :         /* clear VMDq map to permanent rar 0 */
     248                 :          0 :         hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
     249                 :            : 
     250                 :            :         /* clear VMDq map to scan rar 127 */
     251                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(hw->mac.num_rar_entries), 0);
     252                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(hw->mac.num_rar_entries), 0);
     253                 :            : 
     254                 :            :         /* set VMDq map to default PF pool */
     255                 :          0 :         hw->mac.ops.set_vmdq(hw, 0, RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx);
     256                 :            : 
     257                 :            :         /*
     258                 :            :          * SW msut set GCR_EXT.VT_Mode the same as GPIE.VT_Mode
     259                 :            :          */
     260                 :          0 :         gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
     261                 :          0 :         gcr_ext &= ~IXGBE_GCR_EXT_VT_MODE_MASK;
     262                 :            : 
     263                 :          0 :         gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
     264                 :          0 :         gpie &= ~IXGBE_GPIE_VTMODE_MASK;
     265                 :          0 :         gpie |= IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT;
     266                 :            : 
     267   [ #  #  #  # ]:          0 :         switch (RTE_ETH_DEV_SRIOV(eth_dev).active) {
     268                 :          0 :         case RTE_ETH_64_POOLS:
     269                 :          0 :                 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
     270                 :          0 :                 gpie |= IXGBE_GPIE_VTMODE_64;
     271                 :          0 :                 break;
     272                 :          0 :         case RTE_ETH_32_POOLS:
     273                 :          0 :                 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_32;
     274                 :          0 :                 gpie |= IXGBE_GPIE_VTMODE_32;
     275                 :          0 :                 break;
     276                 :          0 :         case RTE_ETH_16_POOLS:
     277                 :          0 :                 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_16;
     278                 :          0 :                 gpie |= IXGBE_GPIE_VTMODE_16;
     279                 :          0 :                 break;
     280                 :            :         }
     281                 :            : 
     282                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
     283                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
     284                 :            : 
     285                 :            :         /*
     286                 :            :          * enable vlan filtering and allow all vlan tags through
     287                 :            :          */
     288                 :          0 :         vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
     289                 :          0 :         vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
     290                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
     291                 :            : 
     292                 :            :         /* VFTA - enable all vlan filters */
     293         [ #  # ]:          0 :         for (i = 0; i < IXGBE_MAX_VFTA; i++)
     294                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), 0xFFFFFFFF);
     295                 :            : 
     296                 :            :         /* Enable MAC Anti-Spoofing */
     297                 :          0 :         hw->mac.ops.set_mac_anti_spoofing(hw, FALSE, vf_num);
     298                 :            : 
     299                 :            :         /* set flow control threshold to max to avoid tx switch hang */
     300         [ #  # ]:          0 :         for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
     301                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
     302                 :          0 :                 fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)) - 32;
     303                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), fcrth);
     304                 :            :         }
     305                 :            : 
     306                 :          0 :         ixgbe_add_tx_flow_control_drop_filter(eth_dev);
     307                 :            : 
     308                 :          0 :         return 0;
     309                 :            : }
     310                 :            : 
     311                 :            : static void
     312                 :          0 : set_rx_mode(struct rte_eth_dev *dev)
     313                 :            : {
     314                 :          0 :         struct rte_eth_dev_data *dev_data = dev->data;
     315                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     316                 :            :         u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
     317                 :            :         uint16_t vfn = dev_num_vf(dev);
     318                 :            : 
     319                 :            :         /* Check for Promiscuous and All Multicast modes */
     320                 :          0 :         fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
     321                 :            : 
     322                 :            :         /* set all bits that we expect to always be set */
     323                 :            :         fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
     324                 :            :         fctrl |= IXGBE_FCTRL_BAM;
     325                 :            : 
     326                 :            :         /* clear the bits we are changing the status of */
     327                 :          0 :         fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
     328                 :            : 
     329         [ #  # ]:          0 :         if (dev_data->promiscuous) {
     330                 :          0 :                 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
     331                 :            :                 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
     332                 :            :         } else {
     333         [ #  # ]:          0 :                 if (dev_data->all_multicast) {
     334                 :          0 :                         fctrl |= IXGBE_FCTRL_MPE;
     335                 :            :                         vmolr |= IXGBE_VMOLR_MPE;
     336                 :            :                 } else {
     337                 :            :                         vmolr |= IXGBE_VMOLR_ROMPE;
     338                 :            :                 }
     339                 :            :         }
     340                 :            : 
     341         [ #  # ]:          0 :         if (hw->mac.type != ixgbe_mac_82598EB) {
     342                 :          0 :                 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(vfn)) &
     343                 :            :                          ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
     344                 :            :                            IXGBE_VMOLR_ROPE);
     345                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vfn), vmolr);
     346                 :            :         }
     347                 :            : 
     348                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
     349                 :            : 
     350                 :          0 :         ixgbe_vlan_hw_strip_config(dev);
     351                 :          0 : }
     352                 :            : 
     353                 :            : static inline void
     354                 :          0 : ixgbe_vf_reset_event(struct rte_eth_dev *dev, uint16_t vf)
     355                 :            : {
     356                 :          0 :         struct ixgbe_hw *hw =
     357                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     358                 :          0 :         struct ixgbe_vf_info *vfinfo =
     359                 :            :                 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
     360                 :          0 :         int rar_entry = hw->mac.num_rar_entries - (vf + 1);
     361                 :          0 :         uint32_t vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
     362                 :            : 
     363                 :          0 :         vmolr |= (IXGBE_VMOLR_ROPE |
     364                 :            :                         IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
     365                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
     366                 :            : 
     367                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0);
     368                 :            : 
     369                 :            :         /* reset multicast table array for vf */
     370                 :          0 :         vfinfo[vf].num_vf_mc_hashes = 0;
     371                 :            : 
     372                 :            :         /* reset rx mode */
     373                 :          0 :         set_rx_mode(dev);
     374                 :            : 
     375                 :          0 :         hw->mac.ops.clear_rar(hw, rar_entry);
     376                 :          0 : }
     377                 :            : 
     378                 :            : static inline void
     379                 :          0 : ixgbe_vf_reset_msg(struct rte_eth_dev *dev, uint16_t vf)
     380                 :            : {
     381                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     382                 :            :         uint32_t reg;
     383                 :            :         uint32_t reg_offset, vf_shift;
     384                 :            :         const uint8_t VFRE_SHIFT = 5;  /* VFRE 32 bits per slot */
     385                 :            :         const uint8_t VFRE_MASK = (uint8_t)((1U << VFRE_SHIFT) - 1);
     386                 :            :         uint8_t  nb_q_per_pool;
     387                 :            :         int i;
     388                 :            : 
     389                 :          0 :         vf_shift = vf & VFRE_MASK;
     390                 :          0 :         reg_offset = (vf >> VFRE_SHIFT) > 0 ? 1 : 0;
     391                 :            : 
     392                 :            :         /* enable transmit for vf */
     393                 :          0 :         reg = IXGBE_READ_REG(hw, IXGBE_VFTE(reg_offset));
     394                 :          0 :         reg |= (reg | (1 << vf_shift));
     395                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), reg);
     396                 :            : 
     397                 :            :         /* enable all queue drop for IOV */
     398                 :          0 :         nb_q_per_pool = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
     399         [ #  # ]:          0 :         for (i = vf * nb_q_per_pool; i < (vf + 1) * nb_q_per_pool; i++) {
     400                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
     401                 :            :                 reg = IXGBE_QDE_ENABLE | IXGBE_QDE_WRITE;
     402                 :          0 :                 reg |= i << IXGBE_QDE_IDX_SHIFT;
     403                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_QDE, reg);
     404                 :            :         }
     405                 :            : 
     406                 :            :         /* enable receive for vf */
     407                 :          0 :         reg = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset));
     408                 :          0 :         reg |= (reg | (1 << vf_shift));
     409                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), reg);
     410                 :            : 
     411                 :            :         /* Enable counting of spoofed packets in the SSVPC register */
     412                 :          0 :         reg = IXGBE_READ_REG(hw, IXGBE_VMECM(reg_offset));
     413                 :          0 :         reg |= (1 << vf_shift);
     414                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VMECM(reg_offset), reg);
     415                 :            : 
     416                 :          0 :         ixgbe_vf_reset_event(dev, vf);
     417                 :          0 : }
     418                 :            : 
     419                 :            : static int
     420                 :          0 : ixgbe_disable_vf_mc_promisc(struct rte_eth_dev *dev, uint32_t vf)
     421                 :            : {
     422                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     423                 :            :         uint32_t vmolr;
     424                 :            : 
     425                 :          0 :         vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
     426                 :            : 
     427                 :          0 :         PMD_DRV_LOG(INFO, "VF %u: disabling multicast promiscuous", vf);
     428                 :            : 
     429                 :          0 :         vmolr &= ~IXGBE_VMOLR_MPE;
     430                 :            : 
     431                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
     432                 :            : 
     433                 :          0 :         return 0;
     434                 :            : }
     435                 :            : 
     436                 :            : static int
     437                 :          0 : ixgbe_vf_reset(struct rte_eth_dev *dev, uint16_t vf, uint32_t *msgbuf)
     438                 :            : {
     439                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     440                 :          0 :         struct ixgbe_vf_info *vfinfo =
     441                 :            :                 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
     442                 :          0 :         unsigned char *vf_mac = vfinfo[vf].vf_mac_addresses;
     443                 :          0 :         int rar_entry = hw->mac.num_rar_entries - (vf + 1);
     444                 :          0 :         uint8_t *new_mac = (uint8_t *)(&msgbuf[1]);
     445                 :            : 
     446                 :          0 :         ixgbe_vf_reset_msg(dev, vf);
     447                 :            : 
     448                 :          0 :         hw->mac.ops.set_rar(hw, rar_entry, vf_mac, vf, IXGBE_RAH_AV);
     449                 :            : 
     450                 :            :         /* Disable multicast promiscuous at reset */
     451                 :          0 :         ixgbe_disable_vf_mc_promisc(dev, vf);
     452                 :            : 
     453                 :            :         /* reply to reset with success and vf mac address */
     454         [ #  # ]:          0 :         msgbuf[0] = IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_SUCCESS;
     455                 :            :         rte_memcpy(new_mac, vf_mac, RTE_ETHER_ADDR_LEN);
     456                 :            :         /*
     457                 :            :          * Piggyback the multicast filter type so VF can compute the
     458                 :            :          * correct vectors
     459                 :            :          */
     460                 :          0 :         msgbuf[3] = hw->mac.mc_filter_type;
     461                 :          0 :         ixgbe_write_mbx(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN, vf);
     462                 :            : 
     463                 :          0 :         return 0;
     464                 :            : }
     465                 :            : 
     466                 :            : static int
     467                 :          0 : ixgbe_vf_set_mac_addr(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
     468                 :            : {
     469                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     470                 :          0 :         struct ixgbe_vf_info *vfinfo =
     471                 :            :                 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
     472                 :          0 :         int rar_entry = hw->mac.num_rar_entries - (vf + 1);
     473         [ #  # ]:          0 :         uint8_t *new_mac = (uint8_t *)(&msgbuf[1]);
     474                 :            : 
     475                 :            :         if (rte_is_valid_assigned_ether_addr(
     476                 :            :                         (struct rte_ether_addr *)new_mac)) {
     477         [ #  # ]:          0 :                 rte_memcpy(vfinfo[vf].vf_mac_addresses, new_mac, 6);
     478                 :          0 :                 return hw->mac.ops.set_rar(hw, rar_entry, new_mac, vf, IXGBE_RAH_AV);
     479                 :            :         }
     480                 :            :         return -1;
     481                 :            : }
     482                 :            : 
     483                 :            : static int
     484                 :          0 : ixgbe_vf_set_multicast(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
     485                 :            : {
     486                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     487                 :          0 :         struct ixgbe_vf_info *vfinfo =
     488                 :            :                 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
     489                 :          0 :         int nb_entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >>
     490                 :            :                 IXGBE_VT_MSGINFO_SHIFT;
     491                 :            :         uint16_t *hash_list = (uint16_t *)&msgbuf[1];
     492                 :            :         uint32_t mta_idx;
     493                 :            :         uint32_t mta_shift;
     494                 :            :         const uint32_t IXGBE_MTA_INDEX_MASK = 0x7F;
     495                 :            :         const uint32_t IXGBE_MTA_BIT_SHIFT = 5;
     496                 :            :         const uint32_t IXGBE_MTA_BIT_MASK = (0x1 << IXGBE_MTA_BIT_SHIFT) - 1;
     497                 :            :         uint32_t reg_val;
     498                 :            :         int i;
     499                 :          0 :         u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
     500                 :            : 
     501                 :            :         /* Disable multicast promiscuous first */
     502                 :          0 :         ixgbe_disable_vf_mc_promisc(dev, vf);
     503                 :            : 
     504                 :            :         /* only so many hash values supported */
     505                 :          0 :         nb_entries = RTE_MIN(nb_entries, IXGBE_MAX_VF_MC_ENTRIES);
     506                 :            : 
     507                 :            :         /* store the mc entries  */
     508                 :          0 :         vfinfo->num_vf_mc_hashes = (uint16_t)nb_entries;
     509         [ #  # ]:          0 :         for (i = 0; i < nb_entries; i++) {
     510                 :          0 :                 vfinfo->vf_mc_hashes[i] = hash_list[i];
     511                 :            :         }
     512                 :            : 
     513         [ #  # ]:          0 :         if (nb_entries == 0) {
     514                 :          0 :                 vmolr &= ~IXGBE_VMOLR_ROMPE;
     515                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
     516                 :          0 :                 return 0;
     517                 :            :         }
     518                 :            : 
     519         [ #  # ]:          0 :         for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) {
     520                 :          0 :                 mta_idx = (vfinfo->vf_mc_hashes[i] >> IXGBE_MTA_BIT_SHIFT)
     521                 :            :                                 & IXGBE_MTA_INDEX_MASK;
     522                 :          0 :                 mta_shift = vfinfo->vf_mc_hashes[i] & IXGBE_MTA_BIT_MASK;
     523                 :          0 :                 reg_val = IXGBE_READ_REG(hw, IXGBE_MTA(mta_idx));
     524                 :          0 :                 reg_val |= (1 << mta_shift);
     525                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MTA(mta_idx), reg_val);
     526                 :            :         }
     527                 :            : 
     528                 :          0 :         vmolr |= IXGBE_VMOLR_ROMPE;
     529                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
     530                 :            : 
     531                 :          0 :         return 0;
     532                 :            : }
     533                 :            : 
     534                 :            : static int
     535                 :          0 : ixgbe_vf_set_vlan(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
     536                 :            : {
     537                 :            :         int add, vid;
     538                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     539                 :          0 :         struct ixgbe_vf_info *vfinfo =
     540                 :            :                 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
     541                 :            : 
     542                 :          0 :         add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK)
     543                 :          0 :                 >> IXGBE_VT_MSGINFO_SHIFT;
     544                 :          0 :         vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK);
     545                 :            : 
     546         [ #  # ]:          0 :         if (add)
     547                 :          0 :                 vfinfo[vf].vlan_count++;
     548         [ #  # ]:          0 :         else if (vfinfo[vf].vlan_count)
     549                 :          0 :                 vfinfo[vf].vlan_count--;
     550                 :          0 :         return hw->mac.ops.set_vfta(hw, vid, vf, (bool)add, false);
     551                 :            : }
     552                 :            : 
     553                 :            : static int
     554                 :          0 : ixgbe_set_vf_lpe(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
     555                 :            : {
     556                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     557                 :          0 :         uint32_t max_frame = msgbuf[1];
     558                 :            :         uint32_t max_frs;
     559                 :            :         uint32_t hlreg0;
     560                 :            : 
     561                 :            :         /* X540 and X550 support jumbo frames in IOV mode */
     562         [ #  # ]:          0 :         if (hw->mac.type != ixgbe_mac_X540 &&
     563         [ #  # ]:          0 :                 hw->mac.type != ixgbe_mac_X550 &&
     564         [ #  # ]:          0 :                 hw->mac.type != ixgbe_mac_X550EM_x &&
     565                 :            :                 hw->mac.type != ixgbe_mac_X550EM_a) {
     566                 :          0 :                 struct ixgbe_vf_info *vfinfo =
     567                 :            :                         *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
     568                 :            : 
     569         [ #  # ]:          0 :                 switch (vfinfo[vf].api_version) {
     570                 :          0 :                 case ixgbe_mbox_api_11:
     571                 :            :                 case ixgbe_mbox_api_12:
     572                 :            :                 case ixgbe_mbox_api_13:
     573                 :            :                          /**
     574                 :            :                           * Version 1.1&1.2&1.3 supports jumbo frames on VFs
     575                 :            :                           * if PF has jumbo frames enabled which means legacy
     576                 :            :                           * VFs are disabled.
     577                 :            :                           */
     578         [ #  # ]:          0 :                         if (dev->data->mtu > RTE_ETHER_MTU)
     579                 :            :                                 break;
     580                 :            :                         /* fall through */
     581                 :            :                 default:
     582                 :            :                         /**
     583                 :            :                          * If the PF or VF are running w/ jumbo frames enabled,
     584                 :            :                          * we return -1 as we cannot support jumbo frames on
     585                 :            :                          * legacy VFs.
     586                 :            :                          */
     587         [ #  # ]:          0 :                         if (max_frame > IXGBE_ETH_MAX_LEN ||
     588         [ #  # ]:          0 :                                         dev->data->mtu > RTE_ETHER_MTU)
     589                 :            :                                 return -1;
     590                 :            :                         break;
     591                 :            :                 }
     592                 :            :         }
     593                 :            : 
     594         [ #  # ]:          0 :         if (max_frame < RTE_ETHER_MIN_LEN ||
     595                 :            :                         max_frame > RTE_ETHER_MAX_JUMBO_FRAME_LEN)
     596                 :            :                 return -1;
     597                 :            : 
     598                 :          0 :         max_frs = (IXGBE_READ_REG(hw, IXGBE_MAXFRS) &
     599                 :          0 :                    IXGBE_MHADD_MFS_MASK) >> IXGBE_MHADD_MFS_SHIFT;
     600         [ #  # ]:          0 :         if (max_frs < max_frame) {
     601                 :          0 :                 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
     602         [ #  # ]:          0 :                 if (max_frame > IXGBE_ETH_MAX_LEN)
     603                 :          0 :                         hlreg0 |= IXGBE_HLREG0_JUMBOEN;
     604                 :            :                 else
     605                 :          0 :                         hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
     606                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
     607                 :            : 
     608                 :          0 :                 max_frs = max_frame << IXGBE_MHADD_MFS_SHIFT;
     609                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs);
     610                 :            :         }
     611                 :            : 
     612                 :            :         return 0;
     613                 :            : }
     614                 :            : 
     615                 :            : static int
     616                 :          0 : ixgbe_negotiate_vf_api(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
     617                 :            : {
     618                 :          0 :         uint32_t api_version = msgbuf[1];
     619                 :          0 :         struct ixgbe_vf_info *vfinfo =
     620                 :          0 :                 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
     621                 :            : 
     622         [ #  # ]:          0 :         switch (api_version) {
     623                 :          0 :         case ixgbe_mbox_api_10:
     624                 :            :         case ixgbe_mbox_api_11:
     625                 :            :         case ixgbe_mbox_api_12:
     626                 :            :         case ixgbe_mbox_api_13:
     627                 :          0 :                 vfinfo[vf].api_version = (uint8_t)api_version;
     628                 :          0 :                 return 0;
     629                 :            :         default:
     630                 :            :                 break;
     631                 :            :         }
     632                 :            : 
     633                 :          0 :         PMD_DRV_LOG(ERR, "Negotiate invalid api version %u from VF %d",
     634                 :            :                 api_version, vf);
     635                 :            : 
     636                 :          0 :         return -1;
     637                 :            : }
     638                 :            : 
     639                 :            : static int
     640                 :          0 : ixgbe_get_vf_queues(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
     641                 :            : {
     642                 :          0 :         struct ixgbe_vf_info *vfinfo =
     643                 :          0 :                 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
     644                 :          0 :         uint32_t default_q = vf * RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
     645                 :            :         struct rte_eth_conf *eth_conf;
     646                 :            :         struct rte_eth_vmdq_dcb_tx_conf *vmdq_dcb_tx_conf;
     647                 :            :         u8 num_tcs;
     648                 :            :         struct ixgbe_hw *hw;
     649                 :            :         u32 vmvir;
     650                 :            : #define IXGBE_VMVIR_VLANA_MASK          0xC0000000
     651                 :            : #define IXGBE_VMVIR_VLAN_VID_MASK       0x00000FFF
     652                 :            : #define IXGBE_VMVIR_VLAN_UP_MASK        0x0000E000
     653                 :            : #define VLAN_PRIO_SHIFT                 13
     654                 :            :         u32 vlana;
     655                 :            :         u32 vid;
     656                 :            :         u32 user_priority;
     657                 :            : 
     658                 :            :         /* Verify if the PF supports the mbox APIs version or not */
     659         [ #  # ]:          0 :         switch (vfinfo[vf].api_version) {
     660                 :            :         case ixgbe_mbox_api_20:
     661                 :            :         case ixgbe_mbox_api_11:
     662                 :            :         case ixgbe_mbox_api_12:
     663                 :            :         case ixgbe_mbox_api_13:
     664                 :            :                 break;
     665                 :            :         default:
     666                 :            :                 return -1;
     667                 :            :         }
     668                 :            : 
     669                 :            :         /* Notify VF of Rx and Tx queue number */
     670                 :          0 :         msgbuf[IXGBE_VF_RX_QUEUES] = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
     671                 :          0 :         msgbuf[IXGBE_VF_TX_QUEUES] = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
     672                 :            : 
     673                 :            :         /* Notify VF of default queue */
     674                 :          0 :         msgbuf[IXGBE_VF_DEF_QUEUE] = default_q;
     675                 :            : 
     676                 :            :         /* Notify VF of number of DCB traffic classes */
     677                 :            :         eth_conf = &dev->data->dev_conf;
     678   [ #  #  #  # ]:          0 :         switch (eth_conf->txmode.mq_mode) {
     679                 :          0 :         case RTE_ETH_MQ_TX_NONE:
     680                 :            :         case RTE_ETH_MQ_TX_DCB:
     681                 :          0 :                 PMD_DRV_LOG(ERR, "PF must work with virtualization for VF %u"
     682                 :            :                         ", but its tx mode = %d", vf,
     683                 :            :                         eth_conf->txmode.mq_mode);
     684                 :          0 :                 return -1;
     685                 :            : 
     686                 :          0 :         case RTE_ETH_MQ_TX_VMDQ_DCB:
     687                 :            :                 vmdq_dcb_tx_conf = &eth_conf->tx_adv_conf.vmdq_dcb_tx_conf;
     688      [ #  #  # ]:          0 :                 switch (vmdq_dcb_tx_conf->nb_queue_pools) {
     689                 :            :                 case RTE_ETH_16_POOLS:
     690                 :            :                         num_tcs = RTE_ETH_8_TCS;
     691                 :            :                         break;
     692                 :          0 :                 case RTE_ETH_32_POOLS:
     693                 :            :                         num_tcs = RTE_ETH_4_TCS;
     694                 :          0 :                         break;
     695                 :            :                 default:
     696                 :            :                         return -1;
     697                 :            :                 }
     698                 :            :                 break;
     699                 :            : 
     700                 :            :         /* RTE_ETH_MQ_TX_VMDQ_ONLY,  DCB not enabled */
     701                 :          0 :         case RTE_ETH_MQ_TX_VMDQ_ONLY:
     702                 :            :                 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     703                 :          0 :                 vmvir = IXGBE_READ_REG(hw, IXGBE_VMVIR(vf));
     704                 :          0 :                 vlana = vmvir & IXGBE_VMVIR_VLANA_MASK;
     705                 :          0 :                 vid = vmvir & IXGBE_VMVIR_VLAN_VID_MASK;
     706                 :          0 :                 user_priority =
     707                 :          0 :                         (vmvir & IXGBE_VMVIR_VLAN_UP_MASK) >> VLAN_PRIO_SHIFT;
     708         [ #  # ]:          0 :                 if ((vlana == IXGBE_VMVIR_VLANA_DEFAULT) &&
     709         [ #  # ]:          0 :                         ((vid !=  0) || (user_priority != 0)))
     710                 :            :                         num_tcs = 1;
     711                 :            :                 else
     712                 :            :                         num_tcs = 0;
     713                 :            :                 break;
     714                 :            : 
     715                 :          0 :         default:
     716                 :          0 :                 PMD_DRV_LOG(ERR, "PF work with invalid mode = %d",
     717                 :            :                         eth_conf->txmode.mq_mode);
     718                 :          0 :                 return -1;
     719                 :            :         }
     720                 :          0 :         msgbuf[IXGBE_VF_TRANS_VLAN] = num_tcs;
     721                 :            : 
     722                 :          0 :         return 0;
     723                 :            : }
     724                 :            : 
     725                 :            : static int
     726                 :          0 : ixgbe_set_vf_mc_promisc(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
     727                 :            : {
     728                 :          0 :         struct ixgbe_vf_info *vfinfo =
     729                 :          0 :                 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
     730                 :            :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     731                 :          0 :         int xcast_mode = msgbuf[1];     /* msgbuf contains the flag to enable */
     732                 :            :         u32 vmolr, fctrl, disable, enable;
     733                 :            : 
     734      [ #  #  # ]:          0 :         switch (vfinfo[vf].api_version) {
     735                 :          0 :         case ixgbe_mbox_api_12:
     736                 :            :                 /* promisc introduced in 1.3 version */
     737         [ #  # ]:          0 :                 if (xcast_mode == IXGBEVF_XCAST_MODE_PROMISC)
     738                 :            :                         return -EOPNOTSUPP;
     739                 :            :                 break;
     740                 :            :                 /* Fall threw */
     741                 :            :         case ixgbe_mbox_api_13:
     742                 :            :                 break;
     743                 :            :         default:
     744                 :            :                 return -1;
     745                 :            :         }
     746                 :            : 
     747         [ #  # ]:          0 :         if (vfinfo[vf].xcast_mode == xcast_mode)
     748                 :          0 :                 goto out;
     749                 :            : 
     750   [ #  #  #  #  :          0 :         switch (xcast_mode) {
                      # ]
     751                 :            :         case IXGBEVF_XCAST_MODE_NONE:
     752                 :            :                 disable = IXGBE_VMOLR_ROMPE |
     753                 :            :                           IXGBE_VMOLR_MPE | IXGBE_VMOLR_UPE | IXGBE_VMOLR_VPE;
     754                 :            :                 enable = IXGBE_VMOLR_BAM;
     755                 :            :                 break;
     756                 :          0 :         case IXGBEVF_XCAST_MODE_MULTI:
     757                 :            :                 disable = IXGBE_VMOLR_MPE | IXGBE_VMOLR_UPE | IXGBE_VMOLR_VPE;
     758                 :            :                 enable = IXGBE_VMOLR_BAM | IXGBE_VMOLR_ROMPE;
     759                 :          0 :                 break;
     760                 :          0 :         case IXGBEVF_XCAST_MODE_ALLMULTI:
     761                 :            :                 disable = IXGBE_VMOLR_UPE | IXGBE_VMOLR_VPE;
     762                 :            :                 enable = IXGBE_VMOLR_BAM | IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_MPE;
     763                 :          0 :                 break;
     764                 :          0 :         case IXGBEVF_XCAST_MODE_PROMISC:
     765         [ #  # ]:          0 :                 if (hw->mac.type <= ixgbe_mac_82599EB)
     766                 :            :                         return -1;
     767                 :            : 
     768                 :          0 :                 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
     769         [ #  # ]:          0 :                 if (!(fctrl & IXGBE_FCTRL_UPE)) {
     770                 :            :                         /* VF promisc requires PF in promisc */
     771                 :          0 :                         PMD_DRV_LOG(ERR,
     772                 :            :                                "Enabling VF promisc requires PF in promisc");
     773                 :          0 :                         return -1;
     774                 :            :                 }
     775                 :            : 
     776                 :            :                 disable = IXGBE_VMOLR_VPE;
     777                 :            :                 enable = IXGBE_VMOLR_BAM | IXGBE_VMOLR_ROMPE |
     778                 :            :                          IXGBE_VMOLR_MPE | IXGBE_VMOLR_UPE;
     779                 :            :                 break;
     780                 :            :         default:
     781                 :            :                 return -1;
     782                 :            :         }
     783                 :            : 
     784                 :          0 :         vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
     785                 :          0 :         vmolr &= ~disable;
     786                 :          0 :         vmolr |= enable;
     787                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
     788                 :          0 :         vfinfo[vf].xcast_mode = xcast_mode;
     789                 :            : 
     790                 :          0 : out:
     791                 :          0 :         msgbuf[1] = xcast_mode;
     792                 :            : 
     793                 :          0 :         return 0;
     794                 :            : }
     795                 :            : 
     796                 :            : static int
     797                 :          0 : ixgbe_set_vf_macvlan_msg(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
     798                 :            : {
     799                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     800                 :          0 :         struct ixgbe_vf_info *vf_info =
     801                 :            :                 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
     802                 :          0 :         uint8_t *new_mac = (uint8_t *)(&msgbuf[1]);
     803                 :          0 :         int index = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >>
     804                 :            :                     IXGBE_VT_MSGINFO_SHIFT;
     805                 :            : 
     806         [ #  # ]:          0 :         if (index) {
     807                 :            :                 if (!rte_is_valid_assigned_ether_addr(
     808                 :            :                         (struct rte_ether_addr *)new_mac)) {
     809                 :          0 :                         PMD_DRV_LOG(ERR, "set invalid mac vf:%d", vf);
     810                 :          0 :                         return -1;
     811                 :            :                 }
     812                 :            : 
     813                 :          0 :                 vf_info[vf].mac_count++;
     814                 :            : 
     815                 :          0 :                 hw->mac.ops.set_rar(hw, vf_info[vf].mac_count,
     816                 :            :                                 new_mac, vf, IXGBE_RAH_AV);
     817                 :            :         } else {
     818         [ #  # ]:          0 :                 if (vf_info[vf].mac_count) {
     819                 :          0 :                         hw->mac.ops.clear_rar(hw, vf_info[vf].mac_count);
     820                 :          0 :                         vf_info[vf].mac_count = 0;
     821                 :            :                 }
     822                 :            :         }
     823                 :            :         return 0;
     824                 :            : }
     825                 :            : 
     826                 :            : static int
     827                 :          0 : ixgbe_rcv_msg_from_vf(struct rte_eth_dev *dev, uint16_t vf)
     828                 :            : {
     829                 :            :         uint16_t mbx_size = IXGBE_VFMAILBOX_SIZE;
     830                 :            :         uint16_t msg_size = IXGBE_VF_MSG_SIZE_DEFAULT;
     831                 :            :         uint32_t msgbuf[IXGBE_VFMAILBOX_SIZE];
     832                 :            :         int32_t retval;
     833                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     834                 :          0 :         struct ixgbe_vf_info *vfinfo =
     835                 :            :                 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
     836                 :            :         struct rte_pmd_ixgbe_mb_event_param ret_param;
     837                 :            : 
     838                 :          0 :         retval = ixgbe_read_mbx(hw, msgbuf, mbx_size, vf);
     839         [ #  # ]:          0 :         if (retval) {
     840                 :          0 :                 PMD_DRV_LOG(ERR, "Error mbx recv msg from VF %d", vf);
     841                 :          0 :                 return retval;
     842                 :            :         }
     843                 :            : 
     844                 :            :         /* do nothing with the message already been processed */
     845         [ #  # ]:          0 :         if (msgbuf[0] & (IXGBE_VT_MSGTYPE_SUCCESS | IXGBE_VT_MSGTYPE_FAILURE))
     846                 :            :                 return retval;
     847                 :            : 
     848                 :            :         /* flush the ack before we write any messages back */
     849                 :          0 :         IXGBE_WRITE_FLUSH(hw);
     850                 :            : 
     851                 :            :         /**
     852                 :            :          * initialise structure to send to user application
     853                 :            :          * will return response from user in retval field
     854                 :            :          */
     855                 :          0 :         ret_param.retval = RTE_PMD_IXGBE_MB_EVENT_PROCEED;
     856                 :          0 :         ret_param.vfid = vf;
     857                 :          0 :         ret_param.msg_type = msgbuf[0] & 0xFFFF;
     858                 :          0 :         ret_param.msg = (void *)msgbuf;
     859                 :            : 
     860                 :            :         /* perform VF reset */
     861         [ #  # ]:          0 :         if (msgbuf[0] == IXGBE_VF_RESET) {
     862                 :          0 :                 int ret = ixgbe_vf_reset(dev, vf, msgbuf);
     863                 :            : 
     864                 :          0 :                 vfinfo[vf].clear_to_send = true;
     865                 :            : 
     866                 :            :                 /* notify application about VF reset */
     867                 :          0 :                 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_VF_MBOX,
     868                 :            :                                               &ret_param);
     869                 :          0 :                 return ret;
     870                 :            :         }
     871                 :            : 
     872                 :            :         /**
     873                 :            :          * ask user application if we allowed to perform those functions
     874                 :            :          * if we get ret_param.retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED
     875                 :            :          * then business as usual,
     876                 :            :          * if 0, do nothing and send ACK to VF
     877                 :            :          * if ret_param.retval > 1, do nothing and send NAK to VF
     878                 :            :          */
     879                 :          0 :         rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_VF_MBOX, &ret_param);
     880                 :            : 
     881                 :          0 :         retval = ret_param.retval;
     882                 :            : 
     883                 :            :         /* check & process VF to PF mailbox message */
     884   [ #  #  #  #  :          0 :         switch ((msgbuf[0] & 0xFFFF)) {
             #  #  #  #  
                      # ]
     885                 :          0 :         case IXGBE_VF_SET_MAC_ADDR:
     886         [ #  # ]:          0 :                 if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
     887                 :          0 :                         retval = ixgbe_vf_set_mac_addr(dev, vf, msgbuf);
     888                 :            :                 break;
     889                 :          0 :         case IXGBE_VF_SET_MULTICAST:
     890         [ #  # ]:          0 :                 if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
     891                 :          0 :                         retval = ixgbe_vf_set_multicast(dev, vf, msgbuf);
     892                 :            :                 break;
     893                 :          0 :         case IXGBE_VF_SET_LPE:
     894         [ #  # ]:          0 :                 if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
     895                 :          0 :                         retval = ixgbe_set_vf_lpe(dev, vf, msgbuf);
     896                 :            :                 break;
     897                 :          0 :         case IXGBE_VF_SET_VLAN:
     898         [ #  # ]:          0 :                 if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
     899                 :          0 :                         retval = ixgbe_vf_set_vlan(dev, vf, msgbuf);
     900                 :            :                 break;
     901                 :          0 :         case IXGBE_VF_API_NEGOTIATE:
     902                 :          0 :                 retval = ixgbe_negotiate_vf_api(dev, vf, msgbuf);
     903                 :          0 :                 break;
     904                 :          0 :         case IXGBE_VF_GET_QUEUES:
     905                 :          0 :                 retval = ixgbe_get_vf_queues(dev, vf, msgbuf);
     906                 :            :                 msg_size = IXGBE_VF_GET_QUEUE_MSG_SIZE;
     907                 :          0 :                 break;
     908                 :          0 :         case IXGBE_VF_UPDATE_XCAST_MODE:
     909         [ #  # ]:          0 :                 if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
     910                 :          0 :                         retval = ixgbe_set_vf_mc_promisc(dev, vf, msgbuf);
     911                 :            :                 break;
     912                 :          0 :         case IXGBE_VF_SET_MACVLAN:
     913         [ #  # ]:          0 :                 if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
     914                 :          0 :                         retval = ixgbe_set_vf_macvlan_msg(dev, vf, msgbuf);
     915                 :            :                 break;
     916                 :          0 :         default:
     917                 :          0 :                 PMD_DRV_LOG(DEBUG, "Unhandled Msg %8.8x", (unsigned)msgbuf[0]);
     918                 :            :                 retval = IXGBE_ERR_MBX;
     919                 :            :                 break;
     920                 :            :         }
     921                 :            : 
     922                 :            :         /* response the VF according to the message process result */
     923         [ #  # ]:          0 :         if (retval)
     924                 :          0 :                 msgbuf[0] |= IXGBE_VT_MSGTYPE_FAILURE;
     925                 :            :         else
     926                 :          0 :                 msgbuf[0] |= IXGBE_VT_MSGTYPE_SUCCESS;
     927                 :            : 
     928                 :          0 :         msgbuf[0] |= IXGBE_VT_MSGTYPE_CTS;
     929                 :            : 
     930                 :          0 :         ixgbe_write_mbx(hw, msgbuf, msg_size, vf);
     931                 :            : 
     932                 :          0 :         return retval;
     933                 :            : }
     934                 :            : 
     935                 :            : static inline void
     936                 :          0 : ixgbe_rcv_ack_from_vf(struct rte_eth_dev *dev, uint16_t vf)
     937                 :            : {
     938                 :          0 :         uint32_t msg = IXGBE_VT_MSGTYPE_FAILURE;
     939                 :          0 :         struct ixgbe_hw *hw =
     940                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     941                 :          0 :         struct ixgbe_vf_info *vfinfo =
     942                 :            :                 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
     943                 :            : 
     944         [ #  # ]:          0 :         if (!vfinfo[vf].clear_to_send)
     945                 :          0 :                 ixgbe_write_mbx(hw, &msg, 1, vf);
     946                 :          0 : }
     947                 :            : 
     948                 :          0 : void ixgbe_pf_mbx_process(struct rte_eth_dev *eth_dev)
     949                 :            : {
     950                 :            :         uint16_t vf;
     951                 :          0 :         struct ixgbe_hw *hw =
     952                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
     953                 :            : 
     954         [ #  # ]:          0 :         for (vf = 0; vf < dev_num_vf(eth_dev); vf++) {
     955                 :            :                 /* check & process vf function level reset */
     956         [ #  # ]:          0 :                 if (!ixgbe_check_for_rst(hw, vf))
     957                 :          0 :                         ixgbe_vf_reset_event(eth_dev, vf);
     958                 :            : 
     959                 :            :                 /* check & process vf mailbox messages */
     960         [ #  # ]:          0 :                 if (!ixgbe_check_for_msg(hw, vf))
     961                 :          0 :                         ixgbe_rcv_msg_from_vf(eth_dev, vf);
     962                 :            : 
     963                 :            :                 /* check & process acks from vf */
     964         [ #  # ]:          0 :                 if (!ixgbe_check_for_ack(hw, vf))
     965                 :          0 :                         ixgbe_rcv_ack_from_vf(eth_dev, vf);
     966                 :            :         }
     967                 :          0 : }

Generated by: LCOV version 1.14