LCOV - code coverage report
Current view: top level - drivers/net/intel/e1000 - igb_pf.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 219 0.0 %
Date: 2026-06-01 18:36:17 Functions: 0 14 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 71 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 <bus_pci_driver.h>
      14                 :            : #include <rte_interrupts.h>
      15                 :            : #include <rte_log.h>
      16                 :            : #include <rte_debug.h>
      17                 :            : #include <rte_eal.h>
      18                 :            : #include <rte_ether.h>
      19                 :            : #include <ethdev_driver.h>
      20                 :            : #include <rte_malloc.h>
      21                 :            : #include <rte_random.h>
      22                 :            : 
      23                 :            : #include "base/e1000_defines.h"
      24                 :            : #include "base/e1000_regs.h"
      25                 :            : #include "base/e1000_hw.h"
      26                 :            : #include "e1000_ethdev.h"
      27                 :            : 
      28                 :            : static inline uint16_t
      29                 :            : dev_num_vf(struct rte_eth_dev *eth_dev)
      30                 :            : {
      31                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
      32                 :            : 
      33                 :          0 :         return pci_dev->max_vfs;
      34                 :            : }
      35                 :            : 
      36                 :            : static inline
      37                 :          0 : int igb_vf_perm_addr_gen(struct rte_eth_dev *dev, uint16_t vf_num)
      38                 :            : {
      39                 :            :         unsigned char vf_mac_addr[RTE_ETHER_ADDR_LEN];
      40                 :          0 :         struct e1000_vf_info *vfinfo =
      41                 :          0 :                 *E1000_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
      42                 :            :         uint16_t vfn;
      43                 :            : 
      44         [ #  # ]:          0 :         for (vfn = 0; vfn < vf_num; vfn++) {
      45                 :          0 :                 rte_eth_random_addr(vf_mac_addr);
      46                 :            :                 /* keep the random address as default */
      47                 :          0 :                 memcpy(vfinfo[vfn].vf_mac_addresses, vf_mac_addr,
      48                 :            :                                 RTE_ETHER_ADDR_LEN);
      49                 :            :         }
      50                 :            : 
      51                 :          0 :         return 0;
      52                 :            : }
      53                 :            : 
      54                 :            : static inline int
      55                 :            : igb_mb_intr_setup(struct rte_eth_dev *dev)
      56                 :            : {
      57                 :            :         struct e1000_interrupt *intr =
      58                 :          0 :                 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
      59                 :            : 
      60                 :          0 :         intr->mask |= E1000_ICR_VMMB;
      61                 :            : 
      62                 :          0 :         return 0;
      63                 :            : }
      64                 :            : 
      65                 :          0 : void igb_pf_host_init(struct rte_eth_dev *eth_dev)
      66                 :            : {
      67                 :            :         struct e1000_vf_info **vfinfo =
      68                 :          0 :                 E1000_DEV_PRIVATE_TO_P_VFDATA(eth_dev->data->dev_private);
      69                 :            :         struct e1000_hw *hw =
      70                 :            :                 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
      71                 :            :         uint16_t vf_num;
      72                 :            :         uint8_t nb_queue;
      73                 :            : 
      74                 :          0 :         RTE_ETH_DEV_SRIOV(eth_dev).active = 0;
      75         [ #  # ]:          0 :         if (0 == (vf_num = dev_num_vf(eth_dev)))
      76                 :            :                 return;
      77                 :            : 
      78         [ #  # ]:          0 :         if (hw->mac.type == e1000_i350)
      79                 :            :                 nb_queue = 1;
      80         [ #  # ]:          0 :         else if(hw->mac.type == e1000_82576)
      81                 :            :                 /* per datasheet, it should be 2, but 1 seems correct */
      82                 :            :                 nb_queue = 1;
      83                 :            :         else
      84                 :            :                 return;
      85                 :            : 
      86                 :          0 :         *vfinfo = rte_zmalloc("vf_info", sizeof(struct e1000_vf_info) * vf_num, 0);
      87         [ #  # ]:          0 :         if (*vfinfo == NULL)
      88                 :          0 :                 rte_panic("Cannot allocate memory for private VF data\n");
      89                 :            : 
      90                 :          0 :         RTE_ETH_DEV_SRIOV(eth_dev).active = RTE_ETH_8_POOLS;
      91                 :          0 :         RTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool = nb_queue;
      92                 :          0 :         RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx = vf_num;
      93                 :          0 :         RTE_ETH_DEV_SRIOV(eth_dev).def_pool_q_idx = (uint16_t)(vf_num * nb_queue);
      94                 :            : 
      95                 :          0 :         igb_vf_perm_addr_gen(eth_dev, vf_num);
      96                 :            : 
      97                 :            :         /* set mb interrupt mask */
      98                 :            :         igb_mb_intr_setup(eth_dev);
      99                 :            : 
     100                 :            :         return;
     101                 :            : }
     102                 :            : 
     103                 :          0 : void igb_pf_host_uninit(struct rte_eth_dev *dev)
     104                 :            : {
     105                 :            :         struct e1000_vf_info **vfinfo;
     106                 :            :         uint16_t vf_num;
     107                 :            : 
     108                 :          0 :         PMD_INIT_FUNC_TRACE();
     109                 :            : 
     110                 :          0 :         vfinfo = E1000_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
     111                 :            : 
     112                 :          0 :         RTE_ETH_DEV_SRIOV(dev).active = 0;
     113                 :          0 :         RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 0;
     114                 :          0 :         RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx = 0;
     115                 :          0 :         RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx = 0;
     116                 :            : 
     117                 :            :         vf_num = dev_num_vf(dev);
     118         [ #  # ]:          0 :         if (vf_num == 0)
     119                 :            :                 return;
     120                 :            : 
     121                 :          0 :         rte_free(*vfinfo);
     122                 :          0 :         *vfinfo = NULL;
     123                 :            : }
     124                 :            : 
     125                 :            : #define E1000_RAH_POOLSEL_SHIFT    (18)
     126                 :          0 : int igb_pf_host_configure(struct rte_eth_dev *eth_dev)
     127                 :            : {
     128                 :            :         uint32_t vtctl;
     129                 :            :         uint16_t vf_num;
     130                 :          0 :         struct e1000_hw *hw =
     131                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
     132                 :            :         uint32_t vlanctrl;
     133                 :            :         int i;
     134                 :            :         uint32_t rah;
     135                 :            : 
     136         [ #  # ]:          0 :         if (0 == (vf_num = dev_num_vf(eth_dev)))
     137                 :            :                 return -1;
     138                 :            : 
     139                 :            :         /* enable VMDq and set the default pool for PF */
     140                 :          0 :         vtctl = E1000_READ_REG(hw, E1000_VT_CTL);
     141                 :          0 :         vtctl &= ~E1000_VT_CTL_DEFAULT_POOL_MASK;
     142                 :          0 :         vtctl |= RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx
     143                 :          0 :                 << E1000_VT_CTL_DEFAULT_POOL_SHIFT;
     144                 :          0 :         vtctl |= E1000_VT_CTL_VM_REPL_EN;
     145                 :          0 :         E1000_WRITE_REG(hw, E1000_VT_CTL, vtctl);
     146                 :            : 
     147                 :            :         /* Enable pools reserved to PF only */
     148                 :          0 :         E1000_WRITE_REG(hw, E1000_VFRE, (~0U) << vf_num);
     149                 :          0 :         E1000_WRITE_REG(hw, E1000_VFTE, (~0U) << vf_num);
     150                 :            : 
     151                 :            :         /* PFDMA Tx General Switch Control Enables VMDQ loopback */
     152         [ #  # ]:          0 :         if (hw->mac.type == e1000_i350)
     153                 :          0 :                 E1000_WRITE_REG(hw, E1000_TXSWC, E1000_DTXSWC_VMDQ_LOOPBACK_EN);
     154                 :            :         else
     155                 :          0 :                 E1000_WRITE_REG(hw, E1000_DTXSWC, E1000_DTXSWC_VMDQ_LOOPBACK_EN);
     156                 :            : 
     157                 :            :         /* clear VMDq map to permanent rar 0 */
     158                 :          0 :         rah = E1000_READ_REG(hw, E1000_RAH(0));
     159                 :          0 :         rah &= ~ (0xFF << E1000_RAH_POOLSEL_SHIFT);
     160                 :          0 :         E1000_WRITE_REG(hw, E1000_RAH(0), rah);
     161                 :            : 
     162                 :            :         /* clear VMDq map to scan rar 32 */
     163         [ #  # ]:          0 :         rah = E1000_READ_REG(hw, E1000_RAH(hw->mac.rar_entry_count));
     164                 :          0 :         rah &= ~ (0xFF << E1000_RAH_POOLSEL_SHIFT);
     165         [ #  # ]:          0 :         E1000_WRITE_REG(hw, E1000_RAH(hw->mac.rar_entry_count), rah);
     166                 :            : 
     167                 :            :         /* set VMDq map to default PF pool */
     168                 :          0 :         rah = E1000_READ_REG(hw, E1000_RAH(0));
     169                 :          0 :         rah |= (0x1 << (RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx +
     170                 :            :                         E1000_RAH_POOLSEL_SHIFT));
     171                 :          0 :         E1000_WRITE_REG(hw, E1000_RAH(0), rah);
     172                 :            : 
     173                 :            :         /*
     174                 :            :          * enable vlan filtering and allow all vlan tags through
     175                 :            :          */
     176                 :          0 :         vlanctrl = E1000_READ_REG(hw, E1000_RCTL);
     177                 :          0 :         vlanctrl |= E1000_RCTL_VFE ; /* enable vlan filters */
     178                 :          0 :         E1000_WRITE_REG(hw, E1000_RCTL, vlanctrl);
     179                 :            : 
     180                 :            :         /* VFTA - enable all vlan filters */
     181         [ #  # ]:          0 :         for (i = 0; i < IGB_VFTA_SIZE; i++) {
     182                 :          0 :                 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, 0xFFFFFFFF);
     183                 :            :         }
     184                 :            : 
     185                 :            :         /* Enable/Disable MAC Anti-Spoofing */
     186                 :          0 :         e1000_vmdq_set_anti_spoofing_pf(hw, FALSE, vf_num);
     187                 :            : 
     188                 :          0 :         return 0;
     189                 :            : }
     190                 :            : 
     191                 :            : static void
     192                 :          0 : set_rx_mode(struct rte_eth_dev *dev)
     193                 :            : {
     194                 :          0 :         struct rte_eth_dev_data *dev_data = dev->data;
     195                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     196                 :            :         uint32_t fctrl, vmolr = E1000_VMOLR_BAM | E1000_VMOLR_AUPE;
     197                 :            :         uint16_t vfn = dev_num_vf(dev);
     198                 :            : 
     199                 :            :         /* Check for Promiscuous and All Multicast modes */
     200                 :          0 :         fctrl = E1000_READ_REG(hw, E1000_RCTL);
     201                 :            : 
     202                 :            :         /* set all bits that we expect to always be set */
     203                 :            :         fctrl &= ~E1000_RCTL_SBP; /* disable store-bad-packets */
     204                 :            :         fctrl |= E1000_RCTL_BAM;
     205                 :            : 
     206                 :            :         /* clear the bits we are changing the status of */
     207                 :          0 :         fctrl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
     208                 :            : 
     209         [ #  # ]:          0 :         if (dev_data->promiscuous) {
     210                 :          0 :                 fctrl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
     211                 :            :                 vmolr |= (E1000_VMOLR_ROPE | E1000_VMOLR_MPME);
     212                 :            :         } else {
     213         [ #  # ]:          0 :                 if (dev_data->all_multicast) {
     214                 :          0 :                         fctrl |= E1000_RCTL_MPE;
     215                 :            :                         vmolr |= E1000_VMOLR_MPME;
     216                 :            :                 } else {
     217                 :            :                         vmolr |= E1000_VMOLR_ROMPE;
     218                 :            :                 }
     219                 :            :         }
     220                 :            : 
     221         [ #  # ]:          0 :         if ((hw->mac.type == e1000_82576) ||
     222                 :            :                 (hw->mac.type == e1000_i350)) {
     223                 :          0 :                 vmolr |= E1000_READ_REG(hw, E1000_VMOLR(vfn)) &
     224                 :            :                          ~(E1000_VMOLR_MPME | E1000_VMOLR_ROMPE |
     225                 :            :                            E1000_VMOLR_ROPE);
     226                 :          0 :                 E1000_WRITE_REG(hw, E1000_VMOLR(vfn), vmolr);
     227                 :            :         }
     228                 :            : 
     229                 :          0 :         E1000_WRITE_REG(hw, E1000_RCTL, fctrl);
     230                 :          0 : }
     231                 :            : 
     232                 :            : static inline void
     233                 :          0 : igb_vf_reset_event(struct rte_eth_dev *dev, uint16_t vf)
     234                 :            : {
     235                 :            :         struct e1000_hw *hw =
     236                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     237                 :          0 :         struct e1000_vf_info *vfinfo =
     238                 :            :                 *(E1000_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
     239                 :          0 :         uint32_t vmolr = E1000_READ_REG(hw, E1000_VMOLR(vf));
     240                 :            : 
     241                 :          0 :         vmolr |= (E1000_VMOLR_ROPE | E1000_VMOLR_ROMPE |
     242                 :            :                         E1000_VMOLR_BAM | E1000_VMOLR_AUPE);
     243                 :          0 :         E1000_WRITE_REG(hw, E1000_VMOLR(vf), vmolr);
     244                 :            : 
     245                 :          0 :         E1000_WRITE_REG(hw, E1000_VMVIR(vf), 0);
     246                 :            : 
     247                 :            :         /* reset multicast table array for vf */
     248                 :          0 :         vfinfo[vf].num_vf_mc_hashes = 0;
     249                 :            : 
     250                 :            :         /* reset rx mode */
     251                 :          0 :         set_rx_mode(dev);
     252                 :          0 : }
     253                 :            : 
     254                 :            : static inline void
     255                 :          0 : igb_vf_reset_msg(struct rte_eth_dev *dev, uint16_t vf)
     256                 :            : {
     257                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     258                 :            :         uint32_t reg;
     259                 :            : 
     260                 :            :         /* enable transmit and receive for vf */
     261                 :          0 :         reg = E1000_READ_REG(hw, E1000_VFTE);
     262                 :          0 :         reg |= (reg | (1 << vf));
     263                 :          0 :         E1000_WRITE_REG(hw, E1000_VFTE, reg);
     264                 :            : 
     265                 :          0 :         reg = E1000_READ_REG(hw, E1000_VFRE);
     266                 :          0 :         reg |= (reg | (1 << vf));
     267                 :          0 :         E1000_WRITE_REG(hw, E1000_VFRE, reg);
     268                 :            : 
     269                 :          0 :         igb_vf_reset_event(dev, vf);
     270                 :          0 : }
     271                 :            : 
     272                 :            : static int
     273                 :          0 : igb_vf_reset(struct rte_eth_dev *dev, uint16_t vf, uint32_t *msgbuf)
     274                 :            : {
     275                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     276                 :          0 :         struct e1000_vf_info *vfinfo =
     277                 :            :                 *(E1000_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
     278                 :          0 :         unsigned char *vf_mac = vfinfo[vf].vf_mac_addresses;
     279                 :          0 :         int rar_entry = hw->mac.rar_entry_count - (vf + 1);
     280                 :          0 :         uint8_t *new_mac = (uint8_t *)(&msgbuf[1]);
     281                 :            :         uint32_t rah;
     282                 :            : 
     283                 :          0 :         igb_vf_reset_msg(dev, vf);
     284                 :            : 
     285                 :          0 :         hw->mac.ops.rar_set(hw, vf_mac, rar_entry);
     286         [ #  # ]:          0 :         rah = E1000_READ_REG(hw, E1000_RAH(rar_entry));
     287                 :          0 :         rah |= (0x1 << (vf + E1000_RAH_POOLSEL_SHIFT));
     288                 :          0 :         E1000_WRITE_REG(hw, E1000_RAH(rar_entry), rah);
     289                 :            : 
     290                 :            :         /* reply to reset with ack and vf mac address */
     291                 :          0 :         msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK;
     292                 :            :         memcpy(new_mac, vf_mac, RTE_ETHER_ADDR_LEN);
     293                 :          0 :         e1000_write_mbx(hw, msgbuf, 3, vf);
     294                 :            : 
     295                 :          0 :         return 0;
     296                 :            : }
     297                 :            : 
     298                 :            : static int
     299                 :          0 : igb_vf_set_mac_addr(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
     300                 :            : {
     301                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     302                 :          0 :         struct e1000_vf_info *vfinfo =
     303                 :            :                 *(E1000_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
     304                 :          0 :         int rar_entry = hw->mac.rar_entry_count - (vf + 1);
     305         [ #  # ]:          0 :         uint8_t *new_mac = (uint8_t *)(&msgbuf[1]);
     306                 :            :         int rah;
     307                 :            : 
     308         [ #  # ]:          0 :         if (rte_is_unicast_ether_addr((struct rte_ether_addr *)new_mac)) {
     309         [ #  # ]:          0 :                 if (!rte_is_zero_ether_addr((struct rte_ether_addr *)new_mac))
     310                 :          0 :                         memcpy(vfinfo[vf].vf_mac_addresses, new_mac,
     311                 :            :                                 sizeof(vfinfo[vf].vf_mac_addresses));
     312                 :          0 :                 hw->mac.ops.rar_set(hw, new_mac, rar_entry);
     313         [ #  # ]:          0 :                 rah = E1000_READ_REG(hw, E1000_RAH(rar_entry));
     314                 :          0 :                 rah |= (0x1 << (E1000_RAH_POOLSEL_SHIFT + vf));
     315                 :          0 :                 E1000_WRITE_REG(hw, E1000_RAH(rar_entry), rah);
     316                 :          0 :                 return 0;
     317                 :            :         }
     318                 :            :         return -1;
     319                 :            : }
     320                 :            : 
     321                 :            : static int
     322                 :          0 : igb_vf_set_multicast(struct rte_eth_dev *dev, __rte_unused uint32_t vf, uint32_t *msgbuf)
     323                 :            : {
     324                 :            :         int i;
     325                 :            :         uint32_t vector_bit;
     326                 :            :         uint32_t vector_reg;
     327                 :            :         uint32_t mta_reg;
     328                 :          0 :         int entries = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >>
     329                 :            :                 E1000_VT_MSGINFO_SHIFT;
     330                 :            :         uint16_t *hash_list = (uint16_t *)&msgbuf[1];
     331                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     332                 :          0 :         struct e1000_vf_info *vfinfo =
     333                 :            :                 *(E1000_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
     334                 :            : 
     335                 :            :         /* only so many hash values supported */
     336                 :          0 :         entries = RTE_MIN(entries, E1000_MAX_VF_MC_ENTRIES);
     337                 :            : 
     338                 :            :         /*
     339                 :            :          * salt away the number of multi cast addresses assigned
     340                 :            :          * to this VF for later use to restore when the PF multi cast
     341                 :            :          * list changes
     342                 :            :          */
     343                 :          0 :         vfinfo->num_vf_mc_hashes = (uint16_t)entries;
     344                 :            : 
     345                 :            :         /*
     346                 :            :          * VFs are limited to using the MTA hash table for their multicast
     347                 :            :          * addresses
     348                 :            :          */
     349         [ #  # ]:          0 :         for (i = 0; i < entries; i++) {
     350                 :          0 :                 vfinfo->vf_mc_hashes[i] = hash_list[i];
     351                 :            :         }
     352                 :            : 
     353         [ #  # ]:          0 :         for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) {
     354                 :          0 :                 vector_reg = (vfinfo->vf_mc_hashes[i] >> 5) & 0x7F;
     355                 :          0 :                 vector_bit = vfinfo->vf_mc_hashes[i] & 0x1F;
     356                 :          0 :                 mta_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, vector_reg);
     357                 :          0 :                 mta_reg |= (1 << vector_bit);
     358                 :          0 :                 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, vector_reg, mta_reg);
     359                 :            :         }
     360                 :            : 
     361                 :          0 :         return 0;
     362                 :            : }
     363                 :            : 
     364                 :            : static int
     365                 :          0 : igb_vf_set_vlan(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
     366                 :            : {
     367                 :            :         int add, vid;
     368                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     369                 :          0 :         struct e1000_vf_info *vfinfo =
     370                 :            :                 *(E1000_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
     371                 :            :         uint32_t vid_idx, vid_bit, vfta;
     372                 :            : 
     373                 :          0 :         add = (msgbuf[0] & E1000_VT_MSGINFO_MASK)
     374                 :          0 :                 >> E1000_VT_MSGINFO_SHIFT;
     375                 :          0 :         vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK);
     376                 :            : 
     377         [ #  # ]:          0 :         if (add)
     378                 :          0 :                 vfinfo[vf].vlan_count++;
     379         [ #  # ]:          0 :         else if (vfinfo[vf].vlan_count)
     380                 :          0 :                 vfinfo[vf].vlan_count--;
     381                 :            : 
     382                 :          0 :         vid_idx = (uint32_t)((vid >> E1000_VFTA_ENTRY_SHIFT) &
     383                 :            :                              E1000_VFTA_ENTRY_MASK);
     384                 :          0 :         vid_bit = (uint32_t)(1 << (vid & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
     385                 :          0 :         vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
     386         [ #  # ]:          0 :         if (add)
     387                 :          0 :                 vfta |= vid_bit;
     388                 :            :         else
     389                 :          0 :                 vfta &= ~vid_bit;
     390                 :            : 
     391                 :          0 :         E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
     392                 :          0 :         E1000_WRITE_FLUSH(hw);
     393                 :            : 
     394                 :          0 :         return 0;
     395                 :            : }
     396                 :            : 
     397                 :            : static int
     398                 :          0 : igb_vf_set_rlpml(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
     399                 :            : {
     400                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     401                 :          0 :         uint16_t rlpml = msgbuf[1] & E1000_VMOLR_RLPML_MASK;
     402                 :            :         uint32_t max_frame = rlpml + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
     403                 :            :         uint32_t vmolr;
     404                 :            : 
     405         [ #  # ]:          0 :         if (max_frame < RTE_ETHER_MIN_LEN ||
     406                 :            :                         max_frame > RTE_ETHER_MAX_JUMBO_FRAME_LEN)
     407                 :            :                 return -1;
     408                 :            : 
     409                 :          0 :         vmolr = E1000_READ_REG(hw, E1000_VMOLR(vf));
     410                 :            : 
     411                 :          0 :         vmolr &= ~E1000_VMOLR_RLPML_MASK;
     412                 :          0 :         vmolr |= rlpml;
     413                 :            : 
     414                 :            :         /* Enable Long Packet support */
     415                 :          0 :         vmolr |= E1000_VMOLR_LPE;
     416                 :            : 
     417                 :          0 :         E1000_WRITE_REG(hw, E1000_VMOLR(vf), vmolr);
     418                 :          0 :         E1000_WRITE_FLUSH(hw);
     419                 :            : 
     420                 :          0 :         return 0;
     421                 :            : }
     422                 :            : 
     423                 :            : static int
     424                 :          0 : igb_rcv_msg_from_vf(struct rte_eth_dev *dev, uint16_t vf)
     425                 :            : {
     426                 :            :         uint16_t mbx_size = E1000_VFMAILBOX_SIZE;
     427                 :            :         uint32_t msgbuf[E1000_VFMAILBOX_SIZE];
     428                 :            :         int32_t retval;
     429                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     430                 :            : 
     431                 :          0 :         retval = e1000_read_mbx(hw, msgbuf, mbx_size, vf);
     432         [ #  # ]:          0 :         if (retval) {
     433                 :          0 :                 PMD_INIT_LOG(ERR, "Error mbx recv msg from VF %d", vf);
     434                 :          0 :                 return retval;
     435                 :            :         }
     436                 :            : 
     437                 :            :         /* do nothing with the message already processed */
     438         [ #  # ]:          0 :         if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK))
     439                 :            :                 return retval;
     440                 :            : 
     441                 :            :         /* flush the ack before we write any messages back */
     442                 :          0 :         E1000_WRITE_FLUSH(hw);
     443                 :            : 
     444                 :            :         /* perform VF reset */
     445         [ #  # ]:          0 :         if (msgbuf[0] == E1000_VF_RESET) {
     446                 :          0 :                 return igb_vf_reset(dev, vf, msgbuf);
     447                 :            :         }
     448                 :            : 
     449                 :            :         /* check & process VF to PF mailbox message */
     450   [ #  #  #  #  :          0 :         switch ((msgbuf[0] & 0xFFFF)) {
                      # ]
     451                 :          0 :         case E1000_VF_SET_MAC_ADDR:
     452                 :          0 :                 retval = igb_vf_set_mac_addr(dev, vf, msgbuf);
     453                 :          0 :                 break;
     454                 :          0 :         case E1000_VF_SET_MULTICAST:
     455                 :          0 :                 retval = igb_vf_set_multicast(dev, vf, msgbuf);
     456                 :          0 :                 break;
     457                 :          0 :         case E1000_VF_SET_LPE:
     458                 :          0 :                 retval = igb_vf_set_rlpml(dev, vf, msgbuf);
     459                 :          0 :                 break;
     460                 :          0 :         case E1000_VF_SET_VLAN:
     461                 :          0 :                 retval = igb_vf_set_vlan(dev, vf, msgbuf);
     462                 :          0 :                 break;
     463                 :          0 :         default:
     464                 :          0 :                 PMD_INIT_LOG(DEBUG, "Unhandled Msg %8.8x",
     465                 :            :                              (unsigned) msgbuf[0]);
     466                 :            :                 retval = E1000_ERR_MBX;
     467                 :            :                 break;
     468                 :            :         }
     469                 :            : 
     470                 :            :         /* response the VF according to the message process result */
     471         [ #  # ]:          0 :         if (retval)
     472                 :          0 :                 msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
     473                 :            :         else
     474                 :          0 :                 msgbuf[0] |= E1000_VT_MSGTYPE_ACK;
     475                 :            : 
     476                 :          0 :         msgbuf[0] |= E1000_VT_MSGTYPE_CTS;
     477                 :            : 
     478                 :          0 :         e1000_write_mbx(hw, msgbuf, 1, vf);
     479                 :            : 
     480                 :          0 :         return retval;
     481                 :            : }
     482                 :            : 
     483                 :            : static inline void
     484                 :            : igb_rcv_ack_from_vf(struct rte_eth_dev *dev, uint16_t vf)
     485                 :            : {
     486                 :          0 :         uint32_t msg = E1000_VT_MSGTYPE_NACK;
     487                 :          0 :         struct e1000_hw *hw =
     488                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     489                 :            : 
     490                 :          0 :         e1000_write_mbx(hw, &msg, 1, vf);
     491                 :          0 : }
     492                 :            : 
     493                 :          0 : void igb_pf_mbx_process(struct rte_eth_dev *eth_dev)
     494                 :            : {
     495                 :            :         uint16_t vf;
     496                 :          0 :         struct e1000_hw *hw =
     497                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
     498                 :            : 
     499         [ #  # ]:          0 :         for (vf = 0; vf < dev_num_vf(eth_dev); vf++) {
     500                 :            :                 /* check & process vf function level reset */
     501         [ #  # ]:          0 :                 if (!e1000_check_for_rst(hw, vf))
     502                 :          0 :                         igb_vf_reset_event(eth_dev, vf);
     503                 :            : 
     504                 :            :                 /* check & process vf mailbox messages */
     505         [ #  # ]:          0 :                 if (!e1000_check_for_msg(hw, vf))
     506                 :          0 :                         igb_rcv_msg_from_vf(eth_dev, vf);
     507                 :            : 
     508                 :            :                 /* check & process acks from vf */
     509         [ #  # ]:          0 :                 if (!e1000_check_for_ack(hw, vf))
     510                 :            :                         igb_rcv_ack_from_vf(eth_dev, vf);
     511                 :            :         }
     512                 :          0 : }

Generated by: LCOV version 1.14