LCOV - code coverage report
Current view: top level - drivers/net/ixgbe/base - ixgbe_vf.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 260 0.0 %
Date: 2024-12-01 18:57:19 Functions: 0 22 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 123 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2001-2020 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : 
       6                 :            : #include "ixgbe_api.h"
       7                 :            : #include "ixgbe_type.h"
       8                 :            : #include "ixgbe_vf.h"
       9                 :            : 
      10                 :            : #define IXGBE_VFWRITE_REG IXGBE_WRITE_REG
      11                 :            : #define IXGBE_VFREAD_REG IXGBE_READ_REG
      12                 :            : 
      13                 :            : /**
      14                 :            :  * ixgbe_init_ops_vf - Initialize the pointers for vf
      15                 :            :  * @hw: pointer to hardware structure
      16                 :            :  *
      17                 :            :  * This will assign function pointers, adapter-specific functions can
      18                 :            :  * override the assignment of generic function pointers by assigning
      19                 :            :  * their own adapter-specific function pointers.
      20                 :            :  * Does not touch the hardware.
      21                 :            :  **/
      22                 :          0 : s32 ixgbe_init_ops_vf(struct ixgbe_hw *hw)
      23                 :            : {
      24                 :            :         u16 i;
      25                 :            : 
      26                 :            :         /* MAC */
      27                 :          0 :         hw->mac.ops.init_hw = ixgbe_init_hw_vf;
      28                 :          0 :         hw->mac.ops.reset_hw = ixgbe_reset_hw_vf;
      29                 :          0 :         hw->mac.ops.start_hw = ixgbe_start_hw_vf;
      30                 :            :         /* Cannot clear stats on VF */
      31                 :          0 :         hw->mac.ops.clear_hw_cntrs = NULL;
      32                 :          0 :         hw->mac.ops.get_media_type = NULL;
      33                 :          0 :         hw->mac.ops.get_mac_addr = ixgbe_get_mac_addr_vf;
      34                 :          0 :         hw->mac.ops.stop_adapter = ixgbe_stop_adapter_vf;
      35                 :          0 :         hw->mac.ops.get_bus_info = NULL;
      36                 :          0 :         hw->mac.ops.negotiate_api_version = ixgbevf_negotiate_api_version;
      37                 :            : 
      38                 :            :         /* Link */
      39                 :          0 :         hw->mac.ops.setup_link = ixgbe_setup_mac_link_vf;
      40                 :          0 :         hw->mac.ops.check_link = ixgbe_check_mac_link_vf;
      41                 :          0 :         hw->mac.ops.get_link_capabilities = NULL;
      42                 :            : 
      43                 :            :         /* RAR, Multicast, VLAN */
      44                 :          0 :         hw->mac.ops.set_rar = ixgbe_set_rar_vf;
      45                 :          0 :         hw->mac.ops.set_uc_addr = ixgbevf_set_uc_addr_vf;
      46                 :          0 :         hw->mac.ops.init_rx_addrs = NULL;
      47                 :          0 :         hw->mac.ops.update_mc_addr_list = ixgbe_update_mc_addr_list_vf;
      48                 :          0 :         hw->mac.ops.update_xcast_mode = ixgbevf_update_xcast_mode;
      49                 :          0 :         hw->mac.ops.get_link_state = ixgbe_get_link_state_vf;
      50                 :          0 :         hw->mac.ops.enable_mc = NULL;
      51                 :          0 :         hw->mac.ops.disable_mc = NULL;
      52                 :          0 :         hw->mac.ops.clear_vfta = NULL;
      53                 :          0 :         hw->mac.ops.set_vfta = ixgbe_set_vfta_vf;
      54                 :          0 :         hw->mac.ops.set_rlpml = ixgbevf_rlpml_set_vf;
      55                 :            : 
      56                 :          0 :         hw->mac.max_tx_queues = 1;
      57                 :          0 :         hw->mac.max_rx_queues = 1;
      58                 :            : 
      59         [ #  # ]:          0 :         for (i = 0; i < 64; i++)
      60                 :          0 :                 hw->mbx.ops[i].init_params = ixgbe_init_mbx_params_vf;
      61                 :            : 
      62                 :          0 :         return IXGBE_SUCCESS;
      63                 :            : }
      64                 :            : 
      65                 :            : /* ixgbe_virt_clr_reg - Set register to default (power on) state.
      66                 :            :  * @hw: pointer to hardware structure
      67                 :            :  */
      68                 :          0 : static void ixgbe_virt_clr_reg(struct ixgbe_hw *hw)
      69                 :            : {
      70                 :            :         int i;
      71                 :            :         u32 vfsrrctl;
      72                 :            :         u32 vfdca_rxctrl;
      73                 :            :         u32 vfdca_txctrl;
      74                 :            : 
      75                 :            :         /* VRSRRCTL default values (BSIZEPACKET = 2048, BSIZEHEADER = 256) */
      76                 :            :         vfsrrctl = 0x100 << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
      77                 :            :         vfsrrctl |= 0x800 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
      78                 :            : 
      79                 :            :         /* DCA_RXCTRL default value */
      80                 :            :         vfdca_rxctrl = IXGBE_DCA_RXCTRL_DESC_RRO_EN |
      81                 :            :                        IXGBE_DCA_RXCTRL_DATA_WRO_EN |
      82                 :            :                        IXGBE_DCA_RXCTRL_HEAD_WRO_EN;
      83                 :            : 
      84                 :            :         /* DCA_TXCTRL default value */
      85                 :            :         vfdca_txctrl = IXGBE_DCA_TXCTRL_DESC_RRO_EN |
      86                 :            :                        IXGBE_DCA_TXCTRL_DESC_WRO_EN |
      87                 :            :                        IXGBE_DCA_TXCTRL_DATA_RRO_EN;
      88                 :            : 
      89                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, 0);
      90                 :            : 
      91         [ #  # ]:          0 :         for (i = 0; i < 8; i++) {
      92                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VFRDH(i), 0);
      93                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VFRDT(i), 0);
      94                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), 0);
      95                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VFSRRCTL(i), vfsrrctl);
      96                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VFTDH(i), 0);
      97                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VFTDT(i), 0);
      98                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), 0);
      99                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VFTDWBAH(i), 0);
     100                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VFTDWBAL(i), 0);
     101                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VFDCA_RXCTRL(i), vfdca_rxctrl);
     102                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VFDCA_TXCTRL(i), vfdca_txctrl);
     103                 :            :         }
     104                 :            : 
     105                 :          0 :         IXGBE_WRITE_FLUSH(hw);
     106                 :          0 : }
     107                 :            : 
     108                 :            : /**
     109                 :            :  * ixgbe_start_hw_vf - Prepare hardware for Tx/Rx
     110                 :            :  * @hw: pointer to hardware structure
     111                 :            :  *
     112                 :            :  * Starts the hardware by filling the bus info structure and media type, clears
     113                 :            :  * all on chip counters, initializes receive address registers, multicast
     114                 :            :  * table, VLAN filter table, calls routine to set up link and flow control
     115                 :            :  * settings, and leaves transmit and receive units disabled and uninitialized
     116                 :            :  **/
     117                 :          0 : s32 ixgbe_start_hw_vf(struct ixgbe_hw *hw)
     118                 :            : {
     119                 :            :         /* Clear adapter stopped flag */
     120                 :          0 :         hw->adapter_stopped = false;
     121                 :            : 
     122                 :          0 :         return IXGBE_SUCCESS;
     123                 :            : }
     124                 :            : 
     125                 :            : /**
     126                 :            :  * ixgbe_init_hw_vf - virtual function hardware initialization
     127                 :            :  * @hw: pointer to hardware structure
     128                 :            :  *
     129                 :            :  * Initialize the hardware by resetting the hardware and then starting
     130                 :            :  * the hardware
     131                 :            :  **/
     132                 :          0 : s32 ixgbe_init_hw_vf(struct ixgbe_hw *hw)
     133                 :            : {
     134                 :          0 :         s32 status = hw->mac.ops.start_hw(hw);
     135                 :            : 
     136                 :          0 :         hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
     137                 :            : 
     138                 :          0 :         return status;
     139                 :            : }
     140                 :            : 
     141                 :            : /**
     142                 :            :  * ixgbe_reset_hw_vf - Performs hardware reset
     143                 :            :  * @hw: pointer to hardware structure
     144                 :            :  *
     145                 :            :  * Resets the hardware by resetting the transmit and receive units, masks and
     146                 :            :  * clears all interrupts.
     147                 :            :  **/
     148                 :          0 : s32 ixgbe_reset_hw_vf(struct ixgbe_hw *hw)
     149                 :            : {
     150                 :            :         struct ixgbe_mbx_info *mbx = &hw->mbx;
     151                 :            :         u32 timeout = IXGBE_VF_INIT_TIMEOUT;
     152                 :            :         s32 ret_val = IXGBE_ERR_INVALID_MAC_ADDR;
     153                 :            :         u32 msgbuf[IXGBE_VF_PERMADDR_MSG_LEN];
     154                 :            :         u8 *addr = (u8 *)(&msgbuf[1]);
     155                 :            : 
     156                 :          0 :         DEBUGFUNC("ixgbevf_reset_hw_vf");
     157                 :            : 
     158                 :            :         /* Call adapter stop to disable tx/rx and clear interrupts */
     159                 :          0 :         hw->mac.ops.stop_adapter(hw);
     160                 :            : 
     161                 :            :         /* reset the api version */
     162                 :          0 :         hw->api_version = ixgbe_mbox_api_10;
     163                 :          0 :         ixgbe_init_mbx_params_vf(hw);
     164                 :            : 
     165                 :          0 :         DEBUGOUT("Issuing a function level reset to MAC\n");
     166                 :            : 
     167                 :          0 :         IXGBE_VFWRITE_REG(hw, IXGBE_VFCTRL, IXGBE_CTRL_RST);
     168                 :          0 :         IXGBE_WRITE_FLUSH(hw);
     169                 :            : 
     170                 :          0 :         msec_delay(50);
     171                 :            : 
     172                 :            :         /* we cannot reset while the RSTI / RSTD bits are asserted */
     173   [ #  #  #  # ]:          0 :         while (!mbx->ops[0].check_for_rst(hw, 0) && timeout) {
     174                 :          0 :                 timeout--;
     175                 :          0 :                 usec_delay(5);
     176                 :            :         }
     177                 :            : 
     178         [ #  # ]:          0 :         if (!timeout)
     179                 :            :                 return IXGBE_ERR_RESET_FAILED;
     180                 :            : 
     181                 :            :         /* Reset VF registers to initial values */
     182                 :          0 :         ixgbe_virt_clr_reg(hw);
     183                 :            : 
     184                 :            :         /* mailbox timeout can now become active */
     185                 :          0 :         mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
     186                 :            : 
     187                 :          0 :         msgbuf[0] = IXGBE_VF_RESET;
     188                 :          0 :         ixgbe_write_mbx(hw, msgbuf, 1, 0);
     189                 :            : 
     190                 :          0 :         msec_delay(10);
     191                 :            : 
     192                 :            :         /*
     193                 :            :          * set our "perm_addr" based on info provided by PF
     194                 :            :          * also set up the mc_filter_type which is piggy backed
     195                 :            :          * on the mac address in word 3
     196                 :            :          */
     197                 :          0 :         ret_val = ixgbe_poll_mbx(hw, msgbuf,
     198                 :            :                                  IXGBE_VF_PERMADDR_MSG_LEN, 0);
     199         [ #  # ]:          0 :         if (ret_val)
     200                 :            :                 return ret_val;
     201                 :            : 
     202         [ #  # ]:          0 :         if (msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_SUCCESS) &&
     203                 :            :             msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_FAILURE))
     204                 :            :                 return IXGBE_ERR_INVALID_MAC_ADDR;
     205                 :            : 
     206         [ #  # ]:          0 :         if (msgbuf[0] == (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_SUCCESS))
     207                 :          0 :                 memcpy(hw->mac.perm_addr, addr, IXGBE_ETH_LENGTH_OF_ADDRESS);
     208                 :            : 
     209                 :          0 :         hw->mac.mc_filter_type = msgbuf[IXGBE_VF_MC_TYPE_WORD];
     210                 :            : 
     211                 :          0 :         return ret_val;
     212                 :            : }
     213                 :            : 
     214                 :            : /**
     215                 :            :  * ixgbe_stop_adapter_vf - Generic stop Tx/Rx units
     216                 :            :  * @hw: pointer to hardware structure
     217                 :            :  *
     218                 :            :  * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
     219                 :            :  * disables transmit and receive units. The adapter_stopped flag is used by
     220                 :            :  * the shared code and drivers to determine if the adapter is in a stopped
     221                 :            :  * state and should not touch the hardware.
     222                 :            :  **/
     223                 :          0 : s32 ixgbe_stop_adapter_vf(struct ixgbe_hw *hw)
     224                 :            : {
     225                 :            :         u32 reg_val;
     226                 :            :         u16 i;
     227                 :            : 
     228                 :            :         /*
     229                 :            :          * Set the adapter_stopped flag so other driver functions stop touching
     230                 :            :          * the hardware
     231                 :            :          */
     232                 :          0 :         hw->adapter_stopped = true;
     233                 :            : 
     234                 :            :         /* Clear interrupt mask to stop from interrupts being generated */
     235                 :          0 :         IXGBE_VFWRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK);
     236                 :            : 
     237                 :            :         /* Clear any pending interrupts, flush previous writes */
     238                 :          0 :         IXGBE_VFREAD_REG(hw, IXGBE_VTEICR);
     239                 :            : 
     240                 :            :         /* Disable the transmit unit.  Each queue must be disabled. */
     241         [ #  # ]:          0 :         for (i = 0; i < hw->mac.max_tx_queues; i++)
     242                 :          0 :                 IXGBE_VFWRITE_REG(hw, IXGBE_VFTXDCTL(i), IXGBE_TXDCTL_SWFLSH);
     243                 :            : 
     244                 :            :         /* Disable the receive unit by stopping each queue */
     245         [ #  # ]:          0 :         for (i = 0; i < hw->mac.max_rx_queues; i++) {
     246                 :          0 :                 reg_val = IXGBE_VFREAD_REG(hw, IXGBE_VFRXDCTL(i));
     247                 :          0 :                 reg_val &= ~IXGBE_RXDCTL_ENABLE;
     248                 :          0 :                 IXGBE_VFWRITE_REG(hw, IXGBE_VFRXDCTL(i), reg_val);
     249                 :            :         }
     250                 :            :         /* Clear packet split and pool config */
     251                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, 0);
     252                 :            : 
     253                 :            :         /* flush all queues disables */
     254                 :          0 :         IXGBE_WRITE_FLUSH(hw);
     255                 :          0 :         msec_delay(2);
     256                 :            : 
     257                 :          0 :         return IXGBE_SUCCESS;
     258                 :            : }
     259                 :            : 
     260                 :            : /**
     261                 :            :  * ixgbe_mta_vector - Determines bit-vector in multicast table to set
     262                 :            :  * @hw: pointer to hardware structure
     263                 :            :  * @mc_addr: the multicast address
     264                 :            :  *
     265                 :            :  * Extracts the 12 bits, from a multicast address, to determine which
     266                 :            :  * bit-vector to set in the multicast table. The hardware uses 12 bits, from
     267                 :            :  * incoming rx multicast addresses, to determine the bit-vector to check in
     268                 :            :  * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
     269                 :            :  * by the MO field of the MCSTCTRL. The MO field is set during initialization
     270                 :            :  * to mc_filter_type.
     271                 :            :  **/
     272                 :          0 : STATIC s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
     273                 :            : {
     274                 :            :         u32 vector = 0;
     275                 :            : 
     276   [ #  #  #  #  :          0 :         switch (hw->mac.mc_filter_type) {
                      # ]
     277                 :          0 :         case 0:   /* use bits [47:36] of the address */
     278                 :          0 :                 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
     279                 :          0 :                 break;
     280                 :          0 :         case 1:   /* use bits [46:35] of the address */
     281                 :          0 :                 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
     282                 :          0 :                 break;
     283                 :          0 :         case 2:   /* use bits [45:34] of the address */
     284                 :          0 :                 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
     285                 :          0 :                 break;
     286                 :          0 :         case 3:   /* use bits [43:32] of the address */
     287                 :          0 :                 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
     288                 :          0 :                 break;
     289                 :          0 :         default:  /* Invalid mc_filter_type */
     290                 :          0 :                 DEBUGOUT("MC filter type param set incorrectly\n");
     291                 :          0 :                 ASSERT(0);
     292                 :            :                 break;
     293                 :            :         }
     294                 :            : 
     295                 :            :         /* vector can only be 12-bits or boundary will be exceeded */
     296                 :          0 :         vector &= 0xFFF;
     297                 :          0 :         return vector;
     298                 :            : }
     299                 :            : 
     300                 :          0 : STATIC s32 ixgbevf_write_msg_read_ack(struct ixgbe_hw *hw, u32 *msg,
     301                 :            :                                       u32 *retmsg, u16 size)
     302                 :            : {
     303                 :          0 :         s32 retval = ixgbe_write_mbx(hw, msg, size, 0);
     304                 :            : 
     305         [ #  # ]:          0 :         if (retval)
     306                 :            :                 return retval;
     307                 :            : 
     308                 :          0 :         return ixgbe_poll_mbx(hw, retmsg, size, 0);
     309                 :            : }
     310                 :            : 
     311                 :            : /**
     312                 :            :  * ixgbe_set_rar_vf - set device MAC address
     313                 :            :  * @hw: pointer to hardware structure
     314                 :            :  * @index: Receive address register to write
     315                 :            :  * @addr: Address to put into receive address register
     316                 :            :  * @vmdq: VMDq "set" or "pool" index
     317                 :            :  * @enable_addr: set flag that address is active
     318                 :            :  **/
     319                 :          0 : s32 ixgbe_set_rar_vf(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
     320                 :            :                      u32 enable_addr)
     321                 :            : {
     322                 :            :         u32 msgbuf[3];
     323                 :            :         u8 *msg_addr = (u8 *)(&msgbuf[1]);
     324                 :            :         s32 ret_val;
     325                 :            :         UNREFERENCED_3PARAMETER(vmdq, enable_addr, index);
     326                 :            : 
     327                 :            :         memset(msgbuf, 0, 12);
     328                 :          0 :         msgbuf[0] = IXGBE_VF_SET_MAC_ADDR;
     329                 :            :         memcpy(msg_addr, addr, 6);
     330                 :          0 :         ret_val = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
     331                 :            : 
     332                 :          0 :         msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
     333                 :            : 
     334                 :            :         /* if we had failure, the address was rejected, use "perm_addr" */
     335   [ #  #  #  # ]:          0 :         if (!ret_val &&
     336                 :            :             (msgbuf[0] == (IXGBE_VF_SET_MAC_ADDR | IXGBE_VT_MSGTYPE_FAILURE))) {
     337                 :          0 :                 ixgbe_get_mac_addr_vf(hw, hw->mac.addr);
     338                 :          0 :                 return IXGBE_ERR_MBX;
     339                 :            :         }
     340                 :            : 
     341                 :            :         return ret_val;
     342                 :            : }
     343                 :            : 
     344                 :            : /**
     345                 :            :  * ixgbe_update_mc_addr_list_vf - Update Multicast addresses
     346                 :            :  * @hw: pointer to the HW structure
     347                 :            :  * @mc_addr_list: array of multicast addresses to program
     348                 :            :  * @mc_addr_count: number of multicast addresses to program
     349                 :            :  * @next: caller supplied function to return next address in list
     350                 :            :  * @clear: unused
     351                 :            :  *
     352                 :            :  * Updates the Multicast Table Array.
     353                 :            :  **/
     354                 :          0 : s32 ixgbe_update_mc_addr_list_vf(struct ixgbe_hw *hw, u8 *mc_addr_list,
     355                 :            :                                  u32 mc_addr_count, ixgbe_mc_addr_itr next,
     356                 :            :                                  bool clear)
     357                 :            : {
     358                 :            :         u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
     359                 :            :         u16 *vector_list = (u16 *)&msgbuf[1];
     360                 :            :         u32 vector;
     361                 :            :         u32 cnt, i;
     362                 :            :         u32 vmdq;
     363                 :            : 
     364                 :            :         UNREFERENCED_1PARAMETER(clear);
     365                 :            : 
     366                 :          0 :         DEBUGFUNC("ixgbe_update_mc_addr_list_vf");
     367                 :            : 
     368                 :            :         /* Each entry in the list uses 1 16 bit word.  We have 30
     369                 :            :          * 16 bit words available in our HW msg buffer (minus 1 for the
     370                 :            :          * msg type).  That's 30 hash values if we pack 'em right.  If
     371                 :            :          * there are more than 30 MC addresses to add then punt the
     372                 :            :          * extras for now and then add code to handle more than 30 later.
     373                 :            :          * It would be unusual for a server to request that many multi-cast
     374                 :            :          * addresses except for in large enterprise network environments.
     375                 :            :          */
     376                 :            : 
     377                 :          0 :         DEBUGOUT1("MC Addr Count = %d\n", mc_addr_count);
     378                 :            : 
     379                 :          0 :         cnt = (mc_addr_count > 30) ? 30 : mc_addr_count;
     380                 :            :         msgbuf[0] = IXGBE_VF_SET_MULTICAST;
     381                 :          0 :         msgbuf[0] |= cnt << IXGBE_VT_MSGINFO_SHIFT;
     382                 :            : 
     383         [ #  # ]:          0 :         for (i = 0; i < cnt; i++) {
     384                 :          0 :                 vector = ixgbe_mta_vector(hw, next(hw, &mc_addr_list, &vmdq));
     385                 :          0 :                 DEBUGOUT1("Hash value = 0x%03X\n", vector);
     386                 :          0 :                 vector_list[i] = (u16)vector;
     387                 :            :         }
     388                 :            : 
     389                 :          0 :         return ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, IXGBE_VFMAILBOX_SIZE);
     390                 :            : }
     391                 :            : 
     392                 :            : /**
     393                 :            :  * ixgbevf_update_xcast_mode - Update Multicast mode
     394                 :            :  * @hw: pointer to the HW structure
     395                 :            :  * @xcast_mode: new multicast mode
     396                 :            :  *
     397                 :            :  * Updates the Multicast Mode of VF.
     398                 :            :  **/
     399                 :          0 : s32 ixgbevf_update_xcast_mode(struct ixgbe_hw *hw, int xcast_mode)
     400                 :            : {
     401                 :            :         u32 msgbuf[2];
     402                 :            :         s32 err;
     403                 :            : 
     404      [ #  #  # ]:          0 :         switch (hw->api_version) {
     405                 :          0 :         case ixgbe_mbox_api_12:
     406                 :            :                 /* New modes were introduced in 1.3 version */
     407         [ #  # ]:          0 :                 if (xcast_mode > IXGBEVF_XCAST_MODE_ALLMULTI)
     408                 :            :                         return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
     409                 :            :                 /* Fall through */
     410                 :            :         case ixgbe_mbox_api_13:
     411                 :            :         case ixgbe_mbox_api_15:
     412                 :            :                 break;
     413                 :            :         default:
     414                 :            :                 return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
     415                 :            :         }
     416                 :            : 
     417                 :          0 :         msgbuf[0] = IXGBE_VF_UPDATE_XCAST_MODE;
     418                 :          0 :         msgbuf[1] = xcast_mode;
     419                 :            : 
     420                 :          0 :         err = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
     421         [ #  # ]:          0 :         if (err)
     422                 :            :                 return err;
     423                 :            : 
     424                 :          0 :         msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
     425         [ #  # ]:          0 :         if (msgbuf[0] == (IXGBE_VF_UPDATE_XCAST_MODE | IXGBE_VT_MSGTYPE_FAILURE))
     426                 :          0 :                 return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
     427                 :            :         return IXGBE_SUCCESS;
     428                 :            : }
     429                 :            : 
     430                 :            : /**
     431                 :            :  * ixgbe_get_link_state_vf - Get VF link state from PF
     432                 :            :  * @hw: pointer to the HW structure
     433                 :            :  * @link_state: link state storage
     434                 :            :  *
     435                 :            :  * Returns state of the operation error or success.
     436                 :            :  **/
     437                 :          0 : s32 ixgbe_get_link_state_vf(struct ixgbe_hw *hw, bool *link_state)
     438                 :            : {
     439                 :            :         u32 msgbuf[2];
     440                 :            :         s32 err;
     441                 :            :         s32 ret_val;
     442                 :            : 
     443                 :          0 :         msgbuf[0] = IXGBE_VF_GET_LINK_STATE;
     444                 :          0 :         msgbuf[1] = 0x0;
     445                 :            : 
     446                 :          0 :         err = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
     447                 :            : 
     448   [ #  #  #  # ]:          0 :         if (err || (msgbuf[0] & IXGBE_VT_MSGTYPE_FAILURE)) {
     449                 :            :                 ret_val = IXGBE_ERR_MBX;
     450                 :            :         } else {
     451                 :            :                 ret_val = IXGBE_SUCCESS;
     452                 :          0 :                 *link_state = msgbuf[1];
     453                 :            :         }
     454                 :            : 
     455                 :          0 :         return ret_val;
     456                 :            : }
     457                 :            : 
     458                 :            : /**
     459                 :            :  * ixgbe_set_vfta_vf - Set/Unset vlan filter table address
     460                 :            :  * @hw: pointer to the HW structure
     461                 :            :  * @vlan: 12 bit VLAN ID
     462                 :            :  * @vind: unused by VF drivers
     463                 :            :  * @vlan_on: if true then set bit, else clear bit
     464                 :            :  * @vlvf_bypass: boolean flag indicating updating default pool is okay
     465                 :            :  *
     466                 :            :  * Turn on/off specified VLAN in the VLAN filter table.
     467                 :            :  **/
     468                 :          0 : s32 ixgbe_set_vfta_vf(struct ixgbe_hw *hw, u32 vlan, u32 vind,
     469                 :            :                       bool vlan_on, bool vlvf_bypass)
     470                 :            : {
     471                 :            :         u32 msgbuf[2];
     472                 :            :         s32 ret_val;
     473                 :            :         UNREFERENCED_2PARAMETER(vind, vlvf_bypass);
     474                 :            : 
     475                 :            :         msgbuf[0] = IXGBE_VF_SET_VLAN;
     476                 :          0 :         msgbuf[1] = vlan;
     477                 :            :         /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
     478                 :          0 :         msgbuf[0] |= vlan_on << IXGBE_VT_MSGINFO_SHIFT;
     479                 :            : 
     480                 :          0 :         ret_val = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
     481   [ #  #  #  # ]:          0 :         if (!ret_val && (msgbuf[0] & IXGBE_VT_MSGTYPE_SUCCESS))
     482                 :            :                 return IXGBE_SUCCESS;
     483                 :            : 
     484                 :          0 :         return ret_val | (msgbuf[0] & IXGBE_VT_MSGTYPE_FAILURE);
     485                 :            : }
     486                 :            : 
     487                 :            : /**
     488                 :            :  * ixgbe_get_num_of_tx_queues_vf - Get number of TX queues
     489                 :            :  * @hw: pointer to hardware structure
     490                 :            :  *
     491                 :            :  * Returns the number of transmit queues for the given adapter.
     492                 :            :  **/
     493                 :          0 : u32 ixgbe_get_num_of_tx_queues_vf(struct ixgbe_hw *hw)
     494                 :            : {
     495                 :            :         UNREFERENCED_1PARAMETER(hw);
     496                 :          0 :         return IXGBE_VF_MAX_TX_QUEUES;
     497                 :            : }
     498                 :            : 
     499                 :            : /**
     500                 :            :  * ixgbe_get_num_of_rx_queues_vf - Get number of RX queues
     501                 :            :  * @hw: pointer to hardware structure
     502                 :            :  *
     503                 :            :  * Returns the number of receive queues for the given adapter.
     504                 :            :  **/
     505                 :          0 : u32 ixgbe_get_num_of_rx_queues_vf(struct ixgbe_hw *hw)
     506                 :            : {
     507                 :            :         UNREFERENCED_1PARAMETER(hw);
     508                 :          0 :         return IXGBE_VF_MAX_RX_QUEUES;
     509                 :            : }
     510                 :            : 
     511                 :            : /**
     512                 :            :  * ixgbe_get_mac_addr_vf - Read device MAC address
     513                 :            :  * @hw: pointer to the HW structure
     514                 :            :  * @mac_addr: the MAC address
     515                 :            :  **/
     516                 :          0 : s32 ixgbe_get_mac_addr_vf(struct ixgbe_hw *hw, u8 *mac_addr)
     517                 :            : {
     518                 :            :         int i;
     519                 :            : 
     520         [ #  # ]:          0 :         for (i = 0; i < IXGBE_ETH_LENGTH_OF_ADDRESS; i++)
     521                 :          0 :                 mac_addr[i] = hw->mac.perm_addr[i];
     522                 :            : 
     523                 :          0 :         return IXGBE_SUCCESS;
     524                 :            : }
     525                 :            : 
     526         [ #  # ]:          0 : s32 ixgbevf_set_uc_addr_vf(struct ixgbe_hw *hw, u32 index, u8 *addr)
     527                 :            : {
     528                 :            :         u32 msgbuf[3], msgbuf_chk;
     529                 :            :         u8 *msg_addr = (u8 *)(&msgbuf[1]);
     530                 :            :         s32 ret_val;
     531                 :            : 
     532                 :            :         memset(msgbuf, 0, sizeof(msgbuf));
     533                 :            :         /*
     534                 :            :          * If index is one then this is the start of a new list and needs
     535                 :            :          * indication to the PF so it can do it's own list management.
     536                 :            :          * If it is zero then that tells the PF to just clear all of
     537                 :            :          * this VF's macvlans and there is no new list.
     538                 :            :          */
     539                 :          0 :         msgbuf[0] |= index << IXGBE_VT_MSGINFO_SHIFT;
     540                 :          0 :         msgbuf[0] |= IXGBE_VF_SET_MACVLAN;
     541                 :            :         msgbuf_chk = msgbuf[0];
     542         [ #  # ]:          0 :         if (addr)
     543                 :            :                 memcpy(msg_addr, addr, 6);
     544                 :            : 
     545                 :          0 :         ret_val = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
     546         [ #  # ]:          0 :         if (!ret_val) {
     547                 :          0 :                 msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
     548                 :            : 
     549         [ #  # ]:          0 :                 if (msgbuf[0] == (msgbuf_chk | IXGBE_VT_MSGTYPE_FAILURE))
     550                 :          0 :                         return IXGBE_ERR_OUT_OF_MEM;
     551                 :            :         }
     552                 :            : 
     553                 :            :         return ret_val;
     554                 :            : }
     555                 :            : 
     556                 :            : /**
     557                 :            :  * ixgbe_setup_mac_link_vf - Setup MAC link settings
     558                 :            :  * @hw: pointer to hardware structure
     559                 :            :  * @speed: new link speed
     560                 :            :  * @autoneg_wait_to_complete: true when waiting for completion is needed
     561                 :            :  *
     562                 :            :  * Set the link speed in the AUTOC register and restarts link.
     563                 :            :  **/
     564                 :          0 : s32 ixgbe_setup_mac_link_vf(struct ixgbe_hw *hw, ixgbe_link_speed speed,
     565                 :            :                             bool autoneg_wait_to_complete)
     566                 :            : {
     567                 :            :         UNREFERENCED_3PARAMETER(hw, speed, autoneg_wait_to_complete);
     568                 :          0 :         return IXGBE_SUCCESS;
     569                 :            : }
     570                 :            : 
     571                 :            : /**
     572                 :            :  * ixgbe_check_mac_link_vf - Get link/speed status
     573                 :            :  * @hw: pointer to hardware structure
     574                 :            :  * @speed: pointer to link speed
     575                 :            :  * @link_up: true is link is up, false otherwise
     576                 :            :  * @autoneg_wait_to_complete: true when waiting for completion is needed
     577                 :            :  *
     578                 :            :  * Reads the links register to determine if link is up and the current speed
     579                 :            :  **/
     580                 :          0 : s32 ixgbe_check_mac_link_vf(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
     581                 :            :                             bool *link_up, bool autoneg_wait_to_complete)
     582                 :            : {
     583                 :            :         struct ixgbe_mbx_info *mbx = &hw->mbx;
     584                 :            :         struct ixgbe_mac_info *mac = &hw->mac;
     585                 :            :         s32 ret_val = IXGBE_SUCCESS;
     586                 :          0 :         u32 in_msg = 0;
     587                 :            :         u32 links_reg;
     588                 :            : 
     589                 :            :         UNREFERENCED_1PARAMETER(autoneg_wait_to_complete);
     590                 :            : 
     591                 :            :         /* If we were hit with a reset drop the link */
     592   [ #  #  #  # ]:          0 :         if (!mbx->ops[0].check_for_rst(hw, 0) || !mbx->timeout)
     593                 :          0 :                 mac->get_link_status = true;
     594                 :            : 
     595         [ #  # ]:          0 :         if (!mac->get_link_status)
     596                 :          0 :                 goto out;
     597                 :            : 
     598                 :            :         /* if link status is down no point in checking to see if pf is up */
     599                 :          0 :         links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
     600         [ #  # ]:          0 :         if (!(links_reg & IXGBE_LINKS_UP))
     601                 :          0 :                 goto out;
     602                 :            : 
     603                 :            :         /* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
     604                 :            :          * before the link status is correct
     605                 :            :          */
     606         [ #  # ]:          0 :         if (mac->type == ixgbe_mac_82599_vf) {
     607                 :            :                 int i;
     608                 :            : 
     609         [ #  # ]:          0 :                 for (i = 0; i < 5; i++) {
     610                 :          0 :                         usec_delay(100);
     611                 :          0 :                         links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
     612                 :            : 
     613         [ #  # ]:          0 :                         if (!(links_reg & IXGBE_LINKS_UP))
     614                 :          0 :                                 goto out;
     615                 :            :                 }
     616                 :            :         }
     617                 :            : 
     618   [ #  #  #  #  :          0 :         switch (links_reg & IXGBE_LINKS_SPEED_82599) {
                      # ]
     619                 :          0 :         case IXGBE_LINKS_SPEED_10G_82599:
     620                 :          0 :                 *speed = IXGBE_LINK_SPEED_10GB_FULL;
     621         [ #  # ]:          0 :                 if (hw->mac.type >= ixgbe_mac_X550_vf) {
     622         [ #  # ]:          0 :                         if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
     623                 :          0 :                                 *speed = IXGBE_LINK_SPEED_2_5GB_FULL;
     624                 :            :                 }
     625                 :            :                 break;
     626                 :          0 :         case IXGBE_LINKS_SPEED_1G_82599:
     627                 :          0 :                 *speed = IXGBE_LINK_SPEED_1GB_FULL;
     628                 :          0 :                 break;
     629                 :          0 :         case IXGBE_LINKS_SPEED_100_82599:
     630                 :          0 :                 *speed = IXGBE_LINK_SPEED_100_FULL;
     631         [ #  # ]:          0 :                 if (hw->mac.type == ixgbe_mac_X550_vf ||
     632                 :            :                     hw->mac.type == ixgbe_mac_E610_vf) {
     633         [ #  # ]:          0 :                         if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
     634                 :          0 :                                 *speed = IXGBE_LINK_SPEED_5GB_FULL;
     635                 :            :                 }
     636                 :            :                 break;
     637                 :          0 :         case IXGBE_LINKS_SPEED_10_X550EM_A:
     638                 :          0 :                 *speed = IXGBE_LINK_SPEED_UNKNOWN;
     639                 :            :                 /* Since Reserved in older MAC's */
     640         [ #  # ]:          0 :                 if (hw->mac.type >= ixgbe_mac_X550_vf)
     641                 :          0 :                         *speed = IXGBE_LINK_SPEED_10_FULL;
     642                 :            :                 break;
     643                 :          0 :         default:
     644                 :          0 :                 *speed = IXGBE_LINK_SPEED_UNKNOWN;
     645                 :            :         }
     646                 :            : 
     647                 :            :         /* if the read failed it could just be a mailbox collision, best wait
     648                 :            :          * until we are called again and don't report an error
     649                 :            :          */
     650         [ #  # ]:          0 :         if (ixgbe_read_mbx(hw, &in_msg, 1, 0)) {
     651         [ #  # ]:          0 :                 if (hw->api_version >= ixgbe_mbox_api_15)
     652                 :          0 :                         mac->get_link_status = false;
     653                 :          0 :                 goto out;
     654                 :            :         }
     655                 :            : 
     656         [ #  # ]:          0 :         if (!(in_msg & IXGBE_VT_MSGTYPE_CTS)) {
     657                 :            :                 /* msg is not CTS and is FAILURE we must have lost CTS status */
     658         [ #  # ]:          0 :                 if (in_msg & IXGBE_VT_MSGTYPE_FAILURE)
     659                 :            :                         ret_val = IXGBE_ERR_MBX;
     660                 :          0 :                 goto out;
     661                 :            :         }
     662                 :            : 
     663                 :            :         /* the pf is talking, if we timed out in the past we reinit */
     664         [ #  # ]:          0 :         if (!mbx->timeout) {
     665                 :            :                 ret_val = IXGBE_ERR_TIMEOUT;
     666                 :          0 :                 goto out;
     667                 :            :         }
     668                 :            : 
     669                 :            :         /* if we passed all the tests above then the link is up and we no
     670                 :            :          * longer need to check for link
     671                 :            :          */
     672                 :          0 :         mac->get_link_status = false;
     673                 :            : 
     674                 :          0 : out:
     675                 :          0 :         *link_up = !mac->get_link_status;
     676                 :          0 :         return ret_val;
     677                 :            : }
     678                 :            : 
     679                 :            : /**
     680                 :            :  * ixgbevf_rlpml_set_vf - Set the maximum receive packet length
     681                 :            :  * @hw: pointer to the HW structure
     682                 :            :  * @max_size: value to assign to max frame size
     683                 :            :  **/
     684                 :          0 : s32 ixgbevf_rlpml_set_vf(struct ixgbe_hw *hw, u16 max_size)
     685                 :            : {
     686                 :            :         u32 msgbuf[2];
     687                 :            :         s32 retval;
     688                 :            : 
     689                 :          0 :         msgbuf[0] = IXGBE_VF_SET_LPE;
     690                 :          0 :         msgbuf[1] = max_size;
     691                 :            : 
     692                 :          0 :         retval = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
     693         [ #  # ]:          0 :         if (retval)
     694                 :            :                 return retval;
     695         [ #  # ]:          0 :         if ((msgbuf[0] & IXGBE_VF_SET_LPE) &&
     696         [ #  # ]:          0 :             (msgbuf[0] & IXGBE_VT_MSGTYPE_FAILURE))
     697                 :          0 :                 return IXGBE_ERR_MBX;
     698                 :            : 
     699                 :            :         return 0;
     700                 :            : }
     701                 :            : 
     702                 :            : /**
     703                 :            :  * ixgbevf_negotiate_api_version - Negotiate supported API version
     704                 :            :  * @hw: pointer to the HW structure
     705                 :            :  * @api: integer containing requested API version
     706                 :            :  **/
     707                 :          0 : int ixgbevf_negotiate_api_version(struct ixgbe_hw *hw, int api)
     708                 :            : {
     709                 :            :         int err;
     710                 :            :         u32 msg[3];
     711                 :            : 
     712                 :            :         /* Negotiate the mailbox API version */
     713                 :          0 :         msg[0] = IXGBE_VF_API_NEGOTIATE;
     714                 :          0 :         msg[1] = api;
     715                 :          0 :         msg[2] = 0;
     716                 :            : 
     717                 :          0 :         err = ixgbevf_write_msg_read_ack(hw, msg, msg, 3);
     718         [ #  # ]:          0 :         if (!err) {
     719                 :          0 :                 msg[0] &= ~IXGBE_VT_MSGTYPE_CTS;
     720                 :            : 
     721                 :            :                 /* Store value and return 0 on success */
     722         [ #  # ]:          0 :                 if (msg[0] == (IXGBE_VF_API_NEGOTIATE | IXGBE_VT_MSGTYPE_SUCCESS)) {
     723                 :          0 :                         hw->api_version = api;
     724                 :          0 :                         return 0;
     725                 :            :                 }
     726                 :            : 
     727                 :            :                 err = IXGBE_ERR_INVALID_ARGUMENT;
     728                 :            :         }
     729                 :            : 
     730                 :            :         return err;
     731                 :            : }
     732                 :            : 
     733                 :          0 : int ixgbevf_get_queues(struct ixgbe_hw *hw, unsigned int *num_tcs,
     734                 :            :                        unsigned int *default_tc)
     735                 :            : {
     736                 :            :         int err;
     737                 :            :         u32 msg[5];
     738                 :            : 
     739                 :            :         /* do nothing if API doesn't support ixgbevf_get_queues */
     740         [ #  # ]:          0 :         switch (hw->api_version) {
     741                 :            :         case ixgbe_mbox_api_11:
     742                 :            :         case ixgbe_mbox_api_12:
     743                 :            :         case ixgbe_mbox_api_13:
     744                 :            :         case ixgbe_mbox_api_15:
     745                 :            :                 break;
     746                 :            :         default:
     747                 :            :                 return 0;
     748                 :            :         }
     749                 :            : 
     750                 :            :         /* Fetch queue configuration from the PF */
     751                 :          0 :         msg[0] = IXGBE_VF_GET_QUEUES;
     752                 :          0 :         msg[1] = msg[2] = msg[3] = msg[4] = 0;
     753                 :            : 
     754                 :          0 :         err = ixgbevf_write_msg_read_ack(hw, msg, msg, 5);
     755         [ #  # ]:          0 :         if (!err) {
     756                 :          0 :                 msg[0] &= ~IXGBE_VT_MSGTYPE_CTS;
     757                 :            : 
     758                 :            :                 /*
     759                 :            :                  * if we didn't get a SUCCESS there must have been
     760                 :            :                  * some sort of mailbox error so we should treat it
     761                 :            :                  * as such
     762                 :            :                  */
     763         [ #  # ]:          0 :                 if (msg[0] != (IXGBE_VF_GET_QUEUES | IXGBE_VT_MSGTYPE_SUCCESS))
     764                 :            :                         return IXGBE_ERR_MBX;
     765                 :            : 
     766                 :            :                 /* record and validate values from message */
     767                 :          0 :                 hw->mac.max_tx_queues = msg[IXGBE_VF_TX_QUEUES];
     768         [ #  # ]:          0 :                 if (hw->mac.max_tx_queues == 0 ||
     769                 :            :                     hw->mac.max_tx_queues > IXGBE_VF_MAX_TX_QUEUES)
     770                 :          0 :                         hw->mac.max_tx_queues = IXGBE_VF_MAX_TX_QUEUES;
     771                 :            : 
     772                 :          0 :                 hw->mac.max_rx_queues = msg[IXGBE_VF_RX_QUEUES];
     773         [ #  # ]:          0 :                 if (hw->mac.max_rx_queues == 0 ||
     774                 :            :                     hw->mac.max_rx_queues > IXGBE_VF_MAX_RX_QUEUES)
     775                 :          0 :                         hw->mac.max_rx_queues = IXGBE_VF_MAX_RX_QUEUES;
     776                 :            : 
     777                 :          0 :                 *num_tcs = msg[IXGBE_VF_TRANS_VLAN];
     778                 :            :                 /* in case of unknown state assume we cannot tag frames */
     779         [ #  # ]:          0 :                 if (*num_tcs > hw->mac.max_rx_queues)
     780                 :          0 :                         *num_tcs = 1;
     781                 :            : 
     782                 :          0 :                 *default_tc = msg[IXGBE_VF_DEF_QUEUE];
     783                 :            :                 /* default to queue 0 on out-of-bounds queue number */
     784         [ #  # ]:          0 :                 if (*default_tc >= hw->mac.max_tx_queues)
     785                 :          0 :                         *default_tc = 0;
     786                 :            :         }
     787                 :            : 
     788                 :            :         return err;
     789                 :            : }

Generated by: LCOV version 1.14