LCOV - code coverage report
Current view: top level - drivers/net/txgbe/base - txgbe_hw.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 1261 0.0 %
Date: 2025-11-01 17:50:34 Functions: 0 88 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 727 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
       3                 :            :  * Copyright(c) 2010-2017 Intel Corporation
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "txgbe_type.h"
       7                 :            : #include "txgbe_mbx.h"
       8                 :            : #include "txgbe_phy.h"
       9                 :            : #include "txgbe_dcb.h"
      10                 :            : #include "txgbe_vf.h"
      11                 :            : #include "txgbe_eeprom.h"
      12                 :            : #include "txgbe_mng.h"
      13                 :            : #include "txgbe_hw.h"
      14                 :            : #include "txgbe_aml.h"
      15                 :            : #include "txgbe_aml40.h"
      16                 :            : 
      17                 :            : #define TXGBE_RAPTOR_MAX_TX_QUEUES 128
      18                 :            : #define TXGBE_RAPTOR_MAX_RX_QUEUES 128
      19                 :            : #define TXGBE_RAPTOR_RAR_ENTRIES   128
      20                 :            : #define TXGBE_RAPTOR_MC_TBL_SIZE   128
      21                 :            : #define TXGBE_RAPTOR_VFT_TBL_SIZE  128
      22                 :            : #define TXGBE_RAPTOR_RX_PB_SIZE   512 /*KB*/
      23                 :            : #define TXGBE_AML_RX_PB_SIZE      768
      24                 :            : 
      25                 :            : static s32 txgbe_setup_copper_link_raptor(struct txgbe_hw *hw,
      26                 :            :                                          u32 speed,
      27                 :            :                                          bool autoneg_wait_to_complete);
      28                 :            : 
      29                 :            : static s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr);
      30                 :            : static s32 txgbe_get_san_mac_addr_offset(struct txgbe_hw *hw,
      31                 :            :                                          u16 *san_mac_offset);
      32                 :            : 
      33                 :          0 : static s32 txgbe_is_lldp(struct txgbe_hw *hw)
      34                 :            : {
      35                 :          0 :         u32 tmp = 0, lldp_flash_data = 0, i;
      36                 :            :         s32 err = 0;
      37                 :            : 
      38         [ #  # ]:          0 :         if ((hw->fw_version & TXGBE_FW_MASK) >= TXGBE_FW_GET_LLDP) {
      39                 :          0 :                 err = txgbe_hic_get_lldp(hw);
      40         [ #  # ]:          0 :                 if (err == 0)
      41                 :            :                         return 0;
      42                 :            :         }
      43                 :            : 
      44         [ #  # ]:          0 :         for (i = 0; i < 1024; i++) {
      45                 :          0 :                 err = txgbe_flash_read_dword(hw, TXGBE_LLDP_REG + i * 4, &tmp);
      46         [ #  # ]:          0 :                 if (err)
      47                 :          0 :                         return err;
      48                 :            : 
      49         [ #  # ]:          0 :                 if (tmp == BIT_MASK32)
      50                 :            :                         break;
      51                 :            :                 lldp_flash_data = tmp;
      52                 :            :         }
      53                 :            : 
      54         [ #  # ]:          0 :         if (lldp_flash_data & MS(hw->bus.lan_id, 1))
      55                 :          0 :                 hw->lldp_enabled = true;
      56                 :            :         else
      57                 :          0 :                 hw->lldp_enabled = false;
      58                 :            : 
      59                 :            :         return 0;
      60                 :            : }
      61                 :            : 
      62                 :          0 : static void txgbe_disable_lldp(struct txgbe_hw *hw)
      63                 :            : {
      64                 :            :         s32 status = 0;
      65                 :            : 
      66         [ #  # ]:          0 :         if ((hw->fw_version & TXGBE_FW_MASK) < TXGBE_FW_SUPPORT_LLDP)
      67                 :            :                 return;
      68                 :            : 
      69                 :          0 :         status = txgbe_is_lldp(hw);
      70         [ #  # ]:          0 :         if (status) {
      71                 :          0 :                 PMD_INIT_LOG(INFO, "Can not get LLDP status.");
      72         [ #  # ]:          0 :         } else if (hw->lldp_enabled) {
      73                 :          0 :                 status = txgbe_hic_set_lldp(hw, false);
      74         [ #  # ]:          0 :                 if (!status)
      75                 :          0 :                         PMD_INIT_LOG(INFO,
      76                 :            :                                 "LLDP detected on port %d, turn it off by default.",
      77                 :            :                                 hw->port_id);
      78                 :            :                 else
      79                 :          0 :                         PMD_INIT_LOG(INFO, "Can not set LLDP status.");
      80                 :            :         }
      81                 :            : }
      82                 :            : 
      83                 :            : /**
      84                 :            :  * txgbe_device_supports_autoneg_fc - Check if device supports autonegotiation
      85                 :            :  * of flow control
      86                 :            :  * @hw: pointer to hardware structure
      87                 :            :  *
      88                 :            :  * This function returns true if the device supports flow control
      89                 :            :  * autonegotiation, and false if it does not.
      90                 :            :  *
      91                 :            :  **/
      92                 :          0 : bool txgbe_device_supports_autoneg_fc(struct txgbe_hw *hw)
      93                 :            : {
      94                 :            :         bool supported = false;
      95                 :            :         u32 speed;
      96                 :            :         bool link_up;
      97                 :            : 
      98   [ #  #  #  # ]:          0 :         switch (hw->phy.media_type) {
      99                 :          0 :         case txgbe_media_type_fiber_qsfp:
     100                 :            :         case txgbe_media_type_fiber:
     101                 :          0 :                 hw->mac.check_link(hw, &speed, &link_up, false);
     102                 :            :                 /* if link is down, assume supported */
     103         [ #  # ]:          0 :                 if (link_up)
     104                 :          0 :                         supported = speed == TXGBE_LINK_SPEED_1GB_FULL ?
     105                 :          0 :                         true : false;
     106                 :            :                 else
     107                 :            :                         supported = true;
     108                 :            : 
     109                 :            :                 break;
     110                 :            :         case txgbe_media_type_backplane:
     111                 :            :                 supported = true;
     112                 :            :                 break;
     113                 :          0 :         case txgbe_media_type_copper:
     114                 :            :                 /* only some copper devices support flow control autoneg */
     115         [ #  # ]:          0 :                 switch (hw->subsystem_device_id & 0xFF) {
     116                 :            :                 case TXGBE_DEV_ID_XAUI:
     117                 :            :                 case TXGBE_DEV_ID_SGMII:
     118                 :            :                         supported = true;
     119                 :            :                         break;
     120                 :            :                 default:
     121                 :            :                         supported = false;
     122                 :            :                 }
     123                 :            :         default:
     124                 :            :                 break;
     125                 :            :         }
     126                 :            : 
     127         [ #  # ]:          0 :         if (!supported)
     128                 :          0 :                 DEBUGOUT("Device %x does not support flow control autoneg",
     129                 :            :                               hw->device_id);
     130                 :          0 :         return supported;
     131                 :            : }
     132                 :            : 
     133                 :            : /**
     134                 :            :  *  txgbe_setup_fc - Set up flow control
     135                 :            :  *  @hw: pointer to hardware structure
     136                 :            :  *
     137                 :            :  *  Called at init time to set up flow control.
     138                 :            :  **/
     139                 :          0 : s32 txgbe_setup_fc(struct txgbe_hw *hw)
     140                 :            : {
     141                 :            :         s32 err = 0;
     142                 :            :         u32 reg = 0;
     143                 :            :         u16 reg_cu = 0;
     144                 :            :         u32 value = 0;
     145                 :            :         u64 reg_bp = 0;
     146                 :            : 
     147                 :            :         /* amlite-to-do */
     148         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_aml || hw->mac.type == txgbe_mac_aml40)
     149                 :            :                 return 0;
     150                 :            : 
     151                 :            :         /* Validate the requested mode */
     152   [ #  #  #  # ]:          0 :         if (hw->fc.strict_ieee && hw->fc.requested_mode == txgbe_fc_rx_pause) {
     153                 :          0 :                 DEBUGOUT("txgbe_fc_rx_pause not valid in strict IEEE mode");
     154                 :            :                 err = TXGBE_ERR_INVALID_LINK_SETTINGS;
     155                 :          0 :                 goto out;
     156                 :            :         }
     157                 :            : 
     158                 :            :         /*
     159                 :            :          * 10gig parts do not have a word in the EEPROM to determine the
     160                 :            :          * default flow control setting, so we explicitly set it to full.
     161                 :            :          */
     162         [ #  # ]:          0 :         if (hw->fc.requested_mode == txgbe_fc_default)
     163                 :          0 :                 hw->fc.requested_mode = txgbe_fc_full;
     164                 :            : 
     165                 :            :         /*
     166                 :            :          * The possible values of fc.requested_mode are:
     167                 :            :          * 0: Flow control is completely disabled
     168                 :            :          * 1: Rx flow control is enabled (we can receive pause frames,
     169                 :            :          *    but not send pause frames).
     170                 :            :          * 2: Tx flow control is enabled (we can send pause frames but
     171                 :            :          *    we do not support receiving pause frames).
     172                 :            :          * 3: Both Rx and Tx flow control (symmetric) are enabled.
     173                 :            :          * other: Invalid.
     174                 :            :          */
     175         [ #  # ]:          0 :         switch (hw->fc.requested_mode) {
     176                 :            :         case txgbe_fc_none:
     177                 :            :                 /* Flow control completely disabled by software override. */
     178                 :            :                 break;
     179                 :            :         case txgbe_fc_tx_pause:
     180                 :            :                 /*
     181                 :            :                  * Tx Flow control is enabled, and Rx Flow control is
     182                 :            :                  * disabled by software override.
     183                 :            :                  */
     184                 :            :                 reg |= SR_MII_MMD_AN_ADV_PAUSE_ASM;
     185                 :            :                 reg_bp |= SR_AN_MMD_ADV_REG1_PAUSE_ASM;
     186                 :            :                 break;
     187                 :            :         case txgbe_fc_rx_pause:
     188                 :            :                 /*
     189                 :            :                  * Rx Flow control is enabled and Tx Flow control is
     190                 :            :                  * disabled by software override. Since there really
     191                 :            :                  * isn't a way to advertise that we are capable of RX
     192                 :            :                  * Pause ONLY, we will advertise that we support both
     193                 :            :                  * symmetric and asymmetric Rx PAUSE, as such we fall
     194                 :            :                  * through to the fc_full statement.  Later, we will
     195                 :            :                  * disable the adapter's ability to send PAUSE frames.
     196                 :            :                  */
     197                 :            :         case txgbe_fc_full:
     198                 :            :                 /* Flow control (both Rx and Tx) is enabled by SW override. */
     199                 :            :                 reg |= SR_MII_MMD_AN_ADV_PAUSE_SYM |
     200                 :            :                         SR_MII_MMD_AN_ADV_PAUSE_ASM;
     201                 :            :                 reg_bp |= SR_AN_MMD_ADV_REG1_PAUSE_SYM |
     202                 :            :                         SR_AN_MMD_ADV_REG1_PAUSE_ASM;
     203                 :            :                 break;
     204                 :          0 :         default:
     205                 :          0 :                 DEBUGOUT("Flow control param set incorrectly");
     206                 :            :                 err = TXGBE_ERR_CONFIG;
     207                 :          0 :                 goto out;
     208                 :            :         }
     209                 :            : 
     210                 :            :         /*
     211                 :            :          * Enable auto-negotiation between the MAC & PHY;
     212                 :            :          * the MAC will advertise clause 37 flow control.
     213                 :            :          */
     214                 :            :         value = rd32_epcs(hw, SR_MII_MMD_AN_ADV);
     215                 :          0 :         value = (value & ~(SR_MII_MMD_AN_ADV_PAUSE_ASM |
     216                 :            :                 SR_MII_MMD_AN_ADV_PAUSE_SYM)) | reg;
     217                 :            :         wr32_epcs(hw, SR_MII_MMD_AN_ADV, value);
     218                 :            : 
     219                 :            :         /*
     220                 :            :          * AUTOC restart handles negotiation of 1G and 10G on backplane
     221                 :            :          * and copper. There is no need to set the PCS1GCTL register.
     222                 :            :          *
     223                 :            :          */
     224         [ #  # ]:          0 :         if (hw->phy.media_type == txgbe_media_type_backplane) {
     225                 :            :                 value = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);
     226                 :          0 :                 value = (value & ~(SR_AN_MMD_ADV_REG1_PAUSE_ASM |
     227                 :          0 :                         SR_AN_MMD_ADV_REG1_PAUSE_SYM)) |
     228                 :            :                         reg_bp;
     229                 :            :                 wr32_epcs(hw, SR_AN_MMD_ADV_REG1, value);
     230   [ #  #  #  # ]:          0 :         } else if ((hw->phy.media_type == txgbe_media_type_copper) &&
     231                 :          0 :                     (txgbe_device_supports_autoneg_fc(hw))) {
     232                 :          0 :                 hw->phy.write_reg(hw, TXGBE_MD_AUTO_NEG_ADVT,
     233                 :            :                                       TXGBE_MD_DEV_AUTO_NEG, reg_cu);
     234                 :            :         }
     235                 :            : 
     236                 :            :         /*
     237                 :            :          * Reconfig mac ctrl frame fwd rule to make sure it still
     238                 :            :          * working after port stop/start.
     239                 :            :          */
     240                 :          0 :         wr32m(hw, TXGBE_MACRXFLT, TXGBE_MACRXFLT_CTL_MASK,
     241         [ #  # ]:          0 :               (hw->fc.mac_ctrl_frame_fwd ?
     242                 :            :                TXGBE_MACRXFLT_CTL_NOPS : TXGBE_MACRXFLT_CTL_DROP));
     243                 :            :         txgbe_flush(hw);
     244                 :            : 
     245                 :          0 :         DEBUGOUT("Set up FC; reg = 0x%08X", reg);
     246                 :            : out:
     247                 :            :         return err;
     248                 :            : }
     249                 :            : 
     250                 :            : /**
     251                 :            :  *  txgbe_start_hw - Prepare hardware for Tx/Rx
     252                 :            :  *  @hw: pointer to hardware structure
     253                 :            :  *
     254                 :            :  *  Starts the hardware by filling the bus info structure and media type, clears
     255                 :            :  *  all on chip counters, initializes receive address registers, multicast
     256                 :            :  *  table, VLAN filter table, calls routine to set up link and flow control
     257                 :            :  *  settings, and leaves transmit and receive units disabled and uninitialized
     258                 :            :  **/
     259                 :          0 : s32 txgbe_start_hw(struct txgbe_hw *hw)
     260                 :            : {
     261                 :            :         s32 err;
     262                 :            :         u16 device_caps;
     263                 :            : 
     264                 :            :         /* Set the media type */
     265                 :          0 :         hw->phy.media_type = hw->phy.get_media_type(hw);
     266                 :            : 
     267                 :            :         /* Clear the VLAN filter table */
     268                 :          0 :         hw->mac.clear_vfta(hw);
     269                 :            : 
     270                 :            :         /* Clear statistics registers */
     271                 :          0 :         hw->mac.clear_hw_cntrs(hw);
     272                 :            : 
     273                 :            :         /* Setup flow control */
     274                 :          0 :         err = txgbe_setup_fc(hw);
     275         [ #  # ]:          0 :         if (err != 0 && err != TXGBE_NOT_IMPLEMENTED) {
     276                 :          0 :                 DEBUGOUT("Flow control setup failed, returning %d", err);
     277                 :          0 :                 return err;
     278                 :            :         }
     279                 :            : 
     280                 :            :         /* Cache bit indicating need for crosstalk fix */
     281         [ #  # ]:          0 :         switch (hw->mac.type) {
     282                 :          0 :         case txgbe_mac_sp:
     283                 :            :         case txgbe_mac_aml:
     284                 :            :         case txgbe_mac_aml40:
     285                 :          0 :                 hw->mac.get_device_caps(hw, &device_caps);
     286         [ #  # ]:          0 :                 if (device_caps & TXGBE_DEVICE_CAPS_NO_CROSSTALK_WR)
     287                 :          0 :                         hw->need_crosstalk_fix = false;
     288                 :            :                 else
     289                 :          0 :                         hw->need_crosstalk_fix = true;
     290                 :            :                 break;
     291                 :          0 :         default:
     292                 :          0 :                 hw->need_crosstalk_fix = false;
     293                 :          0 :                 break;
     294                 :            :         }
     295                 :            : 
     296                 :            :         /* Clear adapter stopped flag */
     297                 :          0 :         hw->adapter_stopped = false;
     298                 :            : 
     299                 :          0 :         return 0;
     300                 :            : }
     301                 :            : 
     302                 :            : /**
     303                 :            :  *  txgbe_start_hw_gen2 - Init sequence for common device family
     304                 :            :  *  @hw: pointer to hw structure
     305                 :            :  *
     306                 :            :  * Performs the init sequence common to the second generation
     307                 :            :  * of 10 GbE devices.
     308                 :            :  **/
     309                 :          0 : s32 txgbe_start_hw_gen2(struct txgbe_hw *hw)
     310                 :            : {
     311                 :            :         u32 i;
     312                 :            : 
     313                 :            :         /* Clear the rate limiters */
     314         [ #  # ]:          0 :         for (i = 0; i < hw->mac.max_tx_queues; i++) {
     315                 :            :                 wr32(hw, TXGBE_ARBPOOLIDX, i);
     316                 :            :                 wr32(hw, TXGBE_ARBTXRATE, 0);
     317                 :            :         }
     318                 :            :         txgbe_flush(hw);
     319                 :            : 
     320                 :            :         /* We need to run link autotry after the driver loads */
     321                 :          0 :         hw->mac.autotry_restart = true;
     322                 :            : 
     323                 :          0 :         return 0;
     324                 :            : }
     325                 :            : 
     326                 :            : /**
     327                 :            :  *  txgbe_init_hw - Generic hardware initialization
     328                 :            :  *  @hw: pointer to hardware structure
     329                 :            :  *
     330                 :            :  *  Initialize the hardware by resetting the hardware, filling the bus info
     331                 :            :  *  structure and media type, clears all on chip counters, initializes receive
     332                 :            :  *  address registers, multicast table, VLAN filter table, calls routine to set
     333                 :            :  *  up link and flow control settings, and leaves transmit and receive units
     334                 :            :  *  disabled and uninitialized
     335                 :            :  **/
     336                 :          0 : s32 txgbe_init_hw(struct txgbe_hw *hw)
     337                 :            : {
     338                 :            :         s32 status;
     339                 :            : 
     340                 :            :         /* Get firmware version */
     341                 :          0 :         hw->phy.get_fw_version(hw, &hw->fw_version);
     342                 :            : 
     343                 :          0 :         txgbe_disable_lldp(hw);
     344                 :            : 
     345                 :            :         /* Init fec mode to 'AUTO' */
     346                 :          0 :         hw->fec_mode = TXGBE_PHY_FEC_AUTO;
     347                 :            : 
     348                 :            :         /* Reset the hardware */
     349                 :          0 :         status = hw->mac.reset_hw(hw);
     350         [ #  # ]:          0 :         if (status == 0 || status == TXGBE_ERR_SFP_NOT_PRESENT) {
     351                 :            :                 /* Start the HW */
     352                 :          0 :                 status = hw->mac.start_hw(hw);
     353                 :            :         }
     354                 :            : 
     355         [ #  # ]:          0 :         if (status != 0)
     356                 :          0 :                 DEBUGOUT("Failed to initialize HW, STATUS = %d", status);
     357                 :            : 
     358                 :          0 :         return status;
     359                 :            : }
     360                 :            : 
     361                 :            : /**
     362                 :            :  *  txgbe_clear_hw_cntrs - Generic clear hardware counters
     363                 :            :  *  @hw: pointer to hardware structure
     364                 :            :  *
     365                 :            :  *  Clears all hardware statistics counters by reading them from the hardware
     366                 :            :  *  Statistics counters are clear on read.
     367                 :            :  **/
     368                 :          0 : s32 txgbe_clear_hw_cntrs(struct txgbe_hw *hw)
     369                 :            : {
     370                 :            :         u16 i = 0;
     371                 :            : 
     372                 :            :         /* QP Stats */
     373                 :            :         /* don't write clear queue stats */
     374         [ #  # ]:          0 :         for (i = 0; i < TXGBE_MAX_QP; i++) {
     375                 :          0 :                 hw->qp_last[i].rx_qp_packets = 0;
     376                 :          0 :                 hw->qp_last[i].tx_qp_packets = 0;
     377                 :          0 :                 hw->qp_last[i].rx_qp_bytes = 0;
     378                 :          0 :                 hw->qp_last[i].tx_qp_bytes = 0;
     379                 :          0 :                 hw->qp_last[i].rx_qp_mc_packets = 0;
     380                 :            :         }
     381                 :            : 
     382                 :            :         /* PB Stats */
     383         [ #  # ]:          0 :         for (i = 0; i < TXGBE_MAX_UP; i++) {
     384                 :          0 :                 rd32(hw, TXGBE_PBRXUPXON(i));
     385                 :          0 :                 rd32(hw, TXGBE_PBRXUPXOFF(i));
     386                 :          0 :                 rd32(hw, TXGBE_PBTXUPXON(i));
     387                 :          0 :                 rd32(hw, TXGBE_PBTXUPXOFF(i));
     388                 :          0 :                 rd32(hw, TXGBE_PBTXUPOFF(i));
     389                 :            : 
     390                 :          0 :                 rd32(hw, TXGBE_PBRXMISS(i));
     391                 :            :         }
     392                 :            :         rd32(hw, TXGBE_PBRXLNKXON);
     393                 :            :         rd32(hw, TXGBE_PBRXLNKXOFF);
     394                 :            :         rd32(hw, TXGBE_PBTXLNKXON);
     395                 :            :         rd32(hw, TXGBE_PBTXLNKXOFF);
     396                 :            : 
     397                 :            :         /* DMA Stats */
     398                 :            :         rd32(hw, TXGBE_DMARXPKT);
     399                 :            :         rd32(hw, TXGBE_DMATXPKT);
     400                 :            : 
     401                 :            :         rd64(hw, TXGBE_DMARXOCTL);
     402                 :            :         rd64(hw, TXGBE_DMATXOCTL);
     403                 :            : 
     404                 :            :         /* MAC Stats */
     405                 :            :         rd64(hw, TXGBE_MACRXERRCRCL);
     406                 :            :         rd64(hw, TXGBE_MACRXMPKTL);
     407                 :            :         rd64(hw, TXGBE_MACTXMPKTL);
     408                 :            : 
     409                 :            :         rd64(hw, TXGBE_MACRXPKTL);
     410                 :            :         rd64(hw, TXGBE_MACTXPKTL);
     411                 :            :         rd64(hw, TXGBE_MACRXGBOCTL);
     412                 :            : 
     413                 :            :         rd64(hw, TXGBE_MACRXOCTL);
     414                 :            :         rd32(hw, TXGBE_MACTXOCTL);
     415                 :            : 
     416                 :            :         rd64(hw, TXGBE_MACRX1TO64L);
     417                 :            :         rd64(hw, TXGBE_MACRX65TO127L);
     418                 :            :         rd64(hw, TXGBE_MACRX128TO255L);
     419                 :            :         rd64(hw, TXGBE_MACRX256TO511L);
     420                 :            :         rd64(hw, TXGBE_MACRX512TO1023L);
     421                 :            :         rd64(hw, TXGBE_MACRX1024TOMAXL);
     422                 :            :         rd64(hw, TXGBE_MACTX1TO64L);
     423                 :            :         rd64(hw, TXGBE_MACTX65TO127L);
     424                 :            :         rd64(hw, TXGBE_MACTX128TO255L);
     425                 :            :         rd64(hw, TXGBE_MACTX256TO511L);
     426                 :            :         rd64(hw, TXGBE_MACTX512TO1023L);
     427                 :            :         rd64(hw, TXGBE_MACTX1024TOMAXL);
     428                 :            : 
     429                 :            :         rd64(hw, TXGBE_MACRXERRLENL);
     430                 :            :         rd32(hw, TXGBE_MACRXOVERSIZE);
     431                 :            :         rd32(hw, TXGBE_MACRXJABBER);
     432                 :            : 
     433                 :            :         /* FCoE Stats */
     434                 :            :         rd32(hw, TXGBE_FCOECRC);
     435                 :            :         rd32(hw, TXGBE_FCOELAST);
     436                 :            :         rd32(hw, TXGBE_FCOERPDC);
     437                 :            :         rd32(hw, TXGBE_FCOEPRC);
     438                 :            :         rd32(hw, TXGBE_FCOEPTC);
     439                 :            :         rd32(hw, TXGBE_FCOEDWRC);
     440                 :            :         rd32(hw, TXGBE_FCOEDWTC);
     441                 :            : 
     442                 :            :         /* Flow Director Stats */
     443                 :            :         rd32(hw, TXGBE_FDIRMATCH);
     444                 :            :         rd32(hw, TXGBE_FDIRMISS);
     445                 :            :         rd32(hw, TXGBE_FDIRUSED);
     446                 :            :         rd32(hw, TXGBE_FDIRUSED);
     447                 :            :         rd32(hw, TXGBE_FDIRFAIL);
     448                 :            :         rd32(hw, TXGBE_FDIRFAIL);
     449                 :            : 
     450                 :            :         /* MACsec Stats */
     451                 :            :         rd32(hw, TXGBE_LSECTX_UTPKT);
     452                 :            :         rd32(hw, TXGBE_LSECTX_ENCPKT);
     453                 :            :         rd32(hw, TXGBE_LSECTX_PROTPKT);
     454                 :            :         rd32(hw, TXGBE_LSECTX_ENCOCT);
     455                 :            :         rd32(hw, TXGBE_LSECTX_PROTOCT);
     456                 :            :         rd32(hw, TXGBE_LSECRX_UTPKT);
     457                 :            :         rd32(hw, TXGBE_LSECRX_BTPKT);
     458                 :            :         rd32(hw, TXGBE_LSECRX_NOSCIPKT);
     459                 :            :         rd32(hw, TXGBE_LSECRX_UNSCIPKT);
     460                 :            :         rd32(hw, TXGBE_LSECRX_DECOCT);
     461                 :            :         rd32(hw, TXGBE_LSECRX_VLDOCT);
     462                 :            :         rd32(hw, TXGBE_LSECRX_UNCHKPKT);
     463                 :            :         rd32(hw, TXGBE_LSECRX_DLYPKT);
     464                 :            :         rd32(hw, TXGBE_LSECRX_LATEPKT);
     465         [ #  # ]:          0 :         for (i = 0; i < 2; i++) {
     466                 :          0 :                 rd32(hw, TXGBE_LSECRX_OKPKT(i));
     467                 :          0 :                 rd32(hw, TXGBE_LSECRX_INVPKT(i));
     468                 :          0 :                 rd32(hw, TXGBE_LSECRX_BADPKT(i));
     469                 :            :         }
     470                 :            :         rd32(hw, TXGBE_LSECRX_INVSAPKT);
     471                 :            :         rd32(hw, TXGBE_LSECRX_BADSAPKT);
     472                 :            : 
     473                 :          0 :         return 0;
     474                 :            : }
     475                 :            : 
     476                 :            : /**
     477                 :            :  *  txgbe_get_mac_addr - Generic get MAC address
     478                 :            :  *  @hw: pointer to hardware structure
     479                 :            :  *  @mac_addr: Adapter MAC address
     480                 :            :  *
     481                 :            :  *  Reads the adapter's MAC address from first Receive Address Register (RAR0)
     482                 :            :  *  A reset of the adapter must be performed prior to calling this function
     483                 :            :  *  in order for the MAC address to have been loaded from the EEPROM into RAR0
     484                 :            :  **/
     485                 :          0 : s32 txgbe_get_mac_addr(struct txgbe_hw *hw, u8 *mac_addr)
     486                 :            : {
     487                 :            :         u32 rar_high;
     488                 :            :         u32 rar_low;
     489                 :            :         u16 i;
     490                 :            : 
     491                 :            :         wr32(hw, TXGBE_ETHADDRIDX, 0);
     492                 :            :         rar_high = rd32(hw, TXGBE_ETHADDRH);
     493                 :            :         rar_low = rd32(hw, TXGBE_ETHADDRL);
     494                 :            : 
     495         [ #  # ]:          0 :         for (i = 0; i < 2; i++)
     496                 :          0 :                 mac_addr[i] = (u8)(rar_high >> (1 - i) * 8);
     497                 :            : 
     498         [ #  # ]:          0 :         for (i = 0; i < 4; i++)
     499                 :          0 :                 mac_addr[i + 2] = (u8)(rar_low >> (3 - i) * 8);
     500                 :            : 
     501                 :          0 :         return 0;
     502                 :            : }
     503                 :            : 
     504                 :            : /**
     505                 :            :  *  txgbe_set_lan_id_multi_port - Set LAN id for PCIe multiple port devices
     506                 :            :  *  @hw: pointer to the HW structure
     507                 :            :  *
     508                 :            :  *  Determines the LAN function id by reading memory-mapped registers and swaps
     509                 :            :  *  the port value if requested, and set MAC instance for devices.
     510                 :            :  **/
     511                 :          0 : void txgbe_set_lan_id_multi_port(struct txgbe_hw *hw)
     512                 :            : {
     513                 :            :         struct txgbe_bus_info *bus = &hw->bus;
     514                 :            :         u32 reg;
     515                 :            : 
     516                 :            :         reg = rd32(hw, TXGBE_PORTSTAT);
     517                 :          0 :         bus->lan_id = TXGBE_PORTSTAT_ID(reg);
     518                 :            : 
     519                 :            :         /* check for single port */
     520                 :            :         reg = rd32(hw, TXGBE_PWR);
     521                 :            :         if (TXGBE_PWR_LANID(reg) == TXGBE_PWR_LANID_SWAP)
     522                 :            :                 bus->func = 0;
     523                 :            :         else
     524                 :          0 :                 bus->func = bus->lan_id;
     525                 :          0 : }
     526                 :            : 
     527                 :            : /**
     528                 :            :  *  txgbe_stop_hw - Generic stop Tx/Rx units
     529                 :            :  *  @hw: pointer to hardware structure
     530                 :            :  *
     531                 :            :  *  Sets the adapter_stopped flag within txgbe_hw struct. Clears interrupts,
     532                 :            :  *  disables transmit and receive units. The adapter_stopped flag is used by
     533                 :            :  *  the shared code and drivers to determine if the adapter is in a stopped
     534                 :            :  *  state and should not touch the hardware.
     535                 :            :  **/
     536                 :          0 : s32 txgbe_stop_hw(struct txgbe_hw *hw)
     537                 :            : {
     538                 :            :         s32 status = 0;
     539                 :            :         u16 i;
     540                 :            : 
     541                 :            :         /*
     542                 :            :          * Set the adapter_stopped flag so other driver functions stop touching
     543                 :            :          * the hardware
     544                 :            :          */
     545                 :          0 :         hw->adapter_stopped = true;
     546                 :            : 
     547                 :            :         /* Disable the receive unit */
     548                 :          0 :         txgbe_disable_rx(hw);
     549                 :            : 
     550                 :            :         /* Clear interrupt mask to stop interrupts from being generated */
     551                 :            :         wr32(hw, TXGBE_IENMISC, 0);
     552                 :            :         wr32(hw, TXGBE_IMS(0), TXGBE_IMS_MASK);
     553                 :            :         wr32(hw, TXGBE_IMS(1), TXGBE_IMS_MASK);
     554                 :            : 
     555                 :            :         /* Clear any pending interrupts, flush previous writes */
     556                 :            :         wr32(hw, TXGBE_ICRMISC, TXGBE_ICRMISC_MASK);
     557                 :            :         wr32(hw, TXGBE_ICR(0), TXGBE_ICR_MASK);
     558                 :            :         wr32(hw, TXGBE_ICR(1), TXGBE_ICR_MASK);
     559                 :            : 
     560                 :            :         wr32(hw, TXGBE_BMECTL, 0x3);
     561                 :            : 
     562                 :            :         /* Disable the receive unit by stopping each queue */
     563         [ #  # ]:          0 :         for (i = 0; i < hw->mac.max_rx_queues; i++)
     564                 :          0 :                 wr32(hw, TXGBE_RXCFG(i), 0);
     565                 :            : 
     566                 :            :         /* flush all queues disables */
     567                 :            :         txgbe_flush(hw);
     568                 :            :         msec_delay(2);
     569                 :            : 
     570                 :            :         /* Prevent the PCI-E bus from hanging by disabling PCI-E master
     571                 :            :          * access and verify no pending requests
     572                 :            :          */
     573                 :          0 :         status = txgbe_set_pcie_master(hw, false);
     574         [ #  # ]:          0 :         if (status)
     575                 :            :                 return status;
     576                 :            : 
     577                 :            :         /* Disable the transmit unit.  Each queue must be disabled. */
     578         [ #  # ]:          0 :         for (i = 0; i < hw->mac.max_tx_queues; i++)
     579                 :          0 :                 wr32(hw, TXGBE_TXCFG(i), 0);
     580                 :            : 
     581                 :            :         /* flush all queues disables */
     582                 :            :         txgbe_flush(hw);
     583                 :            :         msec_delay(2);
     584                 :            : 
     585                 :          0 :         return 0;
     586                 :            : }
     587                 :            : 
     588                 :            : /**
     589                 :            :  *  txgbe_led_on - Turns on the software controllable LEDs.
     590                 :            :  *  @hw: pointer to hardware structure
     591                 :            :  *  @index: led number to turn on
     592                 :            :  **/
     593                 :          0 : s32 txgbe_led_on(struct txgbe_hw *hw, u32 index)
     594                 :            : {
     595                 :            :         u32 led_reg = rd32(hw, TXGBE_LEDCTL);
     596                 :            : 
     597                 :            :         /* To turn on the LED, set mode to ON. */
     598                 :          0 :         led_reg |= index << TXGBE_LEDCTL_ORD_SHIFT;
     599                 :          0 :         led_reg |= index;
     600                 :            :         wr32(hw, TXGBE_LEDCTL, led_reg);
     601                 :            :         txgbe_flush(hw);
     602                 :            : 
     603                 :          0 :         return 0;
     604                 :            : }
     605                 :            : 
     606                 :            : /**
     607                 :            :  *  txgbe_led_off - Turns off the software controllable LEDs.
     608                 :            :  *  @hw: pointer to hardware structure
     609                 :            :  *  @index: led number to turn off
     610                 :            :  **/
     611                 :          0 : s32 txgbe_led_off(struct txgbe_hw *hw, u32 index)
     612                 :            : {
     613                 :            :         u32 led_reg = rd32(hw, TXGBE_LEDCTL);
     614                 :            : 
     615                 :            :         /* To turn off the LED, set mode to OFF. */
     616                 :          0 :         led_reg &= ~(index << TXGBE_LEDCTL_ORD_SHIFT);
     617                 :          0 :         led_reg |= index;
     618                 :            :         wr32(hw, TXGBE_LEDCTL, led_reg);
     619                 :            :         txgbe_flush(hw);
     620                 :            : 
     621                 :          0 :         return 0;
     622                 :            : }
     623                 :            : 
     624                 :            : /**
     625                 :            :  *  txgbe_validate_mac_addr - Validate MAC address
     626                 :            :  *  @mac_addr: pointer to MAC address.
     627                 :            :  *
     628                 :            :  *  Tests a MAC address to ensure it is a valid Individual Address.
     629                 :            :  **/
     630                 :          0 : s32 txgbe_validate_mac_addr(u8 *mac_addr)
     631                 :            : {
     632                 :            :         s32 status = 0;
     633                 :            : 
     634                 :            :         /* Make sure it is not a multicast address */
     635         [ #  # ]:          0 :         if (TXGBE_IS_MULTICAST(mac_addr)) {
     636                 :            :                 status = TXGBE_ERR_INVALID_MAC_ADDR;
     637                 :            :         /* Not a broadcast address */
     638                 :            :         } else if (TXGBE_IS_BROADCAST(mac_addr)) {
     639                 :            :                 status = TXGBE_ERR_INVALID_MAC_ADDR;
     640                 :            :         /* Reject the zero address */
     641   [ #  #  #  #  :          0 :         } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
                   #  # ]
     642   [ #  #  #  #  :          0 :                    mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
                   #  # ]
     643                 :            :                 status = TXGBE_ERR_INVALID_MAC_ADDR;
     644                 :            :         }
     645                 :          0 :         return status;
     646                 :            : }
     647                 :            : 
     648                 :            : /**
     649                 :            :  *  txgbe_set_rar - Set Rx address register
     650                 :            :  *  @hw: pointer to hardware structure
     651                 :            :  *  @index: Receive address register to write
     652                 :            :  *  @addr: Address to put into receive address register
     653                 :            :  *  @vmdq: VMDq "set" or "pool" index
     654                 :            :  *  @enable_addr: set flag that address is active
     655                 :            :  *
     656                 :            :  *  Puts an ethernet address into a receive address register.
     657                 :            :  **/
     658                 :          0 : s32 txgbe_set_rar(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
     659                 :            :                           u32 enable_addr)
     660                 :            : {
     661                 :            :         u32 rar_low, rar_high;
     662                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
     663                 :            : 
     664                 :            :         /* Make sure we are using a valid rar index range */
     665         [ #  # ]:          0 :         if (index >= rar_entries) {
     666                 :          0 :                 DEBUGOUT("RAR index %d is out of range.", index);
     667                 :          0 :                 return TXGBE_ERR_INVALID_ARGUMENT;
     668                 :            :         }
     669                 :            : 
     670                 :            :         /* setup VMDq pool selection before this RAR gets enabled */
     671                 :          0 :         hw->mac.set_vmdq(hw, index, vmdq);
     672                 :            : 
     673                 :            :         /*
     674                 :            :          * HW expects these in little endian so we reverse the byte
     675                 :            :          * order from network order (big endian) to little endian
     676                 :            :          */
     677                 :          0 :         rar_low = TXGBE_ETHADDRL_AD0(addr[5]) |
     678                 :          0 :                   TXGBE_ETHADDRL_AD1(addr[4]) |
     679                 :          0 :                   TXGBE_ETHADDRL_AD2(addr[3]) |
     680                 :          0 :                   TXGBE_ETHADDRL_AD3(addr[2]);
     681                 :            :         /*
     682                 :            :          * Some parts put the VMDq setting in the extra RAH bits,
     683                 :            :          * so save everything except the lower 16 bits that hold part
     684                 :            :          * of the address and the address valid bit.
     685                 :            :          */
     686                 :            :         rar_high = rd32(hw, TXGBE_ETHADDRH);
     687                 :          0 :         rar_high &= ~TXGBE_ETHADDRH_AD_MASK;
     688                 :          0 :         rar_high |= (TXGBE_ETHADDRH_AD4(addr[1]) |
     689                 :          0 :                      TXGBE_ETHADDRH_AD5(addr[0]));
     690                 :            : 
     691                 :          0 :         rar_high &= ~TXGBE_ETHADDRH_VLD;
     692         [ #  # ]:          0 :         if (enable_addr != 0)
     693                 :          0 :                 rar_high |= TXGBE_ETHADDRH_VLD;
     694                 :            : 
     695                 :            :         wr32(hw, TXGBE_ETHADDRIDX, index);
     696                 :            :         wr32(hw, TXGBE_ETHADDRL, rar_low);
     697                 :            :         wr32(hw, TXGBE_ETHADDRH, rar_high);
     698                 :            : 
     699                 :          0 :         return 0;
     700                 :            : }
     701                 :            : 
     702                 :            : /**
     703                 :            :  *  txgbe_clear_rar - Remove Rx address register
     704                 :            :  *  @hw: pointer to hardware structure
     705                 :            :  *  @index: Receive address register to write
     706                 :            :  *
     707                 :            :  *  Clears an ethernet address from a receive address register.
     708                 :            :  **/
     709                 :          0 : s32 txgbe_clear_rar(struct txgbe_hw *hw, u32 index)
     710                 :            : {
     711                 :            :         u32 rar_high;
     712                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
     713                 :            : 
     714                 :            :         /* Make sure we are using a valid rar index range */
     715         [ #  # ]:          0 :         if (index >= rar_entries) {
     716                 :          0 :                 DEBUGOUT("RAR index %d is out of range.", index);
     717                 :          0 :                 return TXGBE_ERR_INVALID_ARGUMENT;
     718                 :            :         }
     719                 :            : 
     720                 :            :         /*
     721                 :            :          * Some parts put the VMDq setting in the extra RAH bits,
     722                 :            :          * so save everything except the lower 16 bits that hold part
     723                 :            :          * of the address and the address valid bit.
     724                 :            :          */
     725                 :            :         wr32(hw, TXGBE_ETHADDRIDX, index);
     726                 :            :         rar_high = rd32(hw, TXGBE_ETHADDRH);
     727                 :          0 :         rar_high &= ~(TXGBE_ETHADDRH_AD_MASK | TXGBE_ETHADDRH_VLD);
     728                 :            : 
     729                 :            :         wr32(hw, TXGBE_ETHADDRL, 0);
     730                 :            :         wr32(hw, TXGBE_ETHADDRH, rar_high);
     731                 :            : 
     732                 :            :         /* clear VMDq pool/queue selection for this RAR */
     733                 :          0 :         hw->mac.clear_vmdq(hw, index, BIT_MASK32);
     734                 :            : 
     735                 :          0 :         return 0;
     736                 :            : }
     737                 :            : 
     738                 :            : /**
     739                 :            :  *  txgbe_init_rx_addrs - Initializes receive address filters.
     740                 :            :  *  @hw: pointer to hardware structure
     741                 :            :  *
     742                 :            :  *  Places the MAC address in receive address register 0 and clears the rest
     743                 :            :  *  of the receive address registers. Clears the multicast table. Assumes
     744                 :            :  *  the receiver is in reset when the routine is called.
     745                 :            :  **/
     746                 :          0 : s32 txgbe_init_rx_addrs(struct txgbe_hw *hw)
     747                 :            : {
     748                 :            :         u32 i;
     749                 :            :         u32 psrctl;
     750                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
     751                 :            : 
     752                 :            :         /*
     753                 :            :          * If the current mac address is valid, assume it is a software override
     754                 :            :          * to the permanent address.
     755                 :            :          * Otherwise, use the permanent address from the eeprom.
     756                 :            :          */
     757         [ #  # ]:          0 :         if (txgbe_validate_mac_addr(hw->mac.addr) ==
     758                 :            :             TXGBE_ERR_INVALID_MAC_ADDR) {
     759                 :            :                 /* Get the MAC address from the RAR0 for later reference */
     760                 :          0 :                 hw->mac.get_mac_addr(hw, hw->mac.addr);
     761                 :            : 
     762                 :          0 :                 DEBUGOUT(" Keeping Current RAR0 Addr = "
     763                 :            :                           RTE_ETHER_ADDR_PRT_FMT,
     764                 :            :                           hw->mac.addr[0], hw->mac.addr[1],
     765                 :            :                           hw->mac.addr[2], hw->mac.addr[3],
     766                 :            :                           hw->mac.addr[4], hw->mac.addr[5]);
     767                 :            :         } else {
     768                 :            :                 /* Setup the receive address. */
     769                 :          0 :                 DEBUGOUT("Overriding MAC Address in RAR[0]");
     770                 :          0 :                 DEBUGOUT(" New MAC Addr = "
     771                 :            :                           RTE_ETHER_ADDR_PRT_FMT,
     772                 :            :                           hw->mac.addr[0], hw->mac.addr[1],
     773                 :            :                           hw->mac.addr[2], hw->mac.addr[3],
     774                 :            :                           hw->mac.addr[4], hw->mac.addr[5]);
     775                 :            : 
     776                 :          0 :                 hw->mac.set_rar(hw, 0, hw->mac.addr, 0, true);
     777                 :            :         }
     778                 :            : 
     779                 :            :         /* clear VMDq pool/queue selection for RAR 0 */
     780                 :          0 :         hw->mac.clear_vmdq(hw, 0, BIT_MASK32);
     781                 :            : 
     782                 :          0 :         hw->addr_ctrl.overflow_promisc = 0;
     783                 :            : 
     784                 :          0 :         hw->addr_ctrl.rar_used_count = 1;
     785                 :            : 
     786                 :            :         /* Zero out the other receive addresses. */
     787                 :          0 :         DEBUGOUT("Clearing RAR[1-%d]", rar_entries - 1);
     788         [ #  # ]:          0 :         for (i = 1; i < rar_entries; i++) {
     789                 :            :                 wr32(hw, TXGBE_ETHADDRIDX, i);
     790                 :            :                 wr32(hw, TXGBE_ETHADDRL, 0);
     791                 :            :                 wr32(hw, TXGBE_ETHADDRH, 0);
     792                 :            :         }
     793                 :            : 
     794                 :            :         /* Clear the MTA */
     795                 :          0 :         hw->addr_ctrl.mta_in_use = 0;
     796                 :            :         psrctl = rd32(hw, TXGBE_PSRCTL);
     797                 :          0 :         psrctl &= ~(TXGBE_PSRCTL_ADHF12_MASK | TXGBE_PSRCTL_MCHFENA);
     798                 :          0 :         psrctl |= TXGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
     799                 :            :         wr32(hw, TXGBE_PSRCTL, psrctl);
     800                 :            : 
     801                 :          0 :         DEBUGOUT(" Clearing MTA");
     802         [ #  # ]:          0 :         for (i = 0; i < hw->mac.mcft_size; i++)
     803                 :          0 :                 wr32(hw, TXGBE_MCADDRTBL(i), 0);
     804                 :            : 
     805                 :          0 :         txgbe_init_uta_tables(hw);
     806                 :            : 
     807                 :          0 :         return 0;
     808                 :            : }
     809                 :            : 
     810                 :            : /**
     811                 :            :  *  txgbe_mta_vector - Determines bit-vector in multicast table to set
     812                 :            :  *  @hw: pointer to hardware structure
     813                 :            :  *  @mc_addr: the multicast address
     814                 :            :  *
     815                 :            :  *  Extracts the 12 bits, from a multicast address, to determine which
     816                 :            :  *  bit-vector to set in the multicast table. The hardware uses 12 bits, from
     817                 :            :  *  incoming rx multicast addresses, to determine the bit-vector to check in
     818                 :            :  *  the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
     819                 :            :  *  by the MO field of the PSRCTRL. The MO field is set during initialization
     820                 :            :  *  to mc_filter_type.
     821                 :            :  **/
     822                 :          0 : static s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr)
     823                 :            : {
     824                 :            :         u32 vector = 0;
     825                 :            : 
     826   [ #  #  #  #  :          0 :         switch (hw->mac.mc_filter_type) {
                      # ]
     827                 :          0 :         case 0:   /* use bits [47:36] of the address */
     828                 :          0 :                 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
     829                 :          0 :                 break;
     830                 :          0 :         case 1:   /* use bits [46:35] of the address */
     831                 :          0 :                 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
     832                 :          0 :                 break;
     833                 :          0 :         case 2:   /* use bits [45:34] of the address */
     834                 :          0 :                 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
     835                 :          0 :                 break;
     836                 :          0 :         case 3:   /* use bits [43:32] of the address */
     837                 :          0 :                 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
     838                 :          0 :                 break;
     839                 :          0 :         default:  /* Invalid mc_filter_type */
     840                 :          0 :                 DEBUGOUT("MC filter type param set incorrectly");
     841                 :          0 :                 ASSERT(0);
     842                 :            :                 break;
     843                 :            :         }
     844                 :            : 
     845                 :            :         /* vector can only be 12-bits or boundary will be exceeded */
     846                 :          0 :         vector &= 0xFFF;
     847                 :          0 :         return vector;
     848                 :            : }
     849                 :            : 
     850                 :            : /**
     851                 :            :  *  txgbe_set_mta - Set bit-vector in multicast table
     852                 :            :  *  @hw: pointer to hardware structure
     853                 :            :  *  @mc_addr: Multicast address
     854                 :            :  *
     855                 :            :  *  Sets the bit-vector in the multicast table.
     856                 :            :  **/
     857                 :          0 : void txgbe_set_mta(struct txgbe_hw *hw, u8 *mc_addr)
     858                 :            : {
     859                 :            :         u32 vector;
     860                 :            :         u32 vector_bit;
     861                 :            :         u32 vector_reg;
     862                 :            : 
     863                 :          0 :         hw->addr_ctrl.mta_in_use++;
     864                 :            : 
     865                 :          0 :         vector = txgbe_mta_vector(hw, mc_addr);
     866                 :          0 :         DEBUGOUT(" bit-vector = 0x%03X", vector);
     867                 :            : 
     868                 :            :         /*
     869                 :            :          * The MTA is a register array of 128 32-bit registers. It is treated
     870                 :            :          * like an array of 4096 bits.  We want to set bit
     871                 :            :          * BitArray[vector_value]. So we figure out what register the bit is
     872                 :            :          * in, read it, OR in the new bit, then write back the new value.  The
     873                 :            :          * register is determined by the upper 7 bits of the vector value and
     874                 :            :          * the bit within that register are determined by the lower 5 bits of
     875                 :            :          * the value.
     876                 :            :          */
     877                 :          0 :         vector_reg = (vector >> 5) & 0x7F;
     878                 :          0 :         vector_bit = vector & 0x1F;
     879                 :          0 :         hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
     880                 :          0 : }
     881                 :            : 
     882                 :            : /**
     883                 :            :  *  txgbe_update_mc_addr_list - Updates MAC list of multicast addresses
     884                 :            :  *  @hw: pointer to hardware structure
     885                 :            :  *  @mc_addr_list: the list of new multicast addresses
     886                 :            :  *  @mc_addr_count: number of addresses
     887                 :            :  *  @next: iterator function to walk the multicast address list
     888                 :            :  *  @clear: flag, when set clears the table beforehand
     889                 :            :  *
     890                 :            :  *  When the clear flag is set, the given list replaces any existing list.
     891                 :            :  *  Hashes the given addresses into the multicast table.
     892                 :            :  **/
     893                 :          0 : s32 txgbe_update_mc_addr_list(struct txgbe_hw *hw, u8 *mc_addr_list,
     894                 :            :                                       u32 mc_addr_count, txgbe_mc_addr_itr next,
     895                 :            :                                       bool clear)
     896                 :            : {
     897                 :            :         u32 i;
     898                 :            :         u32 vmdq;
     899                 :            : 
     900                 :            :         /*
     901                 :            :          * Set the new number of MC addresses that we are being requested to
     902                 :            :          * use.
     903                 :            :          */
     904                 :          0 :         hw->addr_ctrl.num_mc_addrs = mc_addr_count;
     905                 :          0 :         hw->addr_ctrl.mta_in_use = 0;
     906                 :            : 
     907                 :            :         /* Clear mta_shadow */
     908         [ #  # ]:          0 :         if (clear) {
     909                 :          0 :                 DEBUGOUT(" Clearing MTA");
     910                 :          0 :                 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
     911                 :            :         }
     912                 :            : 
     913                 :            :         /* Update mta_shadow */
     914         [ #  # ]:          0 :         for (i = 0; i < mc_addr_count; i++) {
     915                 :          0 :                 DEBUGOUT(" Adding the multicast addresses:");
     916                 :          0 :                 txgbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
     917                 :            :         }
     918                 :            : 
     919                 :            :         /* Enable mta */
     920         [ #  # ]:          0 :         for (i = 0; i < hw->mac.mcft_size; i++)
     921                 :          0 :                 wr32a(hw, TXGBE_MCADDRTBL(0), i,
     922                 :            :                                       hw->mac.mta_shadow[i]);
     923                 :            : 
     924         [ #  # ]:          0 :         if (hw->addr_ctrl.mta_in_use > 0) {
     925                 :            :                 u32 psrctl = rd32(hw, TXGBE_PSRCTL);
     926                 :          0 :                 psrctl &= ~(TXGBE_PSRCTL_ADHF12_MASK | TXGBE_PSRCTL_MCHFENA);
     927                 :          0 :                 psrctl |= TXGBE_PSRCTL_MCHFENA |
     928                 :          0 :                          TXGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
     929                 :            :                 wr32(hw, TXGBE_PSRCTL, psrctl);
     930                 :            :         }
     931                 :            : 
     932                 :          0 :         DEBUGOUT("txgbe update mc addr list complete");
     933                 :          0 :         return 0;
     934                 :            : }
     935                 :            : 
     936                 :            : /**
     937                 :            :  *  txgbe_fc_enable - Enable flow control
     938                 :            :  *  @hw: pointer to hardware structure
     939                 :            :  *
     940                 :            :  *  Enable flow control according to the current settings.
     941                 :            :  **/
     942                 :          0 : s32 txgbe_fc_enable(struct txgbe_hw *hw)
     943                 :            : {
     944                 :            :         s32 err = 0;
     945                 :            :         u32 mflcn_reg, fccfg_reg;
     946                 :            :         u32 pause_time;
     947                 :            :         u32 fcrtl, fcrth;
     948                 :            :         int i;
     949                 :            : 
     950                 :            :         /* Validate the water mark configuration */
     951         [ #  # ]:          0 :         if (!hw->fc.pause_time) {
     952                 :            :                 err = TXGBE_ERR_INVALID_LINK_SETTINGS;
     953                 :          0 :                 goto out;
     954                 :            :         }
     955                 :            : 
     956                 :            :         /* Low water mark of zero causes XOFF floods */
     957         [ #  # ]:          0 :         for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
     958         [ #  # ]:          0 :                 if ((hw->fc.current_mode & txgbe_fc_tx_pause) &&
     959         [ #  # ]:          0 :                     hw->fc.high_water[i]) {
     960   [ #  #  #  # ]:          0 :                         if (!hw->fc.low_water[i] ||
     961                 :            :                             hw->fc.low_water[i] >= hw->fc.high_water[i]) {
     962                 :          0 :                                 DEBUGOUT("Invalid water mark configuration");
     963                 :            :                                 err = TXGBE_ERR_INVALID_LINK_SETTINGS;
     964                 :          0 :                                 goto out;
     965                 :            :                         }
     966                 :            :                 }
     967                 :            :         }
     968                 :            : 
     969                 :            :         /* Negotiate the fc mode to use */
     970                 :          0 :         hw->mac.fc_autoneg(hw);
     971                 :            : 
     972                 :            :         /* Disable any previous flow control settings */
     973                 :            :         mflcn_reg = rd32(hw, TXGBE_RXFCCFG);
     974                 :          0 :         mflcn_reg &= ~(TXGBE_RXFCCFG_FC | TXGBE_RXFCCFG_PFC);
     975                 :            : 
     976                 :            :         fccfg_reg = rd32(hw, TXGBE_TXFCCFG);
     977                 :          0 :         fccfg_reg &= ~(TXGBE_TXFCCFG_FC | TXGBE_TXFCCFG_PFC);
     978                 :            : 
     979                 :            :         /*
     980                 :            :          * The possible values of fc.current_mode are:
     981                 :            :          * 0: Flow control is completely disabled
     982                 :            :          * 1: Rx flow control is enabled (we can receive pause frames,
     983                 :            :          *    but not send pause frames).
     984                 :            :          * 2: Tx flow control is enabled (we can send pause frames but
     985                 :            :          *    we do not support receiving pause frames).
     986                 :            :          * 3: Both Rx and Tx flow control (symmetric) are enabled.
     987                 :            :          * other: Invalid.
     988                 :            :          */
     989   [ #  #  #  #  :          0 :         switch (hw->fc.current_mode) {
                      # ]
     990                 :            :         case txgbe_fc_none:
     991                 :            :                 /*
     992                 :            :                  * Flow control is disabled by software override or autoneg.
     993                 :            :                  * The code below will actually disable it in the HW.
     994                 :            :                  */
     995                 :            :                 break;
     996                 :          0 :         case txgbe_fc_rx_pause:
     997                 :            :                 /*
     998                 :            :                  * Rx Flow control is enabled and Tx Flow control is
     999                 :            :                  * disabled by software override. Since there really
    1000                 :            :                  * isn't a way to advertise that we are capable of RX
    1001                 :            :                  * Pause ONLY, we will advertise that we support both
    1002                 :            :                  * symmetric and asymmetric Rx PAUSE.  Later, we will
    1003                 :            :                  * disable the adapter's ability to send PAUSE frames.
    1004                 :            :                  */
    1005                 :          0 :                 mflcn_reg |= TXGBE_RXFCCFG_FC;
    1006                 :          0 :                 break;
    1007                 :          0 :         case txgbe_fc_tx_pause:
    1008                 :            :                 /*
    1009                 :            :                  * Tx Flow control is enabled, and Rx Flow control is
    1010                 :            :                  * disabled by software override.
    1011                 :            :                  */
    1012                 :          0 :                 fccfg_reg |= TXGBE_TXFCCFG_FC;
    1013                 :          0 :                 break;
    1014                 :          0 :         case txgbe_fc_full:
    1015                 :            :                 /* Flow control (both Rx and Tx) is enabled by SW override. */
    1016                 :          0 :                 mflcn_reg |= TXGBE_RXFCCFG_FC;
    1017                 :          0 :                 fccfg_reg |= TXGBE_TXFCCFG_FC;
    1018                 :          0 :                 break;
    1019                 :          0 :         default:
    1020                 :          0 :                 DEBUGOUT("Flow control param set incorrectly");
    1021                 :            :                 err = TXGBE_ERR_CONFIG;
    1022                 :          0 :                 goto out;
    1023                 :            :         }
    1024                 :            : 
    1025                 :            :         /* Set 802.3x based flow control settings. */
    1026                 :            :         wr32(hw, TXGBE_RXFCCFG, mflcn_reg);
    1027                 :            :         wr32(hw, TXGBE_TXFCCFG, fccfg_reg);
    1028                 :            : 
    1029                 :            :         /* Set up and enable Rx high/low water mark thresholds, enable XON. */
    1030         [ #  # ]:          0 :         for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
    1031         [ #  # ]:          0 :                 if ((hw->fc.current_mode & txgbe_fc_tx_pause) &&
    1032         [ #  # ]:          0 :                     hw->fc.high_water[i]) {
    1033                 :          0 :                         fcrtl = TXGBE_FCWTRLO_TH(hw->fc.low_water[i]) |
    1034                 :            :                                 TXGBE_FCWTRLO_XON;
    1035                 :          0 :                         fcrth = TXGBE_FCWTRHI_TH(hw->fc.high_water[i]) |
    1036                 :            :                                 TXGBE_FCWTRHI_XOFF;
    1037                 :            :                 } else {
    1038                 :            :                         /*
    1039                 :            :                          * In order to prevent Tx hangs when the internal Tx
    1040                 :            :                          * switch is enabled we must set the high water mark
    1041                 :            :                          * to the Rx packet buffer size - 24KB.  This allows
    1042                 :            :                          * the Tx switch to function even under heavy Rx
    1043                 :            :                          * workloads.
    1044                 :            :                          */
    1045                 :            :                         fcrtl = 0;
    1046                 :          0 :                         fcrth = rd32(hw, TXGBE_PBRXSIZE(i)) - 24576;
    1047                 :            :                 }
    1048                 :          0 :                 wr32(hw, TXGBE_FCWTRLO(i), fcrtl);
    1049                 :          0 :                 wr32(hw, TXGBE_FCWTRHI(i), fcrth);
    1050                 :            :         }
    1051                 :            : 
    1052                 :            :         /* Configure pause time (2 TCs per register) */
    1053                 :          0 :         pause_time = TXGBE_RXFCFSH_TIME(hw->fc.pause_time);
    1054         [ #  # ]:          0 :         for (i = 0; i < (TXGBE_DCB_TC_MAX / 2); i++)
    1055                 :          0 :                 wr32(hw, TXGBE_FCXOFFTM(i), pause_time * 0x00010001);
    1056                 :            : 
    1057                 :            :         /* Configure flow control refresh threshold value */
    1058                 :          0 :         wr32(hw, TXGBE_RXFCRFSH, hw->fc.pause_time / 2);
    1059                 :            : 
    1060                 :          0 : out:
    1061                 :          0 :         return err;
    1062                 :            : }
    1063                 :            : 
    1064                 :            : /**
    1065                 :            :  *  txgbe_negotiate_fc - Negotiate flow control
    1066                 :            :  *  @hw: pointer to hardware structure
    1067                 :            :  *  @adv_reg: flow control advertised settings
    1068                 :            :  *  @lp_reg: link partner's flow control settings
    1069                 :            :  *  @adv_sym: symmetric pause bit in advertisement
    1070                 :            :  *  @adv_asm: asymmetric pause bit in advertisement
    1071                 :            :  *  @lp_sym: symmetric pause bit in link partner advertisement
    1072                 :            :  *  @lp_asm: asymmetric pause bit in link partner advertisement
    1073                 :            :  *
    1074                 :            :  *  Find the intersection between advertised settings and link partner's
    1075                 :            :  *  advertised settings
    1076                 :            :  **/
    1077                 :          0 : s32 txgbe_negotiate_fc(struct txgbe_hw *hw, u32 adv_reg, u32 lp_reg,
    1078                 :            :                        u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
    1079                 :            : {
    1080         [ #  # ]:          0 :         if ((!(adv_reg)) ||  (!(lp_reg))) {
    1081                 :          0 :                 DEBUGOUT("Local or link partner's advertised flow control settings are NULL. Local: %x, link partner: %x",
    1082                 :            :                               adv_reg, lp_reg);
    1083                 :          0 :                 return TXGBE_ERR_FC_NOT_NEGOTIATED;
    1084                 :            :         }
    1085                 :            : 
    1086   [ #  #  #  # ]:          0 :         if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
    1087                 :            :                 /*
    1088                 :            :                  * Now we need to check if the user selected Rx ONLY
    1089                 :            :                  * of pause frames.  In this case, we had to advertise
    1090                 :            :                  * FULL flow control because we could not advertise RX
    1091                 :            :                  * ONLY. Hence, we must now check to see if we need to
    1092                 :            :                  * turn OFF the TRANSMISSION of PAUSE frames.
    1093                 :            :                  */
    1094         [ #  # ]:          0 :                 if (hw->fc.requested_mode == txgbe_fc_full) {
    1095                 :          0 :                         hw->fc.current_mode = txgbe_fc_full;
    1096                 :          0 :                         DEBUGOUT("Flow Control = FULL.");
    1097                 :            :                 } else {
    1098                 :          0 :                         hw->fc.current_mode = txgbe_fc_rx_pause;
    1099                 :          0 :                         DEBUGOUT("Flow Control=RX PAUSE frames only");
    1100                 :            :                 }
    1101   [ #  #  #  # ]:          0 :         } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
    1102   [ #  #  #  # ]:          0 :                    (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
    1103                 :          0 :                 hw->fc.current_mode = txgbe_fc_tx_pause;
    1104                 :          0 :                 DEBUGOUT("Flow Control = TX PAUSE frames only.");
    1105   [ #  #  #  # ]:          0 :         } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
    1106   [ #  #  #  # ]:          0 :                    !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
    1107                 :          0 :                 hw->fc.current_mode = txgbe_fc_rx_pause;
    1108                 :          0 :                 DEBUGOUT("Flow Control = RX PAUSE frames only.");
    1109                 :            :         } else {
    1110                 :          0 :                 hw->fc.current_mode = txgbe_fc_none;
    1111                 :          0 :                 DEBUGOUT("Flow Control = NONE.");
    1112                 :            :         }
    1113                 :            :         return 0;
    1114                 :            : }
    1115                 :            : 
    1116                 :            : /**
    1117                 :            :  *  txgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber
    1118                 :            :  *  @hw: pointer to hardware structure
    1119                 :            :  *
    1120                 :            :  *  Enable flow control according on 1 gig fiber.
    1121                 :            :  **/
    1122                 :          0 : STATIC s32 txgbe_fc_autoneg_fiber(struct txgbe_hw *hw)
    1123                 :            : {
    1124                 :            :         u32 pcs_anadv_reg, pcs_lpab_reg;
    1125                 :            :         s32 err = TXGBE_ERR_FC_NOT_NEGOTIATED;
    1126                 :            : 
    1127                 :            :         /*
    1128                 :            :          * On multispeed fiber at 1g, bail out if
    1129                 :            :          * - link is up but AN did not complete, or if
    1130                 :            :          * - link is up and AN completed but timed out
    1131                 :            :          */
    1132                 :            : 
    1133                 :            :         pcs_anadv_reg = rd32_epcs(hw, SR_MII_MMD_AN_ADV);
    1134                 :            :         pcs_lpab_reg = rd32_epcs(hw, SR_MII_MMD_LP_BABL);
    1135                 :            : 
    1136                 :          0 :         err =  txgbe_negotiate_fc(hw, pcs_anadv_reg,
    1137                 :            :                                       pcs_lpab_reg,
    1138                 :            :                                       SR_MII_MMD_AN_ADV_PAUSE_SYM,
    1139                 :            :                                       SR_MII_MMD_AN_ADV_PAUSE_ASM,
    1140                 :            :                                       SR_MII_MMD_AN_ADV_PAUSE_SYM,
    1141                 :            :                                       SR_MII_MMD_AN_ADV_PAUSE_ASM);
    1142                 :            : 
    1143                 :          0 :         return err;
    1144                 :            : }
    1145                 :            : 
    1146                 :            : /**
    1147                 :            :  *  txgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37
    1148                 :            :  *  @hw: pointer to hardware structure
    1149                 :            :  *
    1150                 :            :  *  Enable flow control according to IEEE clause 37.
    1151                 :            :  **/
    1152                 :          0 : STATIC s32 txgbe_fc_autoneg_backplane(struct txgbe_hw *hw)
    1153                 :            : {
    1154                 :            :         u32 anlp1_reg, autoc_reg;
    1155                 :            :         s32 err = TXGBE_ERR_FC_NOT_NEGOTIATED;
    1156                 :            : 
    1157                 :            :         /*
    1158                 :            :          * Read the 10g AN autoc and LP ability registers and resolve
    1159                 :            :          * local flow control settings accordingly
    1160                 :            :          */
    1161                 :            :         autoc_reg = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);
    1162                 :            :         anlp1_reg = rd32_epcs(hw, SR_AN_MMD_LP_ABL1);
    1163                 :            : 
    1164                 :          0 :         err = txgbe_negotiate_fc(hw, autoc_reg,
    1165                 :            :                 anlp1_reg,
    1166                 :            :                 SR_AN_MMD_ADV_REG1_PAUSE_SYM,
    1167                 :            :                 SR_AN_MMD_ADV_REG1_PAUSE_ASM,
    1168                 :            :                 SR_AN_MMD_ADV_REG1_PAUSE_SYM,
    1169                 :            :                 SR_AN_MMD_ADV_REG1_PAUSE_ASM);
    1170                 :            : 
    1171                 :          0 :         return err;
    1172                 :            : }
    1173                 :            : 
    1174                 :            : /**
    1175                 :            :  *  txgbe_fc_autoneg_copper - Enable flow control IEEE clause 37
    1176                 :            :  *  @hw: pointer to hardware structure
    1177                 :            :  *
    1178                 :            :  *  Enable flow control according to IEEE clause 37.
    1179                 :            :  **/
    1180                 :          0 : STATIC s32 txgbe_fc_autoneg_copper(struct txgbe_hw *hw)
    1181                 :            : {
    1182                 :          0 :         u16 technology_ability_reg = 0;
    1183                 :          0 :         u16 lp_technology_ability_reg = 0;
    1184                 :            : 
    1185                 :          0 :         hw->phy.read_reg(hw, TXGBE_MD_AUTO_NEG_ADVT,
    1186                 :            :                              TXGBE_MD_DEV_AUTO_NEG,
    1187                 :            :                              &technology_ability_reg);
    1188                 :          0 :         hw->phy.read_reg(hw, TXGBE_MD_AUTO_NEG_LP,
    1189                 :            :                              TXGBE_MD_DEV_AUTO_NEG,
    1190                 :            :                              &lp_technology_ability_reg);
    1191                 :            : 
    1192                 :          0 :         return txgbe_negotiate_fc(hw, (u32)technology_ability_reg,
    1193                 :            :                                   (u32)lp_technology_ability_reg,
    1194                 :            :                                   TXGBE_TAF_SYM_PAUSE, TXGBE_TAF_ASM_PAUSE,
    1195                 :            :                                   TXGBE_TAF_SYM_PAUSE, TXGBE_TAF_ASM_PAUSE);
    1196                 :            : }
    1197                 :            : 
    1198                 :            : /**
    1199                 :            :  *  txgbe_fc_autoneg - Configure flow control
    1200                 :            :  *  @hw: pointer to hardware structure
    1201                 :            :  *
    1202                 :            :  *  Compares our advertised flow control capabilities to those advertised by
    1203                 :            :  *  our link partner, and determines the proper flow control mode to use.
    1204                 :            :  **/
    1205                 :          0 : void txgbe_fc_autoneg(struct txgbe_hw *hw)
    1206                 :            : {
    1207                 :            :         s32 err = TXGBE_ERR_FC_NOT_NEGOTIATED;
    1208                 :            :         u32 speed;
    1209                 :            :         bool link_up;
    1210                 :            : 
    1211                 :            :         /*
    1212                 :            :          * AN should have completed when the cable was plugged in.
    1213                 :            :          * Look for reasons to bail out.  Bail out if:
    1214                 :            :          * - FC autoneg is disabled, or if
    1215                 :            :          * - link is not up.
    1216                 :            :          */
    1217         [ #  # ]:          0 :         if (hw->fc.disable_fc_autoneg) {
    1218                 :          0 :                 DEBUGOUT("Flow control autoneg is disabled");
    1219                 :          0 :                 goto out;
    1220                 :            :         }
    1221                 :            : 
    1222                 :          0 :         hw->mac.check_link(hw, &speed, &link_up, false);
    1223         [ #  # ]:          0 :         if (!link_up) {
    1224                 :          0 :                 DEBUGOUT("The link is down");
    1225                 :          0 :                 goto out;
    1226                 :            :         }
    1227                 :            : 
    1228   [ #  #  #  # ]:          0 :         switch (hw->phy.media_type) {
    1229                 :            :         /* Autoneg flow control on fiber adapters */
    1230                 :          0 :         case txgbe_media_type_fiber_qsfp:
    1231                 :            :         case txgbe_media_type_fiber:
    1232         [ #  # ]:          0 :                 if (speed == TXGBE_LINK_SPEED_1GB_FULL)
    1233                 :          0 :                         err = txgbe_fc_autoneg_fiber(hw);
    1234                 :            :                 break;
    1235                 :            : 
    1236                 :            :         /* Autoneg flow control on backplane adapters */
    1237                 :          0 :         case txgbe_media_type_backplane:
    1238                 :          0 :                 err = txgbe_fc_autoneg_backplane(hw);
    1239                 :          0 :                 break;
    1240                 :            : 
    1241                 :            :         /* Autoneg flow control on copper adapters */
    1242                 :          0 :         case txgbe_media_type_copper:
    1243         [ #  # ]:          0 :                 if (txgbe_device_supports_autoneg_fc(hw))
    1244                 :          0 :                         err = txgbe_fc_autoneg_copper(hw);
    1245                 :            :                 break;
    1246                 :            : 
    1247                 :            :         default:
    1248                 :            :                 break;
    1249                 :            :         }
    1250                 :            : 
    1251                 :          0 : out:
    1252         [ #  # ]:          0 :         if (err == 0) {
    1253                 :          0 :                 hw->fc.fc_was_autonegged = true;
    1254                 :            :         } else {
    1255                 :          0 :                 hw->fc.fc_was_autonegged = false;
    1256                 :          0 :                 hw->fc.current_mode = hw->fc.requested_mode;
    1257                 :            :         }
    1258                 :          0 : }
    1259                 :            : 
    1260                 :          0 : s32 txgbe_set_pcie_master(struct txgbe_hw *hw, bool enable)
    1261                 :            : {
    1262                 :          0 :         struct rte_pci_device *pci_dev = (struct rte_pci_device *)hw->back;
    1263                 :            :         s32 status = 0;
    1264                 :            :         u32 i;
    1265                 :            : 
    1266         [ #  # ]:          0 :         if (rte_pci_set_bus_master(pci_dev, enable) < 0) {
    1267                 :          0 :                 DEBUGOUT("Cannot configure PCI bus master.");
    1268                 :          0 :                 return -1;
    1269                 :            :         }
    1270                 :            : 
    1271         [ #  # ]:          0 :         if (enable)
    1272                 :          0 :                 goto out;
    1273                 :            : 
    1274                 :            :         /* Exit if master requests are blocked */
    1275         [ #  # ]:          0 :         if (!(rd32(hw, TXGBE_BMEPEND)))
    1276                 :          0 :                 goto out;
    1277                 :            : 
    1278                 :            :         /* Poll for master request bit to clear */
    1279         [ #  # ]:          0 :         for (i = 0; i < TXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
    1280                 :          0 :                 usec_delay(100);
    1281         [ #  # ]:          0 :                 if (!(rd32(hw, TXGBE_BMEPEND)))
    1282                 :          0 :                         goto out;
    1283                 :            :         }
    1284                 :            : 
    1285                 :          0 :         DEBUGOUT("PCIe transaction pending bit also did not clear.");
    1286                 :            :         status = TXGBE_ERR_MASTER_REQUESTS_PENDING;
    1287                 :            : 
    1288                 :            : out:
    1289                 :            :         return status;
    1290                 :            : }
    1291                 :            : 
    1292                 :            : /**
    1293                 :            :  *  txgbe_acquire_swfw_sync - Acquire SWFW semaphore
    1294                 :            :  *  @hw: pointer to hardware structure
    1295                 :            :  *  @mask: Mask to specify which semaphore to acquire
    1296                 :            :  *
    1297                 :            :  *  Acquires the SWFW semaphore through the MNGSEM register for the specified
    1298                 :            :  *  function (CSR, PHY0, PHY1, EEPROM, Flash)
    1299                 :            :  **/
    1300                 :          0 : s32 txgbe_acquire_swfw_sync(struct txgbe_hw *hw, u32 mask)
    1301                 :            : {
    1302                 :            :         u32 mngsem = 0;
    1303                 :          0 :         u32 swmask = TXGBE_MNGSEM_SW(mask);
    1304                 :          0 :         u32 fwmask = TXGBE_MNGSEM_FW(mask);
    1305                 :            :         u32 timeout = 200;
    1306                 :            :         u32 i;
    1307                 :            : 
    1308         [ #  # ]:          0 :         for (i = 0; i < timeout; i++) {
    1309                 :            :                 /*
    1310                 :            :                  * SW NVM semaphore bit is used for access to all
    1311                 :            :                  * SW_FW_SYNC bits (not just NVM)
    1312                 :            :                  */
    1313         [ #  # ]:          0 :                 if (txgbe_get_eeprom_semaphore(hw))
    1314                 :            :                         return TXGBE_ERR_SWFW_SYNC;
    1315                 :            : 
    1316                 :            :                 mngsem = rd32(hw, TXGBE_MNGSEM);
    1317         [ #  # ]:          0 :                 if (mngsem & (fwmask | swmask)) {
    1318                 :            :                         /* Resource is currently in use by FW or SW */
    1319                 :          0 :                         txgbe_release_eeprom_semaphore(hw);
    1320                 :            :                         msec_delay(5);
    1321                 :            :                 } else {
    1322                 :          0 :                         mngsem |= swmask;
    1323                 :            :                         wr32(hw, TXGBE_MNGSEM, mngsem);
    1324                 :          0 :                         txgbe_release_eeprom_semaphore(hw);
    1325                 :          0 :                         return 0;
    1326                 :            :                 }
    1327                 :            :         }
    1328                 :            : 
    1329                 :            :         /* If time expired clear the bits holding the lock and retry */
    1330         [ #  # ]:          0 :         if (mngsem & (fwmask | swmask))
    1331                 :          0 :                 txgbe_release_swfw_sync(hw, mngsem & (fwmask | swmask));
    1332                 :            : 
    1333                 :            :         msec_delay(5);
    1334                 :          0 :         return TXGBE_ERR_SWFW_SYNC;
    1335                 :            : }
    1336                 :            : 
    1337                 :            : /**
    1338                 :            :  *  txgbe_release_swfw_sync - Release SWFW semaphore
    1339                 :            :  *  @hw: pointer to hardware structure
    1340                 :            :  *  @mask: Mask to specify which semaphore to release
    1341                 :            :  *
    1342                 :            :  *  Releases the SWFW semaphore through the MNGSEM register for the specified
    1343                 :            :  *  function (CSR, PHY0, PHY1, EEPROM, Flash)
    1344                 :            :  **/
    1345                 :          0 : void txgbe_release_swfw_sync(struct txgbe_hw *hw, u32 mask)
    1346                 :            : {
    1347                 :            :         u32 mngsem;
    1348                 :            :         u32 swmask = mask;
    1349                 :            : 
    1350                 :          0 :         txgbe_get_eeprom_semaphore(hw);
    1351                 :            : 
    1352                 :            :         mngsem = rd32(hw, TXGBE_MNGSEM);
    1353                 :          0 :         mngsem &= ~swmask;
    1354                 :            :         wr32(hw, TXGBE_MNGSEM, mngsem);
    1355                 :            : 
    1356                 :          0 :         txgbe_release_eeprom_semaphore(hw);
    1357                 :          0 : }
    1358                 :            : 
    1359                 :            : /**
    1360                 :            :  *  txgbe_disable_sec_rx_path - Stops the receive data path
    1361                 :            :  *  @hw: pointer to hardware structure
    1362                 :            :  *
    1363                 :            :  *  Stops the receive data path and waits for the HW to internally empty
    1364                 :            :  *  the Rx security block
    1365                 :            :  **/
    1366                 :          0 : s32 txgbe_disable_sec_rx_path(struct txgbe_hw *hw)
    1367                 :            : {
    1368                 :            : #define TXGBE_MAX_SECRX_POLL 4000
    1369                 :            : 
    1370                 :            :         int i;
    1371                 :            :         u32 secrxreg;
    1372                 :            : 
    1373                 :            :         secrxreg = rd32(hw, TXGBE_SECRXCTL);
    1374                 :          0 :         secrxreg |= TXGBE_SECRXCTL_XDSA;
    1375                 :            :         wr32(hw, TXGBE_SECRXCTL, secrxreg);
    1376         [ #  # ]:          0 :         for (i = 0; i < TXGBE_MAX_SECRX_POLL; i++) {
    1377                 :            :                 secrxreg = rd32(hw, TXGBE_SECRXSTAT);
    1378         [ #  # ]:          0 :                 if (!(secrxreg & TXGBE_SECRXSTAT_RDY))
    1379                 :            :                         /* Use interrupt-safe sleep just in case */
    1380                 :          0 :                         usec_delay(10);
    1381                 :            :                 else
    1382                 :            :                         break;
    1383                 :            :         }
    1384                 :            : 
    1385                 :            :         /* For informational purposes only */
    1386         [ #  # ]:          0 :         if (i >= TXGBE_MAX_SECRX_POLL)
    1387                 :          0 :                 DEBUGOUT("Rx unit being enabled before security path fully disabled.  Continuing with init.");
    1388                 :            : 
    1389                 :          0 :         return 0;
    1390                 :            : }
    1391                 :            : 
    1392                 :            : /**
    1393                 :            :  *  txgbe_enable_sec_rx_path - Enables the receive data path
    1394                 :            :  *  @hw: pointer to hardware structure
    1395                 :            :  *
    1396                 :            :  *  Enables the receive data path.
    1397                 :            :  **/
    1398                 :          0 : s32 txgbe_enable_sec_rx_path(struct txgbe_hw *hw)
    1399                 :            : {
    1400                 :            :         u32 secrxreg;
    1401                 :            : 
    1402                 :            :         secrxreg = rd32(hw, TXGBE_SECRXCTL);
    1403                 :          0 :         secrxreg &= ~TXGBE_SECRXCTL_XDSA;
    1404                 :            :         wr32(hw, TXGBE_SECRXCTL, secrxreg);
    1405                 :            :         txgbe_flush(hw);
    1406                 :            : 
    1407                 :          0 :         return 0;
    1408                 :            : }
    1409                 :            : 
    1410                 :            : /**
    1411                 :            :  *  txgbe_disable_sec_tx_path - Stops the transmit data path
    1412                 :            :  *  @hw: pointer to hardware structure
    1413                 :            :  *
    1414                 :            :  *  Stops the transmit data path and waits for the HW to internally empty
    1415                 :            :  *  the Tx security block
    1416                 :            :  **/
    1417                 :          0 : int txgbe_disable_sec_tx_path(struct txgbe_hw *hw)
    1418                 :            : {
    1419                 :            : #define TXGBE_MAX_SECTX_POLL 40
    1420                 :            : 
    1421                 :            :         int i;
    1422                 :            :         u32 sectxreg;
    1423                 :            : 
    1424                 :            :         sectxreg = rd32(hw, TXGBE_SECTXCTL);
    1425                 :          0 :         sectxreg |= TXGBE_SECTXCTL_XDSA;
    1426                 :            :         wr32(hw, TXGBE_SECTXCTL, sectxreg);
    1427         [ #  # ]:          0 :         for (i = 0; i < TXGBE_MAX_SECTX_POLL; i++) {
    1428                 :            :                 sectxreg = rd32(hw, TXGBE_SECTXSTAT);
    1429         [ #  # ]:          0 :                 if (sectxreg & TXGBE_SECTXSTAT_RDY)
    1430                 :            :                         break;
    1431                 :            :                 /* Use interrupt-safe sleep just in case */
    1432                 :          0 :                 usec_delay(1000);
    1433                 :            :         }
    1434                 :            : 
    1435                 :            :         /* For informational purposes only */
    1436         [ #  # ]:          0 :         if (i >= TXGBE_MAX_SECTX_POLL)
    1437                 :          0 :                 DEBUGOUT("Tx unit being enabled before security path fully disabled.  Continuing with init.");
    1438                 :            : 
    1439                 :          0 :         return 0;
    1440                 :            : }
    1441                 :            : 
    1442                 :            : /**
    1443                 :            :  *  txgbe_enable_sec_tx_path - Enables the transmit data path
    1444                 :            :  *  @hw: pointer to hardware structure
    1445                 :            :  *
    1446                 :            :  *  Enables the transmit data path.
    1447                 :            :  **/
    1448                 :          0 : int txgbe_enable_sec_tx_path(struct txgbe_hw *hw)
    1449                 :            : {
    1450                 :            :         uint32_t sectxreg;
    1451                 :            : 
    1452                 :            :         sectxreg = rd32(hw, TXGBE_SECTXCTL);
    1453                 :          0 :         sectxreg &= ~TXGBE_SECTXCTL_XDSA;
    1454                 :            :         wr32(hw, TXGBE_SECTXCTL, sectxreg);
    1455                 :            :         txgbe_flush(hw);
    1456                 :            : 
    1457                 :          0 :         return 0;
    1458                 :            : }
    1459                 :            : 
    1460                 :            : /**
    1461                 :            :  *  txgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
    1462                 :            :  *  @hw: pointer to hardware structure
    1463                 :            :  *  @san_mac_offset: SAN MAC address offset
    1464                 :            :  *
    1465                 :            :  *  This function will read the EEPROM location for the SAN MAC address
    1466                 :            :  *  pointer, and returns the value at that location.  This is used in both
    1467                 :            :  *  get and set mac_addr routines.
    1468                 :            :  **/
    1469                 :          0 : static s32 txgbe_get_san_mac_addr_offset(struct txgbe_hw *hw,
    1470                 :            :                                          u16 *san_mac_offset)
    1471                 :            : {
    1472                 :            :         s32 err;
    1473                 :            : 
    1474                 :            :         /*
    1475                 :            :          * First read the EEPROM pointer to see if the MAC addresses are
    1476                 :            :          * available.
    1477                 :            :          */
    1478                 :          0 :         err = hw->rom.readw_sw(hw, TXGBE_SAN_MAC_ADDR_PTR,
    1479                 :            :                                       san_mac_offset);
    1480         [ #  # ]:          0 :         if (err) {
    1481                 :          0 :                 DEBUGOUT("eeprom at offset %d failed",
    1482                 :            :                          TXGBE_SAN_MAC_ADDR_PTR);
    1483                 :            :         }
    1484                 :            : 
    1485                 :          0 :         return err;
    1486                 :            : }
    1487                 :            : 
    1488                 :            : /**
    1489                 :            :  *  txgbe_get_san_mac_addr - SAN MAC address retrieval from the EEPROM
    1490                 :            :  *  @hw: pointer to hardware structure
    1491                 :            :  *  @san_mac_addr: SAN MAC address
    1492                 :            :  *
    1493                 :            :  *  Reads the SAN MAC address from the EEPROM, if it's available.  This is
    1494                 :            :  *  per-port, so set_lan_id() must be called before reading the addresses.
    1495                 :            :  *  set_lan_id() is called by identify_sfp(), but this cannot be relied
    1496                 :            :  *  upon for non-SFP connections, so we must call it here.
    1497                 :            :  **/
    1498                 :          0 : s32 txgbe_get_san_mac_addr(struct txgbe_hw *hw, u8 *san_mac_addr)
    1499                 :            : {
    1500                 :            :         u16 san_mac_data, san_mac_offset;
    1501                 :            :         u8 i;
    1502                 :            :         s32 err;
    1503                 :            : 
    1504                 :            :         /*
    1505                 :            :          * First read the EEPROM pointer to see if the MAC addresses are
    1506                 :            :          * available. If they're not, no point in calling set_lan_id() here.
    1507                 :            :          */
    1508                 :          0 :         err = txgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
    1509   [ #  #  #  #  :          0 :         if (err || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
                   #  # ]
    1510                 :          0 :                 goto san_mac_addr_out;
    1511                 :            : 
    1512                 :            :         /* apply the port offset to the address offset */
    1513         [ #  # ]:          0 :         (hw->bus.func) ? (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
    1514                 :            :                          (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
    1515         [ #  # ]:          0 :         for (i = 0; i < 3; i++) {
    1516                 :          0 :                 err = hw->rom.read16(hw, san_mac_offset,
    1517                 :            :                                               &san_mac_data);
    1518         [ #  # ]:          0 :                 if (err) {
    1519                 :          0 :                         DEBUGOUT("eeprom read at offset %d failed",
    1520                 :            :                                  san_mac_offset);
    1521                 :          0 :                         goto san_mac_addr_out;
    1522                 :            :                 }
    1523                 :          0 :                 san_mac_addr[i * 2] = (u8)(san_mac_data);
    1524                 :          0 :                 san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
    1525                 :          0 :                 san_mac_offset++;
    1526                 :            :         }
    1527                 :            :         return 0;
    1528                 :            : 
    1529                 :            : san_mac_addr_out:
    1530                 :            :         /*
    1531                 :            :          * No addresses available in this EEPROM.  It's not an
    1532                 :            :          * error though, so just wipe the local address and return.
    1533                 :            :          */
    1534         [ #  # ]:          0 :         for (i = 0; i < 6; i++)
    1535                 :          0 :                 san_mac_addr[i] = 0xFF;
    1536                 :            :         return 0;
    1537                 :            : }
    1538                 :            : 
    1539                 :            : /**
    1540                 :            :  *  txgbe_set_san_mac_addr - Write the SAN MAC address to the EEPROM
    1541                 :            :  *  @hw: pointer to hardware structure
    1542                 :            :  *  @san_mac_addr: SAN MAC address
    1543                 :            :  *
    1544                 :            :  *  Write a SAN MAC address to the EEPROM.
    1545                 :            :  **/
    1546                 :          0 : s32 txgbe_set_san_mac_addr(struct txgbe_hw *hw, u8 *san_mac_addr)
    1547                 :            : {
    1548                 :            :         s32 err;
    1549                 :            :         u16 san_mac_data, san_mac_offset;
    1550                 :            :         u8 i;
    1551                 :            : 
    1552                 :            :         /* Look for SAN mac address pointer.  If not defined, return */
    1553                 :          0 :         err = txgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
    1554   [ #  #  #  #  :          0 :         if (err || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
                   #  # ]
    1555                 :            :                 return TXGBE_ERR_NO_SAN_ADDR_PTR;
    1556                 :            : 
    1557                 :            :         /* Apply the port offset to the address offset */
    1558         [ #  # ]:          0 :         (hw->bus.func) ? (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
    1559                 :            :                          (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
    1560                 :            : 
    1561         [ #  # ]:          0 :         for (i = 0; i < 3; i++) {
    1562                 :          0 :                 san_mac_data = (u16)((u16)(san_mac_addr[i * 2 + 1]) << 8);
    1563                 :          0 :                 san_mac_data |= (u16)(san_mac_addr[i * 2]);
    1564                 :          0 :                 hw->rom.write16(hw, san_mac_offset, san_mac_data);
    1565                 :          0 :                 san_mac_offset++;
    1566                 :            :         }
    1567                 :            : 
    1568                 :            :         return 0;
    1569                 :            : }
    1570                 :            : 
    1571                 :            : /**
    1572                 :            :  *  txgbe_clear_vmdq - Disassociate a VMDq pool index from a rx address
    1573                 :            :  *  @hw: pointer to hardware struct
    1574                 :            :  *  @rar: receive address register index to disassociate
    1575                 :            :  *  @vmdq: VMDq pool index to remove from the rar
    1576                 :            :  **/
    1577                 :          0 : s32 txgbe_clear_vmdq(struct txgbe_hw *hw, u32 rar, u32 vmdq)
    1578                 :            : {
    1579                 :            :         u32 mpsar_lo, mpsar_hi;
    1580                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
    1581                 :            : 
    1582                 :            :         /* Make sure we are using a valid rar index range */
    1583         [ #  # ]:          0 :         if (rar >= rar_entries) {
    1584                 :          0 :                 DEBUGOUT("RAR index %d is out of range.", rar);
    1585                 :          0 :                 return TXGBE_ERR_INVALID_ARGUMENT;
    1586                 :            :         }
    1587                 :            : 
    1588                 :            :         wr32(hw, TXGBE_ETHADDRIDX, rar);
    1589                 :            :         mpsar_lo = rd32(hw, TXGBE_ETHADDRASSL);
    1590                 :            :         mpsar_hi = rd32(hw, TXGBE_ETHADDRASSH);
    1591                 :            : 
    1592                 :            :         if (TXGBE_REMOVED(hw->hw_addr))
    1593                 :            :                 goto done;
    1594                 :            : 
    1595         [ #  # ]:          0 :         if (!mpsar_lo && !mpsar_hi)
    1596                 :          0 :                 goto done;
    1597                 :            : 
    1598         [ #  # ]:          0 :         if (vmdq == BIT_MASK32) {
    1599         [ #  # ]:          0 :                 if (mpsar_lo) {
    1600                 :            :                         wr32(hw, TXGBE_ETHADDRASSL, 0);
    1601                 :            :                         mpsar_lo = 0;
    1602                 :            :                 }
    1603         [ #  # ]:          0 :                 if (mpsar_hi) {
    1604                 :            :                         wr32(hw, TXGBE_ETHADDRASSH, 0);
    1605                 :            :                         mpsar_hi = 0;
    1606                 :            :                 }
    1607         [ #  # ]:          0 :         } else if (vmdq < 32) {
    1608                 :          0 :                 mpsar_lo &= ~(1 << vmdq);
    1609                 :            :                 wr32(hw, TXGBE_ETHADDRASSL, mpsar_lo);
    1610                 :            :         } else {
    1611                 :          0 :                 mpsar_hi &= ~(1 << (vmdq - 32));
    1612                 :            :                 wr32(hw, TXGBE_ETHADDRASSH, mpsar_hi);
    1613                 :            :         }
    1614                 :            : 
    1615                 :            :         /* was that the last pool using this rar? */
    1616   [ #  #  #  # ]:          0 :         if (mpsar_lo == 0 && mpsar_hi == 0 &&
    1617         [ #  # ]:          0 :             rar != 0 && rar != hw->mac.san_mac_rar_index)
    1618                 :          0 :                 hw->mac.clear_rar(hw, rar);
    1619                 :          0 : done:
    1620                 :            :         return 0;
    1621                 :            : }
    1622                 :            : 
    1623                 :            : /**
    1624                 :            :  *  txgbe_set_vmdq - Associate a VMDq pool index with a rx address
    1625                 :            :  *  @hw: pointer to hardware struct
    1626                 :            :  *  @rar: receive address register index to associate with a VMDq index
    1627                 :            :  *  @vmdq: VMDq pool index
    1628                 :            :  **/
    1629                 :          0 : s32 txgbe_set_vmdq(struct txgbe_hw *hw, u32 rar, u32 vmdq)
    1630                 :            : {
    1631                 :            :         u32 mpsar;
    1632                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
    1633                 :            : 
    1634                 :            :         /* Make sure we are using a valid rar index range */
    1635         [ #  # ]:          0 :         if (rar >= rar_entries) {
    1636                 :          0 :                 DEBUGOUT("RAR index %d is out of range.", rar);
    1637                 :          0 :                 return TXGBE_ERR_INVALID_ARGUMENT;
    1638                 :            :         }
    1639                 :            : 
    1640                 :            :         wr32(hw, TXGBE_ETHADDRIDX, rar);
    1641         [ #  # ]:          0 :         if (vmdq < 32) {
    1642                 :            :                 mpsar = rd32(hw, TXGBE_ETHADDRASSL);
    1643                 :          0 :                 mpsar |= 1 << vmdq;
    1644                 :            :                 wr32(hw, TXGBE_ETHADDRASSL, mpsar);
    1645                 :            :         } else {
    1646                 :            :                 mpsar = rd32(hw, TXGBE_ETHADDRASSH);
    1647                 :          0 :                 mpsar |= 1 << (vmdq - 32);
    1648                 :            :                 wr32(hw, TXGBE_ETHADDRASSH, mpsar);
    1649                 :            :         }
    1650                 :            :         return 0;
    1651                 :            : }
    1652                 :            : 
    1653                 :            : /**
    1654                 :            :  *  txgbe_init_uta_tables - Initialize the Unicast Table Array
    1655                 :            :  *  @hw: pointer to hardware structure
    1656                 :            :  **/
    1657                 :          0 : s32 txgbe_init_uta_tables(struct txgbe_hw *hw)
    1658                 :            : {
    1659                 :            :         int i;
    1660                 :            : 
    1661                 :          0 :         DEBUGOUT(" Clearing UTA");
    1662                 :            : 
    1663         [ #  # ]:          0 :         for (i = 0; i < 128; i++)
    1664                 :          0 :                 wr32(hw, TXGBE_UCADDRTBL(i), 0);
    1665                 :            : 
    1666                 :          0 :         return 0;
    1667                 :            : }
    1668                 :            : 
    1669                 :            : /**
    1670                 :            :  *  txgbe_find_vlvf_slot - find the vlanid or the first empty slot
    1671                 :            :  *  @hw: pointer to hardware structure
    1672                 :            :  *  @vlan: VLAN id to write to VLAN filter
    1673                 :            :  *  @vlvf_bypass: true to find vlanid only, false returns first empty slot if
    1674                 :            :  *                vlanid not found
    1675                 :            :  *
    1676                 :            :  *
    1677                 :            :  *  return the VLVF index where this VLAN id should be placed
    1678                 :            :  *
    1679                 :            :  **/
    1680                 :          0 : s32 txgbe_find_vlvf_slot(struct txgbe_hw *hw, u32 vlan, bool vlvf_bypass)
    1681                 :            : {
    1682                 :            :         s32 regindex, first_empty_slot;
    1683                 :            :         u32 bits;
    1684                 :            : 
    1685                 :            :         /* short cut the special case */
    1686         [ #  # ]:          0 :         if (vlan == 0)
    1687                 :            :                 return 0;
    1688                 :            : 
    1689                 :            :         /* if vlvf_bypass is set we don't want to use an empty slot, we
    1690                 :            :          * will simply bypass the VLVF if there are no entries present in the
    1691                 :            :          * VLVF that contain our VLAN
    1692                 :            :          */
    1693         [ #  # ]:          0 :         first_empty_slot = vlvf_bypass ? TXGBE_ERR_NO_SPACE : 0;
    1694                 :            : 
    1695                 :            :         /* add VLAN enable bit for comparison */
    1696                 :          0 :         vlan |= TXGBE_PSRVLAN_EA;
    1697                 :            : 
    1698                 :            :         /* Search for the vlan id in the VLVF entries. Save off the first empty
    1699                 :            :          * slot found along the way.
    1700                 :            :          *
    1701                 :            :          * pre-decrement loop covering (TXGBE_NUM_POOL - 1) .. 1
    1702                 :            :          */
    1703         [ #  # ]:          0 :         for (regindex = TXGBE_NUM_POOL; --regindex;) {
    1704                 :          0 :                 wr32(hw, TXGBE_PSRVLANIDX, regindex);
    1705                 :            :                 bits = rd32(hw, TXGBE_PSRVLAN);
    1706         [ #  # ]:          0 :                 if (bits == vlan)
    1707                 :          0 :                         return regindex;
    1708         [ #  # ]:          0 :                 if (!first_empty_slot && !bits)
    1709                 :            :                         first_empty_slot = regindex;
    1710                 :            :         }
    1711                 :            : 
    1712                 :            :         /* If we are here then we didn't find the VLAN.  Return first empty
    1713                 :            :          * slot we found during our search, else error.
    1714                 :            :          */
    1715         [ #  # ]:          0 :         if (!first_empty_slot)
    1716                 :          0 :                 DEBUGOUT("No space in VLVF.");
    1717                 :            : 
    1718         [ #  # ]:          0 :         return first_empty_slot ? first_empty_slot : TXGBE_ERR_NO_SPACE;
    1719                 :            : }
    1720                 :            : 
    1721                 :            : /**
    1722                 :            :  *  txgbe_set_vfta - Set VLAN filter table
    1723                 :            :  *  @hw: pointer to hardware structure
    1724                 :            :  *  @vlan: VLAN id to write to VLAN filter
    1725                 :            :  *  @vind: VMDq output index that maps queue to VLAN id in VLVFB
    1726                 :            :  *  @vlan_on: boolean flag to turn on/off VLAN
    1727                 :            :  *  @vlvf_bypass: boolean flag indicating updating default pool is okay
    1728                 :            :  *
    1729                 :            :  *  Turn on/off specified VLAN in the VLAN filter table.
    1730                 :            :  **/
    1731                 :          0 : s32 txgbe_set_vfta(struct txgbe_hw *hw, u32 vlan, u32 vind,
    1732                 :            :                            bool vlan_on, bool vlvf_bypass)
    1733                 :            : {
    1734                 :            :         u32 regidx, vfta_delta, vfta;
    1735                 :            :         s32 err;
    1736                 :            : 
    1737         [ #  # ]:          0 :         if (vlan > 4095 || vind > 63)
    1738                 :            :                 return TXGBE_ERR_PARAM;
    1739                 :            : 
    1740                 :            :         /*
    1741                 :            :          * this is a 2 part operation - first the VFTA, then the
    1742                 :            :          * VLVF and VLVFB if VT Mode is set
    1743                 :            :          * We don't write the VFTA until we know the VLVF part succeeded.
    1744                 :            :          */
    1745                 :            : 
    1746                 :            :         /* Part 1
    1747                 :            :          * The VFTA is a bitstring made up of 128 32-bit registers
    1748                 :            :          * that enable the particular VLAN id, much like the MTA:
    1749                 :            :          *    bits[11-5]: which register
    1750                 :            :          *    bits[4-0]:  which bit in the register
    1751                 :            :          */
    1752                 :          0 :         regidx = vlan / 32;
    1753                 :          0 :         vfta_delta = 1 << (vlan % 32);
    1754                 :          0 :         vfta = rd32(hw, TXGBE_VLANTBL(regidx));
    1755                 :            : 
    1756                 :            :         /*
    1757                 :            :          * vfta_delta represents the difference between the current value
    1758                 :            :          * of vfta and the value we want in the register.  Since the diff
    1759                 :            :          * is an XOR mask we can just update the vfta using an XOR
    1760                 :            :          */
    1761         [ #  # ]:          0 :         vfta_delta &= vlan_on ? ~vfta : vfta;
    1762                 :          0 :         vfta ^= vfta_delta;
    1763                 :            : 
    1764                 :            :         /* Part 2
    1765                 :            :          * Call txgbe_set_vlvf to set VLVFB and VLVF
    1766                 :            :          */
    1767                 :          0 :         err = txgbe_set_vlvf(hw, vlan, vind, vlan_on, &vfta_delta,
    1768                 :            :                                          vfta, vlvf_bypass);
    1769         [ #  # ]:          0 :         if (err != 0) {
    1770         [ #  # ]:          0 :                 if (vlvf_bypass)
    1771                 :          0 :                         goto vfta_update;
    1772                 :            :                 return err;
    1773                 :            :         }
    1774                 :            : 
    1775                 :          0 : vfta_update:
    1776                 :            :         /* Update VFTA now that we are ready for traffic */
    1777         [ #  # ]:          0 :         if (vfta_delta)
    1778                 :            :                 wr32(hw, TXGBE_VLANTBL(regidx), vfta);
    1779                 :            : 
    1780                 :            :         return 0;
    1781                 :            : }
    1782                 :            : 
    1783                 :            : /**
    1784                 :            :  *  txgbe_set_vlvf - Set VLAN Pool Filter
    1785                 :            :  *  @hw: pointer to hardware structure
    1786                 :            :  *  @vlan: VLAN id to write to VLAN filter
    1787                 :            :  *  @vind: VMDq output index that maps queue to VLAN id in PSRVLANPLM
    1788                 :            :  *  @vlan_on: boolean flag to turn on/off VLAN in PSRVLAN
    1789                 :            :  *  @vfta_delta: pointer to the difference between the current value
    1790                 :            :  *               of PSRVLANPLM and the desired value
    1791                 :            :  *  @vfta: the desired value of the VFTA
    1792                 :            :  *  @vlvf_bypass: boolean flag indicating updating default pool is okay
    1793                 :            :  *
    1794                 :            :  *  Turn on/off specified bit in VLVF table.
    1795                 :            :  **/
    1796                 :          0 : s32 txgbe_set_vlvf(struct txgbe_hw *hw, u32 vlan, u32 vind,
    1797                 :            :                            bool vlan_on, u32 *vfta_delta, u32 vfta,
    1798                 :            :                            bool vlvf_bypass)
    1799                 :            : {
    1800                 :            :         u32 bits;
    1801                 :            :         u32 portctl;
    1802                 :            :         s32 vlvf_index;
    1803                 :            : 
    1804         [ #  # ]:          0 :         if (vlan > 4095 || vind > 63)
    1805                 :            :                 return TXGBE_ERR_PARAM;
    1806                 :            : 
    1807                 :            :         /* If VT Mode is set
    1808                 :            :          *   Either vlan_on
    1809                 :            :          *     make sure the vlan is in PSRVLAN
    1810                 :            :          *     set the vind bit in the matching PSRVLANPLM
    1811                 :            :          *   Or !vlan_on
    1812                 :            :          *     clear the pool bit and possibly the vind
    1813                 :            :          */
    1814                 :            :         portctl = rd32(hw, TXGBE_PORTCTL);
    1815         [ #  # ]:          0 :         if (!(portctl & TXGBE_PORTCTL_NUMVT_MASK))
    1816                 :            :                 return 0;
    1817                 :            : 
    1818                 :          0 :         vlvf_index = txgbe_find_vlvf_slot(hw, vlan, vlvf_bypass);
    1819         [ #  # ]:          0 :         if (vlvf_index < 0)
    1820                 :            :                 return vlvf_index;
    1821                 :            : 
    1822                 :          0 :         wr32(hw, TXGBE_PSRVLANIDX, vlvf_index);
    1823                 :          0 :         bits = rd32(hw, TXGBE_PSRVLANPLM(vind / 32));
    1824                 :            : 
    1825                 :            :         /* set the pool bit */
    1826                 :          0 :         bits |= 1 << (vind % 32);
    1827         [ #  # ]:          0 :         if (vlan_on)
    1828                 :          0 :                 goto vlvf_update;
    1829                 :            : 
    1830                 :            :         /* clear the pool bit */
    1831                 :          0 :         bits ^= 1 << (vind % 32);
    1832                 :            : 
    1833   [ #  #  #  # ]:          0 :         if (!bits &&
    1834                 :            :             !rd32(hw, TXGBE_PSRVLANPLM(vind / 32))) {
    1835                 :            :                 /* Clear PSRVLANPLM first, then disable PSRVLAN. Otherwise
    1836                 :            :                  * we run the risk of stray packets leaking into
    1837                 :            :                  * the PF via the default pool
    1838                 :            :                  */
    1839         [ #  # ]:          0 :                 if (*vfta_delta)
    1840                 :          0 :                         wr32(hw, TXGBE_PSRVLANPLM(vlan / 32), vfta);
    1841                 :            : 
    1842                 :            :                 /* disable VLVF and clear remaining bit from pool */
    1843                 :            :                 wr32(hw, TXGBE_PSRVLAN, 0);
    1844                 :            :                 wr32(hw, TXGBE_PSRVLANPLM(vind / 32), 0);
    1845                 :            : 
    1846                 :          0 :                 return 0;
    1847                 :            :         }
    1848                 :            : 
    1849                 :            :         /* If there are still bits set in the PSRVLANPLM registers
    1850                 :            :          * for the VLAN ID indicated we need to see if the
    1851                 :            :          * caller is requesting that we clear the PSRVLANPLM entry bit.
    1852                 :            :          * If the caller has requested that we clear the PSRVLANPLM
    1853                 :            :          * entry bit but there are still pools/VFs using this VLAN
    1854                 :            :          * ID entry then ignore the request.  We're not worried
    1855                 :            :          * about the case where we're turning the PSRVLANPLM VLAN ID
    1856                 :            :          * entry bit on, only when requested to turn it off as
    1857                 :            :          * there may be multiple pools and/or VFs using the
    1858                 :            :          * VLAN ID entry.  In that case we cannot clear the
    1859                 :            :          * PSRVLANPLM bit until all pools/VFs using that VLAN ID have also
    1860                 :            :          * been cleared.  This will be indicated by "bits" being
    1861                 :            :          * zero.
    1862                 :            :          */
    1863                 :          0 :         *vfta_delta = 0;
    1864                 :            : 
    1865                 :          0 : vlvf_update:
    1866                 :            :         /* record pool change and enable VLAN ID if not already enabled */
    1867                 :            :         wr32(hw, TXGBE_PSRVLANPLM(vind / 32), bits);
    1868                 :          0 :         wr32(hw, TXGBE_PSRVLAN, TXGBE_PSRVLAN_EA | vlan);
    1869                 :            : 
    1870                 :          0 :         return 0;
    1871                 :            : }
    1872                 :            : 
    1873                 :            : /**
    1874                 :            :  *  txgbe_clear_vfta - Clear VLAN filter table
    1875                 :            :  *  @hw: pointer to hardware structure
    1876                 :            :  *
    1877                 :            :  *  Clears the VLAN filer table, and the VMDq index associated with the filter
    1878                 :            :  **/
    1879                 :          0 : s32 txgbe_clear_vfta(struct txgbe_hw *hw)
    1880                 :            : {
    1881                 :            :         u32 offset;
    1882                 :            : 
    1883         [ #  # ]:          0 :         for (offset = 0; offset < hw->mac.vft_size; offset++)
    1884                 :          0 :                 wr32(hw, TXGBE_VLANTBL(offset), 0);
    1885                 :            : 
    1886         [ #  # ]:          0 :         for (offset = 0; offset < TXGBE_NUM_POOL; offset++) {
    1887                 :            :                 wr32(hw, TXGBE_PSRVLANIDX, offset);
    1888                 :            :                 wr32(hw, TXGBE_PSRVLAN, 0);
    1889                 :            :                 wr32(hw, TXGBE_PSRVLANPLM(0), 0);
    1890                 :            :                 wr32(hw, TXGBE_PSRVLANPLM(1), 0);
    1891                 :            :         }
    1892                 :            : 
    1893                 :          0 :         return 0;
    1894                 :            : }
    1895                 :            : 
    1896                 :            : /**
    1897                 :            :  *  txgbe_need_crosstalk_fix - Determine if we need to do cross talk fix
    1898                 :            :  *  @hw: pointer to hardware structure
    1899                 :            :  *
    1900                 :            :  *  Contains the logic to identify if we need to verify link for the
    1901                 :            :  *  crosstalk fix
    1902                 :            :  **/
    1903                 :            : static bool txgbe_need_crosstalk_fix(struct txgbe_hw *hw)
    1904                 :            : {
    1905                 :            :         /* Does FW say we need the fix */
    1906                 :          0 :         if (!hw->need_crosstalk_fix)
    1907                 :            :                 return false;
    1908                 :            : 
    1909                 :            :         /* Only consider SFP+ PHYs i.e. media type fiber */
    1910         [ #  # ]:          0 :         switch (hw->phy.media_type) {
    1911                 :            :         case txgbe_media_type_fiber:
    1912                 :            :         case txgbe_media_type_fiber_qsfp:
    1913                 :            :                 break;
    1914                 :            :         default:
    1915                 :            :                 return false;
    1916                 :            :         }
    1917                 :            : 
    1918                 :            :         return true;
    1919                 :            : }
    1920                 :            : 
    1921                 :            : /**
    1922                 :            :  *  txgbe_check_mac_link - Determine link and speed status
    1923                 :            :  *  @hw: pointer to hardware structure
    1924                 :            :  *  @speed: pointer to link speed
    1925                 :            :  *  @link_up: true when link is up
    1926                 :            :  *  @link_up_wait_to_complete: bool used to wait for link up or not
    1927                 :            :  *
    1928                 :            :  *  Reads the links register to determine if link is up and the current speed
    1929                 :            :  **/
    1930         [ #  # ]:          0 : s32 txgbe_check_mac_link_sp(struct txgbe_hw *hw, u32 *speed,
    1931                 :            :                                  bool *link_up, bool link_up_wait_to_complete)
    1932                 :            : {
    1933                 :            :         u32 links_reg, links_orig;
    1934                 :            :         u32 i;
    1935                 :            : 
    1936                 :            :         /* If Crosstalk fix enabled do the sanity check of making sure
    1937                 :            :          * the SFP+ cage is full.
    1938                 :            :          */
    1939                 :            :         if (txgbe_need_crosstalk_fix(hw)) {
    1940                 :            :                 u32 sfp_cage_full;
    1941                 :            : 
    1942         [ #  # ]:          0 :                 switch (hw->mac.type) {
    1943                 :            :                 case txgbe_mac_sp:
    1944                 :          0 :                         sfp_cage_full = !rd32m(hw, TXGBE_GPIODATA,
    1945                 :            :                                         TXGBE_GPIOBIT_2);
    1946                 :            :                         break;
    1947                 :            :                 default:
    1948                 :            :                         /* sanity check - No SFP+ devices here */
    1949                 :            :                         sfp_cage_full = false;
    1950                 :            :                         break;
    1951                 :            :                 }
    1952                 :            : 
    1953         [ #  # ]:          0 :                 if (!sfp_cage_full) {
    1954                 :          0 :                         *link_up = false;
    1955                 :          0 :                         *speed = TXGBE_LINK_SPEED_UNKNOWN;
    1956                 :          0 :                         return 0;
    1957                 :            :                 }
    1958                 :            :         }
    1959                 :            : 
    1960                 :            :         /* clear the old state */
    1961                 :            :         links_orig = rd32(hw, TXGBE_PORTSTAT);
    1962                 :            : 
    1963                 :            :         links_reg = rd32(hw, TXGBE_PORTSTAT);
    1964                 :            : 
    1965         [ #  # ]:          0 :         if (links_orig != links_reg) {
    1966                 :          0 :                 DEBUGOUT("LINKS changed from %08X to %08X",
    1967                 :            :                           links_orig, links_reg);
    1968                 :            :         }
    1969                 :            : 
    1970         [ #  # ]:          0 :         if (link_up_wait_to_complete) {
    1971         [ #  # ]:          0 :                 for (i = 0; i < hw->mac.max_link_up_time; i++) {
    1972         [ #  # ]:          0 :                         if (!(links_reg & TXGBE_PORTSTAT_UP)) {
    1973                 :          0 :                                 *link_up = false;
    1974                 :            :                         } else {
    1975                 :          0 :                                 *link_up = true;
    1976                 :          0 :                                 break;
    1977                 :            :                         }
    1978                 :            :                         msec_delay(100);
    1979                 :            :                         links_reg = rd32(hw, TXGBE_PORTSTAT);
    1980                 :            :                 }
    1981                 :            :         } else {
    1982         [ #  # ]:          0 :                 if (links_reg & TXGBE_PORTSTAT_UP)
    1983                 :          0 :                         *link_up = true;
    1984                 :            :                 else
    1985                 :          0 :                         *link_up = false;
    1986                 :            :         }
    1987                 :            : 
    1988   [ #  #  #  # ]:          0 :         switch (links_reg & TXGBE_PORTSTAT_BW_MASK) {
    1989                 :          0 :         case TXGBE_PORTSTAT_BW_10G:
    1990                 :          0 :                 *speed = TXGBE_LINK_SPEED_10GB_FULL;
    1991                 :          0 :                 break;
    1992                 :          0 :         case TXGBE_PORTSTAT_BW_1G:
    1993                 :          0 :                 *speed = TXGBE_LINK_SPEED_1GB_FULL;
    1994                 :          0 :                 break;
    1995                 :          0 :         case TXGBE_PORTSTAT_BW_100M:
    1996                 :          0 :                 *speed = TXGBE_LINK_SPEED_100M_FULL;
    1997                 :          0 :                 break;
    1998                 :          0 :         default:
    1999                 :          0 :                 *speed = TXGBE_LINK_SPEED_UNKNOWN;
    2000                 :            :         }
    2001                 :            : 
    2002                 :            :         return 0;
    2003                 :            : }
    2004                 :            : 
    2005                 :            : /**
    2006                 :            :  *  txgbe_get_wwn_prefix - Get alternative WWNN/WWPN prefix from
    2007                 :            :  *  the EEPROM
    2008                 :            :  *  @hw: pointer to hardware structure
    2009                 :            :  *  @wwnn_prefix: the alternative WWNN prefix
    2010                 :            :  *  @wwpn_prefix: the alternative WWPN prefix
    2011                 :            :  *
    2012                 :            :  *  This function will read the EEPROM from the alternative SAN MAC address
    2013                 :            :  *  block to check the support for the alternative WWNN/WWPN prefix support.
    2014                 :            :  **/
    2015                 :          0 : s32 txgbe_get_wwn_prefix(struct txgbe_hw *hw, u16 *wwnn_prefix,
    2016                 :            :                                  u16 *wwpn_prefix)
    2017                 :            : {
    2018                 :            :         u16 offset, caps;
    2019                 :            :         u16 alt_san_mac_blk_offset;
    2020                 :            : 
    2021                 :            :         /* clear output first */
    2022                 :          0 :         *wwnn_prefix = 0xFFFF;
    2023                 :          0 :         *wwpn_prefix = 0xFFFF;
    2024                 :            : 
    2025                 :            :         /* check if alternative SAN MAC is supported */
    2026                 :            :         offset = TXGBE_ALT_SAN_MAC_ADDR_BLK_PTR;
    2027         [ #  # ]:          0 :         if (hw->rom.readw_sw(hw, offset, &alt_san_mac_blk_offset))
    2028                 :          0 :                 goto wwn_prefix_err;
    2029                 :            : 
    2030         [ #  # ]:          0 :         if (alt_san_mac_blk_offset == 0 || alt_san_mac_blk_offset == 0xFFFF)
    2031                 :          0 :                 goto wwn_prefix_out;
    2032                 :            : 
    2033                 :            :         /* check capability in alternative san mac address block */
    2034                 :            :         offset = alt_san_mac_blk_offset + TXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
    2035         [ #  # ]:          0 :         if (hw->rom.read16(hw, offset, &caps))
    2036                 :          0 :                 goto wwn_prefix_err;
    2037         [ #  # ]:          0 :         if (!(caps & TXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
    2038                 :          0 :                 goto wwn_prefix_out;
    2039                 :            : 
    2040                 :            :         /* get the corresponding prefix for WWNN/WWPN */
    2041                 :          0 :         offset = alt_san_mac_blk_offset + TXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
    2042         [ #  # ]:          0 :         if (hw->rom.read16(hw, offset, wwnn_prefix))
    2043                 :          0 :                 DEBUGOUT("eeprom read at offset %d failed", offset);
    2044                 :            : 
    2045                 :          0 :         offset = alt_san_mac_blk_offset + TXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
    2046         [ #  # ]:          0 :         if (hw->rom.read16(hw, offset, wwpn_prefix))
    2047                 :          0 :                 goto wwn_prefix_err;
    2048                 :            : 
    2049                 :          0 : wwn_prefix_out:
    2050                 :            :         return 0;
    2051                 :            : 
    2052                 :          0 : wwn_prefix_err:
    2053                 :          0 :         DEBUGOUT("eeprom read at offset %d failed", offset);
    2054                 :          0 :         return 0;
    2055                 :            : }
    2056                 :            : 
    2057                 :            : /**
    2058                 :            :  *  txgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
    2059                 :            :  *  @hw: pointer to hardware structure
    2060                 :            :  *  @enable: enable or disable switch for MAC anti-spoofing
    2061                 :            :  *  @vf: Virtual Function pool - VF Pool to set for MAC anti-spoofing
    2062                 :            :  *
    2063                 :            :  **/
    2064                 :          0 : void txgbe_set_mac_anti_spoofing(struct txgbe_hw *hw, bool enable, int vf)
    2065                 :            : {
    2066                 :          0 :         int vf_target_reg = vf >> 3;
    2067                 :            :         int vf_target_shift = vf % 8;
    2068                 :            :         u32 pfvfspoof;
    2069                 :            : 
    2070                 :          0 :         pfvfspoof = rd32(hw, TXGBE_POOLTXASMAC(vf_target_reg));
    2071         [ #  # ]:          0 :         if (enable)
    2072                 :          0 :                 pfvfspoof |= (1 << vf_target_shift);
    2073                 :            :         else
    2074                 :          0 :                 pfvfspoof &= ~(1 << vf_target_shift);
    2075                 :            :         wr32(hw, TXGBE_POOLTXASMAC(vf_target_reg), pfvfspoof);
    2076                 :          0 : }
    2077                 :            : 
    2078                 :            : /**
    2079                 :            :  * txgbe_set_ethertype_anti_spoofing - Configure Ethertype anti-spoofing
    2080                 :            :  * @hw: pointer to hardware structure
    2081                 :            :  * @enable: enable or disable switch for Ethertype anti-spoofing
    2082                 :            :  * @vf: Virtual Function pool - VF Pool to set for Ethertype anti-spoofing
    2083                 :            :  *
    2084                 :            :  **/
    2085                 :          0 : void txgbe_set_ethertype_anti_spoofing(struct txgbe_hw *hw,
    2086                 :            :                 bool enable, int vf)
    2087                 :            : {
    2088                 :          0 :         int vf_target_reg = vf >> 3;
    2089                 :            :         int vf_target_shift = vf % 8;
    2090                 :            :         u32 pfvfspoof;
    2091                 :            : 
    2092                 :          0 :         pfvfspoof = rd32(hw, TXGBE_POOLTXASET(vf_target_reg));
    2093         [ #  # ]:          0 :         if (enable)
    2094                 :          0 :                 pfvfspoof |= (1 << vf_target_shift);
    2095                 :            :         else
    2096                 :          0 :                 pfvfspoof &= ~(1 << vf_target_shift);
    2097                 :            :         wr32(hw, TXGBE_POOLTXASET(vf_target_reg), pfvfspoof);
    2098                 :          0 : }
    2099                 :            : 
    2100                 :            : /**
    2101                 :            :  *  txgbe_get_device_caps - Get additional device capabilities
    2102                 :            :  *  @hw: pointer to hardware structure
    2103                 :            :  *  @device_caps: the EEPROM word with the extra device capabilities
    2104                 :            :  *
    2105                 :            :  *  This function will read the EEPROM location for the device capabilities,
    2106                 :            :  *  and return the word through device_caps.
    2107                 :            :  **/
    2108                 :          0 : s32 txgbe_get_device_caps(struct txgbe_hw *hw, u16 *device_caps)
    2109                 :            : {
    2110                 :          0 :         hw->rom.readw_sw(hw, TXGBE_DEVICE_CAPS, device_caps);
    2111                 :            : 
    2112                 :          0 :         return 0;
    2113                 :            : }
    2114                 :            : 
    2115                 :            : /**
    2116                 :            :  * txgbe_set_pba - Initialize Rx packet buffer
    2117                 :            :  * @hw: pointer to hardware structure
    2118                 :            :  * @num_pb: number of packet buffers to allocate
    2119                 :            :  * @headroom: reserve n KB of headroom
    2120                 :            :  * @strategy: packet buffer allocation strategy
    2121                 :            :  **/
    2122                 :          0 : void txgbe_set_pba(struct txgbe_hw *hw, int num_pb, u32 headroom,
    2123                 :            :                              int strategy)
    2124                 :            : {
    2125                 :          0 :         u32 pbsize = hw->mac.rx_pb_size;
    2126                 :            :         int i = 0;
    2127                 :            :         u32 rxpktsize, txpktsize, txpbthresh;
    2128                 :            : 
    2129                 :            :         UNREFERENCED_PARAMETER(hw);
    2130                 :            :         UNREFERENCED_PARAMETER(headroom);
    2131                 :            : 
    2132         [ #  # ]:          0 :         if (!num_pb)
    2133                 :            :                 num_pb = 1;
    2134                 :            : 
    2135                 :            :         /* Divide remaining packet buffer space amongst the number of packet
    2136                 :            :          * buffers requested using supplied strategy.
    2137                 :            :          */
    2138      [ #  #  # ]:          0 :         switch (strategy) {
    2139                 :          0 :         case PBA_STRATEGY_WEIGHTED:
    2140                 :            :                 /* txgbe_dcb_pba_80_48 strategy weight first half of packet
    2141                 :            :                  * buffer with 5/8 of the packet buffer space.
    2142                 :            :                  */
    2143                 :          0 :                 rxpktsize = (pbsize * 5) / (num_pb * 4);
    2144                 :          0 :                 pbsize -= rxpktsize * (num_pb / 2);
    2145                 :          0 :                 rxpktsize <<= 10;
    2146         [ #  # ]:          0 :                 for (; i < (num_pb / 2); i++)
    2147                 :          0 :                         wr32(hw, TXGBE_PBRXSIZE(i), rxpktsize);
    2148                 :            :                 /* fall through - configure remaining packet buffers */
    2149                 :            :         case PBA_STRATEGY_EQUAL:
    2150                 :          0 :                 rxpktsize = (pbsize / (num_pb - i));
    2151                 :          0 :                 rxpktsize <<= 10;
    2152         [ #  # ]:          0 :                 for (; i < num_pb; i++)
    2153                 :          0 :                         wr32(hw, TXGBE_PBRXSIZE(i), rxpktsize);
    2154                 :            :                 break;
    2155                 :            :         default:
    2156                 :            :                 break;
    2157                 :            :         }
    2158                 :            : 
    2159                 :            :         /* Only support an equally distributed Tx packet buffer strategy. */
    2160                 :          0 :         txpktsize = TXGBE_PBTXSIZE_MAX / num_pb;
    2161                 :          0 :         txpbthresh = (txpktsize / 1024) - TXGBE_TXPKT_SIZE_MAX;
    2162         [ #  # ]:          0 :         for (i = 0; i < num_pb; i++) {
    2163                 :          0 :                 wr32(hw, TXGBE_PBTXSIZE(i), txpktsize);
    2164                 :          0 :                 wr32(hw, TXGBE_PBTXDMATH(i), txpbthresh);
    2165                 :            :         }
    2166                 :            : 
    2167                 :            :         /* Clear unused TCs, if any, to zero buffer size*/
    2168         [ #  # ]:          0 :         for (; i < TXGBE_MAX_UP; i++) {
    2169                 :          0 :                 wr32(hw, TXGBE_PBRXSIZE(i), 0);
    2170                 :          0 :                 wr32(hw, TXGBE_PBTXSIZE(i), 0);
    2171                 :          0 :                 wr32(hw, TXGBE_PBTXDMATH(i), 0);
    2172                 :            :         }
    2173                 :          0 : }
    2174                 :            : 
    2175                 :            : /**
    2176                 :            :  * txgbe_clear_tx_pending - Clear pending TX work from the PCIe fifo
    2177                 :            :  * @hw: pointer to the hardware structure
    2178                 :            :  *
    2179                 :            :  * The MACs can experience issues if TX work is still pending
    2180                 :            :  * when a reset occurs.  This function prevents this by flushing the PCIe
    2181                 :            :  * buffers on the system.
    2182                 :            :  **/
    2183                 :          0 : void txgbe_clear_tx_pending(struct txgbe_hw *hw)
    2184                 :            : {
    2185                 :            :         u32 hlreg0, i, poll;
    2186                 :            : 
    2187                 :            :         /*
    2188                 :            :          * If double reset is not requested then all transactions should
    2189                 :            :          * already be clear and as such there is no work to do
    2190                 :            :          */
    2191         [ #  # ]:          0 :         if (!(hw->mac.flags & TXGBE_FLAGS_DOUBLE_RESET_REQUIRED))
    2192                 :            :                 return;
    2193                 :            : 
    2194                 :            :         hlreg0 = rd32(hw, TXGBE_PSRCTL);
    2195                 :          0 :         wr32(hw, TXGBE_PSRCTL, hlreg0 | TXGBE_PSRCTL_LBENA);
    2196                 :            : 
    2197                 :            :         /* Wait for a last completion before clearing buffers */
    2198                 :            :         txgbe_flush(hw);
    2199                 :            :         msec_delay(3);
    2200                 :            : 
    2201                 :            :         /*
    2202                 :            :          * Before proceeding, make sure that the PCIe block does not have
    2203                 :            :          * transactions pending.
    2204                 :            :          */
    2205                 :            :         poll = (800 * 11) / 10;
    2206         [ #  # ]:          0 :         for (i = 0; i < poll; i++)
    2207                 :          0 :                 usec_delay(100);
    2208                 :            : 
    2209                 :            :         /* Flush all writes and allow 20usec for all transactions to clear */
    2210                 :            :         txgbe_flush(hw);
    2211                 :          0 :         usec_delay(20);
    2212                 :            : 
    2213                 :            :         /* restore previous register values */
    2214                 :            :         wr32(hw, TXGBE_PSRCTL, hlreg0);
    2215                 :            : }
    2216                 :            : 
    2217                 :            : /**
    2218                 :            :  *  txgbe_get_thermal_sensor_data - Gathers thermal sensor data
    2219                 :            :  *  @hw: pointer to hardware structure
    2220                 :            :  *
    2221                 :            :  *  Returns the thermal sensor data structure
    2222                 :            :  **/
    2223                 :            : #define PHYINIT_TIMEOUT 1000
    2224                 :          0 : s32 txgbe_get_thermal_sensor_data(struct txgbe_hw *hw)
    2225                 :            : {
    2226                 :            :         struct txgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
    2227                 :            :         s64 tsv;
    2228                 :            :         u32 ts_stat;
    2229                 :            :         u32 data_code;
    2230                 :            :         int temp_data, temp_fraction;
    2231                 :            :         int i = 0;
    2232                 :            : 
    2233                 :            :         /* Only support thermal sensors attached to physical port 0 */
    2234         [ #  # ]:          0 :         if (hw->bus.lan_id != 0)
    2235                 :            :                 return TXGBE_NOT_IMPLEMENTED;
    2236                 :            : 
    2237         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_aml || hw->mac.type == txgbe_mac_aml40) {
    2238                 :            :                 wr32(hw, TXGBE_AML_TS_ENA, 0x0001);
    2239                 :            : 
    2240                 :            :                 while (1) {
    2241                 :            :                         data_code = rd32(hw, TXGBE_AML_TS_STS);
    2242         [ #  # ]:          0 :                         if ((data_code & TXGBE_AML_TS_STS_VLD) != 0)
    2243                 :            :                                 break;
    2244                 :            :                         msleep(1);
    2245         [ #  # ]:          0 :                         if (i++ > PHYINIT_TIMEOUT) {
    2246                 :          0 :                                 PMD_DRV_LOG(ERR, "ERROR: Wait 0x1033c Timeout!!!");
    2247                 :          0 :                                 return -1;
    2248                 :            :                         }
    2249                 :            :                 }
    2250                 :            : 
    2251                 :          0 :                 data_code = data_code & 0xFFF;
    2252                 :          0 :                 temp_data = 419400 + 2205 * (data_code * 1000 / 4094 - 500);
    2253                 :            : 
    2254                 :            :                 /* Change double Temperature to int */
    2255                 :          0 :                 tsv = temp_data / 10000;
    2256                 :          0 :                 temp_fraction = temp_data - (tsv * 10000);
    2257         [ #  # ]:          0 :                 if (temp_fraction >= 5000)
    2258                 :          0 :                         tsv += 1;
    2259                 :          0 :                 data->sensor[0].temp = (s16)tsv;
    2260                 :            :         } else {
    2261                 :            :                 ts_stat = rd32(hw, TXGBE_TSSTAT);
    2262                 :            :                 tsv = (s64)TXGBE_TSSTAT_DATA(ts_stat);
    2263                 :            :                 tsv = tsv > 1200 ? tsv : 1200;
    2264                 :            :                 tsv = -(48380 << 8) / 1000
    2265                 :            :                         + tsv * (31020 << 8) / 100000
    2266                 :            :                         - tsv * tsv * (18201 << 8) / 100000000
    2267                 :            :                         + tsv * tsv * tsv * (81542 << 8) / 1000000000000
    2268                 :            :                         - tsv * tsv * tsv * tsv * (16743 << 8) / 1000000000000000;
    2269                 :            :                 tsv >>= 8;
    2270                 :            : 
    2271                 :          0 :                 data->sensor[0].temp = (s16)tsv;
    2272                 :            :         }
    2273                 :            : 
    2274                 :            :         return 0;
    2275                 :            : }
    2276                 :            : 
    2277                 :            : /**
    2278                 :            :  *  txgbe_init_thermal_sensor_thresh - Inits thermal sensor thresholds
    2279                 :            :  *  @hw: pointer to hardware structure
    2280                 :            :  *
    2281                 :            :  *  Inits the thermal sensor thresholds according to the NVM map
    2282                 :            :  *  and save off the threshold and location values into mac.thermal_sensor_data
    2283                 :            :  **/
    2284                 :          0 : s32 txgbe_init_thermal_sensor_thresh(struct txgbe_hw *hw)
    2285                 :            : {
    2286         [ #  # ]:          0 :         struct txgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
    2287                 :            : 
    2288                 :            :         memset(data, 0, sizeof(struct txgbe_thermal_sensor_data));
    2289                 :            : 
    2290         [ #  # ]:          0 :         if (hw->bus.lan_id != 0)
    2291                 :            :                 return TXGBE_NOT_IMPLEMENTED;
    2292                 :            : 
    2293                 :          0 :         data->sensor[0].alarm_thresh = 100;
    2294                 :          0 :         data->sensor[0].dalarm_thresh = 90;
    2295                 :            : 
    2296         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_aml || hw->mac.type == txgbe_mac_aml40) {
    2297                 :            :                 wr32(hw, TXGBE_AML_TS_ENA, 0x0);
    2298                 :            :                 wr32(hw, TXGBE_AML_INTR_RAW_LO, TXGBE_AML_INTR_CL_LO);
    2299                 :            :                 wr32(hw, TXGBE_AML_INTR_RAW_HI, TXGBE_AML_INTR_CL_HI);
    2300                 :            : 
    2301                 :            :                 wr32(hw, TXGBE_AML_INTR_HIGH_EN, TXGBE_AML_INTR_EN_HI);
    2302                 :            :                 wr32(hw, TXGBE_AML_INTR_LOW_EN, TXGBE_AML_INTR_EN_LO);
    2303                 :            : 
    2304                 :            :                 wr32m(hw, TXGBE_AML_TS_CTL1, TXGBE_AML_EVAL_MODE_MASK, 0x10);
    2305                 :            :                 wr32m(hw, TXGBE_AML_TS_CTL1, TXGBE_AML_ALARM_THRE_MASK, 0x186a0000);
    2306                 :            :                 wr32m(hw, TXGBE_AML_TS_CTL1, TXGBE_AML_DALARM_THRE_MASK, 0x16f60);
    2307                 :            :                 wr32(hw, TXGBE_AML_TS_ENA, 0x1);
    2308                 :            :         } else {
    2309                 :            :                 wr32(hw, TXGBE_TSCTRL, TXGBE_TSCTRL_EVALMD);
    2310                 :            :                 wr32(hw, TXGBE_TSINTR,
    2311                 :            :                          TXGBE_TSINTR_AEN | TXGBE_TSINTR_DEN);
    2312                 :            :                 wr32(hw, TXGBE_TSEN, TXGBE_TSEN_ENA);
    2313                 :            : 
    2314                 :          0 :                 data->sensor[0].alarm_thresh = 100;
    2315                 :            :                 wr32(hw, TXGBE_TSATHRE, 677);
    2316                 :          0 :                 data->sensor[0].dalarm_thresh = 90;
    2317                 :            :                 wr32(hw, TXGBE_TSDTHRE, 614);
    2318                 :            :         }
    2319                 :            : 
    2320                 :            :         return 0;
    2321                 :            : }
    2322                 :            : 
    2323                 :          0 : void txgbe_disable_rx(struct txgbe_hw *hw)
    2324                 :            : {
    2325                 :            :         u32 pfdtxgswc;
    2326                 :            : 
    2327                 :            :         pfdtxgswc = rd32(hw, TXGBE_PSRCTL);
    2328         [ #  # ]:          0 :         if (pfdtxgswc & TXGBE_PSRCTL_LBENA) {
    2329                 :          0 :                 pfdtxgswc &= ~TXGBE_PSRCTL_LBENA;
    2330                 :            :                 wr32(hw, TXGBE_PSRCTL, pfdtxgswc);
    2331                 :          0 :                 hw->mac.set_lben = true;
    2332                 :            :         } else {
    2333                 :          0 :                 hw->mac.set_lben = false;
    2334                 :            :         }
    2335                 :            : 
    2336                 :            :         wr32m(hw, TXGBE_PBRXCTL, TXGBE_PBRXCTL_ENA, 0);
    2337                 :            :         wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_ENA, 0);
    2338                 :          0 : }
    2339                 :            : 
    2340                 :          0 : void txgbe_enable_rx(struct txgbe_hw *hw)
    2341                 :            : {
    2342                 :            :         u32 pfdtxgswc;
    2343                 :            : 
    2344                 :            :         wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_ENA, TXGBE_MACRXCFG_ENA);
    2345                 :            :         wr32m(hw, TXGBE_PBRXCTL, TXGBE_PBRXCTL_ENA, TXGBE_PBRXCTL_ENA);
    2346                 :            : 
    2347         [ #  # ]:          0 :         if (hw->mac.set_lben) {
    2348                 :            :                 pfdtxgswc = rd32(hw, TXGBE_PSRCTL);
    2349                 :          0 :                 pfdtxgswc |= TXGBE_PSRCTL_LBENA;
    2350                 :            :                 wr32(hw, TXGBE_PSRCTL, pfdtxgswc);
    2351                 :          0 :                 hw->mac.set_lben = false;
    2352                 :            :         }
    2353                 :          0 : }
    2354                 :            : 
    2355                 :            : /**
    2356                 :            :  *  txgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
    2357                 :            :  *  @hw: pointer to hardware structure
    2358                 :            :  *  @speed: new link speed
    2359                 :            :  *  @autoneg_wait_to_complete: true when waiting for completion is needed
    2360                 :            :  *
    2361                 :            :  *  Set the link speed in the MAC and/or PHY register and restarts link.
    2362                 :            :  **/
    2363                 :          0 : s32 txgbe_setup_mac_link_multispeed_fiber(struct txgbe_hw *hw,
    2364                 :            :                                           u32 speed,
    2365                 :            :                                           bool autoneg_wait_to_complete)
    2366                 :            : {
    2367                 :          0 :         u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
    2368                 :            :         u32 highest_link_speed = TXGBE_LINK_SPEED_UNKNOWN;
    2369                 :            :         s32 status = 0;
    2370                 :            :         u32 speedcnt = 0;
    2371                 :            :         u32 i = 0;
    2372                 :          0 :         bool autoneg, link_up = false;
    2373                 :            : 
    2374                 :            :         /* Mask off requested but non-supported speeds */
    2375                 :          0 :         status = hw->mac.get_link_capabilities(hw, &link_speed, &autoneg);
    2376         [ #  # ]:          0 :         if (status != 0)
    2377                 :            :                 return status;
    2378                 :            : 
    2379                 :          0 :         speed &= link_speed;
    2380                 :            : 
    2381                 :            :         /* Try each speed one by one, highest priority first.  We do this in
    2382                 :            :          * software because 10Gb fiber doesn't support speed autonegotiation.
    2383                 :            :          */
    2384         [ #  # ]:          0 :         if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
    2385                 :            :                 speedcnt++;
    2386                 :            :                 highest_link_speed = TXGBE_LINK_SPEED_10GB_FULL;
    2387                 :            : 
    2388                 :            :                 /* Set the module link speed */
    2389      [ #  #  # ]:          0 :                 switch (hw->phy.media_type) {
    2390                 :          0 :                 case txgbe_media_type_fiber:
    2391                 :          0 :                         hw->mac.set_rate_select_speed(hw,
    2392                 :            :                                 TXGBE_LINK_SPEED_10GB_FULL);
    2393                 :          0 :                         break;
    2394                 :            :                 case txgbe_media_type_fiber_qsfp:
    2395                 :            :                         /* QSFP module automatically detects MAC link speed */
    2396                 :            :                         break;
    2397                 :          0 :                 default:
    2398                 :          0 :                         DEBUGOUT("Unexpected media type.");
    2399                 :          0 :                         break;
    2400                 :            :                 }
    2401                 :            : 
    2402                 :            :                 /* Allow module to change analog characteristics (1G->10G) */
    2403                 :            :                 msec_delay(40);
    2404                 :            : 
    2405                 :          0 :                 status = hw->mac.setup_mac_link(hw,
    2406                 :            :                                 TXGBE_LINK_SPEED_10GB_FULL,
    2407                 :            :                                 autoneg_wait_to_complete);
    2408         [ #  # ]:          0 :                 if (status != 0)
    2409                 :            :                         return status;
    2410                 :            : 
    2411                 :            :                 /* Flap the Tx laser if it has not already been done */
    2412                 :          0 :                 hw->mac.flap_tx_laser(hw);
    2413                 :            : 
    2414                 :            :                 /* Wait for the controller to acquire link.  Per IEEE 802.3ap,
    2415                 :            :                  * Section 73.10.2, we may have to wait up to 500ms if KR is
    2416                 :            :                  * attempted.  uses the same timing for 10g SFI.
    2417                 :            :                  */
    2418         [ #  # ]:          0 :                 for (i = 0; i < 5; i++) {
    2419                 :            :                         /* Wait for the link partner to also set speed */
    2420                 :            :                         msec_delay(100);
    2421                 :            : 
    2422                 :            :                         /* If we have link, just jump out */
    2423                 :          0 :                         status = hw->mac.check_link(hw, &link_speed,
    2424                 :            :                                 &link_up, false);
    2425         [ #  # ]:          0 :                         if (status != 0)
    2426                 :          0 :                                 return status;
    2427                 :            : 
    2428         [ #  # ]:          0 :                         if (link_up)
    2429                 :          0 :                                 goto out;
    2430                 :            :                 }
    2431                 :            :         }
    2432                 :            : 
    2433         [ #  # ]:          0 :         if (speed & TXGBE_LINK_SPEED_1GB_FULL) {
    2434                 :            :                 u32 curr_autoneg;
    2435                 :            : 
    2436                 :          0 :                 speedcnt++;
    2437         [ #  # ]:          0 :                 if (highest_link_speed == TXGBE_LINK_SPEED_UNKNOWN)
    2438                 :            :                         highest_link_speed = TXGBE_LINK_SPEED_1GB_FULL;
    2439                 :            : 
    2440                 :          0 :                 status = hw->mac.check_link(hw, &link_speed, &link_up, false);
    2441         [ #  # ]:          0 :                 if (status != 0)
    2442                 :            :                         return status;
    2443                 :            : 
    2444                 :            :                 /* If we already have link at this speed, just jump out */
    2445         [ #  # ]:          0 :                 if (link_speed == TXGBE_LINK_SPEED_1GB_FULL) {
    2446                 :            :                         curr_autoneg = rd32_epcs(hw, SR_MII_MMD_CTL);
    2447         [ #  # ]:          0 :                         if (link_up && (hw->autoneg ==
    2448         [ #  # ]:          0 :                                         !!(curr_autoneg & SR_MII_MMD_CTL_AN_EN)))
    2449                 :          0 :                                 goto out;
    2450                 :            :                 }
    2451                 :            : 
    2452                 :            :                 /* Set the module link speed */
    2453      [ #  #  # ]:          0 :                 switch (hw->phy.media_type) {
    2454                 :          0 :                 case txgbe_media_type_fiber:
    2455                 :          0 :                         hw->mac.set_rate_select_speed(hw,
    2456                 :            :                                 TXGBE_LINK_SPEED_1GB_FULL);
    2457                 :          0 :                         break;
    2458                 :            :                 case txgbe_media_type_fiber_qsfp:
    2459                 :            :                         /* QSFP module automatically detects link speed */
    2460                 :            :                         break;
    2461                 :          0 :                 default:
    2462                 :          0 :                         DEBUGOUT("Unexpected media type.");
    2463                 :          0 :                         break;
    2464                 :            :                 }
    2465                 :            : 
    2466                 :            :                 /* Allow module to change analog characteristics (10G->1G) */
    2467                 :            :                 msec_delay(40);
    2468                 :            : 
    2469                 :          0 :                 status = hw->mac.setup_mac_link(hw,
    2470                 :            :                                 TXGBE_LINK_SPEED_1GB_FULL,
    2471                 :            :                                 autoneg_wait_to_complete);
    2472         [ #  # ]:          0 :                 if (status != 0)
    2473                 :            :                         return status;
    2474                 :            : 
    2475                 :            :                 /* Flap the Tx laser if it has not already been done */
    2476                 :          0 :                 hw->mac.flap_tx_laser(hw);
    2477                 :            : 
    2478                 :            :                 /* Wait for the link partner to also set speed */
    2479                 :            :                 msec_delay(100);
    2480                 :            : 
    2481                 :            :                 /* If we have link, just jump out */
    2482                 :          0 :                 status = hw->mac.check_link(hw, &link_speed, &link_up, false);
    2483         [ #  # ]:          0 :                 if (status != 0)
    2484                 :            :                         return status;
    2485                 :            : 
    2486         [ #  # ]:          0 :                 if (link_up)
    2487                 :          0 :                         goto out;
    2488                 :            :         }
    2489                 :            : 
    2490                 :            :         /* We didn't get link.  Configure back to the highest speed we tried,
    2491                 :            :          * (if there was more than one).  We call ourselves back with just the
    2492                 :            :          * single highest speed that the user requested.
    2493                 :            :          */
    2494         [ #  # ]:          0 :         if (speedcnt > 1)
    2495                 :          0 :                 status = txgbe_setup_mac_link_multispeed_fiber(hw,
    2496                 :            :                                                       highest_link_speed,
    2497                 :            :                                                       autoneg_wait_to_complete);
    2498                 :            : 
    2499                 :          0 : out:
    2500                 :            :         /* Set autoneg_advertised value based on input link speed */
    2501                 :          0 :         hw->phy.autoneg_advertised = 0;
    2502                 :            : 
    2503         [ #  # ]:          0 :         if (speed & TXGBE_LINK_SPEED_10GB_FULL)
    2504                 :          0 :                 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
    2505                 :            : 
    2506         [ #  # ]:          0 :         if (speed & TXGBE_LINK_SPEED_1GB_FULL)
    2507                 :          0 :                 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;
    2508                 :            : 
    2509                 :            :         return status;
    2510                 :            : }
    2511                 :            : 
    2512                 :            : /**
    2513                 :            :  *  txgbe_init_shared_code - Initialize the shared code
    2514                 :            :  *  @hw: pointer to hardware structure
    2515                 :            :  *
    2516                 :            :  *  This will assign function pointers and assign the MAC type and PHY code.
    2517                 :            :  *  Does not touch the hardware. This function must be called prior to any
    2518                 :            :  *  other function in the shared code. The txgbe_hw structure should be
    2519                 :            :  *  memset to 0 prior to calling this function.  The following fields in
    2520                 :            :  *  hw structure should be filled in prior to calling this function:
    2521                 :            :  *  hw_addr, back, device_id, vendor_id, subsystem_device_id,
    2522                 :            :  *  subsystem_vendor_id, and revision_id
    2523                 :            :  **/
    2524                 :          0 : s32 txgbe_init_shared_code(struct txgbe_hw *hw)
    2525                 :            : {
    2526                 :            :         s32 status = 0;
    2527                 :            : 
    2528                 :            :         /*
    2529                 :            :          * Set the mac type
    2530                 :            :          */
    2531                 :          0 :         txgbe_set_mac_type(hw);
    2532                 :            : 
    2533                 :          0 :         txgbe_init_ops_dummy(hw);
    2534   [ #  #  #  #  :          0 :         switch (hw->mac.type) {
                      # ]
    2535                 :          0 :         case txgbe_mac_sp:
    2536                 :          0 :                 txgbe_init_ops_sp(hw);
    2537                 :          0 :                 break;
    2538                 :          0 :         case txgbe_mac_aml:
    2539                 :          0 :                 txgbe_init_ops_aml(hw);
    2540                 :          0 :                 break;
    2541                 :          0 :         case txgbe_mac_aml40:
    2542                 :          0 :                 txgbe_init_ops_aml40(hw);
    2543                 :          0 :                 break;
    2544                 :          0 :         case txgbe_mac_sp_vf:
    2545                 :            :         case txgbe_mac_aml_vf:
    2546                 :          0 :                 status = txgbe_init_ops_vf(hw);
    2547                 :          0 :                 break;
    2548                 :            :         default:
    2549                 :            :                 status = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
    2550                 :            :                 break;
    2551                 :            :         }
    2552                 :          0 :         hw->mac.max_link_up_time = TXGBE_LINK_UP_TIME;
    2553                 :            : 
    2554                 :          0 :         hw->bus.set_lan_id(hw);
    2555                 :            : 
    2556                 :          0 :         return status;
    2557                 :            : }
    2558                 :            : 
    2559                 :          0 : bool txgbe_is_pf(struct txgbe_hw *hw)
    2560                 :            : {
    2561         [ #  # ]:          0 :         switch (hw->mac.type) {
    2562                 :            :         case txgbe_mac_sp:
    2563                 :            :         case txgbe_mac_aml:
    2564                 :            :         case txgbe_mac_aml40:
    2565                 :            :                 return true;
    2566                 :          0 :         default:
    2567                 :          0 :                 return false;
    2568                 :            :         }
    2569                 :            : }
    2570                 :            : 
    2571                 :          0 : bool txgbe_is_vf(struct txgbe_hw *hw)
    2572                 :            : {
    2573         [ #  # ]:          0 :         switch (hw->mac.type) {
    2574                 :            :         case txgbe_mac_sp_vf:
    2575                 :            :         case txgbe_mac_aml_vf:
    2576                 :            :                 return true;
    2577                 :          0 :         default:
    2578                 :          0 :                 return false;
    2579                 :            :         }
    2580                 :            : }
    2581                 :            : 
    2582                 :            : /**
    2583                 :            :  *  txgbe_set_mac_type - Sets MAC type
    2584                 :            :  *  @hw: pointer to the HW structure
    2585                 :            :  *
    2586                 :            :  *  This function sets the mac type of the adapter based on the
    2587                 :            :  *  vendor ID and device ID stored in the hw structure.
    2588                 :            :  **/
    2589                 :          0 : s32 txgbe_set_mac_type(struct txgbe_hw *hw)
    2590                 :            : {
    2591                 :            :         s32 err = 0;
    2592                 :            : 
    2593         [ #  # ]:          0 :         if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
    2594                 :          0 :                 DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
    2595                 :          0 :                 return TXGBE_ERR_DEVICE_NOT_SUPPORTED;
    2596                 :            :         }
    2597                 :            : 
    2598   [ #  #  #  #  :          0 :         switch (hw->device_id) {
                   #  # ]
    2599                 :          0 :         case TXGBE_DEV_ID_SP1000:
    2600                 :            :         case TXGBE_DEV_ID_WX1820:
    2601                 :          0 :                 hw->mac.type = txgbe_mac_sp;
    2602                 :          0 :                 break;
    2603                 :          0 :         case TXGBE_DEV_ID_AML:
    2604                 :            :         case TXGBE_DEV_ID_AML5025:
    2605                 :            :         case TXGBE_DEV_ID_AML5125:
    2606                 :          0 :                 hw->mac.type = txgbe_mac_aml;
    2607                 :          0 :                 break;
    2608                 :          0 :         case TXGBE_DEV_ID_AML5040:
    2609                 :            :         case TXGBE_DEV_ID_AML5140:
    2610                 :          0 :                 hw->mac.type = txgbe_mac_aml40;
    2611                 :          0 :                 break;
    2612                 :          0 :         case TXGBE_DEV_ID_SP1000_VF:
    2613                 :            :         case TXGBE_DEV_ID_WX1820_VF:
    2614                 :          0 :                 hw->phy.media_type = txgbe_media_type_virtual;
    2615                 :          0 :                 hw->mac.type = txgbe_mac_sp_vf;
    2616                 :          0 :                 break;
    2617                 :          0 :         case TXGBE_DEV_ID_AML_VF:
    2618                 :            :         case TXGBE_DEV_ID_AML5024_VF:
    2619                 :            :         case TXGBE_DEV_ID_AML5124_VF:
    2620                 :          0 :                 hw->phy.media_type = txgbe_media_type_virtual;
    2621                 :          0 :                 hw->mac.type = txgbe_mac_aml_vf;
    2622                 :          0 :                 break;
    2623                 :          0 :         default:
    2624                 :            :                 err = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
    2625                 :          0 :                 DEBUGOUT("Unsupported device id: %x", hw->device_id);
    2626                 :          0 :                 break;
    2627                 :            :         }
    2628                 :            : 
    2629                 :          0 :         DEBUGOUT("found mac: %d, returns: %d",
    2630                 :            :                   hw->mac.type, err);
    2631                 :          0 :         return err;
    2632                 :            : }
    2633                 :            : 
    2634                 :          0 : void txgbe_init_mac_link_ops_sp(struct txgbe_hw *hw)
    2635                 :            : {
    2636                 :            :         struct txgbe_mac_info *mac = &hw->mac;
    2637                 :            : 
    2638                 :            :         /*
    2639                 :            :          * enable the laser control functions for SFP+ fiber
    2640                 :            :          * and MNG not enabled
    2641                 :            :          */
    2642   [ #  #  #  # ]:          0 :         if (hw->phy.media_type == txgbe_media_type_fiber &&
    2643                 :          0 :             !txgbe_mng_enabled(hw)) {
    2644                 :          0 :                 mac->disable_tx_laser =
    2645                 :            :                         txgbe_disable_tx_laser_multispeed_fiber;
    2646                 :          0 :                 mac->enable_tx_laser =
    2647                 :            :                         txgbe_enable_tx_laser_multispeed_fiber;
    2648                 :          0 :                 mac->flap_tx_laser =
    2649                 :            :                         txgbe_flap_tx_laser_multispeed_fiber;
    2650                 :            :         }
    2651                 :            : 
    2652         [ #  # ]:          0 :         if ((hw->phy.media_type == txgbe_media_type_fiber ||
    2653                 :          0 :              hw->phy.media_type == txgbe_media_type_fiber_qsfp) &&
    2654         [ #  # ]:          0 :             hw->phy.multispeed_fiber) {
    2655                 :            :                 /* Set up dual speed SFP+ support */
    2656                 :          0 :                 mac->setup_link = txgbe_setup_mac_link_multispeed_fiber;
    2657                 :          0 :                 mac->setup_mac_link = txgbe_setup_mac_link;
    2658                 :          0 :                 mac->set_rate_select_speed = txgbe_set_hard_rate_select_speed;
    2659                 :            :         } else {
    2660                 :          0 :                 mac->setup_link = txgbe_setup_mac_link;
    2661                 :          0 :                 mac->set_rate_select_speed = txgbe_set_hard_rate_select_speed;
    2662                 :            :         }
    2663                 :          0 : }
    2664                 :            : 
    2665                 :            : /**
    2666                 :            :  *  txgbe_init_phy_raptor - PHY/SFP specific init
    2667                 :            :  *  @hw: pointer to hardware structure
    2668                 :            :  *
    2669                 :            :  *  Initialize any function pointers that were not able to be
    2670                 :            :  *  set during init_shared_code because the PHY/SFP type was
    2671                 :            :  *  not known.  Perform the SFP init if necessary.
    2672                 :            :  *
    2673                 :            :  **/
    2674                 :          0 : s32 txgbe_init_phy_raptor(struct txgbe_hw *hw)
    2675                 :            : {
    2676                 :            :         struct txgbe_mac_info *mac = &hw->mac;
    2677                 :            :         struct txgbe_phy_info *phy = &hw->phy;
    2678                 :            :         s32 err = 0;
    2679                 :            : 
    2680         [ #  # ]:          0 :         if ((hw->device_id & 0xFF) == TXGBE_DEV_ID_QSFP) {
    2681                 :            :                 /* Store flag indicating I2C bus access control unit. */
    2682      [ #  #  # ]:          0 :                 hw->phy.qsfp_shared_i2c_bus = TRUE;
    2683                 :            : 
    2684                 :            :                 /* Initialize access to QSFP+ I2C bus */
    2685                 :            :                 txgbe_flush(hw);
    2686                 :            :         }
    2687                 :            : 
    2688                 :            :         /* Identify the PHY or SFP module */
    2689                 :          0 :         err = phy->identify(hw);
    2690         [ #  # ]:          0 :         if (err == TXGBE_ERR_SFP_NOT_SUPPORTED)
    2691                 :          0 :                 goto init_phy_ops_out;
    2692                 :            : 
    2693                 :            :         /* Setup function pointers based on detected SFP module and speeds */
    2694                 :          0 :         hw->mac.init_mac_link_ops(hw);
    2695                 :            : 
    2696                 :            :         /* If copper media, overwrite with copper function pointers */
    2697         [ #  # ]:          0 :         if (phy->media_type == txgbe_media_type_copper) {
    2698                 :          0 :                 mac->setup_link = txgbe_setup_copper_link_raptor;
    2699                 :          0 :                 mac->get_link_capabilities =
    2700                 :            :                                   txgbe_get_copper_link_capabilities;
    2701                 :            :         }
    2702                 :            : 
    2703         [ #  # ]:          0 :         if (phy->media_type == txgbe_media_type_backplane) {
    2704                 :          0 :                 mac->kr_handle = txgbe_kr_handle;
    2705                 :          0 :                 mac->bp_down_event = txgbe_bp_down_event;
    2706                 :            :         }
    2707                 :            : 
    2708                 :            :         /* Set necessary function pointers based on PHY type */
    2709         [ #  # ]:          0 :         switch (hw->phy.type) {
    2710                 :          0 :         case txgbe_phy_tn:
    2711                 :          0 :                 phy->setup_link = txgbe_setup_phy_link_tnx;
    2712                 :          0 :                 phy->check_link = txgbe_check_phy_link_tnx;
    2713                 :          0 :                 break;
    2714                 :            :         default:
    2715                 :            :                 break;
    2716                 :            :         }
    2717                 :            : 
    2718                 :          0 : init_phy_ops_out:
    2719                 :          0 :         return err;
    2720                 :            : }
    2721                 :            : 
    2722                 :          0 : s32 txgbe_setup_sfp_modules(struct txgbe_hw *hw)
    2723                 :            : {
    2724                 :            :         s32 err = 0;
    2725                 :            : 
    2726         [ #  # ]:          0 :         if (hw->phy.sfp_type == txgbe_sfp_type_unknown)
    2727                 :            :                 return 0;
    2728                 :            : 
    2729                 :          0 :         hw->mac.init_mac_link_ops(hw);
    2730                 :            : 
    2731                 :            :         /* PHY config will finish before releasing the semaphore */
    2732                 :          0 :         err = hw->mac.acquire_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
    2733         [ #  # ]:          0 :         if (err != 0)
    2734                 :            :                 return TXGBE_ERR_SWFW_SYNC;
    2735                 :            : 
    2736                 :            :         /* Release the semaphore */
    2737                 :          0 :         hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
    2738                 :            : 
    2739                 :            :         /* Delay obtaining semaphore again to allow FW access
    2740                 :            :          * prot_autoc_write uses the semaphore too.
    2741                 :            :          */
    2742                 :          0 :         msec_delay(hw->rom.semaphore_delay);
    2743                 :            : 
    2744                 :            :         if (err) {
    2745                 :            :                 DEBUGOUT("sfp module setup not complete");
    2746                 :            :                 return TXGBE_ERR_SFP_SETUP_NOT_COMPLETE;
    2747                 :            :         }
    2748                 :            : 
    2749                 :            :         return err;
    2750                 :            : }
    2751                 :            : 
    2752                 :            : /**
    2753                 :            :  *  txgbe_prot_autoc_read_raptor - Hides MAC differences needed for AUTOC read
    2754                 :            :  *  @hw: pointer to hardware structure
    2755                 :            :  *  @locked: Return the if we locked for this read.
    2756                 :            :  *  @value: Value we read from AUTOC
    2757                 :            :  *
    2758                 :            :  *  For this part we need to wrap read-modify-writes with a possible
    2759                 :            :  *  FW/SW lock.  It is assumed this lock will be freed with the next
    2760                 :            :  *  prot_autoc_write_raptor().
    2761                 :            :  */
    2762                 :          0 : s32 txgbe_prot_autoc_read_raptor(struct txgbe_hw *hw, bool *locked, u64 *value)
    2763                 :            : {
    2764                 :            :         s32 err;
    2765                 :            :         bool lock_state = false;
    2766                 :            : 
    2767                 :            :          /* If LESM is on then we need to hold the SW/FW semaphore. */
    2768         [ #  # ]:          0 :         if (txgbe_verify_lesm_fw_enabled_raptor(hw)) {
    2769                 :          0 :                 err = hw->mac.acquire_swfw_sync(hw,
    2770                 :            :                                         TXGBE_MNGSEM_SWPHY);
    2771         [ #  # ]:          0 :                 if (err != 0)
    2772                 :            :                         return TXGBE_ERR_SWFW_SYNC;
    2773                 :            : 
    2774                 :            :                 lock_state = true;
    2775                 :            :         }
    2776                 :            : 
    2777         [ #  # ]:          0 :         if (locked)
    2778                 :          0 :                 *locked = lock_state;
    2779                 :            : 
    2780                 :          0 :         *value = txgbe_autoc_read(hw);
    2781                 :          0 :         return 0;
    2782                 :            : }
    2783                 :            : 
    2784                 :            : /**
    2785                 :            :  * txgbe_prot_autoc_write_raptor - Hides MAC differences needed for AUTOC write
    2786                 :            :  * @hw: pointer to hardware structure
    2787                 :            :  * @autoc: value to write to AUTOC
    2788                 :            :  * @locked: bool to indicate whether the SW/FW lock was already taken by
    2789                 :            :  *           previous prot_autoc_read_raptor.
    2790                 :            :  *
    2791                 :            :  * This part may need to hold the SW/FW lock around all writes to
    2792                 :            :  * AUTOC. Likewise after a write we need to do a pipeline reset.
    2793                 :            :  */
    2794                 :          0 : s32 txgbe_prot_autoc_write_raptor(struct txgbe_hw *hw, bool locked, u64 autoc)
    2795                 :            : {
    2796                 :            :         int err = 0;
    2797                 :            : 
    2798                 :            :         /* Blocked by MNG FW so bail */
    2799         [ #  # ]:          0 :         if (txgbe_check_reset_blocked(hw))
    2800                 :          0 :                 goto out;
    2801                 :            : 
    2802                 :            :         /* We only need to get the lock if:
    2803                 :            :          *  - We didn't do it already (in the read part of a read-modify-write)
    2804                 :            :          *  - LESM is enabled.
    2805                 :            :          */
    2806   [ #  #  #  # ]:          0 :         if (!locked && txgbe_verify_lesm_fw_enabled_raptor(hw)) {
    2807                 :          0 :                 err = hw->mac.acquire_swfw_sync(hw,
    2808                 :            :                                         TXGBE_MNGSEM_SWPHY);
    2809         [ #  # ]:          0 :                 if (err != 0)
    2810                 :            :                         return TXGBE_ERR_SWFW_SYNC;
    2811                 :            : 
    2812                 :            :                 locked = true;
    2813                 :            :         }
    2814                 :            : 
    2815                 :          0 :         txgbe_autoc_write(hw, autoc);
    2816                 :          0 :         err = txgbe_reset_pipeline_raptor(hw);
    2817                 :            : 
    2818                 :          0 : out:
    2819                 :            :         /* Free the SW/FW semaphore as we either grabbed it here or
    2820                 :            :          * already had it when this function was called.
    2821                 :            :          */
    2822         [ #  # ]:          0 :         if (locked)
    2823                 :          0 :                 hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
    2824                 :            : 
    2825                 :            :         return err;
    2826                 :            : }
    2827                 :            : 
    2828                 :            : /* cmd_addr is used for some special command:
    2829                 :            :  * 1. to be sector address, when implemented erase sector command
    2830                 :            :  * 2. to be flash address when implemented read, write flash address
    2831                 :            :  *
    2832                 :            :  * Return 0 on success, return TXGBE_ERR_TIMEOUT on failure.
    2833                 :            :  */
    2834                 :          0 : s32 txgbe_fmgr_cmd_op(struct txgbe_hw *hw, u32 cmd, u32 cmd_addr)
    2835                 :            : {
    2836                 :            :         u32 cmd_val, i;
    2837                 :            : 
    2838                 :          0 :         cmd_val = TXGBE_SPICMD_CMD(cmd) | TXGBE_SPICMD_CLK(3) | cmd_addr;
    2839                 :            :         wr32(hw, TXGBE_SPICMD, cmd_val);
    2840                 :            : 
    2841         [ #  # ]:          0 :         for (i = 0; i < TXGBE_SPI_TIMEOUT; i++) {
    2842         [ #  # ]:          0 :                 if (rd32(hw, TXGBE_SPISTAT) & TXGBE_SPISTAT_OPDONE)
    2843                 :            :                         break;
    2844                 :            : 
    2845                 :          0 :                 usec_delay(10);
    2846                 :            :         }
    2847                 :            : 
    2848         [ #  # ]:          0 :         if (i == TXGBE_SPI_TIMEOUT)
    2849                 :          0 :                 return TXGBE_ERR_TIMEOUT;
    2850                 :            : 
    2851                 :            :         return 0;
    2852                 :            : }
    2853                 :            : 
    2854                 :          0 : s32 txgbe_flash_read_dword(struct txgbe_hw *hw, u32 addr, u32 *data)
    2855                 :            : {
    2856                 :            :         s32 status;
    2857                 :            : 
    2858                 :          0 :         status = txgbe_fmgr_cmd_op(hw, 1, addr);
    2859         [ #  # ]:          0 :         if (status < 0) {
    2860                 :          0 :                 DEBUGOUT("Read flash timeout.");
    2861                 :          0 :                 return status;
    2862                 :            :         }
    2863                 :            : 
    2864                 :          0 :         *data = rd32(hw, TXGBE_SPIDAT);
    2865                 :            : 
    2866                 :          0 :         return 0;
    2867                 :            : }
    2868                 :            : 
    2869                 :            : /**
    2870                 :            :  *  txgbe_init_ops_generic - Inits func ptrs and MAC type
    2871                 :            :  *  @hw: pointer to hardware structure
    2872                 :            :  *
    2873                 :            :  *  Initialize the function pointers and assign the MAC type.
    2874                 :            :  *  Does not touch the hardware.
    2875                 :            :  **/
    2876                 :          0 : s32 txgbe_init_ops_generic(struct txgbe_hw *hw)
    2877                 :            : {
    2878                 :            :         struct txgbe_bus_info *bus = &hw->bus;
    2879                 :            :         struct txgbe_mac_info *mac = &hw->mac;
    2880                 :            :         struct txgbe_phy_info *phy = &hw->phy;
    2881                 :            :         struct txgbe_rom_info *rom = &hw->rom;
    2882                 :            :         struct txgbe_mbx_info *mbx = &hw->mbx;
    2883                 :            : 
    2884                 :            :         /* BUS */
    2885                 :          0 :         bus->set_lan_id = txgbe_set_lan_id_multi_port;
    2886                 :            : 
    2887                 :            :         /* PHY */
    2888                 :          0 :         phy->identify = txgbe_identify_phy;
    2889                 :          0 :         phy->init = txgbe_init_phy_raptor;
    2890                 :          0 :         phy->read_reg = txgbe_read_phy_reg;
    2891                 :          0 :         phy->write_reg = txgbe_write_phy_reg;
    2892                 :          0 :         phy->read_reg_mdi = txgbe_read_phy_reg_mdi;
    2893                 :          0 :         phy->write_reg_mdi = txgbe_write_phy_reg_mdi;
    2894                 :          0 :         phy->setup_link = txgbe_setup_phy_link;
    2895                 :          0 :         phy->setup_link_speed = txgbe_setup_phy_link_speed;
    2896                 :          0 :         phy->get_fw_version = txgbe_get_phy_fw_version;
    2897                 :          0 :         phy->read_i2c_byte = txgbe_read_i2c_byte;
    2898                 :          0 :         phy->write_i2c_byte = txgbe_write_i2c_byte;
    2899                 :          0 :         phy->read_i2c_sff8472 = txgbe_read_i2c_sff8472;
    2900                 :          0 :         phy->read_i2c_eeprom = txgbe_read_i2c_eeprom;
    2901                 :          0 :         phy->write_i2c_eeprom = txgbe_write_i2c_eeprom;
    2902                 :          0 :         phy->identify_sfp = txgbe_identify_module;
    2903                 :          0 :         phy->read_i2c_byte_unlocked = txgbe_read_i2c_byte_unlocked;
    2904                 :          0 :         phy->write_i2c_byte_unlocked = txgbe_write_i2c_byte_unlocked;
    2905                 :          0 :         phy->check_overtemp = txgbe_check_overtemp;
    2906                 :          0 :         phy->reset = txgbe_reset_phy;
    2907                 :          0 :         phy->set_link_hostif = txgbe_hic_ephy_set_link;
    2908                 :            : 
    2909                 :            :         /* MAC */
    2910                 :          0 :         mac->init_hw = txgbe_init_hw;
    2911                 :          0 :         mac->start_hw = txgbe_start_hw_raptor;
    2912                 :          0 :         mac->clear_hw_cntrs = txgbe_clear_hw_cntrs;
    2913                 :          0 :         mac->enable_rx_dma = txgbe_enable_rx_dma_raptor;
    2914                 :          0 :         mac->get_mac_addr = txgbe_get_mac_addr;
    2915                 :          0 :         mac->stop_hw = txgbe_stop_hw;
    2916                 :          0 :         mac->acquire_swfw_sync = txgbe_acquire_swfw_sync;
    2917                 :          0 :         mac->release_swfw_sync = txgbe_release_swfw_sync;
    2918                 :          0 :         mac->reset_hw = txgbe_reset_hw;
    2919                 :          0 :         mac->update_mc_addr_list = txgbe_update_mc_addr_list;
    2920                 :            : 
    2921                 :          0 :         mac->disable_sec_rx_path = txgbe_disable_sec_rx_path;
    2922                 :          0 :         mac->enable_sec_rx_path = txgbe_enable_sec_rx_path;
    2923                 :          0 :         mac->disable_sec_tx_path = txgbe_disable_sec_tx_path;
    2924                 :          0 :         mac->enable_sec_tx_path = txgbe_enable_sec_tx_path;
    2925                 :          0 :         mac->get_san_mac_addr = txgbe_get_san_mac_addr;
    2926                 :          0 :         mac->set_san_mac_addr = txgbe_set_san_mac_addr;
    2927                 :          0 :         mac->get_device_caps = txgbe_get_device_caps;
    2928                 :          0 :         mac->get_wwn_prefix = txgbe_get_wwn_prefix;
    2929                 :          0 :         mac->autoc_read = txgbe_autoc_read;
    2930                 :          0 :         mac->autoc_write = txgbe_autoc_write;
    2931                 :          0 :         mac->prot_autoc_read = txgbe_prot_autoc_read_raptor;
    2932                 :          0 :         mac->prot_autoc_write = txgbe_prot_autoc_write_raptor;
    2933                 :            : 
    2934                 :            :         /* RAR, Multicast, VLAN */
    2935                 :          0 :         mac->set_rar = txgbe_set_rar;
    2936                 :          0 :         mac->clear_rar = txgbe_clear_rar;
    2937                 :          0 :         mac->init_rx_addrs = txgbe_init_rx_addrs;
    2938                 :          0 :         mac->enable_rx = txgbe_enable_rx;
    2939                 :          0 :         mac->disable_rx = txgbe_disable_rx;
    2940                 :          0 :         mac->set_vmdq = txgbe_set_vmdq;
    2941                 :          0 :         mac->clear_vmdq = txgbe_clear_vmdq;
    2942                 :          0 :         mac->set_vfta = txgbe_set_vfta;
    2943                 :          0 :         mac->set_vlvf = txgbe_set_vlvf;
    2944                 :          0 :         mac->clear_vfta = txgbe_clear_vfta;
    2945                 :          0 :         mac->init_uta_tables = txgbe_init_uta_tables;
    2946                 :          0 :         mac->setup_sfp = txgbe_setup_sfp_modules;
    2947                 :          0 :         mac->set_mac_anti_spoofing = txgbe_set_mac_anti_spoofing;
    2948                 :          0 :         mac->set_ethertype_anti_spoofing = txgbe_set_ethertype_anti_spoofing;
    2949                 :            : 
    2950                 :            :         /* Flow Control */
    2951                 :          0 :         mac->fc_enable = txgbe_fc_enable;
    2952                 :          0 :         mac->setup_fc = txgbe_setup_fc;
    2953                 :          0 :         mac->fc_autoneg = txgbe_fc_autoneg;
    2954                 :            : 
    2955                 :            :         /* Link */
    2956                 :          0 :         mac->setup_pba = txgbe_set_pba;
    2957                 :            : 
    2958                 :            :         /* Manageability interface */
    2959                 :          0 :         mac->set_fw_drv_ver = txgbe_hic_set_drv_ver;
    2960                 :          0 :         mac->get_thermal_sensor_data = txgbe_get_thermal_sensor_data;
    2961                 :          0 :         mac->init_thermal_sensor_thresh = txgbe_init_thermal_sensor_thresh;
    2962                 :            : 
    2963                 :          0 :         mbx->init_params = txgbe_init_mbx_params_pf;
    2964                 :          0 :         mbx->read = txgbe_read_mbx_pf;
    2965                 :          0 :         mbx->write = txgbe_write_mbx_pf;
    2966                 :          0 :         mbx->check_for_msg = txgbe_check_for_msg_pf;
    2967                 :          0 :         mbx->check_for_ack = txgbe_check_for_ack_pf;
    2968                 :          0 :         mbx->check_for_rst = txgbe_check_for_rst_pf;
    2969                 :            : 
    2970                 :            :         /* EEPROM */
    2971                 :          0 :         rom->init_params = txgbe_init_eeprom_params;
    2972                 :          0 :         rom->read16 = txgbe_ee_read16;
    2973                 :          0 :         rom->readw_buffer = txgbe_ee_readw_buffer;
    2974                 :          0 :         rom->readw_sw = txgbe_ee_readw_sw;
    2975                 :          0 :         rom->read32 = txgbe_ee_read32;
    2976                 :          0 :         rom->write16 = txgbe_ee_write16;
    2977                 :          0 :         rom->writew_buffer = txgbe_ee_writew_buffer;
    2978                 :          0 :         rom->writew_sw = txgbe_ee_writew_sw;
    2979                 :          0 :         rom->write32 = txgbe_ee_write32;
    2980                 :          0 :         rom->validate_checksum = txgbe_validate_eeprom_checksum;
    2981                 :          0 :         rom->update_checksum = txgbe_update_eeprom_checksum;
    2982                 :          0 :         rom->calc_checksum = txgbe_calc_eeprom_checksum;
    2983                 :            : 
    2984                 :          0 :         mac->mcft_size               = TXGBE_RAPTOR_MC_TBL_SIZE;
    2985                 :          0 :         mac->vft_size                = TXGBE_RAPTOR_VFT_TBL_SIZE;
    2986                 :          0 :         mac->num_rar_entries = TXGBE_RAPTOR_RAR_ENTRIES;
    2987                 :          0 :         mac->rx_pb_size              = TXGBE_RAPTOR_RX_PB_SIZE;
    2988                 :          0 :         mac->max_rx_queues   = TXGBE_RAPTOR_MAX_RX_QUEUES;
    2989                 :          0 :         mac->max_tx_queues   = TXGBE_RAPTOR_MAX_TX_QUEUES;
    2990                 :            : 
    2991         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_aml || hw->mac.type == txgbe_mac_aml40)
    2992                 :          0 :                 mac->rx_pb_size = TXGBE_AML_RX_PB_SIZE;
    2993                 :            : 
    2994                 :          0 :         return 0;
    2995                 :            : }
    2996                 :            : 
    2997                 :          0 : void txgbe_init_ops_sp(struct txgbe_hw *hw)
    2998                 :            : {
    2999                 :            :         struct txgbe_mac_info *mac = &hw->mac;
    3000                 :            :         struct txgbe_phy_info *phy = &hw->phy;
    3001                 :            : 
    3002                 :          0 :         txgbe_init_ops_generic(hw);
    3003                 :            : 
    3004                 :            :         /* PHY */
    3005                 :          0 :         phy->get_media_type = txgbe_get_media_type_sp;
    3006                 :            : 
    3007                 :            :         /* LINK */
    3008                 :          0 :         mac->init_mac_link_ops = txgbe_init_mac_link_ops_sp;
    3009                 :          0 :         mac->get_link_capabilities = txgbe_get_link_capabilities_sp;
    3010                 :          0 :         mac->check_link = txgbe_check_mac_link_sp;
    3011                 :          0 : }
    3012                 :            : 
    3013                 :            : /**
    3014                 :            :  *  txgbe_get_link_capabilities_sp - Determines link capabilities
    3015                 :            :  *  @hw: pointer to hardware structure
    3016                 :            :  *  @speed: pointer to link speed
    3017                 :            :  *  @autoneg: true when autoneg or autotry is enabled
    3018                 :            :  *
    3019                 :            :  *  Determines the link capabilities by reading the AUTOC register.
    3020                 :            :  **/
    3021                 :          0 : s32 txgbe_get_link_capabilities_sp(struct txgbe_hw *hw,
    3022                 :            :                                       u32 *speed,
    3023                 :            :                                       bool *autoneg)
    3024                 :            : {
    3025                 :            :         s32 status = 0;
    3026                 :            :         u32 autoc = 0;
    3027                 :            : 
    3028                 :            :         /* Check if 1G SFP module. */
    3029                 :          0 :         if (hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core0 ||
    3030         [ #  # ]:          0 :             hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core1 ||
    3031         [ #  # ]:          0 :             hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core0 ||
    3032         [ #  # ]:          0 :             hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core1 ||
    3033         [ #  # ]:          0 :             hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core0 ||
    3034                 :            :             hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core1) {
    3035                 :          0 :                 *speed = TXGBE_LINK_SPEED_1GB_FULL;
    3036                 :          0 :                 *autoneg = true;
    3037                 :          0 :                 return 0;
    3038                 :            :         }
    3039                 :            : 
    3040                 :            :         /*
    3041                 :            :          * Determine link capabilities based on the stored value of AUTOC,
    3042                 :            :          * which represents EEPROM defaults.  If AUTOC value has not
    3043                 :            :          * been stored, use the current register values.
    3044                 :            :          */
    3045         [ #  # ]:          0 :         if (hw->mac.orig_link_settings_stored)
    3046                 :          0 :                 autoc = hw->mac.orig_autoc;
    3047                 :            :         else
    3048                 :          0 :                 autoc = hw->mac.autoc_read(hw);
    3049                 :            : 
    3050   [ #  #  #  #  :          0 :         switch (autoc & TXGBE_AUTOC_LMS_MASK) {
             #  #  #  # ]
    3051                 :          0 :         case TXGBE_AUTOC_LMS_1G_LINK_NO_AN:
    3052                 :          0 :                 *speed = TXGBE_LINK_SPEED_1GB_FULL;
    3053                 :          0 :                 *autoneg = false;
    3054                 :          0 :                 break;
    3055                 :            : 
    3056                 :          0 :         case TXGBE_AUTOC_LMS_10G_LINK_NO_AN:
    3057                 :          0 :                 *speed = TXGBE_LINK_SPEED_10GB_FULL;
    3058                 :          0 :                 *autoneg = false;
    3059                 :          0 :                 break;
    3060                 :            : 
    3061                 :          0 :         case TXGBE_AUTOC_LMS_1G_AN:
    3062                 :          0 :                 *speed = TXGBE_LINK_SPEED_1GB_FULL;
    3063                 :          0 :                 *autoneg = true;
    3064                 :          0 :                 break;
    3065                 :            : 
    3066                 :          0 :         case TXGBE_AUTOC_LMS_10G:
    3067                 :          0 :                 *speed = TXGBE_LINK_SPEED_10GB_FULL;
    3068                 :          0 :                 *autoneg = false;
    3069                 :          0 :                 break;
    3070                 :            : 
    3071                 :          0 :         case TXGBE_AUTOC_LMS_KX4_KX_KR:
    3072                 :            :         case TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
    3073                 :          0 :                 *speed = TXGBE_LINK_SPEED_UNKNOWN;
    3074         [ #  # ]:          0 :                 if (autoc & TXGBE_AUTOC_KR_SUPP)
    3075                 :          0 :                         *speed |= TXGBE_LINK_SPEED_10GB_FULL;
    3076         [ #  # ]:          0 :                 if (autoc & TXGBE_AUTOC_KX4_SUPP)
    3077                 :          0 :                         *speed |= TXGBE_LINK_SPEED_10GB_FULL;
    3078         [ #  # ]:          0 :                 if (autoc & TXGBE_AUTOC_KX_SUPP)
    3079                 :          0 :                         *speed |= TXGBE_LINK_SPEED_1GB_FULL;
    3080                 :          0 :                 *autoneg = true;
    3081                 :          0 :                 break;
    3082                 :            : 
    3083                 :          0 :         case TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
    3084                 :          0 :                 *speed = TXGBE_LINK_SPEED_100M_FULL;
    3085         [ #  # ]:          0 :                 if (autoc & TXGBE_AUTOC_KR_SUPP)
    3086                 :          0 :                         *speed |= TXGBE_LINK_SPEED_10GB_FULL;
    3087         [ #  # ]:          0 :                 if (autoc & TXGBE_AUTOC_KX4_SUPP)
    3088                 :          0 :                         *speed |= TXGBE_LINK_SPEED_10GB_FULL;
    3089         [ #  # ]:          0 :                 if (autoc & TXGBE_AUTOC_KX_SUPP)
    3090                 :          0 :                         *speed |= TXGBE_LINK_SPEED_1GB_FULL;
    3091                 :          0 :                 *autoneg = true;
    3092                 :          0 :                 break;
    3093                 :            : 
    3094                 :          0 :         case TXGBE_AUTOC_LMS_SGMII_1G_100M:
    3095                 :          0 :                 *speed = TXGBE_LINK_SPEED_1GB_FULL |
    3096                 :            :                          TXGBE_LINK_SPEED_100M_FULL |
    3097                 :            :                          TXGBE_LINK_SPEED_10M_FULL;
    3098                 :          0 :                 *autoneg = false;
    3099                 :          0 :                 break;
    3100                 :            : 
    3101                 :            :         default:
    3102                 :            :                 return TXGBE_ERR_LINK_SETUP;
    3103                 :            :         }
    3104                 :            : 
    3105         [ #  # ]:          0 :         if (hw->phy.multispeed_fiber) {
    3106                 :          0 :                 *speed |= TXGBE_LINK_SPEED_10GB_FULL |
    3107                 :            :                           TXGBE_LINK_SPEED_1GB_FULL;
    3108                 :            : 
    3109                 :            :                 /* QSFP must not enable full auto-negotiation
    3110                 :            :                  * Limited autoneg is enabled at 1G
    3111                 :            :                  */
    3112         [ #  # ]:          0 :                 if (hw->phy.media_type == txgbe_media_type_fiber_qsfp)
    3113                 :          0 :                         *autoneg = false;
    3114                 :            :                 else
    3115                 :          0 :                         *autoneg = true;
    3116                 :            :         }
    3117                 :            : 
    3118                 :            :         return status;
    3119                 :            : }
    3120                 :            : 
    3121                 :            : /**
    3122                 :            :  *  txgbe_get_media_type_sp - Get media type
    3123                 :            :  *  @hw: pointer to hardware structure
    3124                 :            :  *
    3125                 :            :  *  Returns the media type (fiber, copper, backplane)
    3126                 :            :  **/
    3127                 :          0 : u32 txgbe_get_media_type_sp(struct txgbe_hw *hw)
    3128                 :            : {
    3129                 :            :         u32 media_type;
    3130                 :            : 
    3131         [ #  # ]:          0 :         if (hw->phy.ffe_set)
    3132                 :          0 :                 txgbe_bp_mode_set(hw);
    3133                 :            : 
    3134                 :            :         /* Detect if there is a copper PHY attached. */
    3135         [ #  # ]:          0 :         switch (hw->phy.type) {
    3136                 :            :         case txgbe_phy_cu_unknown:
    3137                 :            :         case txgbe_phy_tn:
    3138                 :            :                 media_type = txgbe_media_type_copper;
    3139                 :            :                 return media_type;
    3140                 :            :         default:
    3141                 :            :                 break;
    3142                 :            :         }
    3143                 :            : 
    3144   [ #  #  #  #  :          0 :         switch (hw->subsystem_device_id & 0xFF) {
                   #  # ]
    3145                 :            :         case TXGBE_DEV_ID_KR_KX_KX4:
    3146                 :            :         case TXGBE_DEV_ID_MAC_SGMII:
    3147                 :            :         case TXGBE_DEV_ID_MAC_XAUI:
    3148                 :            :                 /* Default device ID is mezzanine card KX/KX4 */
    3149                 :            :                 media_type = txgbe_media_type_backplane;
    3150                 :            :                 break;
    3151                 :          0 :         case TXGBE_DEV_ID_SFP:
    3152                 :            :                 media_type = txgbe_media_type_fiber;
    3153                 :          0 :                 break;
    3154                 :          0 :         case TXGBE_DEV_ID_QSFP:
    3155                 :            :                 media_type = txgbe_media_type_fiber_qsfp;
    3156                 :          0 :                 break;
    3157                 :          0 :         case TXGBE_DEV_ID_XAUI:
    3158                 :            :         case TXGBE_DEV_ID_SGMII:
    3159                 :            :                 media_type = txgbe_media_type_copper;
    3160                 :          0 :                 break;
    3161                 :          0 :         case TXGBE_DEV_ID_SFI_XAUI:
    3162         [ #  # ]:          0 :                 if (hw->bus.lan_id == 0)
    3163                 :            :                         media_type = txgbe_media_type_fiber;
    3164                 :            :                 else
    3165                 :            :                         media_type = txgbe_media_type_copper;
    3166                 :            :                 break;
    3167                 :          0 :         default:
    3168                 :            :                 media_type = txgbe_media_type_unknown;
    3169                 :          0 :                 break;
    3170                 :            :         }
    3171                 :            : 
    3172                 :            :         return media_type;
    3173                 :            : }
    3174                 :            : 
    3175                 :            : /**
    3176                 :            :  *  txgbe_start_mac_link_raptor - Setup MAC link settings
    3177                 :            :  *  @hw: pointer to hardware structure
    3178                 :            :  *  @autoneg_wait_to_complete: true when waiting for completion is needed
    3179                 :            :  *
    3180                 :            :  *  Configures link settings based on values in the txgbe_hw struct.
    3181                 :            :  *  Restarts the link.  Performs autonegotiation if needed.
    3182                 :            :  **/
    3183                 :          0 : s32 txgbe_start_mac_link_raptor(struct txgbe_hw *hw,
    3184                 :            :                                bool autoneg_wait_to_complete)
    3185                 :            : {
    3186                 :            :         s32 status = 0;
    3187                 :            :         bool got_lock = false;
    3188                 :            : 
    3189                 :            :         UNREFERENCED_PARAMETER(autoneg_wait_to_complete);
    3190                 :            : 
    3191                 :            :         /*  reset_pipeline requires us to hold this lock as it writes to
    3192                 :            :          *  AUTOC.
    3193                 :            :          */
    3194         [ #  # ]:          0 :         if (txgbe_verify_lesm_fw_enabled_raptor(hw)) {
    3195                 :          0 :                 status = hw->mac.acquire_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
    3196         [ #  # ]:          0 :                 if (status != 0)
    3197                 :          0 :                         goto out;
    3198                 :            : 
    3199                 :            :                 got_lock = true;
    3200                 :            :         }
    3201                 :            : 
    3202                 :            :         /* Restart link */
    3203                 :          0 :         txgbe_reset_pipeline_raptor(hw);
    3204                 :            : 
    3205         [ #  # ]:          0 :         if (got_lock)
    3206                 :          0 :                 hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
    3207                 :            : 
    3208                 :            :         /* Add delay to filter out noises during initial link setup */
    3209                 :            :         msec_delay(50);
    3210                 :            : 
    3211                 :          0 : out:
    3212                 :          0 :         return status;
    3213                 :            : }
    3214                 :            : 
    3215                 :            : /**
    3216                 :            :  *  txgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser
    3217                 :            :  *  @hw: pointer to hardware structure
    3218                 :            :  *
    3219                 :            :  *  The base drivers may require better control over SFP+ module
    3220                 :            :  *  PHY states.  This includes selectively shutting down the Tx
    3221                 :            :  *  laser on the PHY, effectively halting physical link.
    3222                 :            :  **/
    3223                 :          0 : void txgbe_disable_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
    3224                 :            : {
    3225                 :            :         u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
    3226                 :            : 
    3227         [ #  # ]:          0 :         if (txgbe_close_notify(hw)) {
    3228                 :            :                 /* over write led when ifconfig down */
    3229         [ #  # ]:          0 :                 if (hw->mac.type == txgbe_mac_aml40) {
    3230                 :          0 :                         txgbe_led_off(hw, TXGBE_LEDCTL_UP | TXGBE_AMLITE_LED_LINK_40G |
    3231                 :            :                                         TXGBE_AMLITE_LED_LINK_ACTIVE);
    3232         [ #  # ]:          0 :                 } else if  (hw->mac.type == txgbe_mac_aml)
    3233                 :          0 :                         txgbe_led_off(hw, TXGBE_LEDCTL_UP | TXGBE_AMLITE_LED_LINK_25G |
    3234                 :            :                                         TXGBE_AMLITE_LED_LINK_10G | TXGBE_AMLITE_LED_LINK_ACTIVE);
    3235                 :            :                 else
    3236                 :          0 :                         txgbe_led_off(hw, TXGBE_LEDCTL_UP | TXGBE_LEDCTL_10G |
    3237                 :            :                                         TXGBE_LEDCTL_1G | TXGBE_LEDCTL_ACTIVE);
    3238                 :            :         }
    3239                 :            : 
    3240                 :            :         /* Disable Tx laser; allow 100us to go dark per spec */
    3241         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_aml40) {
    3242                 :            :                 wr32m(hw, TXGBE_GPIODIR, TXGBE_GPIOBIT_1, TXGBE_GPIOBIT_1);
    3243                 :          0 :                 esdp_reg &= ~TXGBE_GPIOBIT_1;
    3244         [ #  # ]:          0 :         } else if (hw->mac.type == txgbe_mac_aml) {
    3245                 :          0 :                 esdp_reg |= TXGBE_GPIOBIT_1;
    3246                 :            :         } else {
    3247                 :          0 :                 esdp_reg |= (TXGBE_GPIOBIT_0 | TXGBE_GPIOBIT_1);
    3248                 :            :         }
    3249                 :            :         wr32(hw, TXGBE_GPIODATA, esdp_reg);
    3250                 :            :         txgbe_flush(hw);
    3251                 :          0 :         usec_delay(100);
    3252                 :          0 : }
    3253                 :            : 
    3254                 :            : /**
    3255                 :            :  *  txgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser
    3256                 :            :  *  @hw: pointer to hardware structure
    3257                 :            :  *
    3258                 :            :  *  The base drivers may require better control over SFP+ module
    3259                 :            :  *  PHY states.  This includes selectively turning on the Tx
    3260                 :            :  *  laser on the PHY, effectively starting physical link.
    3261                 :            :  **/
    3262                 :          0 : void txgbe_enable_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
    3263                 :            : {
    3264                 :            :         u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
    3265                 :            : 
    3266         [ #  # ]:          0 :         if (txgbe_open_notify(hw))
    3267                 :            :                 wr32(hw, TXGBE_LEDCTL, 0);
    3268                 :            : 
    3269                 :            :         /* Enable Tx laser; allow 100ms to light up */
    3270         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_aml40) {
    3271                 :            :                 wr32m(hw, TXGBE_GPIODIR, TXGBE_GPIOBIT_1, TXGBE_GPIOBIT_1);
    3272                 :          0 :                 esdp_reg |= TXGBE_GPIOBIT_1;
    3273                 :            :         } else {
    3274                 :          0 :                 esdp_reg &= ~(TXGBE_GPIOBIT_0 | TXGBE_GPIOBIT_1);
    3275                 :            :         }
    3276                 :            :         wr32(hw, TXGBE_GPIODATA, esdp_reg);
    3277                 :            :         txgbe_flush(hw);
    3278                 :            :         msec_delay(100);
    3279                 :          0 : }
    3280                 :            : 
    3281                 :            : /**
    3282                 :            :  *  txgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser
    3283                 :            :  *  @hw: pointer to hardware structure
    3284                 :            :  *
    3285                 :            :  *  When the driver changes the link speeds that it can support,
    3286                 :            :  *  it sets autotry_restart to true to indicate that we need to
    3287                 :            :  *  initiate a new autotry session with the link partner.  To do
    3288                 :            :  *  so, we set the speed then disable and re-enable the Tx laser, to
    3289                 :            :  *  alert the link partner that it also needs to restart autotry on its
    3290                 :            :  *  end.  This is consistent with true clause 37 autoneg, which also
    3291                 :            :  *  involves a loss of signal.
    3292                 :            :  **/
    3293                 :          0 : void txgbe_flap_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
    3294                 :            : {
    3295         [ #  # ]:          0 :         if (hw->mac.autotry_restart) {
    3296                 :          0 :                 txgbe_disable_tx_laser_multispeed_fiber(hw);
    3297                 :          0 :                 txgbe_enable_tx_laser_multispeed_fiber(hw);
    3298                 :          0 :                 hw->mac.autotry_restart = false;
    3299                 :            :         }
    3300                 :          0 : }
    3301                 :            : 
    3302                 :            : /**
    3303                 :            :  *  txgbe_set_hard_rate_select_speed - Set module link speed
    3304                 :            :  *  @hw: pointer to hardware structure
    3305                 :            :  *  @speed: link speed to set
    3306                 :            :  *
    3307                 :            :  *  Set module link speed via RS0/RS1 rate select pins.
    3308                 :            :  */
    3309                 :          0 : void txgbe_set_hard_rate_select_speed(struct txgbe_hw *hw,
    3310                 :            :                                         u32 speed)
    3311                 :            : {
    3312                 :            :         u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
    3313                 :            : 
    3314   [ #  #  #  # ]:          0 :         switch (speed) {
    3315                 :            :         case TXGBE_LINK_SPEED_25GB_FULL:
    3316                 :            :                 /* amlite-to-do */
    3317                 :            :                 break;
    3318                 :          0 :         case TXGBE_LINK_SPEED_10GB_FULL:
    3319                 :          0 :                 esdp_reg |= (TXGBE_GPIOBIT_4 | TXGBE_GPIOBIT_5);
    3320                 :          0 :                 break;
    3321                 :          0 :         case TXGBE_LINK_SPEED_1GB_FULL:
    3322                 :          0 :                 esdp_reg &= ~(TXGBE_GPIOBIT_4 | TXGBE_GPIOBIT_5);
    3323                 :          0 :                 break;
    3324                 :          0 :         default:
    3325                 :          0 :                 DEBUGOUT("Invalid fixed module speed");
    3326                 :          0 :                 return;
    3327                 :            :         }
    3328                 :            : 
    3329                 :            :         wr32(hw, TXGBE_GPIODATA, esdp_reg);
    3330                 :            :         txgbe_flush(hw);
    3331                 :            : }
    3332                 :            : 
    3333                 :            : /**
    3334                 :            :  *  txgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
    3335                 :            :  *  @hw: pointer to hardware structure
    3336                 :            :  *  @speed: new link speed
    3337                 :            :  *  @autoneg_wait_to_complete: true when waiting for completion is needed
    3338                 :            :  *
    3339                 :            :  *  Implements the Intel SmartSpeed algorithm.
    3340                 :            :  **/
    3341                 :          0 : s32 txgbe_setup_mac_link_smartspeed(struct txgbe_hw *hw,
    3342                 :            :                                     u32 speed,
    3343                 :            :                                     bool autoneg_wait_to_complete)
    3344                 :            : {
    3345                 :            :         s32 status = 0;
    3346                 :          0 :         u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
    3347                 :            :         s32 i, j;
    3348                 :          0 :         bool link_up = false;
    3349                 :            :         u32 autoc_reg = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);
    3350                 :            : 
    3351                 :            :          /* Set autoneg_advertised value based on input link speed */
    3352                 :          0 :         hw->phy.autoneg_advertised = 0;
    3353                 :            : 
    3354         [ #  # ]:          0 :         if (speed & TXGBE_LINK_SPEED_10GB_FULL)
    3355                 :          0 :                 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
    3356                 :            : 
    3357         [ #  # ]:          0 :         if (speed & TXGBE_LINK_SPEED_1GB_FULL)
    3358                 :          0 :                 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;
    3359                 :            : 
    3360         [ #  # ]:          0 :         if (speed & TXGBE_LINK_SPEED_100M_FULL)
    3361                 :          0 :                 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_100M_FULL;
    3362                 :            : 
    3363                 :            :         /*
    3364                 :            :          * Implement Intel SmartSpeed algorithm.  SmartSpeed will reduce the
    3365                 :            :          * autoneg advertisement if link is unable to be established at the
    3366                 :            :          * highest negotiated rate.  This can sometimes happen due to integrity
    3367                 :            :          * issues with the physical media connection.
    3368                 :            :          */
    3369                 :            : 
    3370                 :            :         /* First, try to get link with full advertisement */
    3371                 :          0 :         hw->phy.smart_speed_active = false;
    3372         [ #  # ]:          0 :         for (j = 0; j < TXGBE_SMARTSPEED_MAX_RETRIES; j++) {
    3373                 :          0 :                 status = txgbe_setup_mac_link(hw, speed,
    3374                 :            :                                                     autoneg_wait_to_complete);
    3375         [ #  # ]:          0 :                 if (status != 0)
    3376                 :          0 :                         goto out;
    3377                 :            : 
    3378                 :            :                 /*
    3379                 :            :                  * Wait for the controller to acquire link.  Per IEEE 802.3ap,
    3380                 :            :                  * Section 73.10.2, we may have to wait up to 500ms if KR is
    3381                 :            :                  * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
    3382                 :            :                  * Table 9 in the AN MAS.
    3383                 :            :                  */
    3384         [ #  # ]:          0 :                 for (i = 0; i < 5; i++) {
    3385                 :            :                         msec_delay(100);
    3386                 :            : 
    3387                 :            :                         /* If we have link, just jump out */
    3388                 :          0 :                         status = hw->mac.check_link(hw, &link_speed, &link_up,
    3389                 :            :                                                   false);
    3390         [ #  # ]:          0 :                         if (status != 0)
    3391                 :          0 :                                 goto out;
    3392                 :            : 
    3393         [ #  # ]:          0 :                         if (link_up)
    3394                 :          0 :                                 goto out;
    3395                 :            :                 }
    3396                 :            :         }
    3397                 :            : 
    3398                 :            :         /*
    3399                 :            :          * We didn't get link.  If we advertised KR plus one of KX4/KX
    3400                 :            :          * (or BX4/BX), then disable KR and try again.
    3401                 :            :          */
    3402   [ #  #  #  # ]:          0 :         if (((autoc_reg & TXGBE_AUTOC_KR_SUPP) == 0) ||
    3403                 :          0 :             ((autoc_reg & TXGBE_AUTOC_KX_SUPP) == 0 &&
    3404         [ #  # ]:          0 :              (autoc_reg & TXGBE_AUTOC_KX4_SUPP) == 0))
    3405                 :          0 :                 goto out;
    3406                 :            : 
    3407                 :            :         /* Turn SmartSpeed on to disable KR support */
    3408                 :          0 :         hw->phy.smart_speed_active = true;
    3409                 :          0 :         status = txgbe_setup_mac_link(hw, speed,
    3410                 :            :                                             autoneg_wait_to_complete);
    3411         [ #  # ]:          0 :         if (status != 0)
    3412                 :          0 :                 goto out;
    3413                 :            : 
    3414                 :            :         /*
    3415                 :            :          * Wait for the controller to acquire link.  600ms will allow for
    3416                 :            :          * the AN link_fail_inhibit_timer as well for multiple cycles of
    3417                 :            :          * parallel detect, both 10g and 1g. This allows for the maximum
    3418                 :            :          * connect attempts as defined in the AN MAS table 73-7.
    3419                 :            :          */
    3420         [ #  # ]:          0 :         for (i = 0; i < 6; i++) {
    3421                 :            :                 msec_delay(100);
    3422                 :            : 
    3423                 :            :                 /* If we have link, just jump out */
    3424                 :          0 :                 status = hw->mac.check_link(hw, &link_speed, &link_up, false);
    3425         [ #  # ]:          0 :                 if (status != 0)
    3426                 :          0 :                         goto out;
    3427                 :            : 
    3428         [ #  # ]:          0 :                 if (link_up)
    3429                 :          0 :                         goto out;
    3430                 :            :         }
    3431                 :            : 
    3432                 :            :         /* We didn't get link.  Turn SmartSpeed back off. */
    3433                 :          0 :         hw->phy.smart_speed_active = false;
    3434                 :          0 :         status = txgbe_setup_mac_link(hw, speed,
    3435                 :            :                                             autoneg_wait_to_complete);
    3436                 :            : 
    3437                 :          0 : out:
    3438   [ #  #  #  # ]:          0 :         if (link_up && link_speed == TXGBE_LINK_SPEED_1GB_FULL)
    3439                 :          0 :                 DEBUGOUT("Smartspeed has downgraded the link speed from the maximum advertised");
    3440                 :          0 :         return status;
    3441                 :            : }
    3442                 :            : 
    3443                 :            : /**
    3444                 :            :  *  txgbe_setup_mac_link - Set MAC link speed
    3445                 :            :  *  @hw: pointer to hardware structure
    3446                 :            :  *  @speed: new link speed
    3447                 :            :  *  @autoneg_wait_to_complete: true when waiting for completion is needed
    3448                 :            :  *
    3449                 :            :  *  Set the link speed in the AUTOC register and restarts link.
    3450                 :            :  **/
    3451                 :          0 : s32 txgbe_setup_mac_link(struct txgbe_hw *hw,
    3452                 :            :                                u32 speed,
    3453                 :            :                                bool autoneg_wait_to_complete)
    3454                 :            : {
    3455                 :          0 :         bool autoneg = false;
    3456                 :            :         s32 status = 0;
    3457                 :            : 
    3458                 :          0 :         u64 autoc = hw->mac.autoc_read(hw);
    3459                 :          0 :         u64 pma_pmd_10gs = autoc & TXGBE_AUTOC_10GS_PMA_PMD_MASK;
    3460                 :          0 :         u64 pma_pmd_1g = autoc & TXGBE_AUTOC_1G_PMA_PMD_MASK;
    3461                 :          0 :         u64 link_mode = autoc & TXGBE_AUTOC_LMS_MASK;
    3462                 :            :         u64 orig_autoc = 0;
    3463                 :          0 :         u32 link_capabilities = TXGBE_LINK_SPEED_UNKNOWN;
    3464                 :            : 
    3465                 :            :         UNREFERENCED_PARAMETER(autoneg_wait_to_complete);
    3466                 :            : 
    3467                 :            :         /* Check to see if speed passed in is supported. */
    3468                 :          0 :         status = hw->mac.get_link_capabilities(hw,
    3469                 :            :                         &link_capabilities, &autoneg);
    3470         [ #  # ]:          0 :         if (status)
    3471                 :            :                 return status;
    3472                 :            : 
    3473                 :          0 :         speed &= link_capabilities;
    3474         [ #  # ]:          0 :         if (speed == TXGBE_LINK_SPEED_UNKNOWN)
    3475                 :            :                 return TXGBE_ERR_LINK_SETUP;
    3476                 :            : 
    3477                 :            :         /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
    3478         [ #  # ]:          0 :         if (hw->mac.orig_link_settings_stored)
    3479                 :          0 :                 orig_autoc = hw->mac.orig_autoc;
    3480                 :            :         else
    3481                 :            :                 orig_autoc = autoc;
    3482                 :            : 
    3483                 :            :         link_mode = autoc & TXGBE_AUTOC_LMS_MASK;
    3484                 :            :         pma_pmd_1g = autoc & TXGBE_AUTOC_1G_PMA_PMD_MASK;
    3485                 :            : 
    3486                 :          0 :         if (link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR ||
    3487   [ #  #  #  # ]:          0 :             link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
    3488                 :            :             link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
    3489                 :            :                 /* Set KX4/KX/KR support according to speed requested */
    3490                 :          0 :                 autoc &= ~(TXGBE_AUTOC_KX_SUPP |
    3491                 :            :                            TXGBE_AUTOC_KX4_SUPP |
    3492                 :            :                            TXGBE_AUTOC_KR_SUPP);
    3493         [ #  # ]:          0 :                 if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
    3494         [ #  # ]:          0 :                         if (orig_autoc & TXGBE_AUTOC_KX4_SUPP)
    3495                 :          0 :                                 autoc |= TXGBE_AUTOC_KX4_SUPP;
    3496         [ #  # ]:          0 :                         if (orig_autoc & TXGBE_AUTOC_KR_SUPP)
    3497                 :          0 :                                 autoc |= TXGBE_AUTOC_KR_SUPP;
    3498                 :            :                 }
    3499         [ #  # ]:          0 :                 if (speed & TXGBE_LINK_SPEED_1GB_FULL)
    3500                 :          0 :                         autoc |= TXGBE_AUTOC_KX_SUPP;
    3501         [ #  # ]:          0 :         } else if ((pma_pmd_1g == TXGBE_AUTOC_1G_SFI) &&
    3502                 :          0 :                    (link_mode == TXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
    3503         [ #  # ]:          0 :                     link_mode == TXGBE_AUTOC_LMS_1G_AN)) {
    3504                 :            :                 /* Switch from 1G SFI to 10G SFI if requested */
    3505                 :          0 :                 if (speed == TXGBE_LINK_SPEED_10GB_FULL &&
    3506         [ #  # ]:          0 :                     pma_pmd_10gs == TXGBE_AUTOC_10GS_SFI) {
    3507                 :          0 :                         autoc &= ~TXGBE_AUTOC_LMS_MASK;
    3508                 :          0 :                         autoc |= TXGBE_AUTOC_LMS_10G;
    3509                 :            :                 }
    3510                 :          0 :         } else if ((pma_pmd_10gs == TXGBE_AUTOC_10GS_SFI) &&
    3511         [ #  # ]:          0 :                    (link_mode == TXGBE_AUTOC_LMS_10G)) {
    3512                 :            :                 /* Switch from 10G SFI to 1G SFI if requested */
    3513                 :          0 :                 if (speed == TXGBE_LINK_SPEED_1GB_FULL &&
    3514         [ #  # ]:          0 :                     pma_pmd_1g == TXGBE_AUTOC_1G_SFI) {
    3515                 :          0 :                         autoc &= ~TXGBE_AUTOC_LMS_MASK;
    3516   [ #  #  #  # ]:          0 :                         if (autoneg || hw->phy.type == txgbe_phy_qsfp_intel)
    3517                 :          0 :                                 autoc |= TXGBE_AUTOC_LMS_1G_AN;
    3518                 :            :                         else
    3519                 :            :                                 autoc |= TXGBE_AUTOC_LMS_1G_LINK_NO_AN;
    3520                 :            :                 }
    3521                 :            :         }
    3522                 :            : 
    3523                 :          0 :         autoc &= ~TXGBE_AUTOC_SPEED_MASK;
    3524                 :          0 :         autoc |= TXGBE_AUTOC_SPEED(speed);
    3525                 :          0 :         autoc &= ~TXGBE_AUTOC_AUTONEG;
    3526         [ #  # ]:          0 :         autoc |= (autoneg ? TXGBE_AUTOC_AUTONEG : 0);
    3527                 :            : 
    3528                 :            :         /* Restart link */
    3529                 :          0 :         hw->mac.autoc_write(hw, autoc);
    3530                 :            : 
    3531                 :            :         /* Add delay to filter out noises during initial link setup */
    3532                 :            :         msec_delay(50);
    3533                 :            : 
    3534                 :          0 :         return status;
    3535                 :            : }
    3536                 :            : 
    3537                 :            : /**
    3538                 :            :  *  txgbe_setup_copper_link_raptor - Set the PHY autoneg advertised field
    3539                 :            :  *  @hw: pointer to hardware structure
    3540                 :            :  *  @speed: new link speed
    3541                 :            :  *  @autoneg_wait_to_complete: true if waiting is needed to complete
    3542                 :            :  *
    3543                 :            :  *  Restarts link on PHY and MAC based on settings passed in.
    3544                 :            :  **/
    3545                 :          0 : static s32 txgbe_setup_copper_link_raptor(struct txgbe_hw *hw,
    3546                 :            :                                          u32 speed,
    3547                 :            :                                          bool autoneg_wait_to_complete)
    3548                 :            : {
    3549                 :            :         s32 status;
    3550                 :            : 
    3551                 :            :         /* Setup the PHY according to input speed */
    3552                 :          0 :         status = hw->phy.setup_link_speed(hw, speed,
    3553                 :            :                                               autoneg_wait_to_complete);
    3554                 :            :         /* Set up MAC */
    3555                 :          0 :         txgbe_start_mac_link_raptor(hw, autoneg_wait_to_complete);
    3556                 :            : 
    3557                 :          0 :         return status;
    3558                 :            : }
    3559                 :            : 
    3560                 :            : static int
    3561                 :          0 : txgbe_check_flash_load(struct txgbe_hw *hw, u32 check_bit)
    3562                 :            : {
    3563                 :            :         u32 reg = 0;
    3564                 :            :         u32 i;
    3565                 :            :         int err = 0;
    3566                 :            :         /* if there's flash existing */
    3567         [ #  # ]:          0 :         if (!(rd32(hw, TXGBE_SPISTAT) & TXGBE_SPISTAT_BPFLASH)) {
    3568                 :            :                 /* wait hw load flash done */
    3569         [ #  # ]:          0 :                 for (i = 0; i < 10; i++) {
    3570                 :            :                         reg = rd32(hw, TXGBE_ILDRSTAT);
    3571         [ #  # ]:          0 :                         if (!(reg & check_bit)) {
    3572                 :            :                                 /* done */
    3573                 :            :                                 break;
    3574                 :            :                         }
    3575                 :            :                         msleep(100);
    3576                 :            :                 }
    3577         [ #  # ]:          0 :                 if (i == 10)
    3578                 :            :                         err = TXGBE_ERR_FLASH_LOADING_FAILED;
    3579                 :            :         }
    3580                 :          0 :         return err;
    3581                 :            : }
    3582                 :            : 
    3583                 :          0 : int txgbe_reconfig_mac(struct txgbe_hw *hw)
    3584                 :            : {
    3585                 :            :         u32 mac_wdg_timeout;
    3586                 :            :         u32 mac_flow_ctrl;
    3587                 :            : 
    3588                 :            :         mac_wdg_timeout = rd32(hw, TXGBE_MAC_WDG_TIMEOUT);
    3589                 :            :         mac_flow_ctrl = rd32(hw, TXGBE_RXFCCFG);
    3590                 :            : 
    3591         [ #  # ]:          0 :         if (hw->bus.lan_id == 0)
    3592                 :            :                 wr32(hw, TXGBE_RST, TXGBE_RST_MAC_LAN_0);
    3593         [ #  # ]:          0 :         else if (hw->bus.lan_id == 1)
    3594                 :            :                 wr32(hw, TXGBE_RST, TXGBE_RST_MAC_LAN_1);
    3595                 :            : 
    3596                 :            :         /* wait for mac reset complete */
    3597                 :          0 :         usec_delay(1500);
    3598                 :            :         wr32m(hw, TXGBE_MAC_MISC_CTL, TXGBE_MAC_MISC_LINK_STS_MOD,
    3599                 :            :                 TXGBE_LINK_BOTH_PCS_MAC);
    3600                 :            : 
    3601                 :            :         /* receive packets that size > 2048 */
    3602                 :            :         wr32m(hw, TXGBE_MACRXCFG,
    3603                 :            :                 TXGBE_MACRXCFG_JUMBO, TXGBE_MACRXCFG_JUMBO);
    3604                 :            : 
    3605                 :            :         /* clear counters on read */
    3606                 :            :         wr32m(hw, TXGBE_MACCNTCTL,
    3607                 :            :                 TXGBE_MACCNTCTL_RC, TXGBE_MACCNTCTL_RC);
    3608                 :            : 
    3609                 :            :         wr32m(hw, TXGBE_RXFCCFG,
    3610                 :            :                 TXGBE_RXFCCFG_FC, TXGBE_RXFCCFG_FC);
    3611                 :            : 
    3612                 :            :         wr32(hw, TXGBE_MACRXFLT, TXGBE_MACRXFLT_PROMISC);
    3613                 :            : 
    3614                 :            :         wr32(hw, TXGBE_MAC_WDG_TIMEOUT, mac_wdg_timeout);
    3615                 :            :         wr32(hw, TXGBE_RXFCCFG, mac_flow_ctrl);
    3616                 :            : 
    3617                 :          0 :         return 0;
    3618                 :            : }
    3619                 :            : 
    3620                 :            : static void
    3621                 :          0 : txgbe_reset_misc(struct txgbe_hw *hw)
    3622                 :            : {
    3623                 :            :         int i;
    3624                 :            :         u32 value;
    3625                 :            :         int err = 0;
    3626                 :            :         u32 speed;
    3627                 :            : 
    3628                 :          0 :         wr32(hw, TXGBE_ISBADDRL, hw->isb_dma & 0x00000000FFFFFFFF);
    3629                 :          0 :         wr32(hw, TXGBE_ISBADDRH, hw->isb_dma >> 32);
    3630                 :            : 
    3631         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_aml) {
    3632         [ #  # ]:          0 :                 if ((rd32(hw, TXGBE_EPHY_STAT) & TXGBE_EPHY_STAT_PPL_LOCK)
    3633                 :            :                                                 != TXGBE_EPHY_STAT_PPL_LOCK) {
    3634                 :            :                         speed = TXGBE_LINK_SPEED_25GB_FULL
    3635                 :            :                               | TXGBE_LINK_SPEED_10GB_FULL;
    3636                 :          0 :                         err = hw->mac.setup_link(hw, speed, false);
    3637         [ #  # ]:          0 :                         if (err) {
    3638                 :          0 :                                 DEBUGOUT("setup phy failed");
    3639                 :          0 :                                 return;
    3640                 :            :                         }
    3641                 :            :                 }
    3642         [ #  # ]:          0 :         } else if (hw->mac.type == txgbe_mac_aml40) {
    3643         [ #  # ]:          0 :                 if (!(rd32(hw, TXGBE_EPHY_STAT) & TXGBE_EPHY_STAT_PPL_LOCK)) {
    3644                 :            :                         speed = TXGBE_LINK_SPEED_40GB_FULL;
    3645                 :          0 :                         err = hw->mac.setup_link(hw, speed, false);
    3646         [ #  # ]:          0 :                         if (err) {
    3647                 :          0 :                                 DEBUGOUT("setup phy failed");
    3648                 :          0 :                                 return;
    3649                 :            :                         }
    3650                 :            :                 }
    3651                 :            :         } else {
    3652                 :            :                 value = rd32_epcs(hw, SR_XS_PCS_CTRL2);
    3653         [ #  # ]:          0 :                 if ((value & 0x3) != SR_PCS_CTRL2_TYPE_SEL_X)
    3654                 :          0 :                         hw->link_status = TXGBE_LINK_STATUS_NONE;
    3655                 :            :         }
    3656                 :            : 
    3657                 :            :         /* receive packets that size > 2048 */
    3658                 :            :         wr32m(hw, TXGBE_MACRXCFG,
    3659                 :            :                 TXGBE_MACRXCFG_JUMBO, TXGBE_MACRXCFG_JUMBO);
    3660                 :            : 
    3661                 :            :         wr32m(hw, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK,
    3662                 :            :                 TXGBE_FRMSZ_MAX(TXGBE_FRAME_SIZE_DFT));
    3663                 :            : 
    3664                 :            :         /* clear counters on read */
    3665                 :            :         wr32m(hw, TXGBE_MACCNTCTL,
    3666                 :            :                 TXGBE_MACCNTCTL_RC, TXGBE_MACCNTCTL_RC);
    3667                 :            : 
    3668                 :            :         wr32m(hw, TXGBE_RXFCCFG,
    3669                 :            :                 TXGBE_RXFCCFG_FC, TXGBE_RXFCCFG_FC);
    3670                 :            :         wr32m(hw, TXGBE_TXFCCFG,
    3671                 :            :                 TXGBE_TXFCCFG_FC, TXGBE_TXFCCFG_FC);
    3672                 :            : 
    3673                 :            :         wr32m(hw, TXGBE_MACRXFLT,
    3674                 :            :                 TXGBE_MACRXFLT_PROMISC, TXGBE_MACRXFLT_PROMISC);
    3675                 :            : 
    3676                 :            :         wr32m(hw, TXGBE_RSTSTAT,
    3677                 :            :                 TXGBE_RSTSTAT_TMRINIT_MASK, TXGBE_RSTSTAT_TMRINIT(30));
    3678                 :            : 
    3679                 :            :         /* errata 4: initialize mng flex tbl and wakeup flex tbl*/
    3680                 :            :         wr32(hw, TXGBE_MNGFLEXSEL, 0);
    3681         [ #  # ]:          0 :         for (i = 0; i < 16; i++) {
    3682                 :          0 :                 wr32(hw, TXGBE_MNGFLEXDWL(i), 0);
    3683                 :          0 :                 wr32(hw, TXGBE_MNGFLEXDWH(i), 0);
    3684                 :          0 :                 wr32(hw, TXGBE_MNGFLEXMSK(i), 0);
    3685                 :            :         }
    3686                 :            :         wr32(hw, TXGBE_LANFLEXSEL, 0);
    3687         [ #  # ]:          0 :         for (i = 0; i < 16; i++) {
    3688                 :          0 :                 wr32(hw, TXGBE_LANFLEXDWL(i), 0);
    3689                 :          0 :                 wr32(hw, TXGBE_LANFLEXDWH(i), 0);
    3690                 :          0 :                 wr32(hw, TXGBE_LANFLEXMSK(i), 0);
    3691                 :            :         }
    3692                 :            : 
    3693                 :            :         /* set pause frame dst mac addr */
    3694                 :            :         wr32(hw, TXGBE_RXPBPFCDMACL, 0xC2000001);
    3695                 :            :         wr32(hw, TXGBE_RXPBPFCDMACH, 0x0180);
    3696                 :            : 
    3697                 :          0 :         hw->mac.init_thermal_sensor_thresh(hw);
    3698                 :            : 
    3699                 :            :         /* enable mac transmitter */
    3700                 :            :         wr32m(hw, TXGBE_MACTXCFG, TXGBE_MACTXCFG_TXE, TXGBE_MACTXCFG_TXE);
    3701                 :            : 
    3702                 :          0 :         hw->mac.autoc = hw->mac.orig_autoc;
    3703         [ #  # ]:          0 :         for (i = 0; i < 4; i++)
    3704                 :          0 :                 wr32m(hw, TXGBE_IVAR(i), 0x80808080, 0);
    3705                 :            : }
    3706                 :            : 
    3707                 :            : /**
    3708                 :            :  *  txgbe_reset_hw - Perform hardware reset
    3709                 :            :  *  @hw: pointer to hardware structure
    3710                 :            :  *
    3711                 :            :  *  Resets the hardware by resetting the transmit and receive units, masks
    3712                 :            :  *  and clears all interrupts, perform a PHY reset, and perform a link (MAC)
    3713                 :            :  *  reset.
    3714                 :            :  **/
    3715                 :          0 : s32 txgbe_reset_hw(struct txgbe_hw *hw)
    3716                 :            : {
    3717                 :            :         s32 status;
    3718                 :            :         u32 autoc = 0;
    3719                 :            : 
    3720                 :            :         /* Call adapter stop to disable tx/rx and clear interrupts */
    3721                 :          0 :         status = hw->mac.stop_hw(hw);
    3722         [ #  # ]:          0 :         if (status != 0)
    3723                 :            :                 return status;
    3724                 :            : 
    3725                 :            :         /* flush pending Tx transactions */
    3726                 :          0 :         txgbe_clear_tx_pending(hw);
    3727                 :            : 
    3728                 :            :         /* Identify PHY and related function pointers */
    3729                 :          0 :         status = hw->phy.init(hw);
    3730         [ #  # ]:          0 :         if (status == TXGBE_ERR_SFP_NOT_SUPPORTED)
    3731                 :            :                 return status;
    3732                 :            : 
    3733                 :            :         /* Setup SFP module if there is one present. */
    3734         [ #  # ]:          0 :         if (hw->phy.sfp_setup_needed) {
    3735                 :          0 :                 status = hw->mac.setup_sfp(hw);
    3736                 :          0 :                 hw->phy.sfp_setup_needed = false;
    3737                 :            :         }
    3738         [ #  # ]:          0 :         if (status == TXGBE_ERR_SFP_NOT_SUPPORTED)
    3739                 :            :                 return status;
    3740                 :            : 
    3741                 :            :         /* Reset PHY */
    3742         [ #  # ]:          0 :         if (!hw->phy.reset_disable)
    3743                 :          0 :                 hw->phy.reset(hw);
    3744                 :            : 
    3745         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_sp) {
    3746                 :            :                 /* remember AUTOC from before we reset */
    3747                 :          0 :                 autoc = hw->mac.autoc_read(hw);
    3748                 :            :         }
    3749                 :            : 
    3750                 :          0 : mac_reset_top:
    3751                 :            :         /* Do LAN reset, the MNG domain will not be reset. */
    3752                 :          0 :         wr32(hw, TXGBE_RST, TXGBE_RST_LAN(hw->bus.lan_id));
    3753                 :            :         txgbe_flush(hw);
    3754                 :          0 :         usec_delay(10);
    3755                 :            : 
    3756                 :          0 :         txgbe_reset_misc(hw);
    3757                 :            : 
    3758         [ #  # ]:          0 :         if (hw->bus.lan_id == 0) {
    3759                 :          0 :                 status = txgbe_check_flash_load(hw,
    3760                 :            :                                 TXGBE_ILDRSTAT_SWRST_LAN0);
    3761                 :            :         } else {
    3762                 :          0 :                 status = txgbe_check_flash_load(hw,
    3763                 :            :                                 TXGBE_ILDRSTAT_SWRST_LAN1);
    3764                 :            :         }
    3765         [ #  # ]:          0 :         if (status != 0)
    3766                 :          0 :                 return status;
    3767                 :            : 
    3768                 :            :         msec_delay(50);
    3769                 :            : 
    3770                 :            :         /*
    3771                 :            :          * Double resets are required for recovery from certain error
    3772                 :            :          * conditions.  Between resets, it is necessary to stall to
    3773                 :            :          * allow time for any pending HW events to complete.
    3774                 :            :          */
    3775         [ #  # ]:          0 :         if (hw->mac.flags & TXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
    3776                 :          0 :                 hw->mac.flags &= ~TXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
    3777                 :          0 :                 goto mac_reset_top;
    3778                 :            :         }
    3779                 :            : 
    3780                 :            :         /* amlite TODO*/
    3781         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_aml || hw->mac.type == txgbe_mac_aml40) {
    3782                 :            :                 wr32(hw, TXGBE_LINKUP_FILTER, 30);
    3783                 :            :                 wr32m(hw, TXGBE_MAC_MISC_CTL, TXGBE_MAC_MISC_LINK_STS_MOD,
    3784                 :            :                           TXGBE_LINK_BOTH_PCS_MAC);
    3785                 :            :                 /* amlite: bme */
    3786                 :            :                 wr32(hw, TXGBE_PX_PF_BME, TXGBE_PX_PF_BME_EN);
    3787                 :            :                 /* amlite: rdm_rsc_ctl_free_ctl set to 1 */
    3788                 :            :                 wr32m(hw, TXGBE_RDM_RSC_CTL, TXGBE_RDM_RSC_CTL_FREE_CTL,
    3789                 :            :                           TXGBE_RDM_RSC_CTL_FREE_CTL);
    3790                 :            :         } else {
    3791                 :            :                 /*
    3792                 :            :                  * Store the original AUTOC/AUTOC2 values if they have not been
    3793                 :            :                  * stored off yet.  Otherwise restore the stored original
    3794                 :            :                  * values since the reset operation sets back to defaults.
    3795                 :            :                  */
    3796         [ #  # ]:          0 :                 if (!hw->mac.orig_link_settings_stored) {
    3797                 :          0 :                         hw->mac.orig_autoc = hw->mac.autoc_read(hw);
    3798                 :          0 :                         hw->mac.orig_link_settings_stored = true;
    3799                 :            :                 } else {
    3800                 :          0 :                         hw->mac.orig_autoc = autoc;
    3801                 :            :                 }
    3802                 :            :         }
    3803                 :            : 
    3804         [ #  # ]:          0 :         if (hw->phy.ffe_set) {
    3805                 :            :                 /* Make sure phy power is up */
    3806                 :            :                 msec_delay(50);
    3807                 :            : 
    3808                 :            :                 /* A temporary solution to set phy */
    3809         [ #  # ]:          0 :                 if (hw->mac.type == txgbe_mac_sp)
    3810                 :          0 :                         txgbe_set_phy_temp(hw);
    3811                 :            :         }
    3812                 :            : 
    3813                 :            :         /* Store the permanent mac address */
    3814                 :          0 :         hw->mac.get_mac_addr(hw, hw->mac.perm_addr);
    3815                 :            : 
    3816                 :            :         /*
    3817                 :            :          * Store MAC address from RAR0, clear receive address registers, and
    3818                 :            :          * clear the multicast table.  Also reset num_rar_entries to 128,
    3819                 :            :          * since we modify this value when programming the SAN MAC address.
    3820                 :            :          */
    3821                 :          0 :         hw->mac.num_rar_entries = 128;
    3822                 :          0 :         hw->mac.init_rx_addrs(hw);
    3823                 :            : 
    3824                 :            :         /* Store the permanent SAN mac address */
    3825                 :          0 :         hw->mac.get_san_mac_addr(hw, hw->mac.san_addr);
    3826                 :            : 
    3827                 :            :         /* Add the SAN MAC address to the RAR only if it's a valid address */
    3828         [ #  # ]:          0 :         if (txgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
    3829                 :            :                 /* Save the SAN MAC RAR index */
    3830                 :          0 :                 hw->mac.san_mac_rar_index = hw->mac.num_rar_entries - 1;
    3831                 :            : 
    3832                 :          0 :                 hw->mac.set_rar(hw, hw->mac.san_mac_rar_index,
    3833                 :            :                                     hw->mac.san_addr, 0, true);
    3834                 :            : 
    3835                 :            :                 /* clear VMDq pool/queue selection for this RAR */
    3836                 :          0 :                 hw->mac.clear_vmdq(hw, hw->mac.san_mac_rar_index,
    3837                 :            :                                        BIT_MASK32);
    3838                 :            : 
    3839                 :            :                 /* Reserve the last RAR for the SAN MAC address */
    3840                 :          0 :                 hw->mac.num_rar_entries--;
    3841                 :            :         }
    3842                 :            : 
    3843                 :            :         /* Store the alternative WWNN/WWPN prefix */
    3844                 :          0 :         hw->mac.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
    3845                 :            :                                    &hw->mac.wwpn_prefix);
    3846                 :            : 
    3847                 :          0 :         return status;
    3848                 :            : }
    3849                 :            : 
    3850                 :            : /**
    3851                 :            :  * txgbe_fdir_check_cmd_complete - poll to check whether FDIRPICMD is complete
    3852                 :            :  * @hw: pointer to hardware structure
    3853                 :            :  * @fdircmd: current value of FDIRCMD register
    3854                 :            :  */
    3855                 :            : static s32 txgbe_fdir_check_cmd_complete(struct txgbe_hw *hw, u32 *fdircmd)
    3856                 :            : {
    3857                 :            :         int i;
    3858                 :            : 
    3859         [ #  # ]:          0 :         for (i = 0; i < TXGBE_FDIRCMD_CMD_POLL; i++) {
    3860                 :            :                 *fdircmd = rd32(hw, TXGBE_FDIRPICMD);
    3861         [ #  # ]:          0 :                 if (!(*fdircmd & TXGBE_FDIRPICMD_OP_MASK))
    3862                 :            :                         return 0;
    3863                 :          0 :                 usec_delay(10);
    3864                 :            :         }
    3865                 :            : 
    3866                 :            :         return TXGBE_ERR_FDIR_CMD_INCOMPLETE;
    3867                 :            : }
    3868                 :            : 
    3869                 :            : /**
    3870                 :            :  *  txgbe_reinit_fdir_tables - Reinitialize Flow Director tables.
    3871                 :            :  *  @hw: pointer to hardware structure
    3872                 :            :  **/
    3873                 :          0 : s32 txgbe_reinit_fdir_tables(struct txgbe_hw *hw)
    3874                 :            : {
    3875                 :            :         s32 err;
    3876                 :            :         int i;
    3877                 :            :         u32 fdirctrl = rd32(hw, TXGBE_FDIRCTL);
    3878                 :            :         u32 fdircmd;
    3879                 :          0 :         fdirctrl &= ~TXGBE_FDIRCTL_INITDONE;
    3880                 :            : 
    3881                 :            :         /*
    3882                 :            :          * Before starting reinitialization process,
    3883                 :            :          * FDIRPICMD.OP must be zero.
    3884                 :            :          */
    3885                 :            :         err = txgbe_fdir_check_cmd_complete(hw, &fdircmd);
    3886         [ #  # ]:          0 :         if (err) {
    3887                 :          0 :                 DEBUGOUT("Flow Director previous command did not complete, aborting table re-initialization.");
    3888                 :          0 :                 return err;
    3889                 :            :         }
    3890                 :            : 
    3891                 :            :         wr32(hw, TXGBE_FDIRFREE, 0);
    3892                 :            :         txgbe_flush(hw);
    3893                 :            :         /*
    3894                 :            :          * adapters flow director init flow cannot be restarted,
    3895                 :            :          * Workaround silicon errata by performing the following steps
    3896                 :            :          * before re-writing the FDIRCTL control register with the same value.
    3897                 :            :          * - write 1 to bit 8 of FDIRPICMD register &
    3898                 :            :          * - write 0 to bit 8 of FDIRPICMD register
    3899                 :            :          */
    3900                 :            :         wr32m(hw, TXGBE_FDIRPICMD, TXGBE_FDIRPICMD_CLR, TXGBE_FDIRPICMD_CLR);
    3901                 :            :         txgbe_flush(hw);
    3902                 :            :         wr32m(hw, TXGBE_FDIRPICMD, TXGBE_FDIRPICMD_CLR, 0);
    3903                 :            :         txgbe_flush(hw);
    3904                 :            :         /*
    3905                 :            :          * Clear FDIR Hash register to clear any leftover hashes
    3906                 :            :          * waiting to be programmed.
    3907                 :            :          */
    3908                 :            :         wr32(hw, TXGBE_FDIRPIHASH, 0x00);
    3909                 :            :         txgbe_flush(hw);
    3910                 :            : 
    3911                 :            :         wr32(hw, TXGBE_FDIRCTL, fdirctrl);
    3912                 :            :         txgbe_flush(hw);
    3913                 :            : 
    3914                 :            :         /* Poll init-done after we write FDIRCTL register */
    3915         [ #  # ]:          0 :         for (i = 0; i < TXGBE_FDIR_INIT_DONE_POLL; i++) {
    3916         [ #  # ]:          0 :                 if (rd32m(hw, TXGBE_FDIRCTL, TXGBE_FDIRCTL_INITDONE))
    3917                 :            :                         break;
    3918                 :            :                 msec_delay(1);
    3919                 :            :         }
    3920         [ #  # ]:          0 :         if (i >= TXGBE_FDIR_INIT_DONE_POLL) {
    3921                 :          0 :                 DEBUGOUT("Flow Director Signature poll time exceeded!");
    3922                 :          0 :                 return TXGBE_ERR_FDIR_REINIT_FAILED;
    3923                 :            :         }
    3924                 :            : 
    3925                 :            :         /* Clear FDIR statistics registers (read to clear) */
    3926                 :            :         rd32(hw, TXGBE_FDIRUSED);
    3927                 :            :         rd32(hw, TXGBE_FDIRFAIL);
    3928                 :            :         rd32(hw, TXGBE_FDIRMATCH);
    3929                 :            :         rd32(hw, TXGBE_FDIRMISS);
    3930                 :            :         rd32(hw, TXGBE_FDIRLEN);
    3931                 :            : 
    3932                 :          0 :         return 0;
    3933                 :            : }
    3934                 :            : 
    3935                 :            : /**
    3936                 :            :  *  txgbe_start_hw_raptor - Prepare hardware for Tx/Rx
    3937                 :            :  *  @hw: pointer to hardware structure
    3938                 :            :  *
    3939                 :            :  *  Starts the hardware using the generic start_hw function
    3940                 :            :  *  and the generation start_hw function.
    3941                 :            :  *  Then performs revision-specific operations, if any.
    3942                 :            :  **/
    3943                 :          0 : s32 txgbe_start_hw_raptor(struct txgbe_hw *hw)
    3944                 :            : {
    3945                 :            :         s32 err = 0;
    3946                 :            : 
    3947                 :          0 :         err = txgbe_start_hw(hw);
    3948         [ #  # ]:          0 :         if (err != 0)
    3949                 :          0 :                 goto out;
    3950                 :            : 
    3951                 :          0 :         err = txgbe_start_hw_gen2(hw);
    3952         [ #  # ]:          0 :         if (err != 0)
    3953                 :          0 :                 goto out;
    3954                 :            : 
    3955                 :            :         /* We need to run link autotry after the driver loads */
    3956                 :          0 :         hw->mac.autotry_restart = true;
    3957                 :            : 
    3958                 :          0 : out:
    3959                 :          0 :         return err;
    3960                 :            : }
    3961                 :            : 
    3962                 :            : /**
    3963                 :            :  *  txgbe_enable_rx_dma_raptor - Enable the Rx DMA unit
    3964                 :            :  *  @hw: pointer to hardware structure
    3965                 :            :  *  @regval: register value to write to RXCTRL
    3966                 :            :  *
    3967                 :            :  *  Enables the Rx DMA unit
    3968                 :            :  **/
    3969                 :          0 : s32 txgbe_enable_rx_dma_raptor(struct txgbe_hw *hw, u32 regval)
    3970                 :            : {
    3971                 :            :         /*
    3972                 :            :          * Workaround silicon errata when enabling the Rx datapath.
    3973                 :            :          * If traffic is incoming before we enable the Rx unit, it could hang
    3974                 :            :          * the Rx DMA unit.  Therefore, make sure the security engine is
    3975                 :            :          * completely disabled prior to enabling the Rx unit.
    3976                 :            :          */
    3977                 :            : 
    3978                 :          0 :         hw->mac.disable_sec_rx_path(hw);
    3979                 :            : 
    3980         [ #  # ]:          0 :         if (regval & TXGBE_PBRXCTL_ENA)
    3981                 :          0 :                 txgbe_enable_rx(hw);
    3982                 :            :         else
    3983                 :          0 :                 txgbe_disable_rx(hw);
    3984                 :            : 
    3985                 :          0 :         hw->mac.enable_sec_rx_path(hw);
    3986                 :            : 
    3987                 :          0 :         return 0;
    3988                 :            : }
    3989                 :            : 
    3990                 :            : /**
    3991                 :            :  *  txgbe_verify_lesm_fw_enabled_raptor - Checks LESM FW module state.
    3992                 :            :  *  @hw: pointer to hardware structure
    3993                 :            :  *
    3994                 :            :  *  Returns true if the LESM FW module is present and enabled. Otherwise
    3995                 :            :  *  returns false. Smart Speed must be disabled if LESM FW module is enabled.
    3996                 :            :  **/
    3997                 :          0 : bool txgbe_verify_lesm_fw_enabled_raptor(struct txgbe_hw *hw)
    3998                 :            : {
    3999                 :            :         bool lesm_enabled = false;
    4000                 :            :         u16 fw_offset, fw_lesm_param_offset, fw_lesm_state;
    4001                 :            :         s32 status;
    4002                 :            : 
    4003                 :            :         /* get the offset to the Firmware Module block */
    4004                 :          0 :         status = hw->rom.read16(hw, TXGBE_FW_PTR, &fw_offset);
    4005                 :            : 
    4006   [ #  #  #  #  :          0 :         if (status != 0 || fw_offset == 0 || fw_offset == 0xFFFF)
                   #  # ]
    4007                 :          0 :                 goto out;
    4008                 :            : 
    4009                 :            :         /* get the offset to the LESM Parameters block */
    4010                 :          0 :         status = hw->rom.read16(hw, (fw_offset +
    4011                 :            :                                      TXGBE_FW_LESM_PARAMETERS_PTR),
    4012                 :            :                                      &fw_lesm_param_offset);
    4013                 :            : 
    4014         [ #  # ]:          0 :         if (status != 0 ||
    4015   [ #  #  #  # ]:          0 :             fw_lesm_param_offset == 0 || fw_lesm_param_offset == 0xFFFF)
    4016                 :          0 :                 goto out;
    4017                 :            : 
    4018                 :            :         /* get the LESM state word */
    4019                 :          0 :         status = hw->rom.read16(hw, (fw_lesm_param_offset +
    4020                 :            :                                      TXGBE_FW_LESM_STATE_1),
    4021                 :            :                                      &fw_lesm_state);
    4022                 :            : 
    4023                 :            :         if (status == 0 && (fw_lesm_state & TXGBE_FW_LESM_STATE_ENABLED))
    4024                 :            :                 lesm_enabled = true;
    4025                 :            : 
    4026                 :          0 : out:
    4027                 :            :         lesm_enabled = false;
    4028                 :          0 :         return lesm_enabled;
    4029                 :            : }
    4030                 :            : 
    4031                 :            : /**
    4032                 :            :  * txgbe_reset_pipeline_raptor - perform pipeline reset
    4033                 :            :  *
    4034                 :            :  *  @hw: pointer to hardware structure
    4035                 :            :  *
    4036                 :            :  * Reset pipeline by asserting Restart_AN together with LMS change to ensure
    4037                 :            :  * full pipeline reset.  This function assumes the SW/FW lock is held.
    4038                 :            :  **/
    4039                 :          0 : s32 txgbe_reset_pipeline_raptor(struct txgbe_hw *hw)
    4040                 :            : {
    4041                 :            :         s32 err = 0;
    4042                 :            :         u64 autoc;
    4043                 :            : 
    4044                 :          0 :         autoc = hw->mac.autoc_read(hw);
    4045                 :            : 
    4046                 :            :         /* Enable link if disabled in NVM */
    4047         [ #  # ]:          0 :         if (autoc & TXGBE_AUTOC_LINK_DIA_MASK)
    4048                 :          0 :                 autoc &= ~TXGBE_AUTOC_LINK_DIA_MASK;
    4049                 :            : 
    4050                 :          0 :         autoc |= TXGBE_AUTOC_AN_RESTART;
    4051                 :            :         /* Write AUTOC register with toggled LMS[2] bit and Restart_AN */
    4052                 :          0 :         hw->mac.autoc_write(hw, autoc ^ TXGBE_AUTOC_LMS_AN);
    4053                 :            : 
    4054                 :            :         /* Write AUTOC register with original LMS field and Restart_AN */
    4055                 :          0 :         hw->mac.autoc_write(hw, autoc);
    4056                 :            :         txgbe_flush(hw);
    4057                 :            : 
    4058                 :          0 :         return err;
    4059                 :            : }
    4060                 :            : 
    4061                 :          0 : s32 txgbe_e56_check_phy_link(struct txgbe_hw *hw, u32 *speed,
    4062                 :            :                                 bool *link_up)
    4063                 :            : {
    4064                 :            :         u32 rdata = 0;
    4065                 :            :         u32 links_reg = 0;
    4066                 :            : 
    4067                 :            :         /* must read it twice because the state may
    4068                 :            :          * not be correct the first time you read it
    4069                 :            :          */
    4070                 :            :         rdata = rd32_epcs(hw, 0x30001);
    4071                 :            :         rdata = rd32_epcs(hw, 0x30001);
    4072                 :            : 
    4073         [ #  # ]:          0 :         if (rdata & TXGBE_AML_PHY_LINK_UP)
    4074                 :          0 :                 *link_up = true;
    4075                 :            :         else
    4076                 :          0 :                 *link_up = false;
    4077                 :            : 
    4078                 :            :         links_reg = rd32(hw, TXGBE_PORTSTAT);
    4079         [ #  # ]:          0 :         if (*link_up) {
    4080         [ #  # ]:          0 :                 if ((links_reg & TXGBE_CFG_PORT_ST_AML_LINK_40G) ==
    4081                 :            :                                 TXGBE_CFG_PORT_ST_AML_LINK_40G)
    4082                 :          0 :                         *speed = TXGBE_LINK_SPEED_40GB_FULL;
    4083         [ #  # ]:          0 :                 else if ((links_reg & TXGBE_CFG_PORT_ST_AML_LINK_25G) ==
    4084                 :            :                                 TXGBE_CFG_PORT_ST_AML_LINK_25G)
    4085                 :          0 :                         *speed = TXGBE_LINK_SPEED_25GB_FULL;
    4086         [ #  # ]:          0 :                 else if ((links_reg & TXGBE_CFG_PORT_ST_AML_LINK_10G) ==
    4087                 :            :                                 TXGBE_CFG_PORT_ST_AML_LINK_10G)
    4088                 :          0 :                         *speed = TXGBE_LINK_SPEED_10GB_FULL;
    4089                 :            :         } else {
    4090                 :          0 :                 *speed = TXGBE_LINK_SPEED_UNKNOWN;
    4091                 :            :         }
    4092                 :            : 
    4093                 :          0 :         return 0;
    4094                 :            : }

Generated by: LCOV version 1.14