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

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2001-2024 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "ixgbe_api.h"
       6                 :            : #include "ixgbe_common.h"
       7                 :            : #include "ixgbe_phy.h"
       8                 :            : 
       9                 :            : STATIC void ixgbe_i2c_start(struct ixgbe_hw *hw);
      10                 :            : STATIC void ixgbe_i2c_stop(struct ixgbe_hw *hw);
      11                 :            : STATIC void ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data);
      12                 :            : STATIC s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data);
      13                 :            : STATIC s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw);
      14                 :            : STATIC void ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data);
      15                 :            : STATIC s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data);
      16                 :            : STATIC void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
      17                 :            : STATIC void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
      18                 :            : STATIC s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data);
      19                 :            : STATIC bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl);
      20                 :            : STATIC s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
      21                 :            :                                           u8 *sff8472_data);
      22                 :            : 
      23                 :            : /**
      24                 :            :  * ixgbe_out_i2c_byte_ack - Send I2C byte with ack
      25                 :            :  * @hw: pointer to the hardware structure
      26                 :            :  * @byte: byte to send
      27                 :            :  *
      28                 :            :  * Returns an error code on error.
      29                 :            :  */
      30                 :          0 : STATIC s32 ixgbe_out_i2c_byte_ack(struct ixgbe_hw *hw, u8 byte)
      31                 :            : {
      32                 :            :         s32 status;
      33                 :            : 
      34                 :          0 :         status = ixgbe_clock_out_i2c_byte(hw, byte);
      35         [ #  # ]:          0 :         if (status)
      36                 :            :                 return status;
      37                 :          0 :         return ixgbe_get_i2c_ack(hw);
      38                 :            : }
      39                 :            : 
      40                 :            : /**
      41                 :            :  * ixgbe_in_i2c_byte_ack - Receive an I2C byte and send ack
      42                 :            :  * @hw: pointer to the hardware structure
      43                 :            :  * @byte: pointer to a u8 to receive the byte
      44                 :            :  *
      45                 :            :  * Returns an error code on error.
      46                 :            :  */
      47                 :          0 : STATIC s32 ixgbe_in_i2c_byte_ack(struct ixgbe_hw *hw, u8 *byte)
      48                 :            : {
      49                 :          0 :         ixgbe_clock_in_i2c_byte(hw, byte);
      50                 :            :         /* ACK */
      51                 :          0 :         return ixgbe_clock_out_i2c_bit(hw, false);
      52                 :            : }
      53                 :            : 
      54                 :            : /**
      55                 :            :  * ixgbe_ones_comp_byte_add - Perform one's complement addition
      56                 :            :  * @add1: addend 1
      57                 :            :  * @add2: addend 2
      58                 :            :  *
      59                 :            :  * Returns one's complement 8-bit sum.
      60                 :            :  */
      61                 :            : STATIC u8 ixgbe_ones_comp_byte_add(u8 add1, u8 add2)
      62                 :            : {
      63                 :          0 :         u16 sum = add1 + add2;
      64                 :            : 
      65                 :          0 :         sum = (sum & 0xFF) + (sum >> 8);
      66                 :          0 :         return sum & 0xFF;
      67                 :            : }
      68                 :            : 
      69                 :            : /**
      70                 :            :  * ixgbe_read_i2c_combined_generic_int - Perform I2C read combined operation
      71                 :            :  * @hw: pointer to the hardware structure
      72                 :            :  * @addr: I2C bus address to read from
      73                 :            :  * @reg: I2C device register to read from
      74                 :            :  * @val: pointer to location to receive read value
      75                 :            :  * @lock: true if to take and release semaphore
      76                 :            :  *
      77                 :            :  * Returns an error code on error.
      78                 :            :  */
      79                 :          0 : s32 ixgbe_read_i2c_combined_generic_int(struct ixgbe_hw *hw, u8 addr, u16 reg,
      80                 :            :                                         u16 *val, bool lock)
      81                 :            : {
      82                 :          0 :         u32 swfw_mask = hw->phy.phy_semaphore_mask;
      83                 :            :         int max_retry = 3;
      84                 :            :         int retry = 0;
      85                 :            :         u8 csum_byte;
      86                 :            :         u8 high_bits;
      87                 :            :         u8 low_bits;
      88                 :            :         u8 reg_high;
      89                 :            :         u8 csum;
      90                 :            : 
      91                 :          0 :         reg_high = ((reg >> 7) & 0xFE) | 1;   /* Indicate read combined */
      92                 :          0 :         csum = ixgbe_ones_comp_byte_add(reg_high, reg & 0xFF);
      93                 :          0 :         csum = ~csum;
      94                 :            :         do {
      95   [ #  #  #  # ]:          0 :                 if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
      96                 :            :                         return IXGBE_ERR_SWFW_SYNC;
      97                 :          0 :                 ixgbe_i2c_start(hw);
      98                 :            :                 /* Device Address and write indication */
      99         [ #  # ]:          0 :                 if (ixgbe_out_i2c_byte_ack(hw, addr))
     100                 :          0 :                         goto fail;
     101                 :            :                 /* Write bits 14:8 */
     102         [ #  # ]:          0 :                 if (ixgbe_out_i2c_byte_ack(hw, reg_high))
     103                 :          0 :                         goto fail;
     104                 :            :                 /* Write bits 7:0 */
     105         [ #  # ]:          0 :                 if (ixgbe_out_i2c_byte_ack(hw, reg & 0xFF))
     106                 :          0 :                         goto fail;
     107                 :            :                 /* Write csum */
     108         [ #  # ]:          0 :                 if (ixgbe_out_i2c_byte_ack(hw, csum))
     109                 :          0 :                         goto fail;
     110                 :            :                 /* Re-start condition */
     111                 :          0 :                 ixgbe_i2c_start(hw);
     112                 :            :                 /* Device Address and read indication */
     113         [ #  # ]:          0 :                 if (ixgbe_out_i2c_byte_ack(hw, addr | 1))
     114                 :          0 :                         goto fail;
     115                 :            :                 /* Get upper bits */
     116         [ #  # ]:          0 :                 if (ixgbe_in_i2c_byte_ack(hw, &high_bits))
     117                 :          0 :                         goto fail;
     118                 :            :                 /* Get low bits */
     119         [ #  # ]:          0 :                 if (ixgbe_in_i2c_byte_ack(hw, &low_bits))
     120                 :          0 :                         goto fail;
     121                 :            :                 /* Get csum */
     122                 :          0 :                 ixgbe_clock_in_i2c_byte(hw, &csum_byte);
     123                 :            :                 /* NACK */
     124         [ #  # ]:          0 :                 if (ixgbe_clock_out_i2c_bit(hw, false))
     125                 :          0 :                         goto fail;
     126                 :          0 :                 ixgbe_i2c_stop(hw);
     127         [ #  # ]:          0 :                 if (lock)
     128                 :          0 :                         hw->mac.ops.release_swfw_sync(hw, swfw_mask);
     129                 :          0 :                 *val = (high_bits << 8) | low_bits;
     130                 :          0 :                 return 0;
     131                 :            : 
     132                 :          0 : fail:
     133                 :          0 :                 ixgbe_i2c_bus_clear(hw);
     134         [ #  # ]:          0 :                 if (lock)
     135                 :          0 :                         hw->mac.ops.release_swfw_sync(hw, swfw_mask);
     136         [ #  # ]:          0 :                 if (retry < max_retry)
     137                 :          0 :                         DEBUGOUT("I2C byte read combined error - Retrying.\n");
     138                 :            :                 else
     139                 :          0 :                         DEBUGOUT("I2C byte read combined error.\n");
     140                 :          0 :                 retry++;
     141         [ #  # ]:          0 :         } while (retry <= max_retry);
     142                 :            : 
     143                 :            :         return IXGBE_ERR_I2C;
     144                 :            : }
     145                 :            : 
     146                 :            : /**
     147                 :            :  * ixgbe_write_i2c_combined_generic_int - Perform I2C write combined operation
     148                 :            :  * @hw: pointer to the hardware structure
     149                 :            :  * @addr: I2C bus address to write to
     150                 :            :  * @reg: I2C device register to write to
     151                 :            :  * @val: value to write
     152                 :            :  * @lock: true if to take and release semaphore
     153                 :            :  *
     154                 :            :  * Returns an error code on error.
     155                 :            :  */
     156                 :          0 : s32 ixgbe_write_i2c_combined_generic_int(struct ixgbe_hw *hw, u8 addr, u16 reg,
     157                 :            :                                          u16 val, bool lock)
     158                 :            : {
     159                 :          0 :         u32 swfw_mask = hw->phy.phy_semaphore_mask;
     160                 :            :         int max_retry = 1;
     161                 :            :         int retry = 0;
     162                 :            :         u8 reg_high;
     163                 :            :         u8 csum;
     164                 :            : 
     165                 :          0 :         reg_high = (reg >> 7) & 0xFE; /* Indicate write combined */
     166                 :          0 :         csum = ixgbe_ones_comp_byte_add(reg_high, reg & 0xFF);
     167                 :          0 :         csum = ixgbe_ones_comp_byte_add(csum, val >> 8);
     168                 :          0 :         csum = ixgbe_ones_comp_byte_add(csum, val & 0xFF);
     169                 :          0 :         csum = ~csum;
     170                 :            :         do {
     171   [ #  #  #  # ]:          0 :                 if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
     172                 :            :                         return IXGBE_ERR_SWFW_SYNC;
     173                 :          0 :                 ixgbe_i2c_start(hw);
     174                 :            :                 /* Device Address and write indication */
     175         [ #  # ]:          0 :                 if (ixgbe_out_i2c_byte_ack(hw, addr))
     176                 :          0 :                         goto fail;
     177                 :            :                 /* Write bits 14:8 */
     178         [ #  # ]:          0 :                 if (ixgbe_out_i2c_byte_ack(hw, reg_high))
     179                 :          0 :                         goto fail;
     180                 :            :                 /* Write bits 7:0 */
     181         [ #  # ]:          0 :                 if (ixgbe_out_i2c_byte_ack(hw, reg & 0xFF))
     182                 :          0 :                         goto fail;
     183                 :            :                 /* Write data 15:8 */
     184         [ #  # ]:          0 :                 if (ixgbe_out_i2c_byte_ack(hw, val >> 8))
     185                 :          0 :                         goto fail;
     186                 :            :                 /* Write data 7:0 */
     187         [ #  # ]:          0 :                 if (ixgbe_out_i2c_byte_ack(hw, val & 0xFF))
     188                 :          0 :                         goto fail;
     189                 :            :                 /* Write csum */
     190         [ #  # ]:          0 :                 if (ixgbe_out_i2c_byte_ack(hw, csum))
     191                 :          0 :                         goto fail;
     192                 :          0 :                 ixgbe_i2c_stop(hw);
     193         [ #  # ]:          0 :                 if (lock)
     194                 :          0 :                         hw->mac.ops.release_swfw_sync(hw, swfw_mask);
     195                 :            :                 return 0;
     196                 :            : 
     197                 :          0 : fail:
     198                 :          0 :                 ixgbe_i2c_bus_clear(hw);
     199         [ #  # ]:          0 :                 if (lock)
     200                 :          0 :                         hw->mac.ops.release_swfw_sync(hw, swfw_mask);
     201         [ #  # ]:          0 :                 if (retry < max_retry)
     202                 :          0 :                         DEBUGOUT("I2C byte write combined error - Retrying.\n");
     203                 :            :                 else
     204                 :          0 :                         DEBUGOUT("I2C byte write combined error.\n");
     205                 :          0 :                 retry++;
     206         [ #  # ]:          0 :         } while (retry <= max_retry);
     207                 :            : 
     208                 :            :         return IXGBE_ERR_I2C;
     209                 :            : }
     210                 :            : 
     211                 :            : /**
     212                 :            :  * ixgbe_init_phy_ops_generic - Inits PHY function ptrs
     213                 :            :  * @hw: pointer to the hardware structure
     214                 :            :  *
     215                 :            :  * Initialize the function pointers.
     216                 :            :  **/
     217                 :          0 : s32 ixgbe_init_phy_ops_generic(struct ixgbe_hw *hw)
     218                 :            : {
     219                 :            :         struct ixgbe_phy_info *phy = &hw->phy;
     220                 :            : 
     221                 :          0 :         DEBUGFUNC("ixgbe_init_phy_ops_generic");
     222                 :            : 
     223                 :            :         /* PHY */
     224                 :          0 :         phy->ops.identify = ixgbe_identify_phy_generic;
     225                 :          0 :         phy->ops.reset = ixgbe_reset_phy_generic;
     226                 :          0 :         phy->ops.read_reg = ixgbe_read_phy_reg_generic;
     227                 :          0 :         phy->ops.write_reg = ixgbe_write_phy_reg_generic;
     228                 :          0 :         phy->ops.read_reg_mdi = ixgbe_read_phy_reg_mdi;
     229                 :          0 :         phy->ops.write_reg_mdi = ixgbe_write_phy_reg_mdi;
     230                 :          0 :         phy->ops.setup_link = ixgbe_setup_phy_link_generic;
     231                 :          0 :         phy->ops.setup_link_speed = ixgbe_setup_phy_link_speed_generic;
     232                 :          0 :         phy->ops.check_link = NULL;
     233                 :          0 :         phy->ops.get_firmware_version = ixgbe_get_phy_firmware_version_generic;
     234                 :          0 :         phy->ops.read_i2c_byte = ixgbe_read_i2c_byte_generic;
     235                 :          0 :         phy->ops.write_i2c_byte = ixgbe_write_i2c_byte_generic;
     236                 :          0 :         phy->ops.read_i2c_sff8472 = ixgbe_read_i2c_sff8472_generic;
     237                 :          0 :         phy->ops.read_i2c_eeprom = ixgbe_read_i2c_eeprom_generic;
     238                 :          0 :         phy->ops.write_i2c_eeprom = ixgbe_write_i2c_eeprom_generic;
     239                 :          0 :         phy->ops.i2c_bus_clear = ixgbe_i2c_bus_clear;
     240                 :          0 :         phy->ops.identify_sfp = ixgbe_identify_module_generic;
     241                 :          0 :         phy->sfp_type = ixgbe_sfp_type_unknown;
     242                 :          0 :         phy->ops.read_i2c_byte_unlocked = ixgbe_read_i2c_byte_generic_unlocked;
     243                 :          0 :         phy->ops.write_i2c_byte_unlocked =
     244                 :            :                                 ixgbe_write_i2c_byte_generic_unlocked;
     245                 :          0 :         phy->ops.check_overtemp = ixgbe_tn_check_overtemp;
     246                 :          0 :         return IXGBE_SUCCESS;
     247                 :            : }
     248                 :            : 
     249                 :            : /**
     250                 :            :  * ixgbe_probe_phy - Probe a single address for a PHY
     251                 :            :  * @hw: pointer to hardware structure
     252                 :            :  * @phy_addr: PHY address to probe
     253                 :            :  *
     254                 :            :  * Returns true if PHY found
     255                 :            :  */
     256                 :          0 : static bool ixgbe_probe_phy(struct ixgbe_hw *hw, u16 phy_addr)
     257                 :            : {
     258                 :          0 :         u16 ext_ability = 0;
     259                 :            : 
     260         [ #  # ]:          0 :         if (!ixgbe_validate_phy_addr(hw, phy_addr)) {
     261                 :          0 :                 DEBUGOUT1("Unable to validate PHY address 0x%04X\n",
     262                 :            :                         phy_addr);
     263                 :          0 :                 return false;
     264                 :            :         }
     265                 :            : 
     266         [ #  # ]:          0 :         if (ixgbe_get_phy_id(hw))
     267                 :            :                 return false;
     268                 :            : 
     269                 :          0 :         hw->phy.type = ixgbe_get_phy_type_from_id(hw->phy.id);
     270                 :            : 
     271         [ #  # ]:          0 :         if (hw->phy.type == ixgbe_phy_unknown) {
     272                 :          0 :                 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_EXT_ABILITY,
     273                 :            :                                      IXGBE_MDIO_PMA_PMD_DEV_TYPE, &ext_ability);
     274         [ #  # ]:          0 :                 if (ext_ability &
     275                 :            :                     (IXGBE_MDIO_PHY_10GBASET_ABILITY |
     276                 :            :                      IXGBE_MDIO_PHY_1000BASET_ABILITY))
     277                 :          0 :                         hw->phy.type = ixgbe_phy_cu_unknown;
     278                 :            :                 else
     279                 :          0 :                         hw->phy.type = ixgbe_phy_generic;
     280                 :            :         }
     281                 :            : 
     282                 :            :         return true;
     283                 :            : }
     284                 :            : 
     285                 :            : /**
     286                 :            :  * ixgbe_identify_phy_generic - Get physical layer module
     287                 :            :  * @hw: pointer to hardware structure
     288                 :            :  *
     289                 :            :  * Determines the physical layer module found on the current adapter.
     290                 :            :  **/
     291                 :          0 : s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
     292                 :            : {
     293                 :            :         s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
     294                 :            :         u16 phy_addr;
     295                 :            : 
     296                 :          0 :         DEBUGFUNC("ixgbe_identify_phy_generic");
     297                 :            : 
     298         [ #  # ]:          0 :         if (!hw->phy.phy_semaphore_mask) {
     299         [ #  # ]:          0 :                 if (hw->bus.lan_id)
     300                 :          0 :                         hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
     301                 :            :                 else
     302                 :          0 :                         hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
     303                 :            :         }
     304                 :            : 
     305         [ #  # ]:          0 :         if (hw->phy.type != ixgbe_phy_unknown)
     306                 :            :                 return IXGBE_SUCCESS;
     307                 :            : 
     308         [ #  # ]:          0 :         if (hw->phy.nw_mng_if_sel) {
     309                 :          0 :                 phy_addr = (hw->phy.nw_mng_if_sel &
     310                 :          0 :                             IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD) >>
     311                 :            :                            IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD_SHIFT;
     312         [ #  # ]:          0 :                 if (ixgbe_probe_phy(hw, phy_addr))
     313                 :            :                         return IXGBE_SUCCESS;
     314                 :            :                 else
     315                 :          0 :                         return IXGBE_ERR_PHY_ADDR_INVALID;
     316                 :            :         }
     317                 :            : 
     318         [ #  # ]:          0 :         for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
     319         [ #  # ]:          0 :                 if (ixgbe_probe_phy(hw, phy_addr)) {
     320                 :            :                         status = IXGBE_SUCCESS;
     321                 :            :                         break;
     322                 :            :                 }
     323                 :            :         }
     324                 :            : 
     325                 :            :         /* Certain media types do not have a phy so an address will not
     326                 :            :          * be found and the code will take this path.  Caller has to
     327                 :            :          * decide if it is an error or not.
     328                 :            :          */
     329         [ #  # ]:          0 :         if (status != IXGBE_SUCCESS)
     330                 :          0 :                 hw->phy.addr = 0;
     331                 :            : 
     332                 :            :         return status;
     333                 :            : }
     334                 :            : 
     335                 :            : /**
     336                 :            :  * ixgbe_check_reset_blocked - check status of MNG FW veto bit
     337                 :            :  * @hw: pointer to the hardware structure
     338                 :            :  *
     339                 :            :  * This function checks the MMNGC.MNG_VETO bit to see if there are
     340                 :            :  * any constraints on link from manageability.  For MAC's that don't
     341                 :            :  * have this bit just return faluse since the link can not be blocked
     342                 :            :  * via this method.
     343                 :            :  **/
     344                 :          0 : s32 ixgbe_check_reset_blocked(struct ixgbe_hw *hw)
     345                 :            : {
     346                 :            :         u32 mmngc;
     347                 :            : 
     348                 :          0 :         DEBUGFUNC("ixgbe_check_reset_blocked");
     349                 :            : 
     350                 :            :         /* If we don't have this bit, it can't be blocking */
     351         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82598EB)
     352                 :            :                 return false;
     353                 :            : 
     354                 :          0 :         mmngc = IXGBE_READ_REG(hw, IXGBE_MMNGC);
     355         [ #  # ]:          0 :         if (mmngc & IXGBE_MMNGC_MNG_VETO) {
     356                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_SOFTWARE,
     357                 :            :                               "MNG_VETO bit detected.\n");
     358                 :          0 :                 return true;
     359                 :            :         }
     360                 :            : 
     361                 :            :         return false;
     362                 :            : }
     363                 :            : 
     364                 :            : /**
     365                 :            :  * ixgbe_validate_phy_addr - Determines phy address is valid
     366                 :            :  * @hw: pointer to hardware structure
     367                 :            :  * @phy_addr: PHY address
     368                 :            :  *
     369                 :            :  **/
     370                 :          0 : bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr)
     371                 :            : {
     372                 :          0 :         u16 phy_id = 0;
     373                 :            :         bool valid = false;
     374                 :            : 
     375                 :          0 :         DEBUGFUNC("ixgbe_validate_phy_addr");
     376                 :            : 
     377                 :          0 :         hw->phy.addr = phy_addr;
     378                 :          0 :         hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
     379                 :            :                              IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_id);
     380                 :            : 
     381         [ #  # ]:          0 :         if (phy_id != 0xFFFF && phy_id != 0x0)
     382                 :            :                 valid = true;
     383                 :            : 
     384                 :          0 :         DEBUGOUT1("PHY ID HIGH is 0x%04X\n", phy_id);
     385                 :            : 
     386                 :          0 :         return valid;
     387                 :            : }
     388                 :            : 
     389                 :            : /**
     390                 :            :  * ixgbe_get_phy_id - Get the phy type
     391                 :            :  * @hw: pointer to hardware structure
     392                 :            :  *
     393                 :            :  **/
     394                 :          0 : s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
     395                 :            : {
     396                 :            :         u32 status;
     397                 :          0 :         u16 phy_id_high = 0;
     398                 :          0 :         u16 phy_id_low = 0;
     399                 :            : 
     400                 :          0 :         DEBUGFUNC("ixgbe_get_phy_id");
     401                 :            : 
     402                 :          0 :         status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
     403                 :            :                                       IXGBE_MDIO_PMA_PMD_DEV_TYPE,
     404                 :            :                                       &phy_id_high);
     405                 :            : 
     406         [ #  # ]:          0 :         if (status == IXGBE_SUCCESS) {
     407                 :          0 :                 hw->phy.id = (u32)(phy_id_high << 16);
     408                 :          0 :                 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_LOW,
     409                 :            :                                               IXGBE_MDIO_PMA_PMD_DEV_TYPE,
     410                 :            :                                               &phy_id_low);
     411                 :          0 :                 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
     412                 :          0 :                 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
     413                 :            :         }
     414                 :          0 :         DEBUGOUT2("PHY_ID_HIGH 0x%04X, PHY_ID_LOW 0x%04X\n",
     415                 :            :                   phy_id_high, phy_id_low);
     416                 :            : 
     417                 :          0 :         return status;
     418                 :            : }
     419                 :            : 
     420                 :            : /**
     421                 :            :  * ixgbe_get_phy_type_from_id - Get the phy type
     422                 :            :  * @phy_id: PHY ID information
     423                 :            :  *
     424                 :            :  **/
     425                 :          0 : enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id)
     426                 :            : {
     427                 :            :         enum ixgbe_phy_type phy_type;
     428                 :            : 
     429                 :          0 :         DEBUGFUNC("ixgbe_get_phy_type_from_id");
     430                 :            : 
     431   [ #  #  #  #  :          0 :         switch (phy_id) {
                #  #  # ]
     432                 :            :         case TN1010_PHY_ID:
     433                 :            :                 phy_type = ixgbe_phy_tn;
     434                 :            :                 break;
     435                 :          0 :         case X550_PHY_ID:
     436                 :            :         case X540_PHY_ID:
     437                 :            :                 phy_type = ixgbe_phy_aq;
     438                 :          0 :                 break;
     439                 :          0 :         case QT2022_PHY_ID:
     440                 :            :                 phy_type = ixgbe_phy_qt;
     441                 :          0 :                 break;
     442                 :          0 :         case ATH_PHY_ID:
     443                 :            :                 phy_type = ixgbe_phy_nl;
     444                 :          0 :                 break;
     445                 :          0 :         case X557_PHY_ID:
     446                 :            :         case X557_PHY_ID2:
     447                 :            :                 phy_type = ixgbe_phy_x550em_ext_t;
     448                 :          0 :                 break;
     449                 :          0 :         case IXGBE_M88E1500_E_PHY_ID:
     450                 :            :         case IXGBE_M88E1543_E_PHY_ID:
     451                 :            :                 phy_type = ixgbe_phy_ext_1g_t;
     452                 :          0 :                 break;
     453                 :          0 :         default:
     454                 :            :                 phy_type = ixgbe_phy_unknown;
     455                 :          0 :                 break;
     456                 :            :         }
     457                 :          0 :         return phy_type;
     458                 :            : }
     459                 :            : 
     460                 :            : /**
     461                 :            :  * ixgbe_reset_phy_generic - Performs a PHY reset
     462                 :            :  * @hw: pointer to hardware structure
     463                 :            :  **/
     464                 :          0 : s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
     465                 :            : {
     466                 :            :         u32 i;
     467                 :          0 :         u16 ctrl = 0;
     468                 :            :         s32 status = IXGBE_SUCCESS;
     469                 :            : 
     470                 :          0 :         DEBUGFUNC("ixgbe_reset_phy_generic");
     471                 :            : 
     472         [ #  # ]:          0 :         if (hw->phy.type == ixgbe_phy_unknown)
     473                 :          0 :                 status = ixgbe_identify_phy_generic(hw);
     474                 :            : 
     475   [ #  #  #  # ]:          0 :         if (status != IXGBE_SUCCESS || hw->phy.type == ixgbe_phy_none)
     476                 :          0 :                 goto out;
     477                 :            : 
     478                 :            :         /* Don't reset PHY if it's shut down due to overtemp. */
     479   [ #  #  #  # ]:          0 :         if (!hw->phy.reset_if_overtemp &&
     480                 :          0 :             (IXGBE_ERR_OVERTEMP == hw->phy.ops.check_overtemp(hw)))
     481                 :          0 :                 goto out;
     482                 :            : 
     483                 :            :         /* Blocked by MNG FW so bail */
     484         [ #  # ]:          0 :         if (ixgbe_check_reset_blocked(hw))
     485                 :          0 :                 goto out;
     486                 :            : 
     487                 :            :         /*
     488                 :            :          * Perform soft PHY reset to the PHY_XS.
     489                 :            :          * This will cause a soft reset to the PHY
     490                 :            :          */
     491                 :          0 :         hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
     492                 :            :                               IXGBE_MDIO_PHY_XS_DEV_TYPE,
     493                 :            :                               IXGBE_MDIO_PHY_XS_RESET);
     494                 :            : 
     495                 :            :         /*
     496                 :            :          * Poll for reset bit to self-clear indicating reset is complete.
     497                 :            :          * Some PHYs could take up to 3 seconds to complete and need about
     498                 :            :          * 1.7 usec delay after the reset is complete.
     499                 :            :          */
     500         [ #  # ]:          0 :         for (i = 0; i < 30; i++) {
     501                 :          0 :                 msec_delay(100);
     502         [ #  # ]:          0 :                 if (hw->phy.type == ixgbe_phy_x550em_ext_t) {
     503                 :          0 :                         status = hw->phy.ops.read_reg(hw,
     504                 :            :                                                   IXGBE_MDIO_TX_VENDOR_ALARMS_3,
     505                 :            :                                                   IXGBE_MDIO_PMA_PMD_DEV_TYPE,
     506                 :            :                                                   &ctrl);
     507         [ #  # ]:          0 :                         if (status != IXGBE_SUCCESS)
     508                 :          0 :                                 return status;
     509                 :            : 
     510         [ #  # ]:          0 :                         if (ctrl & IXGBE_MDIO_TX_VENDOR_ALARMS_3_RST_MASK) {
     511                 :          0 :                                 usec_delay(2);
     512                 :          0 :                                 break;
     513                 :            :                         }
     514                 :            :                 } else {
     515                 :          0 :                         status = hw->phy.ops.read_reg(hw,
     516                 :            :                                                      IXGBE_MDIO_PHY_XS_CONTROL,
     517                 :            :                                                      IXGBE_MDIO_PHY_XS_DEV_TYPE,
     518                 :            :                                                      &ctrl);
     519         [ #  # ]:          0 :                         if (status != IXGBE_SUCCESS)
     520                 :          0 :                                 return status;
     521                 :            : 
     522         [ #  # ]:          0 :                         if (!(ctrl & IXGBE_MDIO_PHY_XS_RESET)) {
     523                 :          0 :                                 usec_delay(2);
     524                 :          0 :                                 break;
     525                 :            :                         }
     526                 :            :                 }
     527                 :            :         }
     528                 :            : 
     529         [ #  # ]:          0 :         if (ctrl & IXGBE_MDIO_PHY_XS_RESET) {
     530                 :            :                 status = IXGBE_ERR_RESET_FAILED;
     531                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_POLLING,
     532                 :            :                              "PHY reset polling failed to complete.\n");
     533                 :            :         }
     534                 :            : 
     535                 :          0 : out:
     536                 :            :         return status;
     537                 :            : }
     538                 :            : 
     539                 :            : /**
     540                 :            :  * ixgbe_restart_auto_neg - Restart auto negotiation on the PHY
     541                 :            :  * @hw: pointer to hardware structure
     542                 :            :  **/
     543                 :          0 : void ixgbe_restart_auto_neg(struct ixgbe_hw *hw)
     544                 :            : {
     545                 :            :         u16 autoneg_reg;
     546                 :            : 
     547                 :            :         /* Check if PHY reset is blocked by MNG FW */
     548         [ #  # ]:          0 :         if (ixgbe_check_reset_blocked(hw))
     549                 :          0 :                 return;
     550                 :            : 
     551                 :            :         /* Restart PHY auto-negotiation. */
     552                 :          0 :         hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
     553                 :            :                                 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
     554                 :          0 :         autoneg_reg |= IXGBE_MII_RESTART;
     555                 :          0 :         hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL,
     556                 :            :                                 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
     557                 :            : }
     558                 :            : 
     559                 :            : /**
     560                 :            :  * ixgbe_read_phy_reg_mdi - Reads a value from a specified PHY register without
     561                 :            :  * the SWFW lock
     562                 :            :  * @hw: pointer to hardware structure
     563                 :            :  * @reg_addr: 32 bit address of PHY register to read
     564                 :            :  * @device_type: 5 bit device type
     565                 :            :  * @phy_data: Pointer to read data from PHY register
     566                 :            :  **/
     567                 :          0 : s32 ixgbe_read_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
     568                 :            :                            u16 *phy_data)
     569                 :            : {
     570                 :            :         u32 i, data, command;
     571                 :            : 
     572                 :            :         /* Setup and write the address cycle command */
     573                 :          0 :         command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT)  |
     574                 :          0 :                    (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
     575                 :          0 :                    (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
     576                 :            :                    (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
     577                 :            : 
     578                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
     579                 :            : 
     580                 :            :         /*
     581                 :            :          * Check every 10 usec to see if the address cycle completed.
     582                 :            :          * The MDI Command bit will clear when the operation is
     583                 :            :          * complete
     584                 :            :          */
     585         [ #  # ]:          0 :         for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
     586                 :          0 :                 usec_delay(10);
     587                 :            : 
     588                 :          0 :                 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
     589         [ #  # ]:          0 :                 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
     590                 :            :                         break;
     591                 :            :         }
     592                 :            : 
     593                 :            : 
     594         [ #  # ]:          0 :         if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
     595                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY address command did not complete.\n");
     596                 :          0 :                 DEBUGOUT("PHY address command did not complete, returning IXGBE_ERR_PHY\n");
     597                 :          0 :                 return IXGBE_ERR_PHY;
     598                 :            :         }
     599                 :            : 
     600                 :            :         /*
     601                 :            :          * Address cycle complete, setup and write the read
     602                 :            :          * command
     603                 :            :          */
     604                 :          0 :         command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT)  |
     605                 :          0 :                    (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
     606                 :          0 :                    (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
     607                 :            :                    (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
     608                 :            : 
     609                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
     610                 :            : 
     611                 :            :         /*
     612                 :            :          * Check every 10 usec to see if the address cycle
     613                 :            :          * completed. The MDI Command bit will clear when the
     614                 :            :          * operation is complete
     615                 :            :          */
     616         [ #  # ]:          0 :         for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
     617                 :          0 :                 usec_delay(10);
     618                 :            : 
     619                 :          0 :                 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
     620         [ #  # ]:          0 :                 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
     621                 :            :                         break;
     622                 :            :         }
     623                 :            : 
     624         [ #  # ]:          0 :         if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
     625                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY read command didn't complete\n");
     626                 :          0 :                 DEBUGOUT("PHY read command didn't complete, returning IXGBE_ERR_PHY\n");
     627                 :          0 :                 return IXGBE_ERR_PHY;
     628                 :            :         }
     629                 :            : 
     630                 :            :         /*
     631                 :            :          * Read operation is complete.  Get the data
     632                 :            :          * from MSRWD
     633                 :            :          */
     634                 :          0 :         data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
     635                 :          0 :         data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
     636                 :          0 :         *phy_data = (u16)(data);
     637                 :            : 
     638                 :          0 :         return IXGBE_SUCCESS;
     639                 :            : }
     640                 :            : 
     641                 :            : /**
     642                 :            :  * ixgbe_read_phy_reg_generic - Reads a value from a specified PHY register
     643                 :            :  * using the SWFW lock - this function is needed in most cases
     644                 :            :  * @hw: pointer to hardware structure
     645                 :            :  * @reg_addr: 32 bit address of PHY register to read
     646                 :            :  * @device_type: 5 bit device type
     647                 :            :  * @phy_data: Pointer to read data from PHY register
     648                 :            :  **/
     649                 :          0 : s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
     650                 :            :                                u32 device_type, u16 *phy_data)
     651                 :            : {
     652                 :            :         s32 status;
     653                 :          0 :         u32 gssr = hw->phy.phy_semaphore_mask;
     654                 :            : 
     655                 :          0 :         DEBUGFUNC("ixgbe_read_phy_reg_generic");
     656                 :            : 
     657         [ #  # ]:          0 :         if (hw->mac.ops.acquire_swfw_sync(hw, gssr))
     658                 :            :                 return IXGBE_ERR_SWFW_SYNC;
     659                 :            : 
     660                 :          0 :         status = hw->phy.ops.read_reg_mdi(hw, reg_addr, device_type, phy_data);
     661                 :            : 
     662                 :          0 :         hw->mac.ops.release_swfw_sync(hw, gssr);
     663                 :            : 
     664                 :          0 :         return status;
     665                 :            : }
     666                 :            : 
     667                 :            : /**
     668                 :            :  * ixgbe_write_phy_reg_mdi - Writes a value to specified PHY register
     669                 :            :  * without SWFW lock
     670                 :            :  * @hw: pointer to hardware structure
     671                 :            :  * @reg_addr: 32 bit PHY register to write
     672                 :            :  * @device_type: 5 bit device type
     673                 :            :  * @phy_data: Data to write to the PHY register
     674                 :            :  **/
     675                 :          0 : s32 ixgbe_write_phy_reg_mdi(struct ixgbe_hw *hw, u32 reg_addr,
     676                 :            :                                 u32 device_type, u16 phy_data)
     677                 :            : {
     678                 :            :         u32 i, command;
     679                 :            : 
     680                 :            :         /* Put the data in the MDI single read and write data register*/
     681                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
     682                 :            : 
     683                 :            :         /* Setup and write the address cycle command */
     684                 :          0 :         command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT)  |
     685                 :          0 :                    (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
     686                 :          0 :                    (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
     687                 :            :                    (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
     688                 :            : 
     689                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
     690                 :            : 
     691                 :            :         /*
     692                 :            :          * Check every 10 usec to see if the address cycle completed.
     693                 :            :          * The MDI Command bit will clear when the operation is
     694                 :            :          * complete
     695                 :            :          */
     696         [ #  # ]:          0 :         for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
     697                 :          0 :                 usec_delay(10);
     698                 :            : 
     699                 :          0 :                 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
     700         [ #  # ]:          0 :                 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
     701                 :            :                         break;
     702                 :            :         }
     703                 :            : 
     704         [ #  # ]:          0 :         if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
     705                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY address cmd didn't complete\n");
     706                 :          0 :                 return IXGBE_ERR_PHY;
     707                 :            :         }
     708                 :            : 
     709                 :            :         /*
     710                 :            :          * Address cycle complete, setup and write the write
     711                 :            :          * command
     712                 :            :          */
     713                 :          0 :         command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT)  |
     714                 :          0 :                    (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
     715                 :          0 :                    (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) |
     716                 :            :                    (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
     717                 :            : 
     718                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
     719                 :            : 
     720                 :            :         /*
     721                 :            :          * Check every 10 usec to see if the address cycle
     722                 :            :          * completed. The MDI Command bit will clear when the
     723                 :            :          * operation is complete
     724                 :            :          */
     725         [ #  # ]:          0 :         for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
     726                 :          0 :                 usec_delay(10);
     727                 :            : 
     728                 :          0 :                 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
     729         [ #  # ]:          0 :                 if ((command & IXGBE_MSCA_MDI_COMMAND) == 0)
     730                 :            :                         break;
     731                 :            :         }
     732                 :            : 
     733         [ #  # ]:          0 :         if ((command & IXGBE_MSCA_MDI_COMMAND) != 0) {
     734                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_POLLING, "PHY write cmd didn't complete\n");
     735                 :          0 :                 return IXGBE_ERR_PHY;
     736                 :            :         }
     737                 :            : 
     738                 :            :         return IXGBE_SUCCESS;
     739                 :            : }
     740                 :            : 
     741                 :            : /**
     742                 :            :  * ixgbe_write_phy_reg_generic - Writes a value to specified PHY register
     743                 :            :  * using SWFW lock- this function is needed in most cases
     744                 :            :  * @hw: pointer to hardware structure
     745                 :            :  * @reg_addr: 32 bit PHY register to write
     746                 :            :  * @device_type: 5 bit device type
     747                 :            :  * @phy_data: Data to write to the PHY register
     748                 :            :  **/
     749                 :          0 : s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
     750                 :            :                                 u32 device_type, u16 phy_data)
     751                 :            : {
     752                 :            :         s32 status;
     753                 :          0 :         u32 gssr = hw->phy.phy_semaphore_mask;
     754                 :            : 
     755                 :          0 :         DEBUGFUNC("ixgbe_write_phy_reg_generic");
     756                 :            : 
     757         [ #  # ]:          0 :         if (hw->mac.ops.acquire_swfw_sync(hw, gssr) == IXGBE_SUCCESS) {
     758                 :          0 :                 status = hw->phy.ops.write_reg_mdi(hw, reg_addr, device_type,
     759                 :            :                                                  phy_data);
     760                 :          0 :                 hw->mac.ops.release_swfw_sync(hw, gssr);
     761                 :            :         } else {
     762                 :            :                 status = IXGBE_ERR_SWFW_SYNC;
     763                 :            :         }
     764                 :            : 
     765                 :          0 :         return status;
     766                 :            : }
     767                 :            : 
     768                 :            : /**
     769                 :            :  * ixgbe_setup_phy_link_generic - Set and restart auto-neg
     770                 :            :  * @hw: pointer to hardware structure
     771                 :            :  *
     772                 :            :  * Restart auto-negotiation and PHY and waits for completion.
     773                 :            :  **/
     774                 :          0 : s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
     775                 :            : {
     776                 :            :         s32 status = IXGBE_SUCCESS;
     777                 :          0 :         u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
     778                 :          0 :         bool autoneg = false;
     779                 :            :         ixgbe_link_speed speed;
     780                 :            : 
     781                 :          0 :         DEBUGFUNC("ixgbe_setup_phy_link_generic");
     782                 :            : 
     783                 :          0 :         ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
     784                 :            : 
     785                 :            :         /* Set or unset auto-negotiation 10G advertisement */
     786                 :          0 :         hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
     787                 :            :                              IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
     788                 :            :                              &autoneg_reg);
     789                 :            : 
     790                 :          0 :         autoneg_reg &= ~IXGBE_MII_10GBASE_T_ADVERTISE;
     791         [ #  # ]:          0 :         if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL) &&
     792         [ #  # ]:          0 :             (speed & IXGBE_LINK_SPEED_10GB_FULL))
     793                 :          0 :                 autoneg_reg |= IXGBE_MII_10GBASE_T_ADVERTISE;
     794                 :            : 
     795                 :          0 :         hw->phy.ops.write_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
     796                 :            :                               IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
     797                 :            :                               autoneg_reg);
     798                 :            : 
     799                 :          0 :         hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
     800                 :            :                              IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
     801                 :            :                              &autoneg_reg);
     802                 :            : 
     803         [ #  # ]:          0 :         if ((hw->mac.type == ixgbe_mac_X550) ||
     804                 :            :             (hw->mac.type == ixgbe_mac_E610)) {
     805                 :            :                 /* Set or unset auto-negotiation 5G advertisement */
     806                 :          0 :                 autoneg_reg &= ~IXGBE_MII_5GBASE_T_ADVERTISE;
     807         [ #  # ]:          0 :                 if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_5GB_FULL) &&
     808         [ #  # ]:          0 :                     (speed & IXGBE_LINK_SPEED_5GB_FULL))
     809                 :          0 :                         autoneg_reg |= IXGBE_MII_5GBASE_T_ADVERTISE;
     810                 :            : 
     811                 :            :                 /* Set or unset auto-negotiation 2.5G advertisement */
     812                 :          0 :                 autoneg_reg &= ~IXGBE_MII_2_5GBASE_T_ADVERTISE;
     813         [ #  # ]:          0 :                 if ((hw->phy.autoneg_advertised &
     814                 :          0 :                      IXGBE_LINK_SPEED_2_5GB_FULL) &&
     815         [ #  # ]:          0 :                     (speed & IXGBE_LINK_SPEED_2_5GB_FULL))
     816                 :          0 :                         autoneg_reg |= IXGBE_MII_2_5GBASE_T_ADVERTISE;
     817                 :            :         }
     818                 :            : 
     819                 :            :         /* Set or unset auto-negotiation 1G advertisement */
     820                 :          0 :         autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE;
     821         [ #  # ]:          0 :         if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL) &&
     822         [ #  # ]:          0 :             (speed & IXGBE_LINK_SPEED_1GB_FULL))
     823                 :          0 :                 autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE;
     824                 :            : 
     825                 :          0 :         hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
     826                 :            :                               IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
     827                 :            :                               autoneg_reg);
     828                 :            : 
     829                 :            :         /* Set or unset auto-negotiation 100M advertisement */
     830                 :          0 :         hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
     831                 :            :                              IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
     832                 :            :                              &autoneg_reg);
     833                 :            : 
     834                 :          0 :         autoneg_reg &= ~(IXGBE_MII_100BASE_T_ADVERTISE |
     835                 :            :                          IXGBE_MII_100BASE_T_ADVERTISE_HALF);
     836         [ #  # ]:          0 :         if ((hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL) &&
     837         [ #  # ]:          0 :             (speed & IXGBE_LINK_SPEED_100_FULL))
     838                 :          0 :                 autoneg_reg |= IXGBE_MII_100BASE_T_ADVERTISE;
     839                 :            : 
     840                 :          0 :         hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
     841                 :            :                               IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
     842                 :            :                               autoneg_reg);
     843                 :            : 
     844                 :          0 :         ixgbe_restart_auto_neg(hw);
     845                 :          0 :         return status;
     846                 :            : }
     847                 :            : 
     848                 :            : /**
     849                 :            :  * ixgbe_setup_phy_link_speed_generic - Sets the auto advertised capabilities
     850                 :            :  * @hw: pointer to hardware structure
     851                 :            :  * @speed: new link speed
     852                 :            :  * @autoneg_wait_to_complete: unused
     853                 :            :  **/
     854                 :          0 : s32 ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw,
     855                 :            :                                        ixgbe_link_speed speed,
     856                 :            :                                        bool autoneg_wait_to_complete)
     857                 :            : {
     858                 :            :         UNREFERENCED_1PARAMETER(autoneg_wait_to_complete);
     859                 :            : 
     860                 :          0 :         DEBUGFUNC("ixgbe_setup_phy_link_speed_generic");
     861                 :            : 
     862                 :            :         /*
     863                 :            :          * Clear autoneg_advertised and set new values based on input link
     864                 :            :          * speed.
     865                 :            :          */
     866                 :          0 :         hw->phy.autoneg_advertised = 0;
     867                 :            : 
     868         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_10GB_FULL)
     869                 :          0 :                 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
     870                 :            : 
     871         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_5GB_FULL)
     872                 :          0 :                 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_5GB_FULL;
     873                 :            : 
     874         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_2_5GB_FULL)
     875                 :          0 :                 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_2_5GB_FULL;
     876                 :            : 
     877         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_1GB_FULL)
     878                 :          0 :                 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
     879                 :            : 
     880         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_100_FULL)
     881                 :          0 :                 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
     882                 :            : 
     883         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_10_FULL)
     884                 :          0 :                 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10_FULL;
     885                 :            : 
     886                 :            :         /* Setup link based on the new speed settings */
     887                 :          0 :         ixgbe_setup_phy_link(hw);
     888                 :            : 
     889                 :          0 :         return IXGBE_SUCCESS;
     890                 :            : }
     891                 :            : 
     892                 :            : /**
     893                 :            :  * ixgbe_get_copper_speeds_supported - Get copper link speeds from phy
     894                 :            :  * @hw: pointer to hardware structure
     895                 :            :  *
     896                 :            :  * Determines the supported link capabilities by reading the PHY auto
     897                 :            :  * negotiation register.
     898                 :            :  **/
     899                 :          0 : static s32 ixgbe_get_copper_speeds_supported(struct ixgbe_hw *hw)
     900                 :            : {
     901                 :            :         s32 status;
     902                 :            :         u16 speed_ability;
     903                 :            : 
     904                 :          0 :         status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_SPEED_ABILITY,
     905                 :            :                                       IXGBE_MDIO_PMA_PMD_DEV_TYPE,
     906                 :            :                                       &speed_ability);
     907         [ #  # ]:          0 :         if (status)
     908                 :            :                 return status;
     909                 :            : 
     910         [ #  # ]:          0 :         if (speed_ability & IXGBE_MDIO_PHY_SPEED_10G)
     911                 :          0 :                 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_10GB_FULL;
     912         [ #  # ]:          0 :         if (speed_ability & IXGBE_MDIO_PHY_SPEED_1G)
     913                 :          0 :                 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_1GB_FULL;
     914         [ #  # ]:          0 :         if (speed_ability & IXGBE_MDIO_PHY_SPEED_100M)
     915                 :          0 :                 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_100_FULL;
     916                 :            : 
     917      [ #  #  # ]:          0 :         switch (hw->mac.type) {
     918                 :          0 :         case ixgbe_mac_X550:
     919                 :            :         case ixgbe_mac_E610:
     920                 :          0 :                 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_2_5GB_FULL;
     921                 :          0 :                 hw->phy.speeds_supported |= IXGBE_LINK_SPEED_5GB_FULL;
     922                 :          0 :                 break;
     923                 :          0 :         case ixgbe_mac_X550EM_x:
     924                 :            :         case ixgbe_mac_X550EM_a:
     925                 :          0 :                 hw->phy.speeds_supported &= ~IXGBE_LINK_SPEED_100_FULL;
     926                 :          0 :                 break;
     927                 :            :         default:
     928                 :            :                 break;
     929                 :            :         }
     930                 :            : 
     931                 :            :         return status;
     932                 :            : }
     933                 :            : 
     934                 :            : /**
     935                 :            :  * ixgbe_get_copper_link_capabilities_generic - Determines link capabilities
     936                 :            :  * @hw: pointer to hardware structure
     937                 :            :  * @speed: pointer to link speed
     938                 :            :  * @autoneg: boolean auto-negotiation value
     939                 :            :  **/
     940                 :          0 : s32 ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw,
     941                 :            :                                                ixgbe_link_speed *speed,
     942                 :            :                                                bool *autoneg)
     943                 :            : {
     944                 :            :         s32 status = IXGBE_SUCCESS;
     945                 :            : 
     946                 :          0 :         DEBUGFUNC("ixgbe_get_copper_link_capabilities_generic");
     947                 :            : 
     948                 :          0 :         *autoneg = true;
     949         [ #  # ]:          0 :         if (!hw->phy.speeds_supported)
     950                 :          0 :                 status = ixgbe_get_copper_speeds_supported(hw);
     951                 :            : 
     952                 :          0 :         *speed = hw->phy.speeds_supported;
     953                 :          0 :         return status;
     954                 :            : }
     955                 :            : 
     956                 :            : /**
     957                 :            :  * ixgbe_check_phy_link_tnx - Determine link and speed status
     958                 :            :  * @hw: pointer to hardware structure
     959                 :            :  * @speed: current link speed
     960                 :            :  * @link_up: true is link is up, false otherwise
     961                 :            :  *
     962                 :            :  * Reads the VS1 register to determine if link is up and the current speed for
     963                 :            :  * the PHY.
     964                 :            :  **/
     965                 :          0 : s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
     966                 :            :                              bool *link_up)
     967                 :            : {
     968                 :            :         s32 status = IXGBE_SUCCESS;
     969                 :            :         u32 time_out;
     970                 :            :         u32 max_time_out = 10;
     971                 :            :         u16 phy_link = 0;
     972                 :            :         u16 phy_speed = 0;
     973                 :          0 :         u16 phy_data = 0;
     974                 :            : 
     975                 :          0 :         DEBUGFUNC("ixgbe_check_phy_link_tnx");
     976                 :            : 
     977                 :            :         /* Initialize speed and link to default case */
     978                 :          0 :         *link_up = false;
     979                 :          0 :         *speed = IXGBE_LINK_SPEED_10GB_FULL;
     980                 :            : 
     981                 :            :         /*
     982                 :            :          * Check current speed and link status of the PHY register.
     983                 :            :          * This is a vendor specific register and may have to
     984                 :            :          * be changed for other copper PHYs.
     985                 :            :          */
     986         [ #  # ]:          0 :         for (time_out = 0; time_out < max_time_out; time_out++) {
     987                 :          0 :                 usec_delay(10);
     988                 :          0 :                 status = hw->phy.ops.read_reg(hw,
     989                 :            :                                         IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
     990                 :            :                                         IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
     991                 :            :                                         &phy_data);
     992                 :          0 :                 phy_link = phy_data & IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
     993                 :          0 :                 phy_speed = phy_data &
     994                 :            :                                  IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS;
     995         [ #  # ]:          0 :                 if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) {
     996                 :          0 :                         *link_up = true;
     997         [ #  # ]:          0 :                         if (phy_speed ==
     998                 :            :                             IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS)
     999                 :          0 :                                 *speed = IXGBE_LINK_SPEED_1GB_FULL;
    1000                 :            :                         break;
    1001                 :            :                 }
    1002                 :            :         }
    1003                 :            : 
    1004                 :          0 :         return status;
    1005                 :            : }
    1006                 :            : 
    1007                 :            : /**
    1008                 :            :  *      ixgbe_setup_phy_link_tnx - Set and restart auto-neg
    1009                 :            :  *      @hw: pointer to hardware structure
    1010                 :            :  *
    1011                 :            :  *      Restart auto-negotiation and PHY and waits for completion.
    1012                 :            :  **/
    1013                 :          0 : s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
    1014                 :            : {
    1015                 :            :         s32 status = IXGBE_SUCCESS;
    1016                 :          0 :         u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
    1017                 :          0 :         bool autoneg = false;
    1018                 :            :         ixgbe_link_speed speed;
    1019                 :            : 
    1020                 :          0 :         DEBUGFUNC("ixgbe_setup_phy_link_tnx");
    1021                 :            : 
    1022                 :          0 :         ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg);
    1023                 :            : 
    1024         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
    1025                 :            :                 /* Set or unset auto-negotiation 10G advertisement */
    1026                 :          0 :                 hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
    1027                 :            :                                      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    1028                 :            :                                      &autoneg_reg);
    1029                 :            : 
    1030                 :          0 :                 autoneg_reg &= ~IXGBE_MII_10GBASE_T_ADVERTISE;
    1031         [ #  # ]:          0 :                 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
    1032                 :          0 :                         autoneg_reg |= IXGBE_MII_10GBASE_T_ADVERTISE;
    1033                 :            : 
    1034                 :          0 :                 hw->phy.ops.write_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
    1035                 :            :                                       IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    1036                 :            :                                       autoneg_reg);
    1037                 :            :         }
    1038                 :            : 
    1039         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
    1040                 :            :                 /* Set or unset auto-negotiation 1G advertisement */
    1041                 :          0 :                 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
    1042                 :            :                                      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    1043                 :            :                                      &autoneg_reg);
    1044                 :            : 
    1045                 :          0 :                 autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
    1046         [ #  # ]:          0 :                 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
    1047                 :          0 :                         autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX;
    1048                 :            : 
    1049                 :          0 :                 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG,
    1050                 :            :                                       IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    1051                 :            :                                       autoneg_reg);
    1052                 :            :         }
    1053                 :            : 
    1054         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_100_FULL) {
    1055                 :            :                 /* Set or unset auto-negotiation 100M advertisement */
    1056                 :          0 :                 hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
    1057                 :            :                                      IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    1058                 :            :                                      &autoneg_reg);
    1059                 :            : 
    1060                 :          0 :                 autoneg_reg &= ~IXGBE_MII_100BASE_T_ADVERTISE;
    1061         [ #  # ]:          0 :                 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL)
    1062                 :          0 :                         autoneg_reg |= IXGBE_MII_100BASE_T_ADVERTISE;
    1063                 :            : 
    1064                 :          0 :                 hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_ADVERTISE_REG,
    1065                 :            :                                       IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    1066                 :            :                                       autoneg_reg);
    1067                 :            :         }
    1068                 :            : 
    1069                 :          0 :         ixgbe_restart_auto_neg(hw);
    1070                 :          0 :         return status;
    1071                 :            : }
    1072                 :            : 
    1073                 :            : /**
    1074                 :            :  * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version
    1075                 :            :  * @hw: pointer to hardware structure
    1076                 :            :  * @firmware_version: pointer to the PHY Firmware Version
    1077                 :            :  **/
    1078                 :          0 : s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
    1079                 :            :                                        u16 *firmware_version)
    1080                 :            : {
    1081                 :            :         s32 status;
    1082                 :            : 
    1083                 :          0 :         DEBUGFUNC("ixgbe_get_phy_firmware_version_tnx");
    1084                 :            : 
    1085                 :          0 :         status = hw->phy.ops.read_reg(hw, TNX_FW_REV,
    1086                 :            :                                       IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
    1087                 :            :                                       firmware_version);
    1088                 :            : 
    1089                 :          0 :         return status;
    1090                 :            : }
    1091                 :            : 
    1092                 :            : /**
    1093                 :            :  * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version
    1094                 :            :  * @hw: pointer to hardware structure
    1095                 :            :  * @firmware_version: pointer to the PHY Firmware Version
    1096                 :            :  **/
    1097                 :          0 : s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
    1098                 :            :                                            u16 *firmware_version)
    1099                 :            : {
    1100                 :            :         s32 status;
    1101                 :            : 
    1102                 :          0 :         DEBUGFUNC("ixgbe_get_phy_firmware_version_generic");
    1103                 :            : 
    1104                 :          0 :         status = hw->phy.ops.read_reg(hw, AQ_FW_REV,
    1105                 :            :                                       IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
    1106                 :            :                                       firmware_version);
    1107                 :            : 
    1108                 :          0 :         return status;
    1109                 :            : }
    1110                 :            : 
    1111                 :            : /**
    1112                 :            :  * ixgbe_reset_phy_nl - Performs a PHY reset
    1113                 :            :  * @hw: pointer to hardware structure
    1114                 :            :  **/
    1115                 :          0 : s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
    1116                 :            : {
    1117                 :            :         u16 phy_offset, control, eword, edata, block_crc;
    1118                 :            :         bool end_data = false;
    1119                 :            :         u16 list_offset, data_offset;
    1120                 :          0 :         u16 phy_data = 0;
    1121                 :            :         s32 ret_val = IXGBE_SUCCESS;
    1122                 :            :         u32 i;
    1123                 :            : 
    1124                 :          0 :         DEBUGFUNC("ixgbe_reset_phy_nl");
    1125                 :            : 
    1126                 :            :         /* Blocked by MNG FW so bail */
    1127         [ #  # ]:          0 :         if (ixgbe_check_reset_blocked(hw))
    1128                 :          0 :                 goto out;
    1129                 :            : 
    1130                 :          0 :         hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
    1131                 :            :                              IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
    1132                 :            : 
    1133                 :            :         /* reset the PHY and poll for completion */
    1134                 :          0 :         hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
    1135                 :            :                               IXGBE_MDIO_PHY_XS_DEV_TYPE,
    1136                 :            :                               (phy_data | IXGBE_MDIO_PHY_XS_RESET));
    1137                 :            : 
    1138         [ #  # ]:          0 :         for (i = 0; i < 100; i++) {
    1139                 :          0 :                 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL,
    1140                 :            :                                      IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
    1141         [ #  # ]:          0 :                 if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) == 0)
    1142                 :            :                         break;
    1143                 :          0 :                 msec_delay(10);
    1144                 :            :         }
    1145                 :            : 
    1146         [ #  # ]:          0 :         if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) != 0) {
    1147                 :          0 :                 DEBUGOUT("PHY reset did not complete.\n");
    1148                 :            :                 ret_val = IXGBE_ERR_PHY;
    1149                 :          0 :                 goto out;
    1150                 :            :         }
    1151                 :            : 
    1152                 :            :         /* Get init offsets */
    1153                 :          0 :         ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
    1154                 :            :                                                       &data_offset);
    1155         [ #  # ]:          0 :         if (ret_val != IXGBE_SUCCESS)
    1156                 :          0 :                 goto out;
    1157                 :            : 
    1158                 :          0 :         ret_val = hw->eeprom.ops.read(hw, data_offset, &block_crc);
    1159                 :          0 :         data_offset++;
    1160         [ #  # ]:          0 :         while (!end_data) {
    1161                 :            :                 /*
    1162                 :            :                  * Read control word from PHY init contents offset
    1163                 :            :                  */
    1164                 :          0 :                 ret_val = hw->eeprom.ops.read(hw, data_offset, &eword);
    1165         [ #  # ]:          0 :                 if (ret_val)
    1166                 :          0 :                         goto err_eeprom;
    1167                 :          0 :                 control = (eword & IXGBE_CONTROL_MASK_NL) >>
    1168                 :            :                            IXGBE_CONTROL_SHIFT_NL;
    1169                 :          0 :                 edata = eword & IXGBE_DATA_MASK_NL;
    1170   [ #  #  #  # ]:          0 :                 switch (control) {
    1171                 :          0 :                 case IXGBE_DELAY_NL:
    1172                 :          0 :                         data_offset++;
    1173                 :          0 :                         DEBUGOUT1("DELAY: %d MS\n", edata);
    1174                 :          0 :                         msec_delay(edata);
    1175                 :          0 :                         break;
    1176                 :          0 :                 case IXGBE_DATA_NL:
    1177                 :          0 :                         DEBUGOUT("DATA:\n");
    1178                 :          0 :                         data_offset++;
    1179                 :          0 :                         ret_val = hw->eeprom.ops.read(hw, data_offset,
    1180                 :            :                                                       &phy_offset);
    1181         [ #  # ]:          0 :                         if (ret_val)
    1182                 :          0 :                                 goto err_eeprom;
    1183                 :          0 :                         data_offset++;
    1184         [ #  # ]:          0 :                         for (i = 0; i < edata; i++) {
    1185                 :          0 :                                 ret_val = hw->eeprom.ops.read(hw, data_offset,
    1186                 :            :                                                               &eword);
    1187         [ #  # ]:          0 :                                 if (ret_val)
    1188                 :          0 :                                         goto err_eeprom;
    1189                 :          0 :                                 hw->phy.ops.write_reg(hw, phy_offset,
    1190                 :            :                                                       IXGBE_TWINAX_DEV, eword);
    1191                 :          0 :                                 DEBUGOUT2("Wrote %4.4x to %4.4x\n", eword,
    1192                 :            :                                           phy_offset);
    1193                 :          0 :                                 data_offset++;
    1194                 :          0 :                                 phy_offset++;
    1195                 :            :                         }
    1196                 :            :                         break;
    1197                 :          0 :                 case IXGBE_CONTROL_NL:
    1198                 :          0 :                         data_offset++;
    1199                 :          0 :                         DEBUGOUT("CONTROL:\n");
    1200         [ #  # ]:          0 :                         if (edata == IXGBE_CONTROL_EOL_NL) {
    1201                 :          0 :                                 DEBUGOUT("EOL\n");
    1202                 :            :                                 end_data = true;
    1203         [ #  # ]:          0 :                         } else if (edata == IXGBE_CONTROL_SOL_NL) {
    1204                 :          0 :                                 DEBUGOUT("SOL\n");
    1205                 :            :                         } else {
    1206                 :          0 :                                 DEBUGOUT("Bad control value\n");
    1207                 :            :                                 ret_val = IXGBE_ERR_PHY;
    1208                 :          0 :                                 goto out;
    1209                 :            :                         }
    1210                 :            :                         break;
    1211                 :          0 :                 default:
    1212                 :          0 :                         DEBUGOUT("Bad control type\n");
    1213                 :            :                         ret_val = IXGBE_ERR_PHY;
    1214                 :          0 :                         goto out;
    1215                 :            :                 }
    1216                 :            :         }
    1217                 :            : 
    1218                 :          0 : out:
    1219                 :            :         return ret_val;
    1220                 :            : 
    1221                 :          0 : err_eeprom:
    1222                 :          0 :         ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
    1223                 :            :                       "eeprom read at offset %d failed", data_offset);
    1224                 :          0 :         return IXGBE_ERR_PHY;
    1225                 :            : }
    1226                 :            : 
    1227                 :            : /**
    1228                 :            :  * ixgbe_identify_module_generic - Identifies module type
    1229                 :            :  * @hw: pointer to hardware structure
    1230                 :            :  *
    1231                 :            :  * Determines HW type and calls appropriate function.
    1232                 :            :  **/
    1233                 :          0 : s32 ixgbe_identify_module_generic(struct ixgbe_hw *hw)
    1234                 :            : {
    1235                 :            :         s32 status = IXGBE_ERR_SFP_NOT_PRESENT;
    1236                 :            : 
    1237                 :          0 :         DEBUGFUNC("ixgbe_identify_module_generic");
    1238                 :            : 
    1239      [ #  #  # ]:          0 :         switch (hw->mac.ops.get_media_type(hw)) {
    1240                 :          0 :         case ixgbe_media_type_fiber:
    1241                 :          0 :                 status = ixgbe_identify_sfp_module_generic(hw);
    1242                 :          0 :                 break;
    1243                 :            : 
    1244                 :          0 :         case ixgbe_media_type_fiber_qsfp:
    1245                 :          0 :                 status = ixgbe_identify_qsfp_module_generic(hw);
    1246                 :          0 :                 break;
    1247                 :            : 
    1248                 :          0 :         default:
    1249                 :          0 :                 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
    1250                 :            :                 status = IXGBE_ERR_SFP_NOT_PRESENT;
    1251                 :          0 :                 break;
    1252                 :            :         }
    1253                 :            : 
    1254                 :          0 :         return status;
    1255                 :            : }
    1256                 :            : 
    1257                 :            : /**
    1258                 :            :  * ixgbe_identify_sfp_module_generic - Identifies SFP modules
    1259                 :            :  * @hw: pointer to hardware structure
    1260                 :            :  *
    1261                 :            :  * Searches for and identifies the SFP module and assigns appropriate PHY type.
    1262                 :            :  **/
    1263                 :          0 : s32 ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw)
    1264                 :            : {
    1265                 :            :         s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
    1266                 :            :         u32 vendor_oui = 0;
    1267                 :          0 :         enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
    1268                 :          0 :         u8 identifier = 0;
    1269                 :          0 :         u8 comp_codes_1g = 0;
    1270                 :          0 :         u8 comp_codes_10g = 0;
    1271                 :          0 :         u8 oui_bytes[3] = {0, 0, 0};
    1272                 :          0 :         u8 cable_tech = 0;
    1273                 :          0 :         u8 cable_spec = 0;
    1274                 :          0 :         u16 enforce_sfp = 0;
    1275                 :            :         u8 retries;
    1276                 :            : 
    1277                 :          0 :         DEBUGFUNC("ixgbe_identify_sfp_module_generic");
    1278                 :            : 
    1279         [ #  # ]:          0 :         if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber) {
    1280                 :          0 :                 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
    1281                 :            :                 status = IXGBE_ERR_SFP_NOT_PRESENT;
    1282                 :          0 :                 goto out;
    1283                 :            :         }
    1284                 :            : 
    1285                 :            :         /* LAN ID is needed for I2C access */
    1286                 :          0 :         hw->mac.ops.set_lan_id(hw);
    1287                 :            : 
    1288                 :            :         /* Need to check this a couple of times for a sane value.
    1289                 :            :          *
    1290                 :            :          * SFPs that have a uC slaved to the I2C bus (vs. a dumb EEPROM) can be
    1291                 :            :          * poorly designed such that they will ACK I2C reads and return
    1292                 :            :          * whatever bogus data is in the SRAM (or whatever is backing the target
    1293                 :            :          * device) before things are truly initialized.
    1294                 :            :          *
    1295                 :            :          * In a perfect world devices would NAK I2C requests until they were
    1296                 :            :          * sane, but here we are.
    1297                 :            :          *
    1298                 :            :          * Give such devices a couple tries to get their act together before
    1299                 :            :          * marking the device as unsupported.
    1300                 :            :          */
    1301         [ #  # ]:          0 :         for (retries = 0; retries < 5; retries++) {
    1302                 :          0 :                 status = hw->phy.ops.read_i2c_eeprom(hw,
    1303                 :            :                                                      IXGBE_SFF_IDENTIFIER,
    1304                 :            :                                                      &identifier);
    1305                 :            : 
    1306                 :          0 :                 DEBUGOUT("status %d, SFF identifier 0x%x\n", status, identifier);
    1307         [ #  # ]:          0 :                 if (status == IXGBE_SUCCESS &&
    1308         [ #  # ]:          0 :                 identifier == IXGBE_SFF_IDENTIFIER_SFP)
    1309                 :            :                         break;
    1310                 :            :         }
    1311                 :            : 
    1312         [ #  # ]:          0 :         if (status != IXGBE_SUCCESS)
    1313                 :          0 :                 goto err_read_i2c_eeprom;
    1314                 :            : 
    1315         [ #  # ]:          0 :         if (identifier != IXGBE_SFF_IDENTIFIER_SFP) {
    1316                 :          0 :                 hw->phy.type = ixgbe_phy_sfp_unsupported;
    1317                 :            :                 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
    1318                 :            :         } else {
    1319                 :          0 :                 status = hw->phy.ops.read_i2c_eeprom(hw,
    1320                 :            :                                                      IXGBE_SFF_1GBE_COMP_CODES,
    1321                 :            :                                                      &comp_codes_1g);
    1322                 :            : 
    1323         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    1324                 :          0 :                         goto err_read_i2c_eeprom;
    1325                 :            : 
    1326                 :          0 :                 status = hw->phy.ops.read_i2c_eeprom(hw,
    1327                 :            :                                                      IXGBE_SFF_10GBE_COMP_CODES,
    1328                 :            :                                                      &comp_codes_10g);
    1329                 :            : 
    1330         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    1331                 :          0 :                         goto err_read_i2c_eeprom;
    1332                 :          0 :                 status = hw->phy.ops.read_i2c_eeprom(hw,
    1333                 :            :                                                      IXGBE_SFF_CABLE_TECHNOLOGY,
    1334                 :            :                                                      &cable_tech);
    1335                 :            : 
    1336         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    1337                 :          0 :                         goto err_read_i2c_eeprom;
    1338                 :            : 
    1339                 :            :                  /* ID Module
    1340                 :            :                   * =========
    1341                 :            :                   * 0   SFP_DA_CU
    1342                 :            :                   * 1   SFP_SR
    1343                 :            :                   * 2   SFP_LR
    1344                 :            :                   * 3   SFP_DA_CORE0 - 82599-specific
    1345                 :            :                   * 4   SFP_DA_CORE1 - 82599-specific
    1346                 :            :                   * 5   SFP_SR/LR_CORE0 - 82599-specific
    1347                 :            :                   * 6   SFP_SR/LR_CORE1 - 82599-specific
    1348                 :            :                   * 7   SFP_act_lmt_DA_CORE0 - 82599-specific
    1349                 :            :                   * 8   SFP_act_lmt_DA_CORE1 - 82599-specific
    1350                 :            :                   * 9   SFP_1g_cu_CORE0 - 82599-specific
    1351                 :            :                   * 10  SFP_1g_cu_CORE1 - 82599-specific
    1352                 :            :                   * 11  SFP_1g_sx_CORE0 - 82599-specific
    1353                 :            :                   * 12  SFP_1g_sx_CORE1 - 82599-specific
    1354                 :            :                   */
    1355         [ #  # ]:          0 :                 if (hw->mac.type == ixgbe_mac_82598EB) {
    1356         [ #  # ]:          0 :                         if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
    1357                 :          0 :                                 hw->phy.sfp_type = ixgbe_sfp_type_da_cu;
    1358         [ #  # ]:          0 :                         else if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
    1359                 :          0 :                                 hw->phy.sfp_type = ixgbe_sfp_type_sr;
    1360         [ #  # ]:          0 :                         else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
    1361                 :          0 :                                 hw->phy.sfp_type = ixgbe_sfp_type_lr;
    1362                 :            :                         else
    1363                 :          0 :                                 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
    1364                 :            :                 } else {
    1365         [ #  # ]:          0 :                         if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE) {
    1366         [ #  # ]:          0 :                                 if (hw->bus.lan_id == 0)
    1367                 :          0 :                                         hw->phy.sfp_type =
    1368                 :            :                                                      ixgbe_sfp_type_da_cu_core0;
    1369                 :            :                                 else
    1370                 :          0 :                                         hw->phy.sfp_type =
    1371                 :            :                                                      ixgbe_sfp_type_da_cu_core1;
    1372         [ #  # ]:          0 :                         } else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE) {
    1373                 :          0 :                                 hw->phy.ops.read_i2c_eeprom(
    1374                 :            :                                                 hw, IXGBE_SFF_CABLE_SPEC_COMP,
    1375                 :            :                                                 &cable_spec);
    1376         [ #  # ]:          0 :                                 if (cable_spec &
    1377                 :            :                                     IXGBE_SFF_DA_SPEC_ACTIVE_LIMITING) {
    1378         [ #  # ]:          0 :                                         if (hw->bus.lan_id == 0)
    1379                 :          0 :                                                 hw->phy.sfp_type =
    1380                 :            :                                                 ixgbe_sfp_type_da_act_lmt_core0;
    1381                 :            :                                         else
    1382                 :          0 :                                                 hw->phy.sfp_type =
    1383                 :            :                                                 ixgbe_sfp_type_da_act_lmt_core1;
    1384                 :            :                                 } else {
    1385                 :          0 :                                         hw->phy.sfp_type =
    1386                 :            :                                                         ixgbe_sfp_type_unknown;
    1387                 :            :                                 }
    1388         [ #  # ]:          0 :                         } else if (comp_codes_10g &
    1389                 :            :                                    (IXGBE_SFF_10GBASESR_CAPABLE |
    1390                 :            :                                     IXGBE_SFF_10GBASELR_CAPABLE)) {
    1391         [ #  # ]:          0 :                                 if (hw->bus.lan_id == 0)
    1392                 :          0 :                                         hw->phy.sfp_type =
    1393                 :            :                                                       ixgbe_sfp_type_srlr_core0;
    1394                 :            :                                 else
    1395                 :          0 :                                         hw->phy.sfp_type =
    1396                 :            :                                                       ixgbe_sfp_type_srlr_core1;
    1397         [ #  # ]:          0 :                         } else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE) {
    1398         [ #  # ]:          0 :                                 if (hw->bus.lan_id == 0)
    1399                 :          0 :                                         hw->phy.sfp_type =
    1400                 :            :                                                 ixgbe_sfp_type_1g_cu_core0;
    1401                 :            :                                 else
    1402                 :          0 :                                         hw->phy.sfp_type =
    1403                 :            :                                                 ixgbe_sfp_type_1g_cu_core1;
    1404         [ #  # ]:          0 :                         } else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) {
    1405         [ #  # ]:          0 :                                 if (hw->bus.lan_id == 0)
    1406                 :          0 :                                         hw->phy.sfp_type =
    1407                 :            :                                                 ixgbe_sfp_type_1g_sx_core0;
    1408                 :            :                                 else
    1409                 :          0 :                                         hw->phy.sfp_type =
    1410                 :            :                                                 ixgbe_sfp_type_1g_sx_core1;
    1411         [ #  # ]:          0 :                         } else if (comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) {
    1412         [ #  # ]:          0 :                                 if (hw->bus.lan_id == 0)
    1413                 :          0 :                                         hw->phy.sfp_type =
    1414                 :            :                                                 ixgbe_sfp_type_1g_lx_core0;
    1415                 :            :                                 else
    1416                 :          0 :                                         hw->phy.sfp_type =
    1417                 :            :                                                 ixgbe_sfp_type_1g_lx_core1;
    1418         [ #  # ]:          0 :                         } else if (comp_codes_1g & IXGBE_SFF_1GBASELHA_CAPABLE) {
    1419         [ #  # ]:          0 :                                 if (hw->bus.lan_id == 0)
    1420                 :          0 :                                         hw->phy.sfp_type =
    1421                 :            :                                                 ixgbe_sfp_type_1g_lha_core0;
    1422                 :            :                                 else
    1423                 :          0 :                                         hw->phy.sfp_type =
    1424                 :            :                                                 ixgbe_sfp_type_1g_lha_core1;
    1425                 :            :                         } else {
    1426                 :          0 :                                 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
    1427                 :            :                         }
    1428                 :            :                 }
    1429                 :            : 
    1430         [ #  # ]:          0 :                 if (hw->phy.sfp_type != stored_sfp_type)
    1431                 :          0 :                         hw->phy.sfp_setup_needed = true;
    1432                 :            : 
    1433                 :            :                 /* Determine if the SFP+ PHY is dual speed or not. */
    1434                 :          0 :                 hw->phy.multispeed_fiber = false;
    1435         [ #  # ]:          0 :                 if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
    1436   [ #  #  #  # ]:          0 :                    (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
    1437                 :          0 :                    ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
    1438         [ #  # ]:          0 :                    (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
    1439                 :          0 :                         hw->phy.multispeed_fiber = true;
    1440                 :            : 
    1441                 :            :                 /* Determine PHY vendor */
    1442         [ #  # ]:          0 :                 if (hw->phy.type != ixgbe_phy_nl) {
    1443                 :          0 :                         hw->phy.id = identifier;
    1444                 :          0 :                         status = hw->phy.ops.read_i2c_eeprom(hw,
    1445                 :            :                                                     IXGBE_SFF_VENDOR_OUI_BYTE0,
    1446                 :            :                                                     &oui_bytes[0]);
    1447                 :            : 
    1448         [ #  # ]:          0 :                         if (status != IXGBE_SUCCESS)
    1449                 :          0 :                                 goto err_read_i2c_eeprom;
    1450                 :            : 
    1451                 :          0 :                         status = hw->phy.ops.read_i2c_eeprom(hw,
    1452                 :            :                                                     IXGBE_SFF_VENDOR_OUI_BYTE1,
    1453                 :            :                                                     &oui_bytes[1]);
    1454                 :            : 
    1455         [ #  # ]:          0 :                         if (status != IXGBE_SUCCESS)
    1456                 :          0 :                                 goto err_read_i2c_eeprom;
    1457                 :            : 
    1458                 :          0 :                         status = hw->phy.ops.read_i2c_eeprom(hw,
    1459                 :            :                                                     IXGBE_SFF_VENDOR_OUI_BYTE2,
    1460                 :            :                                                     &oui_bytes[2]);
    1461                 :            : 
    1462         [ #  # ]:          0 :                         if (status != IXGBE_SUCCESS)
    1463                 :          0 :                                 goto err_read_i2c_eeprom;
    1464                 :            : 
    1465                 :            :                         vendor_oui =
    1466                 :          0 :                           ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
    1467                 :          0 :                            (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
    1468                 :          0 :                            (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
    1469                 :            : 
    1470   [ #  #  #  #  :          0 :                         switch (vendor_oui) {
                      # ]
    1471                 :          0 :                         case IXGBE_SFF_VENDOR_OUI_TYCO:
    1472         [ #  # ]:          0 :                                 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
    1473                 :          0 :                                         hw->phy.type =
    1474                 :            :                                                     ixgbe_phy_sfp_passive_tyco;
    1475                 :            :                                 break;
    1476                 :          0 :                         case IXGBE_SFF_VENDOR_OUI_FTL:
    1477         [ #  # ]:          0 :                                 if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
    1478                 :          0 :                                         hw->phy.type = ixgbe_phy_sfp_ftl_active;
    1479                 :            :                                 else
    1480                 :          0 :                                         hw->phy.type = ixgbe_phy_sfp_ftl;
    1481                 :            :                                 break;
    1482                 :          0 :                         case IXGBE_SFF_VENDOR_OUI_AVAGO:
    1483                 :          0 :                                 hw->phy.type = ixgbe_phy_sfp_avago;
    1484                 :          0 :                                 break;
    1485                 :          0 :                         case IXGBE_SFF_VENDOR_OUI_INTEL:
    1486                 :          0 :                                 hw->phy.type = ixgbe_phy_sfp_intel;
    1487                 :          0 :                                 break;
    1488                 :          0 :                         default:
    1489         [ #  # ]:          0 :                                 if (cable_tech & IXGBE_SFF_DA_PASSIVE_CABLE)
    1490                 :          0 :                                         hw->phy.type =
    1491                 :            :                                                  ixgbe_phy_sfp_passive_unknown;
    1492         [ #  # ]:          0 :                                 else if (cable_tech & IXGBE_SFF_DA_ACTIVE_CABLE)
    1493                 :          0 :                                         hw->phy.type =
    1494                 :            :                                                 ixgbe_phy_sfp_active_unknown;
    1495                 :            :                                 else
    1496                 :          0 :                                         hw->phy.type = ixgbe_phy_sfp_unknown;
    1497                 :            :                                 break;
    1498                 :            :                         }
    1499                 :            :                 }
    1500                 :            : 
    1501                 :            :                 /* Allow any DA cable vendor */
    1502         [ #  # ]:          0 :                 if (cable_tech & (IXGBE_SFF_DA_PASSIVE_CABLE |
    1503                 :            :                     IXGBE_SFF_DA_ACTIVE_CABLE)) {
    1504                 :            :                         status = IXGBE_SUCCESS;
    1505                 :          0 :                         goto out;
    1506                 :            :                 }
    1507                 :            : 
    1508                 :            :                 /* Verify supported 1G SFP modules */
    1509         [ #  # ]:          0 :                 if (comp_codes_10g == 0 &&
    1510         [ #  # ]:          0 :                     !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
    1511         [ #  # ]:          0 :                       hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
    1512         [ #  # ]:          0 :                       hw->phy.sfp_type == ixgbe_sfp_type_1g_lha_core0 ||
    1513         [ #  # ]:          0 :                       hw->phy.sfp_type == ixgbe_sfp_type_1g_lha_core1 ||
    1514         [ #  # ]:          0 :                       hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
    1515         [ #  # ]:          0 :                       hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
    1516                 :            :                       hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
    1517                 :            :                       hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
    1518                 :          0 :                         hw->phy.type = ixgbe_phy_sfp_unsupported;
    1519                 :            :                         status = IXGBE_ERR_SFP_NOT_SUPPORTED;
    1520                 :          0 :                         goto out;
    1521                 :            :                 }
    1522                 :            : 
    1523                 :            :                 /* Anything else 82598-based is supported */
    1524         [ #  # ]:          0 :                 if (hw->mac.type == ixgbe_mac_82598EB) {
    1525                 :            :                         status = IXGBE_SUCCESS;
    1526                 :          0 :                         goto out;
    1527                 :            :                 }
    1528                 :            : 
    1529                 :          0 :                 ixgbe_get_device_caps(hw, &enforce_sfp);
    1530         [ #  # ]:          0 :                 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP) &&
    1531                 :          0 :                     !(hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
    1532         [ #  # ]:          0 :                       hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
    1533                 :            :                       hw->phy.sfp_type == ixgbe_sfp_type_1g_lha_core0 ||
    1534                 :            :                       hw->phy.sfp_type == ixgbe_sfp_type_1g_lha_core1 ||
    1535                 :            :                       hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
    1536                 :            :                       hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
    1537                 :            :                       hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
    1538                 :            :                       hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1)) {
    1539                 :            :                         /* Make sure we're a supported PHY type */
    1540         [ #  # ]:          0 :                         if (hw->phy.type == ixgbe_phy_sfp_intel) {
    1541                 :            :                                 status = IXGBE_SUCCESS;
    1542                 :            :                         } else {
    1543         [ #  # ]:          0 :                                 if (hw->allow_unsupported_sfp == true) {
    1544                 :          0 :                                         EWARN(hw,
    1545                 :            :                                                 "WARNING: Intel (R) Network Connections are quality tested using Intel (R) Ethernet Optics. "
    1546                 :            :                                                 "Using untested modules is not supported and may cause unstable operation or damage to the module or the adapter. "
    1547                 :            :                                                 "Intel Corporation is not responsible for any harm caused by using untested modules.\n");
    1548                 :            :                                         status = IXGBE_SUCCESS;
    1549                 :            :                                 } else {
    1550                 :          0 :                                         DEBUGOUT("SFP+ module not supported\n");
    1551                 :          0 :                                         hw->phy.type =
    1552                 :            :                                                 ixgbe_phy_sfp_unsupported;
    1553                 :            :                                         status = IXGBE_ERR_SFP_NOT_SUPPORTED;
    1554                 :            :                                 }
    1555                 :            :                         }
    1556                 :            :                 } else {
    1557                 :            :                         status = IXGBE_SUCCESS;
    1558                 :            :                 }
    1559                 :            :         }
    1560                 :            : 
    1561                 :            : out:
    1562                 :            :         return status;
    1563                 :            : 
    1564                 :          0 : err_read_i2c_eeprom:
    1565                 :          0 :         hw->phy.sfp_type = ixgbe_sfp_type_not_present;
    1566         [ #  # ]:          0 :         if (hw->phy.type != ixgbe_phy_nl) {
    1567                 :          0 :                 hw->phy.id = 0;
    1568                 :          0 :                 hw->phy.type = ixgbe_phy_unknown;
    1569                 :            :         }
    1570                 :            :         return IXGBE_ERR_SFP_NOT_PRESENT;
    1571                 :            : }
    1572                 :            : 
    1573                 :            : /**
    1574                 :            :  * ixgbe_get_supported_phy_sfp_layer_generic - Returns physical layer type
    1575                 :            :  * @hw: pointer to hardware structure
    1576                 :            :  *
    1577                 :            :  * Determines physical layer capabilities of the current SFP.
    1578                 :            :  */
    1579                 :          0 : u64 ixgbe_get_supported_phy_sfp_layer_generic(struct ixgbe_hw *hw)
    1580                 :            : {
    1581                 :            :         u64 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
    1582                 :          0 :         u8 comp_codes_10g = 0;
    1583                 :          0 :         u8 comp_codes_1g = 0;
    1584                 :            : 
    1585                 :          0 :         DEBUGFUNC("ixgbe_get_supported_phy_sfp_layer_generic");
    1586                 :            : 
    1587                 :          0 :         hw->phy.ops.identify_sfp(hw);
    1588         [ #  # ]:          0 :         if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
    1589                 :            :                 return physical_layer;
    1590                 :            : 
    1591   [ #  #  #  #  :          0 :         switch (hw->phy.type) {
                      # ]
    1592                 :          0 :         case ixgbe_phy_sfp_passive_tyco:
    1593                 :            :         case ixgbe_phy_sfp_passive_unknown:
    1594                 :            :         case ixgbe_phy_qsfp_passive_unknown:
    1595                 :            :                 physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
    1596                 :          0 :                 break;
    1597                 :          0 :         case ixgbe_phy_sfp_ftl_active:
    1598                 :            :         case ixgbe_phy_sfp_active_unknown:
    1599                 :            :         case ixgbe_phy_qsfp_active_unknown:
    1600                 :            :                 physical_layer = IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA;
    1601                 :          0 :                 break;
    1602                 :          0 :         case ixgbe_phy_sfp_avago:
    1603                 :            :         case ixgbe_phy_sfp_ftl:
    1604                 :            :         case ixgbe_phy_sfp_intel:
    1605                 :            :         case ixgbe_phy_sfp_unknown:
    1606                 :          0 :                 hw->phy.ops.read_i2c_eeprom(hw,
    1607                 :            :                       IXGBE_SFF_1GBE_COMP_CODES, &comp_codes_1g);
    1608                 :          0 :                 hw->phy.ops.read_i2c_eeprom(hw,
    1609                 :            :                       IXGBE_SFF_10GBE_COMP_CODES, &comp_codes_10g);
    1610         [ #  # ]:          0 :                 if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
    1611                 :            :                         physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
    1612         [ #  # ]:          0 :                 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
    1613                 :            :                         physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
    1614         [ #  # ]:          0 :                 else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE)
    1615                 :            :                         physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_T;
    1616         [ #  # ]:          0 :                 else if (comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE)
    1617                 :            :                         physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_SX;
    1618                 :            :                 break;
    1619                 :          0 :         case ixgbe_phy_qsfp_intel:
    1620                 :            :         case ixgbe_phy_qsfp_unknown:
    1621                 :          0 :                 hw->phy.ops.read_i2c_eeprom(hw,
    1622                 :            :                       IXGBE_SFF_QSFP_10GBE_COMP, &comp_codes_10g);
    1623         [ #  # ]:          0 :                 if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
    1624                 :            :                         physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
    1625         [ #  # ]:          0 :                 else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
    1626                 :            :                         physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
    1627                 :            :                 break;
    1628                 :            :         default:
    1629                 :            :                 break;
    1630                 :            :         }
    1631                 :            : 
    1632                 :            :         return physical_layer;
    1633                 :            : }
    1634                 :            : 
    1635                 :            : /**
    1636                 :            :  * ixgbe_identify_qsfp_module_generic - Identifies QSFP modules
    1637                 :            :  * @hw: pointer to hardware structure
    1638                 :            :  *
    1639                 :            :  * Searches for and identifies the QSFP module and assigns appropriate PHY type
    1640                 :            :  **/
    1641                 :          0 : s32 ixgbe_identify_qsfp_module_generic(struct ixgbe_hw *hw)
    1642                 :            : {
    1643                 :            :         s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
    1644                 :            :         u32 vendor_oui = 0;
    1645                 :          0 :         enum ixgbe_sfp_type stored_sfp_type = hw->phy.sfp_type;
    1646                 :          0 :         u8 identifier = 0;
    1647                 :          0 :         u8 comp_codes_1g = 0;
    1648                 :          0 :         u8 comp_codes_10g = 0;
    1649                 :          0 :         u8 oui_bytes[3] = {0, 0, 0};
    1650                 :          0 :         u16 enforce_sfp = 0;
    1651                 :          0 :         u8 connector = 0;
    1652                 :          0 :         u8 cable_length = 0;
    1653                 :          0 :         u8 device_tech = 0;
    1654                 :            :         bool active_cable = false;
    1655                 :            : 
    1656                 :          0 :         DEBUGFUNC("ixgbe_identify_qsfp_module_generic");
    1657                 :            : 
    1658         [ #  # ]:          0 :         if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_fiber_qsfp) {
    1659                 :          0 :                 hw->phy.sfp_type = ixgbe_sfp_type_not_present;
    1660                 :            :                 status = IXGBE_ERR_SFP_NOT_PRESENT;
    1661                 :          0 :                 goto out;
    1662                 :            :         }
    1663                 :            : 
    1664                 :            :         /* LAN ID is needed for I2C access */
    1665                 :          0 :         hw->mac.ops.set_lan_id(hw);
    1666                 :            : 
    1667                 :          0 :         status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_IDENTIFIER,
    1668                 :            :                                              &identifier);
    1669                 :            : 
    1670         [ #  # ]:          0 :         if (status != IXGBE_SUCCESS)
    1671                 :          0 :                 goto err_read_i2c_eeprom;
    1672                 :            : 
    1673         [ #  # ]:          0 :         if (identifier != IXGBE_SFF_IDENTIFIER_QSFP_PLUS) {
    1674                 :          0 :                 hw->phy.type = ixgbe_phy_sfp_unsupported;
    1675                 :            :                 status = IXGBE_ERR_SFP_NOT_SUPPORTED;
    1676                 :          0 :                 goto out;
    1677                 :            :         }
    1678                 :            : 
    1679                 :          0 :         hw->phy.id = identifier;
    1680                 :            : 
    1681                 :          0 :         status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_10GBE_COMP,
    1682                 :            :                                              &comp_codes_10g);
    1683                 :            : 
    1684         [ #  # ]:          0 :         if (status != IXGBE_SUCCESS)
    1685                 :          0 :                 goto err_read_i2c_eeprom;
    1686                 :            : 
    1687                 :          0 :         status = hw->phy.ops.read_i2c_eeprom(hw, IXGBE_SFF_QSFP_1GBE_COMP,
    1688                 :            :                                              &comp_codes_1g);
    1689                 :            : 
    1690         [ #  # ]:          0 :         if (status != IXGBE_SUCCESS)
    1691                 :          0 :                 goto err_read_i2c_eeprom;
    1692                 :            : 
    1693         [ #  # ]:          0 :         if (comp_codes_10g & IXGBE_SFF_QSFP_DA_PASSIVE_CABLE) {
    1694                 :          0 :                 hw->phy.type = ixgbe_phy_qsfp_passive_unknown;
    1695         [ #  # ]:          0 :                 if (hw->bus.lan_id == 0)
    1696                 :          0 :                         hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core0;
    1697                 :            :                 else
    1698                 :          0 :                         hw->phy.sfp_type = ixgbe_sfp_type_da_cu_core1;
    1699         [ #  # ]:          0 :         } else if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
    1700                 :            :                                      IXGBE_SFF_10GBASELR_CAPABLE)) {
    1701         [ #  # ]:          0 :                 if (hw->bus.lan_id == 0)
    1702                 :          0 :                         hw->phy.sfp_type = ixgbe_sfp_type_srlr_core0;
    1703                 :            :                 else
    1704                 :          0 :                         hw->phy.sfp_type = ixgbe_sfp_type_srlr_core1;
    1705                 :            :         } else {
    1706         [ #  # ]:          0 :                 if (comp_codes_10g & IXGBE_SFF_QSFP_DA_ACTIVE_CABLE)
    1707                 :            :                         active_cable = true;
    1708                 :            : 
    1709                 :            :                 if (!active_cable) {
    1710                 :            :                         /* check for active DA cables that pre-date
    1711                 :            :                          * SFF-8436 v3.6 */
    1712                 :          0 :                         hw->phy.ops.read_i2c_eeprom(hw,
    1713                 :            :                                         IXGBE_SFF_QSFP_CONNECTOR,
    1714                 :            :                                         &connector);
    1715                 :            : 
    1716                 :          0 :                         hw->phy.ops.read_i2c_eeprom(hw,
    1717                 :            :                                         IXGBE_SFF_QSFP_CABLE_LENGTH,
    1718                 :            :                                         &cable_length);
    1719                 :            : 
    1720                 :          0 :                         hw->phy.ops.read_i2c_eeprom(hw,
    1721                 :            :                                         IXGBE_SFF_QSFP_DEVICE_TECH,
    1722                 :            :                                         &device_tech);
    1723                 :            : 
    1724         [ #  # ]:          0 :                         if ((connector ==
    1725                 :          0 :                                      IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE) &&
    1726         [ #  # ]:          0 :                             (cable_length > 0) &&
    1727         [ #  # ]:          0 :                             ((device_tech >> 4) ==
    1728                 :            :                                      IXGBE_SFF_QSFP_TRANSMITER_850NM_VCSEL))
    1729                 :            :                                 active_cable = true;
    1730                 :            :                 }
    1731                 :            : 
    1732         [ #  # ]:          0 :                 if (active_cable) {
    1733                 :          0 :                         hw->phy.type = ixgbe_phy_qsfp_active_unknown;
    1734         [ #  # ]:          0 :                         if (hw->bus.lan_id == 0)
    1735                 :          0 :                                 hw->phy.sfp_type =
    1736                 :            :                                                 ixgbe_sfp_type_da_act_lmt_core0;
    1737                 :            :                         else
    1738                 :          0 :                                 hw->phy.sfp_type =
    1739                 :            :                                                 ixgbe_sfp_type_da_act_lmt_core1;
    1740                 :            :                 } else {
    1741                 :            :                         /* unsupported module type */
    1742                 :          0 :                         hw->phy.type = ixgbe_phy_sfp_unsupported;
    1743                 :            :                         status = IXGBE_ERR_SFP_NOT_SUPPORTED;
    1744                 :          0 :                         goto out;
    1745                 :            :                 }
    1746                 :            :         }
    1747                 :            : 
    1748         [ #  # ]:          0 :         if (hw->phy.sfp_type != stored_sfp_type)
    1749                 :          0 :                 hw->phy.sfp_setup_needed = true;
    1750                 :            : 
    1751                 :            :         /* Determine if the QSFP+ PHY is dual speed or not. */
    1752                 :          0 :         hw->phy.multispeed_fiber = false;
    1753         [ #  # ]:          0 :         if (((comp_codes_1g & IXGBE_SFF_1GBASESX_CAPABLE) &&
    1754   [ #  #  #  # ]:          0 :            (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)) ||
    1755                 :          0 :            ((comp_codes_1g & IXGBE_SFF_1GBASELX_CAPABLE) &&
    1756         [ #  # ]:          0 :            (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)))
    1757                 :          0 :                 hw->phy.multispeed_fiber = true;
    1758                 :            : 
    1759                 :            :         /* Determine PHY vendor for optical modules */
    1760         [ #  # ]:          0 :         if (comp_codes_10g & (IXGBE_SFF_10GBASESR_CAPABLE |
    1761                 :            :                               IXGBE_SFF_10GBASELR_CAPABLE))  {
    1762                 :          0 :                 status = hw->phy.ops.read_i2c_eeprom(hw,
    1763                 :            :                                             IXGBE_SFF_QSFP_VENDOR_OUI_BYTE0,
    1764                 :            :                                             &oui_bytes[0]);
    1765                 :            : 
    1766         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    1767                 :          0 :                         goto err_read_i2c_eeprom;
    1768                 :            : 
    1769                 :          0 :                 status = hw->phy.ops.read_i2c_eeprom(hw,
    1770                 :            :                                             IXGBE_SFF_QSFP_VENDOR_OUI_BYTE1,
    1771                 :            :                                             &oui_bytes[1]);
    1772                 :            : 
    1773         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    1774                 :          0 :                         goto err_read_i2c_eeprom;
    1775                 :            : 
    1776                 :          0 :                 status = hw->phy.ops.read_i2c_eeprom(hw,
    1777                 :            :                                             IXGBE_SFF_QSFP_VENDOR_OUI_BYTE2,
    1778                 :            :                                             &oui_bytes[2]);
    1779                 :            : 
    1780         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    1781                 :          0 :                         goto err_read_i2c_eeprom;
    1782                 :            : 
    1783                 :            :                 vendor_oui =
    1784                 :          0 :                   ((oui_bytes[0] << IXGBE_SFF_VENDOR_OUI_BYTE0_SHIFT) |
    1785                 :          0 :                    (oui_bytes[1] << IXGBE_SFF_VENDOR_OUI_BYTE1_SHIFT) |
    1786                 :          0 :                    (oui_bytes[2] << IXGBE_SFF_VENDOR_OUI_BYTE2_SHIFT));
    1787                 :            : 
    1788         [ #  # ]:          0 :                 if (vendor_oui == IXGBE_SFF_VENDOR_OUI_INTEL)
    1789                 :          0 :                         hw->phy.type = ixgbe_phy_qsfp_intel;
    1790                 :            :                 else
    1791                 :          0 :                         hw->phy.type = ixgbe_phy_qsfp_unknown;
    1792                 :            : 
    1793                 :          0 :                 ixgbe_get_device_caps(hw, &enforce_sfp);
    1794         [ #  # ]:          0 :                 if (!(enforce_sfp & IXGBE_DEVICE_CAPS_ALLOW_ANY_SFP)) {
    1795                 :            :                         /* Make sure we're a supported PHY type */
    1796         [ #  # ]:          0 :                         if (hw->phy.type == ixgbe_phy_qsfp_intel) {
    1797                 :            :                                 status = IXGBE_SUCCESS;
    1798                 :            :                         } else {
    1799         [ #  # ]:          0 :                                 if (hw->allow_unsupported_sfp == true) {
    1800                 :          0 :                                         EWARN(hw,
    1801                 :            :                                                 "WARNING: Intel (R) Network Connections are quality tested using Intel (R) Ethernet Optics. "
    1802                 :            :                                                 "Using untested modules is not supported and may cause unstable operation or damage to the module or the adapter. "
    1803                 :            :                                                 "Intel Corporation is not responsible for any harm caused by using untested modules.\n");
    1804                 :            :                                         status = IXGBE_SUCCESS;
    1805                 :            :                                 } else {
    1806                 :          0 :                                         DEBUGOUT("QSFP module not supported\n");
    1807                 :          0 :                                         hw->phy.type =
    1808                 :            :                                                 ixgbe_phy_sfp_unsupported;
    1809                 :            :                                         status = IXGBE_ERR_SFP_NOT_SUPPORTED;
    1810                 :            :                                 }
    1811                 :            :                         }
    1812                 :            :                 } else {
    1813                 :            :                         status = IXGBE_SUCCESS;
    1814                 :            :                 }
    1815                 :            :         }
    1816                 :            : 
    1817                 :          0 : out:
    1818                 :            :         return status;
    1819                 :            : 
    1820                 :          0 : err_read_i2c_eeprom:
    1821                 :          0 :         hw->phy.sfp_type = ixgbe_sfp_type_not_present;
    1822                 :          0 :         hw->phy.id = 0;
    1823                 :          0 :         hw->phy.type = ixgbe_phy_unknown;
    1824                 :            : 
    1825                 :          0 :         return IXGBE_ERR_SFP_NOT_PRESENT;
    1826                 :            : }
    1827                 :            : 
    1828                 :            : /**
    1829                 :            :  * ixgbe_get_sfp_init_sequence_offsets - Provides offset of PHY init sequence
    1830                 :            :  * @hw: pointer to hardware structure
    1831                 :            :  * @list_offset: offset to the SFP ID list
    1832                 :            :  * @data_offset: offset to the SFP data block
    1833                 :            :  *
    1834                 :            :  * Checks the MAC's EEPROM to see if it supports a given SFP+ module type, if
    1835                 :            :  * so it returns the offsets to the phy init sequence block.
    1836                 :            :  **/
    1837                 :          0 : s32 ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw,
    1838                 :            :                                         u16 *list_offset,
    1839                 :            :                                         u16 *data_offset)
    1840                 :            : {
    1841                 :            :         u16 sfp_id;
    1842                 :          0 :         u16 sfp_type = hw->phy.sfp_type;
    1843                 :            : 
    1844                 :          0 :         DEBUGFUNC("ixgbe_get_sfp_init_sequence_offsets");
    1845                 :            : 
    1846         [ #  # ]:          0 :         if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
    1847                 :            :                 return IXGBE_ERR_SFP_NOT_SUPPORTED;
    1848                 :            : 
    1849         [ #  # ]:          0 :         if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
    1850                 :            :                 return IXGBE_ERR_SFP_NOT_PRESENT;
    1851                 :            : 
    1852   [ #  #  #  # ]:          0 :         if ((hw->device_id == IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) &&
    1853                 :            :             (hw->phy.sfp_type == ixgbe_sfp_type_da_cu))
    1854                 :            :                 return IXGBE_ERR_SFP_NOT_SUPPORTED;
    1855                 :            : 
    1856                 :            :         /*
    1857                 :            :          * Limiting active cables and 1G Phys must be initialized as
    1858                 :            :          * SR modules
    1859                 :            :          */
    1860                 :          0 :         if (sfp_type == ixgbe_sfp_type_da_act_lmt_core0 ||
    1861         [ #  # ]:          0 :             sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
    1862                 :            :             sfp_type == ixgbe_sfp_type_1g_lha_core0 ||
    1863                 :            :             sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
    1864                 :            :             sfp_type == ixgbe_sfp_type_1g_sx_core0)
    1865                 :            :                 sfp_type = ixgbe_sfp_type_srlr_core0;
    1866                 :            :         else if (sfp_type == ixgbe_sfp_type_da_act_lmt_core1 ||
    1867                 :            :                  sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
    1868                 :            :                  sfp_type == ixgbe_sfp_type_1g_lha_core1 ||
    1869                 :            :                  sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
    1870                 :            :                  sfp_type == ixgbe_sfp_type_1g_sx_core1)
    1871                 :            :                 sfp_type = ixgbe_sfp_type_srlr_core1;
    1872                 :            : 
    1873                 :            :         /* Read offset to PHY init contents */
    1874         [ #  # ]:          0 :         if (hw->eeprom.ops.read(hw, IXGBE_PHY_INIT_OFFSET_NL, list_offset)) {
    1875                 :          0 :                 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
    1876                 :            :                               "eeprom read at offset %d failed",
    1877                 :            :                               IXGBE_PHY_INIT_OFFSET_NL);
    1878                 :          0 :                 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
    1879                 :            :         }
    1880                 :            : 
    1881         [ #  # ]:          0 :         if ((!*list_offset) || (*list_offset == 0xFFFF))
    1882                 :            :                 return IXGBE_ERR_SFP_NO_INIT_SEQ_PRESENT;
    1883                 :            : 
    1884                 :            :         /* Shift offset to first ID word */
    1885                 :          0 :         (*list_offset)++;
    1886                 :            : 
    1887                 :            :         /*
    1888                 :            :          * Find the matching SFP ID in the EEPROM
    1889                 :            :          * and program the init sequence
    1890                 :            :          */
    1891         [ #  # ]:          0 :         if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
    1892                 :          0 :                 goto err_phy;
    1893                 :            : 
    1894         [ #  # ]:          0 :         while (sfp_id != IXGBE_PHY_INIT_END_NL) {
    1895         [ #  # ]:          0 :                 if (sfp_id == sfp_type) {
    1896                 :          0 :                         (*list_offset)++;
    1897         [ #  # ]:          0 :                         if (hw->eeprom.ops.read(hw, *list_offset, data_offset))
    1898                 :          0 :                                 goto err_phy;
    1899         [ #  # ]:          0 :                         if ((!*data_offset) || (*data_offset == 0xFFFF)) {
    1900                 :          0 :                                 DEBUGOUT("SFP+ module not supported\n");
    1901                 :          0 :                                 return IXGBE_ERR_SFP_NOT_SUPPORTED;
    1902                 :            :                         } else {
    1903                 :            :                                 break;
    1904                 :            :                         }
    1905                 :            :                 } else {
    1906                 :          0 :                         (*list_offset) += 2;
    1907         [ #  # ]:          0 :                         if (hw->eeprom.ops.read(hw, *list_offset, &sfp_id))
    1908                 :          0 :                                 goto err_phy;
    1909                 :            :                 }
    1910                 :            :         }
    1911                 :            : 
    1912         [ #  # ]:          0 :         if (sfp_id == IXGBE_PHY_INIT_END_NL) {
    1913                 :          0 :                 DEBUGOUT("No matching SFP+ module found\n");
    1914                 :          0 :                 return IXGBE_ERR_SFP_NOT_SUPPORTED;
    1915                 :            :         }
    1916                 :            : 
    1917                 :            :         return IXGBE_SUCCESS;
    1918                 :            : 
    1919                 :          0 : err_phy:
    1920                 :          0 :         ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
    1921                 :            :                       "eeprom read at offset %d failed", *list_offset);
    1922                 :          0 :         return IXGBE_ERR_PHY;
    1923                 :            : }
    1924                 :            : 
    1925                 :            : /**
    1926                 :            :  * ixgbe_read_i2c_eeprom_generic - Reads 8 bit EEPROM word over I2C interface
    1927                 :            :  * @hw: pointer to hardware structure
    1928                 :            :  * @byte_offset: EEPROM byte offset to read
    1929                 :            :  * @eeprom_data: value read
    1930                 :            :  *
    1931                 :            :  * Performs byte read operation to SFP module's EEPROM over I2C interface.
    1932                 :            :  **/
    1933                 :          0 : s32 ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
    1934                 :            :                                   u8 *eeprom_data)
    1935                 :            : {
    1936                 :          0 :         DEBUGFUNC("ixgbe_read_i2c_eeprom_generic");
    1937                 :            : 
    1938                 :          0 :         return hw->phy.ops.read_i2c_byte(hw, byte_offset,
    1939                 :            :                                          IXGBE_I2C_EEPROM_DEV_ADDR,
    1940                 :            :                                          eeprom_data);
    1941                 :            : }
    1942                 :            : 
    1943                 :            : /**
    1944                 :            :  * ixgbe_read_i2c_sff8472_generic - Reads 8 bit word over I2C interface
    1945                 :            :  * @hw: pointer to hardware structure
    1946                 :            :  * @byte_offset: byte offset at address 0xA2
    1947                 :            :  * @sff8472_data: value read
    1948                 :            :  *
    1949                 :            :  * Performs byte read operation to SFP module's SFF-8472 data over I2C
    1950                 :            :  **/
    1951                 :          0 : STATIC s32 ixgbe_read_i2c_sff8472_generic(struct ixgbe_hw *hw, u8 byte_offset,
    1952                 :            :                                           u8 *sff8472_data)
    1953                 :            : {
    1954                 :          0 :         return hw->phy.ops.read_i2c_byte(hw, byte_offset,
    1955                 :            :                                          IXGBE_I2C_EEPROM_DEV_ADDR2,
    1956                 :            :                                          sff8472_data);
    1957                 :            : }
    1958                 :            : 
    1959                 :            : /**
    1960                 :            :  * ixgbe_write_i2c_eeprom_generic - Writes 8 bit EEPROM word over I2C interface
    1961                 :            :  * @hw: pointer to hardware structure
    1962                 :            :  * @byte_offset: EEPROM byte offset to write
    1963                 :            :  * @eeprom_data: value to write
    1964                 :            :  *
    1965                 :            :  * Performs byte write operation to SFP module's EEPROM over I2C interface.
    1966                 :            :  **/
    1967                 :          0 : s32 ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, u8 byte_offset,
    1968                 :            :                                    u8 eeprom_data)
    1969                 :            : {
    1970                 :          0 :         DEBUGFUNC("ixgbe_write_i2c_eeprom_generic");
    1971                 :            : 
    1972                 :          0 :         return hw->phy.ops.write_i2c_byte(hw, byte_offset,
    1973                 :            :                                           IXGBE_I2C_EEPROM_DEV_ADDR,
    1974                 :            :                                           eeprom_data);
    1975                 :            : }
    1976                 :            : 
    1977                 :            : /**
    1978                 :            :  * ixgbe_is_sfp_probe - Returns true if SFP is being detected
    1979                 :            :  * @hw: pointer to hardware structure
    1980                 :            :  * @offset: eeprom offset to be read
    1981                 :            :  * @addr: I2C address to be read
    1982                 :            :  */
    1983                 :            : STATIC bool ixgbe_is_sfp_probe(struct ixgbe_hw *hw, u8 offset, u8 addr)
    1984                 :            : {
    1985                 :          0 :         if (addr == IXGBE_I2C_EEPROM_DEV_ADDR &&
    1986                 :          0 :             offset == IXGBE_SFF_IDENTIFIER &&
    1987         [ #  # ]:          0 :             hw->phy.sfp_type == ixgbe_sfp_type_not_present)
    1988                 :            :                 return true;
    1989                 :            :         return false;
    1990                 :            : }
    1991                 :            : 
    1992                 :            : /**
    1993                 :            :  * ixgbe_read_i2c_byte_generic_int - Reads 8 bit word over I2C
    1994                 :            :  * @hw: pointer to hardware structure
    1995                 :            :  * @byte_offset: byte offset to read
    1996                 :            :  * @dev_addr: address to read from
    1997                 :            :  * @data: value read
    1998                 :            :  * @lock: true if to take and release semaphore
    1999                 :            :  *
    2000                 :            :  * Performs byte read operation to SFP module's EEPROM over I2C interface at
    2001                 :            :  * a specified device address.
    2002                 :            :  **/
    2003                 :          0 : STATIC s32 ixgbe_read_i2c_byte_generic_int(struct ixgbe_hw *hw, u8 byte_offset,
    2004                 :            :                                            u8 dev_addr, u8 *data, bool lock)
    2005                 :            : {
    2006                 :            :         s32 status;
    2007                 :            :         u32 max_retry = 10;
    2008                 :            :         u32 retry = 0;
    2009                 :          0 :         u32 swfw_mask = hw->phy.phy_semaphore_mask;
    2010                 :            :         bool nack = 1;
    2011                 :          0 :         *data = 0;
    2012                 :            : 
    2013                 :          0 :         DEBUGFUNC("ixgbe_read_i2c_byte_generic");
    2014                 :            : 
    2015         [ #  # ]:          0 :         if (hw->mac.type >= ixgbe_mac_X550)
    2016                 :            :                 max_retry = 3;
    2017         [ #  # ]:          0 :         if (ixgbe_is_sfp_probe(hw, byte_offset, dev_addr))
    2018                 :            :                 max_retry = IXGBE_SFP_DETECT_RETRIES;
    2019                 :            : 
    2020                 :            :         do {
    2021   [ #  #  #  # ]:          0 :                 if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask))
    2022                 :            :                         return IXGBE_ERR_SWFW_SYNC;
    2023                 :            : 
    2024                 :          0 :                 ixgbe_i2c_start(hw);
    2025                 :            : 
    2026                 :            :                 /* Device Address and write indication */
    2027                 :          0 :                 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
    2028         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    2029                 :          0 :                         goto fail;
    2030                 :            : 
    2031                 :          0 :                 status = ixgbe_get_i2c_ack(hw);
    2032         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    2033                 :          0 :                         goto fail;
    2034                 :            : 
    2035                 :          0 :                 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
    2036         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    2037                 :          0 :                         goto fail;
    2038                 :            : 
    2039                 :          0 :                 status = ixgbe_get_i2c_ack(hw);
    2040         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    2041                 :          0 :                         goto fail;
    2042                 :            : 
    2043                 :          0 :                 ixgbe_i2c_start(hw);
    2044                 :            : 
    2045                 :            :                 /* Device Address and read indication */
    2046                 :          0 :                 status = ixgbe_clock_out_i2c_byte(hw, (dev_addr | 0x1));
    2047         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    2048                 :          0 :                         goto fail;
    2049                 :            : 
    2050                 :          0 :                 status = ixgbe_get_i2c_ack(hw);
    2051         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    2052                 :          0 :                         goto fail;
    2053                 :            : 
    2054                 :          0 :                 ixgbe_clock_in_i2c_byte(hw, data);
    2055                 :            : 
    2056                 :          0 :                 status = ixgbe_clock_out_i2c_bit(hw, nack);
    2057         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    2058                 :          0 :                         goto fail;
    2059                 :            : 
    2060                 :          0 :                 ixgbe_i2c_stop(hw);
    2061         [ #  # ]:          0 :                 if (lock)
    2062                 :          0 :                         hw->mac.ops.release_swfw_sync(hw, swfw_mask);
    2063                 :            :                 return IXGBE_SUCCESS;
    2064                 :            : 
    2065                 :          0 : fail:
    2066                 :          0 :                 ixgbe_i2c_bus_clear(hw);
    2067         [ #  # ]:          0 :                 if (lock) {
    2068                 :          0 :                         hw->mac.ops.release_swfw_sync(hw, swfw_mask);
    2069                 :          0 :                         msec_delay(100);
    2070                 :            :                 }
    2071         [ #  # ]:          0 :                 if (retry < max_retry)
    2072                 :          0 :                         DEBUGOUT("I2C byte read error - Retrying.\n");
    2073                 :            :                 else
    2074                 :          0 :                         DEBUGOUT("I2C byte read error.\n");
    2075                 :          0 :                 retry++;
    2076         [ #  # ]:          0 :         } while (retry <= max_retry);
    2077                 :            : 
    2078                 :            :         return status;
    2079                 :            : }
    2080                 :            : 
    2081                 :            : /**
    2082                 :            :  * ixgbe_read_i2c_byte_generic - Reads 8 bit word over I2C
    2083                 :            :  * @hw: pointer to hardware structure
    2084                 :            :  * @byte_offset: byte offset to read
    2085                 :            :  * @dev_addr: address to read from
    2086                 :            :  * @data: value read
    2087                 :            :  *
    2088                 :            :  * Performs byte read operation to SFP module's EEPROM over I2C interface at
    2089                 :            :  * a specified device address.
    2090                 :            :  **/
    2091                 :          0 : s32 ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
    2092                 :            :                                 u8 dev_addr, u8 *data)
    2093                 :            : {
    2094                 :          0 :         return ixgbe_read_i2c_byte_generic_int(hw, byte_offset, dev_addr,
    2095                 :            :                                                data, true);
    2096                 :            : }
    2097                 :            : 
    2098                 :            : /**
    2099                 :            :  * ixgbe_read_i2c_byte_generic_unlocked - Reads 8 bit word over I2C
    2100                 :            :  * @hw: pointer to hardware structure
    2101                 :            :  * @byte_offset: byte offset to read
    2102                 :            :  * @dev_addr: address to read from
    2103                 :            :  * @data: value read
    2104                 :            :  *
    2105                 :            :  * Performs byte read operation to SFP module's EEPROM over I2C interface at
    2106                 :            :  * a specified device address.
    2107                 :            :  **/
    2108                 :          0 : s32 ixgbe_read_i2c_byte_generic_unlocked(struct ixgbe_hw *hw, u8 byte_offset,
    2109                 :            :                                          u8 dev_addr, u8 *data)
    2110                 :            : {
    2111                 :          0 :         return ixgbe_read_i2c_byte_generic_int(hw, byte_offset, dev_addr,
    2112                 :            :                                                data, false);
    2113                 :            : }
    2114                 :            : 
    2115                 :            : /**
    2116                 :            :  * ixgbe_write_i2c_byte_generic_int - Writes 8 bit word over I2C
    2117                 :            :  * @hw: pointer to hardware structure
    2118                 :            :  * @byte_offset: byte offset to write
    2119                 :            :  * @dev_addr: address to write to
    2120                 :            :  * @data: value to write
    2121                 :            :  * @lock: true if to take and release semaphore
    2122                 :            :  *
    2123                 :            :  * Performs byte write operation to SFP module's EEPROM over I2C interface at
    2124                 :            :  * a specified device address.
    2125                 :            :  **/
    2126                 :          0 : STATIC s32 ixgbe_write_i2c_byte_generic_int(struct ixgbe_hw *hw, u8 byte_offset,
    2127                 :            :                                             u8 dev_addr, u8 data, bool lock)
    2128                 :            : {
    2129                 :            :         s32 status;
    2130                 :            :         u32 max_retry = 1;
    2131                 :            :         u32 retry = 0;
    2132                 :          0 :         u32 swfw_mask = hw->phy.phy_semaphore_mask;
    2133                 :            : 
    2134                 :          0 :         DEBUGFUNC("ixgbe_write_i2c_byte_generic");
    2135                 :            : 
    2136   [ #  #  #  # ]:          0 :         if (lock && hw->mac.ops.acquire_swfw_sync(hw, swfw_mask) !=
    2137                 :            :             IXGBE_SUCCESS)
    2138                 :            :                 return IXGBE_ERR_SWFW_SYNC;
    2139                 :            : 
    2140                 :            :         do {
    2141                 :          0 :                 ixgbe_i2c_start(hw);
    2142                 :            : 
    2143                 :          0 :                 status = ixgbe_clock_out_i2c_byte(hw, dev_addr);
    2144         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    2145                 :          0 :                         goto fail;
    2146                 :            : 
    2147                 :          0 :                 status = ixgbe_get_i2c_ack(hw);
    2148         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    2149                 :          0 :                         goto fail;
    2150                 :            : 
    2151                 :          0 :                 status = ixgbe_clock_out_i2c_byte(hw, byte_offset);
    2152         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    2153                 :          0 :                         goto fail;
    2154                 :            : 
    2155                 :          0 :                 status = ixgbe_get_i2c_ack(hw);
    2156         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    2157                 :          0 :                         goto fail;
    2158                 :            : 
    2159                 :          0 :                 status = ixgbe_clock_out_i2c_byte(hw, data);
    2160         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    2161                 :          0 :                         goto fail;
    2162                 :            : 
    2163                 :          0 :                 status = ixgbe_get_i2c_ack(hw);
    2164         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    2165                 :          0 :                         goto fail;
    2166                 :            : 
    2167                 :          0 :                 ixgbe_i2c_stop(hw);
    2168         [ #  # ]:          0 :                 if (lock)
    2169                 :          0 :                         hw->mac.ops.release_swfw_sync(hw, swfw_mask);
    2170                 :            :                 return IXGBE_SUCCESS;
    2171                 :            : 
    2172                 :          0 : fail:
    2173                 :          0 :                 ixgbe_i2c_bus_clear(hw);
    2174         [ #  # ]:          0 :                 if (retry < max_retry)
    2175                 :          0 :                         DEBUGOUT("I2C byte write error - Retrying.\n");
    2176                 :            :                 else
    2177                 :          0 :                         DEBUGOUT("I2C byte write error.\n");
    2178                 :          0 :                 retry++;
    2179         [ #  # ]:          0 :         } while (retry <= max_retry);
    2180                 :            : 
    2181         [ #  # ]:          0 :         if (lock)
    2182                 :          0 :                 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
    2183                 :            : 
    2184                 :            :         return status;
    2185                 :            : }
    2186                 :            : 
    2187                 :            : /**
    2188                 :            :  * ixgbe_write_i2c_byte_generic - Writes 8 bit word over I2C
    2189                 :            :  * @hw: pointer to hardware structure
    2190                 :            :  * @byte_offset: byte offset to write
    2191                 :            :  * @dev_addr: address to write to
    2192                 :            :  * @data: value to write
    2193                 :            :  *
    2194                 :            :  * Performs byte write operation to SFP module's EEPROM over I2C interface at
    2195                 :            :  * a specified device address.
    2196                 :            :  **/
    2197                 :          0 : s32 ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, u8 byte_offset,
    2198                 :            :                                  u8 dev_addr, u8 data)
    2199                 :            : {
    2200                 :          0 :         return ixgbe_write_i2c_byte_generic_int(hw, byte_offset, dev_addr,
    2201                 :            :                                                 data, true);
    2202                 :            : }
    2203                 :            : 
    2204                 :            : /**
    2205                 :            :  * ixgbe_write_i2c_byte_generic_unlocked - Writes 8 bit word over I2C
    2206                 :            :  * @hw: pointer to hardware structure
    2207                 :            :  * @byte_offset: byte offset to write
    2208                 :            :  * @dev_addr: address to write to
    2209                 :            :  * @data: value to write
    2210                 :            :  *
    2211                 :            :  * Performs byte write operation to SFP module's EEPROM over I2C interface at
    2212                 :            :  * a specified device address.
    2213                 :            :  **/
    2214                 :          0 : s32 ixgbe_write_i2c_byte_generic_unlocked(struct ixgbe_hw *hw, u8 byte_offset,
    2215                 :            :                                           u8 dev_addr, u8 data)
    2216                 :            : {
    2217                 :          0 :         return ixgbe_write_i2c_byte_generic_int(hw, byte_offset, dev_addr,
    2218                 :            :                                                 data, false);
    2219                 :            : }
    2220                 :            : 
    2221                 :            : /**
    2222                 :            :  * ixgbe_i2c_start - Sets I2C start condition
    2223                 :            :  * @hw: pointer to hardware structure
    2224                 :            :  *
    2225                 :            :  * Sets I2C start condition (High -> Low on SDA while SCL is High)
    2226                 :            :  * Set bit-bang mode on X550 hardware.
    2227                 :            :  **/
    2228                 :          0 : STATIC void ixgbe_i2c_start(struct ixgbe_hw *hw)
    2229                 :            : {
    2230                 :          0 :         u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
    2231                 :            : 
    2232                 :          0 :         DEBUGFUNC("ixgbe_i2c_start");
    2233                 :            : 
    2234                 :          0 :         i2cctl |= IXGBE_I2C_BB_EN_BY_MAC(hw);
    2235                 :            : 
    2236                 :            :         /* Start condition must begin with data and clock high */
    2237                 :          0 :         ixgbe_set_i2c_data(hw, &i2cctl, 1);
    2238                 :          0 :         ixgbe_raise_i2c_clk(hw, &i2cctl);
    2239                 :            : 
    2240                 :            :         /* Setup time for start condition (4.7us) */
    2241                 :          0 :         usec_delay(IXGBE_I2C_T_SU_STA);
    2242                 :            : 
    2243                 :          0 :         ixgbe_set_i2c_data(hw, &i2cctl, 0);
    2244                 :            : 
    2245                 :            :         /* Hold time for start condition (4us) */
    2246                 :          0 :         usec_delay(IXGBE_I2C_T_HD_STA);
    2247                 :            : 
    2248                 :          0 :         ixgbe_lower_i2c_clk(hw, &i2cctl);
    2249                 :            : 
    2250                 :            :         /* Minimum low period of clock is 4.7 us */
    2251                 :          0 :         usec_delay(IXGBE_I2C_T_LOW);
    2252                 :            : 
    2253                 :          0 : }
    2254                 :            : 
    2255                 :            : /**
    2256                 :            :  * ixgbe_i2c_stop - Sets I2C stop condition
    2257                 :            :  * @hw: pointer to hardware structure
    2258                 :            :  *
    2259                 :            :  * Sets I2C stop condition (Low -> High on SDA while SCL is High)
    2260                 :            :  * Disables bit-bang mode and negates data output enable on X550
    2261                 :            :  * hardware.
    2262                 :            :  **/
    2263                 :          0 : STATIC void ixgbe_i2c_stop(struct ixgbe_hw *hw)
    2264                 :            : {
    2265                 :          0 :         u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
    2266                 :          0 :         u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
    2267                 :          0 :         u32 clk_oe_bit = IXGBE_I2C_CLK_OE_N_EN_BY_MAC(hw);
    2268                 :          0 :         u32 bb_en_bit = IXGBE_I2C_BB_EN_BY_MAC(hw);
    2269                 :            : 
    2270                 :          0 :         DEBUGFUNC("ixgbe_i2c_stop");
    2271                 :            : 
    2272                 :            :         /* Stop condition must begin with data low and clock high */
    2273                 :          0 :         ixgbe_set_i2c_data(hw, &i2cctl, 0);
    2274                 :          0 :         ixgbe_raise_i2c_clk(hw, &i2cctl);
    2275                 :            : 
    2276                 :            :         /* Setup time for stop condition (4us) */
    2277                 :          0 :         usec_delay(IXGBE_I2C_T_SU_STO);
    2278                 :            : 
    2279                 :          0 :         ixgbe_set_i2c_data(hw, &i2cctl, 1);
    2280                 :            : 
    2281                 :            :         /* bus free time between stop and start (4.7us)*/
    2282                 :          0 :         usec_delay(IXGBE_I2C_T_BUF);
    2283                 :            : 
    2284         [ #  # ]:          0 :         if (bb_en_bit || data_oe_bit || clk_oe_bit) {
    2285                 :          0 :                 i2cctl &= ~bb_en_bit;
    2286                 :          0 :                 i2cctl |= data_oe_bit | clk_oe_bit;
    2287                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), i2cctl);
    2288                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    2289                 :            :         }
    2290                 :          0 : }
    2291                 :            : 
    2292                 :            : /**
    2293                 :            :  * ixgbe_clock_in_i2c_byte - Clocks in one byte via I2C
    2294                 :            :  * @hw: pointer to hardware structure
    2295                 :            :  * @data: data byte to clock in
    2296                 :            :  *
    2297                 :            :  * Clocks in one byte data via I2C data/clock
    2298                 :            :  **/
    2299                 :          0 : STATIC void ixgbe_clock_in_i2c_byte(struct ixgbe_hw *hw, u8 *data)
    2300                 :            : {
    2301                 :            :         s32 i;
    2302                 :          0 :         bool bit = 0;
    2303                 :            : 
    2304                 :          0 :         DEBUGFUNC("ixgbe_clock_in_i2c_byte");
    2305                 :            : 
    2306                 :          0 :         *data = 0;
    2307         [ #  # ]:          0 :         for (i = 7; i >= 0; i--) {
    2308                 :          0 :                 ixgbe_clock_in_i2c_bit(hw, &bit);
    2309                 :          0 :                 *data |= bit << i;
    2310                 :            :         }
    2311                 :          0 : }
    2312                 :            : 
    2313                 :            : /**
    2314                 :            :  * ixgbe_clock_out_i2c_byte - Clocks out one byte via I2C
    2315                 :            :  * @hw: pointer to hardware structure
    2316                 :            :  * @data: data byte clocked out
    2317                 :            :  *
    2318                 :            :  * Clocks out one byte data via I2C data/clock
    2319                 :            :  **/
    2320                 :          0 : STATIC s32 ixgbe_clock_out_i2c_byte(struct ixgbe_hw *hw, u8 data)
    2321                 :            : {
    2322                 :            :         s32 status = IXGBE_SUCCESS;
    2323                 :            :         s32 i;
    2324                 :            :         u32 i2cctl;
    2325                 :            :         bool bit;
    2326                 :            : 
    2327                 :          0 :         DEBUGFUNC("ixgbe_clock_out_i2c_byte");
    2328                 :            : 
    2329         [ #  # ]:          0 :         for (i = 7; i >= 0; i--) {
    2330                 :          0 :                 bit = (data >> i) & 0x1;
    2331                 :          0 :                 status = ixgbe_clock_out_i2c_bit(hw, bit);
    2332                 :            : 
    2333         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    2334                 :            :                         break;
    2335                 :            :         }
    2336                 :            : 
    2337                 :            :         /* Release SDA line (set high) */
    2338                 :          0 :         i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
    2339                 :          0 :         i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
    2340                 :          0 :         i2cctl |= IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
    2341                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), i2cctl);
    2342                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    2343                 :            : 
    2344                 :          0 :         return status;
    2345                 :            : }
    2346                 :            : 
    2347                 :            : /**
    2348                 :            :  * ixgbe_get_i2c_ack - Polls for I2C ACK
    2349                 :            :  * @hw: pointer to hardware structure
    2350                 :            :  *
    2351                 :            :  * Clocks in/out one bit via I2C data/clock
    2352                 :            :  **/
    2353                 :          0 : STATIC s32 ixgbe_get_i2c_ack(struct ixgbe_hw *hw)
    2354                 :            : {
    2355                 :          0 :         u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
    2356                 :            :         s32 status = IXGBE_SUCCESS;
    2357                 :            :         u32 i = 0;
    2358                 :          0 :         u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
    2359                 :            :         u32 timeout = 10;
    2360                 :            :         bool ack = 1;
    2361                 :            : 
    2362                 :          0 :         DEBUGFUNC("ixgbe_get_i2c_ack");
    2363                 :            : 
    2364         [ #  # ]:          0 :         if (data_oe_bit) {
    2365                 :          0 :                 i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
    2366                 :          0 :                 i2cctl |= data_oe_bit;
    2367                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), i2cctl);
    2368                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    2369                 :            :         }
    2370                 :          0 :         ixgbe_raise_i2c_clk(hw, &i2cctl);
    2371                 :            : 
    2372                 :            :         /* Minimum high period of clock is 4us */
    2373                 :          0 :         usec_delay(IXGBE_I2C_T_HIGH);
    2374                 :            : 
    2375                 :            :         /* Poll for ACK.  Note that ACK in I2C spec is
    2376                 :            :          * transition from 1 to 0 */
    2377         [ #  # ]:          0 :         for (i = 0; i < timeout; i++) {
    2378                 :          0 :                 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
    2379                 :          0 :                 ack = ixgbe_get_i2c_data(hw, &i2cctl);
    2380                 :            : 
    2381                 :          0 :                 usec_delay(1);
    2382         [ #  # ]:          0 :                 if (!ack)
    2383                 :            :                         break;
    2384                 :            :         }
    2385                 :            : 
    2386         [ #  # ]:          0 :         if (ack) {
    2387                 :          0 :                 DEBUGOUT("I2C ack was not received.\n");
    2388                 :            :                 status = IXGBE_ERR_I2C;
    2389                 :            :         }
    2390                 :            : 
    2391                 :          0 :         ixgbe_lower_i2c_clk(hw, &i2cctl);
    2392                 :            : 
    2393                 :            :         /* Minimum low period of clock is 4.7 us */
    2394                 :          0 :         usec_delay(IXGBE_I2C_T_LOW);
    2395                 :            : 
    2396                 :          0 :         return status;
    2397                 :            : }
    2398                 :            : 
    2399                 :            : /**
    2400                 :            :  * ixgbe_clock_in_i2c_bit - Clocks in one bit via I2C data/clock
    2401                 :            :  * @hw: pointer to hardware structure
    2402                 :            :  * @data: read data value
    2403                 :            :  *
    2404                 :            :  * Clocks in one bit via I2C data/clock
    2405                 :            :  **/
    2406                 :          0 : STATIC void ixgbe_clock_in_i2c_bit(struct ixgbe_hw *hw, bool *data)
    2407                 :            : {
    2408                 :          0 :         u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
    2409                 :          0 :         u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
    2410                 :            : 
    2411                 :          0 :         DEBUGFUNC("ixgbe_clock_in_i2c_bit");
    2412                 :            : 
    2413         [ #  # ]:          0 :         if (data_oe_bit) {
    2414                 :          0 :                 i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
    2415                 :          0 :                 i2cctl |= data_oe_bit;
    2416                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), i2cctl);
    2417                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    2418                 :            :         }
    2419                 :          0 :         ixgbe_raise_i2c_clk(hw, &i2cctl);
    2420                 :            : 
    2421                 :            :         /* Minimum high period of clock is 4us */
    2422                 :          0 :         usec_delay(IXGBE_I2C_T_HIGH);
    2423                 :            : 
    2424                 :          0 :         i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
    2425                 :          0 :         *data = ixgbe_get_i2c_data(hw, &i2cctl);
    2426                 :            : 
    2427                 :          0 :         ixgbe_lower_i2c_clk(hw, &i2cctl);
    2428                 :            : 
    2429                 :            :         /* Minimum low period of clock is 4.7 us */
    2430                 :          0 :         usec_delay(IXGBE_I2C_T_LOW);
    2431                 :          0 : }
    2432                 :            : 
    2433                 :            : /**
    2434                 :            :  * ixgbe_clock_out_i2c_bit - Clocks in/out one bit via I2C data/clock
    2435                 :            :  * @hw: pointer to hardware structure
    2436                 :            :  * @data: data value to write
    2437                 :            :  *
    2438                 :            :  * Clocks out one bit via I2C data/clock
    2439                 :            :  **/
    2440                 :          0 : STATIC s32 ixgbe_clock_out_i2c_bit(struct ixgbe_hw *hw, bool data)
    2441                 :            : {
    2442                 :            :         s32 status;
    2443                 :          0 :         u32 i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
    2444                 :            : 
    2445                 :          0 :         DEBUGFUNC("ixgbe_clock_out_i2c_bit");
    2446                 :            : 
    2447                 :          0 :         status = ixgbe_set_i2c_data(hw, &i2cctl, data);
    2448         [ #  # ]:          0 :         if (status == IXGBE_SUCCESS) {
    2449                 :          0 :                 ixgbe_raise_i2c_clk(hw, &i2cctl);
    2450                 :            : 
    2451                 :            :                 /* Minimum high period of clock is 4us */
    2452                 :          0 :                 usec_delay(IXGBE_I2C_T_HIGH);
    2453                 :            : 
    2454                 :          0 :                 ixgbe_lower_i2c_clk(hw, &i2cctl);
    2455                 :            : 
    2456                 :            :                 /* Minimum low period of clock is 4.7 us.
    2457                 :            :                  * This also takes care of the data hold time.
    2458                 :            :                  */
    2459                 :          0 :                 usec_delay(IXGBE_I2C_T_LOW);
    2460                 :            :         } else {
    2461                 :            :                 status = IXGBE_ERR_I2C;
    2462                 :          0 :                 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
    2463                 :            :                              "I2C data was not set to %X\n", data);
    2464                 :            :         }
    2465                 :            : 
    2466                 :          0 :         return status;
    2467                 :            : }
    2468                 :            : 
    2469                 :            : /**
    2470                 :            :  * ixgbe_raise_i2c_clk - Raises the I2C SCL clock
    2471                 :            :  * @hw: pointer to hardware structure
    2472                 :            :  * @i2cctl: Current value of I2CCTL register
    2473                 :            :  *
    2474                 :            :  * Raises the I2C clock line '0'->'1'
    2475                 :            :  * Negates the I2C clock output enable on X550 hardware.
    2476                 :            :  **/
    2477                 :          0 : STATIC void ixgbe_raise_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
    2478                 :            : {
    2479                 :          0 :         u32 clk_oe_bit = IXGBE_I2C_CLK_OE_N_EN_BY_MAC(hw);
    2480                 :            :         u32 i = 0;
    2481                 :            :         u32 timeout = IXGBE_I2C_CLOCK_STRETCHING_TIMEOUT;
    2482                 :            :         u32 i2cctl_r = 0;
    2483                 :            : 
    2484                 :          0 :         DEBUGFUNC("ixgbe_raise_i2c_clk");
    2485                 :            : 
    2486         [ #  # ]:          0 :         if (clk_oe_bit) {
    2487                 :          0 :                 *i2cctl |= clk_oe_bit;
    2488                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
    2489                 :            :         }
    2490                 :            : 
    2491         [ #  # ]:          0 :         for (i = 0; i < timeout; i++) {
    2492                 :          0 :                 *i2cctl |= IXGBE_I2C_CLK_OUT_BY_MAC(hw);
    2493                 :            : 
    2494                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
    2495                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    2496                 :            :                 /* SCL rise time (1000ns) */
    2497                 :          0 :                 usec_delay(IXGBE_I2C_T_RISE);
    2498                 :            : 
    2499                 :          0 :                 i2cctl_r = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
    2500         [ #  # ]:          0 :                 if (i2cctl_r & IXGBE_I2C_CLK_IN_BY_MAC(hw))
    2501                 :            :                         break;
    2502                 :            :         }
    2503                 :          0 : }
    2504                 :            : 
    2505                 :            : /**
    2506                 :            :  * ixgbe_lower_i2c_clk - Lowers the I2C SCL clock
    2507                 :            :  * @hw: pointer to hardware structure
    2508                 :            :  * @i2cctl: Current value of I2CCTL register
    2509                 :            :  *
    2510                 :            :  * Lowers the I2C clock line '1'->'0'
    2511                 :            :  * Asserts the I2C clock output enable on X550 hardware.
    2512                 :            :  **/
    2513                 :          0 : STATIC void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl)
    2514                 :            : {
    2515                 :          0 :         DEBUGFUNC("ixgbe_lower_i2c_clk");
    2516                 :            : 
    2517                 :          0 :         *i2cctl &= ~(IXGBE_I2C_CLK_OUT_BY_MAC(hw));
    2518                 :          0 :         *i2cctl &= ~IXGBE_I2C_CLK_OE_N_EN_BY_MAC(hw);
    2519                 :            : 
    2520                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
    2521                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    2522                 :            : 
    2523                 :            :         /* SCL fall time (300ns) */
    2524                 :          0 :         usec_delay(IXGBE_I2C_T_FALL);
    2525                 :          0 : }
    2526                 :            : 
    2527                 :            : /**
    2528                 :            :  * ixgbe_set_i2c_data - Sets the I2C data bit
    2529                 :            :  * @hw: pointer to hardware structure
    2530                 :            :  * @i2cctl: Current value of I2CCTL register
    2531                 :            :  * @data: I2C data value (0 or 1) to set
    2532                 :            :  *
    2533                 :            :  * Sets the I2C data bit
    2534                 :            :  * Asserts the I2C data output enable on X550 hardware.
    2535                 :            :  **/
    2536                 :          0 : STATIC s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data)
    2537                 :            : {
    2538                 :          0 :         u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
    2539                 :            :         s32 status = IXGBE_SUCCESS;
    2540                 :            : 
    2541                 :          0 :         DEBUGFUNC("ixgbe_set_i2c_data");
    2542                 :            : 
    2543         [ #  # ]:          0 :         if (data)
    2544                 :          0 :                 *i2cctl |= IXGBE_I2C_DATA_OUT_BY_MAC(hw);
    2545                 :            :         else
    2546                 :          0 :                 *i2cctl &= ~(IXGBE_I2C_DATA_OUT_BY_MAC(hw));
    2547                 :          0 :         *i2cctl &= ~data_oe_bit;
    2548                 :            : 
    2549                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
    2550                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    2551                 :            : 
    2552                 :            :         /* Data rise/fall (1000ns/300ns) and set-up time (250ns) */
    2553                 :          0 :         usec_delay(IXGBE_I2C_T_RISE + IXGBE_I2C_T_FALL + IXGBE_I2C_T_SU_DATA);
    2554                 :            : 
    2555         [ #  # ]:          0 :         if (!data)      /* Can't verify data in this case */
    2556                 :            :                 return IXGBE_SUCCESS;
    2557         [ #  # ]:          0 :         if (data_oe_bit) {
    2558                 :          0 :                 *i2cctl |= data_oe_bit;
    2559                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
    2560                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    2561                 :            :         }
    2562                 :            : 
    2563                 :            :         /* Verify data was set correctly */
    2564                 :          0 :         *i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
    2565         [ #  # ]:          0 :         if (data != ixgbe_get_i2c_data(hw, i2cctl)) {
    2566                 :            :                 status = IXGBE_ERR_I2C;
    2567                 :          0 :                 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
    2568                 :            :                              "Error - I2C data was not set to %X.\n",
    2569                 :            :                              data);
    2570                 :            :         }
    2571                 :            : 
    2572                 :            :         return status;
    2573                 :            : }
    2574                 :            : 
    2575                 :            : /**
    2576                 :            :  * ixgbe_get_i2c_data - Reads the I2C SDA data bit
    2577                 :            :  * @hw: pointer to hardware structure
    2578                 :            :  * @i2cctl: Current value of I2CCTL register
    2579                 :            :  *
    2580                 :            :  * Returns the I2C data bit value
    2581                 :            :  * Negates the I2C data output enable on X550 hardware.
    2582                 :            :  **/
    2583                 :          0 : STATIC bool ixgbe_get_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl)
    2584                 :            : {
    2585                 :          0 :         u32 data_oe_bit = IXGBE_I2C_DATA_OE_N_EN_BY_MAC(hw);
    2586                 :            :         bool data;
    2587                 :            : 
    2588                 :          0 :         DEBUGFUNC("ixgbe_get_i2c_data");
    2589                 :            : 
    2590         [ #  # ]:          0 :         if (data_oe_bit) {
    2591                 :          0 :                 *i2cctl |= data_oe_bit;
    2592                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_I2CCTL_BY_MAC(hw), *i2cctl);
    2593                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    2594                 :          0 :                 usec_delay(IXGBE_I2C_T_FALL);
    2595                 :            :         }
    2596                 :            : 
    2597         [ #  # ]:          0 :         if (*i2cctl & IXGBE_I2C_DATA_IN_BY_MAC(hw))
    2598                 :            :                 data = 1;
    2599                 :            :         else
    2600                 :            :                 data = 0;
    2601                 :            : 
    2602                 :          0 :         return data;
    2603                 :            : }
    2604                 :            : 
    2605                 :            : /**
    2606                 :            :  * ixgbe_i2c_bus_clear - Clears the I2C bus
    2607                 :            :  * @hw: pointer to hardware structure
    2608                 :            :  *
    2609                 :            :  * Clears the I2C bus by sending nine clock pulses.
    2610                 :            :  * Used when data line is stuck low.
    2611                 :            :  **/
    2612                 :          0 : void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw)
    2613                 :            : {
    2614                 :            :         u32 i2cctl;
    2615                 :            :         u32 i;
    2616                 :            : 
    2617                 :          0 :         DEBUGFUNC("ixgbe_i2c_bus_clear");
    2618                 :            : 
    2619                 :          0 :         ixgbe_i2c_start(hw);
    2620                 :          0 :         i2cctl = IXGBE_READ_REG(hw, IXGBE_I2CCTL_BY_MAC(hw));
    2621                 :            : 
    2622                 :          0 :         ixgbe_set_i2c_data(hw, &i2cctl, 1);
    2623                 :            : 
    2624         [ #  # ]:          0 :         for (i = 0; i < 9; i++) {
    2625                 :          0 :                 ixgbe_raise_i2c_clk(hw, &i2cctl);
    2626                 :            : 
    2627                 :            :                 /* Min high period of clock is 4us */
    2628                 :          0 :                 usec_delay(IXGBE_I2C_T_HIGH);
    2629                 :            : 
    2630                 :          0 :                 ixgbe_lower_i2c_clk(hw, &i2cctl);
    2631                 :            : 
    2632                 :            :                 /* Min low period of clock is 4.7us*/
    2633                 :          0 :                 usec_delay(IXGBE_I2C_T_LOW);
    2634                 :            :         }
    2635                 :            : 
    2636                 :          0 :         ixgbe_i2c_start(hw);
    2637                 :            : 
    2638                 :            :         /* Put the i2c bus back to default state */
    2639                 :          0 :         ixgbe_i2c_stop(hw);
    2640                 :          0 : }
    2641                 :            : 
    2642                 :            : /**
    2643                 :            :  * ixgbe_tn_check_overtemp - Checks if an overtemp occurred.
    2644                 :            :  * @hw: pointer to hardware structure
    2645                 :            :  *
    2646                 :            :  * Checks if the LASI temp alarm status was triggered due to overtemp
    2647                 :            :  **/
    2648                 :          0 : s32 ixgbe_tn_check_overtemp(struct ixgbe_hw *hw)
    2649                 :            : {
    2650                 :            :         s32 status = IXGBE_SUCCESS;
    2651                 :          0 :         u16 phy_data = 0;
    2652                 :            : 
    2653                 :          0 :         DEBUGFUNC("ixgbe_tn_check_overtemp");
    2654                 :            : 
    2655         [ #  # ]:          0 :         if (hw->device_id != IXGBE_DEV_ID_82599_T3_LOM)
    2656                 :          0 :                 goto out;
    2657                 :            : 
    2658                 :            :         /* Check that the LASI temp alarm status was triggered */
    2659                 :          0 :         hw->phy.ops.read_reg(hw, IXGBE_TN_LASI_STATUS_REG,
    2660                 :            :                              IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_data);
    2661                 :            : 
    2662         [ #  # ]:          0 :         if (!(phy_data & IXGBE_TN_LASI_STATUS_TEMP_ALARM))
    2663                 :          0 :                 goto out;
    2664                 :            : 
    2665                 :            :         status = IXGBE_ERR_OVERTEMP;
    2666                 :          0 :         ERROR_REPORT1(IXGBE_ERROR_CAUTION, "Device over temperature");
    2667                 :          0 : out:
    2668                 :          0 :         return status;
    2669                 :            : }
    2670                 :            : 
    2671                 :            : /**
    2672                 :            :  * ixgbe_set_copper_phy_power - Control power for copper phy
    2673                 :            :  * @hw: pointer to hardware structure
    2674                 :            :  * @on: true for on, false for off
    2675                 :            :  */
    2676                 :          0 : s32 ixgbe_set_copper_phy_power(struct ixgbe_hw *hw, bool on)
    2677                 :            : {
    2678                 :            :         u32 status;
    2679                 :            :         u16 reg;
    2680                 :            : 
    2681   [ #  #  #  # ]:          0 :         if (!on && ixgbe_mng_present(hw))
    2682                 :            :                 return 0;
    2683                 :            : 
    2684                 :          0 :         status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
    2685                 :            :                                       IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
    2686                 :            :                                       &reg);
    2687         [ #  # ]:          0 :         if (status)
    2688                 :            :                 return status;
    2689                 :            : 
    2690         [ #  # ]:          0 :         if (on) {
    2691                 :          0 :                 reg &= ~IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
    2692                 :            :         } else {
    2693         [ #  # ]:          0 :                 if (ixgbe_check_reset_blocked(hw))
    2694                 :            :                         return 0;
    2695                 :          0 :                 reg |= IXGBE_MDIO_PHY_SET_LOW_POWER_MODE;
    2696                 :            :         }
    2697                 :            : 
    2698                 :          0 :         status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
    2699                 :            :                                        IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
    2700                 :            :                                        reg);
    2701                 :          0 :         return status;
    2702                 :            : }

Generated by: LCOV version 1.14