LCOV - code coverage report
Current view: top level - drivers/net/i40e/base - i40e_common.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 2431 0.0 %
Date: 2024-12-01 18:57:19 Functions: 0 187 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 1310 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                 :            : #include <inttypes.h>
       6                 :            : 
       7                 :            : #include "i40e_type.h"
       8                 :            : #include "i40e_adminq.h"
       9                 :            : #include "i40e_prototype.h"
      10                 :            : #include "virtchnl.h"
      11                 :            : 
      12                 :            : /**
      13                 :            :  * i40e_set_mac_type - Sets MAC type
      14                 :            :  * @hw: pointer to the HW structure
      15                 :            :  *
      16                 :            :  * This function sets the mac type of the adapter based on the
      17                 :            :  * vendor ID and device ID stored in the hw structure.
      18                 :            :  **/
      19                 :          0 : enum i40e_status_code i40e_set_mac_type(struct i40e_hw *hw)
      20                 :            : {
      21                 :            :         enum i40e_status_code status = I40E_SUCCESS;
      22                 :            : 
      23                 :          0 :         DEBUGFUNC("i40e_set_mac_type\n");
      24                 :            : 
      25         [ #  # ]:          0 :         if (hw->vendor_id == I40E_INTEL_VENDOR_ID) {
      26      [ #  #  # ]:          0 :                 switch (hw->device_id) {
      27                 :          0 :                 case I40E_DEV_ID_SFP_XL710:
      28                 :            :                 case I40E_DEV_ID_QEMU:
      29                 :            :                 case I40E_DEV_ID_KX_B:
      30                 :            :                 case I40E_DEV_ID_KX_C:
      31                 :            :                 case I40E_DEV_ID_QSFP_A:
      32                 :            :                 case I40E_DEV_ID_QSFP_B:
      33                 :            :                 case I40E_DEV_ID_QSFP_C:
      34                 :            :                 case I40E_DEV_ID_10G_BASE_T:
      35                 :            :                 case I40E_DEV_ID_10G_BASE_T4:
      36                 :            :                 case I40E_DEV_ID_10G_BASE_T_BC:
      37                 :            :                 case I40E_DEV_ID_10G_B:
      38                 :            :                 case I40E_DEV_ID_10G_SFP:
      39                 :            :                 case I40E_DEV_ID_5G_BASE_T_BC:
      40                 :            :                 case I40E_DEV_ID_1G_BASE_T_BC:
      41                 :            :                 case I40E_DEV_ID_20G_KR2:
      42                 :            :                 case I40E_DEV_ID_20G_KR2_A:
      43                 :            :                 case I40E_DEV_ID_25G_B:
      44                 :            :                 case I40E_DEV_ID_25G_SFP28:
      45                 :            :                 case I40E_DEV_ID_X710_N3000:
      46                 :            :                 case I40E_DEV_ID_XXV710_N3000:
      47                 :          0 :                         hw->mac.type = I40E_MAC_XL710;
      48                 :          0 :                         break;
      49                 :          0 :                 case I40E_DEV_ID_KX_X722:
      50                 :            :                 case I40E_DEV_ID_QSFP_X722:
      51                 :            :                 case I40E_DEV_ID_SFP_X722:
      52                 :            :                 case I40E_DEV_ID_1G_BASE_T_X722:
      53                 :            :                 case I40E_DEV_ID_10G_BASE_T_X722:
      54                 :            :                 case I40E_DEV_ID_SFP_I_X722:
      55                 :            :                 case I40E_DEV_ID_SFP_X722_A:
      56                 :          0 :                         hw->mac.type = I40E_MAC_X722;
      57                 :          0 :                         break;
      58                 :          0 :                 default:
      59                 :          0 :                         hw->mac.type = I40E_MAC_GENERIC;
      60                 :          0 :                         break;
      61                 :            :                 }
      62                 :            :         } else {
      63                 :            :                 status = I40E_ERR_DEVICE_NOT_SUPPORTED;
      64                 :            :         }
      65                 :            : 
      66                 :          0 :         DEBUGOUT2("i40e_set_mac_type found mac: %d, returns: %d\n",
      67                 :            :                   hw->mac.type, status);
      68                 :          0 :         return status;
      69                 :            : }
      70                 :            : 
      71                 :            : /**
      72                 :            :  * i40e_aq_str - convert AQ err code to a string
      73                 :            :  * @hw: pointer to the HW structure
      74                 :            :  * @aq_err: the AQ error code to convert
      75                 :            :  **/
      76                 :          0 : const char *i40e_aq_str(struct i40e_hw *hw, enum i40e_admin_queue_err aq_err)
      77                 :            : {
      78   [ #  #  #  #  :          0 :         switch (aq_err) {
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
      79                 :            :         case I40E_AQ_RC_OK:
      80                 :            :                 return "OK";
      81                 :          0 :         case I40E_AQ_RC_EPERM:
      82                 :          0 :                 return "I40E_AQ_RC_EPERM";
      83                 :          0 :         case I40E_AQ_RC_ENOENT:
      84                 :          0 :                 return "I40E_AQ_RC_ENOENT";
      85                 :          0 :         case I40E_AQ_RC_ESRCH:
      86                 :          0 :                 return "I40E_AQ_RC_ESRCH";
      87                 :          0 :         case I40E_AQ_RC_EINTR:
      88                 :          0 :                 return "I40E_AQ_RC_EINTR";
      89                 :          0 :         case I40E_AQ_RC_EIO:
      90                 :          0 :                 return "I40E_AQ_RC_EIO";
      91                 :          0 :         case I40E_AQ_RC_ENXIO:
      92                 :          0 :                 return "I40E_AQ_RC_ENXIO";
      93                 :          0 :         case I40E_AQ_RC_E2BIG:
      94                 :          0 :                 return "I40E_AQ_RC_E2BIG";
      95                 :          0 :         case I40E_AQ_RC_EAGAIN:
      96                 :          0 :                 return "I40E_AQ_RC_EAGAIN";
      97                 :          0 :         case I40E_AQ_RC_ENOMEM:
      98                 :          0 :                 return "I40E_AQ_RC_ENOMEM";
      99                 :          0 :         case I40E_AQ_RC_EACCES:
     100                 :          0 :                 return "I40E_AQ_RC_EACCES";
     101                 :          0 :         case I40E_AQ_RC_EFAULT:
     102                 :          0 :                 return "I40E_AQ_RC_EFAULT";
     103                 :          0 :         case I40E_AQ_RC_EBUSY:
     104                 :          0 :                 return "I40E_AQ_RC_EBUSY";
     105                 :          0 :         case I40E_AQ_RC_EEXIST:
     106                 :          0 :                 return "I40E_AQ_RC_EEXIST";
     107                 :          0 :         case I40E_AQ_RC_EINVAL:
     108                 :          0 :                 return "I40E_AQ_RC_EINVAL";
     109                 :          0 :         case I40E_AQ_RC_ENOTTY:
     110                 :          0 :                 return "I40E_AQ_RC_ENOTTY";
     111                 :          0 :         case I40E_AQ_RC_ENOSPC:
     112                 :          0 :                 return "I40E_AQ_RC_ENOSPC";
     113                 :          0 :         case I40E_AQ_RC_ENOSYS:
     114                 :          0 :                 return "I40E_AQ_RC_ENOSYS";
     115                 :          0 :         case I40E_AQ_RC_ERANGE:
     116                 :          0 :                 return "I40E_AQ_RC_ERANGE";
     117                 :          0 :         case I40E_AQ_RC_EFLUSHED:
     118                 :          0 :                 return "I40E_AQ_RC_EFLUSHED";
     119                 :          0 :         case I40E_AQ_RC_BAD_ADDR:
     120                 :          0 :                 return "I40E_AQ_RC_BAD_ADDR";
     121                 :          0 :         case I40E_AQ_RC_EMODE:
     122                 :          0 :                 return "I40E_AQ_RC_EMODE";
     123                 :          0 :         case I40E_AQ_RC_EFBIG:
     124                 :          0 :                 return "I40E_AQ_RC_EFBIG";
     125                 :            :         }
     126                 :            : 
     127                 :          0 :         snprintf(hw->err_str, sizeof(hw->err_str), "%d", aq_err);
     128                 :          0 :         return hw->err_str;
     129                 :            : }
     130                 :            : 
     131                 :            : /**
     132                 :            :  * i40e_stat_str - convert status err code to a string
     133                 :            :  * @hw: pointer to the HW structure
     134                 :            :  * @stat_err: the status error code to convert
     135                 :            :  **/
     136                 :          0 : const char *i40e_stat_str(struct i40e_hw *hw, enum i40e_status_code stat_err)
     137                 :            : {
     138   [ #  #  #  #  :          0 :         switch (stat_err) {
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
     139                 :            :         case I40E_SUCCESS:
     140                 :            :                 return "OK";
     141                 :          0 :         case I40E_ERR_NVM:
     142                 :          0 :                 return "I40E_ERR_NVM";
     143                 :          0 :         case I40E_ERR_NVM_CHECKSUM:
     144                 :          0 :                 return "I40E_ERR_NVM_CHECKSUM";
     145                 :          0 :         case I40E_ERR_PHY:
     146                 :          0 :                 return "I40E_ERR_PHY";
     147                 :          0 :         case I40E_ERR_CONFIG:
     148                 :          0 :                 return "I40E_ERR_CONFIG";
     149                 :          0 :         case I40E_ERR_PARAM:
     150                 :          0 :                 return "I40E_ERR_PARAM";
     151                 :          0 :         case I40E_ERR_MAC_TYPE:
     152                 :          0 :                 return "I40E_ERR_MAC_TYPE";
     153                 :          0 :         case I40E_ERR_UNKNOWN_PHY:
     154                 :          0 :                 return "I40E_ERR_UNKNOWN_PHY";
     155                 :          0 :         case I40E_ERR_LINK_SETUP:
     156                 :          0 :                 return "I40E_ERR_LINK_SETUP";
     157                 :          0 :         case I40E_ERR_ADAPTER_STOPPED:
     158                 :          0 :                 return "I40E_ERR_ADAPTER_STOPPED";
     159                 :          0 :         case I40E_ERR_INVALID_MAC_ADDR:
     160                 :          0 :                 return "I40E_ERR_INVALID_MAC_ADDR";
     161                 :          0 :         case I40E_ERR_DEVICE_NOT_SUPPORTED:
     162                 :          0 :                 return "I40E_ERR_DEVICE_NOT_SUPPORTED";
     163                 :          0 :         case I40E_ERR_PRIMARY_REQUESTS_PENDING:
     164                 :          0 :                 return "I40E_ERR_PRIMARY_REQUESTS_PENDING";
     165                 :          0 :         case I40E_ERR_INVALID_LINK_SETTINGS:
     166                 :          0 :                 return "I40E_ERR_INVALID_LINK_SETTINGS";
     167                 :          0 :         case I40E_ERR_AUTONEG_NOT_COMPLETE:
     168                 :          0 :                 return "I40E_ERR_AUTONEG_NOT_COMPLETE";
     169                 :          0 :         case I40E_ERR_RESET_FAILED:
     170                 :          0 :                 return "I40E_ERR_RESET_FAILED";
     171                 :          0 :         case I40E_ERR_SWFW_SYNC:
     172                 :          0 :                 return "I40E_ERR_SWFW_SYNC";
     173                 :          0 :         case I40E_ERR_NO_AVAILABLE_VSI:
     174                 :          0 :                 return "I40E_ERR_NO_AVAILABLE_VSI";
     175                 :          0 :         case I40E_ERR_NO_MEMORY:
     176                 :          0 :                 return "I40E_ERR_NO_MEMORY";
     177                 :          0 :         case I40E_ERR_BAD_PTR:
     178                 :          0 :                 return "I40E_ERR_BAD_PTR";
     179                 :          0 :         case I40E_ERR_RING_FULL:
     180                 :          0 :                 return "I40E_ERR_RING_FULL";
     181                 :          0 :         case I40E_ERR_INVALID_PD_ID:
     182                 :          0 :                 return "I40E_ERR_INVALID_PD_ID";
     183                 :          0 :         case I40E_ERR_INVALID_QP_ID:
     184                 :          0 :                 return "I40E_ERR_INVALID_QP_ID";
     185                 :          0 :         case I40E_ERR_INVALID_CQ_ID:
     186                 :          0 :                 return "I40E_ERR_INVALID_CQ_ID";
     187                 :          0 :         case I40E_ERR_INVALID_CEQ_ID:
     188                 :          0 :                 return "I40E_ERR_INVALID_CEQ_ID";
     189                 :          0 :         case I40E_ERR_INVALID_AEQ_ID:
     190                 :          0 :                 return "I40E_ERR_INVALID_AEQ_ID";
     191                 :          0 :         case I40E_ERR_INVALID_SIZE:
     192                 :          0 :                 return "I40E_ERR_INVALID_SIZE";
     193                 :          0 :         case I40E_ERR_INVALID_ARP_INDEX:
     194                 :          0 :                 return "I40E_ERR_INVALID_ARP_INDEX";
     195                 :          0 :         case I40E_ERR_INVALID_FPM_FUNC_ID:
     196                 :          0 :                 return "I40E_ERR_INVALID_FPM_FUNC_ID";
     197                 :          0 :         case I40E_ERR_QP_INVALID_MSG_SIZE:
     198                 :          0 :                 return "I40E_ERR_QP_INVALID_MSG_SIZE";
     199                 :          0 :         case I40E_ERR_QP_TOOMANY_WRS_POSTED:
     200                 :          0 :                 return "I40E_ERR_QP_TOOMANY_WRS_POSTED";
     201                 :          0 :         case I40E_ERR_INVALID_FRAG_COUNT:
     202                 :          0 :                 return "I40E_ERR_INVALID_FRAG_COUNT";
     203                 :          0 :         case I40E_ERR_QUEUE_EMPTY:
     204                 :          0 :                 return "I40E_ERR_QUEUE_EMPTY";
     205                 :          0 :         case I40E_ERR_INVALID_ALIGNMENT:
     206                 :          0 :                 return "I40E_ERR_INVALID_ALIGNMENT";
     207                 :          0 :         case I40E_ERR_FLUSHED_QUEUE:
     208                 :          0 :                 return "I40E_ERR_FLUSHED_QUEUE";
     209                 :          0 :         case I40E_ERR_INVALID_PUSH_PAGE_INDEX:
     210                 :          0 :                 return "I40E_ERR_INVALID_PUSH_PAGE_INDEX";
     211                 :          0 :         case I40E_ERR_INVALID_IMM_DATA_SIZE:
     212                 :          0 :                 return "I40E_ERR_INVALID_IMM_DATA_SIZE";
     213                 :          0 :         case I40E_ERR_TIMEOUT:
     214                 :          0 :                 return "I40E_ERR_TIMEOUT";
     215                 :          0 :         case I40E_ERR_OPCODE_MISMATCH:
     216                 :          0 :                 return "I40E_ERR_OPCODE_MISMATCH";
     217                 :          0 :         case I40E_ERR_CQP_COMPL_ERROR:
     218                 :          0 :                 return "I40E_ERR_CQP_COMPL_ERROR";
     219                 :          0 :         case I40E_ERR_INVALID_VF_ID:
     220                 :          0 :                 return "I40E_ERR_INVALID_VF_ID";
     221                 :          0 :         case I40E_ERR_INVALID_HMCFN_ID:
     222                 :          0 :                 return "I40E_ERR_INVALID_HMCFN_ID";
     223                 :          0 :         case I40E_ERR_BACKING_PAGE_ERROR:
     224                 :          0 :                 return "I40E_ERR_BACKING_PAGE_ERROR";
     225                 :          0 :         case I40E_ERR_NO_PBLCHUNKS_AVAILABLE:
     226                 :          0 :                 return "I40E_ERR_NO_PBLCHUNKS_AVAILABLE";
     227                 :          0 :         case I40E_ERR_INVALID_PBLE_INDEX:
     228                 :          0 :                 return "I40E_ERR_INVALID_PBLE_INDEX";
     229                 :          0 :         case I40E_ERR_INVALID_SD_INDEX:
     230                 :          0 :                 return "I40E_ERR_INVALID_SD_INDEX";
     231                 :          0 :         case I40E_ERR_INVALID_PAGE_DESC_INDEX:
     232                 :          0 :                 return "I40E_ERR_INVALID_PAGE_DESC_INDEX";
     233                 :          0 :         case I40E_ERR_INVALID_SD_TYPE:
     234                 :          0 :                 return "I40E_ERR_INVALID_SD_TYPE";
     235                 :          0 :         case I40E_ERR_MEMCPY_FAILED:
     236                 :          0 :                 return "I40E_ERR_MEMCPY_FAILED";
     237                 :          0 :         case I40E_ERR_INVALID_HMC_OBJ_INDEX:
     238                 :          0 :                 return "I40E_ERR_INVALID_HMC_OBJ_INDEX";
     239                 :          0 :         case I40E_ERR_INVALID_HMC_OBJ_COUNT:
     240                 :          0 :                 return "I40E_ERR_INVALID_HMC_OBJ_COUNT";
     241                 :          0 :         case I40E_ERR_INVALID_SRQ_ARM_LIMIT:
     242                 :          0 :                 return "I40E_ERR_INVALID_SRQ_ARM_LIMIT";
     243                 :          0 :         case I40E_ERR_SRQ_ENABLED:
     244                 :          0 :                 return "I40E_ERR_SRQ_ENABLED";
     245                 :          0 :         case I40E_ERR_ADMIN_QUEUE_ERROR:
     246                 :          0 :                 return "I40E_ERR_ADMIN_QUEUE_ERROR";
     247                 :          0 :         case I40E_ERR_ADMIN_QUEUE_TIMEOUT:
     248                 :          0 :                 return "I40E_ERR_ADMIN_QUEUE_TIMEOUT";
     249                 :          0 :         case I40E_ERR_BUF_TOO_SHORT:
     250                 :          0 :                 return "I40E_ERR_BUF_TOO_SHORT";
     251                 :          0 :         case I40E_ERR_ADMIN_QUEUE_FULL:
     252                 :          0 :                 return "I40E_ERR_ADMIN_QUEUE_FULL";
     253                 :          0 :         case I40E_ERR_ADMIN_QUEUE_NO_WORK:
     254                 :          0 :                 return "I40E_ERR_ADMIN_QUEUE_NO_WORK";
     255                 :          0 :         case I40E_ERR_BAD_IWARP_CQE:
     256                 :          0 :                 return "I40E_ERR_BAD_IWARP_CQE";
     257                 :          0 :         case I40E_ERR_NVM_BLANK_MODE:
     258                 :          0 :                 return "I40E_ERR_NVM_BLANK_MODE";
     259                 :          0 :         case I40E_ERR_NOT_IMPLEMENTED:
     260                 :          0 :                 return "I40E_ERR_NOT_IMPLEMENTED";
     261                 :          0 :         case I40E_ERR_PE_DOORBELL_NOT_ENABLED:
     262                 :          0 :                 return "I40E_ERR_PE_DOORBELL_NOT_ENABLED";
     263                 :          0 :         case I40E_ERR_DIAG_TEST_FAILED:
     264                 :          0 :                 return "I40E_ERR_DIAG_TEST_FAILED";
     265                 :          0 :         case I40E_ERR_NOT_READY:
     266                 :          0 :                 return "I40E_ERR_NOT_READY";
     267                 :          0 :         case I40E_NOT_SUPPORTED:
     268                 :          0 :                 return "I40E_NOT_SUPPORTED";
     269                 :          0 :         case I40E_ERR_FIRMWARE_API_VERSION:
     270                 :          0 :                 return "I40E_ERR_FIRMWARE_API_VERSION";
     271                 :          0 :         case I40E_ERR_ADMIN_QUEUE_CRITICAL_ERROR:
     272                 :          0 :                 return "I40E_ERR_ADMIN_QUEUE_CRITICAL_ERROR";
     273                 :            :         }
     274                 :            : 
     275                 :          0 :         snprintf(hw->err_str, sizeof(hw->err_str), "%d", stat_err);
     276                 :          0 :         return hw->err_str;
     277                 :            : }
     278                 :            : 
     279                 :            : /**
     280                 :            :  * i40e_debug_aq
     281                 :            :  * @hw: debug mask related to admin queue
     282                 :            :  * @mask: debug mask
     283                 :            :  * @desc: pointer to admin queue descriptor
     284                 :            :  * @buffer: pointer to command buffer
     285                 :            :  * @buf_len: max length of buffer
     286                 :            :  *
     287                 :            :  * Dumps debug log about adminq command with descriptor contents.
     288                 :            :  **/
     289                 :          0 : void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
     290                 :            :                    void *buffer, u16 buf_len)
     291                 :            : {
     292                 :            :         struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
     293                 :          0 :         u32 effective_mask = hw->debug_mask & mask;
     294                 :            :         u8 *buf = (u8 *)buffer;
     295                 :            :         u16 len;
     296                 :            :         u16 i;
     297                 :            : 
     298         [ #  # ]:          0 :         if (!effective_mask || !desc)
     299                 :            :                 return;
     300                 :            : 
     301                 :          0 :         len = LE16_TO_CPU(aq_desc->datalen);
     302                 :            : 
     303         [ #  # ]:          0 :         i40e_debug(hw, mask & I40E_DEBUG_AQ_DESCRIPTOR,
     304                 :            :                    "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
     305                 :            :                    LE16_TO_CPU(aq_desc->opcode),
     306                 :            :                    LE16_TO_CPU(aq_desc->flags),
     307                 :            :                    LE16_TO_CPU(aq_desc->datalen),
     308                 :            :                    LE16_TO_CPU(aq_desc->retval));
     309         [ #  # ]:          0 :         i40e_debug(hw, mask & I40E_DEBUG_AQ_DESCRIPTOR,
     310                 :            :                    "\tcookie (h,l) 0x%08X 0x%08X\n",
     311                 :            :                    LE32_TO_CPU(aq_desc->cookie_high),
     312                 :            :                    LE32_TO_CPU(aq_desc->cookie_low));
     313         [ #  # ]:          0 :         i40e_debug(hw, mask & I40E_DEBUG_AQ_DESCRIPTOR,
     314                 :            :                    "\tparam (0,1)  0x%08X 0x%08X\n",
     315                 :            :                    LE32_TO_CPU(aq_desc->params.internal.param0),
     316                 :            :                    LE32_TO_CPU(aq_desc->params.internal.param1));
     317         [ #  # ]:          0 :         i40e_debug(hw, mask & I40E_DEBUG_AQ_DESCRIPTOR,
     318                 :            :                    "\taddr (h,l)   0x%08X 0x%08X\n",
     319                 :            :                    LE32_TO_CPU(aq_desc->params.external.addr_high),
     320                 :            :                    LE32_TO_CPU(aq_desc->params.external.addr_low));
     321                 :            : 
     322   [ #  #  #  # ]:          0 :         if (buffer && (buf_len != 0) && (len != 0) &&
     323         [ #  # ]:          0 :             (effective_mask & I40E_DEBUG_AQ_DESC_BUFFER)) {
     324         [ #  # ]:          0 :                 i40e_debug(hw, mask, "AQ CMD Buffer:\n");
     325                 :            :                 if (buf_len < len)
     326                 :            :                         len = buf_len;
     327                 :            :                 /* write the full 16-byte chunks */
     328         [ #  # ]:          0 :                 for (i = 0; i < (len - 16); i += 16)
     329         [ #  # ]:          0 :                         i40e_debug(hw, mask,
     330                 :            :                                    "\t0x%04X  %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
     331                 :            :                                    i, buf[i], buf[i+1], buf[i+2], buf[i+3],
     332                 :            :                                    buf[i+4], buf[i+5], buf[i+6], buf[i+7],
     333                 :            :                                    buf[i+8], buf[i+9], buf[i+10], buf[i+11],
     334                 :            :                                    buf[i+12], buf[i+13], buf[i+14], buf[i+15]);
     335                 :            :                 /* the most we could have left is 16 bytes, pad with zeros */
     336         [ #  # ]:          0 :                 if (i < len) {
     337                 :            :                         char d_buf[16];
     338                 :            :                         int j, i_sav;
     339                 :            : 
     340                 :            :                         i_sav = i;
     341                 :            :                         memset(d_buf, 0, sizeof(d_buf));
     342         [ #  # ]:          0 :                         for (j = 0; i < len; j++, i++)
     343                 :          0 :                                 d_buf[j] = buf[i];
     344         [ #  # ]:          0 :                         i40e_debug(hw, mask,
     345                 :            :                                    "\t0x%04X  %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
     346                 :            :                                    i_sav, d_buf[0], d_buf[1], d_buf[2], d_buf[3],
     347                 :            :                                    d_buf[4], d_buf[5], d_buf[6], d_buf[7],
     348                 :            :                                    d_buf[8], d_buf[9], d_buf[10], d_buf[11],
     349                 :            :                                    d_buf[12], d_buf[13], d_buf[14], d_buf[15]);
     350                 :            :                 }
     351                 :            :         }
     352                 :            : }
     353                 :            : 
     354                 :            : /**
     355                 :            :  * i40e_check_asq_alive
     356                 :            :  * @hw: pointer to the hw struct
     357                 :            :  *
     358                 :            :  * Returns true if Queue is enabled else false.
     359                 :            :  **/
     360                 :          0 : bool i40e_check_asq_alive(struct i40e_hw *hw)
     361                 :            : {
     362         [ #  # ]:          0 :         if (hw->aq.asq.len)
     363                 :          0 :                 return !!(rd32(hw, hw->aq.asq.len) &
     364                 :            :                         I40E_PF_ATQLEN_ATQENABLE_MASK);
     365                 :            :         return false;
     366                 :            : }
     367                 :            : 
     368                 :            : /**
     369                 :            :  * i40e_aq_queue_shutdown
     370                 :            :  * @hw: pointer to the hw struct
     371                 :            :  * @unloading: is the driver unloading itself
     372                 :            :  *
     373                 :            :  * Tell the Firmware that we're shutting down the AdminQ and whether
     374                 :            :  * or not the driver is unloading as well.
     375                 :            :  **/
     376                 :          0 : enum i40e_status_code i40e_aq_queue_shutdown(struct i40e_hw *hw,
     377                 :            :                                              bool unloading)
     378                 :            : {
     379                 :            :         struct i40e_aq_desc desc;
     380                 :            :         struct i40e_aqc_queue_shutdown *cmd =
     381                 :            :                 (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
     382                 :            :         enum i40e_status_code status;
     383                 :            : 
     384                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
     385                 :            :                                           i40e_aqc_opc_queue_shutdown);
     386                 :            : 
     387         [ #  # ]:          0 :         if (unloading)
     388                 :          0 :                 cmd->driver_unloading = CPU_TO_LE32(I40E_AQ_DRIVER_UNLOADING);
     389                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
     390                 :            : 
     391                 :          0 :         return status;
     392                 :            : }
     393                 :            : 
     394                 :            : /**
     395                 :            :  * i40e_aq_get_set_rss_lut
     396                 :            :  * @hw: pointer to the hardware structure
     397                 :            :  * @vsi_id: vsi fw index
     398                 :            :  * @pf_lut: for PF table set true, for VSI table set false
     399                 :            :  * @lut: pointer to the lut buffer provided by the caller
     400                 :            :  * @lut_size: size of the lut buffer
     401                 :            :  * @set: set true to set the table, false to get the table
     402                 :            :  *
     403                 :            :  * Internal function to get or set RSS look up table
     404                 :            :  **/
     405                 :          0 : STATIC enum i40e_status_code i40e_aq_get_set_rss_lut(struct i40e_hw *hw,
     406                 :            :                                                      u16 vsi_id, bool pf_lut,
     407                 :            :                                                      u8 *lut, u16 lut_size,
     408                 :            :                                                      bool set)
     409                 :            : {
     410                 :            :         enum i40e_status_code status;
     411                 :            :         struct i40e_aq_desc desc;
     412                 :            :         struct i40e_aqc_get_set_rss_lut *cmd_resp =
     413                 :            :                    (struct i40e_aqc_get_set_rss_lut *)&desc.params.raw;
     414                 :            : 
     415         [ #  # ]:          0 :         if (set)
     416                 :          0 :                 i40e_fill_default_direct_cmd_desc(&desc,
     417                 :            :                                                   i40e_aqc_opc_set_rss_lut);
     418                 :            :         else
     419                 :          0 :                 i40e_fill_default_direct_cmd_desc(&desc,
     420                 :            :                                                   i40e_aqc_opc_get_rss_lut);
     421                 :            : 
     422                 :            :         /* Indirect command */
     423                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
     424                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
     425                 :            : 
     426                 :            :         cmd_resp->vsi_id =
     427                 :          0 :                         CPU_TO_LE16((u16)((vsi_id <<
     428                 :            :                                           I40E_AQC_SET_RSS_LUT_VSI_ID_SHIFT) &
     429                 :            :                                           I40E_AQC_SET_RSS_LUT_VSI_ID_MASK));
     430                 :          0 :         cmd_resp->vsi_id |= CPU_TO_LE16((u16)I40E_AQC_SET_RSS_LUT_VSI_VALID);
     431                 :            : 
     432         [ #  # ]:          0 :         if (pf_lut)
     433                 :          0 :                 cmd_resp->flags |= CPU_TO_LE16((u16)
     434                 :            :                                         ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_PF <<
     435                 :            :                                         I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
     436                 :            :                                         I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
     437                 :            :         else
     438                 :            :                 cmd_resp->flags |= CPU_TO_LE16((u16)
     439                 :            :                                         ((I40E_AQC_SET_RSS_LUT_TABLE_TYPE_VSI <<
     440                 :            :                                         I40E_AQC_SET_RSS_LUT_TABLE_TYPE_SHIFT) &
     441                 :            :                                         I40E_AQC_SET_RSS_LUT_TABLE_TYPE_MASK));
     442                 :            : 
     443                 :          0 :         status = i40e_asq_send_command(hw, &desc, lut, lut_size, NULL);
     444                 :            : 
     445                 :          0 :         return status;
     446                 :            : }
     447                 :            : 
     448                 :            : /**
     449                 :            :  * i40e_aq_get_rss_lut
     450                 :            :  * @hw: pointer to the hardware structure
     451                 :            :  * @vsi_id: vsi fw index
     452                 :            :  * @pf_lut: for PF table set true, for VSI table set false
     453                 :            :  * @lut: pointer to the lut buffer provided by the caller
     454                 :            :  * @lut_size: size of the lut buffer
     455                 :            :  *
     456                 :            :  * get the RSS lookup table, PF or VSI type
     457                 :            :  **/
     458                 :          0 : enum i40e_status_code i40e_aq_get_rss_lut(struct i40e_hw *hw, u16 vsi_id,
     459                 :            :                                           bool pf_lut, u8 *lut, u16 lut_size)
     460                 :            : {
     461                 :          0 :         return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size,
     462                 :            :                                        false);
     463                 :            : }
     464                 :            : 
     465                 :            : /**
     466                 :            :  * i40e_aq_set_rss_lut
     467                 :            :  * @hw: pointer to the hardware structure
     468                 :            :  * @vsi_id: vsi fw index
     469                 :            :  * @pf_lut: for PF table set true, for VSI table set false
     470                 :            :  * @lut: pointer to the lut buffer provided by the caller
     471                 :            :  * @lut_size: size of the lut buffer
     472                 :            :  *
     473                 :            :  * set the RSS lookup table, PF or VSI type
     474                 :            :  **/
     475                 :          0 : enum i40e_status_code i40e_aq_set_rss_lut(struct i40e_hw *hw, u16 vsi_id,
     476                 :            :                                           bool pf_lut, u8 *lut, u16 lut_size)
     477                 :            : {
     478                 :          0 :         return i40e_aq_get_set_rss_lut(hw, vsi_id, pf_lut, lut, lut_size, true);
     479                 :            : }
     480                 :            : 
     481                 :            : /**
     482                 :            :  * i40e_aq_get_set_rss_key
     483                 :            :  * @hw: pointer to the hw struct
     484                 :            :  * @vsi_id: vsi fw index
     485                 :            :  * @key: pointer to key info struct
     486                 :            :  * @set: set true to set the key, false to get the key
     487                 :            :  *
     488                 :            :  * get the RSS key per VSI
     489                 :            :  **/
     490                 :          0 : STATIC enum i40e_status_code i40e_aq_get_set_rss_key(struct i40e_hw *hw,
     491                 :            :                                       u16 vsi_id,
     492                 :            :                                       struct i40e_aqc_get_set_rss_key_data *key,
     493                 :            :                                       bool set)
     494                 :            : {
     495                 :            :         enum i40e_status_code status;
     496                 :            :         struct i40e_aq_desc desc;
     497                 :            :         struct i40e_aqc_get_set_rss_key *cmd_resp =
     498                 :            :                         (struct i40e_aqc_get_set_rss_key *)&desc.params.raw;
     499                 :            :         u16 key_size = sizeof(struct i40e_aqc_get_set_rss_key_data);
     500                 :            : 
     501         [ #  # ]:          0 :         if (set)
     502                 :          0 :                 i40e_fill_default_direct_cmd_desc(&desc,
     503                 :            :                                                   i40e_aqc_opc_set_rss_key);
     504                 :            :         else
     505                 :          0 :                 i40e_fill_default_direct_cmd_desc(&desc,
     506                 :            :                                                   i40e_aqc_opc_get_rss_key);
     507                 :            : 
     508                 :            :         /* Indirect command */
     509                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
     510                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
     511                 :            : 
     512                 :            :         cmd_resp->vsi_id =
     513                 :          0 :                         CPU_TO_LE16((u16)((vsi_id <<
     514                 :            :                                           I40E_AQC_SET_RSS_KEY_VSI_ID_SHIFT) &
     515                 :            :                                           I40E_AQC_SET_RSS_KEY_VSI_ID_MASK));
     516                 :          0 :         cmd_resp->vsi_id |= CPU_TO_LE16((u16)I40E_AQC_SET_RSS_KEY_VSI_VALID);
     517                 :            : 
     518                 :          0 :         status = i40e_asq_send_command(hw, &desc, key, key_size, NULL);
     519                 :            : 
     520                 :          0 :         return status;
     521                 :            : }
     522                 :            : 
     523                 :            : /**
     524                 :            :  * i40e_aq_get_rss_key
     525                 :            :  * @hw: pointer to the hw struct
     526                 :            :  * @vsi_id: vsi fw index
     527                 :            :  * @key: pointer to key info struct
     528                 :            :  *
     529                 :            :  **/
     530                 :          0 : enum i40e_status_code i40e_aq_get_rss_key(struct i40e_hw *hw,
     531                 :            :                                       u16 vsi_id,
     532                 :            :                                       struct i40e_aqc_get_set_rss_key_data *key)
     533                 :            : {
     534                 :          0 :         return i40e_aq_get_set_rss_key(hw, vsi_id, key, false);
     535                 :            : }
     536                 :            : 
     537                 :            : /**
     538                 :            :  * i40e_aq_set_rss_key
     539                 :            :  * @hw: pointer to the hw struct
     540                 :            :  * @vsi_id: vsi fw index
     541                 :            :  * @key: pointer to key info struct
     542                 :            :  *
     543                 :            :  * set the RSS key per VSI
     544                 :            :  **/
     545                 :          0 : enum i40e_status_code i40e_aq_set_rss_key(struct i40e_hw *hw,
     546                 :            :                                       u16 vsi_id,
     547                 :            :                                       struct i40e_aqc_get_set_rss_key_data *key)
     548                 :            : {
     549                 :          0 :         return i40e_aq_get_set_rss_key(hw, vsi_id, key, true);
     550                 :            : }
     551                 :            : 
     552                 :            : /* The i40e_ptype_lookup table is used to convert from the 8-bit ptype in the
     553                 :            :  * hardware to a bit-field that can be used by SW to more easily determine the
     554                 :            :  * packet type.
     555                 :            :  *
     556                 :            :  * Macros are used to shorten the table lines and make this table human
     557                 :            :  * readable.
     558                 :            :  *
     559                 :            :  * We store the PTYPE in the top byte of the bit field - this is just so that
     560                 :            :  * we can check that the table doesn't have a row missing, as the index into
     561                 :            :  * the table should be the PTYPE.
     562                 :            :  *
     563                 :            :  * Typical work flow:
     564                 :            :  *
     565                 :            :  * IF NOT i40e_ptype_lookup[ptype].known
     566                 :            :  * THEN
     567                 :            :  *      Packet is unknown
     568                 :            :  * ELSE IF i40e_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
     569                 :            :  *      Use the rest of the fields to look at the tunnels, inner protocols, etc
     570                 :            :  * ELSE
     571                 :            :  *      Use the enum i40e_rx_l2_ptype to decode the packet type
     572                 :            :  * ENDIF
     573                 :            :  */
     574                 :            : 
     575                 :            : /* macro to make the table lines short */
     576                 :            : #define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
     577                 :            :         {       PTYPE, \
     578                 :            :                 1, \
     579                 :            :                 I40E_RX_PTYPE_OUTER_##OUTER_IP, \
     580                 :            :                 I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
     581                 :            :                 I40E_RX_PTYPE_##OUTER_FRAG, \
     582                 :            :                 I40E_RX_PTYPE_TUNNEL_##T, \
     583                 :            :                 I40E_RX_PTYPE_TUNNEL_END_##TE, \
     584                 :            :                 I40E_RX_PTYPE_##TEF, \
     585                 :            :                 I40E_RX_PTYPE_INNER_PROT_##I, \
     586                 :            :                 I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
     587                 :            : 
     588                 :            : #define I40E_PTT_UNUSED_ENTRY(PTYPE) \
     589                 :            :                 { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
     590                 :            : 
     591                 :            : /* shorter macros makes the table fit but are terse */
     592                 :            : #define I40E_RX_PTYPE_NOF               I40E_RX_PTYPE_NOT_FRAG
     593                 :            : #define I40E_RX_PTYPE_FRG               I40E_RX_PTYPE_FRAG
     594                 :            : #define I40E_RX_PTYPE_INNER_PROT_TS     I40E_RX_PTYPE_INNER_PROT_TIMESYNC
     595                 :            : 
     596                 :            : /* Lookup table mapping the HW PTYPE to the bit field for decoding */
     597                 :            : struct i40e_rx_ptype_decoded i40e_ptype_lookup[] = {
     598                 :            :         /* L2 Packet types */
     599                 :            :         I40E_PTT_UNUSED_ENTRY(0),
     600                 :            :         I40E_PTT(1,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
     601                 :            :         I40E_PTT(2,  L2, NONE, NOF, NONE, NONE, NOF, TS,   PAY2),
     602                 :            :         I40E_PTT(3,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
     603                 :            :         I40E_PTT_UNUSED_ENTRY(4),
     604                 :            :         I40E_PTT_UNUSED_ENTRY(5),
     605                 :            :         I40E_PTT(6,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
     606                 :            :         I40E_PTT(7,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
     607                 :            :         I40E_PTT_UNUSED_ENTRY(8),
     608                 :            :         I40E_PTT_UNUSED_ENTRY(9),
     609                 :            :         I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
     610                 :            :         I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
     611                 :            :         I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
     612                 :            :         I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
     613                 :            :         I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
     614                 :            :         I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
     615                 :            :         I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
     616                 :            :         I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
     617                 :            :         I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
     618                 :            :         I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
     619                 :            :         I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
     620                 :            :         I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
     621                 :            : 
     622                 :            :         /* Non Tunneled IPv4 */
     623                 :            :         I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
     624                 :            :         I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
     625                 :            :         I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP,  PAY4),
     626                 :            :         I40E_PTT_UNUSED_ENTRY(25),
     627                 :            :         I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP,  PAY4),
     628                 :            :         I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
     629                 :            :         I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
     630                 :            : 
     631                 :            :         /* IPv4 --> IPv4 */
     632                 :            :         I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
     633                 :            :         I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
     634                 :            :         I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
     635                 :            :         I40E_PTT_UNUSED_ENTRY(32),
     636                 :            :         I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
     637                 :            :         I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
     638                 :            :         I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
     639                 :            : 
     640                 :            :         /* IPv4 --> IPv6 */
     641                 :            :         I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
     642                 :            :         I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
     643                 :            :         I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
     644                 :            :         I40E_PTT_UNUSED_ENTRY(39),
     645                 :            :         I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
     646                 :            :         I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
     647                 :            :         I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
     648                 :            : 
     649                 :            :         /* IPv4 --> GRE/NAT */
     650                 :            :         I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
     651                 :            : 
     652                 :            :         /* IPv4 --> GRE/NAT --> IPv4 */
     653                 :            :         I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
     654                 :            :         I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
     655                 :            :         I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
     656                 :            :         I40E_PTT_UNUSED_ENTRY(47),
     657                 :            :         I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
     658                 :            :         I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
     659                 :            :         I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
     660                 :            : 
     661                 :            :         /* IPv4 --> GRE/NAT --> IPv6 */
     662                 :            :         I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
     663                 :            :         I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
     664                 :            :         I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
     665                 :            :         I40E_PTT_UNUSED_ENTRY(54),
     666                 :            :         I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
     667                 :            :         I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
     668                 :            :         I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
     669                 :            : 
     670                 :            :         /* IPv4 --> GRE/NAT --> MAC */
     671                 :            :         I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
     672                 :            : 
     673                 :            :         /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
     674                 :            :         I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
     675                 :            :         I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
     676                 :            :         I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
     677                 :            :         I40E_PTT_UNUSED_ENTRY(62),
     678                 :            :         I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
     679                 :            :         I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
     680                 :            :         I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
     681                 :            : 
     682                 :            :         /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
     683                 :            :         I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
     684                 :            :         I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
     685                 :            :         I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
     686                 :            :         I40E_PTT_UNUSED_ENTRY(69),
     687                 :            :         I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
     688                 :            :         I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
     689                 :            :         I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
     690                 :            : 
     691                 :            :         /* IPv4 --> GRE/NAT --> MAC/VLAN */
     692                 :            :         I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
     693                 :            : 
     694                 :            :         /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
     695                 :            :         I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
     696                 :            :         I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
     697                 :            :         I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
     698                 :            :         I40E_PTT_UNUSED_ENTRY(77),
     699                 :            :         I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
     700                 :            :         I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
     701                 :            :         I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
     702                 :            : 
     703                 :            :         /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
     704                 :            :         I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
     705                 :            :         I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
     706                 :            :         I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
     707                 :            :         I40E_PTT_UNUSED_ENTRY(84),
     708                 :            :         I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
     709                 :            :         I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
     710                 :            :         I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
     711                 :            : 
     712                 :            :         /* Non Tunneled IPv6 */
     713                 :            :         I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
     714                 :            :         I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
     715                 :            :         I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP,  PAY4),
     716                 :            :         I40E_PTT_UNUSED_ENTRY(91),
     717                 :            :         I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP,  PAY4),
     718                 :            :         I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
     719                 :            :         I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
     720                 :            : 
     721                 :            :         /* IPv6 --> IPv4 */
     722                 :            :         I40E_PTT(95,  IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
     723                 :            :         I40E_PTT(96,  IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
     724                 :            :         I40E_PTT(97,  IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
     725                 :            :         I40E_PTT_UNUSED_ENTRY(98),
     726                 :            :         I40E_PTT(99,  IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
     727                 :            :         I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
     728                 :            :         I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
     729                 :            : 
     730                 :            :         /* IPv6 --> IPv6 */
     731                 :            :         I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
     732                 :            :         I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
     733                 :            :         I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
     734                 :            :         I40E_PTT_UNUSED_ENTRY(105),
     735                 :            :         I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
     736                 :            :         I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
     737                 :            :         I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
     738                 :            : 
     739                 :            :         /* IPv6 --> GRE/NAT */
     740                 :            :         I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
     741                 :            : 
     742                 :            :         /* IPv6 --> GRE/NAT -> IPv4 */
     743                 :            :         I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
     744                 :            :         I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
     745                 :            :         I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
     746                 :            :         I40E_PTT_UNUSED_ENTRY(113),
     747                 :            :         I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
     748                 :            :         I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
     749                 :            :         I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
     750                 :            : 
     751                 :            :         /* IPv6 --> GRE/NAT -> IPv6 */
     752                 :            :         I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
     753                 :            :         I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
     754                 :            :         I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
     755                 :            :         I40E_PTT_UNUSED_ENTRY(120),
     756                 :            :         I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
     757                 :            :         I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
     758                 :            :         I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
     759                 :            : 
     760                 :            :         /* IPv6 --> GRE/NAT -> MAC */
     761                 :            :         I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
     762                 :            : 
     763                 :            :         /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
     764                 :            :         I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
     765                 :            :         I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
     766                 :            :         I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
     767                 :            :         I40E_PTT_UNUSED_ENTRY(128),
     768                 :            :         I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
     769                 :            :         I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
     770                 :            :         I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
     771                 :            : 
     772                 :            :         /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
     773                 :            :         I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
     774                 :            :         I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
     775                 :            :         I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
     776                 :            :         I40E_PTT_UNUSED_ENTRY(135),
     777                 :            :         I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
     778                 :            :         I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
     779                 :            :         I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
     780                 :            : 
     781                 :            :         /* IPv6 --> GRE/NAT -> MAC/VLAN */
     782                 :            :         I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
     783                 :            : 
     784                 :            :         /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
     785                 :            :         I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
     786                 :            :         I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
     787                 :            :         I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
     788                 :            :         I40E_PTT_UNUSED_ENTRY(143),
     789                 :            :         I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
     790                 :            :         I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
     791                 :            :         I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
     792                 :            : 
     793                 :            :         /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
     794                 :            :         I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
     795                 :            :         I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
     796                 :            :         I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
     797                 :            :         I40E_PTT_UNUSED_ENTRY(150),
     798                 :            :         I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
     799                 :            :         I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
     800                 :            :         I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
     801                 :            : 
     802                 :            :         /* unused entries */
     803                 :            :         I40E_PTT_UNUSED_ENTRY(154),
     804                 :            :         I40E_PTT_UNUSED_ENTRY(155),
     805                 :            :         I40E_PTT_UNUSED_ENTRY(156),
     806                 :            :         I40E_PTT_UNUSED_ENTRY(157),
     807                 :            :         I40E_PTT_UNUSED_ENTRY(158),
     808                 :            :         I40E_PTT_UNUSED_ENTRY(159),
     809                 :            : 
     810                 :            :         I40E_PTT_UNUSED_ENTRY(160),
     811                 :            :         I40E_PTT_UNUSED_ENTRY(161),
     812                 :            :         I40E_PTT_UNUSED_ENTRY(162),
     813                 :            :         I40E_PTT_UNUSED_ENTRY(163),
     814                 :            :         I40E_PTT_UNUSED_ENTRY(164),
     815                 :            :         I40E_PTT_UNUSED_ENTRY(165),
     816                 :            :         I40E_PTT_UNUSED_ENTRY(166),
     817                 :            :         I40E_PTT_UNUSED_ENTRY(167),
     818                 :            :         I40E_PTT_UNUSED_ENTRY(168),
     819                 :            :         I40E_PTT_UNUSED_ENTRY(169),
     820                 :            : 
     821                 :            :         I40E_PTT_UNUSED_ENTRY(170),
     822                 :            :         I40E_PTT_UNUSED_ENTRY(171),
     823                 :            :         I40E_PTT_UNUSED_ENTRY(172),
     824                 :            :         I40E_PTT_UNUSED_ENTRY(173),
     825                 :            :         I40E_PTT_UNUSED_ENTRY(174),
     826                 :            :         I40E_PTT_UNUSED_ENTRY(175),
     827                 :            :         I40E_PTT_UNUSED_ENTRY(176),
     828                 :            :         I40E_PTT_UNUSED_ENTRY(177),
     829                 :            :         I40E_PTT_UNUSED_ENTRY(178),
     830                 :            :         I40E_PTT_UNUSED_ENTRY(179),
     831                 :            : 
     832                 :            :         I40E_PTT_UNUSED_ENTRY(180),
     833                 :            :         I40E_PTT_UNUSED_ENTRY(181),
     834                 :            :         I40E_PTT_UNUSED_ENTRY(182),
     835                 :            :         I40E_PTT_UNUSED_ENTRY(183),
     836                 :            :         I40E_PTT_UNUSED_ENTRY(184),
     837                 :            :         I40E_PTT_UNUSED_ENTRY(185),
     838                 :            :         I40E_PTT_UNUSED_ENTRY(186),
     839                 :            :         I40E_PTT_UNUSED_ENTRY(187),
     840                 :            :         I40E_PTT_UNUSED_ENTRY(188),
     841                 :            :         I40E_PTT_UNUSED_ENTRY(189),
     842                 :            : 
     843                 :            :         I40E_PTT_UNUSED_ENTRY(190),
     844                 :            :         I40E_PTT_UNUSED_ENTRY(191),
     845                 :            :         I40E_PTT_UNUSED_ENTRY(192),
     846                 :            :         I40E_PTT_UNUSED_ENTRY(193),
     847                 :            :         I40E_PTT_UNUSED_ENTRY(194),
     848                 :            :         I40E_PTT_UNUSED_ENTRY(195),
     849                 :            :         I40E_PTT_UNUSED_ENTRY(196),
     850                 :            :         I40E_PTT_UNUSED_ENTRY(197),
     851                 :            :         I40E_PTT_UNUSED_ENTRY(198),
     852                 :            :         I40E_PTT_UNUSED_ENTRY(199),
     853                 :            : 
     854                 :            :         I40E_PTT_UNUSED_ENTRY(200),
     855                 :            :         I40E_PTT_UNUSED_ENTRY(201),
     856                 :            :         I40E_PTT_UNUSED_ENTRY(202),
     857                 :            :         I40E_PTT_UNUSED_ENTRY(203),
     858                 :            :         I40E_PTT_UNUSED_ENTRY(204),
     859                 :            :         I40E_PTT_UNUSED_ENTRY(205),
     860                 :            :         I40E_PTT_UNUSED_ENTRY(206),
     861                 :            :         I40E_PTT_UNUSED_ENTRY(207),
     862                 :            :         I40E_PTT_UNUSED_ENTRY(208),
     863                 :            :         I40E_PTT_UNUSED_ENTRY(209),
     864                 :            : 
     865                 :            :         I40E_PTT_UNUSED_ENTRY(210),
     866                 :            :         I40E_PTT_UNUSED_ENTRY(211),
     867                 :            :         I40E_PTT_UNUSED_ENTRY(212),
     868                 :            :         I40E_PTT_UNUSED_ENTRY(213),
     869                 :            :         I40E_PTT_UNUSED_ENTRY(214),
     870                 :            :         I40E_PTT_UNUSED_ENTRY(215),
     871                 :            :         I40E_PTT_UNUSED_ENTRY(216),
     872                 :            :         I40E_PTT_UNUSED_ENTRY(217),
     873                 :            :         I40E_PTT_UNUSED_ENTRY(218),
     874                 :            :         I40E_PTT_UNUSED_ENTRY(219),
     875                 :            : 
     876                 :            :         I40E_PTT_UNUSED_ENTRY(220),
     877                 :            :         I40E_PTT_UNUSED_ENTRY(221),
     878                 :            :         I40E_PTT_UNUSED_ENTRY(222),
     879                 :            :         I40E_PTT_UNUSED_ENTRY(223),
     880                 :            :         I40E_PTT_UNUSED_ENTRY(224),
     881                 :            :         I40E_PTT_UNUSED_ENTRY(225),
     882                 :            :         I40E_PTT_UNUSED_ENTRY(226),
     883                 :            :         I40E_PTT_UNUSED_ENTRY(227),
     884                 :            :         I40E_PTT_UNUSED_ENTRY(228),
     885                 :            :         I40E_PTT_UNUSED_ENTRY(229),
     886                 :            : 
     887                 :            :         I40E_PTT_UNUSED_ENTRY(230),
     888                 :            :         I40E_PTT_UNUSED_ENTRY(231),
     889                 :            :         I40E_PTT_UNUSED_ENTRY(232),
     890                 :            :         I40E_PTT_UNUSED_ENTRY(233),
     891                 :            :         I40E_PTT_UNUSED_ENTRY(234),
     892                 :            :         I40E_PTT_UNUSED_ENTRY(235),
     893                 :            :         I40E_PTT_UNUSED_ENTRY(236),
     894                 :            :         I40E_PTT_UNUSED_ENTRY(237),
     895                 :            :         I40E_PTT_UNUSED_ENTRY(238),
     896                 :            :         I40E_PTT_UNUSED_ENTRY(239),
     897                 :            : 
     898                 :            :         I40E_PTT_UNUSED_ENTRY(240),
     899                 :            :         I40E_PTT_UNUSED_ENTRY(241),
     900                 :            :         I40E_PTT_UNUSED_ENTRY(242),
     901                 :            :         I40E_PTT_UNUSED_ENTRY(243),
     902                 :            :         I40E_PTT_UNUSED_ENTRY(244),
     903                 :            :         I40E_PTT_UNUSED_ENTRY(245),
     904                 :            :         I40E_PTT_UNUSED_ENTRY(246),
     905                 :            :         I40E_PTT_UNUSED_ENTRY(247),
     906                 :            :         I40E_PTT_UNUSED_ENTRY(248),
     907                 :            :         I40E_PTT_UNUSED_ENTRY(249),
     908                 :            : 
     909                 :            :         I40E_PTT_UNUSED_ENTRY(250),
     910                 :            :         I40E_PTT_UNUSED_ENTRY(251),
     911                 :            :         I40E_PTT_UNUSED_ENTRY(252),
     912                 :            :         I40E_PTT_UNUSED_ENTRY(253),
     913                 :            :         I40E_PTT_UNUSED_ENTRY(254),
     914                 :            :         I40E_PTT_UNUSED_ENTRY(255)
     915                 :            : };
     916                 :            : 
     917                 :            : /**
     918                 :            :  * i40e_validate_mac_addr - Validate unicast MAC address
     919                 :            :  * @mac_addr: pointer to MAC address
     920                 :            :  *
     921                 :            :  * Tests a MAC address to ensure it is a valid Individual Address
     922                 :            :  **/
     923                 :          0 : enum i40e_status_code i40e_validate_mac_addr(u8 *mac_addr)
     924                 :            : {
     925                 :            :         enum i40e_status_code status = I40E_SUCCESS;
     926                 :            : 
     927                 :          0 :         DEBUGFUNC("i40e_validate_mac_addr");
     928                 :            : 
     929                 :            :         /* Broadcast addresses ARE multicast addresses
     930                 :            :          * Make sure it is not a multicast address
     931                 :            :          * Reject the zero address
     932                 :            :          */
     933   [ #  #  #  # ]:          0 :         if (I40E_IS_MULTICAST(mac_addr) ||
     934   [ #  #  #  # ]:          0 :             (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
     935   [ #  #  #  #  :          0 :               mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0))
                   #  # ]
     936                 :            :                 status = I40E_ERR_INVALID_MAC_ADDR;
     937                 :            : 
     938                 :          0 :         return status;
     939                 :            : }
     940                 :            : 
     941                 :            : /**
     942                 :            :  * i40e_init_shared_code - Initialize the shared code
     943                 :            :  * @hw: pointer to hardware structure
     944                 :            :  *
     945                 :            :  * This assigns the MAC type and PHY code and inits the NVM.
     946                 :            :  * Does not touch the hardware. This function must be called prior to any
     947                 :            :  * other function in the shared code. The i40e_hw structure should be
     948                 :            :  * memset to 0 prior to calling this function.  The following fields in
     949                 :            :  * hw structure should be filled in prior to calling this function:
     950                 :            :  * hw_addr, back, device_id, vendor_id, subsystem_device_id,
     951                 :            :  * subsystem_vendor_id, and revision_id
     952                 :            :  **/
     953                 :          0 : enum i40e_status_code i40e_init_shared_code(struct i40e_hw *hw)
     954                 :            : {
     955                 :            :         enum i40e_status_code status = I40E_SUCCESS;
     956                 :            :         u32 port, ari, func_rid;
     957                 :            : 
     958                 :          0 :         DEBUGFUNC("i40e_init_shared_code");
     959                 :            : 
     960                 :          0 :         i40e_set_mac_type(hw);
     961                 :            : 
     962         [ #  # ]:          0 :         switch (hw->mac.type) {
     963                 :            :         case I40E_MAC_XL710:
     964                 :            :         case I40E_MAC_X722:
     965                 :            :                 break;
     966                 :            :         default:
     967                 :            :                 return I40E_ERR_DEVICE_NOT_SUPPORTED;
     968                 :            :         }
     969                 :            : 
     970                 :          0 :         hw->phy.get_link_info = true;
     971                 :            : 
     972                 :            :         /* Determine port number and PF number*/
     973                 :          0 :         port = (rd32(hw, I40E_PFGEN_PORTNUM) & I40E_PFGEN_PORTNUM_PORT_NUM_MASK)
     974                 :            :                                            >> I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT;
     975                 :          0 :         hw->port = (u8)port;
     976                 :          0 :         ari = (rd32(hw, I40E_GLPCI_CAPSUP) & I40E_GLPCI_CAPSUP_ARI_EN_MASK) >>
     977                 :            :                                                  I40E_GLPCI_CAPSUP_ARI_EN_SHIFT;
     978                 :          0 :         func_rid = rd32(hw, I40E_PF_FUNC_RID);
     979         [ #  # ]:          0 :         if (ari)
     980                 :          0 :                 hw->pf_id = (u8)(func_rid & 0xff);
     981                 :            :         else
     982                 :          0 :                 hw->pf_id = (u8)(func_rid & 0x7);
     983                 :            : 
     984                 :            :         /* NVMUpdate features structure initialization */
     985                 :          0 :         hw->nvmupd_features.major = I40E_NVMUPD_FEATURES_API_VER_MAJOR;
     986                 :          0 :         hw->nvmupd_features.minor = I40E_NVMUPD_FEATURES_API_VER_MINOR;
     987                 :          0 :         hw->nvmupd_features.size = sizeof(hw->nvmupd_features);
     988                 :          0 :         i40e_memset(hw->nvmupd_features.features, 0x0,
     989                 :            :                     I40E_NVMUPD_FEATURES_API_FEATURES_ARRAY_LEN *
     990                 :            :                     sizeof(*hw->nvmupd_features.features),
     991                 :            :                     I40E_NONDMA_MEM);
     992                 :            : 
     993                 :            :         /* No features supported at the moment */
     994                 :            :         hw->nvmupd_features.features[0] = 0;
     995                 :            : 
     996                 :          0 :         status = i40e_init_nvm(hw);
     997                 :          0 :         return status;
     998                 :            : }
     999                 :            : 
    1000                 :            : /**
    1001                 :            :  * i40e_aq_mac_address_read - Retrieve the MAC addresses
    1002                 :            :  * @hw: pointer to the hw struct
    1003                 :            :  * @flags: a return indicator of what addresses were added to the addr store
    1004                 :            :  * @addrs: the requestor's mac addr store
    1005                 :            :  * @cmd_details: pointer to command details structure or NULL
    1006                 :            :  **/
    1007                 :          0 : STATIC enum i40e_status_code i40e_aq_mac_address_read(struct i40e_hw *hw,
    1008                 :            :                                    u16 *flags,
    1009                 :            :                                    struct i40e_aqc_mac_address_read_data *addrs,
    1010                 :            :                                    struct i40e_asq_cmd_details *cmd_details)
    1011                 :            : {
    1012                 :            :         struct i40e_aq_desc desc;
    1013                 :            :         struct i40e_aqc_mac_address_read *cmd_data =
    1014                 :            :                 (struct i40e_aqc_mac_address_read *)&desc.params.raw;
    1015                 :            :         enum i40e_status_code status;
    1016                 :            : 
    1017                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
    1018                 :          0 :         desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_BUF);
    1019                 :            : 
    1020                 :          0 :         status = i40e_asq_send_command(hw, &desc, addrs,
    1021                 :            :                                        sizeof(*addrs), cmd_details);
    1022                 :          0 :         *flags = LE16_TO_CPU(cmd_data->command_flags);
    1023                 :            : 
    1024                 :          0 :         return status;
    1025                 :            : }
    1026                 :            : 
    1027                 :            : /**
    1028                 :            :  * i40e_aq_mac_address_write - Change the MAC addresses
    1029                 :            :  * @hw: pointer to the hw struct
    1030                 :            :  * @flags: indicates which MAC to be written
    1031                 :            :  * @mac_addr: address to write
    1032                 :            :  * @cmd_details: pointer to command details structure or NULL
    1033                 :            :  **/
    1034                 :          0 : enum i40e_status_code i40e_aq_mac_address_write(struct i40e_hw *hw,
    1035                 :            :                                     u16 flags, u8 *mac_addr,
    1036                 :            :                                     struct i40e_asq_cmd_details *cmd_details)
    1037                 :            : {
    1038                 :            :         struct i40e_aq_desc desc;
    1039                 :            :         struct i40e_aqc_mac_address_write *cmd_data =
    1040                 :            :                 (struct i40e_aqc_mac_address_write *)&desc.params.raw;
    1041                 :            :         enum i40e_status_code status;
    1042                 :            : 
    1043                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    1044                 :            :                                           i40e_aqc_opc_mac_address_write);
    1045                 :          0 :         cmd_data->command_flags = CPU_TO_LE16(flags);
    1046                 :          0 :         cmd_data->mac_sah = CPU_TO_LE16((u16)mac_addr[0] << 8 | mac_addr[1]);
    1047                 :          0 :         cmd_data->mac_sal = CPU_TO_LE32(((u32)mac_addr[2] << 24) |
    1048                 :            :                                         ((u32)mac_addr[3] << 16) |
    1049                 :            :                                         ((u32)mac_addr[4] << 8) |
    1050                 :            :                                         mac_addr[5]);
    1051                 :            : 
    1052                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    1053                 :            : 
    1054                 :          0 :         return status;
    1055                 :            : }
    1056                 :            : 
    1057                 :            : /**
    1058                 :            :  * i40e_get_mac_addr - get MAC address
    1059                 :            :  * @hw: pointer to the HW structure
    1060                 :            :  * @mac_addr: pointer to MAC address
    1061                 :            :  *
    1062                 :            :  * Reads the adapter's MAC address from register
    1063                 :            :  **/
    1064                 :          0 : enum i40e_status_code i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
    1065                 :            : {
    1066                 :            :         struct i40e_aqc_mac_address_read_data addrs;
    1067                 :            :         enum i40e_status_code status;
    1068                 :          0 :         u16 flags = 0;
    1069                 :            : 
    1070                 :          0 :         status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
    1071                 :            : 
    1072         [ #  # ]:          0 :         if (flags & I40E_AQC_LAN_ADDR_VALID)
    1073                 :            :                 i40e_memcpy(mac_addr, &addrs.pf_lan_mac, sizeof(addrs.pf_lan_mac),
    1074                 :            :                         I40E_NONDMA_TO_NONDMA);
    1075                 :            : 
    1076                 :          0 :         return status;
    1077                 :            : }
    1078                 :            : 
    1079                 :            : /**
    1080                 :            :  * i40e_get_port_mac_addr - get Port MAC address
    1081                 :            :  * @hw: pointer to the HW structure
    1082                 :            :  * @mac_addr: pointer to Port MAC address
    1083                 :            :  *
    1084                 :            :  * Reads the adapter's Port MAC address
    1085                 :            :  **/
    1086                 :          0 : enum i40e_status_code i40e_get_port_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
    1087                 :            : {
    1088                 :            :         struct i40e_aqc_mac_address_read_data addrs;
    1089                 :            :         enum i40e_status_code status;
    1090                 :          0 :         u16 flags = 0;
    1091                 :            : 
    1092                 :          0 :         status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
    1093         [ #  # ]:          0 :         if (status)
    1094                 :            :                 return status;
    1095                 :            : 
    1096         [ #  # ]:          0 :         if (flags & I40E_AQC_PORT_ADDR_VALID)
    1097                 :            :                 i40e_memcpy(mac_addr, &addrs.port_mac, sizeof(addrs.port_mac),
    1098                 :            :                         I40E_NONDMA_TO_NONDMA);
    1099                 :            :         else
    1100                 :            :                 status = I40E_ERR_INVALID_MAC_ADDR;
    1101                 :            : 
    1102                 :            :         return status;
    1103                 :            : }
    1104                 :            : 
    1105                 :            : /**
    1106                 :            :  * i40e_pre_tx_queue_cfg - pre tx queue configure
    1107                 :            :  * @hw: pointer to the HW structure
    1108                 :            :  * @queue: target pf queue index
    1109                 :            :  * @enable: state change request
    1110                 :            :  *
    1111                 :            :  * Handles hw requirement to indicate intention to enable
    1112                 :            :  * or disable target queue.
    1113                 :            :  **/
    1114                 :          0 : void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
    1115                 :            : {
    1116                 :          0 :         u32 abs_queue_idx = hw->func_caps.base_queue + queue;
    1117                 :            :         u32 reg_block = 0;
    1118                 :            :         u32 reg_val;
    1119                 :            : 
    1120         [ #  # ]:          0 :         if (abs_queue_idx >= 128) {
    1121                 :          0 :                 reg_block = abs_queue_idx / 128;
    1122                 :          0 :                 abs_queue_idx %= 128;
    1123                 :            :         }
    1124                 :            : 
    1125                 :          0 :         reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
    1126                 :          0 :         reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
    1127                 :          0 :         reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
    1128                 :            : 
    1129         [ #  # ]:          0 :         if (enable)
    1130                 :          0 :                 reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
    1131                 :            :         else
    1132                 :          0 :                 reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
    1133                 :            : 
    1134                 :          0 :         wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
    1135                 :          0 : }
    1136                 :            : 
    1137                 :            : /**
    1138                 :            :  * i40e_get_san_mac_addr - get SAN MAC address
    1139                 :            :  * @hw: pointer to the HW structure
    1140                 :            :  * @mac_addr: pointer to SAN MAC address
    1141                 :            :  *
    1142                 :            :  * Reads the adapter's SAN MAC address from NVM
    1143                 :            :  **/
    1144                 :          0 : enum i40e_status_code i40e_get_san_mac_addr(struct i40e_hw *hw,
    1145                 :            :                                             u8 *mac_addr)
    1146                 :            : {
    1147                 :            :         struct i40e_aqc_mac_address_read_data addrs;
    1148                 :            :         enum i40e_status_code status;
    1149                 :          0 :         u16 flags = 0;
    1150                 :            : 
    1151                 :          0 :         status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
    1152         [ #  # ]:          0 :         if (status)
    1153                 :            :                 return status;
    1154                 :            : 
    1155         [ #  # ]:          0 :         if (flags & I40E_AQC_SAN_ADDR_VALID)
    1156                 :            :                 i40e_memcpy(mac_addr, &addrs.pf_san_mac, sizeof(addrs.pf_san_mac),
    1157                 :            :                         I40E_NONDMA_TO_NONDMA);
    1158                 :            :         else
    1159                 :            :                 status = I40E_ERR_INVALID_MAC_ADDR;
    1160                 :            : 
    1161                 :            :         return status;
    1162                 :            : }
    1163                 :            : 
    1164                 :            : /**
    1165                 :            :  *  i40e_read_pba_string - Reads part number string from EEPROM
    1166                 :            :  *  @hw: pointer to hardware structure
    1167                 :            :  *  @pba_num: stores the part number string from the EEPROM
    1168                 :            :  *  @pba_num_size: part number string buffer length
    1169                 :            :  *
    1170                 :            :  *  Reads the part number string from the EEPROM.
    1171                 :            :  **/
    1172                 :          0 : enum i40e_status_code i40e_read_pba_string(struct i40e_hw *hw, u8 *pba_num,
    1173                 :            :                                             u32 pba_num_size)
    1174                 :            : {
    1175                 :            :         enum i40e_status_code status = I40E_SUCCESS;
    1176                 :          0 :         u16 pba_word = 0;
    1177                 :          0 :         u16 pba_size = 0;
    1178                 :          0 :         u16 pba_ptr = 0;
    1179                 :            :         u16 i = 0;
    1180                 :            : 
    1181                 :          0 :         status = i40e_read_nvm_word(hw, I40E_SR_PBA_FLAGS, &pba_word);
    1182   [ #  #  #  # ]:          0 :         if ((status != I40E_SUCCESS) || (pba_word != 0xFAFA)) {
    1183                 :          0 :                 DEBUGOUT("Failed to read PBA flags or flag is invalid.\n");
    1184                 :          0 :                 return status;
    1185                 :            :         }
    1186                 :            : 
    1187                 :          0 :         status = i40e_read_nvm_word(hw, I40E_SR_PBA_BLOCK_PTR, &pba_ptr);
    1188         [ #  # ]:          0 :         if (status != I40E_SUCCESS) {
    1189                 :          0 :                 DEBUGOUT("Failed to read PBA Block pointer.\n");
    1190                 :          0 :                 return status;
    1191                 :            :         }
    1192                 :            : 
    1193                 :          0 :         status = i40e_read_nvm_word(hw, pba_ptr, &pba_size);
    1194         [ #  # ]:          0 :         if (status != I40E_SUCCESS) {
    1195                 :          0 :                 DEBUGOUT("Failed to read PBA Block size.\n");
    1196                 :          0 :                 return status;
    1197                 :            :         }
    1198                 :            : 
    1199                 :            :         /* Subtract one to get PBA word count (PBA Size word is included in
    1200                 :            :          * total size)
    1201                 :            :          */
    1202                 :          0 :         pba_size--;
    1203         [ #  # ]:          0 :         if (pba_num_size < (((u32)pba_size * 2) + 1)) {
    1204                 :          0 :                 DEBUGOUT("Buffer to small for PBA data.\n");
    1205                 :          0 :                 return I40E_ERR_PARAM;
    1206                 :            :         }
    1207                 :            : 
    1208         [ #  # ]:          0 :         for (i = 0; i < pba_size; i++) {
    1209                 :          0 :                 status = i40e_read_nvm_word(hw, (pba_ptr + 1) + i, &pba_word);
    1210         [ #  # ]:          0 :                 if (status != I40E_SUCCESS) {
    1211                 :          0 :                         DEBUGOUT1("Failed to read PBA Block word %d.\n", i);
    1212                 :          0 :                         return status;
    1213                 :            :                 }
    1214                 :            : 
    1215                 :          0 :                 pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
    1216                 :          0 :                 pba_num[(i * 2) + 1] = pba_word & 0xFF;
    1217                 :            :         }
    1218                 :          0 :         pba_num[(pba_size * 2)] = '\0';
    1219                 :            : 
    1220                 :          0 :         return status;
    1221                 :            : }
    1222                 :            : 
    1223                 :            : /**
    1224                 :            :  * i40e_get_media_type - Gets media type
    1225                 :            :  * @hw: pointer to the hardware structure
    1226                 :            :  **/
    1227                 :            : STATIC enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
    1228                 :            : {
    1229                 :            :         enum i40e_media_type media;
    1230                 :            : 
    1231                 :            :         switch (hw->phy.link_info.phy_type) {
    1232                 :            :         case I40E_PHY_TYPE_10GBASE_SR:
    1233                 :            :         case I40E_PHY_TYPE_10GBASE_LR:
    1234                 :            :         case I40E_PHY_TYPE_1000BASE_SX:
    1235                 :            :         case I40E_PHY_TYPE_1000BASE_LX:
    1236                 :            :         case I40E_PHY_TYPE_40GBASE_SR4:
    1237                 :            :         case I40E_PHY_TYPE_40GBASE_LR4:
    1238                 :            :         case I40E_PHY_TYPE_25GBASE_LR:
    1239                 :            :         case I40E_PHY_TYPE_25GBASE_SR:
    1240                 :            :         case I40E_PHY_TYPE_10GBASE_AOC:
    1241                 :            :         case I40E_PHY_TYPE_25GBASE_AOC:
    1242                 :            :         case I40E_PHY_TYPE_40GBASE_AOC:
    1243                 :            :                 media = I40E_MEDIA_TYPE_FIBER;
    1244                 :            :                 break;
    1245                 :            :         case I40E_PHY_TYPE_100BASE_TX:
    1246                 :            :         case I40E_PHY_TYPE_1000BASE_T:
    1247                 :            :         case I40E_PHY_TYPE_2_5GBASE_T_LINK_STATUS:
    1248                 :            :         case I40E_PHY_TYPE_5GBASE_T_LINK_STATUS:
    1249                 :            :         case I40E_PHY_TYPE_10GBASE_T:
    1250                 :            :                 media = I40E_MEDIA_TYPE_BASET;
    1251                 :            :                 break;
    1252                 :            :         case I40E_PHY_TYPE_10GBASE_CR1_CU:
    1253                 :            :         case I40E_PHY_TYPE_40GBASE_CR4_CU:
    1254                 :            :         case I40E_PHY_TYPE_10GBASE_CR1:
    1255                 :            :         case I40E_PHY_TYPE_40GBASE_CR4:
    1256                 :            :         case I40E_PHY_TYPE_10GBASE_SFPP_CU:
    1257                 :            :         case I40E_PHY_TYPE_25GBASE_CR:
    1258                 :            :         case I40E_PHY_TYPE_25GBASE_ACC:
    1259                 :            :                 media = I40E_MEDIA_TYPE_DA;
    1260                 :            :                 break;
    1261                 :            :         case I40E_PHY_TYPE_1000BASE_KX:
    1262                 :            :         case I40E_PHY_TYPE_10GBASE_KX4:
    1263                 :            :         case I40E_PHY_TYPE_10GBASE_KR:
    1264                 :            :         case I40E_PHY_TYPE_40GBASE_KR4:
    1265                 :            :         case I40E_PHY_TYPE_20GBASE_KR2:
    1266                 :            :         case I40E_PHY_TYPE_25GBASE_KR:
    1267                 :            :                 media = I40E_MEDIA_TYPE_BACKPLANE;
    1268                 :            :                 break;
    1269                 :            :         case I40E_PHY_TYPE_SGMII:
    1270                 :            :         case I40E_PHY_TYPE_XAUI:
    1271                 :            :         case I40E_PHY_TYPE_XFI:
    1272                 :            :         case I40E_PHY_TYPE_XLAUI:
    1273                 :            :         case I40E_PHY_TYPE_XLPPI:
    1274                 :            :         default:
    1275                 :            :                 media = I40E_MEDIA_TYPE_UNKNOWN;
    1276                 :            :                 break;
    1277                 :            :         }
    1278                 :            : 
    1279                 :            :         return media;
    1280                 :            : }
    1281                 :            : 
    1282                 :            : /**
    1283                 :            :  * i40e_poll_globr - Poll for Global Reset completion
    1284                 :            :  * @hw: pointer to the hardware structure
    1285                 :            :  * @retry_limit: how many times to retry before failure
    1286                 :            :  **/
    1287                 :          0 : STATIC enum i40e_status_code i40e_poll_globr(struct i40e_hw *hw,
    1288                 :            :                                              u32 retry_limit)
    1289                 :            : {
    1290                 :            :         u32 cnt, reg = 0;
    1291                 :            : 
    1292         [ #  # ]:          0 :         for (cnt = 0; cnt < retry_limit; cnt++) {
    1293                 :          0 :                 reg = rd32(hw, I40E_GLGEN_RSTAT);
    1294         [ #  # ]:          0 :                 if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
    1295                 :            :                         return I40E_SUCCESS;
    1296                 :          0 :                 i40e_msec_delay(100);
    1297                 :            :         }
    1298                 :            : 
    1299                 :          0 :         DEBUGOUT("Global reset failed.\n");
    1300                 :          0 :         DEBUGOUT1("I40E_GLGEN_RSTAT = 0x%x\n", reg);
    1301                 :            : 
    1302                 :          0 :         return I40E_ERR_RESET_FAILED;
    1303                 :            : }
    1304                 :            : 
    1305                 :            : #define I40E_PF_RESET_WAIT_COUNT        1000
    1306                 :            : /**
    1307                 :            :  * i40e_pf_reset - Reset the PF
    1308                 :            :  * @hw: pointer to the hardware structure
    1309                 :            :  *
    1310                 :            :  * Assuming someone else has triggered a global reset,
    1311                 :            :  * assure the global reset is complete and then reset the PF
    1312                 :            :  **/
    1313                 :          0 : enum i40e_status_code i40e_pf_reset(struct i40e_hw *hw)
    1314                 :            : {
    1315                 :            :         u32 cnt = 0;
    1316                 :            :         u32 cnt1 = 0;
    1317                 :            :         u32 reg = 0;
    1318                 :            :         u32 grst_del;
    1319                 :            : 
    1320                 :            :         /* Poll for Global Reset steady state in case of recent GRST.
    1321                 :            :          * The grst delay value is in 100ms units, and we'll wait a
    1322                 :            :          * couple counts longer to be sure we don't just miss the end.
    1323                 :            :          */
    1324                 :          0 :         grst_del = (rd32(hw, I40E_GLGEN_RSTCTL) &
    1325                 :            :                         I40E_GLGEN_RSTCTL_GRSTDEL_MASK) >>
    1326                 :            :                         I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
    1327                 :            : 
    1328                 :          0 :         grst_del = min(grst_del * 20, 160U);
    1329                 :            : 
    1330         [ #  # ]:          0 :         for (cnt = 0; cnt < grst_del; cnt++) {
    1331                 :          0 :                 reg = rd32(hw, I40E_GLGEN_RSTAT);
    1332         [ #  # ]:          0 :                 if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
    1333                 :            :                         break;
    1334                 :          0 :                 i40e_msec_delay(100);
    1335                 :            :         }
    1336         [ #  # ]:          0 :         if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
    1337                 :          0 :                 DEBUGOUT("Global reset polling failed to complete.\n");
    1338                 :          0 :                 return I40E_ERR_RESET_FAILED;
    1339                 :            :         }
    1340                 :            : 
    1341                 :            :         /* Now Wait for the FW to be ready */
    1342         [ #  # ]:          0 :         for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
    1343                 :          0 :                 reg = rd32(hw, I40E_GLNVM_ULD);
    1344                 :          0 :                 reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
    1345                 :            :                         I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
    1346         [ #  # ]:          0 :                 if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
    1347                 :            :                             I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
    1348                 :          0 :                         DEBUGOUT1("Core and Global modules ready %d\n", cnt1);
    1349                 :          0 :                         break;
    1350                 :            :                 }
    1351                 :          0 :                 i40e_msec_delay(10);
    1352                 :            :         }
    1353         [ #  # ]:          0 :         if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
    1354                 :            :                      I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
    1355                 :          0 :                 DEBUGOUT("wait for FW Reset complete timedout\n");
    1356                 :          0 :                 DEBUGOUT1("I40E_GLNVM_ULD = 0x%x\n", reg);
    1357                 :          0 :                 return I40E_ERR_RESET_FAILED;
    1358                 :            :         }
    1359                 :            : 
    1360                 :            :         /* If there was a Global Reset in progress when we got here,
    1361                 :            :          * we don't need to do the PF Reset
    1362                 :            :          */
    1363         [ #  # ]:          0 :         if (!cnt) {
    1364                 :            :                 u32 reg2 = 0;
    1365                 :            : 
    1366                 :          0 :                 reg = rd32(hw, I40E_PFGEN_CTRL);
    1367                 :          0 :                 wr32(hw, I40E_PFGEN_CTRL,
    1368                 :            :                      (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
    1369         [ #  # ]:          0 :                 for (cnt = 0; cnt < I40E_PF_RESET_WAIT_COUNT; cnt++) {
    1370                 :          0 :                         reg = rd32(hw, I40E_PFGEN_CTRL);
    1371         [ #  # ]:          0 :                         if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
    1372                 :            :                                 break;
    1373                 :          0 :                         reg2 = rd32(hw, I40E_GLGEN_RSTAT);
    1374         [ #  # ]:          0 :                         if (reg2 & I40E_GLGEN_RSTAT_DEVSTATE_MASK)
    1375                 :            :                                 break;
    1376                 :          0 :                         i40e_msec_delay(1);
    1377                 :            :                 }
    1378         [ #  # ]:          0 :                 if (reg2 & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
    1379         [ #  # ]:          0 :                         if (i40e_poll_globr(hw, grst_del) != I40E_SUCCESS)
    1380                 :            :                                 return I40E_ERR_RESET_FAILED;
    1381         [ #  # ]:          0 :                 } else if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
    1382                 :          0 :                         DEBUGOUT("PF reset polling failed to complete.\n");
    1383                 :          0 :                         return I40E_ERR_RESET_FAILED;
    1384                 :            :                 }
    1385                 :            :         }
    1386                 :            : 
    1387                 :          0 :         i40e_clear_pxe_mode(hw);
    1388                 :            : 
    1389                 :          0 :         return I40E_SUCCESS;
    1390                 :            : }
    1391                 :            : 
    1392                 :            : /**
    1393                 :            :  * i40e_clear_hw - clear out any left over hw state
    1394                 :            :  * @hw: pointer to the hw struct
    1395                 :            :  *
    1396                 :            :  * Clear queues and interrupts, typically called at init time,
    1397                 :            :  * but after the capabilities have been found so we know how many
    1398                 :            :  * queues and msix vectors have been allocated.
    1399                 :            :  **/
    1400                 :          0 : void i40e_clear_hw(struct i40e_hw *hw)
    1401                 :            : {
    1402                 :            :         u32 num_queues, base_queue;
    1403                 :            :         u32 num_pf_int;
    1404                 :            :         u32 num_vf_int;
    1405                 :            :         u32 num_vfs;
    1406                 :            :         u32 i, j;
    1407                 :            :         u32 val;
    1408                 :            :         u32 eol = 0x7ff;
    1409                 :            : 
    1410                 :            :         /* get number of interrupts, queues, and vfs */
    1411                 :          0 :         val = rd32(hw, I40E_GLPCI_CNF2);
    1412                 :          0 :         num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
    1413                 :            :                         I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
    1414                 :          0 :         num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
    1415                 :            :                         I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
    1416                 :            : 
    1417                 :          0 :         val = rd32(hw, I40E_PFLAN_QALLOC);
    1418                 :          0 :         base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
    1419                 :            :                         I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
    1420                 :          0 :         j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
    1421                 :            :                         I40E_PFLAN_QALLOC_LASTQ_SHIFT;
    1422         [ #  # ]:          0 :         if (val & I40E_PFLAN_QALLOC_VALID_MASK)
    1423                 :          0 :                 num_queues = (j - base_queue) + 1;
    1424                 :            :         else
    1425                 :            :                 num_queues = 0;
    1426                 :            : 
    1427                 :          0 :         val = rd32(hw, I40E_PF_VT_PFALLOC);
    1428                 :          0 :         i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
    1429                 :            :                         I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
    1430                 :          0 :         j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
    1431                 :            :                         I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
    1432         [ #  # ]:          0 :         if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
    1433                 :          0 :                 num_vfs = (j - i) + 1;
    1434                 :            :         else
    1435                 :            :                 num_vfs = 0;
    1436                 :            : 
    1437                 :            :         /* stop all the interrupts */
    1438                 :          0 :         wr32(hw, I40E_PFINT_ICR0_ENA, 0);
    1439                 :            :         val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
    1440         [ #  # ]:          0 :         for (i = 0; i < num_pf_int - 2; i++)
    1441                 :          0 :                 wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
    1442                 :            : 
    1443                 :            :         /* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
    1444                 :            :         val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
    1445                 :          0 :         wr32(hw, I40E_PFINT_LNKLST0, val);
    1446         [ #  # ]:          0 :         for (i = 0; i < num_pf_int - 2; i++)
    1447                 :          0 :                 wr32(hw, I40E_PFINT_LNKLSTN(i), val);
    1448                 :            :         val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
    1449         [ #  # ]:          0 :         for (i = 0; i < num_vfs; i++)
    1450                 :          0 :                 wr32(hw, I40E_VPINT_LNKLST0(i), val);
    1451         [ #  # ]:          0 :         for (i = 0; i < num_vf_int - 2; i++)
    1452                 :          0 :                 wr32(hw, I40E_VPINT_LNKLSTN(i), val);
    1453                 :            : 
    1454                 :            :         /* warn the HW of the coming Tx disables */
    1455         [ #  # ]:          0 :         for (i = 0; i < num_queues; i++) {
    1456                 :          0 :                 u32 abs_queue_idx = base_queue + i;
    1457                 :            :                 u32 reg_block = 0;
    1458                 :            : 
    1459         [ #  # ]:          0 :                 if (abs_queue_idx >= 128) {
    1460                 :          0 :                         reg_block = abs_queue_idx / 128;
    1461                 :          0 :                         abs_queue_idx %= 128;
    1462                 :            :                 }
    1463                 :            : 
    1464                 :          0 :                 val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
    1465                 :          0 :                 val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
    1466                 :          0 :                 val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
    1467                 :          0 :                 val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
    1468                 :            : 
    1469                 :          0 :                 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
    1470                 :            :         }
    1471                 :          0 :         i40e_usec_delay(400);
    1472                 :            : 
    1473                 :            :         /* stop all the queues */
    1474         [ #  # ]:          0 :         for (i = 0; i < num_queues; i++) {
    1475                 :          0 :                 wr32(hw, I40E_QINT_TQCTL(i), 0);
    1476                 :          0 :                 wr32(hw, I40E_QTX_ENA(i), 0);
    1477                 :          0 :                 wr32(hw, I40E_QINT_RQCTL(i), 0);
    1478                 :          0 :                 wr32(hw, I40E_QRX_ENA(i), 0);
    1479                 :            :         }
    1480                 :            : 
    1481                 :            :         /* short wait for all queue disables to settle */
    1482                 :          0 :         i40e_usec_delay(50);
    1483                 :          0 : }
    1484                 :            : 
    1485                 :            : /**
    1486                 :            :  * i40e_clear_pxe_mode - clear pxe operations mode
    1487                 :            :  * @hw: pointer to the hw struct
    1488                 :            :  *
    1489                 :            :  * Make sure all PXE mode settings are cleared, including things
    1490                 :            :  * like descriptor fetch/write-back mode.
    1491                 :            :  **/
    1492                 :          0 : void i40e_clear_pxe_mode(struct i40e_hw *hw)
    1493                 :            : {
    1494         [ #  # ]:          0 :         if (i40e_check_asq_alive(hw))
    1495                 :          0 :                 i40e_aq_clear_pxe_mode(hw, NULL);
    1496                 :          0 : }
    1497                 :            : 
    1498                 :            : /**
    1499                 :            :  * i40e_led_is_mine - helper to find matching led
    1500                 :            :  * @hw: pointer to the hw struct
    1501                 :            :  * @idx: index into GPIO registers
    1502                 :            :  *
    1503                 :            :  * returns: 0 if no match, otherwise the value of the GPIO_CTL register
    1504                 :            :  */
    1505                 :          0 : static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
    1506                 :            : {
    1507                 :            :         u32 gpio_val = 0;
    1508                 :            :         u32 port;
    1509                 :            : 
    1510   [ #  #  #  # ]:          0 :         if (!I40E_IS_X710TL_DEVICE(hw->device_id) &&
    1511         [ #  # ]:          0 :             !hw->func_caps.led[idx])
    1512                 :            :                 return 0;
    1513                 :          0 :         gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
    1514                 :          0 :         port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
    1515                 :            :                 I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
    1516                 :            : 
    1517                 :            :         /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
    1518                 :            :          * if it is not our port then ignore
    1519                 :            :          */
    1520         [ #  # ]:          0 :         if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
    1521         [ #  # ]:          0 :             (port != hw->port))
    1522                 :          0 :                 return 0;
    1523                 :            : 
    1524                 :            :         return gpio_val;
    1525                 :            : }
    1526                 :            : 
    1527                 :            : #define I40E_COMBINED_ACTIVITY 0xA
    1528                 :            : #define I40E_FILTER_ACTIVITY 0xE
    1529                 :            : #define I40E_LINK_ACTIVITY 0xC
    1530                 :            : #define I40E_MAC_ACTIVITY 0xD
    1531                 :            : #define I40E_FW_LED BIT(4)
    1532                 :            : #define I40E_LED_MODE_VALID (I40E_GLGEN_GPIO_CTL_LED_MODE_MASK >> \
    1533                 :            :                              I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT)
    1534                 :            : 
    1535                 :            : #define I40E_LED0 22
    1536                 :            : 
    1537                 :            : #define I40E_PIN_FUNC_SDP 0x0
    1538                 :            : #define I40E_PIN_FUNC_LED 0x1
    1539                 :            : 
    1540                 :            : /**
    1541                 :            :  * i40e_led_get - return current on/off mode
    1542                 :            :  * @hw: pointer to the hw struct
    1543                 :            :  *
    1544                 :            :  * The value returned is the 'mode' field as defined in the
    1545                 :            :  * GPIO register definitions: 0x0 = off, 0xf = on, and other
    1546                 :            :  * values are variations of possible behaviors relating to
    1547                 :            :  * blink, link, and wire.
    1548                 :            :  **/
    1549                 :          0 : u32 i40e_led_get(struct i40e_hw *hw)
    1550                 :            : {
    1551                 :            :         u32 mode = 0;
    1552                 :            :         int i;
    1553                 :            : 
    1554                 :            :         /* as per the documentation GPIO 22-29 are the LED
    1555                 :            :          * GPIO pins named LED0..LED7
    1556                 :            :          */
    1557         [ #  # ]:          0 :         for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
    1558                 :          0 :                 u32 gpio_val = i40e_led_is_mine(hw, i);
    1559                 :            : 
    1560         [ #  # ]:          0 :                 if (!gpio_val)
    1561                 :            :                         continue;
    1562                 :            : 
    1563                 :          0 :                 mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
    1564                 :            :                         I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
    1565                 :          0 :                 break;
    1566                 :            :         }
    1567                 :            : 
    1568                 :          0 :         return mode;
    1569                 :            : }
    1570                 :            : 
    1571                 :            : /**
    1572                 :            :  * i40e_led_get_blink - return current LED blink setting
    1573                 :            :  * @hw: pointer to the hw struct
    1574                 :            :  *
    1575                 :            :  * The value returned is the LED_BLINK bit as defined in the
    1576                 :            :  * GPIO register definitions (0 = no blink, 1 = do blink).
    1577                 :            :  **/
    1578                 :          0 : bool i40e_led_get_blink(struct i40e_hw *hw)
    1579                 :            : {
    1580                 :            :         bool blink = 0;
    1581                 :            :         int i;
    1582                 :            : 
    1583                 :            :         /* as per the documentation GPIO 22-29 are the LED
    1584                 :            :          * GPIO pins named LED0..LED7
    1585                 :            :          */
    1586         [ #  # ]:          0 :         for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
    1587                 :          0 :                 u32 gpio_val = i40e_led_is_mine(hw, i);
    1588                 :            : 
    1589         [ #  # ]:          0 :                 if (!gpio_val)
    1590                 :            :                         continue;
    1591                 :            : 
    1592                 :          0 :                 blink = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_BLINK_MASK) >>
    1593                 :            :                         I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT;
    1594                 :          0 :                 break;
    1595                 :            :         }
    1596                 :            : 
    1597                 :          0 :         return blink;
    1598                 :            : }
    1599                 :            : 
    1600                 :            : /**
    1601                 :            :  * i40e_led_set - set new on/off mode
    1602                 :            :  * @hw: pointer to the hw struct
    1603                 :            :  * @mode: 0=off, 0xf=on (else see manual for mode details)
    1604                 :            :  * @blink: true if the LED should blink when on, false if steady
    1605                 :            :  *
    1606                 :            :  * if this function is used to turn on the blink it should
    1607                 :            :  * be used to disable the blink when restoring the original state.
    1608                 :            :  **/
    1609                 :          0 : void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
    1610                 :            : {
    1611                 :            :         int i;
    1612                 :            : 
    1613         [ #  # ]:          0 :         if (mode & ~I40E_LED_MODE_VALID) {
    1614                 :          0 :                 DEBUGOUT1("invalid mode passed in %X\n", mode);
    1615                 :          0 :                 return;
    1616                 :            :         }
    1617                 :            : 
    1618                 :            :         /* as per the documentation GPIO 22-29 are the LED
    1619                 :            :          * GPIO pins named LED0..LED7
    1620                 :            :          */
    1621         [ #  # ]:          0 :         for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
    1622                 :          0 :                 u32 gpio_val = i40e_led_is_mine(hw, i);
    1623                 :            : 
    1624         [ #  # ]:          0 :                 if (!gpio_val)
    1625                 :            :                         continue;
    1626                 :            : 
    1627   [ #  #  #  # ]:          0 :                 if (I40E_IS_X710TL_DEVICE(hw->device_id)) {
    1628                 :            :                         u32 pin_func = 0;
    1629                 :            : 
    1630         [ #  # ]:          0 :                         if (mode & I40E_FW_LED)
    1631                 :            :                                 pin_func = I40E_PIN_FUNC_SDP;
    1632                 :            :                         else
    1633                 :            :                                 pin_func = I40E_PIN_FUNC_LED;
    1634                 :            : 
    1635                 :          0 :                         gpio_val &= ~I40E_GLGEN_GPIO_CTL_PIN_FUNC_MASK;
    1636                 :          0 :                         gpio_val |= ((pin_func <<
    1637                 :            :                                      I40E_GLGEN_GPIO_CTL_PIN_FUNC_SHIFT) &
    1638                 :            :                                      I40E_GLGEN_GPIO_CTL_PIN_FUNC_MASK);
    1639                 :            :                 }
    1640                 :          0 :                 gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
    1641                 :            :                 /* this & is a bit of paranoia, but serves as a range check */
    1642                 :          0 :                 gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
    1643                 :            :                              I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
    1644                 :            : 
    1645         [ #  # ]:          0 :                 if (blink)
    1646                 :          0 :                         gpio_val |= BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
    1647                 :            :                 else
    1648                 :          0 :                         gpio_val &= ~BIT(I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
    1649                 :            : 
    1650                 :          0 :                 wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
    1651                 :            :                 break;
    1652                 :            :         }
    1653                 :            : }
    1654                 :            : 
    1655                 :            : /* Admin command wrappers */
    1656                 :            : 
    1657                 :            : /**
    1658                 :            :  * i40e_aq_get_phy_capabilities
    1659                 :            :  * @hw: pointer to the hw struct
    1660                 :            :  * @abilities: structure for PHY capabilities to be filled
    1661                 :            :  * @qualified_modules: report Qualified Modules
    1662                 :            :  * @report_init: report init capabilities (active are default)
    1663                 :            :  * @cmd_details: pointer to command details structure or NULL
    1664                 :            :  *
    1665                 :            :  * Returns the various PHY abilities supported on the Port.
    1666                 :            :  **/
    1667                 :          0 : enum i40e_status_code i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
    1668                 :            :                         bool qualified_modules, bool report_init,
    1669                 :            :                         struct i40e_aq_get_phy_abilities_resp *abilities,
    1670                 :            :                         struct i40e_asq_cmd_details *cmd_details)
    1671                 :            : {
    1672                 :            :         struct i40e_aq_desc desc;
    1673                 :            :         enum i40e_status_code status;
    1674                 :            :         u16 max_delay = I40E_MAX_PHY_TIMEOUT, total_delay = 0;
    1675                 :            :         u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
    1676                 :            : 
    1677         [ #  # ]:          0 :         if (!abilities)
    1678                 :            :                 return I40E_ERR_PARAM;
    1679                 :            : 
    1680                 :            :         do {
    1681                 :          0 :                 i40e_fill_default_direct_cmd_desc(&desc,
    1682                 :            :                                                i40e_aqc_opc_get_phy_abilities);
    1683                 :            : 
    1684                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    1685                 :            :                 if (abilities_size > I40E_AQ_LARGE_BUF)
    1686                 :          0 :                         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    1687                 :            : 
    1688         [ #  # ]:          0 :                 if (qualified_modules)
    1689                 :          0 :                         desc.params.external.param0 |=
    1690                 :            :                         CPU_TO_LE32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
    1691                 :            : 
    1692         [ #  # ]:          0 :                 if (report_init)
    1693                 :          0 :                         desc.params.external.param0 |=
    1694                 :            :                         CPU_TO_LE32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
    1695                 :            : 
    1696                 :          0 :                 status = i40e_asq_send_command(hw, &desc, abilities,
    1697                 :            :                                                abilities_size, cmd_details);
    1698                 :            : 
    1699      [ #  #  # ]:          0 :                 switch (hw->aq.asq_last_status) {
    1700                 :          0 :                 case I40E_AQ_RC_EIO:
    1701                 :            :                         status = I40E_ERR_UNKNOWN_PHY;
    1702                 :          0 :                         break;
    1703                 :          0 :                 case I40E_AQ_RC_EAGAIN:
    1704                 :          0 :                         i40e_msec_delay(1);
    1705                 :          0 :                         total_delay++;
    1706                 :            :                         status = I40E_ERR_TIMEOUT;
    1707                 :          0 :                         break;
    1708                 :            :                 /* also covers I40E_AQ_RC_OK */
    1709                 :            :                 default:
    1710                 :            :                         break;
    1711                 :            :                 }
    1712                 :            : 
    1713   [ #  #  #  # ]:          0 :         } while ((hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN) &&
    1714                 :            :                 (total_delay < max_delay));
    1715                 :            : 
    1716         [ #  # ]:          0 :         if (status != I40E_SUCCESS)
    1717                 :            :                 return status;
    1718                 :            : 
    1719         [ #  # ]:          0 :         if (report_init) {
    1720         [ #  # ]:          0 :                 if (hw->mac.type ==  I40E_MAC_XL710 &&
    1721         [ #  # ]:          0 :                     hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
    1722         [ #  # ]:          0 :                     hw->aq.api_min_ver >= I40E_MINOR_VER_GET_LINK_INFO_XL710) {
    1723                 :          0 :                         status = i40e_aq_get_link_info(hw, true, NULL, NULL);
    1724                 :            :                 } else {
    1725                 :          0 :                         hw->phy.phy_types = LE32_TO_CPU(abilities->phy_type);
    1726                 :          0 :                         hw->phy.phy_types |=
    1727                 :          0 :                                         ((u64)abilities->phy_type_ext << 32);
    1728                 :            :                 }
    1729                 :            :         }
    1730                 :            : 
    1731                 :            :         return status;
    1732                 :            : }
    1733                 :            : 
    1734                 :            : /**
    1735                 :            :  * i40e_aq_set_phy_config
    1736                 :            :  * @hw: pointer to the hw struct
    1737                 :            :  * @config: structure with PHY configuration to be set
    1738                 :            :  * @cmd_details: pointer to command details structure or NULL
    1739                 :            :  *
    1740                 :            :  * Set the various PHY configuration parameters
    1741                 :            :  * supported on the Port.One or more of the Set PHY config parameters may be
    1742                 :            :  * ignored in an MFP mode as the PF may not have the privilege to set some
    1743                 :            :  * of the PHY Config parameters. This status will be indicated by the
    1744                 :            :  * command response.
    1745                 :            :  **/
    1746                 :          0 : enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
    1747                 :            :                                 struct i40e_aq_set_phy_config *config,
    1748                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    1749                 :            : {
    1750                 :            :         struct i40e_aq_desc desc;
    1751                 :            :         struct i40e_aq_set_phy_config *cmd =
    1752                 :            :                 (struct i40e_aq_set_phy_config *)&desc.params.raw;
    1753                 :            :         enum i40e_status_code status;
    1754                 :            : 
    1755         [ #  # ]:          0 :         if (!config)
    1756                 :            :                 return I40E_ERR_PARAM;
    1757                 :            : 
    1758                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    1759                 :            :                                           i40e_aqc_opc_set_phy_config);
    1760                 :            : 
    1761                 :          0 :         *cmd = *config;
    1762                 :            : 
    1763                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    1764                 :            : 
    1765                 :          0 :         return status;
    1766                 :            : }
    1767                 :            : 
    1768                 :            : /**
    1769                 :            :  * i40e_set_fc
    1770                 :            :  * @hw: pointer to the hw struct
    1771                 :            :  * @aq_failures: buffer to return AdminQ failure information
    1772                 :            :  * @atomic_restart: whether to enable atomic link restart
    1773                 :            :  *
    1774                 :            :  * Set the requested flow control mode using set_phy_config.
    1775                 :            :  **/
    1776                 :          0 : enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
    1777                 :            :                                   bool atomic_restart)
    1778                 :            : {
    1779                 :          0 :         enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
    1780                 :            :         struct i40e_aq_get_phy_abilities_resp abilities;
    1781                 :            :         struct i40e_aq_set_phy_config config;
    1782                 :            :         enum i40e_status_code status;
    1783                 :            :         u8 pause_mask = 0x0;
    1784                 :            : 
    1785         [ #  # ]:          0 :         *aq_failures = 0x0;
    1786                 :            : 
    1787                 :            :         switch (fc_mode) {
    1788                 :            :         case I40E_FC_FULL:
    1789                 :            :                 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
    1790                 :            :                 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
    1791                 :            :                 break;
    1792                 :            :         case I40E_FC_RX_PAUSE:
    1793                 :            :                 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
    1794                 :            :                 break;
    1795                 :            :         case I40E_FC_TX_PAUSE:
    1796                 :            :                 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
    1797                 :            :                 break;
    1798                 :            :         default:
    1799                 :            :                 break;
    1800                 :            :         }
    1801                 :            : 
    1802                 :            :         /* Get the current phy config */
    1803                 :          0 :         status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
    1804                 :            :                                               NULL);
    1805         [ #  # ]:          0 :         if (status) {
    1806                 :          0 :                 *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
    1807                 :          0 :                 return status;
    1808                 :            :         }
    1809                 :            : 
    1810                 :            :         memset(&config, 0, sizeof(config));
    1811                 :            :         /* clear the old pause settings */
    1812                 :          0 :         config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
    1813                 :            :                            ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
    1814                 :            :         /* set the new abilities */
    1815                 :          0 :         config.abilities |= pause_mask;
    1816                 :            :         /* If the abilities have changed, then set the new config */
    1817         [ #  # ]:          0 :         if (config.abilities != abilities.abilities) {
    1818                 :            :                 /* Auto restart link so settings take effect */
    1819         [ #  # ]:          0 :                 if (atomic_restart)
    1820                 :          0 :                         config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
    1821                 :            :                 /* Copy over all the old settings */
    1822                 :          0 :                 config.phy_type = abilities.phy_type;
    1823                 :          0 :                 config.phy_type_ext = abilities.phy_type_ext;
    1824                 :          0 :                 config.link_speed = abilities.link_speed;
    1825                 :          0 :                 config.eee_capability = abilities.eee_capability;
    1826                 :          0 :                 config.eeer = abilities.eeer_val;
    1827                 :          0 :                 config.low_power_ctrl = abilities.d3_lpan;
    1828                 :          0 :                 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
    1829                 :            :                                     I40E_AQ_PHY_FEC_CONFIG_MASK;
    1830                 :          0 :                 status = i40e_aq_set_phy_config(hw, &config, NULL);
    1831                 :            : 
    1832         [ #  # ]:          0 :                 if (status)
    1833                 :          0 :                         *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
    1834                 :            :         }
    1835                 :            :         /* Update the link info */
    1836                 :          0 :         status = i40e_update_link_info(hw);
    1837         [ #  # ]:          0 :         if (status) {
    1838                 :            :                 /* Wait a little bit (on 40G cards it sometimes takes a really
    1839                 :            :                  * long time for link to come back from the atomic reset)
    1840                 :            :                  * and try once more
    1841                 :            :                  */
    1842                 :          0 :                 i40e_msec_delay(1000);
    1843                 :          0 :                 status = i40e_update_link_info(hw);
    1844                 :            :         }
    1845         [ #  # ]:          0 :         if (status)
    1846                 :          0 :                 *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
    1847                 :            : 
    1848                 :            :         return status;
    1849                 :            : }
    1850                 :            : 
    1851                 :            : /**
    1852                 :            :  * i40e_aq_set_mac_config
    1853                 :            :  * @hw: pointer to the hw struct
    1854                 :            :  * @max_frame_size: Maximum Frame Size to be supported by the port
    1855                 :            :  * @crc_en: Tell HW to append a CRC to outgoing frames
    1856                 :            :  * @pacing: Pacing configurations
    1857                 :            :  * @auto_drop_blocking_packets: Tell HW to drop packets if TC queue is blocked
    1858                 :            :  * @cmd_details: pointer to command details structure or NULL
    1859                 :            :  *
    1860                 :            :  * Configure MAC settings for frame size, jumbo frame support and the
    1861                 :            :  * addition of a CRC by the hardware.
    1862                 :            :  **/
    1863                 :          0 : enum i40e_status_code i40e_aq_set_mac_config(struct i40e_hw *hw,
    1864                 :            :                                 u16 max_frame_size,
    1865                 :            :                                 bool crc_en, u16 pacing,
    1866                 :            :                                 bool auto_drop_blocking_packets,
    1867                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    1868                 :            : {
    1869                 :            :         struct i40e_aq_desc desc;
    1870                 :            :         struct i40e_aq_set_mac_config *cmd =
    1871                 :            :                 (struct i40e_aq_set_mac_config *)&desc.params.raw;
    1872                 :            :         enum i40e_status_code status;
    1873                 :            : 
    1874         [ #  # ]:          0 :         if (max_frame_size == 0)
    1875                 :            :                 return I40E_ERR_PARAM;
    1876                 :            : 
    1877                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    1878                 :            :                                           i40e_aqc_opc_set_mac_config);
    1879                 :            : 
    1880                 :          0 :         cmd->max_frame_size = CPU_TO_LE16(max_frame_size);
    1881                 :          0 :         cmd->params = ((u8)pacing & 0x0F) << 3;
    1882         [ #  # ]:          0 :         if (crc_en)
    1883                 :          0 :                 cmd->params |= I40E_AQ_SET_MAC_CONFIG_CRC_EN;
    1884                 :            : 
    1885         [ #  # ]:          0 :         if (auto_drop_blocking_packets) {
    1886         [ #  # ]:          0 :                 if (hw->flags & I40E_HW_FLAG_DROP_MODE)
    1887                 :          0 :                         cmd->params |=
    1888                 :            :                                 I40E_AQ_SET_MAC_CONFIG_DROP_BLOCKING_PACKET_EN;
    1889                 :            :                 else
    1890         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_ALL,
    1891                 :            :                                    "This FW api version does not support drop mode.\n");
    1892                 :            :         }
    1893                 :            : 
    1894                 :            : #define I40E_AQ_SET_MAC_CONFIG_FC_DEFAULT_THRESHOLD     0x7FFF
    1895                 :          0 :         cmd->fc_refresh_threshold =
    1896                 :            :                 CPU_TO_LE16(I40E_AQ_SET_MAC_CONFIG_FC_DEFAULT_THRESHOLD);
    1897                 :            : 
    1898                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    1899                 :            : 
    1900                 :          0 :         return status;
    1901                 :            : }
    1902                 :            : 
    1903                 :            : /**
    1904                 :            :  * i40e_aq_clear_pxe_mode
    1905                 :            :  * @hw: pointer to the hw struct
    1906                 :            :  * @cmd_details: pointer to command details structure or NULL
    1907                 :            :  *
    1908                 :            :  * Tell the firmware that the driver is taking over from PXE
    1909                 :            :  **/
    1910                 :          0 : enum i40e_status_code i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
    1911                 :            :                         struct i40e_asq_cmd_details *cmd_details)
    1912                 :            : {
    1913                 :            :         enum i40e_status_code status;
    1914                 :            :         struct i40e_aq_desc desc;
    1915                 :            :         struct i40e_aqc_clear_pxe *cmd =
    1916                 :            :                 (struct i40e_aqc_clear_pxe *)&desc.params.raw;
    1917                 :            : 
    1918                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    1919                 :            :                                           i40e_aqc_opc_clear_pxe_mode);
    1920                 :            : 
    1921                 :          0 :         cmd->rx_cnt = 0x2;
    1922                 :            : 
    1923                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    1924                 :            : 
    1925                 :          0 :         wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
    1926                 :            : 
    1927                 :          0 :         return status;
    1928                 :            : }
    1929                 :            : 
    1930                 :            : /**
    1931                 :            :  * i40e_aq_set_link_restart_an
    1932                 :            :  * @hw: pointer to the hw struct
    1933                 :            :  * @enable_link: if true: enable link, if false: disable link
    1934                 :            :  * @cmd_details: pointer to command details structure or NULL
    1935                 :            :  *
    1936                 :            :  * Sets up the link and restarts the Auto-Negotiation over the link.
    1937                 :            :  **/
    1938                 :          0 : enum i40e_status_code i40e_aq_set_link_restart_an(struct i40e_hw *hw,
    1939                 :            :                 bool enable_link, struct i40e_asq_cmd_details *cmd_details)
    1940                 :            : {
    1941                 :            :         struct i40e_aq_desc desc;
    1942                 :            :         struct i40e_aqc_set_link_restart_an *cmd =
    1943                 :            :                 (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
    1944                 :            :         enum i40e_status_code status;
    1945                 :            : 
    1946                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    1947                 :            :                                           i40e_aqc_opc_set_link_restart_an);
    1948                 :            : 
    1949                 :          0 :         cmd->command = I40E_AQ_PHY_RESTART_AN;
    1950         [ #  # ]:          0 :         if (enable_link)
    1951                 :          0 :                 cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
    1952                 :            :         else
    1953                 :            :                 cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
    1954                 :            : 
    1955                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    1956                 :            : 
    1957                 :          0 :         return status;
    1958                 :            : }
    1959                 :            : 
    1960                 :            : /**
    1961                 :            :  * i40e_aq_get_link_info
    1962                 :            :  * @hw: pointer to the hw struct
    1963                 :            :  * @enable_lse: enable/disable LinkStatusEvent reporting
    1964                 :            :  * @link: pointer to link status structure - optional
    1965                 :            :  * @cmd_details: pointer to command details structure or NULL
    1966                 :            :  *
    1967                 :            :  * Returns the link status of the adapter.
    1968                 :            :  **/
    1969                 :          0 : enum i40e_status_code i40e_aq_get_link_info(struct i40e_hw *hw,
    1970                 :            :                                 bool enable_lse, struct i40e_link_status *link,
    1971                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    1972                 :            : {
    1973                 :            :         struct i40e_aq_desc desc;
    1974                 :            :         struct i40e_aqc_get_link_status *resp =
    1975                 :            :                 (struct i40e_aqc_get_link_status *)&desc.params.raw;
    1976                 :          0 :         struct i40e_link_status *hw_link_info = &hw->phy.link_info;
    1977                 :            :         enum i40e_status_code status;
    1978                 :            :         bool tx_pause, rx_pause;
    1979                 :            :         u16 command_flags;
    1980                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
    1981                 :            : 
    1982         [ #  # ]:          0 :         if (enable_lse)
    1983                 :            :                 command_flags = I40E_AQ_LSE_ENABLE;
    1984                 :            :         else
    1985                 :            :                 command_flags = I40E_AQ_LSE_DISABLE;
    1986                 :          0 :         resp->command_flags = CPU_TO_LE16(command_flags);
    1987                 :            : 
    1988                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    1989                 :            : 
    1990         [ #  # ]:          0 :         if (status != I40E_SUCCESS)
    1991                 :          0 :                 goto aq_get_link_info_exit;
    1992                 :            : 
    1993                 :            :         /* save off old link status information */
    1994         [ #  # ]:          0 :         i40e_memcpy(&hw->phy.link_info_old, hw_link_info,
    1995                 :            :                     sizeof(*hw_link_info), I40E_NONDMA_TO_NONDMA);
    1996                 :            : 
    1997                 :            :         /* update link status */
    1998         [ #  # ]:          0 :         hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
    1999                 :          0 :         hw->phy.media_type = i40e_get_media_type(hw);
    2000                 :          0 :         hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
    2001                 :          0 :         hw_link_info->link_info = resp->link_info;
    2002                 :          0 :         hw_link_info->an_info = resp->an_info;
    2003                 :          0 :         hw_link_info->fec_info = resp->config & (I40E_AQ_CONFIG_FEC_KR_ENA |
    2004                 :            :                                                  I40E_AQ_CONFIG_FEC_RS_ENA);
    2005                 :          0 :         hw_link_info->ext_info = resp->ext_info;
    2006                 :          0 :         hw_link_info->loopback = resp->loopback & I40E_AQ_LOOPBACK_MASK;
    2007                 :          0 :         hw_link_info->max_frame_size = LE16_TO_CPU(resp->max_frame_size);
    2008                 :          0 :         hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
    2009                 :            : 
    2010                 :            :         /* update fc info */
    2011                 :          0 :         tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
    2012                 :          0 :         rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
    2013         [ #  # ]:          0 :         if (tx_pause & rx_pause)
    2014                 :          0 :                 hw->fc.current_mode = I40E_FC_FULL;
    2015         [ #  # ]:          0 :         else if (tx_pause)
    2016                 :          0 :                 hw->fc.current_mode = I40E_FC_TX_PAUSE;
    2017         [ #  # ]:          0 :         else if (rx_pause)
    2018                 :          0 :                 hw->fc.current_mode = I40E_FC_RX_PAUSE;
    2019                 :            :         else
    2020                 :          0 :                 hw->fc.current_mode = I40E_FC_NONE;
    2021                 :            : 
    2022         [ #  # ]:          0 :         if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
    2023                 :          0 :                 hw_link_info->crc_enable = true;
    2024                 :            :         else
    2025                 :          0 :                 hw_link_info->crc_enable = false;
    2026                 :            : 
    2027         [ #  # ]:          0 :         if (resp->command_flags & CPU_TO_LE16(I40E_AQ_LSE_IS_ENABLED))
    2028                 :          0 :                 hw_link_info->lse_enable = true;
    2029                 :            :         else
    2030                 :          0 :                 hw_link_info->lse_enable = false;
    2031                 :            : 
    2032         [ #  # ]:          0 :         if ((hw->mac.type == I40E_MAC_XL710) &&
    2033   [ #  #  #  # ]:          0 :             (hw->aq.fw_maj_ver < 4 || (hw->aq.fw_maj_ver == 4 &&
    2034   [ #  #  #  # ]:          0 :              hw->aq.fw_min_ver < 40)) && hw_link_info->phy_type == 0xE)
    2035                 :          0 :                 hw_link_info->phy_type = I40E_PHY_TYPE_10GBASE_SFPP_CU;
    2036                 :            : 
    2037                 :            :         /* 'Get Link Status' response data structure from X722 FW has
    2038                 :            :          * different format and does not contain this information
    2039                 :            :          */
    2040   [ #  #  #  # ]:          0 :         if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE &&
    2041                 :            :             hw->mac.type != I40E_MAC_X722) {
    2042                 :            :                 __le32 tmp;
    2043                 :            : 
    2044                 :            :                 i40e_memcpy(&tmp, resp->link_type, sizeof(tmp),
    2045                 :            :                             I40E_NONDMA_TO_NONDMA);
    2046                 :          0 :                 hw->phy.phy_types = LE32_TO_CPU(tmp);
    2047                 :          0 :                 hw->phy.phy_types |= ((u64)resp->link_type_ext << 32);
    2048                 :            :         }
    2049                 :            : 
    2050                 :            :         /* save link status information */
    2051         [ #  # ]:          0 :         if (link)
    2052                 :            :                 i40e_memcpy(link, hw_link_info, sizeof(*hw_link_info),
    2053                 :            :                             I40E_NONDMA_TO_NONDMA);
    2054                 :            : 
    2055                 :            :         /* flag cleared so helper functions don't call AQ again */
    2056                 :          0 :         hw->phy.get_link_info = false;
    2057                 :            : 
    2058                 :          0 : aq_get_link_info_exit:
    2059                 :          0 :         return status;
    2060                 :            : }
    2061                 :            : 
    2062                 :            : /**
    2063                 :            :  * i40e_aq_set_phy_int_mask
    2064                 :            :  * @hw: pointer to the hw struct
    2065                 :            :  * @mask: interrupt mask to be set
    2066                 :            :  * @cmd_details: pointer to command details structure or NULL
    2067                 :            :  *
    2068                 :            :  * Set link interrupt mask.
    2069                 :            :  **/
    2070                 :          0 : enum i40e_status_code i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
    2071                 :            :                                 u16 mask,
    2072                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2073                 :            : {
    2074                 :            :         struct i40e_aq_desc desc;
    2075                 :            :         struct i40e_aqc_set_phy_int_mask *cmd =
    2076                 :            :                 (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
    2077                 :            :         enum i40e_status_code status;
    2078                 :            : 
    2079                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2080                 :            :                                           i40e_aqc_opc_set_phy_int_mask);
    2081                 :            : 
    2082                 :          0 :         cmd->event_mask = CPU_TO_LE16(mask);
    2083                 :            : 
    2084                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2085                 :            : 
    2086                 :          0 :         return status;
    2087                 :            : }
    2088                 :            : 
    2089                 :            : /**
    2090                 :            :  * i40e_aq_get_local_advt_reg
    2091                 :            :  * @hw: pointer to the hw struct
    2092                 :            :  * @advt_reg: local AN advertisement register value
    2093                 :            :  * @cmd_details: pointer to command details structure or NULL
    2094                 :            :  *
    2095                 :            :  * Get the Local AN advertisement register value.
    2096                 :            :  **/
    2097                 :          0 : enum i40e_status_code i40e_aq_get_local_advt_reg(struct i40e_hw *hw,
    2098                 :            :                                 u64 *advt_reg,
    2099                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2100                 :            : {
    2101                 :            :         struct i40e_aq_desc desc;
    2102                 :            :         struct i40e_aqc_an_advt_reg *resp =
    2103                 :            :                 (struct i40e_aqc_an_advt_reg *)&desc.params.raw;
    2104                 :            :         enum i40e_status_code status;
    2105                 :            : 
    2106                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2107                 :            :                                           i40e_aqc_opc_get_local_advt_reg);
    2108                 :            : 
    2109                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2110                 :            : 
    2111         [ #  # ]:          0 :         if (status != I40E_SUCCESS)
    2112                 :          0 :                 goto aq_get_local_advt_reg_exit;
    2113                 :            : 
    2114                 :          0 :         *advt_reg = (u64)(LE16_TO_CPU(resp->local_an_reg1)) << 32;
    2115                 :          0 :         *advt_reg |= LE32_TO_CPU(resp->local_an_reg0);
    2116                 :            : 
    2117                 :          0 : aq_get_local_advt_reg_exit:
    2118                 :          0 :         return status;
    2119                 :            : }
    2120                 :            : 
    2121                 :            : /**
    2122                 :            :  * i40e_aq_set_local_advt_reg
    2123                 :            :  * @hw: pointer to the hw struct
    2124                 :            :  * @advt_reg: local AN advertisement register value
    2125                 :            :  * @cmd_details: pointer to command details structure or NULL
    2126                 :            :  *
    2127                 :            :  * Get the Local AN advertisement register value.
    2128                 :            :  **/
    2129                 :          0 : enum i40e_status_code i40e_aq_set_local_advt_reg(struct i40e_hw *hw,
    2130                 :            :                                 u64 advt_reg,
    2131                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2132                 :            : {
    2133                 :            :         struct i40e_aq_desc desc;
    2134                 :            :         struct i40e_aqc_an_advt_reg *cmd =
    2135                 :            :                 (struct i40e_aqc_an_advt_reg *)&desc.params.raw;
    2136                 :            :         enum i40e_status_code status;
    2137                 :            : 
    2138                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2139                 :            :                                           i40e_aqc_opc_get_local_advt_reg);
    2140                 :            : 
    2141                 :          0 :         cmd->local_an_reg0 = CPU_TO_LE32(I40E_LO_DWORD(advt_reg));
    2142                 :          0 :         cmd->local_an_reg1 = CPU_TO_LE16(I40E_HI_DWORD(advt_reg));
    2143                 :            : 
    2144                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2145                 :            : 
    2146                 :          0 :         return status;
    2147                 :            : }
    2148                 :            : 
    2149                 :            : /**
    2150                 :            :  * i40e_aq_get_partner_advt
    2151                 :            :  * @hw: pointer to the hw struct
    2152                 :            :  * @advt_reg: AN partner advertisement register value
    2153                 :            :  * @cmd_details: pointer to command details structure or NULL
    2154                 :            :  *
    2155                 :            :  * Get the link partner AN advertisement register value.
    2156                 :            :  **/
    2157                 :          0 : enum i40e_status_code i40e_aq_get_partner_advt(struct i40e_hw *hw,
    2158                 :            :                                 u64 *advt_reg,
    2159                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2160                 :            : {
    2161                 :            :         struct i40e_aq_desc desc;
    2162                 :            :         struct i40e_aqc_an_advt_reg *resp =
    2163                 :            :                 (struct i40e_aqc_an_advt_reg *)&desc.params.raw;
    2164                 :            :         enum i40e_status_code status;
    2165                 :            : 
    2166                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2167                 :            :                                           i40e_aqc_opc_get_partner_advt);
    2168                 :            : 
    2169                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2170                 :            : 
    2171         [ #  # ]:          0 :         if (status != I40E_SUCCESS)
    2172                 :          0 :                 goto aq_get_partner_advt_exit;
    2173                 :            : 
    2174                 :          0 :         *advt_reg = (u64)(LE16_TO_CPU(resp->local_an_reg1)) << 32;
    2175                 :          0 :         *advt_reg |= LE32_TO_CPU(resp->local_an_reg0);
    2176                 :            : 
    2177                 :          0 : aq_get_partner_advt_exit:
    2178                 :          0 :         return status;
    2179                 :            : }
    2180                 :            : 
    2181                 :            : /**
    2182                 :            :  * i40e_aq_set_lb_modes
    2183                 :            :  * @hw: pointer to the hw struct
    2184                 :            :  * @lb_modes: loopback mode to be set
    2185                 :            :  * @cmd_details: pointer to command details structure or NULL
    2186                 :            :  *
    2187                 :            :  * Sets loopback modes.
    2188                 :            :  **/
    2189                 :          0 : enum i40e_status_code i40e_aq_set_lb_modes(struct i40e_hw *hw,
    2190                 :            :                                 u16 lb_modes,
    2191                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2192                 :            : {
    2193                 :            :         struct i40e_aq_desc desc;
    2194                 :            :         struct i40e_aqc_set_lb_mode *cmd =
    2195                 :            :                 (struct i40e_aqc_set_lb_mode *)&desc.params.raw;
    2196                 :            :         enum i40e_status_code status;
    2197                 :            : 
    2198                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2199                 :            :                                           i40e_aqc_opc_set_lb_modes);
    2200                 :            : 
    2201                 :          0 :         cmd->lb_mode = CPU_TO_LE16(lb_modes);
    2202                 :            : 
    2203                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2204                 :            : 
    2205                 :          0 :         return status;
    2206                 :            : }
    2207                 :            : 
    2208                 :            : /**
    2209                 :            :  * i40e_aq_set_phy_debug
    2210                 :            :  * @hw: pointer to the hw struct
    2211                 :            :  * @cmd_flags: debug command flags
    2212                 :            :  * @cmd_details: pointer to command details structure or NULL
    2213                 :            :  *
    2214                 :            :  * Reset the external PHY.
    2215                 :            :  **/
    2216                 :          0 : enum i40e_status_code i40e_aq_set_phy_debug(struct i40e_hw *hw, u8 cmd_flags,
    2217                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2218                 :            : {
    2219                 :            :         struct i40e_aq_desc desc;
    2220                 :            :         struct i40e_aqc_set_phy_debug *cmd =
    2221                 :            :                 (struct i40e_aqc_set_phy_debug *)&desc.params.raw;
    2222                 :            :         enum i40e_status_code status;
    2223                 :            : 
    2224                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2225                 :            :                                           i40e_aqc_opc_set_phy_debug);
    2226                 :            : 
    2227                 :          0 :         cmd->command_flags = cmd_flags;
    2228                 :            : 
    2229                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2230                 :            : 
    2231                 :          0 :         return status;
    2232                 :            : }
    2233                 :            : 
    2234                 :            : /**
    2235                 :            :  * i40e_hw_ver_ge
    2236                 :            :  * @hw: pointer to the hw struct
    2237                 :            :  * @maj: api major value
    2238                 :            :  * @min: api minor value
    2239                 :            :  *
    2240                 :            :  * Assert whether current HW api version is greater/equal than provided.
    2241                 :            :  **/
    2242                 :            : static bool i40e_hw_ver_ge(struct i40e_hw *hw, u16 maj, u16 min)
    2243                 :            : {
    2244   [ #  #  #  #  :          0 :         if (hw->aq.api_maj_ver > maj ||
          #  #  #  #  #  
                #  #  # ]
    2245   [ #  #  #  #  :          0 :             (hw->aq.api_maj_ver == maj && hw->aq.api_min_ver >= min))
             #  #  #  # ]
    2246                 :            :                 return true;
    2247                 :            :         return false;
    2248                 :            : }
    2249                 :            : 
    2250                 :            : /**
    2251                 :            :  * i40e_aq_add_vsi
    2252                 :            :  * @hw: pointer to the hw struct
    2253                 :            :  * @vsi_ctx: pointer to a vsi context struct
    2254                 :            :  * @cmd_details: pointer to command details structure or NULL
    2255                 :            :  *
    2256                 :            :  * Add a VSI context to the hardware.
    2257                 :            : **/
    2258                 :          0 : enum i40e_status_code i40e_aq_add_vsi(struct i40e_hw *hw,
    2259                 :            :                                 struct i40e_vsi_context *vsi_ctx,
    2260                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2261                 :            : {
    2262                 :            :         struct i40e_aq_desc desc;
    2263                 :            :         struct i40e_aqc_add_get_update_vsi *cmd =
    2264                 :            :                 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
    2265                 :            :         struct i40e_aqc_add_get_update_vsi_completion *resp =
    2266                 :            :                 (struct i40e_aqc_add_get_update_vsi_completion *)
    2267                 :            :                 &desc.params.raw;
    2268                 :            :         enum i40e_status_code status;
    2269                 :            : 
    2270                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2271                 :            :                                           i40e_aqc_opc_add_vsi);
    2272                 :            : 
    2273                 :          0 :         cmd->uplink_seid = CPU_TO_LE16(vsi_ctx->uplink_seid);
    2274                 :          0 :         cmd->connection_type = vsi_ctx->connection_type;
    2275                 :          0 :         cmd->vf_id = vsi_ctx->vf_num;
    2276                 :          0 :         cmd->vsi_flags = CPU_TO_LE16(vsi_ctx->flags);
    2277                 :            : 
    2278                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    2279                 :            : 
    2280                 :          0 :         status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
    2281                 :            :                                        sizeof(vsi_ctx->info), cmd_details);
    2282                 :            : 
    2283         [ #  # ]:          0 :         if (status != I40E_SUCCESS)
    2284                 :          0 :                 goto aq_add_vsi_exit;
    2285                 :            : 
    2286                 :          0 :         vsi_ctx->seid = LE16_TO_CPU(resp->seid);
    2287                 :          0 :         vsi_ctx->vsi_number = LE16_TO_CPU(resp->vsi_number);
    2288                 :          0 :         vsi_ctx->vsis_allocated = LE16_TO_CPU(resp->vsi_used);
    2289                 :          0 :         vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
    2290                 :            : 
    2291                 :          0 : aq_add_vsi_exit:
    2292                 :          0 :         return status;
    2293                 :            : }
    2294                 :            : 
    2295                 :            : /**
    2296                 :            :  * i40e_aq_set_default_vsi
    2297                 :            :  * @hw: pointer to the hw struct
    2298                 :            :  * @seid: vsi number
    2299                 :            :  * @cmd_details: pointer to command details structure or NULL
    2300                 :            :  **/
    2301                 :          0 : enum i40e_status_code i40e_aq_set_default_vsi(struct i40e_hw *hw,
    2302                 :            :                                 u16 seid,
    2303                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2304                 :            : {
    2305                 :            :         struct i40e_aq_desc desc;
    2306                 :            :         struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
    2307                 :            :                 (struct i40e_aqc_set_vsi_promiscuous_modes *)
    2308                 :            :                 &desc.params.raw;
    2309                 :            :         enum i40e_status_code status;
    2310                 :            : 
    2311                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2312                 :            :                                         i40e_aqc_opc_set_vsi_promiscuous_modes);
    2313                 :            : 
    2314                 :          0 :         cmd->promiscuous_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_DEFAULT);
    2315                 :          0 :         cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_DEFAULT);
    2316                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    2317                 :            : 
    2318                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2319                 :            : 
    2320                 :          0 :         return status;
    2321                 :            : }
    2322                 :            : 
    2323                 :            : /**
    2324                 :            :  * i40e_aq_clear_default_vsi
    2325                 :            :  * @hw: pointer to the hw struct
    2326                 :            :  * @seid: vsi number
    2327                 :            :  * @cmd_details: pointer to command details structure or NULL
    2328                 :            :  **/
    2329                 :          0 : enum i40e_status_code i40e_aq_clear_default_vsi(struct i40e_hw *hw,
    2330                 :            :                                 u16 seid,
    2331                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2332                 :            : {
    2333                 :            :         struct i40e_aq_desc desc;
    2334                 :            :         struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
    2335                 :            :                 (struct i40e_aqc_set_vsi_promiscuous_modes *)
    2336                 :            :                 &desc.params.raw;
    2337                 :            :         enum i40e_status_code status;
    2338                 :            : 
    2339                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2340                 :            :                                         i40e_aqc_opc_set_vsi_promiscuous_modes);
    2341                 :            : 
    2342                 :          0 :         cmd->promiscuous_flags = CPU_TO_LE16(0);
    2343                 :          0 :         cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_DEFAULT);
    2344                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    2345                 :            : 
    2346                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2347                 :            : 
    2348                 :          0 :         return status;
    2349                 :            : }
    2350                 :            : 
    2351                 :            : /**
    2352                 :            :  * i40e_aq_set_vsi_unicast_promiscuous
    2353                 :            :  * @hw: pointer to the hw struct
    2354                 :            :  * @seid: vsi number
    2355                 :            :  * @set: set unicast promiscuous enable/disable
    2356                 :            :  * @cmd_details: pointer to command details structure or NULL
    2357                 :            :  * @rx_only_promisc: flag to decide if egress traffic gets mirrored in promisc
    2358                 :            :  **/
    2359                 :          0 : enum i40e_status_code i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
    2360                 :            :                                 u16 seid, bool set,
    2361                 :            :                                 struct i40e_asq_cmd_details *cmd_details,
    2362                 :            :                                 bool rx_only_promisc)
    2363                 :            : {
    2364                 :            :         struct i40e_aq_desc desc;
    2365                 :            :         struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
    2366                 :            :                 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
    2367                 :            :         enum i40e_status_code status;
    2368                 :            :         u16 flags = 0;
    2369                 :            : 
    2370                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2371                 :            :                                         i40e_aqc_opc_set_vsi_promiscuous_modes);
    2372                 :            : 
    2373         [ #  # ]:          0 :         if (set) {
    2374                 :            :                 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
    2375         [ #  # ]:          0 :                 if (rx_only_promisc && i40e_hw_ver_ge(hw, 1, 5))
    2376                 :            :                         flags |= I40E_AQC_SET_VSI_PROMISC_RX_ONLY;
    2377                 :            :         }
    2378                 :            : 
    2379                 :          0 :         cmd->promiscuous_flags = CPU_TO_LE16(flags);
    2380                 :            : 
    2381         [ #  # ]:          0 :         cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
    2382                 :            :         if (i40e_hw_ver_ge(hw, 1, 5))
    2383                 :          0 :                 cmd->valid_flags |=
    2384                 :            :                         CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_RX_ONLY);
    2385                 :            : 
    2386                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    2387                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2388                 :            : 
    2389                 :          0 :         return status;
    2390                 :            : }
    2391                 :            : 
    2392                 :            : /**
    2393                 :            :  * i40e_aq_set_vsi_multicast_promiscuous
    2394                 :            :  * @hw: pointer to the hw struct
    2395                 :            :  * @seid: vsi number
    2396                 :            :  * @set: set multicast promiscuous enable/disable
    2397                 :            :  * @cmd_details: pointer to command details structure or NULL
    2398                 :            :  **/
    2399                 :          0 : enum i40e_status_code i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
    2400                 :            :                                 u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
    2401                 :            : {
    2402                 :            :         struct i40e_aq_desc desc;
    2403                 :            :         struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
    2404                 :            :                 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
    2405                 :            :         enum i40e_status_code status;
    2406                 :            :         u16 flags = 0;
    2407                 :            : 
    2408                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2409                 :            :                                         i40e_aqc_opc_set_vsi_promiscuous_modes);
    2410                 :            : 
    2411         [ #  # ]:          0 :         if (set)
    2412                 :            :                 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
    2413                 :            : 
    2414                 :          0 :         cmd->promiscuous_flags = CPU_TO_LE16(flags);
    2415                 :            : 
    2416                 :          0 :         cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
    2417                 :            : 
    2418                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    2419                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2420                 :            : 
    2421                 :          0 :         return status;
    2422                 :            : }
    2423                 :            : 
    2424                 :            : /**
    2425                 :            : * i40e_aq_set_vsi_full_promiscuous
    2426                 :            : * @hw: pointer to the hw struct
    2427                 :            : * @seid: VSI number
    2428                 :            : * @set: set promiscuous enable/disable
    2429                 :            : * @cmd_details: pointer to command details structure or NULL
    2430                 :            : **/
    2431                 :          0 : enum i40e_status_code i40e_aq_set_vsi_full_promiscuous(struct i40e_hw *hw,
    2432                 :            :                                 u16 seid, bool set,
    2433                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2434                 :            : {
    2435                 :            :         struct i40e_aq_desc desc;
    2436                 :            :         struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
    2437                 :            :                 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
    2438                 :            :         enum i40e_status_code status;
    2439                 :            :         u16 flags = 0;
    2440                 :            : 
    2441                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2442                 :            :                 i40e_aqc_opc_set_vsi_promiscuous_modes);
    2443                 :            : 
    2444         [ #  # ]:          0 :         if (set)
    2445                 :            :                 flags = I40E_AQC_SET_VSI_PROMISC_UNICAST   |
    2446                 :            :                         I40E_AQC_SET_VSI_PROMISC_MULTICAST |
    2447                 :            :                         I40E_AQC_SET_VSI_PROMISC_BROADCAST;
    2448                 :            : 
    2449                 :          0 :         cmd->promiscuous_flags = CPU_TO_LE16(flags);
    2450                 :            : 
    2451                 :          0 :         cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_UNICAST   |
    2452                 :            :                                        I40E_AQC_SET_VSI_PROMISC_MULTICAST |
    2453                 :            :                                        I40E_AQC_SET_VSI_PROMISC_BROADCAST);
    2454                 :            : 
    2455                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    2456                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2457                 :            : 
    2458                 :          0 :         return status;
    2459                 :            : }
    2460                 :            : 
    2461                 :            : /**
    2462                 :            :  * i40e_aq_set_vsi_mc_promisc_on_vlan
    2463                 :            :  * @hw: pointer to the hw struct
    2464                 :            :  * @seid: vsi number
    2465                 :            :  * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
    2466                 :            :  * @vid: The VLAN tag filter - capture any multicast packet with this VLAN tag
    2467                 :            :  * @cmd_details: pointer to command details structure or NULL
    2468                 :            :  **/
    2469                 :          0 : enum i40e_status_code i40e_aq_set_vsi_mc_promisc_on_vlan(struct i40e_hw *hw,
    2470                 :            :                                 u16 seid, bool enable, u16 vid,
    2471                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2472                 :            : {
    2473                 :            :         struct i40e_aq_desc desc;
    2474                 :            :         struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
    2475                 :            :                 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
    2476                 :            :         enum i40e_status_code status;
    2477                 :            :         u16 flags = 0;
    2478                 :            : 
    2479                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2480                 :            :                                         i40e_aqc_opc_set_vsi_promiscuous_modes);
    2481                 :            : 
    2482         [ #  # ]:          0 :         if (enable)
    2483                 :            :                 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
    2484                 :            : 
    2485                 :          0 :         cmd->promiscuous_flags = CPU_TO_LE16(flags);
    2486                 :          0 :         cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
    2487                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    2488                 :          0 :         cmd->vlan_tag = CPU_TO_LE16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
    2489                 :            : 
    2490                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2491                 :            : 
    2492                 :          0 :         return status;
    2493                 :            : }
    2494                 :            : 
    2495                 :            : /**
    2496                 :            :  * i40e_aq_set_vsi_uc_promisc_on_vlan
    2497                 :            :  * @hw: pointer to the hw struct
    2498                 :            :  * @seid: vsi number
    2499                 :            :  * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
    2500                 :            :  * @vid: The VLAN tag filter - capture any unicast packet with this VLAN tag
    2501                 :            :  * @cmd_details: pointer to command details structure or NULL
    2502                 :            :  **/
    2503                 :          0 : enum i40e_status_code i40e_aq_set_vsi_uc_promisc_on_vlan(struct i40e_hw *hw,
    2504                 :            :                                 u16 seid, bool enable, u16 vid,
    2505                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2506                 :            : {
    2507                 :            :         struct i40e_aq_desc desc;
    2508                 :            :         struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
    2509                 :            :                 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
    2510                 :            :         enum i40e_status_code status;
    2511                 :            :         u16 flags = 0;
    2512                 :            : 
    2513                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2514                 :            :                                         i40e_aqc_opc_set_vsi_promiscuous_modes);
    2515                 :            : 
    2516         [ #  # ]:          0 :         if (enable) {
    2517                 :            :                 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
    2518                 :            :                 if (i40e_hw_ver_ge(hw, 1, 5))
    2519                 :            :                         flags |= I40E_AQC_SET_VSI_PROMISC_RX_ONLY;
    2520                 :            :         }
    2521                 :            : 
    2522                 :          0 :         cmd->promiscuous_flags = CPU_TO_LE16(flags);
    2523         [ #  # ]:          0 :         cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
    2524                 :            :         if (i40e_hw_ver_ge(hw, 1, 5))
    2525                 :          0 :                 cmd->valid_flags |=
    2526                 :            :                         CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_RX_ONLY);
    2527                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    2528                 :          0 :         cmd->vlan_tag = CPU_TO_LE16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
    2529                 :            : 
    2530                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2531                 :            : 
    2532                 :          0 :         return status;
    2533                 :            : }
    2534                 :            : 
    2535                 :            : /**
    2536                 :            :  * i40e_aq_set_vsi_bc_promisc_on_vlan
    2537                 :            :  * @hw: pointer to the hw struct
    2538                 :            :  * @seid: vsi number
    2539                 :            :  * @enable: set broadcast promiscuous enable/disable for a given VLAN
    2540                 :            :  * @vid: The VLAN tag filter - capture any broadcast packet with this VLAN tag
    2541                 :            :  * @cmd_details: pointer to command details structure or NULL
    2542                 :            :  **/
    2543                 :          0 : enum i40e_status_code i40e_aq_set_vsi_bc_promisc_on_vlan(struct i40e_hw *hw,
    2544                 :            :                                 u16 seid, bool enable, u16 vid,
    2545                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2546                 :            : {
    2547                 :            :         struct i40e_aq_desc desc;
    2548                 :            :         struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
    2549                 :            :                 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
    2550                 :            :         enum i40e_status_code status;
    2551                 :            :         u16 flags = 0;
    2552                 :            : 
    2553                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2554                 :            :                                         i40e_aqc_opc_set_vsi_promiscuous_modes);
    2555                 :            : 
    2556         [ #  # ]:          0 :         if (enable)
    2557                 :            :                 flags |= I40E_AQC_SET_VSI_PROMISC_BROADCAST;
    2558                 :            : 
    2559                 :          0 :         cmd->promiscuous_flags = CPU_TO_LE16(flags);
    2560                 :          0 :         cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
    2561                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    2562                 :          0 :         cmd->vlan_tag = CPU_TO_LE16(vid | I40E_AQC_SET_VSI_VLAN_VALID);
    2563                 :            : 
    2564                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2565                 :            : 
    2566                 :          0 :         return status;
    2567                 :            : }
    2568                 :            : 
    2569                 :            : /**
    2570                 :            :  * i40e_aq_set_vsi_broadcast
    2571                 :            :  * @hw: pointer to the hw struct
    2572                 :            :  * @seid: vsi number
    2573                 :            :  * @set_filter: true to set filter, false to clear filter
    2574                 :            :  * @cmd_details: pointer to command details structure or NULL
    2575                 :            :  *
    2576                 :            :  * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
    2577                 :            :  **/
    2578                 :          0 : enum i40e_status_code i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
    2579                 :            :                                 u16 seid, bool set_filter,
    2580                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2581                 :            : {
    2582                 :            :         struct i40e_aq_desc desc;
    2583                 :            :         struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
    2584                 :            :                 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
    2585                 :            :         enum i40e_status_code status;
    2586                 :            : 
    2587                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2588                 :            :                                         i40e_aqc_opc_set_vsi_promiscuous_modes);
    2589                 :            : 
    2590         [ #  # ]:          0 :         if (set_filter)
    2591                 :            :                 cmd->promiscuous_flags
    2592                 :          0 :                             |= CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
    2593                 :            :         else
    2594                 :            :                 cmd->promiscuous_flags
    2595                 :          0 :                             &= CPU_TO_LE16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
    2596                 :            : 
    2597                 :          0 :         cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
    2598                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    2599                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2600                 :            : 
    2601                 :          0 :         return status;
    2602                 :            : }
    2603                 :            : 
    2604                 :            : /**
    2605                 :            :  * i40e_aq_set_vsi_vlan_promisc - control the VLAN promiscuous setting
    2606                 :            :  * @hw: pointer to the hw struct
    2607                 :            :  * @seid: vsi number
    2608                 :            :  * @enable: set MAC L2 layer unicast promiscuous enable/disable for a given VLAN
    2609                 :            :  * @cmd_details: pointer to command details structure or NULL
    2610                 :            :  **/
    2611                 :          0 : enum i40e_status_code i40e_aq_set_vsi_vlan_promisc(struct i40e_hw *hw,
    2612                 :            :                                 u16 seid, bool enable,
    2613                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2614                 :            : {
    2615                 :            :         struct i40e_aq_desc desc;
    2616                 :            :         struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
    2617                 :            :                 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
    2618                 :            :         enum i40e_status_code status;
    2619                 :            :         u16 flags = 0;
    2620                 :            : 
    2621                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2622                 :            :                                         i40e_aqc_opc_set_vsi_promiscuous_modes);
    2623         [ #  # ]:          0 :         if (enable)
    2624                 :            :                 flags |= I40E_AQC_SET_VSI_PROMISC_VLAN;
    2625                 :            : 
    2626                 :          0 :         cmd->promiscuous_flags = CPU_TO_LE16(flags);
    2627                 :          0 :         cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_VLAN);
    2628                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    2629                 :            : 
    2630                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2631                 :            : 
    2632                 :          0 :         return status;
    2633                 :            : }
    2634                 :            : 
    2635                 :            : /**
    2636                 :            :  * i40e_aq_get_vsi_params - get VSI configuration info
    2637                 :            :  * @hw: pointer to the hw struct
    2638                 :            :  * @vsi_ctx: pointer to a vsi context struct
    2639                 :            :  * @cmd_details: pointer to command details structure or NULL
    2640                 :            :  **/
    2641                 :          0 : enum i40e_status_code i40e_aq_get_vsi_params(struct i40e_hw *hw,
    2642                 :            :                                 struct i40e_vsi_context *vsi_ctx,
    2643                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2644                 :            : {
    2645                 :            :         struct i40e_aq_desc desc;
    2646                 :            :         struct i40e_aqc_add_get_update_vsi *cmd =
    2647                 :            :                 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
    2648                 :            :         struct i40e_aqc_add_get_update_vsi_completion *resp =
    2649                 :            :                 (struct i40e_aqc_add_get_update_vsi_completion *)
    2650                 :            :                 &desc.params.raw;
    2651                 :            :         enum i40e_status_code status;
    2652                 :            : 
    2653                 :            :         UNREFERENCED_1PARAMETER(cmd_details);
    2654                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2655                 :            :                                           i40e_aqc_opc_get_vsi_parameters);
    2656                 :            : 
    2657                 :          0 :         cmd->uplink_seid = CPU_TO_LE16(vsi_ctx->seid);
    2658                 :            : 
    2659                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    2660                 :            : 
    2661                 :          0 :         status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
    2662                 :            :                                     sizeof(vsi_ctx->info), NULL);
    2663                 :            : 
    2664         [ #  # ]:          0 :         if (status != I40E_SUCCESS)
    2665                 :          0 :                 goto aq_get_vsi_params_exit;
    2666                 :            : 
    2667                 :          0 :         vsi_ctx->seid = LE16_TO_CPU(resp->seid);
    2668                 :          0 :         vsi_ctx->vsi_number = LE16_TO_CPU(resp->vsi_number);
    2669                 :          0 :         vsi_ctx->vsis_allocated = LE16_TO_CPU(resp->vsi_used);
    2670                 :          0 :         vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
    2671                 :            : 
    2672                 :          0 : aq_get_vsi_params_exit:
    2673                 :          0 :         return status;
    2674                 :            : }
    2675                 :            : 
    2676                 :            : /**
    2677                 :            :  * i40e_aq_update_vsi_params
    2678                 :            :  * @hw: pointer to the hw struct
    2679                 :            :  * @vsi_ctx: pointer to a vsi context struct
    2680                 :            :  * @cmd_details: pointer to command details structure or NULL
    2681                 :            :  *
    2682                 :            :  * Update a VSI context.
    2683                 :            :  **/
    2684                 :          0 : enum i40e_status_code i40e_aq_update_vsi_params(struct i40e_hw *hw,
    2685                 :            :                                 struct i40e_vsi_context *vsi_ctx,
    2686                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2687                 :            : {
    2688                 :            :         struct i40e_aq_desc desc;
    2689                 :            :         struct i40e_aqc_add_get_update_vsi *cmd =
    2690                 :            :                 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
    2691                 :            :         struct i40e_aqc_add_get_update_vsi_completion *resp =
    2692                 :            :                 (struct i40e_aqc_add_get_update_vsi_completion *)
    2693                 :            :                 &desc.params.raw;
    2694                 :            :         enum i40e_status_code status;
    2695                 :            : 
    2696                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2697                 :            :                                           i40e_aqc_opc_update_vsi_parameters);
    2698                 :          0 :         cmd->uplink_seid = CPU_TO_LE16(vsi_ctx->seid);
    2699                 :            : 
    2700                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    2701                 :            : 
    2702                 :          0 :         status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
    2703                 :            :                                        sizeof(vsi_ctx->info), cmd_details);
    2704                 :            : 
    2705                 :          0 :         vsi_ctx->vsis_allocated = LE16_TO_CPU(resp->vsi_used);
    2706                 :          0 :         vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
    2707                 :            : 
    2708                 :          0 :         return status;
    2709                 :            : }
    2710                 :            : 
    2711                 :            : /**
    2712                 :            :  * i40e_aq_get_switch_config
    2713                 :            :  * @hw: pointer to the hardware structure
    2714                 :            :  * @buf: pointer to the result buffer
    2715                 :            :  * @buf_size: length of input buffer
    2716                 :            :  * @start_seid: seid to start for the report, 0 == beginning
    2717                 :            :  * @cmd_details: pointer to command details structure or NULL
    2718                 :            :  *
    2719                 :            :  * Fill the buf with switch configuration returned from AdminQ command
    2720                 :            :  **/
    2721                 :          0 : enum i40e_status_code i40e_aq_get_switch_config(struct i40e_hw *hw,
    2722                 :            :                                 struct i40e_aqc_get_switch_config_resp *buf,
    2723                 :            :                                 u16 buf_size, u16 *start_seid,
    2724                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2725                 :            : {
    2726                 :            :         struct i40e_aq_desc desc;
    2727                 :            :         struct i40e_aqc_switch_seid *scfg =
    2728                 :            :                 (struct i40e_aqc_switch_seid *)&desc.params.raw;
    2729                 :            :         enum i40e_status_code status;
    2730                 :            : 
    2731                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2732                 :            :                                           i40e_aqc_opc_get_switch_config);
    2733                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    2734         [ #  # ]:          0 :         if (buf_size > I40E_AQ_LARGE_BUF)
    2735                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    2736                 :          0 :         scfg->seid = CPU_TO_LE16(*start_seid);
    2737                 :            : 
    2738                 :          0 :         status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
    2739                 :          0 :         *start_seid = LE16_TO_CPU(scfg->seid);
    2740                 :            : 
    2741                 :          0 :         return status;
    2742                 :            : }
    2743                 :            : 
    2744                 :            : /**
    2745                 :            :  * i40e_aq_set_switch_config
    2746                 :            :  * @hw: pointer to the hardware structure
    2747                 :            :  * @flags: bit flag values to set
    2748                 :            :  * @mode: cloud filter mode
    2749                 :            :  * @valid_flags: which bit flags to set
    2750                 :            :  * @cmd_details: pointer to command details structure or NULL
    2751                 :            :  *
    2752                 :            :  * Set switch configuration bits
    2753                 :            :  **/
    2754                 :          0 : enum i40e_status_code i40e_aq_set_switch_config(struct i40e_hw *hw,
    2755                 :            :                                 u16 flags, u16 valid_flags, u8 mode,
    2756                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2757                 :            : {
    2758                 :            :         struct i40e_aq_desc desc;
    2759                 :            :         struct i40e_aqc_set_switch_config *scfg =
    2760                 :            :                 (struct i40e_aqc_set_switch_config *)&desc.params.raw;
    2761                 :            :         enum i40e_status_code status;
    2762                 :            : 
    2763                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    2764                 :            :                                           i40e_aqc_opc_set_switch_config);
    2765                 :          0 :         scfg->flags = CPU_TO_LE16(flags);
    2766                 :          0 :         scfg->valid_flags = CPU_TO_LE16(valid_flags);
    2767                 :          0 :         scfg->mode = mode;
    2768         [ #  # ]:          0 :         if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
    2769                 :          0 :                 scfg->switch_tag = CPU_TO_LE16(hw->switch_tag);
    2770                 :          0 :                 scfg->first_tag = CPU_TO_LE16(hw->first_tag);
    2771                 :          0 :                 scfg->second_tag = CPU_TO_LE16(hw->second_tag);
    2772                 :            :         }
    2773                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2774                 :            : 
    2775                 :          0 :         return status;
    2776                 :            : }
    2777                 :            : 
    2778                 :            : /**
    2779                 :            :  * i40e_aq_get_firmware_version
    2780                 :            :  * @hw: pointer to the hw struct
    2781                 :            :  * @fw_major_version: firmware major version
    2782                 :            :  * @fw_minor_version: firmware minor version
    2783                 :            :  * @fw_build: firmware build number
    2784                 :            :  * @api_major_version: major queue version
    2785                 :            :  * @api_minor_version: minor queue version
    2786                 :            :  * @cmd_details: pointer to command details structure or NULL
    2787                 :            :  *
    2788                 :            :  * Get the firmware version from the admin queue commands
    2789                 :            :  **/
    2790                 :          0 : enum i40e_status_code i40e_aq_get_firmware_version(struct i40e_hw *hw,
    2791                 :            :                                 u16 *fw_major_version, u16 *fw_minor_version,
    2792                 :            :                                 u32 *fw_build,
    2793                 :            :                                 u16 *api_major_version, u16 *api_minor_version,
    2794                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2795                 :            : {
    2796                 :            :         struct i40e_aq_desc desc;
    2797                 :            :         struct i40e_aqc_get_version *resp =
    2798                 :            :                 (struct i40e_aqc_get_version *)&desc.params.raw;
    2799                 :            :         enum i40e_status_code status;
    2800                 :            : 
    2801                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
    2802                 :            : 
    2803                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    2804                 :            : 
    2805         [ #  # ]:          0 :         if (status == I40E_SUCCESS) {
    2806         [ #  # ]:          0 :                 if (fw_major_version != NULL)
    2807                 :          0 :                         *fw_major_version = LE16_TO_CPU(resp->fw_major);
    2808         [ #  # ]:          0 :                 if (fw_minor_version != NULL)
    2809                 :          0 :                         *fw_minor_version = LE16_TO_CPU(resp->fw_minor);
    2810         [ #  # ]:          0 :                 if (fw_build != NULL)
    2811                 :          0 :                         *fw_build = LE32_TO_CPU(resp->fw_build);
    2812         [ #  # ]:          0 :                 if (api_major_version != NULL)
    2813                 :          0 :                         *api_major_version = LE16_TO_CPU(resp->api_major);
    2814         [ #  # ]:          0 :                 if (api_minor_version != NULL)
    2815                 :          0 :                         *api_minor_version = LE16_TO_CPU(resp->api_minor);
    2816                 :            : 
    2817                 :            :                 /* A workaround to fix the API version in SW */
    2818         [ #  # ]:          0 :                 if (api_major_version && api_minor_version &&
    2819         [ #  # ]:          0 :                     fw_major_version && fw_minor_version &&
    2820   [ #  #  #  # ]:          0 :                     ((*api_major_version == 1) && (*api_minor_version == 1)) &&
    2821   [ #  #  #  #  :          0 :                     (((*fw_major_version == 4) && (*fw_minor_version >= 2)) ||
                   #  # ]
    2822                 :            :                      (*fw_major_version > 4)))
    2823                 :          0 :                         *api_minor_version = 2;
    2824                 :            :         }
    2825                 :            : 
    2826                 :          0 :         return status;
    2827                 :            : }
    2828                 :            : 
    2829                 :            : /**
    2830                 :            :  * i40e_aq_send_driver_version
    2831                 :            :  * @hw: pointer to the hw struct
    2832                 :            :  * @dv: driver's major, minor version
    2833                 :            :  * @cmd_details: pointer to command details structure or NULL
    2834                 :            :  *
    2835                 :            :  * Send the driver version to the firmware
    2836                 :            :  **/
    2837                 :          0 : enum i40e_status_code i40e_aq_send_driver_version(struct i40e_hw *hw,
    2838                 :            :                                 struct i40e_driver_version *dv,
    2839                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2840                 :            : {
    2841                 :            :         struct i40e_aq_desc desc;
    2842                 :            :         struct i40e_aqc_driver_version *cmd =
    2843                 :            :                 (struct i40e_aqc_driver_version *)&desc.params.raw;
    2844                 :            :         enum i40e_status_code status;
    2845                 :            :         u16 len;
    2846                 :            : 
    2847         [ #  # ]:          0 :         if (dv == NULL)
    2848                 :            :                 return I40E_ERR_PARAM;
    2849                 :            : 
    2850                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
    2851                 :            : 
    2852                 :          0 :         desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
    2853                 :          0 :         cmd->driver_major_ver = dv->major_version;
    2854                 :          0 :         cmd->driver_minor_ver = dv->minor_version;
    2855                 :          0 :         cmd->driver_build_ver = dv->build_version;
    2856                 :          0 :         cmd->driver_subbuild_ver = dv->subbuild_version;
    2857                 :            : 
    2858                 :            :         len = 0;
    2859                 :          0 :         while (len < sizeof(dv->driver_string) &&
    2860   [ #  #  #  #  :          0 :                (dv->driver_string[len] < 0x80) &&
                   #  # ]
    2861                 :            :                dv->driver_string[len])
    2862                 :          0 :                 len++;
    2863                 :          0 :         status = i40e_asq_send_command(hw, &desc, dv->driver_string,
    2864                 :            :                                        len, cmd_details);
    2865                 :            : 
    2866                 :          0 :         return status;
    2867                 :            : }
    2868                 :            : 
    2869                 :            : /**
    2870                 :            :  * i40e_get_link_status - get status of the HW network link
    2871                 :            :  * @hw: pointer to the hw struct
    2872                 :            :  * @link_up: pointer to bool (true/false = linkup/linkdown)
    2873                 :            :  *
    2874                 :            :  * Variable link_up true if link is up, false if link is down.
    2875                 :            :  * The variable link_up is invalid if returned value of status != I40E_SUCCESS
    2876                 :            :  *
    2877                 :            :  * Side effect: LinkStatusEvent reporting becomes enabled
    2878                 :            :  **/
    2879                 :          0 : enum i40e_status_code i40e_get_link_status(struct i40e_hw *hw, bool *link_up)
    2880                 :            : {
    2881                 :            :         enum i40e_status_code status = I40E_SUCCESS;
    2882                 :            : 
    2883         [ #  # ]:          0 :         if (hw->phy.get_link_info) {
    2884                 :          0 :                 status = i40e_update_link_info(hw);
    2885                 :            : 
    2886         [ #  # ]:          0 :                 if (status != I40E_SUCCESS)
    2887         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_LINK, "get link failed: status %d\n",
    2888                 :            :                                    status);
    2889                 :            :         }
    2890                 :            : 
    2891                 :          0 :         *link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
    2892                 :            : 
    2893                 :          0 :         return status;
    2894                 :            : }
    2895                 :            : 
    2896                 :            : /**
    2897                 :            :  * i40e_update_link_info - update status of the HW network link
    2898                 :            :  * @hw: pointer to the hw struct
    2899                 :            :  **/
    2900                 :          0 : enum i40e_status_code i40e_update_link_info(struct i40e_hw *hw)
    2901                 :            : {
    2902                 :            :         struct i40e_aq_get_phy_abilities_resp abilities;
    2903                 :            :         enum i40e_status_code status = I40E_SUCCESS;
    2904                 :            : 
    2905                 :          0 :         status = i40e_aq_get_link_info(hw, true, NULL, NULL);
    2906         [ #  # ]:          0 :         if (status)
    2907                 :            :                 return status;
    2908                 :            : 
    2909                 :            :         /* extra checking needed to ensure link info to user is timely */
    2910   [ #  #  #  # ]:          0 :         if (((hw->phy.link_info.link_info & I40E_AQ_MEDIA_AVAILABLE) &&
    2911                 :          0 :              ((hw->phy.link_info.link_info & I40E_AQ_LINK_UP) ||
    2912         [ #  # ]:          0 :               !(hw->phy.link_info_old.link_info & I40E_AQ_LINK_UP))) ||
    2913         [ #  # ]:          0 :             hw->mac.type == I40E_MAC_X722) {
    2914                 :          0 :                 status = i40e_aq_get_phy_capabilities(hw, false,
    2915                 :          0 :                                                       hw->mac.type ==
    2916                 :            :                                                       I40E_MAC_X722,
    2917                 :            :                                                       &abilities, NULL);
    2918         [ #  # ]:          0 :                 if (status)
    2919                 :            :                         return status;
    2920                 :            : 
    2921         [ #  # ]:          0 :                 if (abilities.fec_cfg_curr_mod_ext_info &
    2922                 :            :                     I40E_AQ_ENABLE_FEC_AUTO)
    2923                 :          0 :                         hw->phy.link_info.req_fec_info =
    2924                 :            :                                 (I40E_AQ_REQUEST_FEC_KR |
    2925                 :            :                                  I40E_AQ_REQUEST_FEC_RS);
    2926                 :            :                 else
    2927                 :          0 :                         hw->phy.link_info.req_fec_info =
    2928                 :          0 :                                 abilities.fec_cfg_curr_mod_ext_info &
    2929                 :            :                                 (I40E_AQ_REQUEST_FEC_KR |
    2930                 :            :                                  I40E_AQ_REQUEST_FEC_RS);
    2931                 :            : 
    2932         [ #  # ]:          0 :                 i40e_memcpy(hw->phy.link_info.module_type, &abilities.module_type,
    2933                 :            :                         sizeof(hw->phy.link_info.module_type), I40E_NONDMA_TO_NONDMA);
    2934                 :            :         }
    2935                 :            :         return status;
    2936                 :            : }
    2937                 :            : 
    2938                 :            : /**
    2939                 :            :  * i40e_get_link_speed
    2940                 :            :  * @hw: pointer to the hw struct
    2941                 :            :  *
    2942                 :            :  * Returns the link speed of the adapter.
    2943                 :            :  **/
    2944                 :          0 : enum i40e_aq_link_speed i40e_get_link_speed(struct i40e_hw *hw)
    2945                 :            : {
    2946                 :            :         enum i40e_aq_link_speed speed = I40E_LINK_SPEED_UNKNOWN;
    2947                 :            :         enum i40e_status_code status = I40E_SUCCESS;
    2948                 :            : 
    2949         [ #  # ]:          0 :         if (hw->phy.get_link_info) {
    2950                 :          0 :                 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
    2951                 :            : 
    2952         [ #  # ]:          0 :                 if (status != I40E_SUCCESS)
    2953                 :          0 :                         goto i40e_link_speed_exit;
    2954                 :            :         }
    2955                 :            : 
    2956                 :          0 :         speed = hw->phy.link_info.link_speed;
    2957                 :            : 
    2958                 :          0 : i40e_link_speed_exit:
    2959                 :          0 :         return speed;
    2960                 :            : }
    2961                 :            : 
    2962                 :            : /**
    2963                 :            :  * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
    2964                 :            :  * @hw: pointer to the hw struct
    2965                 :            :  * @uplink_seid: the MAC or other gizmo SEID
    2966                 :            :  * @downlink_seid: the VSI SEID
    2967                 :            :  * @enabled_tc: bitmap of TCs to be enabled
    2968                 :            :  * @default_port: true for default port VSI, false for control port
    2969                 :            :  * @veb_seid: pointer to where to put the resulting VEB SEID
    2970                 :            :  * @enable_stats: true to turn on VEB stats
    2971                 :            :  * @cmd_details: pointer to command details structure or NULL
    2972                 :            :  *
    2973                 :            :  * This asks the FW to add a VEB between the uplink and downlink
    2974                 :            :  * elements.  If the uplink SEID is 0, this will be a floating VEB.
    2975                 :            :  **/
    2976                 :          0 : enum i40e_status_code i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
    2977                 :            :                                 u16 downlink_seid, u8 enabled_tc,
    2978                 :            :                                 bool default_port, u16 *veb_seid,
    2979                 :            :                                 bool enable_stats,
    2980                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    2981                 :            : {
    2982                 :            :         struct i40e_aq_desc desc;
    2983                 :            :         struct i40e_aqc_add_veb *cmd =
    2984                 :            :                 (struct i40e_aqc_add_veb *)&desc.params.raw;
    2985                 :            :         struct i40e_aqc_add_veb_completion *resp =
    2986                 :            :                 (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
    2987                 :            :         enum i40e_status_code status;
    2988                 :            :         u16 veb_flags = 0;
    2989                 :            : 
    2990                 :            :         /* SEIDs need to either both be set or both be 0 for floating VEB */
    2991         [ #  # ]:          0 :         if (!!uplink_seid != !!downlink_seid)
    2992                 :            :                 return I40E_ERR_PARAM;
    2993                 :            : 
    2994                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
    2995                 :            : 
    2996                 :          0 :         cmd->uplink_seid = CPU_TO_LE16(uplink_seid);
    2997                 :          0 :         cmd->downlink_seid = CPU_TO_LE16(downlink_seid);
    2998                 :          0 :         cmd->enable_tcs = enabled_tc;
    2999         [ #  # ]:          0 :         if (!uplink_seid)
    3000                 :            :                 veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
    3001         [ #  # ]:          0 :         if (default_port)
    3002                 :          0 :                 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
    3003                 :            :         else
    3004                 :          0 :                 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
    3005                 :            : 
    3006                 :            :         /* reverse logic here: set the bitflag to disable the stats */
    3007         [ #  # ]:          0 :         if (!enable_stats)
    3008                 :          0 :                 veb_flags |= I40E_AQC_ADD_VEB_ENABLE_DISABLE_STATS;
    3009                 :            : 
    3010                 :          0 :         cmd->veb_flags = CPU_TO_LE16(veb_flags);
    3011                 :            : 
    3012                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    3013                 :            : 
    3014         [ #  # ]:          0 :         if (!status && veb_seid)
    3015                 :          0 :                 *veb_seid = LE16_TO_CPU(resp->veb_seid);
    3016                 :            : 
    3017                 :            :         return status;
    3018                 :            : }
    3019                 :            : 
    3020                 :            : /**
    3021                 :            :  * i40e_aq_get_veb_parameters - Retrieve VEB parameters
    3022                 :            :  * @hw: pointer to the hw struct
    3023                 :            :  * @veb_seid: the SEID of the VEB to query
    3024                 :            :  * @switch_id: the uplink switch id
    3025                 :            :  * @floating: set to true if the VEB is floating
    3026                 :            :  * @statistic_index: index of the stats counter block for this VEB
    3027                 :            :  * @vebs_used: number of VEB's used by function
    3028                 :            :  * @vebs_free: total VEB's not reserved by any function
    3029                 :            :  * @cmd_details: pointer to command details structure or NULL
    3030                 :            :  *
    3031                 :            :  * This retrieves the parameters for a particular VEB, specified by
    3032                 :            :  * uplink_seid, and returns them to the caller.
    3033                 :            :  **/
    3034                 :          0 : enum i40e_status_code i40e_aq_get_veb_parameters(struct i40e_hw *hw,
    3035                 :            :                                 u16 veb_seid, u16 *switch_id,
    3036                 :            :                                 bool *floating, u16 *statistic_index,
    3037                 :            :                                 u16 *vebs_used, u16 *vebs_free,
    3038                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    3039                 :            : {
    3040                 :            :         struct i40e_aq_desc desc;
    3041                 :            :         struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
    3042                 :            :                 (struct i40e_aqc_get_veb_parameters_completion *)
    3043                 :            :                 &desc.params.raw;
    3044                 :            :         enum i40e_status_code status;
    3045                 :            : 
    3046         [ #  # ]:          0 :         if (veb_seid == 0)
    3047                 :            :                 return I40E_ERR_PARAM;
    3048                 :            : 
    3049                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    3050                 :            :                                           i40e_aqc_opc_get_veb_parameters);
    3051                 :          0 :         cmd_resp->seid = CPU_TO_LE16(veb_seid);
    3052                 :            : 
    3053                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    3054         [ #  # ]:          0 :         if (status)
    3055                 :          0 :                 goto get_veb_exit;
    3056                 :            : 
    3057         [ #  # ]:          0 :         if (switch_id)
    3058                 :          0 :                 *switch_id = LE16_TO_CPU(cmd_resp->switch_id);
    3059         [ #  # ]:          0 :         if (statistic_index)
    3060                 :          0 :                 *statistic_index = LE16_TO_CPU(cmd_resp->statistic_index);
    3061         [ #  # ]:          0 :         if (vebs_used)
    3062                 :          0 :                 *vebs_used = LE16_TO_CPU(cmd_resp->vebs_used);
    3063         [ #  # ]:          0 :         if (vebs_free)
    3064                 :          0 :                 *vebs_free = LE16_TO_CPU(cmd_resp->vebs_free);
    3065         [ #  # ]:          0 :         if (floating) {
    3066                 :          0 :                 u16 flags = LE16_TO_CPU(cmd_resp->veb_flags);
    3067                 :            : 
    3068         [ #  # ]:          0 :                 if (flags & I40E_AQC_ADD_VEB_FLOATING)
    3069                 :          0 :                         *floating = true;
    3070                 :            :                 else
    3071                 :          0 :                         *floating = false;
    3072                 :            :         }
    3073                 :            : 
    3074                 :          0 : get_veb_exit:
    3075                 :            :         return status;
    3076                 :            : }
    3077                 :            : 
    3078                 :            : /**
    3079                 :            :  * i40e_prepare_add_macvlan
    3080                 :            :  * @mv_list: list of macvlans to be added
    3081                 :            :  * @desc: pointer to AQ descriptor structure
    3082                 :            :  * @count: length of the list
    3083                 :            :  * @seid: VSI for the mac address
    3084                 :            :  *
    3085                 :            :  * Internal helper function that prepares the add macvlan request
    3086                 :            :  * and returns the buffer size.
    3087                 :            :  **/
    3088                 :            : static u16
    3089                 :          0 : i40e_prepare_add_macvlan(struct i40e_aqc_add_macvlan_element_data *mv_list,
    3090                 :            :                          struct i40e_aq_desc *desc, u16 count, u16 seid)
    3091                 :            : {
    3092                 :            :         struct i40e_aqc_macvlan *cmd =
    3093                 :            :                 (struct i40e_aqc_macvlan *)&desc->params.raw;
    3094                 :            :         u16 buf_size;
    3095                 :            :         int i;
    3096                 :            : 
    3097                 :          0 :         buf_size = count * sizeof(*mv_list);
    3098                 :            : 
    3099                 :            :         /* prep the rest of the request */
    3100                 :          0 :         i40e_fill_default_direct_cmd_desc(desc, i40e_aqc_opc_add_macvlan);
    3101                 :          0 :         cmd->num_addresses = CPU_TO_LE16(count);
    3102                 :          0 :         cmd->seid[0] = CPU_TO_LE16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
    3103                 :          0 :         cmd->seid[1] = 0;
    3104                 :          0 :         cmd->seid[2] = 0;
    3105                 :            : 
    3106         [ #  # ]:          0 :         for (i = 0; i < count; i++)
    3107         [ #  # ]:          0 :                 if (I40E_IS_MULTICAST(mv_list[i].mac_addr))
    3108                 :          0 :                         mv_list[i].flags |=
    3109                 :            :                             CPU_TO_LE16(I40E_AQC_MACVLAN_ADD_USE_SHARED_MAC);
    3110                 :            : 
    3111                 :          0 :         desc->flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    3112         [ #  # ]:          0 :         if (buf_size > I40E_AQ_LARGE_BUF)
    3113                 :          0 :                 desc->flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    3114                 :            : 
    3115                 :          0 :         return buf_size;
    3116                 :            : }
    3117                 :            : 
    3118                 :            : /**
    3119                 :            :  * i40e_aq_add_macvlan
    3120                 :            :  * @hw: pointer to the hw struct
    3121                 :            :  * @seid: VSI for the mac address
    3122                 :            :  * @mv_list: list of macvlans to be added
    3123                 :            :  * @count: length of the list
    3124                 :            :  * @cmd_details: pointer to command details structure or NULL
    3125                 :            :  *
    3126                 :            :  * Add MAC/VLAN addresses to the HW filtering
    3127                 :            :  **/
    3128                 :            : enum i40e_status_code
    3129                 :          0 : i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
    3130                 :            :                     struct i40e_aqc_add_macvlan_element_data *mv_list,
    3131                 :            :                     u16 count, struct i40e_asq_cmd_details *cmd_details)
    3132                 :            : {
    3133                 :            :         struct i40e_aq_desc desc;
    3134                 :            :         enum i40e_status_code status;
    3135                 :            :         u16 buf_size;
    3136                 :            : 
    3137   [ #  #  #  # ]:          0 :         if (count == 0 || !mv_list || !hw)
    3138                 :            :                 return I40E_ERR_PARAM;
    3139                 :            : 
    3140                 :          0 :         buf_size = i40e_prepare_add_macvlan(mv_list, &desc, count, seid);
    3141                 :            : 
    3142                 :          0 :         status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
    3143                 :            :                                        cmd_details);
    3144                 :            : 
    3145                 :          0 :         return status;
    3146                 :            : }
    3147                 :            : 
    3148                 :            : /**
    3149                 :            :  * i40e_aq_add_macvlan_v2
    3150                 :            :  * @hw: pointer to the hw struct
    3151                 :            :  * @seid: VSI for the mac address
    3152                 :            :  * @mv_list: list of macvlans to be added
    3153                 :            :  * @count: length of the list
    3154                 :            :  * @cmd_details: pointer to command details structure or NULL
    3155                 :            :  * @aq_status: pointer to Admin Queue status return value
    3156                 :            :  *
    3157                 :            :  * Add MAC/VLAN addresses to the HW filtering.
    3158                 :            :  * The _v2 version returns the last Admin Queue status in aq_status
    3159                 :            :  * to avoid race conditions in access to hw->aq.asq_last_status.
    3160                 :            :  * It also calls _v2 versions of asq_send_command functions to
    3161                 :            :  * get the aq_status on the stack.
    3162                 :            :  **/
    3163                 :            : enum i40e_status_code
    3164                 :          0 : i40e_aq_add_macvlan_v2(struct i40e_hw *hw, u16 seid,
    3165                 :            :                        struct i40e_aqc_add_macvlan_element_data *mv_list,
    3166                 :            :                        u16 count, struct i40e_asq_cmd_details *cmd_details,
    3167                 :            :                        enum i40e_admin_queue_err *aq_status)
    3168                 :            : {
    3169                 :            :         struct i40e_aq_desc desc;
    3170                 :            :         enum i40e_status_code status;
    3171                 :            :         u16 buf_size;
    3172                 :            : 
    3173   [ #  #  #  # ]:          0 :         if (count == 0 || !mv_list || !hw)
    3174                 :            :                 return I40E_ERR_PARAM;
    3175                 :            : 
    3176                 :          0 :         buf_size = i40e_prepare_add_macvlan(mv_list, &desc, count, seid);
    3177                 :            : 
    3178                 :          0 :         status = i40e_asq_send_command_v2(hw, &desc, mv_list, buf_size,
    3179                 :            :                                           cmd_details, aq_status);
    3180                 :            : 
    3181                 :          0 :         return status;
    3182                 :            : }
    3183                 :            : 
    3184                 :            : /**
    3185                 :            :  * i40e_aq_remove_macvlan
    3186                 :            :  * @hw: pointer to the hw struct
    3187                 :            :  * @seid: VSI for the mac address
    3188                 :            :  * @mv_list: list of macvlans to be removed
    3189                 :            :  * @count: length of the list
    3190                 :            :  * @cmd_details: pointer to command details structure or NULL
    3191                 :            :  *
    3192                 :            :  * Remove MAC/VLAN addresses from the HW filtering
    3193                 :            :  **/
    3194                 :          0 : enum i40e_status_code i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
    3195                 :            :                         struct i40e_aqc_remove_macvlan_element_data *mv_list,
    3196                 :            :                         u16 count, struct i40e_asq_cmd_details *cmd_details)
    3197                 :            : {
    3198                 :            :         struct i40e_aq_desc desc;
    3199                 :            :         struct i40e_aqc_macvlan *cmd =
    3200                 :            :                 (struct i40e_aqc_macvlan *)&desc.params.raw;
    3201                 :            :         enum i40e_status_code status;
    3202                 :            :         u16 buf_size;
    3203                 :            : 
    3204   [ #  #  #  # ]:          0 :         if (count == 0 || !mv_list || !hw)
    3205                 :            :                 return I40E_ERR_PARAM;
    3206                 :            : 
    3207                 :          0 :         buf_size = count * sizeof(*mv_list);
    3208                 :            : 
    3209                 :            :         /* prep the rest of the request */
    3210                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
    3211                 :          0 :         cmd->num_addresses = CPU_TO_LE16(count);
    3212                 :          0 :         cmd->seid[0] = CPU_TO_LE16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
    3213                 :          0 :         cmd->seid[1] = 0;
    3214                 :          0 :         cmd->seid[2] = 0;
    3215                 :            : 
    3216                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    3217         [ #  # ]:          0 :         if (buf_size > I40E_AQ_LARGE_BUF)
    3218                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    3219                 :            : 
    3220                 :          0 :         status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
    3221                 :            :                                        cmd_details);
    3222                 :            : 
    3223                 :          0 :         return status;
    3224                 :            : }
    3225                 :            : 
    3226                 :            : /**
    3227                 :            :  * i40e_aq_remove_macvlan_v2
    3228                 :            :  * @hw: pointer to the hw struct
    3229                 :            :  * @seid: VSI for the mac address
    3230                 :            :  * @mv_list: list of macvlans to be removed
    3231                 :            :  * @count: length of the list
    3232                 :            :  * @cmd_details: pointer to command details structure or NULL
    3233                 :            :  * @aq_status: pointer to Admin Queue status return value
    3234                 :            :  *
    3235                 :            :  * Remove MAC/VLAN addresses from the HW filtering.
    3236                 :            :  * The _v2 version returns the last Admin Queue status in aq_status
    3237                 :            :  * to avoid race conditions in access to hw->aq.asq_last_status.
    3238                 :            :  * It also calls _v2 versions of asq_send_command functions to
    3239                 :            :  * get the aq_status on the stack.
    3240                 :            :  **/
    3241                 :            : enum i40e_status_code
    3242                 :          0 : i40e_aq_remove_macvlan_v2(struct i40e_hw *hw, u16 seid,
    3243                 :            :                           struct i40e_aqc_remove_macvlan_element_data *mv_list,
    3244                 :            :                           u16 count, struct i40e_asq_cmd_details *cmd_details,
    3245                 :            :                           enum i40e_admin_queue_err *aq_status)
    3246                 :            : {
    3247                 :            :         struct i40e_aq_desc desc;
    3248                 :            :         struct i40e_aqc_macvlan *cmd =
    3249                 :            :                 (struct i40e_aqc_macvlan *)&desc.params.raw;
    3250                 :            :         enum i40e_status_code status;
    3251                 :            :         u16 buf_size;
    3252                 :            : 
    3253   [ #  #  #  # ]:          0 :         if (count == 0 || !mv_list || !hw)
    3254                 :            :                 return I40E_ERR_PARAM;
    3255                 :            : 
    3256                 :          0 :         buf_size = count * sizeof(*mv_list);
    3257                 :            : 
    3258                 :            :         /* prep the rest of the request */
    3259                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
    3260                 :          0 :         cmd->num_addresses = CPU_TO_LE16(count);
    3261                 :          0 :         cmd->seid[0] = CPU_TO_LE16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
    3262                 :          0 :         cmd->seid[1] = 0;
    3263                 :          0 :         cmd->seid[2] = 0;
    3264                 :            : 
    3265                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    3266         [ #  # ]:          0 :         if (buf_size > I40E_AQ_LARGE_BUF)
    3267                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    3268                 :            : 
    3269                 :          0 :         status = i40e_asq_send_command_v2(hw, &desc, mv_list, buf_size,
    3270                 :            :                                           cmd_details, aq_status);
    3271                 :            : 
    3272                 :          0 :         return status;
    3273                 :            : }
    3274                 :            : 
    3275                 :            : /**
    3276                 :            :  * i40e_mirrorrule_op - Internal helper function to add/delete mirror rule
    3277                 :            :  * @hw: pointer to the hw struct
    3278                 :            :  * @opcode: AQ opcode for add or delete mirror rule
    3279                 :            :  * @sw_seid: Switch SEID (to which rule refers)
    3280                 :            :  * @rule_type: Rule Type (ingress/egress/VLAN)
    3281                 :            :  * @id: Destination VSI SEID or Rule ID
    3282                 :            :  * @count: length of the list
    3283                 :            :  * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
    3284                 :            :  * @cmd_details: pointer to command details structure or NULL
    3285                 :            :  * @rule_id: Rule ID returned from FW
    3286                 :            :  * @rules_used: Number of rules used in internal switch
    3287                 :            :  * @rules_free: Number of rules free in internal switch
    3288                 :            :  *
    3289                 :            :  * Add/Delete a mirror rule to a specific switch. Mirror rules are supported for
    3290                 :            :  * VEBs/VEPA elements only
    3291                 :            :  **/
    3292                 :          0 : static enum i40e_status_code i40e_mirrorrule_op(struct i40e_hw *hw,
    3293                 :            :                         u16 opcode, u16 sw_seid, u16 rule_type, u16 id,
    3294                 :            :                         u16 count, __le16 *mr_list,
    3295                 :            :                         struct i40e_asq_cmd_details *cmd_details,
    3296                 :            :                         u16 *rule_id, u16 *rules_used, u16 *rules_free)
    3297                 :            : {
    3298                 :            :         struct i40e_aq_desc desc;
    3299                 :            :         struct i40e_aqc_add_delete_mirror_rule *cmd =
    3300                 :            :                 (struct i40e_aqc_add_delete_mirror_rule *)&desc.params.raw;
    3301                 :            :         struct i40e_aqc_add_delete_mirror_rule_completion *resp =
    3302                 :            :         (struct i40e_aqc_add_delete_mirror_rule_completion *)&desc.params.raw;
    3303                 :            :         enum i40e_status_code status;
    3304                 :            :         u16 buf_size;
    3305                 :            : 
    3306                 :          0 :         buf_size = count * sizeof(*mr_list);
    3307                 :            : 
    3308                 :            :         /* prep the rest of the request */
    3309                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, opcode);
    3310                 :          0 :         cmd->seid = CPU_TO_LE16(sw_seid);
    3311                 :          0 :         cmd->rule_type = CPU_TO_LE16(rule_type &
    3312                 :            :                                      I40E_AQC_MIRROR_RULE_TYPE_MASK);
    3313                 :          0 :         cmd->num_entries = CPU_TO_LE16(count);
    3314                 :            :         /* Dest VSI for add, rule_id for delete */
    3315                 :          0 :         cmd->destination = CPU_TO_LE16(id);
    3316         [ #  # ]:          0 :         if (mr_list) {
    3317                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF |
    3318                 :            :                                                 I40E_AQ_FLAG_RD));
    3319         [ #  # ]:          0 :                 if (buf_size > I40E_AQ_LARGE_BUF)
    3320                 :          0 :                         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    3321                 :            :         }
    3322                 :            : 
    3323                 :          0 :         status = i40e_asq_send_command(hw, &desc, mr_list, buf_size,
    3324                 :            :                                        cmd_details);
    3325         [ #  # ]:          0 :         if (status == I40E_SUCCESS ||
    3326         [ #  # ]:          0 :             hw->aq.asq_last_status == I40E_AQ_RC_ENOSPC) {
    3327         [ #  # ]:          0 :                 if (rule_id)
    3328                 :          0 :                         *rule_id = LE16_TO_CPU(resp->rule_id);
    3329         [ #  # ]:          0 :                 if (rules_used)
    3330                 :          0 :                         *rules_used = LE16_TO_CPU(resp->mirror_rules_used);
    3331         [ #  # ]:          0 :                 if (rules_free)
    3332                 :          0 :                         *rules_free = LE16_TO_CPU(resp->mirror_rules_free);
    3333                 :            :         }
    3334                 :          0 :         return status;
    3335                 :            : }
    3336                 :            : 
    3337                 :            : /**
    3338                 :            :  * i40e_aq_add_mirrorrule - add a mirror rule
    3339                 :            :  * @hw: pointer to the hw struct
    3340                 :            :  * @sw_seid: Switch SEID (to which rule refers)
    3341                 :            :  * @rule_type: Rule Type (ingress/egress/VLAN)
    3342                 :            :  * @dest_vsi: SEID of VSI to which packets will be mirrored
    3343                 :            :  * @count: length of the list
    3344                 :            :  * @mr_list: list of mirrored VSI SEIDs or VLAN IDs
    3345                 :            :  * @cmd_details: pointer to command details structure or NULL
    3346                 :            :  * @rule_id: Rule ID returned from FW
    3347                 :            :  * @rules_used: Number of rules used in internal switch
    3348                 :            :  * @rules_free: Number of rules free in internal switch
    3349                 :            :  *
    3350                 :            :  * Add mirror rule. Mirror rules are supported for VEBs or VEPA elements only
    3351                 :            :  **/
    3352                 :          0 : enum i40e_status_code i40e_aq_add_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
    3353                 :            :                         u16 rule_type, u16 dest_vsi, u16 count, __le16 *mr_list,
    3354                 :            :                         struct i40e_asq_cmd_details *cmd_details,
    3355                 :            :                         u16 *rule_id, u16 *rules_used, u16 *rules_free)
    3356                 :            : {
    3357         [ #  # ]:          0 :         if (!(rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS ||
    3358                 :            :             rule_type == I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS)) {
    3359         [ #  # ]:          0 :                 if (count == 0 || !mr_list)
    3360                 :            :                         return I40E_ERR_PARAM;
    3361                 :            :         }
    3362                 :            : 
    3363                 :          0 :         return i40e_mirrorrule_op(hw, i40e_aqc_opc_add_mirror_rule, sw_seid,
    3364                 :            :                                   rule_type, dest_vsi, count, mr_list,
    3365                 :            :                                   cmd_details, rule_id, rules_used, rules_free);
    3366                 :            : }
    3367                 :            : 
    3368                 :            : /**
    3369                 :            :  * i40e_aq_delete_mirrorrule - delete a mirror rule
    3370                 :            :  * @hw: pointer to the hw struct
    3371                 :            :  * @sw_seid: Switch SEID (to which rule refers)
    3372                 :            :  * @rule_type: Rule Type (ingress/egress/VLAN)
    3373                 :            :  * @count: length of the list
    3374                 :            :  * @rule_id: Rule ID that is returned in the receive desc as part of
    3375                 :            :  *              add_mirrorrule.
    3376                 :            :  * @mr_list: list of mirrored VLAN IDs to be removed
    3377                 :            :  * @cmd_details: pointer to command details structure or NULL
    3378                 :            :  * @rules_used: Number of rules used in internal switch
    3379                 :            :  * @rules_free: Number of rules free in internal switch
    3380                 :            :  *
    3381                 :            :  * Delete a mirror rule. Mirror rules are supported for VEBs/VEPA elements only
    3382                 :            :  **/
    3383                 :          0 : enum i40e_status_code i40e_aq_delete_mirrorrule(struct i40e_hw *hw, u16 sw_seid,
    3384                 :            :                         u16 rule_type, u16 rule_id, u16 count, __le16 *mr_list,
    3385                 :            :                         struct i40e_asq_cmd_details *cmd_details,
    3386                 :            :                         u16 *rules_used, u16 *rules_free)
    3387                 :            : {
    3388                 :            :         /* Rule ID has to be valid except rule_type: INGRESS VLAN mirroring */
    3389         [ #  # ]:          0 :         if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
    3390                 :            :                 /* count and mr_list shall be valid for rule_type INGRESS VLAN
    3391                 :            :                  * mirroring. For other rule_type, count and rule_type should
    3392                 :            :                  * not matter.
    3393                 :            :                  */
    3394         [ #  # ]:          0 :                 if (count == 0 || !mr_list)
    3395                 :            :                         return I40E_ERR_PARAM;
    3396                 :            :         }
    3397                 :            : 
    3398                 :          0 :         return i40e_mirrorrule_op(hw, i40e_aqc_opc_delete_mirror_rule, sw_seid,
    3399                 :            :                                   rule_type, rule_id, count, mr_list,
    3400                 :            :                                   cmd_details, NULL, rules_used, rules_free);
    3401                 :            : }
    3402                 :            : 
    3403                 :            : /**
    3404                 :            :  * i40e_aq_add_vlan - Add VLAN ids to the HW filtering
    3405                 :            :  * @hw: pointer to the hw struct
    3406                 :            :  * @seid: VSI for the vlan filters
    3407                 :            :  * @v_list: list of vlan filters to be added
    3408                 :            :  * @count: length of the list
    3409                 :            :  * @cmd_details: pointer to command details structure or NULL
    3410                 :            :  **/
    3411                 :          0 : enum i40e_status_code i40e_aq_add_vlan(struct i40e_hw *hw, u16 seid,
    3412                 :            :                         struct i40e_aqc_add_remove_vlan_element_data *v_list,
    3413                 :            :                         u8 count, struct i40e_asq_cmd_details *cmd_details)
    3414                 :            : {
    3415                 :            :         struct i40e_aq_desc desc;
    3416                 :            :         struct i40e_aqc_macvlan *cmd =
    3417                 :            :                 (struct i40e_aqc_macvlan *)&desc.params.raw;
    3418                 :            :         enum i40e_status_code status;
    3419                 :            :         u16 buf_size;
    3420                 :            : 
    3421   [ #  #  #  # ]:          0 :         if (count == 0 || !v_list || !hw)
    3422                 :            :                 return I40E_ERR_PARAM;
    3423                 :            : 
    3424                 :          0 :         buf_size = count * sizeof(*v_list);
    3425                 :            : 
    3426                 :            :         /* prep the rest of the request */
    3427                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_vlan);
    3428                 :          0 :         cmd->num_addresses = CPU_TO_LE16(count);
    3429                 :          0 :         cmd->seid[0] = CPU_TO_LE16(seid | I40E_AQC_MACVLAN_CMD_SEID_VALID);
    3430                 :          0 :         cmd->seid[1] = 0;
    3431                 :          0 :         cmd->seid[2] = 0;
    3432                 :            : 
    3433                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    3434         [ #  # ]:          0 :         if (buf_size > I40E_AQ_LARGE_BUF)
    3435                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    3436                 :            : 
    3437                 :          0 :         status = i40e_asq_send_command(hw, &desc, v_list, buf_size,
    3438                 :            :                                        cmd_details);
    3439                 :            : 
    3440                 :          0 :         return status;
    3441                 :            : }
    3442                 :            : 
    3443                 :            : /**
    3444                 :            :  * i40e_aq_remove_vlan - Remove VLANs from the HW filtering
    3445                 :            :  * @hw: pointer to the hw struct
    3446                 :            :  * @seid: VSI for the vlan filters
    3447                 :            :  * @v_list: list of macvlans to be removed
    3448                 :            :  * @count: length of the list
    3449                 :            :  * @cmd_details: pointer to command details structure or NULL
    3450                 :            :  **/
    3451                 :          0 : enum i40e_status_code i40e_aq_remove_vlan(struct i40e_hw *hw, u16 seid,
    3452                 :            :                         struct i40e_aqc_add_remove_vlan_element_data *v_list,
    3453                 :            :                         u8 count, struct i40e_asq_cmd_details *cmd_details)
    3454                 :            : {
    3455                 :            :         struct i40e_aq_desc desc;
    3456                 :            :         struct i40e_aqc_macvlan *cmd =
    3457                 :            :                 (struct i40e_aqc_macvlan *)&desc.params.raw;
    3458                 :            :         enum i40e_status_code status;
    3459                 :            :         u16 buf_size;
    3460                 :            : 
    3461   [ #  #  #  # ]:          0 :         if (count == 0 || !v_list || !hw)
    3462                 :            :                 return I40E_ERR_PARAM;
    3463                 :            : 
    3464                 :          0 :         buf_size = count * sizeof(*v_list);
    3465                 :            : 
    3466                 :            :         /* prep the rest of the request */
    3467                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_vlan);
    3468                 :          0 :         cmd->num_addresses = CPU_TO_LE16(count);
    3469                 :          0 :         cmd->seid[0] = CPU_TO_LE16(seid | I40E_AQC_MACVLAN_CMD_SEID_VALID);
    3470                 :          0 :         cmd->seid[1] = 0;
    3471                 :          0 :         cmd->seid[2] = 0;
    3472                 :            : 
    3473                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    3474         [ #  # ]:          0 :         if (buf_size > I40E_AQ_LARGE_BUF)
    3475                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    3476                 :            : 
    3477                 :          0 :         status = i40e_asq_send_command(hw, &desc, v_list, buf_size,
    3478                 :            :                                        cmd_details);
    3479                 :            : 
    3480                 :          0 :         return status;
    3481                 :            : }
    3482                 :            : 
    3483                 :            : /**
    3484                 :            :  * i40e_aq_send_msg_to_vf
    3485                 :            :  * @hw: pointer to the hardware structure
    3486                 :            :  * @vfid: vf id to send msg
    3487                 :            :  * @v_opcode: opcodes for VF-PF communication
    3488                 :            :  * @v_retval: return error code
    3489                 :            :  * @msg: pointer to the msg buffer
    3490                 :            :  * @msglen: msg length
    3491                 :            :  * @cmd_details: pointer to command details
    3492                 :            :  *
    3493                 :            :  * send msg to vf
    3494                 :            :  **/
    3495                 :          0 : enum i40e_status_code i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
    3496                 :            :                                 u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
    3497                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    3498                 :            : {
    3499                 :            :         struct i40e_aq_desc desc;
    3500                 :            :         struct i40e_aqc_pf_vf_message *cmd =
    3501                 :            :                 (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
    3502                 :            :         enum i40e_status_code status;
    3503                 :            : 
    3504                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
    3505                 :          0 :         cmd->id = CPU_TO_LE32(vfid);
    3506                 :          0 :         desc.cookie_high = CPU_TO_LE32(v_opcode);
    3507                 :          0 :         desc.cookie_low = CPU_TO_LE32(v_retval);
    3508                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_SI);
    3509         [ #  # ]:          0 :         if (msglen) {
    3510                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF |
    3511                 :            :                                                 I40E_AQ_FLAG_RD));
    3512         [ #  # ]:          0 :                 if (msglen > I40E_AQ_LARGE_BUF)
    3513                 :          0 :                         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    3514                 :          0 :                 desc.datalen = CPU_TO_LE16(msglen);
    3515                 :            :         }
    3516                 :          0 :         status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
    3517                 :            : 
    3518                 :          0 :         return status;
    3519                 :            : }
    3520                 :            : 
    3521                 :            : /**
    3522                 :            :  * i40e_aq_debug_read_register
    3523                 :            :  * @hw: pointer to the hw struct
    3524                 :            :  * @reg_addr: register address
    3525                 :            :  * @reg_val: register value
    3526                 :            :  * @cmd_details: pointer to command details structure or NULL
    3527                 :            :  *
    3528                 :            :  * Read the register using the admin queue commands
    3529                 :            :  **/
    3530                 :          0 : enum i40e_status_code i40e_aq_debug_read_register(struct i40e_hw *hw,
    3531                 :            :                                 u32 reg_addr, u64 *reg_val,
    3532                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    3533                 :            : {
    3534                 :            :         struct i40e_aq_desc desc;
    3535                 :            :         struct i40e_aqc_debug_reg_read_write *cmd_resp =
    3536                 :            :                 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
    3537                 :            :         enum i40e_status_code status;
    3538                 :            : 
    3539         [ #  # ]:          0 :         if (reg_val == NULL)
    3540                 :            :                 return I40E_ERR_PARAM;
    3541                 :            : 
    3542                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_read_reg);
    3543                 :            : 
    3544                 :          0 :         cmd_resp->address = CPU_TO_LE32(reg_addr);
    3545                 :            : 
    3546                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    3547                 :            : 
    3548         [ #  # ]:          0 :         if (status == I40E_SUCCESS) {
    3549                 :          0 :                 *reg_val = ((u64)LE32_TO_CPU(cmd_resp->value_high) << 32) |
    3550                 :          0 :                            (u64)LE32_TO_CPU(cmd_resp->value_low);
    3551                 :            :         }
    3552                 :            : 
    3553                 :            :         return status;
    3554                 :            : }
    3555                 :            : 
    3556                 :            : /**
    3557                 :            :  * i40e_aq_debug_write_register
    3558                 :            :  * @hw: pointer to the hw struct
    3559                 :            :  * @reg_addr: register address
    3560                 :            :  * @reg_val: register value
    3561                 :            :  * @cmd_details: pointer to command details structure or NULL
    3562                 :            :  *
    3563                 :            :  * Write to a register using the admin queue commands
    3564                 :            :  **/
    3565                 :          0 : enum i40e_status_code i40e_aq_debug_write_register(struct i40e_hw *hw,
    3566                 :            :                                 u32 reg_addr, u64 reg_val,
    3567                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    3568                 :            : {
    3569                 :            :         struct i40e_aq_desc desc;
    3570                 :            :         struct i40e_aqc_debug_reg_read_write *cmd =
    3571                 :            :                 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
    3572                 :            :         enum i40e_status_code status;
    3573                 :            : 
    3574                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
    3575                 :            : 
    3576                 :          0 :         cmd->address = CPU_TO_LE32(reg_addr);
    3577                 :          0 :         cmd->value_high = CPU_TO_LE32((u32)(reg_val >> 32));
    3578                 :          0 :         cmd->value_low = CPU_TO_LE32((u32)(reg_val & 0xFFFFFFFF));
    3579                 :            : 
    3580                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    3581                 :            : 
    3582                 :          0 :         return status;
    3583                 :            : }
    3584                 :            : 
    3585                 :            : /**
    3586                 :            :  * i40e_aq_request_resource
    3587                 :            :  * @hw: pointer to the hw struct
    3588                 :            :  * @resource: resource id
    3589                 :            :  * @access: access type
    3590                 :            :  * @sdp_number: resource number
    3591                 :            :  * @timeout: the maximum time in ms that the driver may hold the resource
    3592                 :            :  * @cmd_details: pointer to command details structure or NULL
    3593                 :            :  *
    3594                 :            :  * requests common resource using the admin queue commands
    3595                 :            :  **/
    3596                 :          0 : enum i40e_status_code i40e_aq_request_resource(struct i40e_hw *hw,
    3597                 :            :                                 enum i40e_aq_resources_ids resource,
    3598                 :            :                                 enum i40e_aq_resource_access_type access,
    3599                 :            :                                 u8 sdp_number, u32 *timeout,
    3600                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    3601                 :            : {
    3602                 :            :         struct i40e_aq_desc desc;
    3603                 :            :         struct i40e_aqc_request_resource *cmd_resp =
    3604                 :            :                 (struct i40e_aqc_request_resource *)&desc.params.raw;
    3605                 :            :         enum i40e_status_code status;
    3606                 :            : 
    3607                 :          0 :         DEBUGFUNC("i40e_aq_request_resource");
    3608                 :            : 
    3609                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
    3610                 :            : 
    3611                 :          0 :         cmd_resp->resource_id = CPU_TO_LE16(resource);
    3612                 :          0 :         cmd_resp->access_type = CPU_TO_LE16(access);
    3613                 :          0 :         cmd_resp->resource_number = CPU_TO_LE32(sdp_number);
    3614                 :            : 
    3615                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    3616                 :            :         /* The completion specifies the maximum time in ms that the driver
    3617                 :            :          * may hold the resource in the Timeout field.
    3618                 :            :          * If the resource is held by someone else, the command completes with
    3619                 :            :          * busy return value and the timeout field indicates the maximum time
    3620                 :            :          * the current owner of the resource has to free it.
    3621                 :            :          */
    3622   [ #  #  #  # ]:          0 :         if (status == I40E_SUCCESS || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
    3623                 :          0 :                 *timeout = LE32_TO_CPU(cmd_resp->timeout);
    3624                 :            : 
    3625                 :          0 :         return status;
    3626                 :            : }
    3627                 :            : 
    3628                 :            : /**
    3629                 :            :  * i40e_aq_release_resource
    3630                 :            :  * @hw: pointer to the hw struct
    3631                 :            :  * @resource: resource id
    3632                 :            :  * @sdp_number: resource number
    3633                 :            :  * @cmd_details: pointer to command details structure or NULL
    3634                 :            :  *
    3635                 :            :  * release common resource using the admin queue commands
    3636                 :            :  **/
    3637                 :          0 : enum i40e_status_code i40e_aq_release_resource(struct i40e_hw *hw,
    3638                 :            :                                 enum i40e_aq_resources_ids resource,
    3639                 :            :                                 u8 sdp_number,
    3640                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    3641                 :            : {
    3642                 :            :         struct i40e_aq_desc desc;
    3643                 :            :         struct i40e_aqc_request_resource *cmd =
    3644                 :            :                 (struct i40e_aqc_request_resource *)&desc.params.raw;
    3645                 :            :         enum i40e_status_code status;
    3646                 :            : 
    3647                 :          0 :         DEBUGFUNC("i40e_aq_release_resource");
    3648                 :            : 
    3649                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
    3650                 :            : 
    3651                 :          0 :         cmd->resource_id = CPU_TO_LE16(resource);
    3652                 :          0 :         cmd->resource_number = CPU_TO_LE32(sdp_number);
    3653                 :            : 
    3654                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    3655                 :            : 
    3656                 :          0 :         return status;
    3657                 :            : }
    3658                 :            : 
    3659                 :            : /**
    3660                 :            :  * i40e_aq_read_nvm
    3661                 :            :  * @hw: pointer to the hw struct
    3662                 :            :  * @module_pointer: module pointer location in words from the NVM beginning
    3663                 :            :  * @offset: byte offset from the module beginning
    3664                 :            :  * @length: length of the section to be read (in bytes from the offset)
    3665                 :            :  * @data: command buffer (size [bytes] = length)
    3666                 :            :  * @last_command: tells if this is the last command in a series
    3667                 :            :  * @cmd_details: pointer to command details structure or NULL
    3668                 :            :  *
    3669                 :            :  * Read the NVM using the admin queue commands
    3670                 :            :  **/
    3671                 :          0 : enum i40e_status_code i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
    3672                 :            :                                 u32 offset, u16 length, void *data,
    3673                 :            :                                 bool last_command,
    3674                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    3675                 :            : {
    3676                 :            :         struct i40e_aq_desc desc;
    3677                 :            :         struct i40e_aqc_nvm_update *cmd =
    3678                 :            :                 (struct i40e_aqc_nvm_update *)&desc.params.raw;
    3679                 :            :         enum i40e_status_code status;
    3680                 :            : 
    3681                 :          0 :         DEBUGFUNC("i40e_aq_read_nvm");
    3682                 :            : 
    3683                 :            :         /* In offset the highest byte must be zeroed. */
    3684         [ #  # ]:          0 :         if (offset & 0xFF000000) {
    3685                 :            :                 status = I40E_ERR_PARAM;
    3686                 :          0 :                 goto i40e_aq_read_nvm_exit;
    3687                 :            :         }
    3688                 :            : 
    3689                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
    3690                 :            : 
    3691                 :            :         /* If this is the last command in a series, set the proper flag. */
    3692         [ #  # ]:          0 :         if (last_command)
    3693                 :          0 :                 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
    3694                 :          0 :         cmd->module_pointer = module_pointer;
    3695                 :          0 :         cmd->offset = CPU_TO_LE32(offset);
    3696                 :          0 :         cmd->length = CPU_TO_LE16(length);
    3697                 :            : 
    3698                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    3699         [ #  # ]:          0 :         if (length > I40E_AQ_LARGE_BUF)
    3700                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    3701                 :            : 
    3702                 :          0 :         status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
    3703                 :            : 
    3704                 :          0 : i40e_aq_read_nvm_exit:
    3705                 :          0 :         return status;
    3706                 :            : }
    3707                 :            : 
    3708                 :            : /**
    3709                 :            :  * i40e_aq_read_nvm_config - read an nvm config block
    3710                 :            :  * @hw: pointer to the hw struct
    3711                 :            :  * @cmd_flags: NVM access admin command bits
    3712                 :            :  * @field_id: field or feature id
    3713                 :            :  * @data: buffer for result
    3714                 :            :  * @buf_size: buffer size
    3715                 :            :  * @element_count: pointer to count of elements read by FW
    3716                 :            :  * @cmd_details: pointer to command details structure or NULL
    3717                 :            :  **/
    3718                 :          0 : enum i40e_status_code i40e_aq_read_nvm_config(struct i40e_hw *hw,
    3719                 :            :                                 u8 cmd_flags, u32 field_id, void *data,
    3720                 :            :                                 u16 buf_size, u16 *element_count,
    3721                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    3722                 :            : {
    3723                 :            :         struct i40e_aq_desc desc;
    3724                 :            :         struct i40e_aqc_nvm_config_read *cmd =
    3725                 :            :                 (struct i40e_aqc_nvm_config_read *)&desc.params.raw;
    3726                 :            :         enum i40e_status_code status;
    3727                 :            : 
    3728                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_config_read);
    3729                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF));
    3730         [ #  # ]:          0 :         if (buf_size > I40E_AQ_LARGE_BUF)
    3731                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    3732                 :            : 
    3733                 :          0 :         cmd->cmd_flags = CPU_TO_LE16(cmd_flags);
    3734                 :          0 :         cmd->element_id = CPU_TO_LE16((u16)(0xffff & field_id));
    3735         [ #  # ]:          0 :         if (cmd_flags & I40E_AQ_ANVM_FEATURE_OR_IMMEDIATE_MASK)
    3736                 :          0 :                 cmd->element_id_msw = CPU_TO_LE16((u16)(field_id >> 16));
    3737                 :            :         else
    3738                 :          0 :                 cmd->element_id_msw = 0;
    3739                 :            : 
    3740                 :          0 :         status = i40e_asq_send_command(hw, &desc, data, buf_size, cmd_details);
    3741                 :            : 
    3742         [ #  # ]:          0 :         if (!status && element_count)
    3743                 :          0 :                 *element_count = LE16_TO_CPU(cmd->element_count);
    3744                 :            : 
    3745                 :          0 :         return status;
    3746                 :            : }
    3747                 :            : 
    3748                 :            : /**
    3749                 :            :  * i40e_aq_write_nvm_config - write an nvm config block
    3750                 :            :  * @hw: pointer to the hw struct
    3751                 :            :  * @cmd_flags: NVM access admin command bits
    3752                 :            :  * @data: buffer for result
    3753                 :            :  * @buf_size: buffer size
    3754                 :            :  * @element_count: count of elements to be written
    3755                 :            :  * @cmd_details: pointer to command details structure or NULL
    3756                 :            :  **/
    3757                 :          0 : enum i40e_status_code i40e_aq_write_nvm_config(struct i40e_hw *hw,
    3758                 :            :                                 u8 cmd_flags, void *data, u16 buf_size,
    3759                 :            :                                 u16 element_count,
    3760                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    3761                 :            : {
    3762                 :            :         struct i40e_aq_desc desc;
    3763                 :            :         struct i40e_aqc_nvm_config_write *cmd =
    3764                 :            :                 (struct i40e_aqc_nvm_config_write *)&desc.params.raw;
    3765                 :            :         enum i40e_status_code status;
    3766                 :            : 
    3767                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_config_write);
    3768                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    3769         [ #  # ]:          0 :         if (buf_size > I40E_AQ_LARGE_BUF)
    3770                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    3771                 :            : 
    3772                 :          0 :         cmd->element_count = CPU_TO_LE16(element_count);
    3773                 :          0 :         cmd->cmd_flags = CPU_TO_LE16(cmd_flags);
    3774                 :          0 :         status = i40e_asq_send_command(hw, &desc, data, buf_size, cmd_details);
    3775                 :            : 
    3776                 :          0 :         return status;
    3777                 :            : }
    3778                 :            : 
    3779                 :            : /**
    3780                 :            :  * i40e_aq_nvm_update_in_process
    3781                 :            :  * @hw: pointer to the hw struct
    3782                 :            :  * @update_flow_state: True indicates that update flow starts, false that ends
    3783                 :            :  * @cmd_details: pointer to command details structure or NULL
    3784                 :            :  *
    3785                 :            :  * Indicate NVM update in process.
    3786                 :            :  **/
    3787                 :          0 : enum i40e_status_code i40e_aq_nvm_update_in_process(struct i40e_hw *hw,
    3788                 :            :                                 bool update_flow_state,
    3789                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    3790                 :            : {
    3791                 :            :         struct i40e_aq_desc desc;
    3792                 :            :         struct i40e_aqc_nvm_update_in_process *cmd =
    3793                 :            :                 (struct i40e_aqc_nvm_update_in_process *)&desc.params.raw;
    3794                 :            :         enum i40e_status_code status;
    3795                 :            : 
    3796                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    3797                 :            :                                           i40e_aqc_opc_nvm_update_in_process);
    3798                 :            : 
    3799                 :          0 :         cmd->command = I40E_AQ_UPDATE_FLOW_END;
    3800                 :            : 
    3801         [ #  # ]:          0 :         if (update_flow_state)
    3802                 :          0 :                 cmd->command |= I40E_AQ_UPDATE_FLOW_START;
    3803                 :            : 
    3804                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    3805                 :            : 
    3806                 :          0 :         return status;
    3807                 :            : }
    3808                 :            : 
    3809                 :            : /**
    3810                 :            :  * i40e_aq_min_rollback_rev_update - triggers an ow after update
    3811                 :            :  * @hw: pointer to the hw struct
    3812                 :            :  * @mode: opt-in mode, 1b for single module update, 0b for bulk update
    3813                 :            :  * @module: module to be updated. Ignored if mode is 0b
    3814                 :            :  * @min_rrev: value of the new minimal version. Ignored if mode is 0b
    3815                 :            :  * @cmd_details: pointer to command details structure or NULL
    3816                 :            :  **/
    3817                 :            : enum i40e_status_code
    3818                 :          0 : i40e_aq_min_rollback_rev_update(struct i40e_hw *hw, u8 mode, u8 module,
    3819                 :            :                                 u32 min_rrev,
    3820                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    3821                 :            : {
    3822                 :            :         struct i40e_aq_desc desc;
    3823                 :            :         struct i40e_aqc_rollback_revision_update *cmd =
    3824                 :            :                 (struct i40e_aqc_rollback_revision_update *)&desc.params.raw;
    3825                 :            :         enum i40e_status_code status;
    3826                 :            : 
    3827                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    3828                 :            :                 i40e_aqc_opc_rollback_revision_update);
    3829                 :          0 :         cmd->optin_mode = mode;
    3830                 :          0 :         cmd->module_selected = module;
    3831                 :          0 :         cmd->min_rrev = min_rrev;
    3832                 :            : 
    3833                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    3834                 :            : 
    3835                 :          0 :         return status;
    3836                 :            : }
    3837                 :            : 
    3838                 :            : /**
    3839                 :            :  * i40e_aq_oem_post_update - triggers an OEM specific flow after update
    3840                 :            :  * @hw: pointer to the hw struct
    3841                 :            :  * @buff: buffer for result
    3842                 :            :  * @buff_size: buffer size
    3843                 :            :  * @cmd_details: pointer to command details structure or NULL
    3844                 :            :  **/
    3845                 :          0 : enum i40e_status_code i40e_aq_oem_post_update(struct i40e_hw *hw,
    3846                 :            :                                 void *buff, u16 buff_size,
    3847                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    3848                 :            : {
    3849                 :            :         struct i40e_aq_desc desc;
    3850                 :            :         enum i40e_status_code status;
    3851                 :            : 
    3852                 :            :         UNREFERENCED_2PARAMETER(buff, buff_size);
    3853                 :            : 
    3854                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_oem_post_update);
    3855                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    3856   [ #  #  #  # ]:          0 :         if (status && LE16_TO_CPU(desc.retval) == I40E_AQ_RC_ESRCH)
    3857                 :            :                 status = I40E_ERR_NOT_IMPLEMENTED;
    3858                 :            : 
    3859                 :          0 :         return status;
    3860                 :            : }
    3861                 :            : 
    3862                 :            : /**
    3863                 :            :  * i40e_aq_erase_nvm
    3864                 :            :  * @hw: pointer to the hw struct
    3865                 :            :  * @module_pointer: module pointer location in words from the NVM beginning
    3866                 :            :  * @offset: offset in the module (expressed in 4 KB from module's beginning)
    3867                 :            :  * @length: length of the section to be erased (expressed in 4 KB)
    3868                 :            :  * @last_command: tells if this is the last command in a series
    3869                 :            :  * @cmd_details: pointer to command details structure or NULL
    3870                 :            :  *
    3871                 :            :  * Erase the NVM sector using the admin queue commands
    3872                 :            :  **/
    3873                 :          0 : enum i40e_status_code i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
    3874                 :            :                                 u32 offset, u16 length, bool last_command,
    3875                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    3876                 :            : {
    3877                 :            :         struct i40e_aq_desc desc;
    3878                 :            :         struct i40e_aqc_nvm_update *cmd =
    3879                 :            :                 (struct i40e_aqc_nvm_update *)&desc.params.raw;
    3880                 :            :         enum i40e_status_code status;
    3881                 :            : 
    3882                 :          0 :         DEBUGFUNC("i40e_aq_erase_nvm");
    3883                 :            : 
    3884                 :            :         /* In offset the highest byte must be zeroed. */
    3885         [ #  # ]:          0 :         if (offset & 0xFF000000) {
    3886                 :            :                 status = I40E_ERR_PARAM;
    3887                 :          0 :                 goto i40e_aq_erase_nvm_exit;
    3888                 :            :         }
    3889                 :            : 
    3890                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
    3891                 :            : 
    3892                 :            :         /* If this is the last command in a series, set the proper flag. */
    3893         [ #  # ]:          0 :         if (last_command)
    3894                 :          0 :                 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
    3895                 :          0 :         cmd->module_pointer = module_pointer;
    3896                 :          0 :         cmd->offset = CPU_TO_LE32(offset);
    3897                 :          0 :         cmd->length = CPU_TO_LE16(length);
    3898                 :            : 
    3899                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    3900                 :            : 
    3901                 :          0 : i40e_aq_erase_nvm_exit:
    3902                 :          0 :         return status;
    3903                 :            : }
    3904                 :            : 
    3905                 :            : /**
    3906                 :            :  * i40e_parse_discover_capabilities
    3907                 :            :  * @hw: pointer to the hw struct
    3908                 :            :  * @buff: pointer to a buffer containing device/function capability records
    3909                 :            :  * @cap_count: number of capability records in the list
    3910                 :            :  * @list_type_opc: type of capabilities list to parse
    3911                 :            :  *
    3912                 :            :  * Parse the device/function capabilities list.
    3913                 :            :  **/
    3914                 :          0 : STATIC void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
    3915                 :            :                                      u32 cap_count,
    3916                 :            :                                      enum i40e_admin_queue_opc list_type_opc)
    3917                 :            : {
    3918                 :            :         struct i40e_aqc_list_capabilities_element_resp *cap;
    3919                 :            :         u32 valid_functions, num_functions;
    3920                 :            :         u32 number, logical_id, phys_id;
    3921                 :            :         struct i40e_hw_capabilities *p;
    3922                 :            :         enum i40e_status_code status;
    3923                 :            :         u16 id, ocp_cfg_word0;
    3924                 :            :         u8 major_rev;
    3925                 :            :         u32 i = 0;
    3926                 :            : 
    3927                 :            :         cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
    3928                 :            : 
    3929         [ #  # ]:          0 :         if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
    3930                 :          0 :                 p = (struct i40e_hw_capabilities *)&hw->dev_caps;
    3931         [ #  # ]:          0 :         else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
    3932                 :          0 :                 p = (struct i40e_hw_capabilities *)&hw->func_caps;
    3933                 :            :         else
    3934                 :          0 :                 return;
    3935                 :            : 
    3936         [ #  # ]:          0 :         for (i = 0; i < cap_count; i++, cap++) {
    3937                 :          0 :                 id = LE16_TO_CPU(cap->id);
    3938                 :          0 :                 number = LE32_TO_CPU(cap->number);
    3939                 :          0 :                 logical_id = LE32_TO_CPU(cap->logical_id);
    3940                 :          0 :                 phys_id = LE32_TO_CPU(cap->phys_id);
    3941                 :          0 :                 major_rev = cap->major_rev;
    3942                 :            : 
    3943   [ #  #  #  #  :          0 :                 switch (id) {
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
    3944                 :          0 :                 case I40E_AQ_CAP_ID_SWITCH_MODE:
    3945                 :          0 :                         p->switch_mode = number;
    3946         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    3947                 :            :                                    "HW Capability: Switch mode = %d\n",
    3948                 :            :                                    p->switch_mode);
    3949                 :            :                         break;
    3950                 :          0 :                 case I40E_AQ_CAP_ID_MNG_MODE:
    3951                 :          0 :                         p->management_mode = number;
    3952         [ #  # ]:          0 :                         if (major_rev > 1) {
    3953                 :          0 :                                 p->mng_protocols_over_mctp = logical_id;
    3954         [ #  # ]:          0 :                                 i40e_debug(hw, I40E_DEBUG_INIT,
    3955                 :            :                                            "HW Capability: Protocols over MCTP = %d\n",
    3956                 :            :                                            p->mng_protocols_over_mctp);
    3957                 :            :                         } else {
    3958                 :          0 :                                 p->mng_protocols_over_mctp = 0;
    3959                 :            :                         }
    3960         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    3961                 :            :                                    "HW Capability: Management Mode = %d\n",
    3962                 :            :                                    p->management_mode);
    3963                 :            :                         break;
    3964                 :          0 :                 case I40E_AQ_CAP_ID_NPAR_ACTIVE:
    3965                 :          0 :                         p->npar_enable = number;
    3966         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    3967                 :            :                                    "HW Capability: NPAR enable = %d\n",
    3968                 :            :                                    p->npar_enable);
    3969                 :            :                         break;
    3970                 :          0 :                 case I40E_AQ_CAP_ID_OS2BMC_CAP:
    3971                 :          0 :                         p->os2bmc = number;
    3972         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    3973                 :            :                                    "HW Capability: OS2BMC = %d\n", p->os2bmc);
    3974                 :            :                         break;
    3975                 :          0 :                 case I40E_AQ_CAP_ID_FUNCTIONS_VALID:
    3976                 :          0 :                         p->valid_functions = number;
    3977         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    3978                 :            :                                    "HW Capability: Valid Functions = %d\n",
    3979                 :            :                                    p->valid_functions);
    3980                 :            :                         break;
    3981                 :          0 :                 case I40E_AQ_CAP_ID_SRIOV:
    3982         [ #  # ]:          0 :                         if (number == 1)
    3983                 :          0 :                                 p->sr_iov_1_1 = true;
    3984         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    3985                 :            :                                    "HW Capability: SR-IOV = %d\n",
    3986                 :            :                                    p->sr_iov_1_1);
    3987                 :            :                         break;
    3988                 :          0 :                 case I40E_AQ_CAP_ID_VF:
    3989                 :          0 :                         p->num_vfs = number;
    3990                 :          0 :                         p->vf_base_id = logical_id;
    3991         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    3992                 :            :                                    "HW Capability: VF count = %d\n",
    3993                 :            :                                    p->num_vfs);
    3994         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    3995                 :            :                                    "HW Capability: VF base_id = %d\n",
    3996                 :            :                                    p->vf_base_id);
    3997                 :            :                         break;
    3998                 :          0 :                 case I40E_AQ_CAP_ID_VMDQ:
    3999         [ #  # ]:          0 :                         if (number == 1)
    4000                 :          0 :                                 p->vmdq = true;
    4001         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4002                 :            :                                    "HW Capability: VMDQ = %d\n", p->vmdq);
    4003                 :            :                         break;
    4004                 :          0 :                 case I40E_AQ_CAP_ID_8021QBG:
    4005         [ #  # ]:          0 :                         if (number == 1)
    4006                 :          0 :                                 p->evb_802_1_qbg = true;
    4007         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4008                 :            :                                    "HW Capability: 802.1Qbg = %d\n", number);
    4009                 :            :                         break;
    4010                 :          0 :                 case I40E_AQ_CAP_ID_8021QBR:
    4011         [ #  # ]:          0 :                         if (number == 1)
    4012                 :          0 :                                 p->evb_802_1_qbh = true;
    4013         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4014                 :            :                                    "HW Capability: 802.1Qbh = %d\n", number);
    4015                 :            :                         break;
    4016                 :          0 :                 case I40E_AQ_CAP_ID_VSI:
    4017                 :          0 :                         p->num_vsis = number;
    4018         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4019                 :            :                                    "HW Capability: VSI count = %d\n",
    4020                 :            :                                    p->num_vsis);
    4021                 :            :                         break;
    4022                 :          0 :                 case I40E_AQ_CAP_ID_DCB:
    4023         [ #  # ]:          0 :                         if (number == 1) {
    4024                 :          0 :                                 p->dcb = true;
    4025                 :          0 :                                 p->enabled_tcmap = logical_id;
    4026                 :          0 :                                 p->maxtc = phys_id;
    4027                 :            :                         }
    4028         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4029                 :            :                                    "HW Capability: DCB = %d\n", p->dcb);
    4030         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4031                 :            :                                    "HW Capability: TC Mapping = %d\n",
    4032                 :            :                                    logical_id);
    4033         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4034                 :            :                                    "HW Capability: TC Max = %d\n", p->maxtc);
    4035                 :            :                         break;
    4036                 :          0 :                 case I40E_AQ_CAP_ID_FCOE:
    4037         [ #  # ]:          0 :                         if (number == 1)
    4038                 :          0 :                                 p->fcoe = true;
    4039         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4040                 :            :                                    "HW Capability: FCOE = %d\n", p->fcoe);
    4041                 :            :                         break;
    4042                 :          0 :                 case I40E_AQ_CAP_ID_ISCSI:
    4043         [ #  # ]:          0 :                         if (number == 1)
    4044                 :          0 :                                 p->iscsi = true;
    4045         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4046                 :            :                                    "HW Capability: iSCSI = %d\n", p->iscsi);
    4047                 :            :                         break;
    4048                 :          0 :                 case I40E_AQ_CAP_ID_RSS:
    4049                 :          0 :                         p->rss = true;
    4050                 :          0 :                         p->rss_table_size = number;
    4051                 :          0 :                         p->rss_table_entry_width = logical_id;
    4052         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4053                 :            :                                    "HW Capability: RSS = %d\n", p->rss);
    4054         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4055                 :            :                                    "HW Capability: RSS table size = %d\n",
    4056                 :            :                                    p->rss_table_size);
    4057         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4058                 :            :                                    "HW Capability: RSS table width = %d\n",
    4059                 :            :                                    p->rss_table_entry_width);
    4060                 :            :                         break;
    4061                 :          0 :                 case I40E_AQ_CAP_ID_RXQ:
    4062                 :          0 :                         p->num_rx_qp = number;
    4063                 :          0 :                         p->base_queue = phys_id;
    4064         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4065                 :            :                                    "HW Capability: Rx QP = %d\n", number);
    4066         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4067                 :            :                                    "HW Capability: base_queue = %d\n",
    4068                 :            :                                    p->base_queue);
    4069                 :            :                         break;
    4070                 :          0 :                 case I40E_AQ_CAP_ID_TXQ:
    4071                 :          0 :                         p->num_tx_qp = number;
    4072                 :          0 :                         p->base_queue = phys_id;
    4073         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4074                 :            :                                    "HW Capability: Tx QP = %d\n", number);
    4075         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4076                 :            :                                    "HW Capability: base_queue = %d\n",
    4077                 :            :                                    p->base_queue);
    4078                 :            :                         break;
    4079                 :          0 :                 case I40E_AQ_CAP_ID_MSIX:
    4080                 :          0 :                         p->num_msix_vectors = number;
    4081         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4082                 :            :                                    "HW Capability: MSIX vector count = %d\n",
    4083                 :            :                                    p->num_msix_vectors);
    4084                 :            :                         break;
    4085                 :          0 :                 case I40E_AQ_CAP_ID_VF_MSIX:
    4086                 :          0 :                         p->num_msix_vectors_vf = number;
    4087         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4088                 :            :                                    "HW Capability: MSIX VF vector count = %d\n",
    4089                 :            :                                    p->num_msix_vectors_vf);
    4090                 :            :                         break;
    4091                 :          0 :                 case I40E_AQ_CAP_ID_FLEX10:
    4092         [ #  # ]:          0 :                         if (major_rev == 1) {
    4093         [ #  # ]:          0 :                                 if (number == 1) {
    4094                 :          0 :                                         p->flex10_enable = true;
    4095                 :          0 :                                         p->flex10_capable = true;
    4096                 :            :                                 }
    4097                 :            :                         } else {
    4098                 :            :                                 /* Capability revision >= 2 */
    4099         [ #  # ]:          0 :                                 if (number & 1)
    4100                 :          0 :                                         p->flex10_enable = true;
    4101         [ #  # ]:          0 :                                 if (number & 2)
    4102                 :          0 :                                         p->flex10_capable = true;
    4103                 :            :                         }
    4104                 :          0 :                         p->flex10_mode = logical_id;
    4105                 :          0 :                         p->flex10_status = phys_id;
    4106         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4107                 :            :                                    "HW Capability: Flex10 mode = %d\n",
    4108                 :            :                                    p->flex10_mode);
    4109         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4110                 :            :                                    "HW Capability: Flex10 status = %d\n",
    4111                 :            :                                    p->flex10_status);
    4112                 :            :                         break;
    4113                 :          0 :                 case I40E_AQ_CAP_ID_CEM:
    4114         [ #  # ]:          0 :                         if (number == 1)
    4115                 :          0 :                                 p->mgmt_cem = true;
    4116         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4117                 :            :                                    "HW Capability: CEM = %d\n", p->mgmt_cem);
    4118                 :            :                         break;
    4119                 :          0 :                 case I40E_AQ_CAP_ID_IWARP:
    4120         [ #  # ]:          0 :                         if (number == 1)
    4121                 :          0 :                                 p->iwarp = true;
    4122         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4123                 :            :                                    "HW Capability: iWARP = %d\n", p->iwarp);
    4124                 :            :                         break;
    4125                 :          0 :                 case I40E_AQ_CAP_ID_LED:
    4126         [ #  # ]:          0 :                         if (phys_id < I40E_HW_CAP_MAX_GPIO)
    4127                 :          0 :                                 p->led[phys_id] = true;
    4128         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4129                 :            :                                    "HW Capability: LED - PIN %d\n", phys_id);
    4130                 :            :                         break;
    4131                 :          0 :                 case I40E_AQ_CAP_ID_SDP:
    4132         [ #  # ]:          0 :                         if (phys_id < I40E_HW_CAP_MAX_GPIO)
    4133                 :          0 :                                 p->sdp[phys_id] = true;
    4134         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4135                 :            :                                    "HW Capability: SDP - PIN %d\n", phys_id);
    4136                 :            :                         break;
    4137                 :          0 :                 case I40E_AQ_CAP_ID_MDIO:
    4138         [ #  # ]:          0 :                         if (number == 1) {
    4139                 :          0 :                                 p->mdio_port_num = phys_id;
    4140                 :          0 :                                 p->mdio_port_mode = logical_id;
    4141                 :            :                         }
    4142         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4143                 :            :                                    "HW Capability: MDIO port number = %d\n",
    4144                 :            :                                    p->mdio_port_num);
    4145         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4146                 :            :                                    "HW Capability: MDIO port mode = %d\n",
    4147                 :            :                                    p->mdio_port_mode);
    4148                 :            :                         break;
    4149                 :          0 :                 case I40E_AQ_CAP_ID_1588:
    4150         [ #  # ]:          0 :                         if (number == 1)
    4151                 :          0 :                                 p->ieee_1588 = true;
    4152         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4153                 :            :                                    "HW Capability: IEEE 1588 = %d\n",
    4154                 :            :                                    p->ieee_1588);
    4155                 :            :                         break;
    4156                 :          0 :                 case I40E_AQ_CAP_ID_FLOW_DIRECTOR:
    4157                 :          0 :                         p->fd = true;
    4158                 :          0 :                         p->fd_filters_guaranteed = number;
    4159                 :          0 :                         p->fd_filters_best_effort = logical_id;
    4160         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4161                 :            :                                    "HW Capability: Flow Director = 1\n");
    4162         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4163                 :            :                                    "HW Capability: Guaranteed FD filters = %d\n",
    4164                 :            :                                    p->fd_filters_guaranteed);
    4165                 :            :                         break;
    4166                 :          0 :                 case I40E_AQ_CAP_ID_WSR_PROT:
    4167                 :          0 :                         p->wr_csr_prot = (u64)number;
    4168                 :          0 :                         p->wr_csr_prot |= (u64)logical_id << 32;
    4169         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4170                 :            :                                    "HW Capability: wr_csr_prot = 0x%" PRIX64 "\n\n",
    4171                 :            :                                    (p->wr_csr_prot & 0xffff));
    4172                 :            :                         break;
    4173                 :          0 :                 case I40E_AQ_CAP_ID_DIS_UNUSED_PORTS:
    4174                 :          0 :                         p->dis_unused_ports = (bool)number;
    4175         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4176                 :            :                                    "HW Capability: dis_unused_ports = %d\n\n",
    4177                 :            :                                    p->dis_unused_ports);
    4178                 :            :                         break;
    4179                 :          0 :                 case I40E_AQ_CAP_ID_NVM_MGMT:
    4180         [ #  # ]:          0 :                         if (number & I40E_NVM_MGMT_SEC_REV_DISABLED)
    4181                 :          0 :                                 p->sec_rev_disabled = true;
    4182         [ #  # ]:          0 :                         if (number & I40E_NVM_MGMT_UPDATE_DISABLED)
    4183                 :          0 :                                 p->update_disabled = true;
    4184                 :            :                         break;
    4185                 :          0 :                 case I40E_AQ_CAP_ID_WOL_AND_PROXY:
    4186                 :          0 :                         hw->num_wol_proxy_filters = (u16)number;
    4187                 :          0 :                         hw->wol_proxy_vsi_seid = (u16)logical_id;
    4188                 :          0 :                         p->apm_wol_support = phys_id & I40E_WOL_SUPPORT_MASK;
    4189         [ #  # ]:          0 :                         if (phys_id & I40E_ACPI_PROGRAMMING_METHOD_MASK)
    4190                 :          0 :                                 p->acpi_prog_method = I40E_ACPI_PROGRAMMING_METHOD_AQC_FPK;
    4191                 :            :                         else
    4192                 :          0 :                                 p->acpi_prog_method = I40E_ACPI_PROGRAMMING_METHOD_HW_FVL;
    4193                 :          0 :                         p->proxy_support = (phys_id & I40E_PROXY_SUPPORT_MASK) ? 1 : 0;
    4194         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_INIT,
    4195                 :            :                                    "HW Capability: WOL proxy filters = %d\n",
    4196                 :            :                                    hw->num_wol_proxy_filters);
    4197                 :            :                         break;
    4198                 :            :                 default:
    4199                 :            :                         break;
    4200                 :            :                 }
    4201                 :            :         }
    4202                 :            : 
    4203         [ #  # ]:          0 :         if (p->fcoe)
    4204         [ #  # ]:          0 :                 i40e_debug(hw, I40E_DEBUG_ALL, "device is FCoE capable\n");
    4205                 :            : 
    4206                 :            :         /* Always disable FCoE if compiled without the I40E_FCOE_ENA flag */
    4207                 :          0 :         p->fcoe = false;
    4208                 :            : 
    4209                 :            :         /* count the enabled ports (aka the "not disabled" ports) */
    4210                 :          0 :         hw->num_ports = 0;
    4211         [ #  # ]:          0 :         for (i = 0; i < 4; i++) {
    4212                 :          0 :                 u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
    4213                 :          0 :                 u64 port_cfg = 0;
    4214                 :            : 
    4215                 :            :                 /* use AQ read to get the physical register offset instead
    4216                 :            :                  * of the port relative offset
    4217                 :            :                  */
    4218                 :          0 :                 status = i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
    4219   [ #  #  #  # ]:          0 :                 if ((status == I40E_SUCCESS) && (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK)))
    4220                 :          0 :                         hw->num_ports++;
    4221                 :            :         }
    4222                 :            : 
    4223                 :            :         /* OCP cards case: if a mezz is removed the ethernet port is at
    4224                 :            :          * disabled state in PRTGEN_CNF register. Additional NVM read is
    4225                 :            :          * needed in order to check if we are dealing with OCP card.
    4226                 :            :          * Those cards have 4 PFs at minimum, so using PRTGEN_CNF for counting
    4227                 :            :          * physical ports results in wrong partition id calculation and thus
    4228                 :            :          * not supporting WoL.
    4229                 :            :          */
    4230         [ #  # ]:          0 :         if (hw->mac.type == I40E_MAC_X722) {
    4231         [ #  # ]:          0 :                 if (i40e_acquire_nvm(hw, I40E_RESOURCE_READ) == I40E_SUCCESS) {
    4232                 :          0 :                         status = i40e_aq_read_nvm(hw, I40E_SR_EMP_MODULE_PTR,
    4233                 :            :                                                   2 * I40E_SR_OCP_CFG_WORD0,
    4234                 :            :                                                   sizeof(ocp_cfg_word0),
    4235                 :            :                                                   &ocp_cfg_word0, true, NULL);
    4236   [ #  #  #  # ]:          0 :                         if (status == I40E_SUCCESS &&
    4237                 :            :                             (ocp_cfg_word0 & I40E_SR_OCP_ENABLED))
    4238                 :          0 :                                 hw->num_ports = 4;
    4239                 :          0 :                         i40e_release_nvm(hw);
    4240                 :            :                 }
    4241                 :            :         }
    4242                 :            : 
    4243                 :          0 :         valid_functions = p->valid_functions;
    4244                 :            :         num_functions = 0;
    4245         [ #  # ]:          0 :         while (valid_functions) {
    4246         [ #  # ]:          0 :                 if (valid_functions & 1)
    4247                 :          0 :                         num_functions++;
    4248                 :          0 :                 valid_functions >>= 1;
    4249                 :            :         }
    4250                 :            : 
    4251                 :            :         /* partition id is 1-based, and functions are evenly spread
    4252                 :            :          * across the ports as partitions
    4253                 :            :          */
    4254         [ #  # ]:          0 :         if (hw->num_ports != 0) {
    4255                 :          0 :                 hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
    4256                 :          0 :                 hw->num_partitions = (u16)(num_functions / hw->num_ports);
    4257                 :            :         }
    4258                 :            : 
    4259                 :            :         /* additional HW specific goodies that might
    4260                 :            :          * someday be HW version specific
    4261                 :            :          */
    4262                 :          0 :         p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
    4263                 :            : }
    4264                 :            : 
    4265                 :            : /**
    4266                 :            :  * i40e_aq_discover_capabilities
    4267                 :            :  * @hw: pointer to the hw struct
    4268                 :            :  * @buff: a virtual buffer to hold the capabilities
    4269                 :            :  * @buff_size: Size of the virtual buffer
    4270                 :            :  * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
    4271                 :            :  * @list_type_opc: capabilities type to discover - pass in the command opcode
    4272                 :            :  * @cmd_details: pointer to command details structure or NULL
    4273                 :            :  *
    4274                 :            :  * Get the device capabilities descriptions from the firmware
    4275                 :            :  **/
    4276                 :          0 : enum i40e_status_code i40e_aq_discover_capabilities(struct i40e_hw *hw,
    4277                 :            :                                 void *buff, u16 buff_size, u16 *data_size,
    4278                 :            :                                 enum i40e_admin_queue_opc list_type_opc,
    4279                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    4280                 :            : {
    4281                 :            :         struct i40e_aqc_list_capabilites *cmd;
    4282                 :            :         struct i40e_aq_desc desc;
    4283                 :            :         enum i40e_status_code status = I40E_SUCCESS;
    4284                 :            : 
    4285                 :            :         cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
    4286                 :            : 
    4287         [ #  # ]:          0 :         if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
    4288                 :            :                 list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
    4289                 :            :                 status = I40E_ERR_PARAM;
    4290                 :          0 :                 goto exit;
    4291                 :            :         }
    4292                 :            : 
    4293                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
    4294                 :            : 
    4295                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    4296         [ #  # ]:          0 :         if (buff_size > I40E_AQ_LARGE_BUF)
    4297                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    4298                 :            : 
    4299                 :          0 :         status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
    4300                 :          0 :         *data_size = LE16_TO_CPU(desc.datalen);
    4301                 :            : 
    4302         [ #  # ]:          0 :         if (status)
    4303                 :          0 :                 goto exit;
    4304                 :            : 
    4305                 :          0 :         i40e_parse_discover_capabilities(hw, buff, LE32_TO_CPU(cmd->count),
    4306                 :            :                                          list_type_opc);
    4307                 :            : 
    4308                 :          0 : exit:
    4309                 :          0 :         return status;
    4310                 :            : }
    4311                 :            : 
    4312                 :            : /**
    4313                 :            :  * i40e_aq_update_nvm
    4314                 :            :  * @hw: pointer to the hw struct
    4315                 :            :  * @module_pointer: module pointer location in words from the NVM beginning
    4316                 :            :  * @offset: byte offset from the module beginning
    4317                 :            :  * @length: length of the section to be written (in bytes from the offset)
    4318                 :            :  * @data: command buffer (size [bytes] = length)
    4319                 :            :  * @last_command: tells if this is the last command in a series
    4320                 :            :  * @preservation_flags: Preservation mode flags
    4321                 :            :  * @cmd_details: pointer to command details structure or NULL
    4322                 :            :  *
    4323                 :            :  * Update the NVM using the admin queue commands
    4324                 :            :  **/
    4325                 :          0 : enum i40e_status_code i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
    4326                 :            :                                 u32 offset, u16 length, void *data,
    4327                 :            :                                 bool last_command, u8 preservation_flags,
    4328                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    4329                 :            : {
    4330                 :            :         struct i40e_aq_desc desc;
    4331                 :            :         struct i40e_aqc_nvm_update *cmd =
    4332                 :            :                 (struct i40e_aqc_nvm_update *)&desc.params.raw;
    4333                 :            :         enum i40e_status_code status;
    4334                 :            : 
    4335                 :          0 :         DEBUGFUNC("i40e_aq_update_nvm");
    4336                 :            : 
    4337                 :            :         /* In offset the highest byte must be zeroed. */
    4338         [ #  # ]:          0 :         if (offset & 0xFF000000) {
    4339                 :            :                 status = I40E_ERR_PARAM;
    4340                 :          0 :                 goto i40e_aq_update_nvm_exit;
    4341                 :            :         }
    4342                 :            : 
    4343                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
    4344                 :            : 
    4345                 :            :         /* If this is the last command in a series, set the proper flag. */
    4346         [ #  # ]:          0 :         if (last_command)
    4347                 :          0 :                 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
    4348         [ #  # ]:          0 :         if (hw->mac.type == I40E_MAC_X722) {
    4349         [ #  # ]:          0 :                 if (preservation_flags == I40E_NVM_PRESERVATION_FLAGS_SELECTED)
    4350                 :          0 :                         cmd->command_flags |=
    4351                 :            :                                 (I40E_AQ_NVM_PRESERVATION_FLAGS_SELECTED <<
    4352                 :            :                                  I40E_AQ_NVM_PRESERVATION_FLAGS_SHIFT);
    4353         [ #  # ]:          0 :                 else if (preservation_flags == I40E_NVM_PRESERVATION_FLAGS_ALL)
    4354                 :          0 :                         cmd->command_flags |=
    4355                 :            :                                 (I40E_AQ_NVM_PRESERVATION_FLAGS_ALL <<
    4356                 :            :                                  I40E_AQ_NVM_PRESERVATION_FLAGS_SHIFT);
    4357                 :            :         }
    4358                 :          0 :         cmd->module_pointer = module_pointer;
    4359                 :          0 :         cmd->offset = CPU_TO_LE32(offset);
    4360                 :          0 :         cmd->length = CPU_TO_LE16(length);
    4361                 :            : 
    4362                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    4363         [ #  # ]:          0 :         if (length > I40E_AQ_LARGE_BUF)
    4364                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    4365                 :            : 
    4366                 :          0 :         status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
    4367                 :            : 
    4368                 :          0 : i40e_aq_update_nvm_exit:
    4369                 :          0 :         return status;
    4370                 :            : }
    4371                 :            : 
    4372                 :            : /**
    4373                 :            :  * i40e_aq_rearrange_nvm
    4374                 :            :  * @hw: pointer to the hw struct
    4375                 :            :  * @rearrange_nvm: defines direction of rearrangement
    4376                 :            :  * @cmd_details: pointer to command details structure or NULL
    4377                 :            :  *
    4378                 :            :  * Rearrange NVM structure, available only for transition FW
    4379                 :            :  **/
    4380                 :          0 : enum i40e_status_code i40e_aq_rearrange_nvm(struct i40e_hw *hw,
    4381                 :            :                                 u8 rearrange_nvm,
    4382                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    4383                 :            : {
    4384                 :            :         struct i40e_aqc_nvm_update *cmd;
    4385                 :            :         enum i40e_status_code status;
    4386                 :            :         struct i40e_aq_desc desc;
    4387                 :            : 
    4388                 :          0 :         DEBUGFUNC("i40e_aq_rearrange_nvm");
    4389                 :            : 
    4390                 :            :         cmd = (struct i40e_aqc_nvm_update *)&desc.params.raw;
    4391                 :            : 
    4392                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
    4393                 :            : 
    4394                 :          0 :         rearrange_nvm &= (I40E_AQ_NVM_REARRANGE_TO_FLAT |
    4395                 :            :                          I40E_AQ_NVM_REARRANGE_TO_STRUCT);
    4396                 :            : 
    4397         [ #  # ]:          0 :         if (!rearrange_nvm) {
    4398                 :            :                 status = I40E_ERR_PARAM;
    4399                 :          0 :                 goto i40e_aq_rearrange_nvm_exit;
    4400                 :            :         }
    4401                 :            : 
    4402                 :          0 :         cmd->command_flags |= rearrange_nvm;
    4403                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    4404                 :            : 
    4405                 :          0 : i40e_aq_rearrange_nvm_exit:
    4406                 :          0 :         return status;
    4407                 :            : }
    4408                 :            : 
    4409                 :            : /**
    4410                 :            :  * i40e_aq_get_lldp_mib
    4411                 :            :  * @hw: pointer to the hw struct
    4412                 :            :  * @bridge_type: type of bridge requested
    4413                 :            :  * @mib_type: Local, Remote or both Local and Remote MIBs
    4414                 :            :  * @buff: pointer to a user supplied buffer to store the MIB block
    4415                 :            :  * @buff_size: size of the buffer (in bytes)
    4416                 :            :  * @local_len : length of the returned Local LLDP MIB
    4417                 :            :  * @remote_len: length of the returned Remote LLDP MIB
    4418                 :            :  * @cmd_details: pointer to command details structure or NULL
    4419                 :            :  *
    4420                 :            :  * Requests the complete LLDP MIB (entire packet).
    4421                 :            :  **/
    4422                 :          0 : enum i40e_status_code i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
    4423                 :            :                                 u8 mib_type, void *buff, u16 buff_size,
    4424                 :            :                                 u16 *local_len, u16 *remote_len,
    4425                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    4426                 :            : {
    4427                 :            :         struct i40e_aq_desc desc;
    4428                 :            :         struct i40e_aqc_lldp_get_mib *cmd =
    4429                 :            :                 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
    4430                 :            :         struct i40e_aqc_lldp_get_mib *resp =
    4431                 :            :                 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
    4432                 :            :         enum i40e_status_code status;
    4433                 :            : 
    4434         [ #  # ]:          0 :         if (buff_size == 0 || !buff)
    4435                 :            :                 return I40E_ERR_PARAM;
    4436                 :            : 
    4437                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
    4438                 :            :         /* Indirect Command */
    4439                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    4440                 :            : 
    4441                 :          0 :         cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
    4442                 :          0 :         cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
    4443                 :            :                        I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
    4444                 :            : 
    4445                 :          0 :         desc.datalen = CPU_TO_LE16(buff_size);
    4446                 :            : 
    4447                 :            :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    4448         [ #  # ]:          0 :         if (buff_size > I40E_AQ_LARGE_BUF)
    4449                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    4450                 :            : 
    4451                 :          0 :         status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
    4452         [ #  # ]:          0 :         if (!status) {
    4453         [ #  # ]:          0 :                 if (local_len != NULL)
    4454                 :          0 :                         *local_len = LE16_TO_CPU(resp->local_len);
    4455         [ #  # ]:          0 :                 if (remote_len != NULL)
    4456                 :          0 :                         *remote_len = LE16_TO_CPU(resp->remote_len);
    4457                 :            :         }
    4458                 :            : 
    4459                 :            :         return status;
    4460                 :            : }
    4461                 :            : 
    4462                 :            :  /**
    4463                 :            :  * i40e_aq_set_lldp_mib - Set the LLDP MIB
    4464                 :            :  * @hw: pointer to the hw struct
    4465                 :            :  * @mib_type: Local, Remote or both Local and Remote MIBs
    4466                 :            :  * @buff: pointer to a user supplied buffer to store the MIB block
    4467                 :            :  * @buff_size: size of the buffer (in bytes)
    4468                 :            :  * @cmd_details: pointer to command details structure or NULL
    4469                 :            :  *
    4470                 :            :  * Set the LLDP MIB.
    4471                 :            :  **/
    4472                 :          0 : enum i40e_status_code i40e_aq_set_lldp_mib(struct i40e_hw *hw,
    4473                 :            :                                 u8 mib_type, void *buff, u16 buff_size,
    4474                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    4475                 :            : {
    4476                 :            :         struct i40e_aq_desc desc;
    4477                 :            :         struct i40e_aqc_lldp_set_local_mib *cmd =
    4478                 :            :                 (struct i40e_aqc_lldp_set_local_mib *)&desc.params.raw;
    4479                 :            :         enum i40e_status_code status;
    4480                 :            : 
    4481         [ #  # ]:          0 :         if (buff_size == 0 || !buff)
    4482                 :            :                 return I40E_ERR_PARAM;
    4483                 :            : 
    4484                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    4485                 :            :                                 i40e_aqc_opc_lldp_set_local_mib);
    4486                 :            :         /* Indirect Command */
    4487                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    4488         [ #  # ]:          0 :         if (buff_size > I40E_AQ_LARGE_BUF)
    4489                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    4490                 :          0 :         desc.datalen = CPU_TO_LE16(buff_size);
    4491                 :            : 
    4492                 :          0 :         cmd->type = mib_type;
    4493                 :          0 :         cmd->length = CPU_TO_LE16(buff_size);
    4494                 :          0 :         cmd->address_high = CPU_TO_LE32(I40E_HI_DWORD((u64)buff));
    4495                 :          0 :         cmd->address_low =  CPU_TO_LE32(I40E_LO_DWORD((u64)buff));
    4496                 :            : 
    4497                 :          0 :         status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
    4498                 :          0 :         return status;
    4499                 :            : }
    4500                 :            : 
    4501                 :            : /**
    4502                 :            :  * i40e_aq_cfg_lldp_mib_change_event
    4503                 :            :  * @hw: pointer to the hw struct
    4504                 :            :  * @enable_update: Enable or Disable event posting
    4505                 :            :  * @cmd_details: pointer to command details structure or NULL
    4506                 :            :  *
    4507                 :            :  * Enable or Disable posting of an event on ARQ when LLDP MIB
    4508                 :            :  * associated with the interface changes
    4509                 :            :  **/
    4510                 :          0 : enum i40e_status_code i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
    4511                 :            :                                 bool enable_update,
    4512                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    4513                 :            : {
    4514                 :            :         struct i40e_aq_desc desc;
    4515                 :            :         struct i40e_aqc_lldp_update_mib *cmd =
    4516                 :            :                 (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
    4517                 :            :         enum i40e_status_code status;
    4518                 :            : 
    4519                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
    4520                 :            : 
    4521         [ #  # ]:          0 :         if (!enable_update)
    4522                 :          0 :                 cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
    4523                 :            : 
    4524                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    4525                 :            : 
    4526                 :          0 :         return status;
    4527                 :            : }
    4528                 :            : 
    4529                 :            : /**
    4530                 :            :  * i40e_aq_restore_lldp
    4531                 :            :  * @hw: pointer to the hw struct
    4532                 :            :  * @setting: pointer to factory setting variable or NULL
    4533                 :            :  * @restore: True if factory settings should be restored
    4534                 :            :  * @cmd_details: pointer to command details structure or NULL
    4535                 :            :  *
    4536                 :            :  * Restore LLDP Agent factory settings if @restore set to True. In other case
    4537                 :            :  * only returns factory setting in AQ response.
    4538                 :            :  **/
    4539                 :            : enum i40e_status_code
    4540                 :          0 : i40e_aq_restore_lldp(struct i40e_hw *hw, u8 *setting, bool restore,
    4541                 :            :                      struct i40e_asq_cmd_details *cmd_details)
    4542                 :            : {
    4543                 :            :         struct i40e_aq_desc desc;
    4544                 :            :         struct i40e_aqc_lldp_restore *cmd =
    4545                 :            :                 (struct i40e_aqc_lldp_restore *)&desc.params.raw;
    4546                 :            :         enum i40e_status_code status;
    4547                 :            : 
    4548         [ #  # ]:          0 :         if (!(hw->flags & I40E_HW_FLAG_FW_LLDP_PERSISTENT)) {
    4549         [ #  # ]:          0 :                 i40e_debug(hw, I40E_DEBUG_ALL,
    4550                 :            :                            "Restore LLDP not supported by current FW version.\n");
    4551                 :          0 :                 return I40E_ERR_DEVICE_NOT_SUPPORTED;
    4552                 :            :         }
    4553                 :            : 
    4554                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_restore);
    4555                 :            : 
    4556         [ #  # ]:          0 :         if (restore)
    4557                 :          0 :                 cmd->command |= I40E_AQ_LLDP_AGENT_RESTORE;
    4558                 :            : 
    4559                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    4560                 :            : 
    4561         [ #  # ]:          0 :         if (setting)
    4562                 :          0 :                 *setting = cmd->command & 1;
    4563                 :            : 
    4564                 :            :         return status;
    4565                 :            : }
    4566                 :            : 
    4567                 :            : /**
    4568                 :            :  * i40e_aq_stop_lldp
    4569                 :            :  * @hw: pointer to the hw struct
    4570                 :            :  * @shutdown_agent: True if LLDP Agent needs to be Shutdown
    4571                 :            :  * @persist: True if stop of LLDP should be persistent across power cycles
    4572                 :            :  * @cmd_details: pointer to command details structure or NULL
    4573                 :            :  *
    4574                 :            :  * Stop or Shutdown the embedded LLDP Agent
    4575                 :            :  **/
    4576                 :          0 : enum i40e_status_code i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
    4577                 :            :                                 bool persist,
    4578                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    4579                 :            : {
    4580                 :            :         struct i40e_aq_desc desc;
    4581                 :            :         struct i40e_aqc_lldp_stop *cmd =
    4582                 :            :                 (struct i40e_aqc_lldp_stop *)&desc.params.raw;
    4583                 :            :         enum i40e_status_code status;
    4584                 :            : 
    4585                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
    4586                 :            : 
    4587         [ #  # ]:          0 :         if (shutdown_agent)
    4588                 :          0 :                 cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
    4589                 :            : 
    4590         [ #  # ]:          0 :         if (persist) {
    4591         [ #  # ]:          0 :                 if (hw->flags & I40E_HW_FLAG_FW_LLDP_PERSISTENT)
    4592                 :          0 :                         cmd->command |= I40E_AQ_LLDP_AGENT_STOP_PERSIST;
    4593                 :            :                 else
    4594         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_ALL,
    4595                 :            :                                    "Persistent Stop LLDP not supported by current FW version.\n");
    4596                 :            :         }
    4597                 :            : 
    4598                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    4599                 :            : 
    4600                 :          0 :         return status;
    4601                 :            : }
    4602                 :            : 
    4603                 :            : /**
    4604                 :            :  * i40e_aq_start_lldp
    4605                 :            :  * @hw: pointer to the hw struct
    4606                 :            :  * @persist: True if start of LLDP should be persistent across power cycles
    4607                 :            :  * @cmd_details: pointer to command details structure or NULL
    4608                 :            :  *
    4609                 :            :  * Start the embedded LLDP Agent on all ports.
    4610                 :            :  **/
    4611                 :          0 : enum i40e_status_code i40e_aq_start_lldp(struct i40e_hw *hw,
    4612                 :            :                                 bool persist,
    4613                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    4614                 :            : {
    4615                 :            :         struct i40e_aq_desc desc;
    4616                 :            :         struct i40e_aqc_lldp_start *cmd =
    4617                 :            :                 (struct i40e_aqc_lldp_start *)&desc.params.raw;
    4618                 :            :         enum i40e_status_code status;
    4619                 :            : 
    4620                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
    4621                 :            : 
    4622                 :          0 :         cmd->command = I40E_AQ_LLDP_AGENT_START;
    4623                 :            : 
    4624         [ #  # ]:          0 :         if (persist) {
    4625         [ #  # ]:          0 :                 if (hw->flags & I40E_HW_FLAG_FW_LLDP_PERSISTENT)
    4626                 :          0 :                         cmd->command |= I40E_AQ_LLDP_AGENT_START_PERSIST;
    4627                 :            :                 else
    4628         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_ALL,
    4629                 :            :                                    "Persistent Start LLDP not supported by current FW version.\n");
    4630                 :            :         }
    4631                 :            : 
    4632                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    4633                 :            : 
    4634                 :          0 :         return status;
    4635                 :            : }
    4636                 :            : 
    4637                 :            : /**
    4638                 :            :  * i40e_aq_set_dcb_parameters
    4639                 :            :  * @hw: pointer to the hw struct
    4640                 :            :  * @cmd_details: pointer to command details structure or NULL
    4641                 :            :  * @dcb_enable: True if DCB configuration needs to be applied
    4642                 :            :  *
    4643                 :            :  **/
    4644                 :            : enum i40e_status_code
    4645                 :          0 : i40e_aq_set_dcb_parameters(struct i40e_hw *hw, bool dcb_enable,
    4646                 :            :                            struct i40e_asq_cmd_details *cmd_details)
    4647                 :            : {
    4648                 :            :         struct i40e_aq_desc desc;
    4649                 :            :         struct i40e_aqc_set_dcb_parameters *cmd =
    4650                 :            :                 (struct i40e_aqc_set_dcb_parameters *)&desc.params.raw;
    4651                 :            :         enum i40e_status_code status;
    4652                 :            : 
    4653         [ #  # ]:          0 :         if (!(hw->flags & I40E_HW_FLAG_FW_LLDP_STOPPABLE))
    4654                 :            :                 return I40E_ERR_DEVICE_NOT_SUPPORTED;
    4655                 :            : 
    4656                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    4657                 :            :                                           i40e_aqc_opc_set_dcb_parameters);
    4658                 :            : 
    4659         [ #  # ]:          0 :         if (dcb_enable) {
    4660                 :          0 :                 cmd->valid_flags = I40E_DCB_VALID;
    4661                 :          0 :                 cmd->command = I40E_AQ_DCB_SET_AGENT;
    4662                 :            :         }
    4663                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    4664                 :            : 
    4665                 :          0 :         return status;
    4666                 :            : }
    4667                 :            : 
    4668                 :            : /**
    4669                 :            :  * i40e_aq_get_cee_dcb_config
    4670                 :            :  * @hw: pointer to the hw struct
    4671                 :            :  * @buff: response buffer that stores CEE operational configuration
    4672                 :            :  * @buff_size: size of the buffer passed
    4673                 :            :  * @cmd_details: pointer to command details structure or NULL
    4674                 :            :  *
    4675                 :            :  * Get CEE DCBX mode operational configuration from firmware
    4676                 :            :  **/
    4677                 :          0 : enum i40e_status_code i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
    4678                 :            :                                 void *buff, u16 buff_size,
    4679                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    4680                 :            : {
    4681                 :            :         struct i40e_aq_desc desc;
    4682                 :            :         enum i40e_status_code status;
    4683                 :            : 
    4684         [ #  # ]:          0 :         if (buff_size == 0 || !buff)
    4685                 :            :                 return I40E_ERR_PARAM;
    4686                 :            : 
    4687                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
    4688                 :            : 
    4689                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    4690                 :          0 :         status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
    4691                 :            :                                        cmd_details);
    4692                 :            : 
    4693                 :          0 :         return status;
    4694                 :            : }
    4695                 :            : 
    4696                 :            : /**
    4697                 :            :  * i40e_aq_start_stop_dcbx - Start/Stop DCBx service in FW
    4698                 :            :  * @hw: pointer to the hw struct
    4699                 :            :  * @start_agent: True if DCBx Agent needs to be Started
    4700                 :            :  *                              False if DCBx Agent needs to be Stopped
    4701                 :            :  * @cmd_details: pointer to command details structure or NULL
    4702                 :            :  *
    4703                 :            :  * Start/Stop the embedded dcbx Agent
    4704                 :            :  **/
    4705                 :          0 : enum i40e_status_code i40e_aq_start_stop_dcbx(struct i40e_hw *hw,
    4706                 :            :                                 bool start_agent,
    4707                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    4708                 :            : {
    4709                 :            :         struct i40e_aq_desc desc;
    4710                 :            :         struct i40e_aqc_lldp_stop_start_specific_agent *cmd =
    4711                 :            :                 (struct i40e_aqc_lldp_stop_start_specific_agent *)
    4712                 :            :                                 &desc.params.raw;
    4713                 :            :         enum i40e_status_code status;
    4714                 :            : 
    4715                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    4716                 :            :                                 i40e_aqc_opc_lldp_stop_start_spec_agent);
    4717                 :            : 
    4718         [ #  # ]:          0 :         if (start_agent)
    4719                 :          0 :                 cmd->command = I40E_AQC_START_SPECIFIC_AGENT_MASK;
    4720                 :            : 
    4721                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    4722                 :            : 
    4723                 :          0 :         return status;
    4724                 :            : }
    4725                 :            : 
    4726                 :            : /**
    4727                 :            :  * i40e_aq_add_udp_tunnel
    4728                 :            :  * @hw: pointer to the hw struct
    4729                 :            :  * @udp_port: the UDP port to add in Host byte order
    4730                 :            :  * @protocol_index: protocol index type
    4731                 :            :  * @filter_index: pointer to filter index
    4732                 :            :  * @cmd_details: pointer to command details structure or NULL
    4733                 :            :  *
    4734                 :            :  * Note: Firmware expects the udp_port value to be in Little Endian format,
    4735                 :            :  * and this function will call CPU_TO_LE16 to convert from Host byte order to
    4736                 :            :  * Little Endian order.
    4737                 :            :  **/
    4738                 :          0 : enum i40e_status_code i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
    4739                 :            :                                 u16 udp_port, u8 protocol_index,
    4740                 :            :                                 u8 *filter_index,
    4741                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    4742                 :            : {
    4743                 :            :         struct i40e_aq_desc desc;
    4744                 :            :         struct i40e_aqc_add_udp_tunnel *cmd =
    4745                 :            :                 (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
    4746                 :            :         struct i40e_aqc_del_udp_tunnel_completion *resp =
    4747                 :            :                 (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
    4748                 :            :         enum i40e_status_code status;
    4749                 :            : 
    4750                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
    4751                 :            : 
    4752                 :          0 :         cmd->udp_port = CPU_TO_LE16(udp_port);
    4753                 :          0 :         cmd->protocol_type = protocol_index;
    4754                 :            : 
    4755                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    4756                 :            : 
    4757         [ #  # ]:          0 :         if (!status && filter_index)
    4758                 :          0 :                 *filter_index = resp->index;
    4759                 :            : 
    4760                 :          0 :         return status;
    4761                 :            : }
    4762                 :            : 
    4763                 :            : /**
    4764                 :            :  * i40e_aq_del_udp_tunnel
    4765                 :            :  * @hw: pointer to the hw struct
    4766                 :            :  * @index: filter index
    4767                 :            :  * @cmd_details: pointer to command details structure or NULL
    4768                 :            :  **/
    4769                 :          0 : enum i40e_status_code i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
    4770                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    4771                 :            : {
    4772                 :            :         struct i40e_aq_desc desc;
    4773                 :            :         struct i40e_aqc_remove_udp_tunnel *cmd =
    4774                 :            :                 (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
    4775                 :            :         enum i40e_status_code status;
    4776                 :            : 
    4777                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
    4778                 :            : 
    4779                 :          0 :         cmd->index = index;
    4780                 :            : 
    4781                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    4782                 :            : 
    4783                 :          0 :         return status;
    4784                 :            : }
    4785                 :            : 
    4786                 :            : /**
    4787                 :            :  * i40e_aq_get_switch_resource_alloc - command (0x0204) to get allocations
    4788                 :            :  * @hw: pointer to the hw struct
    4789                 :            :  * @num_entries: pointer to u8 to store the number of resource entries returned
    4790                 :            :  * @buf: pointer to a user supplied buffer.  This buffer must be large enough
    4791                 :            :  *        to store the resource information for all resource types.  Each
    4792                 :            :  *        resource type is a i40e_aqc_switch_resource_alloc_data structure.
    4793                 :            :  * @count: size, in bytes, of the buffer provided
    4794                 :            :  * @cmd_details: pointer to command details structure or NULL
    4795                 :            :  *
    4796                 :            :  * Query the resources allocated to a function.
    4797                 :            :  **/
    4798                 :          0 : enum i40e_status_code i40e_aq_get_switch_resource_alloc(struct i40e_hw *hw,
    4799                 :            :                         u8 *num_entries,
    4800                 :            :                         struct i40e_aqc_switch_resource_alloc_element_resp *buf,
    4801                 :            :                         u16 count,
    4802                 :            :                         struct i40e_asq_cmd_details *cmd_details)
    4803                 :            : {
    4804                 :            :         struct i40e_aq_desc desc;
    4805                 :            :         struct i40e_aqc_get_switch_resource_alloc *cmd_resp =
    4806                 :            :                 (struct i40e_aqc_get_switch_resource_alloc *)&desc.params.raw;
    4807                 :            :         enum i40e_status_code status;
    4808                 :          0 :         u16 length = count * sizeof(*buf);
    4809                 :            : 
    4810                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    4811                 :            :                                         i40e_aqc_opc_get_switch_resource_alloc);
    4812                 :            : 
    4813                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    4814         [ #  # ]:          0 :         if (length > I40E_AQ_LARGE_BUF)
    4815                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    4816                 :            : 
    4817                 :          0 :         status = i40e_asq_send_command(hw, &desc, buf, length, cmd_details);
    4818                 :            : 
    4819         [ #  # ]:          0 :         if (!status && num_entries)
    4820                 :          0 :                 *num_entries = cmd_resp->num_entries;
    4821                 :            : 
    4822                 :          0 :         return status;
    4823                 :            : }
    4824                 :            : 
    4825                 :            : /**
    4826                 :            :  * i40e_aq_delete_element - Delete switch element
    4827                 :            :  * @hw: pointer to the hw struct
    4828                 :            :  * @seid: the SEID to delete from the switch
    4829                 :            :  * @cmd_details: pointer to command details structure or NULL
    4830                 :            :  *
    4831                 :            :  * This deletes a switch element from the switch.
    4832                 :            :  **/
    4833                 :          0 : enum i40e_status_code i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
    4834                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    4835                 :            : {
    4836                 :            :         struct i40e_aq_desc desc;
    4837                 :            :         struct i40e_aqc_switch_seid *cmd =
    4838                 :            :                 (struct i40e_aqc_switch_seid *)&desc.params.raw;
    4839                 :            :         enum i40e_status_code status;
    4840                 :            : 
    4841         [ #  # ]:          0 :         if (seid == 0)
    4842                 :            :                 return I40E_ERR_PARAM;
    4843                 :            : 
    4844                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
    4845                 :            : 
    4846                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    4847                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    4848                 :            : 
    4849                 :          0 :         return status;
    4850                 :            : }
    4851                 :            : 
    4852                 :            : /**
    4853                 :            :  * i40e_aq_add_pvirt - Instantiate a Port Virtualizer on a port
    4854                 :            :  * @hw: pointer to the hw struct
    4855                 :            :  * @flags: component flags
    4856                 :            :  * @mac_seid: uplink seid (MAC SEID)
    4857                 :            :  * @vsi_seid: connected vsi seid
    4858                 :            :  * @ret_seid: seid of create pv component
    4859                 :            :  *
    4860                 :            :  * This instantiates an i40e port virtualizer with specified flags.
    4861                 :            :  * Depending on specified flags the port virtualizer can act as a
    4862                 :            :  * 802.1Qbr port virtualizer or a 802.1Qbg S-component.
    4863                 :            :  */
    4864                 :          0 : enum i40e_status_code i40e_aq_add_pvirt(struct i40e_hw *hw, u16 flags,
    4865                 :            :                                        u16 mac_seid, u16 vsi_seid,
    4866                 :            :                                        u16 *ret_seid)
    4867                 :            : {
    4868                 :            :         struct i40e_aq_desc desc;
    4869                 :            :         struct i40e_aqc_add_update_pv *cmd =
    4870                 :            :                 (struct i40e_aqc_add_update_pv *)&desc.params.raw;
    4871                 :            :         struct i40e_aqc_add_update_pv_completion *resp =
    4872                 :            :                 (struct i40e_aqc_add_update_pv_completion *)&desc.params.raw;
    4873                 :            :         enum i40e_status_code status;
    4874                 :            : 
    4875         [ #  # ]:          0 :         if (vsi_seid == 0)
    4876                 :            :                 return I40E_ERR_PARAM;
    4877                 :            : 
    4878                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_pv);
    4879                 :          0 :         cmd->command_flags = CPU_TO_LE16(flags);
    4880                 :          0 :         cmd->uplink_seid = CPU_TO_LE16(mac_seid);
    4881                 :          0 :         cmd->connected_seid = CPU_TO_LE16(vsi_seid);
    4882                 :            : 
    4883                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
    4884         [ #  # ]:          0 :         if (!status && ret_seid)
    4885                 :          0 :                 *ret_seid = LE16_TO_CPU(resp->pv_seid);
    4886                 :            : 
    4887                 :            :         return status;
    4888                 :            : }
    4889                 :            : 
    4890                 :            : /**
    4891                 :            :  * i40e_aq_add_tag - Add an S/E-tag
    4892                 :            :  * @hw: pointer to the hw struct
    4893                 :            :  * @direct_to_queue: should s-tag direct flow to a specific queue
    4894                 :            :  * @vsi_seid: VSI SEID to use this tag
    4895                 :            :  * @tag: value of the tag
    4896                 :            :  * @queue_num: queue number, only valid is direct_to_queue is true
    4897                 :            :  * @tags_used: return value, number of tags in use by this PF
    4898                 :            :  * @tags_free: return value, number of unallocated tags
    4899                 :            :  * @cmd_details: pointer to command details structure or NULL
    4900                 :            :  *
    4901                 :            :  * This associates an S- or E-tag to a VSI in the switch complex.  It returns
    4902                 :            :  * the number of tags allocated by the PF, and the number of unallocated
    4903                 :            :  * tags available.
    4904                 :            :  **/
    4905                 :          0 : enum i40e_status_code i40e_aq_add_tag(struct i40e_hw *hw, bool direct_to_queue,
    4906                 :            :                                 u16 vsi_seid, u16 tag, u16 queue_num,
    4907                 :            :                                 u16 *tags_used, u16 *tags_free,
    4908                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    4909                 :            : {
    4910                 :            :         struct i40e_aq_desc desc;
    4911                 :            :         struct i40e_aqc_add_tag *cmd =
    4912                 :            :                 (struct i40e_aqc_add_tag *)&desc.params.raw;
    4913                 :            :         struct i40e_aqc_add_remove_tag_completion *resp =
    4914                 :            :                 (struct i40e_aqc_add_remove_tag_completion *)&desc.params.raw;
    4915                 :            :         enum i40e_status_code status;
    4916                 :            : 
    4917         [ #  # ]:          0 :         if (vsi_seid == 0)
    4918                 :            :                 return I40E_ERR_PARAM;
    4919                 :            : 
    4920                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_tag);
    4921                 :            : 
    4922                 :          0 :         cmd->seid = CPU_TO_LE16(vsi_seid);
    4923                 :          0 :         cmd->tag = CPU_TO_LE16(tag);
    4924         [ #  # ]:          0 :         if (direct_to_queue) {
    4925                 :          0 :                 cmd->flags = CPU_TO_LE16(I40E_AQC_ADD_TAG_FLAG_TO_QUEUE);
    4926                 :          0 :                 cmd->queue_number = CPU_TO_LE16(queue_num);
    4927                 :            :         }
    4928                 :            : 
    4929                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    4930                 :            : 
    4931         [ #  # ]:          0 :         if (!status) {
    4932         [ #  # ]:          0 :                 if (tags_used != NULL)
    4933                 :          0 :                         *tags_used = LE16_TO_CPU(resp->tags_used);
    4934         [ #  # ]:          0 :                 if (tags_free != NULL)
    4935                 :          0 :                         *tags_free = LE16_TO_CPU(resp->tags_free);
    4936                 :            :         }
    4937                 :            : 
    4938                 :            :         return status;
    4939                 :            : }
    4940                 :            : 
    4941                 :            : /**
    4942                 :            :  * i40e_aq_remove_tag - Remove an S- or E-tag
    4943                 :            :  * @hw: pointer to the hw struct
    4944                 :            :  * @vsi_seid: VSI SEID this tag is associated with
    4945                 :            :  * @tag: value of the S-tag to delete
    4946                 :            :  * @tags_used: return value, number of tags in use by this PF
    4947                 :            :  * @tags_free: return value, number of unallocated tags
    4948                 :            :  * @cmd_details: pointer to command details structure or NULL
    4949                 :            :  *
    4950                 :            :  * This deletes an S- or E-tag from a VSI in the switch complex.  It returns
    4951                 :            :  * the number of tags allocated by the PF, and the number of unallocated
    4952                 :            :  * tags available.
    4953                 :            :  **/
    4954                 :          0 : enum i40e_status_code i40e_aq_remove_tag(struct i40e_hw *hw, u16 vsi_seid,
    4955                 :            :                                 u16 tag, u16 *tags_used, u16 *tags_free,
    4956                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    4957                 :            : {
    4958                 :            :         struct i40e_aq_desc desc;
    4959                 :            :         struct i40e_aqc_remove_tag *cmd =
    4960                 :            :                 (struct i40e_aqc_remove_tag *)&desc.params.raw;
    4961                 :            :         struct i40e_aqc_add_remove_tag_completion *resp =
    4962                 :            :                 (struct i40e_aqc_add_remove_tag_completion *)&desc.params.raw;
    4963                 :            :         enum i40e_status_code status;
    4964                 :            : 
    4965         [ #  # ]:          0 :         if (vsi_seid == 0)
    4966                 :            :                 return I40E_ERR_PARAM;
    4967                 :            : 
    4968                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_tag);
    4969                 :            : 
    4970                 :          0 :         cmd->seid = CPU_TO_LE16(vsi_seid);
    4971                 :          0 :         cmd->tag = CPU_TO_LE16(tag);
    4972                 :            : 
    4973                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    4974                 :            : 
    4975         [ #  # ]:          0 :         if (!status) {
    4976         [ #  # ]:          0 :                 if (tags_used != NULL)
    4977                 :          0 :                         *tags_used = LE16_TO_CPU(resp->tags_used);
    4978         [ #  # ]:          0 :                 if (tags_free != NULL)
    4979                 :          0 :                         *tags_free = LE16_TO_CPU(resp->tags_free);
    4980                 :            :         }
    4981                 :            : 
    4982                 :            :         return status;
    4983                 :            : }
    4984                 :            : 
    4985                 :            : /**
    4986                 :            :  * i40e_aq_add_mcast_etag - Add a multicast E-tag
    4987                 :            :  * @hw: pointer to the hw struct
    4988                 :            :  * @pv_seid: Port Virtualizer of this SEID to associate E-tag with
    4989                 :            :  * @etag: value of E-tag to add
    4990                 :            :  * @num_tags_in_buf: number of unicast E-tags in indirect buffer
    4991                 :            :  * @buf: address of indirect buffer
    4992                 :            :  * @tags_used: return value, number of E-tags in use by this port
    4993                 :            :  * @tags_free: return value, number of unallocated M-tags
    4994                 :            :  * @cmd_details: pointer to command details structure or NULL
    4995                 :            :  *
    4996                 :            :  * This associates a multicast E-tag to a port virtualizer.  It will return
    4997                 :            :  * the number of tags allocated by the PF, and the number of unallocated
    4998                 :            :  * tags available.
    4999                 :            :  *
    5000                 :            :  * The indirect buffer pointed to by buf is a list of 2-byte E-tags,
    5001                 :            :  * num_tags_in_buf long.
    5002                 :            :  **/
    5003                 :          0 : enum i40e_status_code i40e_aq_add_mcast_etag(struct i40e_hw *hw, u16 pv_seid,
    5004                 :            :                                 u16 etag, u8 num_tags_in_buf, void *buf,
    5005                 :            :                                 u16 *tags_used, u16 *tags_free,
    5006                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    5007                 :            : {
    5008                 :            :         struct i40e_aq_desc desc;
    5009                 :            :         struct i40e_aqc_add_remove_mcast_etag *cmd =
    5010                 :            :                 (struct i40e_aqc_add_remove_mcast_etag *)&desc.params.raw;
    5011                 :            :         struct i40e_aqc_add_remove_mcast_etag_completion *resp =
    5012                 :            :            (struct i40e_aqc_add_remove_mcast_etag_completion *)&desc.params.raw;
    5013                 :            :         enum i40e_status_code status;
    5014                 :          0 :         u16 length = sizeof(u16) * num_tags_in_buf;
    5015                 :            : 
    5016   [ #  #  #  # ]:          0 :         if ((pv_seid == 0) || (buf == NULL) || (num_tags_in_buf == 0))
    5017                 :            :                 return I40E_ERR_PARAM;
    5018                 :            : 
    5019                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    5020                 :            :                                           i40e_aqc_opc_add_multicast_etag);
    5021                 :            : 
    5022                 :          0 :         cmd->pv_seid = CPU_TO_LE16(pv_seid);
    5023                 :          0 :         cmd->etag = CPU_TO_LE16(etag);
    5024                 :          0 :         cmd->num_unicast_etags = num_tags_in_buf;
    5025                 :            : 
    5026                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    5027                 :            : 
    5028                 :          0 :         status = i40e_asq_send_command(hw, &desc, buf, length, cmd_details);
    5029                 :            : 
    5030         [ #  # ]:          0 :         if (!status) {
    5031         [ #  # ]:          0 :                 if (tags_used != NULL)
    5032                 :          0 :                         *tags_used = LE16_TO_CPU(resp->mcast_etags_used);
    5033         [ #  # ]:          0 :                 if (tags_free != NULL)
    5034                 :          0 :                         *tags_free = LE16_TO_CPU(resp->mcast_etags_free);
    5035                 :            :         }
    5036                 :            : 
    5037                 :            :         return status;
    5038                 :            : }
    5039                 :            : 
    5040                 :            : /**
    5041                 :            :  * i40e_aq_remove_mcast_etag - Remove a multicast E-tag
    5042                 :            :  * @hw: pointer to the hw struct
    5043                 :            :  * @pv_seid: Port Virtualizer SEID this M-tag is associated with
    5044                 :            :  * @etag: value of the E-tag to remove
    5045                 :            :  * @tags_used: return value, number of tags in use by this port
    5046                 :            :  * @tags_free: return value, number of unallocated tags
    5047                 :            :  * @cmd_details: pointer to command details structure or NULL
    5048                 :            :  *
    5049                 :            :  * This deletes an E-tag from the port virtualizer.  It will return
    5050                 :            :  * the number of tags allocated by the port, and the number of unallocated
    5051                 :            :  * tags available.
    5052                 :            :  **/
    5053                 :          0 : enum i40e_status_code i40e_aq_remove_mcast_etag(struct i40e_hw *hw, u16 pv_seid,
    5054                 :            :                                 u16 etag, u16 *tags_used, u16 *tags_free,
    5055                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    5056                 :            : {
    5057                 :            :         struct i40e_aq_desc desc;
    5058                 :            :         struct i40e_aqc_add_remove_mcast_etag *cmd =
    5059                 :            :                 (struct i40e_aqc_add_remove_mcast_etag *)&desc.params.raw;
    5060                 :            :         struct i40e_aqc_add_remove_mcast_etag_completion *resp =
    5061                 :            :            (struct i40e_aqc_add_remove_mcast_etag_completion *)&desc.params.raw;
    5062                 :            :         enum i40e_status_code status;
    5063                 :            : 
    5064                 :            : 
    5065         [ #  # ]:          0 :         if (pv_seid == 0)
    5066                 :            :                 return I40E_ERR_PARAM;
    5067                 :            : 
    5068                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    5069                 :            :                                           i40e_aqc_opc_remove_multicast_etag);
    5070                 :            : 
    5071                 :          0 :         cmd->pv_seid = CPU_TO_LE16(pv_seid);
    5072                 :          0 :         cmd->etag = CPU_TO_LE16(etag);
    5073                 :            : 
    5074                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    5075                 :            : 
    5076         [ #  # ]:          0 :         if (!status) {
    5077         [ #  # ]:          0 :                 if (tags_used != NULL)
    5078                 :          0 :                         *tags_used = LE16_TO_CPU(resp->mcast_etags_used);
    5079         [ #  # ]:          0 :                 if (tags_free != NULL)
    5080                 :          0 :                         *tags_free = LE16_TO_CPU(resp->mcast_etags_free);
    5081                 :            :         }
    5082                 :            : 
    5083                 :            :         return status;
    5084                 :            : }
    5085                 :            : 
    5086                 :            : /**
    5087                 :            :  * i40e_aq_update_tag - Update an S/E-tag
    5088                 :            :  * @hw: pointer to the hw struct
    5089                 :            :  * @vsi_seid: VSI SEID using this S-tag
    5090                 :            :  * @old_tag: old tag value
    5091                 :            :  * @new_tag: new tag value
    5092                 :            :  * @tags_used: return value, number of tags in use by this PF
    5093                 :            :  * @tags_free: return value, number of unallocated tags
    5094                 :            :  * @cmd_details: pointer to command details structure or NULL
    5095                 :            :  *
    5096                 :            :  * This updates the value of the tag currently attached to this VSI
    5097                 :            :  * in the switch complex.  It will return the number of tags allocated
    5098                 :            :  * by the PF, and the number of unallocated tags available.
    5099                 :            :  **/
    5100                 :          0 : enum i40e_status_code i40e_aq_update_tag(struct i40e_hw *hw, u16 vsi_seid,
    5101                 :            :                                 u16 old_tag, u16 new_tag, u16 *tags_used,
    5102                 :            :                                 u16 *tags_free,
    5103                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    5104                 :            : {
    5105                 :            :         struct i40e_aq_desc desc;
    5106                 :            :         struct i40e_aqc_update_tag *cmd =
    5107                 :            :                 (struct i40e_aqc_update_tag *)&desc.params.raw;
    5108                 :            :         struct i40e_aqc_update_tag_completion *resp =
    5109                 :            :                 (struct i40e_aqc_update_tag_completion *)&desc.params.raw;
    5110                 :            :         enum i40e_status_code status;
    5111                 :            : 
    5112         [ #  # ]:          0 :         if (vsi_seid == 0)
    5113                 :            :                 return I40E_ERR_PARAM;
    5114                 :            : 
    5115                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_update_tag);
    5116                 :            : 
    5117                 :          0 :         cmd->seid = CPU_TO_LE16(vsi_seid);
    5118                 :          0 :         cmd->old_tag = CPU_TO_LE16(old_tag);
    5119                 :          0 :         cmd->new_tag = CPU_TO_LE16(new_tag);
    5120                 :            : 
    5121                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    5122                 :            : 
    5123         [ #  # ]:          0 :         if (!status) {
    5124         [ #  # ]:          0 :                 if (tags_used != NULL)
    5125                 :          0 :                         *tags_used = LE16_TO_CPU(resp->tags_used);
    5126         [ #  # ]:          0 :                 if (tags_free != NULL)
    5127                 :          0 :                         *tags_free = LE16_TO_CPU(resp->tags_free);
    5128                 :            :         }
    5129                 :            : 
    5130                 :            :         return status;
    5131                 :            : }
    5132                 :            : 
    5133                 :            : /**
    5134                 :            :  * i40e_aq_dcb_ignore_pfc - Ignore PFC for given TCs
    5135                 :            :  * @hw: pointer to the hw struct
    5136                 :            :  * @tcmap: TC map for request/release any ignore PFC condition
    5137                 :            :  * @request: request or release ignore PFC condition
    5138                 :            :  * @tcmap_ret: return TCs for which PFC is currently ignored
    5139                 :            :  * @cmd_details: pointer to command details structure or NULL
    5140                 :            :  *
    5141                 :            :  * This sends out request/release to ignore PFC condition for a TC.
    5142                 :            :  * It will return the TCs for which PFC is currently ignored.
    5143                 :            :  **/
    5144                 :          0 : enum i40e_status_code i40e_aq_dcb_ignore_pfc(struct i40e_hw *hw, u8 tcmap,
    5145                 :            :                                 bool request, u8 *tcmap_ret,
    5146                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    5147                 :            : {
    5148                 :            :         struct i40e_aq_desc desc;
    5149                 :            :         struct i40e_aqc_pfc_ignore *cmd_resp =
    5150                 :            :                 (struct i40e_aqc_pfc_ignore *)&desc.params.raw;
    5151                 :            :         enum i40e_status_code status;
    5152                 :            : 
    5153                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_ignore_pfc);
    5154                 :            : 
    5155         [ #  # ]:          0 :         if (request)
    5156                 :          0 :                 cmd_resp->command_flags = I40E_AQC_PFC_IGNORE_SET;
    5157                 :            : 
    5158                 :          0 :         cmd_resp->tc_bitmap = tcmap;
    5159                 :            : 
    5160                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    5161                 :            : 
    5162         [ #  # ]:          0 :         if (!status) {
    5163         [ #  # ]:          0 :                 if (tcmap_ret != NULL)
    5164                 :          0 :                         *tcmap_ret = cmd_resp->tc_bitmap;
    5165                 :            :         }
    5166                 :            : 
    5167                 :          0 :         return status;
    5168                 :            : }
    5169                 :            : 
    5170                 :            : /**
    5171                 :            :  * i40e_aq_dcb_updated - DCB Updated Command
    5172                 :            :  * @hw: pointer to the hw struct
    5173                 :            :  * @cmd_details: pointer to command details structure or NULL
    5174                 :            :  *
    5175                 :            :  * When LLDP is handled in PF this command is used by the PF
    5176                 :            :  * to notify EMP that a DCB setting is modified.
    5177                 :            :  * When LLDP is handled in EMP this command is used by the PF
    5178                 :            :  * to notify EMP whenever one of the following parameters get
    5179                 :            :  * modified:
    5180                 :            :  *   - PFCLinkDelayAllowance in PRTDCB_GENC.PFCLDA
    5181                 :            :  *   - PCIRTT in PRTDCB_GENC.PCIRTT
    5182                 :            :  *   - Maximum Frame Size for non-FCoE TCs set by PRTDCB_TDPUC.MAX_TXFRAME.
    5183                 :            :  * EMP will return when the shared RPB settings have been
    5184                 :            :  * recomputed and modified. The retval field in the descriptor
    5185                 :            :  * will be set to 0 when RPB is modified.
    5186                 :            :  **/
    5187                 :          0 : enum i40e_status_code i40e_aq_dcb_updated(struct i40e_hw *hw,
    5188                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    5189                 :            : {
    5190                 :            :         struct i40e_aq_desc desc;
    5191                 :            :         enum i40e_status_code status;
    5192                 :            : 
    5193                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
    5194                 :            : 
    5195                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    5196                 :            : 
    5197                 :          0 :         return status;
    5198                 :            : }
    5199                 :            : 
    5200                 :            : /**
    5201                 :            :  * i40e_aq_add_statistics - Add a statistics block to a VLAN in a switch.
    5202                 :            :  * @hw: pointer to the hw struct
    5203                 :            :  * @seid: defines the SEID of the switch for which the stats are requested
    5204                 :            :  * @vlan_id: the VLAN ID for which the statistics are requested
    5205                 :            :  * @stat_index: index of the statistics counters block assigned to this VLAN
    5206                 :            :  * @cmd_details: pointer to command details structure or NULL
    5207                 :            :  *
    5208                 :            :  * XL710 supports 128 smonVlanStats counters.This command is used to
    5209                 :            :  * allocate a set of smonVlanStats counters to a specific VLAN in a specific
    5210                 :            :  * switch.
    5211                 :            :  **/
    5212                 :          0 : enum i40e_status_code i40e_aq_add_statistics(struct i40e_hw *hw, u16 seid,
    5213                 :            :                                 u16 vlan_id, u16 *stat_index,
    5214                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    5215                 :            : {
    5216                 :            :         struct i40e_aq_desc desc;
    5217                 :            :         struct i40e_aqc_add_remove_statistics *cmd_resp =
    5218                 :            :                 (struct i40e_aqc_add_remove_statistics *)&desc.params.raw;
    5219                 :            :         enum i40e_status_code status;
    5220                 :            : 
    5221         [ #  # ]:          0 :         if ((seid == 0) || (stat_index == NULL))
    5222                 :            :                 return I40E_ERR_PARAM;
    5223                 :            : 
    5224                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_statistics);
    5225                 :            : 
    5226                 :          0 :         cmd_resp->seid = CPU_TO_LE16(seid);
    5227                 :          0 :         cmd_resp->vlan = CPU_TO_LE16(vlan_id);
    5228                 :            : 
    5229                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    5230                 :            : 
    5231         [ #  # ]:          0 :         if (!status && stat_index)
    5232                 :          0 :                 *stat_index = LE16_TO_CPU(cmd_resp->stat_index);
    5233                 :            : 
    5234                 :            :         return status;
    5235                 :            : }
    5236                 :            : 
    5237                 :            : /**
    5238                 :            :  * i40e_aq_remove_statistics - Remove a statistics block to a VLAN in a switch.
    5239                 :            :  * @hw: pointer to the hw struct
    5240                 :            :  * @seid: defines the SEID of the switch for which the stats are requested
    5241                 :            :  * @vlan_id: the VLAN ID for which the statistics are requested
    5242                 :            :  * @stat_index: index of the statistics counters block assigned to this VLAN
    5243                 :            :  * @cmd_details: pointer to command details structure or NULL
    5244                 :            :  *
    5245                 :            :  * XL710 supports 128 smonVlanStats counters.This command is used to
    5246                 :            :  * deallocate a set of smonVlanStats counters to a specific VLAN in a specific
    5247                 :            :  * switch.
    5248                 :            :  **/
    5249                 :          0 : enum i40e_status_code i40e_aq_remove_statistics(struct i40e_hw *hw, u16 seid,
    5250                 :            :                                 u16 vlan_id, u16 stat_index,
    5251                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    5252                 :            : {
    5253                 :            :         struct i40e_aq_desc desc;
    5254                 :            :         struct i40e_aqc_add_remove_statistics *cmd =
    5255                 :            :                 (struct i40e_aqc_add_remove_statistics *)&desc.params.raw;
    5256                 :            :         enum i40e_status_code status;
    5257                 :            : 
    5258         [ #  # ]:          0 :         if (seid == 0)
    5259                 :            :                 return I40E_ERR_PARAM;
    5260                 :            : 
    5261                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    5262                 :            :                                           i40e_aqc_opc_remove_statistics);
    5263                 :            : 
    5264                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    5265                 :          0 :         cmd->vlan  = CPU_TO_LE16(vlan_id);
    5266                 :          0 :         cmd->stat_index = CPU_TO_LE16(stat_index);
    5267                 :            : 
    5268                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    5269                 :            : 
    5270                 :          0 :         return status;
    5271                 :            : }
    5272                 :            : 
    5273                 :            : /**
    5274                 :            :  * i40e_aq_set_port_parameters - set physical port parameters.
    5275                 :            :  * @hw: pointer to the hw struct
    5276                 :            :  * @bad_frame_vsi: defines the VSI to which bad frames are forwarded
    5277                 :            :  * @save_bad_pac: if set packets with errors are forwarded to the bad frames VSI
    5278                 :            :  * @pad_short_pac: if set transmit packets smaller than 60 bytes are padded
    5279                 :            :  * @double_vlan: if set double VLAN is enabled
    5280                 :            :  * @cmd_details: pointer to command details structure or NULL
    5281                 :            :  **/
    5282                 :          0 : enum i40e_status_code i40e_aq_set_port_parameters(struct i40e_hw *hw,
    5283                 :            :                                 u16 bad_frame_vsi, bool save_bad_pac,
    5284                 :            :                                 bool pad_short_pac, bool double_vlan,
    5285                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    5286                 :            : {
    5287                 :            :         struct i40e_aqc_set_port_parameters *cmd;
    5288                 :            :         enum i40e_status_code status;
    5289                 :            :         struct i40e_aq_desc desc;
    5290                 :            :         u16 command_flags = 0;
    5291                 :            : 
    5292                 :            :         cmd = (struct i40e_aqc_set_port_parameters *)&desc.params.raw;
    5293                 :            : 
    5294                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    5295                 :            :                                           i40e_aqc_opc_set_port_parameters);
    5296                 :            : 
    5297                 :          0 :         cmd->bad_frame_vsi = CPU_TO_LE16(bad_frame_vsi);
    5298         [ #  # ]:          0 :         if (save_bad_pac)
    5299                 :            :                 command_flags |= I40E_AQ_SET_P_PARAMS_SAVE_BAD_PACKETS;
    5300         [ #  # ]:          0 :         if (pad_short_pac)
    5301                 :          0 :                 command_flags |= I40E_AQ_SET_P_PARAMS_PAD_SHORT_PACKETS;
    5302         [ #  # ]:          0 :         if (double_vlan)
    5303                 :          0 :                 command_flags |= I40E_AQ_SET_P_PARAMS_DOUBLE_VLAN_ENA;
    5304                 :          0 :         cmd->command_flags = CPU_TO_LE16(command_flags);
    5305                 :            : 
    5306                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    5307                 :            : 
    5308                 :          0 :         return status;
    5309                 :            : }
    5310                 :            : 
    5311                 :            : /**
    5312                 :            :  * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
    5313                 :            :  * @hw: pointer to the hw struct
    5314                 :            :  * @seid: seid for the physical port/switching component/vsi
    5315                 :            :  * @buff: Indirect buffer to hold data parameters and response
    5316                 :            :  * @buff_size: Indirect buffer size
    5317                 :            :  * @opcode: Tx scheduler AQ command opcode
    5318                 :            :  * @cmd_details: pointer to command details structure or NULL
    5319                 :            :  *
    5320                 :            :  * Generic command handler for Tx scheduler AQ commands
    5321                 :            :  **/
    5322                 :          0 : static enum i40e_status_code i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
    5323                 :            :                                 void *buff, u16 buff_size,
    5324                 :            :                                  enum i40e_admin_queue_opc opcode,
    5325                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    5326                 :            : {
    5327                 :            :         struct i40e_aq_desc desc;
    5328                 :            :         struct i40e_aqc_tx_sched_ind *cmd =
    5329                 :            :                 (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
    5330                 :            :         enum i40e_status_code status;
    5331                 :            :         bool cmd_param_flag = false;
    5332                 :            : 
    5333      [ #  #  # ]:          0 :         switch (opcode) {
    5334                 :            :         case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
    5335                 :            :         case i40e_aqc_opc_configure_vsi_tc_bw:
    5336                 :            :         case i40e_aqc_opc_enable_switching_comp_ets:
    5337                 :            :         case i40e_aqc_opc_modify_switching_comp_ets:
    5338                 :            :         case i40e_aqc_opc_disable_switching_comp_ets:
    5339                 :            :         case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
    5340                 :            :         case i40e_aqc_opc_configure_switching_comp_bw_config:
    5341                 :            :                 cmd_param_flag = true;
    5342                 :            :                 break;
    5343                 :          0 :         case i40e_aqc_opc_query_vsi_bw_config:
    5344                 :            :         case i40e_aqc_opc_query_vsi_ets_sla_config:
    5345                 :            :         case i40e_aqc_opc_query_switching_comp_ets_config:
    5346                 :            :         case i40e_aqc_opc_query_port_ets_config:
    5347                 :            :         case i40e_aqc_opc_query_switching_comp_bw_config:
    5348                 :            :                 cmd_param_flag = false;
    5349                 :          0 :                 break;
    5350                 :            :         default:
    5351                 :            :                 return I40E_ERR_PARAM;
    5352                 :            :         }
    5353                 :            : 
    5354                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, opcode);
    5355                 :            : 
    5356                 :            :         /* Indirect command */
    5357                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    5358         [ #  # ]:          0 :         if (cmd_param_flag)
    5359                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
    5360         [ #  # ]:          0 :         if (buff_size > I40E_AQ_LARGE_BUF)
    5361                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    5362                 :            : 
    5363                 :          0 :         desc.datalen = CPU_TO_LE16(buff_size);
    5364                 :            : 
    5365                 :          0 :         cmd->vsi_seid = CPU_TO_LE16(seid);
    5366                 :            : 
    5367                 :          0 :         status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
    5368                 :            : 
    5369                 :          0 :         return status;
    5370                 :            : }
    5371                 :            : 
    5372                 :            : /**
    5373                 :            :  * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
    5374                 :            :  * @hw: pointer to the hw struct
    5375                 :            :  * @seid: VSI seid
    5376                 :            :  * @credit: BW limit credits (0 = disabled)
    5377                 :            :  * @max_credit: Max BW limit credits
    5378                 :            :  * @cmd_details: pointer to command details structure or NULL
    5379                 :            :  **/
    5380                 :          0 : enum i40e_status_code i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
    5381                 :            :                                 u16 seid, u16 credit, u8 max_credit,
    5382                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    5383                 :            : {
    5384                 :            :         struct i40e_aq_desc desc;
    5385                 :            :         struct i40e_aqc_configure_vsi_bw_limit *cmd =
    5386                 :            :                 (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
    5387                 :            :         enum i40e_status_code status;
    5388                 :            : 
    5389                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    5390                 :            :                                           i40e_aqc_opc_configure_vsi_bw_limit);
    5391                 :            : 
    5392                 :          0 :         cmd->vsi_seid = CPU_TO_LE16(seid);
    5393                 :          0 :         cmd->credit = CPU_TO_LE16(credit);
    5394                 :          0 :         cmd->max_credit = max_credit;
    5395                 :            : 
    5396                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    5397                 :            : 
    5398                 :          0 :         return status;
    5399                 :            : }
    5400                 :            : 
    5401                 :            : /**
    5402                 :            :  * i40e_aq_config_switch_comp_bw_limit - Configure Switching component BW Limit
    5403                 :            :  * @hw: pointer to the hw struct
    5404                 :            :  * @seid: switching component seid
    5405                 :            :  * @credit: BW limit credits (0 = disabled)
    5406                 :            :  * @max_bw: Max BW limit credits
    5407                 :            :  * @cmd_details: pointer to command details structure or NULL
    5408                 :            :  **/
    5409                 :          0 : enum i40e_status_code i40e_aq_config_switch_comp_bw_limit(struct i40e_hw *hw,
    5410                 :            :                                 u16 seid, u16 credit, u8 max_bw,
    5411                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    5412                 :            : {
    5413                 :            :         struct i40e_aq_desc desc;
    5414                 :            :         struct i40e_aqc_configure_switching_comp_bw_limit *cmd =
    5415                 :            :           (struct i40e_aqc_configure_switching_comp_bw_limit *)&desc.params.raw;
    5416                 :            :         enum i40e_status_code status;
    5417                 :            : 
    5418                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    5419                 :            :                                 i40e_aqc_opc_configure_switching_comp_bw_limit);
    5420                 :            : 
    5421                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    5422                 :          0 :         cmd->credit = CPU_TO_LE16(credit);
    5423                 :          0 :         cmd->max_bw = max_bw;
    5424                 :            : 
    5425                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    5426                 :            : 
    5427                 :          0 :         return status;
    5428                 :            : }
    5429                 :            : 
    5430                 :            : /**
    5431                 :            :  * i40e_aq_config_vsi_ets_sla_bw_limit - Config VSI BW Limit per TC
    5432                 :            :  * @hw: pointer to the hw struct
    5433                 :            :  * @seid: VSI seid
    5434                 :            :  * @bw_data: Buffer holding enabled TCs, per TC BW limit/credits
    5435                 :            :  * @cmd_details: pointer to command details structure or NULL
    5436                 :            :  **/
    5437                 :          0 : enum i40e_status_code i40e_aq_config_vsi_ets_sla_bw_limit(struct i40e_hw *hw,
    5438                 :            :                         u16 seid,
    5439                 :            :                         struct i40e_aqc_configure_vsi_ets_sla_bw_data *bw_data,
    5440                 :            :                         struct i40e_asq_cmd_details *cmd_details)
    5441                 :            : {
    5442                 :          0 :         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
    5443                 :            :                                     i40e_aqc_opc_configure_vsi_ets_sla_bw_limit,
    5444                 :            :                                     cmd_details);
    5445                 :            : }
    5446                 :            : 
    5447                 :            : /**
    5448                 :            :  * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
    5449                 :            :  * @hw: pointer to the hw struct
    5450                 :            :  * @seid: VSI seid
    5451                 :            :  * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
    5452                 :            :  * @cmd_details: pointer to command details structure or NULL
    5453                 :            :  **/
    5454                 :          0 : enum i40e_status_code i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
    5455                 :            :                         u16 seid,
    5456                 :            :                         struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
    5457                 :            :                         struct i40e_asq_cmd_details *cmd_details)
    5458                 :            : {
    5459                 :          0 :         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
    5460                 :            :                                     i40e_aqc_opc_configure_vsi_tc_bw,
    5461                 :            :                                     cmd_details);
    5462                 :            : }
    5463                 :            : 
    5464                 :            : /**
    5465                 :            :  * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
    5466                 :            :  * @hw: pointer to the hw struct
    5467                 :            :  * @seid: seid of the switching component connected to Physical Port
    5468                 :            :  * @ets_data: Buffer holding ETS parameters
    5469                 :            :  * @opcode: Tx scheduler AQ command opcode
    5470                 :            :  * @cmd_details: pointer to command details structure or NULL
    5471                 :            :  **/
    5472                 :          0 : enum i40e_status_code i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
    5473                 :            :                 u16 seid,
    5474                 :            :                 struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
    5475                 :            :                 enum i40e_admin_queue_opc opcode,
    5476                 :            :                 struct i40e_asq_cmd_details *cmd_details)
    5477                 :            : {
    5478                 :          0 :         return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
    5479                 :            :                                     sizeof(*ets_data), opcode, cmd_details);
    5480                 :            : }
    5481                 :            : 
    5482                 :            : /**
    5483                 :            :  * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
    5484                 :            :  * @hw: pointer to the hw struct
    5485                 :            :  * @seid: seid of the switching component
    5486                 :            :  * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
    5487                 :            :  * @cmd_details: pointer to command details structure or NULL
    5488                 :            :  **/
    5489                 :          0 : enum i40e_status_code i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
    5490                 :            :         u16 seid,
    5491                 :            :         struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
    5492                 :            :         struct i40e_asq_cmd_details *cmd_details)
    5493                 :            : {
    5494                 :          0 :         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
    5495                 :            :                             i40e_aqc_opc_configure_switching_comp_bw_config,
    5496                 :            :                             cmd_details);
    5497                 :            : }
    5498                 :            : 
    5499                 :            : /**
    5500                 :            :  * i40e_aq_config_switch_comp_ets_bw_limit - Config Switch comp BW Limit per TC
    5501                 :            :  * @hw: pointer to the hw struct
    5502                 :            :  * @seid: seid of the switching component
    5503                 :            :  * @bw_data: Buffer holding enabled TCs, per TC BW limit/credits
    5504                 :            :  * @cmd_details: pointer to command details structure or NULL
    5505                 :            :  **/
    5506                 :          0 : enum i40e_status_code i40e_aq_config_switch_comp_ets_bw_limit(
    5507                 :            :         struct i40e_hw *hw, u16 seid,
    5508                 :            :         struct i40e_aqc_configure_switching_comp_ets_bw_limit_data *bw_data,
    5509                 :            :         struct i40e_asq_cmd_details *cmd_details)
    5510                 :            : {
    5511                 :          0 :         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
    5512                 :            :                             i40e_aqc_opc_configure_switching_comp_ets_bw_limit,
    5513                 :            :                             cmd_details);
    5514                 :            : }
    5515                 :            : 
    5516                 :            : /**
    5517                 :            :  * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
    5518                 :            :  * @hw: pointer to the hw struct
    5519                 :            :  * @seid: seid of the VSI
    5520                 :            :  * @bw_data: Buffer to hold VSI BW configuration
    5521                 :            :  * @cmd_details: pointer to command details structure or NULL
    5522                 :            :  **/
    5523                 :          0 : enum i40e_status_code i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
    5524                 :            :                         u16 seid,
    5525                 :            :                         struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
    5526                 :            :                         struct i40e_asq_cmd_details *cmd_details)
    5527                 :            : {
    5528                 :          0 :         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
    5529                 :            :                                     i40e_aqc_opc_query_vsi_bw_config,
    5530                 :            :                                     cmd_details);
    5531                 :            : }
    5532                 :            : 
    5533                 :            : /**
    5534                 :            :  * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
    5535                 :            :  * @hw: pointer to the hw struct
    5536                 :            :  * @seid: seid of the VSI
    5537                 :            :  * @bw_data: Buffer to hold VSI BW configuration per TC
    5538                 :            :  * @cmd_details: pointer to command details structure or NULL
    5539                 :            :  **/
    5540                 :          0 : enum i40e_status_code i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
    5541                 :            :                         u16 seid,
    5542                 :            :                         struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
    5543                 :            :                         struct i40e_asq_cmd_details *cmd_details)
    5544                 :            : {
    5545                 :          0 :         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
    5546                 :            :                                     i40e_aqc_opc_query_vsi_ets_sla_config,
    5547                 :            :                                     cmd_details);
    5548                 :            : }
    5549                 :            : 
    5550                 :            : /**
    5551                 :            :  * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
    5552                 :            :  * @hw: pointer to the hw struct
    5553                 :            :  * @seid: seid of the switching component
    5554                 :            :  * @bw_data: Buffer to hold switching component's per TC BW config
    5555                 :            :  * @cmd_details: pointer to command details structure or NULL
    5556                 :            :  **/
    5557                 :          0 : enum i40e_status_code i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
    5558                 :            :                 u16 seid,
    5559                 :            :                 struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
    5560                 :            :                 struct i40e_asq_cmd_details *cmd_details)
    5561                 :            : {
    5562                 :          0 :         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
    5563                 :            :                                    i40e_aqc_opc_query_switching_comp_ets_config,
    5564                 :            :                                    cmd_details);
    5565                 :            : }
    5566                 :            : 
    5567                 :            : /**
    5568                 :            :  * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
    5569                 :            :  * @hw: pointer to the hw struct
    5570                 :            :  * @seid: seid of the VSI or switching component connected to Physical Port
    5571                 :            :  * @bw_data: Buffer to hold current ETS configuration for the Physical Port
    5572                 :            :  * @cmd_details: pointer to command details structure or NULL
    5573                 :            :  **/
    5574                 :          0 : enum i40e_status_code i40e_aq_query_port_ets_config(struct i40e_hw *hw,
    5575                 :            :                         u16 seid,
    5576                 :            :                         struct i40e_aqc_query_port_ets_config_resp *bw_data,
    5577                 :            :                         struct i40e_asq_cmd_details *cmd_details)
    5578                 :            : {
    5579                 :          0 :         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
    5580                 :            :                                     i40e_aqc_opc_query_port_ets_config,
    5581                 :            :                                     cmd_details);
    5582                 :            : }
    5583                 :            : 
    5584                 :            : /**
    5585                 :            :  * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
    5586                 :            :  * @hw: pointer to the hw struct
    5587                 :            :  * @seid: seid of the switching component
    5588                 :            :  * @bw_data: Buffer to hold switching component's BW configuration
    5589                 :            :  * @cmd_details: pointer to command details structure or NULL
    5590                 :            :  **/
    5591                 :          0 : enum i40e_status_code i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
    5592                 :            :                 u16 seid,
    5593                 :            :                 struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
    5594                 :            :                 struct i40e_asq_cmd_details *cmd_details)
    5595                 :            : {
    5596                 :          0 :         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
    5597                 :            :                                     i40e_aqc_opc_query_switching_comp_bw_config,
    5598                 :            :                                     cmd_details);
    5599                 :            : }
    5600                 :            : 
    5601                 :            : /**
    5602                 :            :  * i40e_validate_filter_settings
    5603                 :            :  * @hw: pointer to the hardware structure
    5604                 :            :  * @settings: Filter control settings
    5605                 :            :  *
    5606                 :            :  * Check and validate the filter control settings passed.
    5607                 :            :  * The function checks for the valid filter/context sizes being
    5608                 :            :  * passed for FCoE and PE.
    5609                 :            :  *
    5610                 :            :  * Returns I40E_SUCCESS if the values passed are valid and within
    5611                 :            :  * range else returns an error.
    5612                 :            :  **/
    5613                 :          0 : STATIC enum i40e_status_code i40e_validate_filter_settings(struct i40e_hw *hw,
    5614                 :            :                                 struct i40e_filter_control_settings *settings)
    5615                 :            : {
    5616                 :            :         u32 fcoe_cntx_size, fcoe_filt_size;
    5617                 :            :         u32 fcoe_fmax;
    5618                 :            : 
    5619                 :            :         u32 val;
    5620                 :            : 
    5621                 :            :         /* Validate FCoE settings passed */
    5622         [ #  # ]:          0 :         switch (settings->fcoe_filt_num) {
    5623                 :          0 :         case I40E_HASH_FILTER_SIZE_1K:
    5624                 :            :         case I40E_HASH_FILTER_SIZE_2K:
    5625                 :            :         case I40E_HASH_FILTER_SIZE_4K:
    5626                 :            :         case I40E_HASH_FILTER_SIZE_8K:
    5627                 :            :         case I40E_HASH_FILTER_SIZE_16K:
    5628                 :            :         case I40E_HASH_FILTER_SIZE_32K:
    5629                 :            :                 fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
    5630                 :          0 :                 fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
    5631                 :            :                 break;
    5632                 :            :         default:
    5633                 :            :                 return I40E_ERR_PARAM;
    5634                 :            :         }
    5635                 :            : 
    5636         [ #  # ]:          0 :         switch (settings->fcoe_cntx_num) {
    5637                 :          0 :         case I40E_DMA_CNTX_SIZE_512:
    5638                 :            :         case I40E_DMA_CNTX_SIZE_1K:
    5639                 :            :         case I40E_DMA_CNTX_SIZE_2K:
    5640                 :            :         case I40E_DMA_CNTX_SIZE_4K:
    5641                 :            :                 fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
    5642                 :          0 :                 fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
    5643                 :            :                 break;
    5644                 :            :         default:
    5645                 :            :                 return I40E_ERR_PARAM;
    5646                 :            :         }
    5647                 :            : 
    5648                 :            :         /* Validate PE settings passed */
    5649         [ #  # ]:          0 :         switch (settings->pe_filt_num) {
    5650                 :            :         case I40E_HASH_FILTER_SIZE_1K:
    5651                 :            :         case I40E_HASH_FILTER_SIZE_2K:
    5652                 :            :         case I40E_HASH_FILTER_SIZE_4K:
    5653                 :            :         case I40E_HASH_FILTER_SIZE_8K:
    5654                 :            :         case I40E_HASH_FILTER_SIZE_16K:
    5655                 :            :         case I40E_HASH_FILTER_SIZE_32K:
    5656                 :            :         case I40E_HASH_FILTER_SIZE_64K:
    5657                 :            :         case I40E_HASH_FILTER_SIZE_128K:
    5658                 :            :         case I40E_HASH_FILTER_SIZE_256K:
    5659                 :            :         case I40E_HASH_FILTER_SIZE_512K:
    5660                 :            :         case I40E_HASH_FILTER_SIZE_1M:
    5661                 :            :                 break;
    5662                 :            :         default:
    5663                 :            :                 return I40E_ERR_PARAM;
    5664                 :            :         }
    5665                 :            : 
    5666         [ #  # ]:          0 :         switch (settings->pe_cntx_num) {
    5667                 :            :         case I40E_DMA_CNTX_SIZE_512:
    5668                 :            :         case I40E_DMA_CNTX_SIZE_1K:
    5669                 :            :         case I40E_DMA_CNTX_SIZE_2K:
    5670                 :            :         case I40E_DMA_CNTX_SIZE_4K:
    5671                 :            :         case I40E_DMA_CNTX_SIZE_8K:
    5672                 :            :         case I40E_DMA_CNTX_SIZE_16K:
    5673                 :            :         case I40E_DMA_CNTX_SIZE_32K:
    5674                 :            :         case I40E_DMA_CNTX_SIZE_64K:
    5675                 :            :         case I40E_DMA_CNTX_SIZE_128K:
    5676                 :            :         case I40E_DMA_CNTX_SIZE_256K:
    5677                 :            :                 break;
    5678                 :            :         default:
    5679                 :            :                 return I40E_ERR_PARAM;
    5680                 :            :         }
    5681                 :            : 
    5682                 :            :         /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
    5683                 :          0 :         val = rd32(hw, I40E_GLHMC_FCOEFMAX);
    5684                 :          0 :         fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
    5685                 :            :                      >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
    5686         [ #  # ]:          0 :         if (fcoe_filt_size + fcoe_cntx_size >  fcoe_fmax)
    5687                 :          0 :                 return I40E_ERR_INVALID_SIZE;
    5688                 :            : 
    5689                 :            :         return I40E_SUCCESS;
    5690                 :            : }
    5691                 :            : 
    5692                 :            : /**
    5693                 :            :  * i40e_set_filter_control
    5694                 :            :  * @hw: pointer to the hardware structure
    5695                 :            :  * @settings: Filter control settings
    5696                 :            :  *
    5697                 :            :  * Set the Queue Filters for PE/FCoE and enable filters required
    5698                 :            :  * for a single PF. It is expected that these settings are programmed
    5699                 :            :  * at the driver initialization time.
    5700                 :            :  **/
    5701                 :          0 : enum i40e_status_code i40e_set_filter_control(struct i40e_hw *hw,
    5702                 :            :                                 struct i40e_filter_control_settings *settings)
    5703                 :            : {
    5704                 :            :         enum i40e_status_code ret = I40E_SUCCESS;
    5705                 :            :         u32 hash_lut_size = 0;
    5706                 :            :         u32 val;
    5707                 :            : 
    5708         [ #  # ]:          0 :         if (!settings)
    5709                 :            :                 return I40E_ERR_PARAM;
    5710                 :            : 
    5711                 :            :         /* Validate the input settings */
    5712                 :          0 :         ret = i40e_validate_filter_settings(hw, settings);
    5713         [ #  # ]:          0 :         if (ret)
    5714                 :            :                 return ret;
    5715                 :            : 
    5716                 :            :         /* Read the PF Queue Filter control register */
    5717                 :          0 :         val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
    5718                 :            : 
    5719                 :            :         /* Program required PE hash buckets for the PF */
    5720                 :          0 :         val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
    5721                 :          0 :         val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
    5722                 :            :                 I40E_PFQF_CTL_0_PEHSIZE_MASK;
    5723                 :            :         /* Program required PE contexts for the PF */
    5724                 :          0 :         val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
    5725                 :          0 :         val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
    5726                 :            :                 I40E_PFQF_CTL_0_PEDSIZE_MASK;
    5727                 :            : 
    5728                 :            :         /* Program required FCoE hash buckets for the PF */
    5729                 :          0 :         val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
    5730                 :          0 :         val |= ((u32)settings->fcoe_filt_num <<
    5731                 :          0 :                         I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
    5732                 :            :                 I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
    5733                 :            :         /* Program required FCoE DDP contexts for the PF */
    5734                 :          0 :         val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
    5735                 :          0 :         val |= ((u32)settings->fcoe_cntx_num <<
    5736                 :          0 :                         I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
    5737                 :            :                 I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
    5738                 :            : 
    5739                 :            :         /* Program Hash LUT size for the PF */
    5740                 :          0 :         val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
    5741         [ #  # ]:          0 :         if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
    5742                 :            :                 hash_lut_size = 1;
    5743                 :          0 :         val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
    5744                 :            :                 I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
    5745                 :            : 
    5746                 :            :         /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
    5747         [ #  # ]:          0 :         if (settings->enable_fdir)
    5748                 :          0 :                 val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
    5749         [ #  # ]:          0 :         if (settings->enable_ethtype)
    5750                 :          0 :                 val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
    5751         [ #  # ]:          0 :         if (settings->enable_macvlan)
    5752                 :          0 :                 val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
    5753                 :            : 
    5754                 :          0 :         i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, val);
    5755                 :            : 
    5756                 :          0 :         return I40E_SUCCESS;
    5757                 :            : }
    5758                 :            : 
    5759                 :            : /**
    5760                 :            :  * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
    5761                 :            :  * @hw: pointer to the hw struct
    5762                 :            :  * @mac_addr: MAC address to use in the filter
    5763                 :            :  * @ethtype: Ethertype to use in the filter
    5764                 :            :  * @flags: Flags that needs to be applied to the filter
    5765                 :            :  * @vsi_seid: seid of the control VSI
    5766                 :            :  * @queue: VSI queue number to send the packet to
    5767                 :            :  * @is_add: Add control packet filter if True else remove
    5768                 :            :  * @stats: Structure to hold information on control filter counts
    5769                 :            :  * @cmd_details: pointer to command details structure or NULL
    5770                 :            :  *
    5771                 :            :  * This command will Add or Remove control packet filter for a control VSI.
    5772                 :            :  * In return it will update the total number of perfect filter count in
    5773                 :            :  * the stats member.
    5774                 :            :  **/
    5775                 :          0 : enum i40e_status_code i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
    5776                 :            :                                 u8 *mac_addr, u16 ethtype, u16 flags,
    5777                 :            :                                 u16 vsi_seid, u16 queue, bool is_add,
    5778                 :            :                                 struct i40e_control_filter_stats *stats,
    5779                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    5780                 :            : {
    5781                 :            :         struct i40e_aq_desc desc;
    5782                 :            :         struct i40e_aqc_add_remove_control_packet_filter *cmd =
    5783                 :            :                 (struct i40e_aqc_add_remove_control_packet_filter *)
    5784                 :            :                 &desc.params.raw;
    5785                 :            :         struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
    5786                 :            :                 (struct i40e_aqc_add_remove_control_packet_filter_completion *)
    5787                 :            :                 &desc.params.raw;
    5788                 :            :         enum i40e_status_code status;
    5789                 :            : 
    5790         [ #  # ]:          0 :         if (vsi_seid == 0)
    5791                 :            :                 return I40E_ERR_PARAM;
    5792                 :            : 
    5793         [ #  # ]:          0 :         if (is_add) {
    5794                 :          0 :                 i40e_fill_default_direct_cmd_desc(&desc,
    5795                 :            :                                 i40e_aqc_opc_add_control_packet_filter);
    5796                 :          0 :                 cmd->queue = CPU_TO_LE16(queue);
    5797                 :            :         } else {
    5798                 :          0 :                 i40e_fill_default_direct_cmd_desc(&desc,
    5799                 :            :                                 i40e_aqc_opc_remove_control_packet_filter);
    5800                 :            :         }
    5801                 :            : 
    5802         [ #  # ]:          0 :         if (mac_addr)
    5803                 :            :                 i40e_memcpy(cmd->mac, mac_addr, ETH_ALEN,
    5804                 :            :                             I40E_NONDMA_TO_NONDMA);
    5805                 :            : 
    5806                 :          0 :         cmd->etype = CPU_TO_LE16(ethtype);
    5807                 :          0 :         cmd->flags = CPU_TO_LE16(flags);
    5808                 :          0 :         cmd->seid = CPU_TO_LE16(vsi_seid);
    5809                 :            : 
    5810                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    5811                 :            : 
    5812         [ #  # ]:          0 :         if (!status && stats) {
    5813                 :          0 :                 stats->mac_etype_used = LE16_TO_CPU(resp->mac_etype_used);
    5814                 :          0 :                 stats->etype_used = LE16_TO_CPU(resp->etype_used);
    5815                 :          0 :                 stats->mac_etype_free = LE16_TO_CPU(resp->mac_etype_free);
    5816                 :          0 :                 stats->etype_free = LE16_TO_CPU(resp->etype_free);
    5817                 :            :         }
    5818                 :            : 
    5819                 :            :         return status;
    5820                 :            : }
    5821                 :            : 
    5822                 :            : /**
    5823                 :            :  * i40e_add_filter_to_drop_tx_flow_control_frames- filter to drop flow control
    5824                 :            :  * @hw: pointer to the hw struct
    5825                 :            :  * @seid: VSI seid to add ethertype filter from
    5826                 :            :  **/
    5827                 :          0 : void i40e_add_filter_to_drop_tx_flow_control_frames(struct i40e_hw *hw,
    5828                 :            :                                                     u16 seid)
    5829                 :            : {
    5830                 :            : #define I40E_FLOW_CONTROL_ETHTYPE 0x8808
    5831                 :            :         u16 flag = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
    5832                 :            :                    I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
    5833                 :            :                    I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
    5834                 :            :         u16 ethtype = I40E_FLOW_CONTROL_ETHTYPE;
    5835                 :            :         enum i40e_status_code status;
    5836                 :            : 
    5837                 :          0 :         status = i40e_aq_add_rem_control_packet_filter(hw, NULL, ethtype, flag,
    5838                 :            :                                                        seid, 0, true, NULL,
    5839                 :            :                                                        NULL);
    5840         [ #  # ]:          0 :         if (status)
    5841                 :          0 :                 DEBUGOUT("Ethtype Filter Add failed: Error pruning Tx flow control frames\n");
    5842                 :          0 : }
    5843                 :            : 
    5844                 :            : /**
    5845                 :            :  * i40e_fix_up_geneve_vni - adjust Geneve VNI for HW issue
    5846                 :            :  * @filters: list of cloud filters
    5847                 :            :  * @filter_count: length of list
    5848                 :            :  *
    5849                 :            :  * There's an issue in the device where the Geneve VNI layout needs
    5850                 :            :  * to be shifted 1 byte over from the VxLAN VNI
    5851                 :            :  **/
    5852                 :            : STATIC void i40e_fix_up_geneve_vni(
    5853                 :            :         struct i40e_aqc_cloud_filters_element_data *filters,
    5854                 :            :         u8 filter_count)
    5855                 :            : {
    5856                 :            :         struct i40e_aqc_cloud_filters_element_data *f = filters;
    5857                 :            :         int i;
    5858                 :            : 
    5859   [ #  #  #  # ]:          0 :         for (i = 0; i < filter_count; i++) {
    5860                 :            :                 u16 tnl_type;
    5861                 :            :                 u32 ti;
    5862                 :            : 
    5863                 :          0 :                 tnl_type = (LE16_TO_CPU(f[i].flags) &
    5864                 :          0 :                            I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
    5865                 :            :                            I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
    5866   [ #  #  #  # ]:          0 :                 if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
    5867                 :          0 :                         ti = LE32_TO_CPU(f[i].tenant_id);
    5868                 :          0 :                         f[i].tenant_id = CPU_TO_LE32(ti << 8);
    5869                 :            :                 }
    5870                 :            :         }
    5871                 :            : }
    5872                 :            : 
    5873                 :            : /**
    5874                 :            :  * i40e_aq_add_cloud_filters
    5875                 :            :  * @hw: pointer to the hardware structure
    5876                 :            :  * @seid: VSI seid to add cloud filters from
    5877                 :            :  * @filters: Buffer which contains the filters to be added
    5878                 :            :  * @filter_count: number of filters contained in the buffer
    5879                 :            :  *
    5880                 :            :  * Set the cloud filters for a given VSI.  The contents of the
    5881                 :            :  * i40e_aqc_cloud_filters_element_data are filled
    5882                 :            :  * in by the caller of the function.
    5883                 :            :  *
    5884                 :            :  **/
    5885                 :          0 : enum i40e_status_code i40e_aq_add_cloud_filters(struct i40e_hw *hw,
    5886                 :            :         u16 seid,
    5887                 :            :         struct i40e_aqc_cloud_filters_element_data *filters,
    5888                 :            :         u8 filter_count)
    5889                 :            : {
    5890                 :            :         struct i40e_aq_desc desc;
    5891                 :            :         struct i40e_aqc_add_remove_cloud_filters *cmd =
    5892                 :            :         (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
    5893                 :            :         enum i40e_status_code status;
    5894                 :            :         u16 buff_len;
    5895                 :            : 
    5896                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    5897                 :            :                                           i40e_aqc_opc_add_cloud_filters);
    5898                 :            : 
    5899                 :          0 :         buff_len = filter_count * sizeof(*filters);
    5900                 :          0 :         desc.datalen = CPU_TO_LE16(buff_len);
    5901                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    5902                 :          0 :         cmd->num_filters = filter_count;
    5903                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    5904                 :            : 
    5905                 :          0 :         i40e_fix_up_geneve_vni(filters, filter_count);
    5906                 :            : 
    5907                 :          0 :         status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
    5908                 :            : 
    5909                 :          0 :         return status;
    5910                 :            : }
    5911                 :            : 
    5912                 :            : /**
    5913                 :            :  * i40e_aq_add_cloud_filters_bb
    5914                 :            :  * @hw: pointer to the hardware structure
    5915                 :            :  * @seid: VSI seid to add cloud filters from
    5916                 :            :  * @filters: Buffer which contains the filters in big buffer to be added
    5917                 :            :  * @filter_count: number of filters contained in the buffer
    5918                 :            :  *
    5919                 :            :  * Set the cloud filters for a given VSI.  The contents of the
    5920                 :            :  * i40e_aqc_cloud_filters_element_bb are filled in by the caller of
    5921                 :            :  * the function.
    5922                 :            :  *
    5923                 :            :  **/
    5924                 :            : enum i40e_status_code
    5925                 :          0 : i40e_aq_add_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
    5926                 :            :                              struct i40e_aqc_cloud_filters_element_bb *filters,
    5927                 :            :                              u8 filter_count)
    5928                 :            : {
    5929                 :            :         struct i40e_aq_desc desc;
    5930                 :            :         struct i40e_aqc_add_remove_cloud_filters *cmd =
    5931                 :            :         (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
    5932                 :            :         enum i40e_status_code status;
    5933                 :            :         u16 buff_len;
    5934                 :            :         int i;
    5935                 :            : 
    5936                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    5937                 :            :                                           i40e_aqc_opc_add_cloud_filters);
    5938                 :            : 
    5939                 :          0 :         buff_len = filter_count * sizeof(*filters);
    5940                 :          0 :         desc.datalen = CPU_TO_LE16(buff_len);
    5941                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    5942                 :          0 :         cmd->num_filters = filter_count;
    5943                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    5944                 :          0 :         cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
    5945                 :            : 
    5946         [ #  # ]:          0 :         for (i = 0; i < filter_count; i++) {
    5947                 :            :                 u16 tnl_type;
    5948                 :            :                 u32 ti;
    5949                 :            : 
    5950                 :          0 :                 tnl_type = (LE16_TO_CPU(filters[i].element.flags) &
    5951                 :          0 :                            I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
    5952                 :            :                            I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
    5953                 :            : 
    5954                 :            :                 /* Due to hardware eccentricities, the VNI for Geneve is shifted
    5955                 :            :                  * one more byte further than normally used for Tenant ID in
    5956                 :            :                  * other tunnel types.
    5957                 :            :                  */
    5958         [ #  # ]:          0 :                 if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
    5959                 :          0 :                         ti = LE32_TO_CPU(filters[i].element.tenant_id);
    5960                 :          0 :                         filters[i].element.tenant_id = CPU_TO_LE32(ti << 8);
    5961                 :            :                 }
    5962                 :            :         }
    5963                 :            : 
    5964                 :          0 :         status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
    5965                 :            : 
    5966                 :          0 :         return status;
    5967                 :            : }
    5968                 :            : 
    5969                 :            : /**
    5970                 :            :  * i40e_aq_rem_cloud_filters
    5971                 :            :  * @hw: pointer to the hardware structure
    5972                 :            :  * @seid: VSI seid to remove cloud filters from
    5973                 :            :  * @filters: Buffer which contains the filters to be removed
    5974                 :            :  * @filter_count: number of filters contained in the buffer
    5975                 :            :  *
    5976                 :            :  * Remove the cloud filters for a given VSI.  The contents of the
    5977                 :            :  * i40e_aqc_cloud_filters_element_data are filled in by the caller
    5978                 :            :  * of the function.
    5979                 :            :  *
    5980                 :            :  **/
    5981                 :            : enum i40e_status_code
    5982                 :          0 : i40e_aq_rem_cloud_filters(struct i40e_hw *hw, u16 seid,
    5983                 :            :                           struct i40e_aqc_cloud_filters_element_data *filters,
    5984                 :            :                           u8 filter_count)
    5985                 :            : {
    5986                 :            :         struct i40e_aq_desc desc;
    5987                 :            :         struct i40e_aqc_add_remove_cloud_filters *cmd =
    5988                 :            :         (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
    5989                 :            :         enum i40e_status_code status;
    5990                 :            :         u16 buff_len;
    5991                 :            : 
    5992                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    5993                 :            :                                           i40e_aqc_opc_remove_cloud_filters);
    5994                 :            : 
    5995                 :          0 :         buff_len = filter_count * sizeof(*filters);
    5996                 :          0 :         desc.datalen = CPU_TO_LE16(buff_len);
    5997                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    5998                 :          0 :         cmd->num_filters = filter_count;
    5999                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    6000                 :            : 
    6001                 :          0 :         i40e_fix_up_geneve_vni(filters, filter_count);
    6002                 :            : 
    6003                 :          0 :         status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
    6004                 :            : 
    6005                 :          0 :         return status;
    6006                 :            : }
    6007                 :            : 
    6008                 :            : /**
    6009                 :            :  * i40e_aq_rem_cloud_filters_bb
    6010                 :            :  * @hw: pointer to the hardware structure
    6011                 :            :  * @seid: VSI seid to remove cloud filters from
    6012                 :            :  * @filters: Buffer which contains the filters in big buffer to be removed
    6013                 :            :  * @filter_count: number of filters contained in the buffer
    6014                 :            :  *
    6015                 :            :  * Remove the big buffer cloud filters for a given VSI.  The contents of the
    6016                 :            :  * i40e_aqc_cloud_filters_element_bb are filled in by the caller of the
    6017                 :            :  * function.
    6018                 :            :  *
    6019                 :            :  **/
    6020                 :            : enum i40e_status_code
    6021                 :          0 : i40e_aq_rem_cloud_filters_bb(struct i40e_hw *hw, u16 seid,
    6022                 :            :                              struct i40e_aqc_cloud_filters_element_bb *filters,
    6023                 :            :                              u8 filter_count)
    6024                 :            : {
    6025                 :            :         struct i40e_aq_desc desc;
    6026                 :            :         struct i40e_aqc_add_remove_cloud_filters *cmd =
    6027                 :            :         (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
    6028                 :            :         enum i40e_status_code status;
    6029                 :            :         u16 buff_len;
    6030                 :            :         int i;
    6031                 :            : 
    6032                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    6033                 :            :                                           i40e_aqc_opc_remove_cloud_filters);
    6034                 :            : 
    6035                 :          0 :         buff_len = filter_count * sizeof(*filters);
    6036                 :          0 :         desc.datalen = CPU_TO_LE16(buff_len);
    6037                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    6038                 :          0 :         cmd->num_filters = filter_count;
    6039                 :          0 :         cmd->seid = CPU_TO_LE16(seid);
    6040                 :          0 :         cmd->big_buffer_flag = I40E_AQC_ADD_CLOUD_CMD_BB;
    6041                 :            : 
    6042         [ #  # ]:          0 :         for (i = 0; i < filter_count; i++) {
    6043                 :            :                 u16 tnl_type;
    6044                 :            :                 u32 ti;
    6045                 :            : 
    6046                 :          0 :                 tnl_type = (LE16_TO_CPU(filters[i].element.flags) &
    6047                 :          0 :                            I40E_AQC_ADD_CLOUD_TNL_TYPE_MASK) >>
    6048                 :            :                            I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT;
    6049                 :            : 
    6050                 :            :                 /* Due to hardware eccentricities, the VNI for Geneve is shifted
    6051                 :            :                  * one more byte further than normally used for Tenant ID in
    6052                 :            :                  * other tunnel types.
    6053                 :            :                  */
    6054         [ #  # ]:          0 :                 if (tnl_type == I40E_AQC_ADD_CLOUD_TNL_TYPE_GENEVE) {
    6055                 :          0 :                         ti = LE32_TO_CPU(filters[i].element.tenant_id);
    6056                 :          0 :                         filters[i].element.tenant_id = CPU_TO_LE32(ti << 8);
    6057                 :            :                 }
    6058                 :            :         }
    6059                 :            : 
    6060                 :          0 :         status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
    6061                 :            : 
    6062                 :          0 :         return status;
    6063                 :            : }
    6064                 :            : 
    6065                 :            : /**
    6066                 :            :  * i40e_aq_replace_cloud_filters - Replace cloud filter command
    6067                 :            :  * @hw: pointer to the hw struct
    6068                 :            :  * @filters: pointer to the i40e_aqc_replace_cloud_filter_cmd struct
    6069                 :            :  * @cmd_buf: pointer to the i40e_aqc_replace_cloud_filter_cmd_buf struct
    6070                 :            :  *
    6071                 :            :  **/
    6072                 :            : enum
    6073                 :          0 : i40e_status_code i40e_aq_replace_cloud_filters(struct i40e_hw *hw,
    6074                 :            :         struct i40e_aqc_replace_cloud_filters_cmd *filters,
    6075                 :            :         struct i40e_aqc_replace_cloud_filters_cmd_buf *cmd_buf)
    6076                 :            : {
    6077                 :            :         struct i40e_aq_desc desc;
    6078                 :            :         struct i40e_aqc_replace_cloud_filters_cmd *cmd =
    6079                 :            :                 (struct i40e_aqc_replace_cloud_filters_cmd *)&desc.params.raw;
    6080                 :            :         enum i40e_status_code status = I40E_SUCCESS;
    6081                 :            :         int i = 0;
    6082                 :            : 
    6083                 :            :         /* X722 doesn't support this command */
    6084         [ #  # ]:          0 :         if (hw->mac.type == I40E_MAC_X722)
    6085                 :            :                 return I40E_ERR_DEVICE_NOT_SUPPORTED;
    6086                 :            : 
    6087                 :            :         /* need FW version greater than 6.00 */
    6088         [ #  # ]:          0 :         if (hw->aq.fw_maj_ver < 6)
    6089                 :            :                 return I40E_NOT_SUPPORTED;
    6090                 :            : 
    6091                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    6092                 :            :                                           i40e_aqc_opc_replace_cloud_filters);
    6093                 :            : 
    6094                 :          0 :         desc.datalen = CPU_TO_LE16(32);
    6095                 :          0 :         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
    6096                 :          0 :         cmd->old_filter_type = filters->old_filter_type;
    6097                 :          0 :         cmd->new_filter_type = filters->new_filter_type;
    6098                 :          0 :         cmd->valid_flags = filters->valid_flags;
    6099                 :          0 :         cmd->tr_bit = filters->tr_bit;
    6100                 :          0 :         cmd->tr_bit2 = filters->tr_bit2;
    6101                 :            : 
    6102                 :          0 :         status = i40e_asq_send_command(hw, &desc, cmd_buf,
    6103                 :            :                 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf),  NULL);
    6104                 :            : 
    6105                 :            :         /* for get cloud filters command */
    6106         [ #  # ]:          0 :         for (i = 0; i < 32; i += 4) {
    6107                 :          0 :                 cmd_buf->filters[i / 4].filter_type = cmd_buf->data[i];
    6108                 :          0 :                 cmd_buf->filters[i / 4].input[0] = cmd_buf->data[i + 1];
    6109                 :          0 :                 cmd_buf->filters[i / 4].input[1] = cmd_buf->data[i + 2];
    6110                 :          0 :                 cmd_buf->filters[i / 4].input[2] = cmd_buf->data[i + 3];
    6111                 :            :         }
    6112                 :            : 
    6113                 :            :         return status;
    6114                 :            : }
    6115                 :            : 
    6116                 :            : /**
    6117                 :            :  * i40e_aq_alternate_write
    6118                 :            :  * @hw: pointer to the hardware structure
    6119                 :            :  * @reg_addr0: address of first dword to be read
    6120                 :            :  * @reg_val0: value to be written under 'reg_addr0'
    6121                 :            :  * @reg_addr1: address of second dword to be read
    6122                 :            :  * @reg_val1: value to be written under 'reg_addr1'
    6123                 :            :  *
    6124                 :            :  * Write one or two dwords to alternate structure. Fields are indicated
    6125                 :            :  * by 'reg_addr0' and 'reg_addr1' register numbers.
    6126                 :            :  *
    6127                 :            :  **/
    6128                 :          0 : enum i40e_status_code i40e_aq_alternate_write(struct i40e_hw *hw,
    6129                 :            :                                 u32 reg_addr0, u32 reg_val0,
    6130                 :            :                                 u32 reg_addr1, u32 reg_val1)
    6131                 :            : {
    6132                 :            :         struct i40e_aq_desc desc;
    6133                 :            :         struct i40e_aqc_alternate_write *cmd_resp =
    6134                 :            :                 (struct i40e_aqc_alternate_write *)&desc.params.raw;
    6135                 :            :         enum i40e_status_code status;
    6136                 :            : 
    6137                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_write);
    6138                 :          0 :         cmd_resp->address0 = CPU_TO_LE32(reg_addr0);
    6139                 :          0 :         cmd_resp->address1 = CPU_TO_LE32(reg_addr1);
    6140                 :          0 :         cmd_resp->data0 = CPU_TO_LE32(reg_val0);
    6141                 :          0 :         cmd_resp->data1 = CPU_TO_LE32(reg_val1);
    6142                 :            : 
    6143                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
    6144                 :            : 
    6145                 :          0 :         return status;
    6146                 :            : }
    6147                 :            : 
    6148                 :            : /**
    6149                 :            :  * i40e_aq_alternate_write_indirect
    6150                 :            :  * @hw: pointer to the hardware structure
    6151                 :            :  * @addr: address of a first register to be modified
    6152                 :            :  * @dw_count: number of alternate structure fields to write
    6153                 :            :  * @buffer: pointer to the command buffer
    6154                 :            :  *
    6155                 :            :  * Write 'dw_count' dwords from 'buffer' to alternate structure
    6156                 :            :  * starting at 'addr'.
    6157                 :            :  *
    6158                 :            :  **/
    6159                 :          0 : enum i40e_status_code i40e_aq_alternate_write_indirect(struct i40e_hw *hw,
    6160                 :            :                                 u32 addr, u32 dw_count, void *buffer)
    6161                 :            : {
    6162                 :            :         struct i40e_aq_desc desc;
    6163                 :            :         struct i40e_aqc_alternate_ind_write *cmd_resp =
    6164                 :            :                 (struct i40e_aqc_alternate_ind_write *)&desc.params.raw;
    6165                 :            :         enum i40e_status_code status;
    6166                 :            : 
    6167         [ #  # ]:          0 :         if (buffer == NULL)
    6168                 :            :                 return I40E_ERR_PARAM;
    6169                 :            : 
    6170                 :            :         /* Indirect command */
    6171                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    6172                 :            :                                          i40e_aqc_opc_alternate_write_indirect);
    6173                 :            : 
    6174                 :          0 :         desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_RD);
    6175                 :          0 :         desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_BUF);
    6176         [ #  # ]:          0 :         if (dw_count > (I40E_AQ_LARGE_BUF/4))
    6177                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    6178                 :            : 
    6179                 :          0 :         cmd_resp->address = CPU_TO_LE32(addr);
    6180                 :          0 :         cmd_resp->length = CPU_TO_LE32(dw_count);
    6181                 :            : 
    6182                 :          0 :         status = i40e_asq_send_command(hw, &desc, buffer,
    6183                 :          0 :                                        I40E_LO_WORD(4*dw_count), NULL);
    6184                 :            : 
    6185                 :          0 :         return status;
    6186                 :            : }
    6187                 :            : 
    6188                 :            : /**
    6189                 :            :  * i40e_aq_alternate_read
    6190                 :            :  * @hw: pointer to the hardware structure
    6191                 :            :  * @reg_addr0: address of first dword to be read
    6192                 :            :  * @reg_val0: pointer for data read from 'reg_addr0'
    6193                 :            :  * @reg_addr1: address of second dword to be read
    6194                 :            :  * @reg_val1: pointer for data read from 'reg_addr1'
    6195                 :            :  *
    6196                 :            :  * Read one or two dwords from alternate structure. Fields are indicated
    6197                 :            :  * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
    6198                 :            :  * is not passed then only register at 'reg_addr0' is read.
    6199                 :            :  *
    6200                 :            :  **/
    6201                 :          0 : enum i40e_status_code i40e_aq_alternate_read(struct i40e_hw *hw,
    6202                 :            :                                 u32 reg_addr0, u32 *reg_val0,
    6203                 :            :                                 u32 reg_addr1, u32 *reg_val1)
    6204                 :            : {
    6205                 :            :         struct i40e_aq_desc desc;
    6206                 :            :         struct i40e_aqc_alternate_write *cmd_resp =
    6207                 :            :                 (struct i40e_aqc_alternate_write *)&desc.params.raw;
    6208                 :            :         enum i40e_status_code status;
    6209                 :            : 
    6210         [ #  # ]:          0 :         if (reg_val0 == NULL)
    6211                 :            :                 return I40E_ERR_PARAM;
    6212                 :            : 
    6213                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
    6214                 :          0 :         cmd_resp->address0 = CPU_TO_LE32(reg_addr0);
    6215                 :          0 :         cmd_resp->address1 = CPU_TO_LE32(reg_addr1);
    6216                 :            : 
    6217                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
    6218                 :            : 
    6219         [ #  # ]:          0 :         if (status == I40E_SUCCESS) {
    6220                 :          0 :                 *reg_val0 = LE32_TO_CPU(cmd_resp->data0);
    6221                 :            : 
    6222         [ #  # ]:          0 :                 if (reg_val1 != NULL)
    6223                 :          0 :                         *reg_val1 = LE32_TO_CPU(cmd_resp->data1);
    6224                 :            :         }
    6225                 :            : 
    6226                 :            :         return status;
    6227                 :            : }
    6228                 :            : 
    6229                 :            : /**
    6230                 :            :  * i40e_aq_alternate_read_indirect
    6231                 :            :  * @hw: pointer to the hardware structure
    6232                 :            :  * @addr: address of the alternate structure field
    6233                 :            :  * @dw_count: number of alternate structure fields to read
    6234                 :            :  * @buffer: pointer to the command buffer
    6235                 :            :  *
    6236                 :            :  * Read 'dw_count' dwords from alternate structure starting at 'addr' and
    6237                 :            :  * place them in 'buffer'. The buffer should be allocated by caller.
    6238                 :            :  *
    6239                 :            :  **/
    6240                 :          0 : enum i40e_status_code i40e_aq_alternate_read_indirect(struct i40e_hw *hw,
    6241                 :            :                                 u32 addr, u32 dw_count, void *buffer)
    6242                 :            : {
    6243                 :            :         struct i40e_aq_desc desc;
    6244                 :            :         struct i40e_aqc_alternate_ind_write *cmd_resp =
    6245                 :            :                 (struct i40e_aqc_alternate_ind_write *)&desc.params.raw;
    6246                 :            :         enum i40e_status_code status;
    6247                 :            : 
    6248         [ #  # ]:          0 :         if (buffer == NULL)
    6249                 :            :                 return I40E_ERR_PARAM;
    6250                 :            : 
    6251                 :            :         /* Indirect command */
    6252                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    6253                 :            :                 i40e_aqc_opc_alternate_read_indirect);
    6254                 :            : 
    6255                 :          0 :         desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_RD);
    6256                 :          0 :         desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_BUF);
    6257         [ #  # ]:          0 :         if (dw_count > (I40E_AQ_LARGE_BUF/4))
    6258                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    6259                 :            : 
    6260                 :          0 :         cmd_resp->address = CPU_TO_LE32(addr);
    6261                 :          0 :         cmd_resp->length = CPU_TO_LE32(dw_count);
    6262                 :            : 
    6263                 :          0 :         status = i40e_asq_send_command(hw, &desc, buffer,
    6264                 :          0 :                                        I40E_LO_WORD(4*dw_count), NULL);
    6265                 :            : 
    6266                 :          0 :         return status;
    6267                 :            : }
    6268                 :            : 
    6269                 :            : /**
    6270                 :            :  *  i40e_aq_alternate_clear
    6271                 :            :  *  @hw: pointer to the HW structure.
    6272                 :            :  *
    6273                 :            :  *  Clear the alternate structures of the port from which the function
    6274                 :            :  *  is called.
    6275                 :            :  *
    6276                 :            :  **/
    6277                 :          0 : enum i40e_status_code i40e_aq_alternate_clear(struct i40e_hw *hw)
    6278                 :            : {
    6279                 :            :         struct i40e_aq_desc desc;
    6280                 :            :         enum i40e_status_code status;
    6281                 :            : 
    6282                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    6283                 :            :                                           i40e_aqc_opc_alternate_clear_port);
    6284                 :            : 
    6285                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
    6286                 :            : 
    6287                 :          0 :         return status;
    6288                 :            : }
    6289                 :            : 
    6290                 :            : /**
    6291                 :            :  *  i40e_aq_alternate_write_done
    6292                 :            :  *  @hw: pointer to the HW structure.
    6293                 :            :  *  @bios_mode: indicates whether the command is executed by UEFI or legacy BIOS
    6294                 :            :  *  @reset_needed: indicates the SW should trigger GLOBAL reset
    6295                 :            :  *
    6296                 :            :  *  Indicates to the FW that alternate structures have been changed.
    6297                 :            :  *
    6298                 :            :  **/
    6299                 :          0 : enum i40e_status_code i40e_aq_alternate_write_done(struct i40e_hw *hw,
    6300                 :            :                 u8 bios_mode, bool *reset_needed)
    6301                 :            : {
    6302                 :            :         struct i40e_aq_desc desc;
    6303                 :            :         struct i40e_aqc_alternate_write_done *cmd =
    6304                 :            :                 (struct i40e_aqc_alternate_write_done *)&desc.params.raw;
    6305                 :            :         enum i40e_status_code status;
    6306                 :            : 
    6307         [ #  # ]:          0 :         if (reset_needed == NULL)
    6308                 :            :                 return I40E_ERR_PARAM;
    6309                 :            : 
    6310                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    6311                 :            :                                           i40e_aqc_opc_alternate_write_done);
    6312                 :            : 
    6313                 :          0 :         cmd->cmd_flags = CPU_TO_LE16(bios_mode);
    6314                 :            : 
    6315                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
    6316         [ #  # ]:          0 :         if (!status && reset_needed)
    6317                 :          0 :                 *reset_needed = ((LE16_TO_CPU(cmd->cmd_flags) &
    6318                 :          0 :                                  I40E_AQ_ALTERNATE_RESET_NEEDED) != 0);
    6319                 :            : 
    6320                 :            :         return status;
    6321                 :            : }
    6322                 :            : 
    6323                 :            : /**
    6324                 :            :  *  i40e_aq_set_oem_mode
    6325                 :            :  *  @hw: pointer to the HW structure.
    6326                 :            :  *  @oem_mode: the OEM mode to be used
    6327                 :            :  *
    6328                 :            :  *  Sets the device to a specific operating mode. Currently the only supported
    6329                 :            :  *  mode is no_clp, which causes FW to refrain from using Alternate RAM.
    6330                 :            :  *
    6331                 :            :  **/
    6332                 :          0 : enum i40e_status_code i40e_aq_set_oem_mode(struct i40e_hw *hw,
    6333                 :            :                 u8 oem_mode)
    6334                 :            : {
    6335                 :            :         struct i40e_aq_desc desc;
    6336                 :            :         struct i40e_aqc_alternate_write_done *cmd =
    6337                 :            :                 (struct i40e_aqc_alternate_write_done *)&desc.params.raw;
    6338                 :            :         enum i40e_status_code status;
    6339                 :            : 
    6340                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    6341                 :            :                                           i40e_aqc_opc_alternate_set_mode);
    6342                 :            : 
    6343                 :          0 :         cmd->cmd_flags = CPU_TO_LE16(oem_mode);
    6344                 :            : 
    6345                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
    6346                 :            : 
    6347                 :          0 :         return status;
    6348                 :            : }
    6349                 :            : 
    6350                 :            : /**
    6351                 :            :  * i40e_aq_resume_port_tx
    6352                 :            :  * @hw: pointer to the hardware structure
    6353                 :            :  * @cmd_details: pointer to command details structure or NULL
    6354                 :            :  *
    6355                 :            :  * Resume port's Tx traffic
    6356                 :            :  **/
    6357                 :          0 : enum i40e_status_code i40e_aq_resume_port_tx(struct i40e_hw *hw,
    6358                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    6359                 :            : {
    6360                 :            :         struct i40e_aq_desc desc;
    6361                 :            :         enum i40e_status_code status;
    6362                 :            : 
    6363                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
    6364                 :            : 
    6365                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    6366                 :            : 
    6367                 :          0 :         return status;
    6368                 :            : }
    6369                 :            : 
    6370                 :            : /**
    6371                 :            :  * i40e_set_pci_config_data - store PCI bus info
    6372                 :            :  * @hw: pointer to hardware structure
    6373                 :            :  * @link_status: the link status word from PCI config space
    6374                 :            :  *
    6375                 :            :  * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
    6376                 :            :  **/
    6377                 :          0 : void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
    6378                 :            : {
    6379                 :          0 :         hw->bus.type = i40e_bus_type_pci_express;
    6380                 :            : 
    6381   [ #  #  #  #  :          0 :         switch (link_status & I40E_PCI_LINK_WIDTH) {
                      # ]
    6382                 :          0 :         case I40E_PCI_LINK_WIDTH_1:
    6383                 :          0 :                 hw->bus.width = i40e_bus_width_pcie_x1;
    6384                 :          0 :                 break;
    6385                 :          0 :         case I40E_PCI_LINK_WIDTH_2:
    6386                 :          0 :                 hw->bus.width = i40e_bus_width_pcie_x2;
    6387                 :          0 :                 break;
    6388                 :          0 :         case I40E_PCI_LINK_WIDTH_4:
    6389                 :          0 :                 hw->bus.width = i40e_bus_width_pcie_x4;
    6390                 :          0 :                 break;
    6391                 :          0 :         case I40E_PCI_LINK_WIDTH_8:
    6392                 :          0 :                 hw->bus.width = i40e_bus_width_pcie_x8;
    6393                 :          0 :                 break;
    6394                 :          0 :         default:
    6395                 :          0 :                 hw->bus.width = i40e_bus_width_unknown;
    6396                 :          0 :                 break;
    6397                 :            :         }
    6398                 :            : 
    6399   [ #  #  #  # ]:          0 :         switch (link_status & I40E_PCI_LINK_SPEED) {
    6400                 :          0 :         case I40E_PCI_LINK_SPEED_2500:
    6401                 :          0 :                 hw->bus.speed = i40e_bus_speed_2500;
    6402                 :          0 :                 break;
    6403                 :          0 :         case I40E_PCI_LINK_SPEED_5000:
    6404                 :          0 :                 hw->bus.speed = i40e_bus_speed_5000;
    6405                 :          0 :                 break;
    6406                 :          0 :         case I40E_PCI_LINK_SPEED_8000:
    6407                 :          0 :                 hw->bus.speed = i40e_bus_speed_8000;
    6408                 :          0 :                 break;
    6409                 :          0 :         default:
    6410                 :          0 :                 hw->bus.speed = i40e_bus_speed_unknown;
    6411                 :          0 :                 break;
    6412                 :            :         }
    6413                 :          0 : }
    6414                 :            : 
    6415                 :            : /**
    6416                 :            :  * i40e_aq_debug_dump
    6417                 :            :  * @hw: pointer to the hardware structure
    6418                 :            :  * @cluster_id: specific cluster to dump
    6419                 :            :  * @table_id: table id within cluster
    6420                 :            :  * @start_index: index of line in the block to read
    6421                 :            :  * @buff_size: dump buffer size
    6422                 :            :  * @buff: dump buffer
    6423                 :            :  * @ret_buff_size: actual buffer size returned
    6424                 :            :  * @ret_next_table: next block to read
    6425                 :            :  * @ret_next_index: next index to read
    6426                 :            :  * @cmd_details: pointer to command details structure or NULL
    6427                 :            :  *
    6428                 :            :  * Dump internal FW/HW data for debug purposes.
    6429                 :            :  *
    6430                 :            :  **/
    6431                 :          0 : enum i40e_status_code i40e_aq_debug_dump(struct i40e_hw *hw, u8 cluster_id,
    6432                 :            :                                 u8 table_id, u32 start_index, u16 buff_size,
    6433                 :            :                                 void *buff, u16 *ret_buff_size,
    6434                 :            :                                 u8 *ret_next_table, u32 *ret_next_index,
    6435                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    6436                 :            : {
    6437                 :            :         struct i40e_aq_desc desc;
    6438                 :            :         struct i40e_aqc_debug_dump_internals *cmd =
    6439                 :            :                 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
    6440                 :            :         struct i40e_aqc_debug_dump_internals *resp =
    6441                 :            :                 (struct i40e_aqc_debug_dump_internals *)&desc.params.raw;
    6442                 :            :         enum i40e_status_code status;
    6443                 :            : 
    6444         [ #  # ]:          0 :         if (buff_size == 0 || !buff)
    6445                 :            :                 return I40E_ERR_PARAM;
    6446                 :            : 
    6447                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    6448                 :            :                                           i40e_aqc_opc_debug_dump_internals);
    6449                 :            :         /* Indirect Command */
    6450                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    6451         [ #  # ]:          0 :         if (buff_size > I40E_AQ_LARGE_BUF)
    6452                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    6453                 :            : 
    6454                 :          0 :         cmd->cluster_id = cluster_id;
    6455                 :          0 :         cmd->table_id = table_id;
    6456                 :          0 :         cmd->idx = CPU_TO_LE32(start_index);
    6457                 :            : 
    6458                 :          0 :         desc.datalen = CPU_TO_LE16(buff_size);
    6459                 :            : 
    6460                 :          0 :         status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
    6461         [ #  # ]:          0 :         if (!status) {
    6462         [ #  # ]:          0 :                 if (ret_buff_size != NULL)
    6463                 :          0 :                         *ret_buff_size = LE16_TO_CPU(desc.datalen);
    6464         [ #  # ]:          0 :                 if (ret_next_table != NULL)
    6465                 :          0 :                         *ret_next_table = resp->table_id;
    6466         [ #  # ]:          0 :                 if (ret_next_index != NULL)
    6467                 :          0 :                         *ret_next_index = LE32_TO_CPU(resp->idx);
    6468                 :            :         }
    6469                 :            : 
    6470                 :            :         return status;
    6471                 :            : }
    6472                 :            : 
    6473                 :            : /**
    6474                 :            :  * i40e_enable_eee
    6475                 :            :  * @hw: pointer to the hardware structure
    6476                 :            :  * @enable: state of Energy Efficient Ethernet mode to be set
    6477                 :            :  *
    6478                 :            :  * Enables or disables Energy Efficient Ethernet (EEE) mode
    6479                 :            :  * accordingly to @enable parameter.
    6480                 :            :  **/
    6481                 :          0 : enum i40e_status_code i40e_enable_eee(struct i40e_hw *hw, bool enable)
    6482                 :            : {
    6483                 :            :         struct i40e_aq_get_phy_abilities_resp abilities;
    6484                 :            :         struct i40e_aq_set_phy_config config;
    6485                 :            :         enum i40e_status_code status;
    6486                 :            :         __le16 eee_capability;
    6487                 :            : 
    6488                 :            :         /* Get initial PHY capabilities */
    6489                 :          0 :         status = i40e_aq_get_phy_capabilities(hw, false, true, &abilities,
    6490                 :            :                                               NULL);
    6491         [ #  # ]:          0 :         if (status)
    6492                 :          0 :                 goto err;
    6493                 :            : 
    6494                 :            :         /* Check whether NIC configuration is compatible with Energy Efficient
    6495                 :            :          * Ethernet (EEE) mode.
    6496                 :            :          */
    6497         [ #  # ]:          0 :         if (abilities.eee_capability == 0) {
    6498                 :            :                 status = I40E_ERR_CONFIG;
    6499                 :          0 :                 goto err;
    6500                 :            :         }
    6501                 :            : 
    6502                 :            :         /* Cache initial EEE capability */
    6503                 :            :         eee_capability = abilities.eee_capability;
    6504                 :            : 
    6505                 :            :         /* Get current configuration */
    6506                 :          0 :         status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
    6507                 :            :                                               NULL);
    6508         [ #  # ]:          0 :         if (status)
    6509                 :          0 :                 goto err;
    6510                 :            : 
    6511                 :            :         /* Cache current configuration */
    6512                 :          0 :         config.phy_type = abilities.phy_type;
    6513                 :          0 :         config.phy_type_ext = abilities.phy_type_ext;
    6514                 :          0 :         config.link_speed = abilities.link_speed;
    6515                 :          0 :         config.abilities = abilities.abilities |
    6516                 :            :                            I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
    6517                 :          0 :         config.eeer = abilities.eeer_val;
    6518                 :          0 :         config.low_power_ctrl = abilities.d3_lpan;
    6519                 :          0 :         config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
    6520                 :            :                             I40E_AQ_PHY_FEC_CONFIG_MASK;
    6521                 :            : 
    6522                 :            :         /* Set desired EEE state */
    6523         [ #  # ]:          0 :         if (enable) {
    6524                 :          0 :                 config.eee_capability = eee_capability;
    6525                 :          0 :                 config.eeer |= I40E_PRTPM_EEER_TX_LPI_EN_MASK;
    6526                 :            :         } else {
    6527                 :          0 :                 config.eee_capability = 0;
    6528                 :          0 :                 config.eeer &= ~I40E_PRTPM_EEER_TX_LPI_EN_MASK;
    6529                 :            :         }
    6530                 :            : 
    6531                 :            :         /* Save modified config */
    6532                 :          0 :         status = i40e_aq_set_phy_config(hw, &config, NULL);
    6533                 :          0 : err:
    6534                 :          0 :         return status;
    6535                 :            : }
    6536                 :            : 
    6537                 :            : /**
    6538                 :            :  * i40e_read_bw_from_alt_ram
    6539                 :            :  * @hw: pointer to the hardware structure
    6540                 :            :  * @max_bw: pointer for max_bw read
    6541                 :            :  * @min_bw: pointer for min_bw read
    6542                 :            :  * @min_valid: pointer for bool that is true if min_bw is a valid value
    6543                 :            :  * @max_valid: pointer for bool that is true if max_bw is a valid value
    6544                 :            :  *
    6545                 :            :  * Read bw from the alternate ram for the given pf
    6546                 :            :  **/
    6547                 :          0 : enum i40e_status_code i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
    6548                 :            :                                         u32 *max_bw, u32 *min_bw,
    6549                 :            :                                         bool *min_valid, bool *max_valid)
    6550                 :            : {
    6551                 :            :         enum i40e_status_code status;
    6552                 :            :         u32 max_bw_addr, min_bw_addr;
    6553                 :            : 
    6554                 :            :         /* Calculate the address of the min/max bw registers */
    6555                 :          0 :         max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
    6556                 :          0 :                       I40E_ALT_STRUCT_MAX_BW_OFFSET +
    6557                 :          0 :                       (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
    6558                 :          0 :         min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
    6559                 :          0 :                       I40E_ALT_STRUCT_MIN_BW_OFFSET +
    6560                 :            :                       (I40E_ALT_STRUCT_DWORDS_PER_PF * hw->pf_id);
    6561                 :            : 
    6562                 :            :         /* Read the bandwidths from alt ram */
    6563                 :          0 :         status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
    6564                 :            :                                         min_bw_addr, min_bw);
    6565                 :            : 
    6566         [ #  # ]:          0 :         if (*min_bw & I40E_ALT_BW_VALID_MASK)
    6567                 :          0 :                 *min_valid = true;
    6568                 :            :         else
    6569                 :          0 :                 *min_valid = false;
    6570                 :            : 
    6571         [ #  # ]:          0 :         if (*max_bw & I40E_ALT_BW_VALID_MASK)
    6572                 :          0 :                 *max_valid = true;
    6573                 :            :         else
    6574                 :          0 :                 *max_valid = false;
    6575                 :            : 
    6576                 :          0 :         return status;
    6577                 :            : }
    6578                 :            : 
    6579                 :            : /**
    6580                 :            :  * i40e_aq_configure_partition_bw
    6581                 :            :  * @hw: pointer to the hardware structure
    6582                 :            :  * @bw_data: Buffer holding valid pfs and bw limits
    6583                 :            :  * @cmd_details: pointer to command details
    6584                 :            :  *
    6585                 :            :  * Configure partitions guaranteed/max bw
    6586                 :            :  **/
    6587                 :          0 : enum i40e_status_code i40e_aq_configure_partition_bw(struct i40e_hw *hw,
    6588                 :            :                         struct i40e_aqc_configure_partition_bw_data *bw_data,
    6589                 :            :                         struct i40e_asq_cmd_details *cmd_details)
    6590                 :            : {
    6591                 :            :         enum i40e_status_code status;
    6592                 :            :         struct i40e_aq_desc desc;
    6593                 :            :         u16 bwd_size = sizeof(*bw_data);
    6594                 :            : 
    6595                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    6596                 :            :                                 i40e_aqc_opc_configure_partition_bw);
    6597                 :            : 
    6598                 :            :         /* Indirect command */
    6599                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    6600                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
    6601                 :            : 
    6602                 :          0 :         desc.datalen = CPU_TO_LE16(bwd_size);
    6603                 :            : 
    6604                 :          0 :         status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size, cmd_details);
    6605                 :            : 
    6606                 :          0 :         return status;
    6607                 :            : }
    6608                 :            : 
    6609                 :            : /**
    6610                 :            :  * i40e_read_phy_register_clause22
    6611                 :            :  * @hw: pointer to the HW structure
    6612                 :            :  * @reg: register address in the page
    6613                 :            :  * @phy_addr: PHY address on MDIO interface
    6614                 :            :  * @value: PHY register value
    6615                 :            :  *
    6616                 :            :  * Reads specified PHY register value
    6617                 :            :  **/
    6618                 :          0 : enum i40e_status_code i40e_read_phy_register_clause22(struct i40e_hw *hw,
    6619                 :            :                                         u16 reg, u8 phy_addr, u16 *value)
    6620                 :            : {
    6621                 :            :         enum i40e_status_code status = I40E_ERR_TIMEOUT;
    6622                 :          0 :         u8 port_num = (u8)hw->func_caps.mdio_port_num;
    6623                 :            :         u32 command = 0;
    6624                 :            :         u16 retry = 1000;
    6625                 :            : 
    6626                 :          0 :         command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
    6627                 :          0 :                   (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
    6628                 :            :                   (I40E_MDIO_CLAUSE22_OPCODE_READ_MASK) |
    6629                 :          0 :                   (I40E_MDIO_CLAUSE22_STCODE_MASK) |
    6630                 :            :                   (I40E_GLGEN_MSCA_MDICMD_MASK);
    6631                 :          0 :         wr32(hw, I40E_GLGEN_MSCA(port_num), command);
    6632                 :            :         do {
    6633                 :          0 :                 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
    6634         [ #  # ]:          0 :                 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
    6635                 :            :                         status = I40E_SUCCESS;
    6636                 :            :                         break;
    6637                 :            :                 }
    6638                 :          0 :                 i40e_usec_delay(10);
    6639                 :          0 :                 retry--;
    6640         [ #  # ]:          0 :         } while (retry);
    6641                 :            : 
    6642         [ #  # ]:          0 :         if (status) {
    6643         [ #  # ]:          0 :                 i40e_debug(hw, I40E_DEBUG_PHY,
    6644                 :            :                            "PHY: Can't write command to external PHY.\n");
    6645                 :            :         } else {
    6646                 :          0 :                 command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
    6647                 :          0 :                 *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
    6648                 :            :                          I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
    6649                 :            :         }
    6650                 :            : 
    6651                 :          0 :         return status;
    6652                 :            : }
    6653                 :            : 
    6654                 :            : /**
    6655                 :            :  * i40e_write_phy_register_clause22
    6656                 :            :  * @hw: pointer to the HW structure
    6657                 :            :  * @reg: register address in the page
    6658                 :            :  * @phy_addr: PHY address on MDIO interface
    6659                 :            :  * @value: PHY register value
    6660                 :            :  *
    6661                 :            :  * Writes specified PHY register value
    6662                 :            :  **/
    6663                 :          0 : enum i40e_status_code i40e_write_phy_register_clause22(struct i40e_hw *hw,
    6664                 :            :                                         u16 reg, u8 phy_addr, u16 value)
    6665                 :            : {
    6666                 :            :         enum i40e_status_code status = I40E_ERR_TIMEOUT;
    6667                 :          0 :         u8 port_num = (u8)hw->func_caps.mdio_port_num;
    6668                 :            :         u32 command  = 0;
    6669                 :            :         u16 retry = 1000;
    6670                 :            : 
    6671                 :          0 :         command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
    6672                 :          0 :         wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
    6673                 :            : 
    6674                 :          0 :         command = (reg << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
    6675                 :          0 :                   (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
    6676                 :            :                   (I40E_MDIO_CLAUSE22_OPCODE_WRITE_MASK) |
    6677                 :          0 :                   (I40E_MDIO_CLAUSE22_STCODE_MASK) |
    6678                 :            :                   (I40E_GLGEN_MSCA_MDICMD_MASK);
    6679                 :            : 
    6680                 :          0 :         wr32(hw, I40E_GLGEN_MSCA(port_num), command);
    6681                 :            :         do {
    6682                 :          0 :                 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
    6683         [ #  # ]:          0 :                 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
    6684                 :            :                         status = I40E_SUCCESS;
    6685                 :            :                         break;
    6686                 :            :                 }
    6687                 :          0 :                 i40e_usec_delay(10);
    6688                 :          0 :                 retry--;
    6689         [ #  # ]:          0 :         } while (retry);
    6690                 :            : 
    6691                 :          0 :         return status;
    6692                 :            : }
    6693                 :            : 
    6694                 :            : /**
    6695                 :            :  * i40e_read_phy_register_clause45
    6696                 :            :  * @hw: pointer to the HW structure
    6697                 :            :  * @page: registers page number
    6698                 :            :  * @reg: register address in the page
    6699                 :            :  * @phy_addr: PHY address on MDIO interface
    6700                 :            :  * @value: PHY register value
    6701                 :            :  *
    6702                 :            :  * Reads specified PHY register value
    6703                 :            :  **/
    6704                 :          0 : enum i40e_status_code i40e_read_phy_register_clause45(struct i40e_hw *hw,
    6705                 :            :                                 u8 page, u16 reg, u8 phy_addr, u16 *value)
    6706                 :            : {
    6707                 :            :         enum i40e_status_code status = I40E_ERR_TIMEOUT;
    6708                 :            :         u32 command  = 0;
    6709                 :            :         u16 retry = 1000;
    6710                 :          0 :         u8 port_num = (u8)hw->func_caps.mdio_port_num;
    6711                 :            : 
    6712                 :          0 :         command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
    6713                 :          0 :                   (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
    6714                 :          0 :                   (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
    6715                 :          0 :                   (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
    6716                 :            :                   (I40E_MDIO_CLAUSE45_STCODE_MASK) |
    6717                 :          0 :                   (I40E_GLGEN_MSCA_MDICMD_MASK) |
    6718                 :            :                   (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
    6719                 :          0 :         wr32(hw, I40E_GLGEN_MSCA(port_num), command);
    6720                 :            :         do {
    6721                 :          0 :                 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
    6722         [ #  # ]:          0 :                 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
    6723                 :            :                         status = I40E_SUCCESS;
    6724                 :            :                         break;
    6725                 :            :                 }
    6726                 :          0 :                 i40e_usec_delay(10);
    6727                 :          0 :                 retry--;
    6728         [ #  # ]:          0 :         } while (retry);
    6729                 :            : 
    6730         [ #  # ]:          0 :         if (status) {
    6731         [ #  # ]:          0 :                 i40e_debug(hw, I40E_DEBUG_PHY,
    6732                 :            :                            "PHY: Can't write command to external PHY.\n");
    6733                 :          0 :                 goto phy_read_end;
    6734                 :            :         }
    6735                 :            : 
    6736                 :          0 :         command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
    6737                 :            :                   (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
    6738                 :            :                   (I40E_MDIO_CLAUSE45_OPCODE_READ_MASK) |
    6739                 :            :                   (I40E_MDIO_CLAUSE45_STCODE_MASK) |
    6740                 :          0 :                   (I40E_GLGEN_MSCA_MDICMD_MASK) |
    6741                 :            :                   (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
    6742                 :            :         status = I40E_ERR_TIMEOUT;
    6743                 :            :         retry = 1000;
    6744                 :          0 :         wr32(hw, I40E_GLGEN_MSCA(port_num), command);
    6745                 :            :         do {
    6746                 :          0 :                 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
    6747         [ #  # ]:          0 :                 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
    6748                 :            :                         status = I40E_SUCCESS;
    6749                 :            :                         break;
    6750                 :            :                 }
    6751                 :          0 :                 i40e_usec_delay(10);
    6752                 :          0 :                 retry--;
    6753         [ #  # ]:          0 :         } while (retry);
    6754                 :            : 
    6755         [ #  # ]:          0 :         if (!status) {
    6756                 :          0 :                 command = rd32(hw, I40E_GLGEN_MSRWD(port_num));
    6757                 :          0 :                 *value = (command & I40E_GLGEN_MSRWD_MDIRDDATA_MASK) >>
    6758                 :            :                          I40E_GLGEN_MSRWD_MDIRDDATA_SHIFT;
    6759                 :            :         } else {
    6760         [ #  # ]:          0 :                 i40e_debug(hw, I40E_DEBUG_PHY,
    6761                 :            :                            "PHY: Can't read register value from external PHY.\n");
    6762                 :            :         }
    6763                 :            : 
    6764                 :          0 : phy_read_end:
    6765                 :          0 :         return status;
    6766                 :            : }
    6767                 :            : 
    6768                 :            : /**
    6769                 :            :  * i40e_write_phy_register_clause45
    6770                 :            :  * @hw: pointer to the HW structure
    6771                 :            :  * @page: registers page number
    6772                 :            :  * @reg: register address in the page
    6773                 :            :  * @phy_addr: PHY address on MDIO interface
    6774                 :            :  * @value: PHY register value
    6775                 :            :  *
    6776                 :            :  * Writes value to specified PHY register
    6777                 :            :  **/
    6778                 :          0 : enum i40e_status_code i40e_write_phy_register_clause45(struct i40e_hw *hw,
    6779                 :            :                                 u8 page, u16 reg, u8 phy_addr, u16 value)
    6780                 :            : {
    6781                 :            :         enum i40e_status_code status = I40E_ERR_TIMEOUT;
    6782                 :            :         u32 command  = 0;
    6783                 :            :         u16 retry = 1000;
    6784                 :          0 :         u8 port_num = (u8)hw->func_caps.mdio_port_num;
    6785                 :            : 
    6786                 :          0 :         command = (reg << I40E_GLGEN_MSCA_MDIADD_SHIFT) |
    6787                 :          0 :                   (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
    6788                 :          0 :                   (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
    6789                 :          0 :                   (I40E_MDIO_CLAUSE45_OPCODE_ADDRESS_MASK) |
    6790                 :            :                   (I40E_MDIO_CLAUSE45_STCODE_MASK) |
    6791                 :          0 :                   (I40E_GLGEN_MSCA_MDICMD_MASK) |
    6792                 :            :                   (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
    6793                 :          0 :         wr32(hw, I40E_GLGEN_MSCA(port_num), command);
    6794                 :            :         do {
    6795                 :          0 :                 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
    6796         [ #  # ]:          0 :                 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
    6797                 :            :                         status = I40E_SUCCESS;
    6798                 :            :                         break;
    6799                 :            :                 }
    6800                 :          0 :                 i40e_usec_delay(10);
    6801                 :          0 :                 retry--;
    6802         [ #  # ]:          0 :         } while (retry);
    6803         [ #  # ]:          0 :         if (status) {
    6804         [ #  # ]:          0 :                 i40e_debug(hw, I40E_DEBUG_PHY,
    6805                 :            :                            "PHY: Can't write command to external PHY.\n");
    6806                 :          0 :                 goto phy_write_end;
    6807                 :            :         }
    6808                 :            : 
    6809                 :          0 :         command = value << I40E_GLGEN_MSRWD_MDIWRDATA_SHIFT;
    6810                 :          0 :         wr32(hw, I40E_GLGEN_MSRWD(port_num), command);
    6811                 :            : 
    6812                 :          0 :         command = (page << I40E_GLGEN_MSCA_DEVADD_SHIFT) |
    6813                 :            :                   (phy_addr << I40E_GLGEN_MSCA_PHYADD_SHIFT) |
    6814                 :            :                   (I40E_MDIO_CLAUSE45_OPCODE_WRITE_MASK) |
    6815                 :            :                   (I40E_MDIO_CLAUSE45_STCODE_MASK) |
    6816                 :          0 :                   (I40E_GLGEN_MSCA_MDICMD_MASK) |
    6817                 :            :                   (I40E_GLGEN_MSCA_MDIINPROGEN_MASK);
    6818                 :            :         status = I40E_ERR_TIMEOUT;
    6819                 :            :         retry = 1000;
    6820                 :          0 :         wr32(hw, I40E_GLGEN_MSCA(port_num), command);
    6821                 :            :         do {
    6822                 :          0 :                 command = rd32(hw, I40E_GLGEN_MSCA(port_num));
    6823         [ #  # ]:          0 :                 if (!(command & I40E_GLGEN_MSCA_MDICMD_MASK)) {
    6824                 :            :                         status = I40E_SUCCESS;
    6825                 :            :                         break;
    6826                 :            :                 }
    6827                 :          0 :                 i40e_usec_delay(10);
    6828                 :          0 :                 retry--;
    6829         [ #  # ]:          0 :         } while (retry);
    6830                 :            : 
    6831                 :          0 : phy_write_end:
    6832                 :          0 :         return status;
    6833                 :            : }
    6834                 :            : 
    6835                 :            : /**
    6836                 :            :  * i40e_write_phy_register
    6837                 :            :  * @hw: pointer to the HW structure
    6838                 :            :  * @page: registers page number
    6839                 :            :  * @reg: register address in the page
    6840                 :            :  * @phy_addr: PHY address on MDIO interface
    6841                 :            :  * @value: PHY register value
    6842                 :            :  *
    6843                 :            :  * Writes value to specified PHY register
    6844                 :            :  **/
    6845                 :          0 : enum i40e_status_code i40e_write_phy_register(struct i40e_hw *hw,
    6846                 :            :                                 u8 page, u16 reg, u8 phy_addr, u16 value)
    6847                 :            : {
    6848                 :            :         enum i40e_status_code status;
    6849                 :            : 
    6850      [ #  #  # ]:          0 :         switch (hw->device_id) {
    6851                 :          0 :         case I40E_DEV_ID_1G_BASE_T_X722:
    6852                 :          0 :                 status = i40e_write_phy_register_clause22(hw,
    6853                 :            :                         reg, phy_addr, value);
    6854                 :          0 :                 break;
    6855                 :          0 :         case I40E_DEV_ID_10G_BASE_T:
    6856                 :            :         case I40E_DEV_ID_10G_BASE_T4:
    6857                 :            :         case I40E_DEV_ID_10G_BASE_T_BC:
    6858                 :            :         case I40E_DEV_ID_5G_BASE_T_BC:
    6859                 :            :         case I40E_DEV_ID_1G_BASE_T_BC:
    6860                 :            :         case I40E_DEV_ID_10G_BASE_T_X722:
    6861                 :            :         case I40E_DEV_ID_25G_B:
    6862                 :            :         case I40E_DEV_ID_25G_SFP28:
    6863                 :          0 :                 status = i40e_write_phy_register_clause45(hw,
    6864                 :            :                         page, reg, phy_addr, value);
    6865                 :          0 :                 break;
    6866                 :            :         default:
    6867                 :            :                 status = I40E_ERR_UNKNOWN_PHY;
    6868                 :            :                 break;
    6869                 :            :         }
    6870                 :            : 
    6871                 :          0 :         return status;
    6872                 :            : }
    6873                 :            : 
    6874                 :            : /**
    6875                 :            :  * i40e_read_phy_register
    6876                 :            :  * @hw: pointer to the HW structure
    6877                 :            :  * @page: registers page number
    6878                 :            :  * @reg: register address in the page
    6879                 :            :  * @phy_addr: PHY address on MDIO interface
    6880                 :            :  * @value: PHY register value
    6881                 :            :  *
    6882                 :            :  * Reads specified PHY register value
    6883                 :            :  **/
    6884                 :          0 : enum i40e_status_code i40e_read_phy_register(struct i40e_hw *hw,
    6885                 :            :                                 u8 page, u16 reg, u8 phy_addr, u16 *value)
    6886                 :            : {
    6887                 :            :         enum i40e_status_code status;
    6888                 :            : 
    6889      [ #  #  # ]:          0 :         switch (hw->device_id) {
    6890                 :          0 :         case I40E_DEV_ID_1G_BASE_T_X722:
    6891                 :          0 :                 status = i40e_read_phy_register_clause22(hw, reg, phy_addr,
    6892                 :            :                                                          value);
    6893                 :          0 :                 break;
    6894                 :          0 :         case I40E_DEV_ID_10G_BASE_T:
    6895                 :            :         case I40E_DEV_ID_10G_BASE_T4:
    6896                 :            :         case I40E_DEV_ID_10G_BASE_T_BC:
    6897                 :            :         case I40E_DEV_ID_5G_BASE_T_BC:
    6898                 :            :         case I40E_DEV_ID_1G_BASE_T_BC:
    6899                 :            :         case I40E_DEV_ID_10G_BASE_T_X722:
    6900                 :            :         case I40E_DEV_ID_25G_B:
    6901                 :            :         case I40E_DEV_ID_25G_SFP28:
    6902                 :          0 :                 status = i40e_read_phy_register_clause45(hw, page, reg,
    6903                 :            :                                                          phy_addr, value);
    6904                 :          0 :                 break;
    6905                 :            :         default:
    6906                 :            :                 status = I40E_ERR_UNKNOWN_PHY;
    6907                 :            :                 break;
    6908                 :            :         }
    6909                 :            : 
    6910                 :          0 :         return status;
    6911                 :            : }
    6912                 :            : 
    6913                 :            : /**
    6914                 :            :  * i40e_get_phy_address
    6915                 :            :  * @hw: pointer to the HW structure
    6916                 :            :  * @dev_num: PHY port num that address we want
    6917                 :            :  *
    6918                 :            :  * Gets PHY address for current port
    6919                 :            :  **/
    6920                 :          0 : u8 i40e_get_phy_address(struct i40e_hw *hw, u8 dev_num)
    6921                 :            : {
    6922                 :          0 :         u8 port_num = (u8)hw->func_caps.mdio_port_num;
    6923                 :          0 :         u32 reg_val = rd32(hw, I40E_GLGEN_MDIO_I2C_SEL(port_num));
    6924                 :            : 
    6925                 :          0 :         return (u8)(reg_val >> ((dev_num + 1) * 5)) & 0x1f;
    6926                 :            : }
    6927                 :            : 
    6928                 :            : /**
    6929                 :            :  * i40e_blink_phy_link_led
    6930                 :            :  * @hw: pointer to the HW structure
    6931                 :            :  * @time: time how long led will blinks in secs
    6932                 :            :  * @interval: gap between LED on and off in msecs
    6933                 :            :  *
    6934                 :            :  * Blinks PHY link LED
    6935                 :            :  **/
    6936                 :          0 : enum i40e_status_code i40e_blink_phy_link_led(struct i40e_hw *hw,
    6937                 :            :                                               u32 time, u32 interval)
    6938                 :            : {
    6939                 :            :         enum i40e_status_code status = I40E_SUCCESS;
    6940                 :            :         u32 i;
    6941                 :            :         u16 led_ctl = 0;
    6942                 :            :         u16 gpio_led_port;
    6943                 :            :         u16 led_reg;
    6944                 :            :         u16 led_addr = I40E_PHY_LED_PROV_REG_1;
    6945                 :            :         u8 phy_addr = 0;
    6946                 :            :         u8 port_num;
    6947                 :            : 
    6948                 :          0 :         i = rd32(hw, I40E_PFGEN_PORTNUM);
    6949                 :          0 :         port_num = (u8)(i & I40E_PFGEN_PORTNUM_PORT_NUM_MASK);
    6950                 :          0 :         phy_addr = i40e_get_phy_address(hw, port_num);
    6951                 :            : 
    6952         [ #  # ]:          0 :         for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
    6953                 :          0 :              led_addr++) {
    6954                 :          0 :                 status = i40e_read_phy_register_clause45(hw,
    6955                 :            :                                                          I40E_PHY_COM_REG_PAGE,
    6956                 :            :                                                          led_addr, phy_addr,
    6957                 :            :                                                          &led_reg);
    6958         [ #  # ]:          0 :                 if (status)
    6959                 :          0 :                         goto phy_blinking_end;
    6960                 :          0 :                 led_ctl = led_reg;
    6961         [ #  # ]:          0 :                 if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
    6962                 :          0 :                         led_reg = 0;
    6963                 :          0 :                         status = i40e_write_phy_register_clause45(hw,
    6964                 :            :                                                          I40E_PHY_COM_REG_PAGE,
    6965                 :            :                                                          led_addr, phy_addr,
    6966                 :            :                                                          led_reg);
    6967         [ #  # ]:          0 :                         if (status)
    6968                 :          0 :                                 goto phy_blinking_end;
    6969                 :            :                         break;
    6970                 :            :                 }
    6971                 :            :         }
    6972                 :            : 
    6973         [ #  # ]:          0 :         if (time > 0 && interval > 0) {
    6974         [ #  # ]:          0 :                 for (i = 0; i < time * 1000; i += interval) {
    6975                 :          0 :                         status = i40e_read_phy_register_clause45(hw,
    6976                 :            :                                                 I40E_PHY_COM_REG_PAGE,
    6977                 :            :                                                 led_addr, phy_addr, &led_reg);
    6978         [ #  # ]:          0 :                         if (status)
    6979                 :          0 :                                 goto restore_config;
    6980         [ #  # ]:          0 :                         if (led_reg & I40E_PHY_LED_MANUAL_ON)
    6981                 :          0 :                                 led_reg = 0;
    6982                 :            :                         else
    6983                 :          0 :                                 led_reg = I40E_PHY_LED_MANUAL_ON;
    6984                 :          0 :                         status = i40e_write_phy_register_clause45(hw,
    6985                 :            :                                                 I40E_PHY_COM_REG_PAGE,
    6986                 :            :                                                 led_addr, phy_addr, led_reg);
    6987         [ #  # ]:          0 :                         if (status)
    6988                 :          0 :                                 goto restore_config;
    6989                 :          0 :                         i40e_msec_delay(interval);
    6990                 :            :                 }
    6991                 :            :         }
    6992                 :            : 
    6993                 :          0 : restore_config:
    6994                 :          0 :         status = i40e_write_phy_register_clause45(hw,
    6995                 :            :                                                   I40E_PHY_COM_REG_PAGE,
    6996                 :            :                                                   led_addr, phy_addr, led_ctl);
    6997                 :            : 
    6998                 :          0 : phy_blinking_end:
    6999                 :          0 :         return status;
    7000                 :            : }
    7001                 :            : 
    7002                 :            : /**
    7003                 :            :  * i40e_led_get_reg - read LED register
    7004                 :            :  * @hw: pointer to the HW structure
    7005                 :            :  * @led_addr: LED register address
    7006                 :            :  * @reg_val: read register value
    7007                 :            :  **/
    7008                 :          0 : enum i40e_status_code i40e_led_get_reg(struct i40e_hw *hw, u16 led_addr,
    7009                 :            :                                        u32 *reg_val)
    7010                 :            : {
    7011                 :            :         enum i40e_status_code status;
    7012                 :            :         u8 phy_addr = 0;
    7013                 :            : 
    7014                 :          0 :         *reg_val = 0;
    7015         [ #  # ]:          0 :         if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
    7016                 :          0 :                 status = i40e_aq_get_phy_register(hw,
    7017                 :            :                                                 I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
    7018                 :            :                                                 I40E_PHY_COM_REG_PAGE, true,
    7019                 :            :                                                 I40E_PHY_LED_PROV_REG_1,
    7020                 :            :                                                 reg_val, NULL);
    7021                 :            :         } else {
    7022                 :          0 :                 phy_addr = i40e_get_phy_address(hw, hw->port);
    7023                 :          0 :                 status = i40e_read_phy_register_clause45(hw,
    7024                 :            :                                                          I40E_PHY_COM_REG_PAGE,
    7025                 :            :                                                          led_addr, phy_addr,
    7026                 :            :                                                          (u16 *)reg_val);
    7027                 :            :         }
    7028                 :          0 :         return status;
    7029                 :            : }
    7030                 :            : 
    7031                 :            : /**
    7032                 :            :  * i40e_led_set_reg - write LED register
    7033                 :            :  * @hw: pointer to the HW structure
    7034                 :            :  * @led_addr: LED register address
    7035                 :            :  * @reg_val: register value to write
    7036                 :            :  **/
    7037                 :          0 : enum i40e_status_code i40e_led_set_reg(struct i40e_hw *hw, u16 led_addr,
    7038                 :            :                                        u32 reg_val)
    7039                 :            : {
    7040                 :            :         enum i40e_status_code status;
    7041                 :            :         u8 phy_addr = 0;
    7042                 :            : 
    7043         [ #  # ]:          0 :         if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
    7044                 :          0 :                 status = i40e_aq_set_phy_register(hw,
    7045                 :            :                                                 I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
    7046                 :            :                                                 I40E_PHY_COM_REG_PAGE, true,
    7047                 :            :                                                 I40E_PHY_LED_PROV_REG_1,
    7048                 :            :                                                 reg_val, NULL);
    7049                 :            :         } else {
    7050                 :          0 :                 phy_addr = i40e_get_phy_address(hw, hw->port);
    7051                 :          0 :                 status = i40e_write_phy_register_clause45(hw,
    7052                 :            :                                                           I40E_PHY_COM_REG_PAGE,
    7053                 :            :                                                           led_addr, phy_addr,
    7054                 :            :                                                           (u16)reg_val);
    7055                 :            :         }
    7056                 :            : 
    7057                 :          0 :         return status;
    7058                 :            : }
    7059                 :            : 
    7060                 :            : /**
    7061                 :            :  * i40e_led_get_phy - return current on/off mode
    7062                 :            :  * @hw: pointer to the hw struct
    7063                 :            :  * @led_addr: address of led register to use
    7064                 :            :  * @val: original value of register to use
    7065                 :            :  *
    7066                 :            :  **/
    7067                 :          0 : enum i40e_status_code i40e_led_get_phy(struct i40e_hw *hw, u16 *led_addr,
    7068                 :            :                                        u16 *val)
    7069                 :            : {
    7070                 :            :         enum i40e_status_code status = I40E_SUCCESS;
    7071                 :            :         u16 gpio_led_port;
    7072                 :            :         u32 reg_val_aq;
    7073                 :            :         u16 temp_addr;
    7074                 :            :         u8 phy_addr = 0;
    7075                 :            :         u16 reg_val;
    7076                 :            : 
    7077         [ #  # ]:          0 :         if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE) {
    7078                 :          0 :                 status = i40e_aq_get_phy_register(hw,
    7079                 :            :                                                 I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
    7080                 :            :                                                 I40E_PHY_COM_REG_PAGE, true,
    7081                 :            :                                                 I40E_PHY_LED_PROV_REG_1,
    7082                 :            :                                                 &reg_val_aq, NULL);
    7083         [ #  # ]:          0 :                 if (status == I40E_SUCCESS)
    7084                 :          0 :                         *val = (u16)reg_val_aq;
    7085                 :          0 :                 return status;
    7086                 :            :         }
    7087                 :            :         temp_addr = I40E_PHY_LED_PROV_REG_1;
    7088                 :          0 :         phy_addr = i40e_get_phy_address(hw, hw->port);
    7089         [ #  # ]:          0 :         for (gpio_led_port = 0; gpio_led_port < 3; gpio_led_port++,
    7090                 :          0 :              temp_addr++) {
    7091                 :          0 :                 status = i40e_read_phy_register_clause45(hw,
    7092                 :            :                                                          I40E_PHY_COM_REG_PAGE,
    7093                 :            :                                                          temp_addr, phy_addr,
    7094                 :            :                                                          &reg_val);
    7095         [ #  # ]:          0 :                 if (status)
    7096                 :          0 :                         return status;
    7097                 :          0 :                 *val = reg_val;
    7098         [ #  # ]:          0 :                 if (reg_val & I40E_PHY_LED_LINK_MODE_MASK) {
    7099                 :          0 :                         *led_addr = temp_addr;
    7100                 :          0 :                         break;
    7101                 :            :                 }
    7102                 :            :         }
    7103                 :            :         return status;
    7104                 :            : }
    7105                 :            : 
    7106                 :            : /**
    7107                 :            :  * i40e_led_set_phy
    7108                 :            :  * @hw: pointer to the HW structure
    7109                 :            :  * @on: true or false
    7110                 :            :  * @led_addr: address of led register to use
    7111                 :            :  * @mode: original val plus bit for set or ignore
    7112                 :            :  *
    7113                 :            :  * Set led's on or off when controlled by the PHY
    7114                 :            :  *
    7115                 :            :  **/
    7116                 :          0 : enum i40e_status_code i40e_led_set_phy(struct i40e_hw *hw, bool on,
    7117                 :            :                                        u16 led_addr, u32 mode)
    7118                 :            : {
    7119                 :            :         enum i40e_status_code status = I40E_SUCCESS;
    7120                 :            :         u32 led_ctl = 0;
    7121                 :          0 :         u32 led_reg = 0;
    7122                 :            : 
    7123                 :          0 :         status = i40e_led_get_reg(hw, led_addr, &led_reg);
    7124         [ #  # ]:          0 :         if (status)
    7125                 :            :                 return status;
    7126                 :          0 :         led_ctl = led_reg;
    7127         [ #  # ]:          0 :         if (led_reg & I40E_PHY_LED_LINK_MODE_MASK) {
    7128                 :          0 :                 led_reg = 0;
    7129                 :          0 :                 status = i40e_led_set_reg(hw, led_addr, led_reg);
    7130         [ #  # ]:          0 :                 if (status)
    7131                 :            :                         return status;
    7132                 :            :         }
    7133                 :          0 :         status = i40e_led_get_reg(hw, led_addr, &led_reg);
    7134         [ #  # ]:          0 :         if (status)
    7135                 :          0 :                 goto restore_config;
    7136         [ #  # ]:          0 :         if (on)
    7137                 :          0 :                 led_reg = I40E_PHY_LED_MANUAL_ON;
    7138                 :            :         else
    7139                 :          0 :                 led_reg = 0;
    7140                 :          0 :         status = i40e_led_set_reg(hw, led_addr, led_reg);
    7141         [ #  # ]:          0 :         if (status)
    7142                 :          0 :                 goto restore_config;
    7143         [ #  # ]:          0 :         if (mode & I40E_PHY_LED_MODE_ORIG) {
    7144                 :          0 :                 led_ctl = (mode & I40E_PHY_LED_MODE_MASK);
    7145                 :          0 :                 status = i40e_led_set_reg(hw, led_addr, led_ctl);
    7146                 :            :         }
    7147                 :            :         return status;
    7148                 :            : 
    7149                 :          0 : restore_config:
    7150                 :          0 :         status = i40e_led_set_reg(hw, led_addr, led_ctl);
    7151                 :          0 :         return status;
    7152                 :            : }
    7153                 :            : 
    7154                 :            : /**
    7155                 :            :  * i40e_get_phy_lpi_status - read LPI status from PHY or MAC register
    7156                 :            :  * @hw: pointer to the hw struct
    7157                 :            :  * @stat: pointer to structure with status of rx and tx lpi
    7158                 :            :  *
    7159                 :            :  * Read LPI state directly from external PHY register or from MAC
    7160                 :            :  * register, depending on device ID and current link speed.
    7161                 :            :  */
    7162                 :          0 : enum i40e_status_code i40e_get_phy_lpi_status(struct i40e_hw *hw,
    7163                 :            :                                               struct i40e_hw_port_stats *stat)
    7164                 :            : {
    7165                 :            :         enum i40e_status_code ret = I40E_SUCCESS;
    7166                 :            :         bool eee_mrvl_phy;
    7167                 :            :         bool eee_bcm_phy;
    7168                 :            :         u32 val;
    7169                 :            : 
    7170                 :          0 :         stat->rx_lpi_status = 0;
    7171                 :          0 :         stat->tx_lpi_status = 0;
    7172                 :            : 
    7173                 :          0 :         eee_bcm_phy =
    7174                 :          0 :                 (hw->device_id == I40E_DEV_ID_10G_BASE_T_BC ||
    7175         [ #  # ]:          0 :                  hw->device_id == I40E_DEV_ID_5G_BASE_T_BC) &&
    7176         [ #  # ]:          0 :                 (hw->phy.link_info.link_speed == I40E_LINK_SPEED_2_5GB ||
    7177                 :            :                  hw->phy.link_info.link_speed == I40E_LINK_SPEED_5GB);
    7178                 :          0 :         eee_mrvl_phy =
    7179                 :            :                 hw->device_id == I40E_DEV_ID_1G_BASE_T_X722;
    7180                 :            : 
    7181         [ #  # ]:          0 :         if (eee_bcm_phy || eee_mrvl_phy) {
    7182                 :            :                 /* read Clause 45 PCS Status 1 register */
    7183                 :          0 :                 ret = i40e_aq_get_phy_register(hw,
    7184                 :            :                                                I40E_AQ_PHY_REG_ACCESS_EXTERNAL,
    7185                 :            :                                                I40E_BCM_PHY_PCS_STATUS1_PAGE,
    7186                 :            :                                                true,
    7187                 :            :                                                I40E_BCM_PHY_PCS_STATUS1_REG,
    7188                 :            :                                                &val, NULL);
    7189                 :            : 
    7190         [ #  # ]:          0 :                 if (ret != I40E_SUCCESS)
    7191                 :            :                         return ret;
    7192                 :            : 
    7193                 :          0 :                 stat->rx_lpi_status = !!(val & I40E_BCM_PHY_PCS_STATUS1_RX_LPI);
    7194                 :          0 :                 stat->tx_lpi_status = !!(val & I40E_BCM_PHY_PCS_STATUS1_TX_LPI);
    7195                 :            : 
    7196                 :          0 :                 return ret;
    7197                 :            :         }
    7198                 :            : 
    7199                 :          0 :         val = rd32(hw, I40E_PRTPM_EEE_STAT);
    7200                 :          0 :         stat->rx_lpi_status = (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
    7201                 :            :                                I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
    7202                 :          0 :         stat->tx_lpi_status = (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
    7203                 :            :                                I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
    7204                 :            : 
    7205                 :          0 :         return ret;
    7206                 :            : }
    7207                 :            : 
    7208                 :            : /**
    7209                 :            :  * i40e_get_lpi_counters - read LPI counters from EEE statistics
    7210                 :            :  * @hw: pointer to the hw struct
    7211                 :            :  * @tx_counter: pointer to memory for TX LPI counter
    7212                 :            :  * @rx_counter: pointer to memory for RX LPI counter
    7213                 :            :  * @is_clear:   returns true if counters are clear after read
    7214                 :            :  *
    7215                 :            :  * Read Low Power Idle (LPI) mode counters from Energy Efficient
    7216                 :            :  * Ethernet (EEE) statistics.
    7217                 :            :  **/
    7218                 :          0 : enum i40e_status_code i40e_get_lpi_counters(struct i40e_hw *hw,
    7219                 :            :                                             u32 *tx_counter, u32 *rx_counter,
    7220                 :            :                                             bool *is_clear)
    7221                 :            : {
    7222                 :            :         /* only X710-T*L requires special handling of counters
    7223                 :            :          * for other devices we just read the MAC registers
    7224                 :            :          */
    7225         [ #  # ]:          0 :         if ((hw->device_id == I40E_DEV_ID_10G_BASE_T_BC ||
    7226                 :          0 :              hw->device_id == I40E_DEV_ID_5G_BASE_T_BC) &&
    7227         [ #  # ]:          0 :              hw->phy.link_info.link_speed != I40E_LINK_SPEED_1GB) {
    7228                 :            :                 enum i40e_status_code retval;
    7229                 :            :                 u32 cmd_status;
    7230                 :            : 
    7231                 :          0 :                 *is_clear = false;
    7232                 :          0 :                 retval = i40e_aq_run_phy_activity(hw,
    7233                 :            :                                 I40E_AQ_RUN_PHY_ACT_ID_USR_DFND,
    7234                 :            :                                 I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_STAT,
    7235                 :            :                                 &cmd_status, tx_counter, rx_counter, NULL);
    7236                 :            : 
    7237   [ #  #  #  # ]:          0 :                 if (!retval && cmd_status != I40E_AQ_RUN_PHY_ACT_CMD_STAT_SUCC)
    7238                 :            :                         retval = I40E_ERR_ADMIN_QUEUE_ERROR;
    7239                 :            : 
    7240                 :            :                 return retval;
    7241                 :            :         }
    7242                 :            : 
    7243                 :          0 :         *is_clear = true;
    7244                 :          0 :         *tx_counter = rd32(hw, I40E_PRTPM_TLPIC);
    7245                 :          0 :         *rx_counter = rd32(hw, I40E_PRTPM_RLPIC);
    7246                 :            : 
    7247                 :          0 :         return I40E_SUCCESS;
    7248                 :            : }
    7249                 :            : 
    7250                 :            : /**
    7251                 :            :  * i40e_get_lpi_duration - read LPI time duration from EEE statistics
    7252                 :            :  * @hw: pointer to the hw struct
    7253                 :            :  * @stat: pointer to structure with status of rx and tx lpi
    7254                 :            :  * @tx_duration: pointer to memory for TX LPI time duration
    7255                 :            :  * @rx_duration: pointer to memory for RX LPI time duration
    7256                 :            :  *
    7257                 :            :  * Read Low Power Idle (LPI) mode time duration from Energy Efficient
    7258                 :            :  * Ethernet (EEE) statistics.
    7259                 :            :  */
    7260                 :          0 : enum i40e_status_code i40e_get_lpi_duration(struct i40e_hw *hw,
    7261                 :            :                                             struct i40e_hw_port_stats *stat,
    7262                 :            :                                             u64 *tx_duration, u64 *rx_duration)
    7263                 :            : {
    7264                 :            :         u32 tx_time_dur, rx_time_dur;
    7265                 :            :         enum i40e_status_code retval;
    7266                 :            :         u32 cmd_status;
    7267                 :            : 
    7268         [ #  # ]:          0 :         if (hw->device_id != I40E_DEV_ID_10G_BASE_T_BC &&
    7269                 :            :             hw->device_id != I40E_DEV_ID_5G_BASE_T_BC)
    7270                 :            :                 return I40E_ERR_NOT_IMPLEMENTED;
    7271                 :            : 
    7272                 :          0 :         retval = i40e_aq_run_phy_activity
    7273                 :            :                 (hw, I40E_AQ_RUN_PHY_ACT_ID_USR_DFND,
    7274                 :            :                 I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_DUR,
    7275                 :            :                 &cmd_status, &tx_time_dur, &rx_time_dur, NULL);
    7276                 :            : 
    7277         [ #  # ]:          0 :         if (retval)
    7278                 :            :                 return retval;
    7279         [ #  # ]:          0 :         if ((cmd_status & I40E_AQ_RUN_PHY_ACT_CMD_STAT_MASK) !=
    7280                 :            :             I40E_AQ_RUN_PHY_ACT_CMD_STAT_SUCC)
    7281                 :            :                 return I40E_ERR_ADMIN_QUEUE_ERROR;
    7282                 :            : 
    7283         [ #  # ]:          0 :         if (hw->phy.link_info.link_speed == I40E_LINK_SPEED_1GB &&
    7284   [ #  #  #  # ]:          0 :             !tx_time_dur && !rx_time_dur &&
    7285   [ #  #  #  # ]:          0 :             stat->tx_lpi_status && stat->rx_lpi_status) {
    7286                 :          0 :                 retval = i40e_aq_run_phy_activity
    7287                 :            :                         (hw, I40E_AQ_RUN_PHY_ACT_ID_USR_DFND,
    7288                 :            :                         I40E_AQ_RUN_PHY_ACT_DNL_OPCODE_GET_EEE_STAT_DUR,
    7289                 :            :                         &cmd_status,
    7290                 :            :                         &tx_time_dur, &rx_time_dur, NULL);
    7291                 :            : 
    7292         [ #  # ]:          0 :                 if (retval)
    7293                 :            :                         return retval;
    7294         [ #  # ]:          0 :                 if ((cmd_status & I40E_AQ_RUN_PHY_ACT_CMD_STAT_MASK) !=
    7295                 :            :                     I40E_AQ_RUN_PHY_ACT_CMD_STAT_SUCC)
    7296                 :            :                         return I40E_ERR_ADMIN_QUEUE_ERROR;
    7297                 :          0 :                 tx_time_dur = 0;
    7298                 :          0 :                 rx_time_dur = 0;
    7299                 :            :         }
    7300                 :            : 
    7301                 :          0 :         *tx_duration = tx_time_dur;
    7302                 :          0 :         *rx_duration = rx_time_dur;
    7303                 :            : 
    7304                 :          0 :         return retval;
    7305                 :            : }
    7306                 :            : 
    7307                 :            : /**
    7308                 :            :  * i40e_lpi_stat_update - update LPI counters with values relative to offset
    7309                 :            :  * @hw: pointer to the hw struct
    7310                 :            :  * @offset_loaded: flag indicating need of writing current value to offset
    7311                 :            :  * @tx_offset: pointer to offset of TX LPI counter
    7312                 :            :  * @tx_stat: pointer to value of TX LPI counter
    7313                 :            :  * @rx_offset: pointer to offset of RX LPI counter
    7314                 :            :  * @rx_stat: pointer to value of RX LPI counter
    7315                 :            :  *
    7316                 :            :  * Update Low Power Idle (LPI) mode counters while having regard to passed
    7317                 :            :  * offsets.
    7318                 :            :  **/
    7319                 :          0 : enum i40e_status_code i40e_lpi_stat_update(struct i40e_hw *hw,
    7320                 :            :                                            bool offset_loaded, u64 *tx_offset,
    7321                 :            :                                            u64 *tx_stat, u64 *rx_offset,
    7322                 :            :                                            u64 *rx_stat)
    7323                 :            : {
    7324                 :            :         enum i40e_status_code retval;
    7325                 :            :         u32 tx_counter, rx_counter;
    7326                 :            :         bool is_clear;
    7327                 :            : 
    7328                 :          0 :         retval = i40e_get_lpi_counters(hw, &tx_counter, &rx_counter, &is_clear);
    7329         [ #  # ]:          0 :         if (retval)
    7330                 :          0 :                 goto err;
    7331                 :            : 
    7332         [ #  # ]:          0 :         if (is_clear) {
    7333                 :          0 :                 *tx_stat += tx_counter;
    7334                 :          0 :                 *rx_stat += rx_counter;
    7335                 :            :         } else {
    7336         [ #  # ]:          0 :                 if (!offset_loaded) {
    7337                 :          0 :                         *tx_offset = tx_counter;
    7338                 :          0 :                         *rx_offset = rx_counter;
    7339                 :            :                 }
    7340                 :            : 
    7341                 :          0 :                 *tx_stat = (tx_counter >= *tx_offset) ?
    7342                 :          0 :                         (u32)(tx_counter - *tx_offset) :
    7343                 :            :                         (u32)((tx_counter + BIT_ULL(32)) - *tx_offset);
    7344                 :          0 :                 *rx_stat = (rx_counter >= *rx_offset) ?
    7345                 :          0 :                         (u32)(rx_counter - *rx_offset) :
    7346                 :            :                         (u32)((rx_counter + BIT_ULL(32)) - *rx_offset);
    7347                 :            :         }
    7348                 :          0 : err:
    7349                 :          0 :         return retval;
    7350                 :            : }
    7351                 :            : 
    7352                 :            : /**
    7353                 :            :  * i40e_aq_rx_ctl_read_register - use FW to read from an Rx control register
    7354                 :            :  * @hw: pointer to the hw struct
    7355                 :            :  * @reg_addr: register address
    7356                 :            :  * @reg_val: ptr to register value
    7357                 :            :  * @cmd_details: pointer to command details structure or NULL
    7358                 :            :  *
    7359                 :            :  * Use the firmware to read the Rx control register,
    7360                 :            :  * especially useful if the Rx unit is under heavy pressure
    7361                 :            :  **/
    7362                 :          0 : enum i40e_status_code i40e_aq_rx_ctl_read_register(struct i40e_hw *hw,
    7363                 :            :                                 u32 reg_addr, u32 *reg_val,
    7364                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    7365                 :            : {
    7366                 :            :         struct i40e_aq_desc desc;
    7367                 :            :         struct i40e_aqc_rx_ctl_reg_read_write *cmd_resp =
    7368                 :            :                 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
    7369                 :            :         enum i40e_status_code status;
    7370                 :            : 
    7371         [ #  # ]:          0 :         if (reg_val == NULL)
    7372                 :            :                 return I40E_ERR_PARAM;
    7373                 :            : 
    7374                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_read);
    7375                 :            : 
    7376                 :          0 :         cmd_resp->address = CPU_TO_LE32(reg_addr);
    7377                 :            : 
    7378                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    7379                 :            : 
    7380         [ #  # ]:          0 :         if (status == I40E_SUCCESS)
    7381                 :          0 :                 *reg_val = LE32_TO_CPU(cmd_resp->value);
    7382                 :            : 
    7383                 :            :         return status;
    7384                 :            : }
    7385                 :            : 
    7386                 :            : /**
    7387                 :            :  * i40e_read_rx_ctl - read from an Rx control register
    7388                 :            :  * @hw: pointer to the hw struct
    7389                 :            :  * @reg_addr: register address
    7390                 :            :  **/
    7391                 :          0 : u32 i40e_read_rx_ctl(struct i40e_hw *hw, u32 reg_addr)
    7392                 :            : {
    7393                 :            :         enum i40e_status_code status = I40E_SUCCESS;
    7394                 :            :         bool use_register;
    7395                 :            :         int retry = 5;
    7396                 :          0 :         u32 val = 0;
    7397                 :            : 
    7398                 :          0 :         use_register = (((hw->aq.api_maj_ver == 1) &&
    7399   [ #  #  #  # ]:          0 :                         (hw->aq.api_min_ver < 5)) ||
    7400         [ #  # ]:          0 :                         (hw->mac.type == I40E_MAC_X722));
    7401         [ #  # ]:          0 :         if (!use_register) {
    7402                 :          0 : do_retry:
    7403                 :          0 :                 status = i40e_aq_rx_ctl_read_register(hw, reg_addr, &val, NULL);
    7404   [ #  #  #  # ]:          0 :                 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
    7405                 :          0 :                         i40e_msec_delay(1);
    7406                 :          0 :                         retry--;
    7407                 :          0 :                         goto do_retry;
    7408                 :            :                 }
    7409                 :            :         }
    7410                 :            : 
    7411                 :            :         /* if the AQ access failed, try the old-fashioned way */
    7412         [ #  # ]:          0 :         if (status || use_register)
    7413                 :          0 :                 val = rd32(hw, reg_addr);
    7414                 :            : 
    7415                 :          0 :         return val;
    7416                 :            : }
    7417                 :            : 
    7418                 :            : /**
    7419                 :            :  * i40e_aq_rx_ctl_write_register
    7420                 :            :  * @hw: pointer to the hw struct
    7421                 :            :  * @reg_addr: register address
    7422                 :            :  * @reg_val: register value
    7423                 :            :  * @cmd_details: pointer to command details structure or NULL
    7424                 :            :  *
    7425                 :            :  * Use the firmware to write to an Rx control register,
    7426                 :            :  * especially useful if the Rx unit is under heavy pressure
    7427                 :            :  **/
    7428                 :          0 : enum i40e_status_code i40e_aq_rx_ctl_write_register(struct i40e_hw *hw,
    7429                 :            :                                 u32 reg_addr, u32 reg_val,
    7430                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    7431                 :            : {
    7432                 :            :         struct i40e_aq_desc desc;
    7433                 :            :         struct i40e_aqc_rx_ctl_reg_read_write *cmd =
    7434                 :            :                 (struct i40e_aqc_rx_ctl_reg_read_write *)&desc.params.raw;
    7435                 :            :         enum i40e_status_code status;
    7436                 :            : 
    7437                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_rx_ctl_reg_write);
    7438                 :            : 
    7439                 :          0 :         cmd->address = CPU_TO_LE32(reg_addr);
    7440                 :          0 :         cmd->value = CPU_TO_LE32(reg_val);
    7441                 :            : 
    7442                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    7443                 :            : 
    7444                 :          0 :         return status;
    7445                 :            : }
    7446                 :            : 
    7447                 :            : /**
    7448                 :            :  * i40e_write_rx_ctl - write to an Rx control register
    7449                 :            :  * @hw: pointer to the hw struct
    7450                 :            :  * @reg_addr: register address
    7451                 :            :  * @reg_val: register value
    7452                 :            :  **/
    7453                 :          0 : void i40e_write_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
    7454                 :            : {
    7455                 :            :         enum i40e_status_code status = I40E_SUCCESS;
    7456                 :            :         bool use_register;
    7457                 :            :         int retry = 5;
    7458                 :            : 
    7459                 :          0 :         use_register = (((hw->aq.api_maj_ver == 1) &&
    7460   [ #  #  #  # ]:          0 :                         (hw->aq.api_min_ver < 5)) ||
    7461         [ #  # ]:          0 :                         (hw->mac.type == I40E_MAC_X722));
    7462         [ #  # ]:          0 :         if (!use_register) {
    7463                 :          0 : do_retry:
    7464                 :          0 :                 status = i40e_aq_rx_ctl_write_register(hw, reg_addr,
    7465                 :            :                                                        reg_val, NULL);
    7466   [ #  #  #  # ]:          0 :                 if (hw->aq.asq_last_status == I40E_AQ_RC_EAGAIN && retry) {
    7467                 :          0 :                         i40e_msec_delay(1);
    7468                 :          0 :                         retry--;
    7469                 :          0 :                         goto do_retry;
    7470                 :            :                 }
    7471                 :            :         }
    7472                 :            : 
    7473                 :            :         /* if the AQ access failed, try the old-fashioned way */
    7474         [ #  # ]:          0 :         if (status || use_register)
    7475                 :          0 :                 wr32(hw, reg_addr, reg_val);
    7476                 :          0 : }
    7477                 :            : 
    7478                 :            : /**
    7479                 :            :  * i40e_mdio_if_number_selection - MDIO I/F number selection
    7480                 :            :  * @hw: pointer to the hw struct
    7481                 :            :  * @set_mdio: use MDIO I/F number specified by mdio_num
    7482                 :            :  * @mdio_num: MDIO I/F number
    7483                 :            :  * @cmd: pointer to PHY Register command structure
    7484                 :            :  **/
    7485                 :            : static void
    7486                 :          0 : i40e_mdio_if_number_selection(struct i40e_hw *hw, bool set_mdio, u8 mdio_num,
    7487                 :            :                               struct i40e_aqc_phy_register_access *cmd)
    7488                 :            : {
    7489   [ #  #  #  # ]:          0 :         if (set_mdio && cmd->phy_interface == I40E_AQ_PHY_REG_ACCESS_EXTERNAL) {
    7490         [ #  # ]:          0 :                 if (hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_EXTENDED)
    7491                 :          0 :                         cmd->cmd_flags |=
    7492                 :            :                                 I40E_AQ_PHY_REG_ACCESS_SET_MDIO_IF_NUMBER |
    7493                 :          0 :                                 ((mdio_num <<
    7494                 :            :                                 I40E_AQ_PHY_REG_ACCESS_MDIO_IF_NUMBER_SHIFT) &
    7495                 :            :                                 I40E_AQ_PHY_REG_ACCESS_MDIO_IF_NUMBER_MASK);
    7496                 :            :                 else
    7497         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_PHY,
    7498                 :            :                                    "MDIO I/F number selection not supported by current FW version.\n");
    7499                 :            :         }
    7500                 :          0 : }
    7501                 :            : 
    7502                 :            : /**
    7503                 :            :  * i40e_aq_set_phy_register_ext
    7504                 :            :  * @hw: pointer to the hw struct
    7505                 :            :  * @phy_select: select which phy should be accessed
    7506                 :            :  * @dev_addr: PHY device address
    7507                 :            :  * @page_change: enable auto page change
    7508                 :            :  * @set_mdio: use MDIO I/F number specified by mdio_num
    7509                 :            :  * @mdio_num: MDIO I/F number
    7510                 :            :  * @reg_addr: PHY register address
    7511                 :            :  * @reg_val: new register value
    7512                 :            :  * @cmd_details: pointer to command details structure or NULL
    7513                 :            :  *
    7514                 :            :  * Write the external PHY register.
    7515                 :            :  * NOTE: In common cases MDIO I/F number should not be changed, thats why you
    7516                 :            :  * may use simple wrapper i40e_aq_set_phy_register.
    7517                 :            :  **/
    7518                 :            : enum i40e_status_code
    7519                 :          0 : i40e_aq_set_phy_register_ext(struct i40e_hw *hw,
    7520                 :            :                              u8 phy_select, u8 dev_addr, bool page_change,
    7521                 :            :                              bool set_mdio, u8 mdio_num,
    7522                 :            :                              u32 reg_addr, u32 reg_val,
    7523                 :            :                              struct i40e_asq_cmd_details *cmd_details)
    7524                 :            : {
    7525                 :            :         struct i40e_aq_desc desc;
    7526                 :            :         struct i40e_aqc_phy_register_access *cmd =
    7527                 :            :                 (struct i40e_aqc_phy_register_access *)&desc.params.raw;
    7528                 :            :         enum i40e_status_code status;
    7529                 :            : 
    7530                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    7531                 :            :                                           i40e_aqc_opc_set_phy_register);
    7532                 :            : 
    7533                 :          0 :         cmd->phy_interface = phy_select;
    7534                 :          0 :         cmd->dev_addres = dev_addr;
    7535                 :          0 :         cmd->reg_address = CPU_TO_LE32(reg_addr);
    7536                 :          0 :         cmd->reg_value = CPU_TO_LE32(reg_val);
    7537                 :            : 
    7538         [ #  # ]:          0 :         if (!page_change)
    7539                 :          0 :                 cmd->cmd_flags = I40E_AQ_PHY_REG_ACCESS_DONT_CHANGE_QSFP_PAGE;
    7540                 :            : 
    7541                 :          0 :         i40e_mdio_if_number_selection(hw, set_mdio, mdio_num, cmd);
    7542                 :            : 
    7543                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    7544                 :            : 
    7545                 :          0 :         return status;
    7546                 :            : }
    7547                 :            : 
    7548                 :            : /**
    7549                 :            :  * i40e_aq_get_phy_register_ext
    7550                 :            :  * @hw: pointer to the hw struct
    7551                 :            :  * @phy_select: select which phy should be accessed
    7552                 :            :  * @dev_addr: PHY device address
    7553                 :            :  * @page_change: enable auto page change
    7554                 :            :  * @set_mdio: use MDIO I/F number specified by mdio_num
    7555                 :            :  * @mdio_num: MDIO I/F number
    7556                 :            :  * @reg_addr: PHY register address
    7557                 :            :  * @reg_val: read register value
    7558                 :            :  * @cmd_details: pointer to command details structure or NULL
    7559                 :            :  *
    7560                 :            :  * Read the external PHY register.
    7561                 :            :  * NOTE: In common cases MDIO I/F number should not be changed, thats why you
    7562                 :            :  * may use simple wrapper i40e_aq_get_phy_register.
    7563                 :            :  **/
    7564                 :            : enum i40e_status_code
    7565                 :          0 : i40e_aq_get_phy_register_ext(struct i40e_hw *hw,
    7566                 :            :                              u8 phy_select, u8 dev_addr, bool page_change,
    7567                 :            :                              bool set_mdio, u8 mdio_num,
    7568                 :            :                              u32 reg_addr, u32 *reg_val,
    7569                 :            :                              struct i40e_asq_cmd_details *cmd_details)
    7570                 :            : {
    7571                 :            :         struct i40e_aq_desc desc;
    7572                 :            :         struct i40e_aqc_phy_register_access *cmd =
    7573                 :            :                 (struct i40e_aqc_phy_register_access *)&desc.params.raw;
    7574                 :            :         enum i40e_status_code status;
    7575                 :            : 
    7576                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    7577                 :            :                                           i40e_aqc_opc_get_phy_register);
    7578                 :            : 
    7579                 :          0 :         cmd->phy_interface = phy_select;
    7580                 :          0 :         cmd->dev_addres = dev_addr;
    7581                 :          0 :         cmd->reg_address = CPU_TO_LE32(reg_addr);
    7582                 :            : 
    7583         [ #  # ]:          0 :         if (!page_change)
    7584                 :          0 :                 cmd->cmd_flags = I40E_AQ_PHY_REG_ACCESS_DONT_CHANGE_QSFP_PAGE;
    7585                 :            : 
    7586                 :          0 :         i40e_mdio_if_number_selection(hw, set_mdio, mdio_num, cmd);
    7587                 :            : 
    7588                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    7589         [ #  # ]:          0 :         if (!status)
    7590                 :          0 :                 *reg_val = LE32_TO_CPU(cmd->reg_value);
    7591                 :            : 
    7592                 :          0 :         return status;
    7593                 :            : }
    7594                 :            : 
    7595                 :            : /**
    7596                 :            :  * i40e_aq_run_phy_activity
    7597                 :            :  * @hw: pointer to the hw struct
    7598                 :            :  * @activity_id: ID of DNL activity to run
    7599                 :            :  * @dnl_opcode: opcode passed to DNL script
    7600                 :            :  * @cmd_status: pointer to memory to write return value of DNL script
    7601                 :            :  * @data0: pointer to memory for first 4 bytes of data returned by DNL script
    7602                 :            :  * @data1: pointer to memory for last 4 bytes of data returned by DNL script
    7603                 :            :  * @cmd_details: pointer to command details structure or NULL
    7604                 :            :  *
    7605                 :            :  * Run DNL admin command.
    7606                 :            :  **/
    7607                 :            : enum i40e_status_code
    7608                 :          0 : i40e_aq_run_phy_activity(struct i40e_hw *hw, u16 activity_id, u32 dnl_opcode,
    7609                 :            :                          u32 *cmd_status, u32 *data0, u32 *data1,
    7610                 :            :                          struct i40e_asq_cmd_details *cmd_details)
    7611                 :            : {
    7612                 :            :         struct i40e_aqc_run_phy_activity *cmd;
    7613                 :            :         enum i40e_status_code retval;
    7614                 :            :         struct i40e_aq_desc desc;
    7615                 :            : 
    7616                 :            :         cmd = (struct i40e_aqc_run_phy_activity *)&desc.params.raw;
    7617                 :            : 
    7618   [ #  #  #  # ]:          0 :         if (!cmd_status || !data0 || !data1) {
    7619                 :            :                 retval = I40E_ERR_PARAM;
    7620                 :          0 :                 goto err;
    7621                 :            :         }
    7622                 :            : 
    7623                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    7624                 :            :                                           i40e_aqc_opc_run_phy_activity);
    7625                 :            : 
    7626                 :          0 :         cmd->activity_id = CPU_TO_LE16(activity_id);
    7627                 :          0 :         cmd->params.cmd.dnl_opcode = CPU_TO_LE32(dnl_opcode);
    7628                 :            : 
    7629                 :          0 :         retval = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    7630         [ #  # ]:          0 :         if (retval)
    7631                 :          0 :                 goto err;
    7632                 :            : 
    7633                 :          0 :         *cmd_status = LE32_TO_CPU(cmd->params.resp.cmd_status);
    7634                 :          0 :         *data0 = LE32_TO_CPU(cmd->params.resp.data0);
    7635                 :          0 :         *data1 = LE32_TO_CPU(cmd->params.resp.data1);
    7636                 :          0 : err:
    7637                 :          0 :         return retval;
    7638                 :            : }
    7639                 :            : 
    7640                 :            : /**
    7641                 :            :  * i40e_aq_set_arp_proxy_config
    7642                 :            :  * @hw: pointer to the HW structure
    7643                 :            :  * @proxy_config: pointer to proxy config command table struct
    7644                 :            :  * @cmd_details: pointer to command details
    7645                 :            :  *
    7646                 :            :  * Set ARP offload parameters from pre-populated
    7647                 :            :  * i40e_aqc_arp_proxy_data struct
    7648                 :            :  **/
    7649                 :          0 : enum i40e_status_code i40e_aq_set_arp_proxy_config(struct i40e_hw *hw,
    7650                 :            :                                 struct i40e_aqc_arp_proxy_data *proxy_config,
    7651                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    7652                 :            : {
    7653                 :            :         struct i40e_aq_desc desc;
    7654                 :            :         enum i40e_status_code status;
    7655                 :            : 
    7656         [ #  # ]:          0 :         if (!proxy_config)
    7657                 :            :                 return I40E_ERR_PARAM;
    7658                 :            : 
    7659                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_set_proxy_config);
    7660                 :            : 
    7661                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    7662                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
    7663                 :          0 :         desc.params.external.addr_high =
    7664                 :          0 :                                   CPU_TO_LE32(I40E_HI_DWORD((u64)proxy_config));
    7665                 :          0 :         desc.params.external.addr_low =
    7666                 :          0 :                                   CPU_TO_LE32(I40E_LO_DWORD((u64)proxy_config));
    7667                 :          0 :         desc.datalen = CPU_TO_LE16(sizeof(struct i40e_aqc_arp_proxy_data));
    7668                 :            : 
    7669                 :          0 :         status = i40e_asq_send_command(hw, &desc, proxy_config,
    7670                 :            :                                        sizeof(struct i40e_aqc_arp_proxy_data),
    7671                 :            :                                        cmd_details);
    7672                 :            : 
    7673                 :          0 :         return status;
    7674                 :            : }
    7675                 :            : 
    7676                 :            : /**
    7677                 :            :  * i40e_aq_set_ns_proxy_table_entry
    7678                 :            :  * @hw: pointer to the HW structure
    7679                 :            :  * @ns_proxy_table_entry: pointer to NS table entry command struct
    7680                 :            :  * @cmd_details: pointer to command details
    7681                 :            :  *
    7682                 :            :  * Set IPv6 Neighbor Solicitation (NS) protocol offload parameters
    7683                 :            :  * from pre-populated i40e_aqc_ns_proxy_data struct
    7684                 :            :  **/
    7685                 :          0 : enum i40e_status_code i40e_aq_set_ns_proxy_table_entry(struct i40e_hw *hw,
    7686                 :            :                         struct i40e_aqc_ns_proxy_data *ns_proxy_table_entry,
    7687                 :            :                         struct i40e_asq_cmd_details *cmd_details)
    7688                 :            : {
    7689                 :            :         struct i40e_aq_desc desc;
    7690                 :            :         enum i40e_status_code status;
    7691                 :            : 
    7692         [ #  # ]:          0 :         if (!ns_proxy_table_entry)
    7693                 :            :                 return I40E_ERR_PARAM;
    7694                 :            : 
    7695                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    7696                 :            :                                 i40e_aqc_opc_set_ns_proxy_table_entry);
    7697                 :            : 
    7698                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    7699                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
    7700                 :          0 :         desc.params.external.addr_high =
    7701                 :          0 :                 CPU_TO_LE32(I40E_HI_DWORD((u64)ns_proxy_table_entry));
    7702                 :          0 :         desc.params.external.addr_low =
    7703                 :          0 :                 CPU_TO_LE32(I40E_LO_DWORD((u64)ns_proxy_table_entry));
    7704                 :          0 :         desc.datalen = CPU_TO_LE16(sizeof(struct i40e_aqc_ns_proxy_data));
    7705                 :            : 
    7706                 :          0 :         status = i40e_asq_send_command(hw, &desc, ns_proxy_table_entry,
    7707                 :            :                                        sizeof(struct i40e_aqc_ns_proxy_data),
    7708                 :            :                                        cmd_details);
    7709                 :            : 
    7710                 :          0 :         return status;
    7711                 :            : }
    7712                 :            : 
    7713                 :            : /**
    7714                 :            :  * i40e_aq_set_clear_wol_filter
    7715                 :            :  * @hw: pointer to the hw struct
    7716                 :            :  * @filter_index: index of filter to modify (0-7)
    7717                 :            :  * @filter: buffer containing filter to be set
    7718                 :            :  * @set_filter: true to set filter, false to clear filter
    7719                 :            :  * @no_wol_tco: if true, pass through packets cannot cause wake-up
    7720                 :            :  *              if false, pass through packets may cause wake-up
    7721                 :            :  * @filter_valid: true if filter action is valid
    7722                 :            :  * @no_wol_tco_valid: true if no WoL in TCO traffic action valid
    7723                 :            :  * @cmd_details: pointer to command details structure or NULL
    7724                 :            :  *
    7725                 :            :  * Set or clear WoL filter for port attached to the PF
    7726                 :            :  **/
    7727                 :          0 : enum i40e_status_code i40e_aq_set_clear_wol_filter(struct i40e_hw *hw,
    7728                 :            :                                 u8 filter_index,
    7729                 :            :                                 struct i40e_aqc_set_wol_filter_data *filter,
    7730                 :            :                                 bool set_filter, bool no_wol_tco,
    7731                 :            :                                 bool filter_valid, bool no_wol_tco_valid,
    7732                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    7733                 :            : {
    7734                 :            :         struct i40e_aq_desc desc;
    7735                 :            :         struct i40e_aqc_set_wol_filter *cmd =
    7736                 :            :                 (struct i40e_aqc_set_wol_filter *)&desc.params.raw;
    7737                 :            :         enum i40e_status_code status;
    7738                 :            :         u16 cmd_flags = 0;
    7739                 :            :         u16 valid_flags = 0;
    7740                 :            :         u16 buff_len = 0;
    7741                 :            : 
    7742                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_set_wol_filter);
    7743                 :            : 
    7744         [ #  # ]:          0 :         if (filter_index >= I40E_AQC_MAX_NUM_WOL_FILTERS)
    7745                 :            :                 return  I40E_ERR_PARAM;
    7746                 :          0 :         cmd->filter_index = CPU_TO_LE16(filter_index);
    7747                 :            : 
    7748         [ #  # ]:          0 :         if (set_filter) {
    7749         [ #  # ]:          0 :                 if (!filter)
    7750                 :            :                         return  I40E_ERR_PARAM;
    7751                 :            : 
    7752                 :            :                 cmd_flags |= I40E_AQC_SET_WOL_FILTER;
    7753                 :            :                 cmd_flags |= I40E_AQC_SET_WOL_FILTER_WOL_PRESERVE_ON_PFR;
    7754                 :            :         }
    7755                 :            : 
    7756         [ #  # ]:          0 :         if (no_wol_tco)
    7757                 :          0 :                 cmd_flags |= I40E_AQC_SET_WOL_FILTER_NO_TCO_WOL;
    7758                 :          0 :         cmd->cmd_flags = CPU_TO_LE16(cmd_flags);
    7759                 :            : 
    7760         [ #  # ]:          0 :         if (filter_valid)
    7761                 :            :                 valid_flags |= I40E_AQC_SET_WOL_FILTER_ACTION_VALID;
    7762         [ #  # ]:          0 :         if (no_wol_tco_valid)
    7763                 :          0 :                 valid_flags |= I40E_AQC_SET_WOL_FILTER_NO_TCO_ACTION_VALID;
    7764                 :          0 :         cmd->valid_flags = CPU_TO_LE16(valid_flags);
    7765                 :            : 
    7766                 :            :         buff_len = sizeof(*filter);
    7767                 :          0 :         desc.datalen = CPU_TO_LE16(buff_len);
    7768                 :            : 
    7769                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    7770                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
    7771                 :            : 
    7772                 :          0 :         cmd->address_high = CPU_TO_LE32(I40E_HI_DWORD((u64)filter));
    7773                 :          0 :         cmd->address_low = CPU_TO_LE32(I40E_LO_DWORD((u64)filter));
    7774                 :            : 
    7775                 :          0 :         status = i40e_asq_send_command(hw, &desc, filter,
    7776                 :            :                                        buff_len, cmd_details);
    7777                 :            : 
    7778                 :          0 :         return status;
    7779                 :            : }
    7780                 :            : 
    7781                 :            : /**
    7782                 :            :  * i40e_aq_get_wake_event_reason
    7783                 :            :  * @hw: pointer to the hw struct
    7784                 :            :  * @wake_reason: return value, index of matching filter
    7785                 :            :  * @cmd_details: pointer to command details structure or NULL
    7786                 :            :  *
    7787                 :            :  * Get information for the reason of a Wake Up event
    7788                 :            :  **/
    7789                 :          0 : enum i40e_status_code i40e_aq_get_wake_event_reason(struct i40e_hw *hw,
    7790                 :            :                                 u16 *wake_reason,
    7791                 :            :                                 struct i40e_asq_cmd_details *cmd_details)
    7792                 :            : {
    7793                 :            :         struct i40e_aq_desc desc;
    7794                 :            :         struct i40e_aqc_get_wake_reason_completion *resp =
    7795                 :            :                 (struct i40e_aqc_get_wake_reason_completion *)&desc.params.raw;
    7796                 :            :         enum i40e_status_code status;
    7797                 :            : 
    7798                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_wake_reason);
    7799                 :            : 
    7800                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    7801                 :            : 
    7802         [ #  # ]:          0 :         if (status == I40E_SUCCESS)
    7803                 :          0 :                 *wake_reason = LE16_TO_CPU(resp->wake_reason);
    7804                 :            : 
    7805                 :          0 :         return status;
    7806                 :            : }
    7807                 :            : 
    7808                 :            : /**
    7809                 :            : * i40e_aq_clear_all_wol_filters
    7810                 :            : * @hw: pointer to the hw struct
    7811                 :            : * @cmd_details: pointer to command details structure or NULL
    7812                 :            : *
    7813                 :            : * Get information for the reason of a Wake Up event
    7814                 :            : **/
    7815                 :          0 : enum i40e_status_code i40e_aq_clear_all_wol_filters(struct i40e_hw *hw,
    7816                 :            :         struct i40e_asq_cmd_details *cmd_details)
    7817                 :            : {
    7818                 :            :         struct i40e_aq_desc desc;
    7819                 :            :         enum i40e_status_code status;
    7820                 :            : 
    7821                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    7822                 :            :                                           i40e_aqc_opc_clear_all_wol_filters);
    7823                 :            : 
    7824                 :          0 :         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
    7825                 :            : 
    7826                 :          0 :         return status;
    7827                 :            : }
    7828                 :            : 
    7829                 :            : /**
    7830                 :            :  * i40e_aq_write_ddp - Write dynamic device personalization (ddp)
    7831                 :            :  * @hw: pointer to the hw struct
    7832                 :            :  * @buff: command buffer (size in bytes = buff_size)
    7833                 :            :  * @buff_size: buffer size in bytes
    7834                 :            :  * @track_id: package tracking id
    7835                 :            :  * @error_offset: returns error offset
    7836                 :            :  * @error_info: returns error information
    7837                 :            :  * @cmd_details: pointer to command details structure or NULL
    7838                 :            :  **/
    7839                 :            : enum
    7840                 :          0 : i40e_status_code i40e_aq_write_ddp(struct i40e_hw *hw, void *buff,
    7841                 :            :                                    u16 buff_size, u32 track_id,
    7842                 :            :                                    u32 *error_offset, u32 *error_info,
    7843                 :            :                                    struct i40e_asq_cmd_details *cmd_details)
    7844                 :            : {
    7845                 :            :         struct i40e_aq_desc desc;
    7846                 :            :         struct i40e_aqc_write_personalization_profile *cmd =
    7847                 :            :                 (struct i40e_aqc_write_personalization_profile *)
    7848                 :            :                 &desc.params.raw;
    7849                 :            :         struct i40e_aqc_write_ddp_resp *resp;
    7850                 :            :         enum i40e_status_code status;
    7851                 :            : 
    7852                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    7853                 :            :                                   i40e_aqc_opc_write_personalization_profile);
    7854                 :            : 
    7855                 :          0 :         desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
    7856         [ #  # ]:          0 :         if (buff_size > I40E_AQ_LARGE_BUF)
    7857                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    7858                 :            : 
    7859                 :          0 :         desc.datalen = CPU_TO_LE16(buff_size);
    7860                 :            : 
    7861                 :          0 :         cmd->profile_track_id = CPU_TO_LE32(track_id);
    7862                 :            : 
    7863                 :          0 :         status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
    7864         [ #  # ]:          0 :         if (!status) {
    7865                 :            :                 resp = (struct i40e_aqc_write_ddp_resp *)&desc.params.raw;
    7866         [ #  # ]:          0 :                 if (error_offset)
    7867                 :          0 :                         *error_offset = LE32_TO_CPU(resp->error_offset);
    7868         [ #  # ]:          0 :                 if (error_info)
    7869                 :          0 :                         *error_info = LE32_TO_CPU(resp->error_info);
    7870                 :            :         }
    7871                 :            : 
    7872                 :          0 :         return status;
    7873                 :            : }
    7874                 :            : 
    7875                 :            : /**
    7876                 :            :  * i40e_aq_get_ddp_list - Read dynamic device personalization (ddp)
    7877                 :            :  * @hw: pointer to the hw struct
    7878                 :            :  * @buff: command buffer (size in bytes = buff_size)
    7879                 :            :  * @buff_size: buffer size in bytes
    7880                 :            :  * @flags: AdminQ command flags
    7881                 :            :  * @cmd_details: pointer to command details structure or NULL
    7882                 :            :  **/
    7883                 :            : enum
    7884                 :          0 : i40e_status_code i40e_aq_get_ddp_list(struct i40e_hw *hw, void *buff,
    7885                 :            :                                       u16 buff_size, u8 flags,
    7886                 :            :                                       struct i40e_asq_cmd_details *cmd_details)
    7887                 :            : {
    7888                 :            :         struct i40e_aq_desc desc;
    7889                 :            :         struct i40e_aqc_get_applied_profiles *cmd =
    7890                 :            :                 (struct i40e_aqc_get_applied_profiles *)&desc.params.raw;
    7891                 :            :         enum i40e_status_code status;
    7892                 :            : 
    7893                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc,
    7894                 :            :                           i40e_aqc_opc_get_personalization_profile_list);
    7895                 :            : 
    7896                 :          0 :         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
    7897         [ #  # ]:          0 :         if (buff_size > I40E_AQ_LARGE_BUF)
    7898                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    7899                 :          0 :         desc.datalen = CPU_TO_LE16(buff_size);
    7900                 :            : 
    7901                 :          0 :         cmd->flags = flags;
    7902                 :            : 
    7903                 :          0 :         status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
    7904                 :            : 
    7905                 :          0 :         return status;
    7906                 :            : }
    7907                 :            : 
    7908                 :            : /**
    7909                 :            :  * i40e_find_segment_in_package
    7910                 :            :  * @segment_type: the segment type to search for (i.e., SEGMENT_TYPE_I40E)
    7911                 :            :  * @pkg_hdr: pointer to the package header to be searched
    7912                 :            :  *
    7913                 :            :  * This function searches a package file for a particular segment type. On
    7914                 :            :  * success it returns a pointer to the segment header, otherwise it will
    7915                 :            :  * return NULL.
    7916                 :            :  **/
    7917                 :            : struct i40e_generic_seg_header *
    7918                 :          0 : i40e_find_segment_in_package(u32 segment_type,
    7919                 :            :                              struct i40e_package_header *pkg_hdr)
    7920                 :            : {
    7921                 :            :         struct i40e_generic_seg_header *segment;
    7922                 :            :         u32 i;
    7923                 :            : 
    7924                 :            :         /* Search all package segments for the requested segment type */
    7925         [ #  # ]:          0 :         for (i = 0; i < pkg_hdr->segment_count; i++) {
    7926                 :          0 :                 segment =
    7927                 :            :                         (struct i40e_generic_seg_header *)((u8 *)pkg_hdr +
    7928                 :          0 :                          pkg_hdr->segment_offset[i]);
    7929                 :            : 
    7930         [ #  # ]:          0 :                 if (segment->type == segment_type)
    7931                 :          0 :                         return segment;
    7932                 :            :         }
    7933                 :            : 
    7934                 :            :         return NULL;
    7935                 :            : }
    7936                 :            : 
    7937                 :            : /* Get section table in profile */
    7938                 :            : #define I40E_SECTION_TABLE(profile, sec_tbl)                            \
    7939                 :            :         do {                                                            \
    7940                 :            :                 struct i40e_profile_segment *p = (profile);             \
    7941                 :            :                 u32 count;                                              \
    7942                 :            :                 u32 *nvm;                                               \
    7943                 :            :                 count = p->device_table_count;                               \
    7944                 :            :                 nvm = (u32 *)&p->device_table[count];                    \
    7945                 :            :                 sec_tbl = (struct i40e_section_table *)&nvm[nvm[0] + 1]; \
    7946                 :            :         } while (0)
    7947                 :            : 
    7948                 :            : /* Get section header in profile */
    7949                 :            : #define I40E_SECTION_HEADER(profile, offset)                            \
    7950                 :            :         (struct i40e_profile_section_header *)((u8 *)(profile) + (offset))
    7951                 :            : 
    7952                 :            : /**
    7953                 :            :  * i40e_find_section_in_profile
    7954                 :            :  * @section_type: the section type to search for (i.e., SECTION_TYPE_NOTE)
    7955                 :            :  * @profile: pointer to the i40e segment header to be searched
    7956                 :            :  *
    7957                 :            :  * This function searches i40e segment for a particular section type. On
    7958                 :            :  * success it returns a pointer to the section header, otherwise it will
    7959                 :            :  * return NULL.
    7960                 :            :  **/
    7961                 :            : struct i40e_profile_section_header *
    7962                 :          0 : i40e_find_section_in_profile(u32 section_type,
    7963                 :            :                              struct i40e_profile_segment *profile)
    7964                 :            : {
    7965                 :            :         struct i40e_profile_section_header *sec;
    7966                 :            :         struct i40e_section_table *sec_tbl;
    7967                 :            :         u32 sec_off;
    7968                 :            :         u32 i;
    7969                 :            : 
    7970         [ #  # ]:          0 :         if (profile->header.type != SEGMENT_TYPE_I40E)
    7971                 :            :                 return NULL;
    7972                 :            : 
    7973                 :          0 :         I40E_SECTION_TABLE(profile, sec_tbl);
    7974                 :            : 
    7975         [ #  # ]:          0 :         for (i = 0; i < sec_tbl->section_count; i++) {
    7976                 :          0 :                 sec_off = sec_tbl->section_offset[i];
    7977                 :          0 :                 sec = I40E_SECTION_HEADER(profile, sec_off);
    7978         [ #  # ]:          0 :                 if (sec->section.type == section_type)
    7979                 :          0 :                         return sec;
    7980                 :            :         }
    7981                 :            : 
    7982                 :            :         return NULL;
    7983                 :            : }
    7984                 :            : 
    7985                 :            : /**
    7986                 :            :  * i40e_ddp_exec_aq_section - Execute generic AQ for DDP
    7987                 :            :  * @hw: pointer to the hw struct
    7988                 :            :  * @aq: command buffer containing all data to execute AQ
    7989                 :            :  **/
    7990                 :            : STATIC enum
    7991                 :          0 : i40e_status_code i40e_ddp_exec_aq_section(struct i40e_hw *hw,
    7992                 :            :                                           struct i40e_profile_aq_section *aq)
    7993                 :            : {
    7994                 :            :         enum i40e_status_code status;
    7995                 :            :         struct i40e_aq_desc desc;
    7996                 :            :         u8 *msg = NULL;
    7997                 :            :         u16 msglen;
    7998                 :            : 
    7999                 :          0 :         i40e_fill_default_direct_cmd_desc(&desc, aq->opcode);
    8000                 :          0 :         desc.flags |= CPU_TO_LE16(aq->flags);
    8001         [ #  # ]:          0 :         i40e_memcpy(desc.params.raw, aq->param, sizeof(desc.params.raw),
    8002                 :            :                     I40E_NONDMA_TO_NONDMA);
    8003                 :            : 
    8004                 :          0 :         msglen = aq->datalen;
    8005         [ #  # ]:          0 :         if (msglen) {
    8006                 :          0 :                 desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF |
    8007                 :            :                                                 I40E_AQ_FLAG_RD));
    8008         [ #  # ]:          0 :                 if (msglen > I40E_AQ_LARGE_BUF)
    8009                 :          0 :                         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
    8010                 :          0 :                 desc.datalen = CPU_TO_LE16(msglen);
    8011                 :          0 :                 msg = &aq->data[0];
    8012                 :            :         }
    8013                 :            : 
    8014                 :          0 :         status = i40e_asq_send_command(hw, &desc, msg, msglen, NULL);
    8015                 :            : 
    8016         [ #  # ]:          0 :         if (status != I40E_SUCCESS) {
    8017         [ #  # ]:          0 :                 i40e_debug(hw, I40E_DEBUG_PACKAGE,
    8018                 :            :                            "unable to exec DDP AQ opcode %u, error %d\n",
    8019                 :            :                            aq->opcode, status);
    8020                 :          0 :                 return status;
    8021                 :            :         }
    8022                 :            : 
    8023                 :            :         /* copy returned desc to aq_buf */
    8024                 :            :         i40e_memcpy(aq->param, desc.params.raw, sizeof(desc.params.raw),
    8025                 :            :                     I40E_NONDMA_TO_NONDMA);
    8026                 :            : 
    8027                 :            :         return I40E_SUCCESS;
    8028                 :            : }
    8029                 :            : 
    8030                 :            : /**
    8031                 :            :  * i40e_validate_profile
    8032                 :            :  * @hw: pointer to the hardware structure
    8033                 :            :  * @profile: pointer to the profile segment of the package to be validated
    8034                 :            :  * @track_id: package tracking id
    8035                 :            :  * @rollback: flag if the profile is for rollback.
    8036                 :            :  *
    8037                 :            :  * Validates supported devices and profile's sections.
    8038                 :            :  */
    8039                 :            : STATIC enum i40e_status_code
    8040                 :          0 : i40e_validate_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
    8041                 :            :                       u32 track_id, bool rollback)
    8042                 :            : {
    8043                 :            :         struct i40e_profile_section_header *sec = NULL;
    8044                 :            :         enum i40e_status_code status = I40E_SUCCESS;
    8045                 :            :         struct i40e_section_table *sec_tbl;
    8046                 :            :         u32 vendor_dev_id;
    8047                 :            :         u32 dev_cnt;
    8048                 :            :         u32 sec_off;
    8049                 :            :         u32 i;
    8050                 :            : 
    8051         [ #  # ]:          0 :         if (track_id == I40E_DDP_TRACKID_INVALID ||
    8052                 :            :             track_id == I40E_DDP_TRACKID_RDONLY) {
    8053         [ #  # ]:          0 :                 i40e_debug(hw, I40E_DEBUG_PACKAGE, "Invalid track_id\n");
    8054                 :          0 :                 return I40E_NOT_SUPPORTED;
    8055                 :            :         }
    8056                 :            : 
    8057                 :          0 :         dev_cnt = profile->device_table_count;
    8058         [ #  # ]:          0 :         for (i = 0; i < dev_cnt; i++) {
    8059                 :          0 :                 vendor_dev_id = profile->device_table[i].vendor_dev_id;
    8060         [ #  # ]:          0 :                 if ((vendor_dev_id >> 16) == I40E_INTEL_VENDOR_ID &&
    8061         [ #  # ]:          0 :                     hw->device_id == (vendor_dev_id & 0xFFFF))
    8062                 :            :                         break;
    8063                 :            :         }
    8064         [ #  # ]:          0 :         if (dev_cnt && (i == dev_cnt)) {
    8065         [ #  # ]:          0 :                 i40e_debug(hw, I40E_DEBUG_PACKAGE,
    8066                 :            :                            "Device doesn't support DDP\n");
    8067                 :          0 :                 return I40E_ERR_DEVICE_NOT_SUPPORTED;
    8068                 :            :         }
    8069                 :            : 
    8070                 :          0 :         I40E_SECTION_TABLE(profile, sec_tbl);
    8071                 :            : 
    8072                 :            :         /* Validate sections types */
    8073         [ #  # ]:          0 :         for (i = 0; i < sec_tbl->section_count; i++) {
    8074                 :          0 :                 sec_off = sec_tbl->section_offset[i];
    8075                 :          0 :                 sec = I40E_SECTION_HEADER(profile, sec_off);
    8076         [ #  # ]:          0 :                 if (rollback) {
    8077                 :          0 :                         if (sec->section.type == SECTION_TYPE_MMIO ||
    8078         [ #  # ]:          0 :                             sec->section.type == SECTION_TYPE_AQ ||
    8079                 :            :                             sec->section.type == SECTION_TYPE_RB_AQ) {
    8080         [ #  # ]:          0 :                                 i40e_debug(hw, I40E_DEBUG_PACKAGE,
    8081                 :            :                                            "Not a roll-back package\n");
    8082                 :          0 :                                 return I40E_NOT_SUPPORTED;
    8083                 :            :                         }
    8084                 :            :                 } else {
    8085         [ #  # ]:          0 :                         if (sec->section.type == SECTION_TYPE_RB_AQ ||
    8086                 :            :                             sec->section.type == SECTION_TYPE_RB_MMIO) {
    8087         [ #  # ]:          0 :                                 i40e_debug(hw, I40E_DEBUG_PACKAGE,
    8088                 :            :                                            "Not an original package\n");
    8089                 :          0 :                                 return I40E_NOT_SUPPORTED;
    8090                 :            :                         }
    8091                 :            :                 }
    8092                 :            :         }
    8093                 :            : 
    8094                 :            :         return status;
    8095                 :            : }
    8096                 :            : 
    8097                 :            : /**
    8098                 :            :  * i40e_write_profile
    8099                 :            :  * @hw: pointer to the hardware structure
    8100                 :            :  * @profile: pointer to the profile segment of the package to be downloaded
    8101                 :            :  * @track_id: package tracking id
    8102                 :            :  *
    8103                 :            :  * Handles the download of a complete package.
    8104                 :            :  */
    8105                 :            : enum i40e_status_code
    8106                 :          0 : i40e_write_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
    8107                 :            :                    u32 track_id)
    8108                 :            : {
    8109                 :            :         enum i40e_status_code status = I40E_SUCCESS;
    8110                 :            :         struct i40e_section_table *sec_tbl;
    8111                 :            :         struct i40e_profile_section_header *sec = NULL;
    8112                 :            :         struct i40e_profile_aq_section *ddp_aq;
    8113                 :            :         u32 section_size = 0;
    8114                 :          0 :         u32 offset = 0, info = 0;
    8115                 :            :         u32 sec_off;
    8116                 :            :         u32 i;
    8117                 :            : 
    8118                 :          0 :         status = i40e_validate_profile(hw, profile, track_id, false);
    8119         [ #  # ]:          0 :         if (status)
    8120                 :            :                 return status;
    8121                 :            : 
    8122                 :          0 :         I40E_SECTION_TABLE(profile, sec_tbl);
    8123                 :            : 
    8124         [ #  # ]:          0 :         for (i = 0; i < sec_tbl->section_count; i++) {
    8125                 :          0 :                 sec_off = sec_tbl->section_offset[i];
    8126                 :          0 :                 sec = I40E_SECTION_HEADER(profile, sec_off);
    8127                 :            :                 /* Process generic admin command */
    8128         [ #  # ]:          0 :                 if (sec->section.type == SECTION_TYPE_AQ) {
    8129                 :          0 :                         ddp_aq = (struct i40e_profile_aq_section *)&sec[1];
    8130                 :          0 :                         status = i40e_ddp_exec_aq_section(hw, ddp_aq);
    8131         [ #  # ]:          0 :                         if (status) {
    8132         [ #  # ]:          0 :                                 i40e_debug(hw, I40E_DEBUG_PACKAGE,
    8133                 :            :                                            "Failed to execute aq: section %d, opcode %u\n",
    8134                 :            :                                            i, ddp_aq->opcode);
    8135                 :            :                                 break;
    8136                 :            :                         }
    8137                 :          0 :                         sec->section.type = SECTION_TYPE_RB_AQ;
    8138                 :            :                 }
    8139                 :            : 
    8140                 :            :                 /* Skip any non-mmio sections */
    8141         [ #  # ]:          0 :                 if (sec->section.type != SECTION_TYPE_MMIO)
    8142                 :          0 :                         continue;
    8143                 :            : 
    8144                 :          0 :                 section_size = sec->section.size +
    8145                 :            :                         sizeof(struct i40e_profile_section_header);
    8146                 :            : 
    8147                 :            :                 /* Write MMIO section */
    8148                 :          0 :                 status = i40e_aq_write_ddp(hw, (void *)sec, (u16)section_size,
    8149                 :            :                                            track_id, &offset, &info, NULL);
    8150         [ #  # ]:          0 :                 if (status) {
    8151         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_PACKAGE,
    8152                 :            :                                    "Failed to write profile: section %d, offset %d, info %d\n",
    8153                 :            :                                    i, offset, info);
    8154                 :            :                         break;
    8155                 :            :                 }
    8156                 :            :         }
    8157                 :            :         return status;
    8158                 :            : }
    8159                 :            : 
    8160                 :            : /**
    8161                 :            :  * i40e_rollback_profile
    8162                 :            :  * @hw: pointer to the hardware structure
    8163                 :            :  * @profile: pointer to the profile segment of the package to be removed
    8164                 :            :  * @track_id: package tracking id
    8165                 :            :  *
    8166                 :            :  * Rolls back previously loaded package.
    8167                 :            :  */
    8168                 :            : enum i40e_status_code
    8169                 :          0 : i40e_rollback_profile(struct i40e_hw *hw, struct i40e_profile_segment *profile,
    8170                 :            :                       u32 track_id)
    8171                 :            : {
    8172                 :            :         struct i40e_profile_section_header *sec = NULL;
    8173                 :            :         enum i40e_status_code status = I40E_SUCCESS;
    8174                 :            :         struct i40e_section_table *sec_tbl;
    8175                 :          0 :         u32 offset = 0, info = 0;
    8176                 :            :         u32 section_size = 0;
    8177                 :            :         u32 sec_off;
    8178                 :            :         int i;
    8179                 :            : 
    8180                 :          0 :         status = i40e_validate_profile(hw, profile, track_id, true);
    8181         [ #  # ]:          0 :         if (status)
    8182                 :            :                 return status;
    8183                 :            : 
    8184                 :          0 :         I40E_SECTION_TABLE(profile, sec_tbl);
    8185                 :            : 
    8186                 :            :         /* For rollback write sections in reverse */
    8187         [ #  # ]:          0 :         for (i = sec_tbl->section_count - 1; i >= 0; i--) {
    8188                 :          0 :                 sec_off = sec_tbl->section_offset[i];
    8189                 :          0 :                 sec = I40E_SECTION_HEADER(profile, sec_off);
    8190                 :            : 
    8191                 :            :                 /* Skip any non-rollback sections */
    8192         [ #  # ]:          0 :                 if (sec->section.type != SECTION_TYPE_RB_MMIO)
    8193                 :          0 :                         continue;
    8194                 :            : 
    8195                 :          0 :                 section_size = sec->section.size +
    8196                 :            :                         sizeof(struct i40e_profile_section_header);
    8197                 :            : 
    8198                 :            :                 /* Write roll-back MMIO section */
    8199                 :          0 :                 status = i40e_aq_write_ddp(hw, (void *)sec, (u16)section_size,
    8200                 :            :                                            track_id, &offset, &info, NULL);
    8201         [ #  # ]:          0 :                 if (status) {
    8202         [ #  # ]:          0 :                         i40e_debug(hw, I40E_DEBUG_PACKAGE,
    8203                 :            :                                    "Failed to write profile: section %d, offset %d, info %d\n",
    8204                 :            :                                    i, offset, info);
    8205                 :            :                         break;
    8206                 :            :                 }
    8207                 :            :         }
    8208                 :            :         return status;
    8209                 :            : }
    8210                 :            : 
    8211                 :            : /**
    8212                 :            :  * i40e_add_pinfo_to_list
    8213                 :            :  * @hw: pointer to the hardware structure
    8214                 :            :  * @profile: pointer to the profile segment of the package
    8215                 :            :  * @profile_info_sec: buffer for information section
    8216                 :            :  * @track_id: package tracking id
    8217                 :            :  *
    8218                 :            :  * Register a profile to the list of loaded profiles.
    8219                 :            :  */
    8220                 :            : enum i40e_status_code
    8221                 :          0 : i40e_add_pinfo_to_list(struct i40e_hw *hw,
    8222                 :            :                        struct i40e_profile_segment *profile,
    8223                 :            :                        u8 *profile_info_sec, u32 track_id)
    8224                 :            : {
    8225                 :            :         enum i40e_status_code status = I40E_SUCCESS;
    8226                 :            :         struct i40e_profile_section_header *sec = NULL;
    8227                 :            :         struct i40e_profile_info *pinfo;
    8228                 :          0 :         u32 offset = 0, info = 0;
    8229                 :            : 
    8230                 :            :         sec = (struct i40e_profile_section_header *)profile_info_sec;
    8231                 :          0 :         sec->tbl_size = 1;
    8232                 :          0 :         sec->data_end = sizeof(struct i40e_profile_section_header) +
    8233                 :            :                         sizeof(struct i40e_profile_info);
    8234                 :          0 :         sec->section.type = SECTION_TYPE_INFO;
    8235                 :          0 :         sec->section.offset = sizeof(struct i40e_profile_section_header);
    8236                 :          0 :         sec->section.size = sizeof(struct i40e_profile_info);
    8237                 :          0 :         pinfo = (struct i40e_profile_info *)(profile_info_sec +
    8238                 :            :                                              sec->section.offset);
    8239                 :          0 :         pinfo->track_id = track_id;
    8240                 :          0 :         pinfo->version = profile->version;
    8241                 :          0 :         pinfo->op = I40E_DDP_ADD_TRACKID;
    8242         [ #  # ]:          0 :         i40e_memcpy(pinfo->name, profile->name, I40E_DDP_NAME_SIZE,
    8243                 :            :                     I40E_NONDMA_TO_NONDMA);
    8244                 :            : 
    8245                 :          0 :         status = i40e_aq_write_ddp(hw, (void *)sec, sec->data_end,
    8246                 :            :                                    track_id, &offset, &info, NULL);
    8247                 :          0 :         return status;
    8248                 :            : }

Generated by: LCOV version 1.14