LCOV - code coverage report
Current view: top level - drivers/net/igc/base - igc_phy.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 1477 0.0 %
Date: 2025-01-02 22:41:34 Functions: 0 96 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 835 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2001-2020 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "igc_api.h"
       6                 :            : 
       7                 :            : static s32 igc_wait_autoneg(struct igc_hw *hw);
       8                 :            : static s32 igc_access_phy_wakeup_reg_bm(struct igc_hw *hw, u32 offset,
       9                 :            :                                           u16 *data, bool read, bool page_set);
      10                 :            : static u32 igc_get_phy_addr_for_hv_page(u32 page);
      11                 :            : static s32 igc_access_phy_debug_regs_hv(struct igc_hw *hw, u32 offset,
      12                 :            :                                           u16 *data, bool read);
      13                 :            : 
      14                 :            : /* Cable length tables */
      15                 :            : static const u16 igc_m88_cable_length_table[] = {
      16                 :            :         0, 50, 80, 110, 140, 140, IGC_CABLE_LENGTH_UNDEFINED };
      17                 :            : #define M88IGC_CABLE_LENGTH_TABLE_SIZE \
      18                 :            :                 (sizeof(igc_m88_cable_length_table) / \
      19                 :            :                  sizeof(igc_m88_cable_length_table[0]))
      20                 :            : 
      21                 :            : static const u16 igc_igp_2_cable_length_table[] = {
      22                 :            :         0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, 0, 0, 0, 3,
      23                 :            :         6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, 6, 10, 14, 18, 22,
      24                 :            :         26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, 21, 26, 31, 35, 40,
      25                 :            :         44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, 40, 45, 51, 56, 61,
      26                 :            :         66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, 60, 66, 72, 77, 82,
      27                 :            :         87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, 83, 89, 95,
      28                 :            :         100, 105, 109, 113, 116, 119, 122, 124, 104, 109, 114, 118, 121,
      29                 :            :         124};
      30                 :            : #define IGP02IGC_CABLE_LENGTH_TABLE_SIZE \
      31                 :            :                 (sizeof(igc_igp_2_cable_length_table) / \
      32                 :            :                  sizeof(igc_igp_2_cable_length_table[0]))
      33                 :            : 
      34                 :            : /**
      35                 :            :  *  igc_init_phy_ops_generic - Initialize PHY function pointers
      36                 :            :  *  @hw: pointer to the HW structure
      37                 :            :  *
      38                 :            :  *  Setups up the function pointers to no-op functions
      39                 :            :  **/
      40                 :          0 : void igc_init_phy_ops_generic(struct igc_hw *hw)
      41                 :            : {
      42                 :            :         struct igc_phy_info *phy = &hw->phy;
      43                 :          0 :         DEBUGFUNC("igc_init_phy_ops_generic");
      44                 :            : 
      45                 :            :         /* Initialize function pointers */
      46                 :          0 :         phy->ops.init_params = igc_null_ops_generic;
      47                 :          0 :         phy->ops.acquire = igc_null_ops_generic;
      48                 :          0 :         phy->ops.check_polarity = igc_null_ops_generic;
      49                 :          0 :         phy->ops.check_reset_block = igc_null_ops_generic;
      50                 :          0 :         phy->ops.commit = igc_null_ops_generic;
      51                 :          0 :         phy->ops.force_speed_duplex = igc_null_ops_generic;
      52                 :          0 :         phy->ops.get_cfg_done = igc_null_ops_generic;
      53                 :          0 :         phy->ops.get_cable_length = igc_null_ops_generic;
      54                 :          0 :         phy->ops.get_info = igc_null_ops_generic;
      55                 :          0 :         phy->ops.set_page = igc_null_set_page;
      56                 :          0 :         phy->ops.read_reg = igc_null_read_reg;
      57                 :          0 :         phy->ops.read_reg_locked = igc_null_read_reg;
      58                 :          0 :         phy->ops.read_reg_page = igc_null_read_reg;
      59                 :          0 :         phy->ops.release = igc_null_phy_generic;
      60                 :          0 :         phy->ops.reset = igc_null_ops_generic;
      61                 :          0 :         phy->ops.set_d0_lplu_state = igc_null_lplu_state;
      62                 :          0 :         phy->ops.set_d3_lplu_state = igc_null_lplu_state;
      63                 :          0 :         phy->ops.write_reg = igc_null_write_reg;
      64                 :          0 :         phy->ops.write_reg_locked = igc_null_write_reg;
      65                 :          0 :         phy->ops.write_reg_page = igc_null_write_reg;
      66                 :          0 :         phy->ops.power_up = igc_null_phy_generic;
      67                 :          0 :         phy->ops.power_down = igc_null_phy_generic;
      68                 :          0 :         phy->ops.read_i2c_byte = igc_read_i2c_byte_null;
      69                 :          0 :         phy->ops.write_i2c_byte = igc_write_i2c_byte_null;
      70                 :          0 :         phy->ops.cfg_on_link_up = igc_null_ops_generic;
      71                 :          0 : }
      72                 :            : 
      73                 :            : /**
      74                 :            :  *  igc_null_set_page - No-op function, return 0
      75                 :            :  *  @hw: pointer to the HW structure
      76                 :            :  *  @data: dummy variable
      77                 :            :  **/
      78                 :          0 : s32 igc_null_set_page(struct igc_hw IGC_UNUSEDARG * hw,
      79                 :            :                         u16 IGC_UNUSEDARG data)
      80                 :            : {
      81                 :          0 :         DEBUGFUNC("igc_null_set_page");
      82                 :            :         UNREFERENCED_2PARAMETER(hw, data);
      83                 :          0 :         return IGC_SUCCESS;
      84                 :            : }
      85                 :            : 
      86                 :            : /**
      87                 :            :  *  igc_null_read_reg - No-op function, return 0
      88                 :            :  *  @hw: pointer to the HW structure
      89                 :            :  *  @offset: dummy variable
      90                 :            :  *  @data: dummy variable
      91                 :            :  **/
      92                 :          0 : s32 igc_null_read_reg(struct igc_hw IGC_UNUSEDARG * hw,
      93                 :            :                         u32 IGC_UNUSEDARG offset, u16 IGC_UNUSEDARG * data)
      94                 :            : {
      95                 :          0 :         DEBUGFUNC("igc_null_read_reg");
      96                 :            :         UNREFERENCED_3PARAMETER(hw, offset, data);
      97                 :          0 :         return IGC_SUCCESS;
      98                 :            : }
      99                 :            : 
     100                 :            : /**
     101                 :            :  *  igc_null_phy_generic - No-op function, return void
     102                 :            :  *  @hw: pointer to the HW structure
     103                 :            :  **/
     104                 :          0 : void igc_null_phy_generic(struct igc_hw IGC_UNUSEDARG * hw)
     105                 :            : {
     106                 :          0 :         DEBUGFUNC("igc_null_phy_generic");
     107                 :            :         UNREFERENCED_1PARAMETER(hw);
     108                 :          0 : }
     109                 :            : 
     110                 :            : /**
     111                 :            :  *  igc_null_lplu_state - No-op function, return 0
     112                 :            :  *  @hw: pointer to the HW structure
     113                 :            :  *  @active: dummy variable
     114                 :            :  **/
     115                 :          0 : s32 igc_null_lplu_state(struct igc_hw IGC_UNUSEDARG * hw,
     116                 :            :                           bool IGC_UNUSEDARG active)
     117                 :            : {
     118                 :          0 :         DEBUGFUNC("igc_null_lplu_state");
     119                 :            :         UNREFERENCED_2PARAMETER(hw, active);
     120                 :          0 :         return IGC_SUCCESS;
     121                 :            : }
     122                 :            : 
     123                 :            : /**
     124                 :            :  *  igc_null_write_reg - No-op function, return 0
     125                 :            :  *  @hw: pointer to the HW structure
     126                 :            :  *  @offset: dummy variable
     127                 :            :  *  @data: dummy variable
     128                 :            :  **/
     129                 :          0 : s32 igc_null_write_reg(struct igc_hw IGC_UNUSEDARG * hw,
     130                 :            :                          u32 IGC_UNUSEDARG offset, u16 IGC_UNUSEDARG data)
     131                 :            : {
     132                 :          0 :         DEBUGFUNC("igc_null_write_reg");
     133                 :            :         UNREFERENCED_3PARAMETER(hw, offset, data);
     134                 :          0 :         return IGC_SUCCESS;
     135                 :            : }
     136                 :            : 
     137                 :            : /**
     138                 :            :  *  igc_read_i2c_byte_null - No-op function, return 0
     139                 :            :  *  @hw: pointer to hardware structure
     140                 :            :  *  @byte_offset: byte offset to write
     141                 :            :  *  @dev_addr: device address
     142                 :            :  *  @data: data value read
     143                 :            :  *
     144                 :            :  **/
     145                 :          0 : s32 igc_read_i2c_byte_null(struct igc_hw IGC_UNUSEDARG * hw,
     146                 :            :                              u8 IGC_UNUSEDARG byte_offset,
     147                 :            :                              u8 IGC_UNUSEDARG dev_addr,
     148                 :            :                              u8 IGC_UNUSEDARG * data)
     149                 :            : {
     150                 :          0 :         DEBUGFUNC("igc_read_i2c_byte_null");
     151                 :            :         UNREFERENCED_4PARAMETER(hw, byte_offset, dev_addr, data);
     152                 :          0 :         return IGC_SUCCESS;
     153                 :            : }
     154                 :            : 
     155                 :            : /**
     156                 :            :  *  igc_write_i2c_byte_null - No-op function, return 0
     157                 :            :  *  @hw: pointer to hardware structure
     158                 :            :  *  @byte_offset: byte offset to write
     159                 :            :  *  @dev_addr: device address
     160                 :            :  *  @data: data value to write
     161                 :            :  *
     162                 :            :  **/
     163                 :          0 : s32 igc_write_i2c_byte_null(struct igc_hw IGC_UNUSEDARG * hw,
     164                 :            :                               u8 IGC_UNUSEDARG byte_offset,
     165                 :            :                               u8 IGC_UNUSEDARG dev_addr,
     166                 :            :                               u8 IGC_UNUSEDARG data)
     167                 :            : {
     168                 :          0 :         DEBUGFUNC("igc_write_i2c_byte_null");
     169                 :            :         UNREFERENCED_4PARAMETER(hw, byte_offset, dev_addr, data);
     170                 :          0 :         return IGC_SUCCESS;
     171                 :            : }
     172                 :            : 
     173                 :            : /**
     174                 :            :  *  igc_check_reset_block_generic - Check if PHY reset is blocked
     175                 :            :  *  @hw: pointer to the HW structure
     176                 :            :  *
     177                 :            :  *  Read the PHY management control register and check whether a PHY reset
     178                 :            :  *  is blocked.  If a reset is not blocked return IGC_SUCCESS, otherwise
     179                 :            :  *  return IGC_BLK_PHY_RESET (12).
     180                 :            :  **/
     181                 :          0 : s32 igc_check_reset_block_generic(struct igc_hw *hw)
     182                 :            : {
     183                 :            :         u32 manc;
     184                 :            : 
     185                 :          0 :         DEBUGFUNC("igc_check_reset_block");
     186                 :            : 
     187                 :          0 :         manc = IGC_READ_REG(hw, IGC_MANC);
     188                 :            : 
     189                 :          0 :         return (manc & IGC_MANC_BLK_PHY_RST_ON_IDE) ?
     190         [ #  # ]:          0 :                IGC_BLK_PHY_RESET : IGC_SUCCESS;
     191                 :            : }
     192                 :            : 
     193                 :            : /**
     194                 :            :  *  igc_get_phy_id - Retrieve the PHY ID and revision
     195                 :            :  *  @hw: pointer to the HW structure
     196                 :            :  *
     197                 :            :  *  Reads the PHY registers and stores the PHY ID and possibly the PHY
     198                 :            :  *  revision in the hardware structure.
     199                 :            :  **/
     200                 :          0 : s32 igc_get_phy_id(struct igc_hw *hw)
     201                 :            : {
     202                 :            :         struct igc_phy_info *phy = &hw->phy;
     203                 :            :         s32 ret_val = IGC_SUCCESS;
     204                 :            :         u16 phy_id;
     205                 :            :         u16 retry_count = 0;
     206                 :            : 
     207                 :          0 :         DEBUGFUNC("igc_get_phy_id");
     208                 :            : 
     209         [ #  # ]:          0 :         if (!phy->ops.read_reg)
     210                 :            :                 return IGC_SUCCESS;
     211                 :            : 
     212         [ #  # ]:          0 :         while (retry_count < 2) {
     213                 :          0 :                 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
     214         [ #  # ]:          0 :                 if (ret_val)
     215                 :          0 :                         return ret_val;
     216                 :            : 
     217                 :          0 :                 phy->id = (u32)(phy_id << 16);
     218                 :          0 :                 usec_delay(20);
     219                 :          0 :                 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
     220         [ #  # ]:          0 :                 if (ret_val)
     221                 :          0 :                         return ret_val;
     222                 :            : 
     223                 :          0 :                 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
     224                 :          0 :                 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
     225                 :            : 
     226         [ #  # ]:          0 :                 if (phy->id != 0 && phy->id != PHY_REVISION_MASK)
     227                 :            :                         return IGC_SUCCESS;
     228                 :            : 
     229                 :          0 :                 retry_count++;
     230                 :            :         }
     231                 :            : 
     232                 :            :         return IGC_SUCCESS;
     233                 :            : }
     234                 :            : 
     235                 :            : /**
     236                 :            :  *  igc_phy_reset_dsp_generic - Reset PHY DSP
     237                 :            :  *  @hw: pointer to the HW structure
     238                 :            :  *
     239                 :            :  *  Reset the digital signal processor.
     240                 :            :  **/
     241                 :          0 : s32 igc_phy_reset_dsp_generic(struct igc_hw *hw)
     242                 :            : {
     243                 :            :         s32 ret_val;
     244                 :            : 
     245                 :          0 :         DEBUGFUNC("igc_phy_reset_dsp_generic");
     246                 :            : 
     247         [ #  # ]:          0 :         if (!hw->phy.ops.write_reg)
     248                 :            :                 return IGC_SUCCESS;
     249                 :            : 
     250                 :          0 :         ret_val = hw->phy.ops.write_reg(hw, M88IGC_PHY_GEN_CONTROL, 0xC1);
     251         [ #  # ]:          0 :         if (ret_val)
     252                 :            :                 return ret_val;
     253                 :            : 
     254                 :          0 :         return hw->phy.ops.write_reg(hw, M88IGC_PHY_GEN_CONTROL, 0);
     255                 :            : }
     256                 :            : 
     257                 :            : /**
     258                 :            :  *  igc_read_phy_reg_mdic - Read MDI control register
     259                 :            :  *  @hw: pointer to the HW structure
     260                 :            :  *  @offset: register offset to be read
     261                 :            :  *  @data: pointer to the read data
     262                 :            :  *
     263                 :            :  *  Reads the MDI control register in the PHY at offset and stores the
     264                 :            :  *  information read to data.
     265                 :            :  **/
     266                 :          0 : s32 igc_read_phy_reg_mdic(struct igc_hw *hw, u32 offset, u16 *data)
     267                 :            : {
     268                 :            :         struct igc_phy_info *phy = &hw->phy;
     269                 :            :         u32 i, mdic = 0;
     270                 :            : 
     271                 :          0 :         DEBUGFUNC("igc_read_phy_reg_mdic");
     272                 :            : 
     273         [ #  # ]:          0 :         if (offset > MAX_PHY_REG_ADDRESS) {
     274                 :          0 :                 DEBUGOUT1("PHY Address %d is out of range\n", offset);
     275                 :          0 :                 return -IGC_ERR_PARAM;
     276                 :            :         }
     277                 :            : 
     278                 :            :         /* Set up Op-code, Phy Address, and register offset in the MDI
     279                 :            :          * Control register.  The MAC will take care of interfacing with the
     280                 :            :          * PHY to retrieve the desired data.
     281                 :            :          */
     282                 :          0 :         mdic = ((offset << IGC_MDIC_REG_SHIFT) |
     283                 :          0 :                 (phy->addr << IGC_MDIC_PHY_SHIFT) |
     284                 :            :                 (IGC_MDIC_OP_READ));
     285                 :            : 
     286                 :          0 :         IGC_WRITE_REG(hw, IGC_MDIC, mdic);
     287                 :            : 
     288                 :            :         /* Poll the ready bit to see if the MDI read completed
     289                 :            :          * Increasing the time out as testing showed failures with
     290                 :            :          * the lower time out
     291                 :            :          */
     292         [ #  # ]:          0 :         for (i = 0; i < (IGC_GEN_POLL_TIMEOUT * 3); i++) {
     293                 :          0 :                 usec_delay_irq(50);
     294                 :          0 :                 mdic = IGC_READ_REG(hw, IGC_MDIC);
     295         [ #  # ]:          0 :                 if (mdic & IGC_MDIC_READY)
     296                 :            :                         break;
     297                 :            :         }
     298         [ #  # ]:          0 :         if (!(mdic & IGC_MDIC_READY)) {
     299                 :          0 :                 DEBUGOUT("MDI Read did not complete\n");
     300                 :          0 :                 return -IGC_ERR_PHY;
     301                 :            :         }
     302         [ #  # ]:          0 :         if (mdic & IGC_MDIC_ERROR) {
     303                 :          0 :                 DEBUGOUT("MDI Error\n");
     304                 :          0 :                 return -IGC_ERR_PHY;
     305                 :            :         }
     306         [ #  # ]:          0 :         if (((mdic & IGC_MDIC_REG_MASK) >> IGC_MDIC_REG_SHIFT) != offset) {
     307                 :          0 :                 DEBUGOUT2("MDI Read offset error - requested %d, returned %d\n",
     308                 :            :                           offset,
     309                 :            :                           (mdic & IGC_MDIC_REG_MASK) >> IGC_MDIC_REG_SHIFT);
     310                 :          0 :                 return -IGC_ERR_PHY;
     311                 :            :         }
     312                 :          0 :         *data = (u16)mdic;
     313                 :            : 
     314                 :            :         /* Allow some time after each MDIC transaction to avoid
     315                 :            :          * reading duplicate data in the next MDIC transaction.
     316                 :            :          */
     317         [ #  # ]:          0 :         if (hw->mac.type == igc_pch2lan)
     318                 :          0 :                 usec_delay_irq(100);
     319                 :            : 
     320                 :            :         return IGC_SUCCESS;
     321                 :            : }
     322                 :            : 
     323                 :            : /**
     324                 :            :  *  igc_write_phy_reg_mdic - Write MDI control register
     325                 :            :  *  @hw: pointer to the HW structure
     326                 :            :  *  @offset: register offset to write to
     327                 :            :  *  @data: data to write to register at offset
     328                 :            :  *
     329                 :            :  *  Writes data to MDI control register in the PHY at offset.
     330                 :            :  **/
     331                 :          0 : s32 igc_write_phy_reg_mdic(struct igc_hw *hw, u32 offset, u16 data)
     332                 :            : {
     333                 :            :         struct igc_phy_info *phy = &hw->phy;
     334                 :            :         u32 i, mdic = 0;
     335                 :            : 
     336                 :          0 :         DEBUGFUNC("igc_write_phy_reg_mdic");
     337                 :            : 
     338         [ #  # ]:          0 :         if (offset > MAX_PHY_REG_ADDRESS) {
     339                 :          0 :                 DEBUGOUT1("PHY Address %d is out of range\n", offset);
     340                 :          0 :                 return -IGC_ERR_PARAM;
     341                 :            :         }
     342                 :            : 
     343                 :            :         /* Set up Op-code, Phy Address, and register offset in the MDI
     344                 :            :          * Control register.  The MAC will take care of interfacing with the
     345                 :            :          * PHY to retrieve the desired data.
     346                 :            :          */
     347                 :          0 :         mdic = (((u32)data) |
     348                 :          0 :                 (offset << IGC_MDIC_REG_SHIFT) |
     349                 :          0 :                 (phy->addr << IGC_MDIC_PHY_SHIFT) |
     350                 :            :                 (IGC_MDIC_OP_WRITE));
     351                 :            : 
     352                 :          0 :         IGC_WRITE_REG(hw, IGC_MDIC, mdic);
     353                 :            : 
     354                 :            :         /* Poll the ready bit to see if the MDI read completed
     355                 :            :          * Increasing the time out as testing showed failures with
     356                 :            :          * the lower time out
     357                 :            :          */
     358         [ #  # ]:          0 :         for (i = 0; i < (IGC_GEN_POLL_TIMEOUT * 3); i++) {
     359                 :          0 :                 usec_delay_irq(50);
     360                 :          0 :                 mdic = IGC_READ_REG(hw, IGC_MDIC);
     361         [ #  # ]:          0 :                 if (mdic & IGC_MDIC_READY)
     362                 :            :                         break;
     363                 :            :         }
     364         [ #  # ]:          0 :         if (!(mdic & IGC_MDIC_READY)) {
     365                 :          0 :                 DEBUGOUT("MDI Write did not complete\n");
     366                 :          0 :                 return -IGC_ERR_PHY;
     367                 :            :         }
     368         [ #  # ]:          0 :         if (mdic & IGC_MDIC_ERROR) {
     369                 :          0 :                 DEBUGOUT("MDI Error\n");
     370                 :          0 :                 return -IGC_ERR_PHY;
     371                 :            :         }
     372         [ #  # ]:          0 :         if (((mdic & IGC_MDIC_REG_MASK) >> IGC_MDIC_REG_SHIFT) != offset) {
     373                 :          0 :                 DEBUGOUT2("MDI Write offset error - requested %d, returned %d\n",
     374                 :            :                           offset,
     375                 :            :                           (mdic & IGC_MDIC_REG_MASK) >> IGC_MDIC_REG_SHIFT);
     376                 :          0 :                 return -IGC_ERR_PHY;
     377                 :            :         }
     378                 :            : 
     379                 :            :         /* Allow some time after each MDIC transaction to avoid
     380                 :            :          * reading duplicate data in the next MDIC transaction.
     381                 :            :          */
     382         [ #  # ]:          0 :         if (hw->mac.type == igc_pch2lan)
     383                 :          0 :                 usec_delay_irq(100);
     384                 :            : 
     385                 :            :         return IGC_SUCCESS;
     386                 :            : }
     387                 :            : 
     388                 :            : /**
     389                 :            :  *  igc_read_phy_reg_i2c - Read PHY register using i2c
     390                 :            :  *  @hw: pointer to the HW structure
     391                 :            :  *  @offset: register offset to be read
     392                 :            :  *  @data: pointer to the read data
     393                 :            :  *
     394                 :            :  *  Reads the PHY register at offset using the i2c interface and stores the
     395                 :            :  *  retrieved information in data.
     396                 :            :  **/
     397                 :          0 : s32 igc_read_phy_reg_i2c(struct igc_hw *hw, u32 offset, u16 *data)
     398                 :            : {
     399                 :            :         struct igc_phy_info *phy = &hw->phy;
     400                 :            :         u32 i, i2ccmd = 0;
     401                 :            : 
     402                 :          0 :         DEBUGFUNC("igc_read_phy_reg_i2c");
     403                 :            : 
     404                 :            :         /* Set up Op-code, Phy Address, and register address in the I2CCMD
     405                 :            :          * register.  The MAC will take care of interfacing with the
     406                 :            :          * PHY to retrieve the desired data.
     407                 :            :          */
     408                 :          0 :         i2ccmd = ((offset << IGC_I2CCMD_REG_ADDR_SHIFT) |
     409                 :          0 :                   (phy->addr << IGC_I2CCMD_PHY_ADDR_SHIFT) |
     410                 :            :                   (IGC_I2CCMD_OPCODE_READ));
     411                 :            : 
     412                 :          0 :         IGC_WRITE_REG(hw, IGC_I2CCMD, i2ccmd);
     413                 :            : 
     414                 :            :         /* Poll the ready bit to see if the I2C read completed */
     415         [ #  # ]:          0 :         for (i = 0; i < IGC_I2CCMD_PHY_TIMEOUT; i++) {
     416                 :          0 :                 usec_delay(50);
     417                 :          0 :                 i2ccmd = IGC_READ_REG(hw, IGC_I2CCMD);
     418         [ #  # ]:          0 :                 if (i2ccmd & IGC_I2CCMD_READY)
     419                 :            :                         break;
     420                 :            :         }
     421         [ #  # ]:          0 :         if (!(i2ccmd & IGC_I2CCMD_READY)) {
     422                 :          0 :                 DEBUGOUT("I2CCMD Read did not complete\n");
     423                 :          0 :                 return -IGC_ERR_PHY;
     424                 :            :         }
     425         [ #  # ]:          0 :         if (i2ccmd & IGC_I2CCMD_ERROR) {
     426                 :          0 :                 DEBUGOUT("I2CCMD Error bit set\n");
     427                 :          0 :                 return -IGC_ERR_PHY;
     428                 :            :         }
     429                 :            : 
     430                 :            :         /* Need to byte-swap the 16-bit value. */
     431                 :          0 :         *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
     432                 :            : 
     433                 :          0 :         return IGC_SUCCESS;
     434                 :            : }
     435                 :            : 
     436                 :            : /**
     437                 :            :  *  igc_write_phy_reg_i2c - Write PHY register using i2c
     438                 :            :  *  @hw: pointer to the HW structure
     439                 :            :  *  @offset: register offset to write to
     440                 :            :  *  @data: data to write at register offset
     441                 :            :  *
     442                 :            :  *  Writes the data to PHY register at the offset using the i2c interface.
     443                 :            :  **/
     444                 :          0 : s32 igc_write_phy_reg_i2c(struct igc_hw *hw, u32 offset, u16 data)
     445                 :            : {
     446                 :            :         struct igc_phy_info *phy = &hw->phy;
     447                 :            :         u32 i, i2ccmd = 0;
     448                 :            :         u16 phy_data_swapped;
     449                 :            : 
     450                 :          0 :         DEBUGFUNC("igc_write_phy_reg_i2c");
     451                 :            : 
     452                 :            :         /* Prevent overwriting SFP I2C EEPROM which is at A0 address. */
     453         [ #  # ]:          0 :         if (hw->phy.addr == 0 || hw->phy.addr > 7) {
     454                 :          0 :                 DEBUGOUT1("PHY I2C Address %d is out of range.\n",
     455                 :            :                         hw->phy.addr);
     456                 :          0 :                 return -IGC_ERR_CONFIG;
     457                 :            :         }
     458                 :            : 
     459                 :            :         /* Swap the data bytes for the I2C interface */
     460                 :          0 :         phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
     461                 :            : 
     462                 :            :         /* Set up Op-code, Phy Address, and register address in the I2CCMD
     463                 :            :          * register.  The MAC will take care of interfacing with the
     464                 :            :          * PHY to retrieve the desired data.
     465                 :            :          */
     466                 :          0 :         i2ccmd = ((offset << IGC_I2CCMD_REG_ADDR_SHIFT) |
     467                 :          0 :                   (phy->addr << IGC_I2CCMD_PHY_ADDR_SHIFT) |
     468                 :          0 :                   IGC_I2CCMD_OPCODE_WRITE |
     469                 :            :                   phy_data_swapped);
     470                 :            : 
     471                 :          0 :         IGC_WRITE_REG(hw, IGC_I2CCMD, i2ccmd);
     472                 :            : 
     473                 :            :         /* Poll the ready bit to see if the I2C read completed */
     474         [ #  # ]:          0 :         for (i = 0; i < IGC_I2CCMD_PHY_TIMEOUT; i++) {
     475                 :          0 :                 usec_delay(50);
     476                 :          0 :                 i2ccmd = IGC_READ_REG(hw, IGC_I2CCMD);
     477         [ #  # ]:          0 :                 if (i2ccmd & IGC_I2CCMD_READY)
     478                 :            :                         break;
     479                 :            :         }
     480         [ #  # ]:          0 :         if (!(i2ccmd & IGC_I2CCMD_READY)) {
     481                 :          0 :                 DEBUGOUT("I2CCMD Write did not complete\n");
     482                 :          0 :                 return -IGC_ERR_PHY;
     483                 :            :         }
     484         [ #  # ]:          0 :         if (i2ccmd & IGC_I2CCMD_ERROR) {
     485                 :          0 :                 DEBUGOUT("I2CCMD Error bit set\n");
     486                 :          0 :                 return -IGC_ERR_PHY;
     487                 :            :         }
     488                 :            : 
     489                 :            :         return IGC_SUCCESS;
     490                 :            : }
     491                 :            : 
     492                 :            : /**
     493                 :            :  *  igc_read_sfp_data_byte - Reads SFP module data.
     494                 :            :  *  @hw: pointer to the HW structure
     495                 :            :  *  @offset: byte location offset to be read
     496                 :            :  *  @data: read data buffer pointer
     497                 :            :  *
     498                 :            :  *  Reads one byte from SFP module data stored
     499                 :            :  *  in SFP resided EEPROM memory or SFP diagnostic area.
     500                 :            :  *  Function should be called with
     501                 :            :  *  IGC_I2CCMD_SFP_DATA_ADDR(<byte offset>) for SFP module database access
     502                 :            :  *  IGC_I2CCMD_SFP_DIAG_ADDR(<byte offset>) for SFP diagnostics parameters
     503                 :            :  *  access
     504                 :            :  **/
     505                 :          0 : s32 igc_read_sfp_data_byte(struct igc_hw *hw, u16 offset, u8 *data)
     506                 :            : {
     507                 :            :         u32 i = 0;
     508                 :            :         u32 i2ccmd = 0;
     509                 :            :         u32 data_local = 0;
     510                 :            : 
     511                 :          0 :         DEBUGFUNC("igc_read_sfp_data_byte");
     512                 :            : 
     513         [ #  # ]:          0 :         if (offset > IGC_I2CCMD_SFP_DIAG_ADDR(255)) {
     514                 :          0 :                 DEBUGOUT("I2CCMD command address exceeds upper limit\n");
     515                 :          0 :                 return -IGC_ERR_PHY;
     516                 :            :         }
     517                 :            : 
     518                 :            :         /* Set up Op-code, EEPROM Address,in the I2CCMD
     519                 :            :          * register. The MAC will take care of interfacing with the
     520                 :            :          * EEPROM to retrieve the desired data.
     521                 :            :          */
     522                 :          0 :         i2ccmd = ((offset << IGC_I2CCMD_REG_ADDR_SHIFT) |
     523                 :            :                   IGC_I2CCMD_OPCODE_READ);
     524                 :            : 
     525                 :          0 :         IGC_WRITE_REG(hw, IGC_I2CCMD, i2ccmd);
     526                 :            : 
     527                 :            :         /* Poll the ready bit to see if the I2C read completed */
     528         [ #  # ]:          0 :         for (i = 0; i < IGC_I2CCMD_PHY_TIMEOUT; i++) {
     529                 :          0 :                 usec_delay(50);
     530                 :          0 :                 data_local = IGC_READ_REG(hw, IGC_I2CCMD);
     531         [ #  # ]:          0 :                 if (data_local & IGC_I2CCMD_READY)
     532                 :            :                         break;
     533                 :            :         }
     534         [ #  # ]:          0 :         if (!(data_local & IGC_I2CCMD_READY)) {
     535                 :          0 :                 DEBUGOUT("I2CCMD Read did not complete\n");
     536                 :          0 :                 return -IGC_ERR_PHY;
     537                 :            :         }
     538         [ #  # ]:          0 :         if (data_local & IGC_I2CCMD_ERROR) {
     539                 :          0 :                 DEBUGOUT("I2CCMD Error bit set\n");
     540                 :          0 :                 return -IGC_ERR_PHY;
     541                 :            :         }
     542                 :          0 :         *data = (u8)data_local & 0xFF;
     543                 :            : 
     544                 :          0 :         return IGC_SUCCESS;
     545                 :            : }
     546                 :            : 
     547                 :            : /**
     548                 :            :  *  igc_write_sfp_data_byte - Writes SFP module data.
     549                 :            :  *  @hw: pointer to the HW structure
     550                 :            :  *  @offset: byte location offset to write to
     551                 :            :  *  @data: data to write
     552                 :            :  *
     553                 :            :  *  Writes one byte to SFP module data stored
     554                 :            :  *  in SFP resided EEPROM memory or SFP diagnostic area.
     555                 :            :  *  Function should be called with
     556                 :            :  *  IGC_I2CCMD_SFP_DATA_ADDR(<byte offset>) for SFP module database access
     557                 :            :  *  IGC_I2CCMD_SFP_DIAG_ADDR(<byte offset>) for SFP diagnostics parameters
     558                 :            :  *  access
     559                 :            :  **/
     560                 :          0 : s32 igc_write_sfp_data_byte(struct igc_hw *hw, u16 offset, u8 data)
     561                 :            : {
     562                 :            :         u32 i = 0;
     563                 :            :         u32 i2ccmd = 0;
     564                 :            :         u32 data_local = 0;
     565                 :            : 
     566                 :          0 :         DEBUGFUNC("igc_write_sfp_data_byte");
     567                 :            : 
     568         [ #  # ]:          0 :         if (offset > IGC_I2CCMD_SFP_DIAG_ADDR(255)) {
     569                 :          0 :                 DEBUGOUT("I2CCMD command address exceeds upper limit\n");
     570                 :          0 :                 return -IGC_ERR_PHY;
     571                 :            :         }
     572                 :            :         /* The programming interface is 16 bits wide
     573                 :            :          * so we need to read the whole word first
     574                 :            :          * then update appropriate byte lane and write
     575                 :            :          * the updated word back.
     576                 :            :          */
     577                 :            :         /* Set up Op-code, EEPROM Address,in the I2CCMD
     578                 :            :          * register. The MAC will take care of interfacing
     579                 :            :          * with an EEPROM to write the data given.
     580                 :            :          */
     581                 :          0 :         i2ccmd = ((offset << IGC_I2CCMD_REG_ADDR_SHIFT) |
     582                 :            :                   IGC_I2CCMD_OPCODE_READ);
     583                 :            :         /* Set a command to read single word */
     584                 :          0 :         IGC_WRITE_REG(hw, IGC_I2CCMD, i2ccmd);
     585         [ #  # ]:          0 :         for (i = 0; i < IGC_I2CCMD_PHY_TIMEOUT; i++) {
     586                 :          0 :                 usec_delay(50);
     587                 :            :                 /* Poll the ready bit to see if lastly
     588                 :            :                  * launched I2C operation completed
     589                 :            :                  */
     590                 :          0 :                 i2ccmd = IGC_READ_REG(hw, IGC_I2CCMD);
     591         [ #  # ]:          0 :                 if (i2ccmd & IGC_I2CCMD_READY) {
     592                 :            :                         /* Check if this is READ or WRITE phase */
     593         [ #  # ]:          0 :                         if ((i2ccmd & IGC_I2CCMD_OPCODE_READ) ==
     594                 :            :                             IGC_I2CCMD_OPCODE_READ) {
     595                 :            :                                 /* Write the selected byte
     596                 :            :                                  * lane and update whole word
     597                 :            :                                  */
     598                 :          0 :                                 data_local = i2ccmd & 0xFF00;
     599                 :          0 :                                 data_local |= (u32)data;
     600                 :          0 :                                 i2ccmd = ((offset <<
     601                 :          0 :                                         IGC_I2CCMD_REG_ADDR_SHIFT) |
     602                 :            :                                         IGC_I2CCMD_OPCODE_WRITE | data_local);
     603                 :          0 :                                 IGC_WRITE_REG(hw, IGC_I2CCMD, i2ccmd);
     604                 :            :                         } else {
     605                 :            :                                 break;
     606                 :            :                         }
     607                 :            :                 }
     608                 :            :         }
     609         [ #  # ]:          0 :         if (!(i2ccmd & IGC_I2CCMD_READY)) {
     610                 :          0 :                 DEBUGOUT("I2CCMD Write did not complete\n");
     611                 :          0 :                 return -IGC_ERR_PHY;
     612                 :            :         }
     613         [ #  # ]:          0 :         if (i2ccmd & IGC_I2CCMD_ERROR) {
     614                 :          0 :                 DEBUGOUT("I2CCMD Error bit set\n");
     615                 :          0 :                 return -IGC_ERR_PHY;
     616                 :            :         }
     617                 :            :         return IGC_SUCCESS;
     618                 :            : }
     619                 :            : 
     620                 :            : /**
     621                 :            :  *  igc_read_phy_reg_m88 - Read m88 PHY register
     622                 :            :  *  @hw: pointer to the HW structure
     623                 :            :  *  @offset: register offset to be read
     624                 :            :  *  @data: pointer to the read data
     625                 :            :  *
     626                 :            :  *  Acquires semaphore, if necessary, then reads the PHY register at offset
     627                 :            :  *  and storing the retrieved information in data.  Release any acquired
     628                 :            :  *  semaphores before exiting.
     629                 :            :  **/
     630                 :          0 : s32 igc_read_phy_reg_m88(struct igc_hw *hw, u32 offset, u16 *data)
     631                 :            : {
     632                 :            :         s32 ret_val;
     633                 :            : 
     634                 :          0 :         DEBUGFUNC("igc_read_phy_reg_m88");
     635                 :            : 
     636         [ #  # ]:          0 :         if (!hw->phy.ops.acquire)
     637                 :            :                 return IGC_SUCCESS;
     638                 :            : 
     639                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
     640         [ #  # ]:          0 :         if (ret_val)
     641                 :            :                 return ret_val;
     642                 :            : 
     643                 :          0 :         ret_val = igc_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
     644                 :            :                                           data);
     645                 :            : 
     646                 :          0 :         hw->phy.ops.release(hw);
     647                 :            : 
     648                 :          0 :         return ret_val;
     649                 :            : }
     650                 :            : 
     651                 :            : /**
     652                 :            :  *  igc_write_phy_reg_m88 - Write m88 PHY register
     653                 :            :  *  @hw: pointer to the HW structure
     654                 :            :  *  @offset: register offset to write to
     655                 :            :  *  @data: data to write at register offset
     656                 :            :  *
     657                 :            :  *  Acquires semaphore, if necessary, then writes the data to PHY register
     658                 :            :  *  at the offset.  Release any acquired semaphores before exiting.
     659                 :            :  **/
     660                 :          0 : s32 igc_write_phy_reg_m88(struct igc_hw *hw, u32 offset, u16 data)
     661                 :            : {
     662                 :            :         s32 ret_val;
     663                 :            : 
     664                 :          0 :         DEBUGFUNC("igc_write_phy_reg_m88");
     665                 :            : 
     666         [ #  # ]:          0 :         if (!hw->phy.ops.acquire)
     667                 :            :                 return IGC_SUCCESS;
     668                 :            : 
     669                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
     670         [ #  # ]:          0 :         if (ret_val)
     671                 :            :                 return ret_val;
     672                 :            : 
     673                 :          0 :         ret_val = igc_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
     674                 :            :                                            data);
     675                 :            : 
     676                 :          0 :         hw->phy.ops.release(hw);
     677                 :            : 
     678                 :          0 :         return ret_val;
     679                 :            : }
     680                 :            : 
     681                 :            : /**
     682                 :            :  *  igc_set_page_igp - Set page as on IGP-like PHY(s)
     683                 :            :  *  @hw: pointer to the HW structure
     684                 :            :  *  @page: page to set (shifted left when necessary)
     685                 :            :  *
     686                 :            :  *  Sets PHY page required for PHY register access.  Assumes semaphore is
     687                 :            :  *  already acquired.  Note, this function sets phy.addr to 1 so the caller
     688                 :            :  *  must set it appropriately (if necessary) after this function returns.
     689                 :            :  **/
     690                 :          0 : s32 igc_set_page_igp(struct igc_hw *hw, u16 page)
     691                 :            : {
     692                 :          0 :         DEBUGFUNC("igc_set_page_igp");
     693                 :            : 
     694                 :          0 :         DEBUGOUT1("Setting page 0x%x\n", page);
     695                 :            : 
     696                 :          0 :         hw->phy.addr = 1;
     697                 :            : 
     698                 :          0 :         return igc_write_phy_reg_mdic(hw, IGP01IGC_PHY_PAGE_SELECT, page);
     699                 :            : }
     700                 :            : 
     701                 :            : /**
     702                 :            :  *  __igc_read_phy_reg_igp - Read igp PHY register
     703                 :            :  *  @hw: pointer to the HW structure
     704                 :            :  *  @offset: register offset to be read
     705                 :            :  *  @data: pointer to the read data
     706                 :            :  *  @locked: semaphore has already been acquired or not
     707                 :            :  *
     708                 :            :  *  Acquires semaphore, if necessary, then reads the PHY register at offset
     709                 :            :  *  and stores the retrieved information in data.  Release any acquired
     710                 :            :  *  semaphores before exiting.
     711                 :            :  **/
     712                 :          0 : static s32 __igc_read_phy_reg_igp(struct igc_hw *hw, u32 offset, u16 *data,
     713                 :            :                                     bool locked)
     714                 :            : {
     715                 :            :         s32 ret_val = IGC_SUCCESS;
     716                 :            : 
     717                 :          0 :         DEBUGFUNC("__igc_read_phy_reg_igp");
     718                 :            : 
     719         [ #  # ]:          0 :         if (!locked) {
     720         [ #  # ]:          0 :                 if (!hw->phy.ops.acquire)
     721                 :            :                         return IGC_SUCCESS;
     722                 :            : 
     723                 :          0 :                 ret_val = hw->phy.ops.acquire(hw);
     724         [ #  # ]:          0 :                 if (ret_val)
     725                 :            :                         return ret_val;
     726                 :            :         }
     727                 :            : 
     728         [ #  # ]:          0 :         if (offset > MAX_PHY_MULTI_PAGE_REG)
     729                 :          0 :                 ret_val = igc_write_phy_reg_mdic(hw,
     730                 :            :                                                    IGP01IGC_PHY_PAGE_SELECT,
     731                 :            :                                                    (u16)offset);
     732         [ #  # ]:          0 :         if (!ret_val)
     733                 :          0 :                 ret_val = igc_read_phy_reg_mdic(hw,
     734                 :            :                                                   MAX_PHY_REG_ADDRESS & offset,
     735                 :            :                                                   data);
     736         [ #  # ]:          0 :         if (!locked)
     737                 :          0 :                 hw->phy.ops.release(hw);
     738                 :            : 
     739                 :            :         return ret_val;
     740                 :            : }
     741                 :            : 
     742                 :            : /**
     743                 :            :  *  igc_read_phy_reg_igp - Read igp PHY register
     744                 :            :  *  @hw: pointer to the HW structure
     745                 :            :  *  @offset: register offset to be read
     746                 :            :  *  @data: pointer to the read data
     747                 :            :  *
     748                 :            :  *  Acquires semaphore then reads the PHY register at offset and stores the
     749                 :            :  *  retrieved information in data.
     750                 :            :  *  Release the acquired semaphore before exiting.
     751                 :            :  **/
     752                 :          0 : s32 igc_read_phy_reg_igp(struct igc_hw *hw, u32 offset, u16 *data)
     753                 :            : {
     754                 :          0 :         return __igc_read_phy_reg_igp(hw, offset, data, false);
     755                 :            : }
     756                 :            : 
     757                 :            : /**
     758                 :            :  *  igc_read_phy_reg_igp_locked - Read igp PHY register
     759                 :            :  *  @hw: pointer to the HW structure
     760                 :            :  *  @offset: register offset to be read
     761                 :            :  *  @data: pointer to the read data
     762                 :            :  *
     763                 :            :  *  Reads the PHY register at offset and stores the retrieved information
     764                 :            :  *  in data.  Assumes semaphore already acquired.
     765                 :            :  **/
     766                 :          0 : s32 igc_read_phy_reg_igp_locked(struct igc_hw *hw, u32 offset, u16 *data)
     767                 :            : {
     768                 :          0 :         return __igc_read_phy_reg_igp(hw, offset, data, true);
     769                 :            : }
     770                 :            : 
     771                 :            : /**
     772                 :            :  *  igc_write_phy_reg_igp - Write igp PHY register
     773                 :            :  *  @hw: pointer to the HW structure
     774                 :            :  *  @offset: register offset to write to
     775                 :            :  *  @data: data to write at register offset
     776                 :            :  *  @locked: semaphore has already been acquired or not
     777                 :            :  *
     778                 :            :  *  Acquires semaphore, if necessary, then writes the data to PHY register
     779                 :            :  *  at the offset.  Release any acquired semaphores before exiting.
     780                 :            :  **/
     781                 :          0 : static s32 __igc_write_phy_reg_igp(struct igc_hw *hw, u32 offset, u16 data,
     782                 :            :                                      bool locked)
     783                 :            : {
     784                 :            :         s32 ret_val = IGC_SUCCESS;
     785                 :            : 
     786                 :          0 :         DEBUGFUNC("igc_write_phy_reg_igp");
     787                 :            : 
     788         [ #  # ]:          0 :         if (!locked) {
     789         [ #  # ]:          0 :                 if (!hw->phy.ops.acquire)
     790                 :            :                         return IGC_SUCCESS;
     791                 :            : 
     792                 :          0 :                 ret_val = hw->phy.ops.acquire(hw);
     793         [ #  # ]:          0 :                 if (ret_val)
     794                 :            :                         return ret_val;
     795                 :            :         }
     796                 :            : 
     797         [ #  # ]:          0 :         if (offset > MAX_PHY_MULTI_PAGE_REG)
     798                 :          0 :                 ret_val = igc_write_phy_reg_mdic(hw,
     799                 :            :                                                    IGP01IGC_PHY_PAGE_SELECT,
     800                 :            :                                                    (u16)offset);
     801         [ #  # ]:          0 :         if (!ret_val)
     802                 :          0 :                 ret_val = igc_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS &
     803                 :            :                                                        offset,
     804                 :            :                                                    data);
     805         [ #  # ]:          0 :         if (!locked)
     806                 :          0 :                 hw->phy.ops.release(hw);
     807                 :            : 
     808                 :            :         return ret_val;
     809                 :            : }
     810                 :            : 
     811                 :            : /**
     812                 :            :  *  igc_write_phy_reg_igp - Write igp PHY register
     813                 :            :  *  @hw: pointer to the HW structure
     814                 :            :  *  @offset: register offset to write to
     815                 :            :  *  @data: data to write at register offset
     816                 :            :  *
     817                 :            :  *  Acquires semaphore then writes the data to PHY register
     818                 :            :  *  at the offset.  Release any acquired semaphores before exiting.
     819                 :            :  **/
     820                 :          0 : s32 igc_write_phy_reg_igp(struct igc_hw *hw, u32 offset, u16 data)
     821                 :            : {
     822                 :          0 :         return __igc_write_phy_reg_igp(hw, offset, data, false);
     823                 :            : }
     824                 :            : 
     825                 :            : /**
     826                 :            :  *  igc_write_phy_reg_igp_locked - Write igp PHY register
     827                 :            :  *  @hw: pointer to the HW structure
     828                 :            :  *  @offset: register offset to write to
     829                 :            :  *  @data: data to write at register offset
     830                 :            :  *
     831                 :            :  *  Writes the data to PHY register at the offset.
     832                 :            :  *  Assumes semaphore already acquired.
     833                 :            :  **/
     834                 :          0 : s32 igc_write_phy_reg_igp_locked(struct igc_hw *hw, u32 offset, u16 data)
     835                 :            : {
     836                 :          0 :         return __igc_write_phy_reg_igp(hw, offset, data, true);
     837                 :            : }
     838                 :            : 
     839                 :            : /**
     840                 :            :  *  __igc_read_kmrn_reg - Read kumeran register
     841                 :            :  *  @hw: pointer to the HW structure
     842                 :            :  *  @offset: register offset to be read
     843                 :            :  *  @data: pointer to the read data
     844                 :            :  *  @locked: semaphore has already been acquired or not
     845                 :            :  *
     846                 :            :  *  Acquires semaphore, if necessary.  Then reads the PHY register at offset
     847                 :            :  *  using the kumeran interface.  The information retrieved is stored in data.
     848                 :            :  *  Release any acquired semaphores before exiting.
     849                 :            :  **/
     850                 :          0 : static s32 __igc_read_kmrn_reg(struct igc_hw *hw, u32 offset, u16 *data,
     851                 :            :                                  bool locked)
     852                 :            : {
     853                 :            :         u32 kmrnctrlsta;
     854                 :            : 
     855                 :          0 :         DEBUGFUNC("__igc_read_kmrn_reg");
     856                 :            : 
     857         [ #  # ]:          0 :         if (!locked) {
     858                 :            :                 s32 ret_val = IGC_SUCCESS;
     859                 :            : 
     860         [ #  # ]:          0 :                 if (!hw->phy.ops.acquire)
     861                 :            :                         return IGC_SUCCESS;
     862                 :            : 
     863                 :          0 :                 ret_val = hw->phy.ops.acquire(hw);
     864         [ #  # ]:          0 :                 if (ret_val)
     865                 :            :                         return ret_val;
     866                 :            :         }
     867                 :            : 
     868                 :          0 :         kmrnctrlsta = ((offset << IGC_KMRNCTRLSTA_OFFSET_SHIFT) &
     869                 :            :                        IGC_KMRNCTRLSTA_OFFSET) | IGC_KMRNCTRLSTA_REN;
     870                 :          0 :         IGC_WRITE_REG(hw, IGC_KMRNCTRLSTA, kmrnctrlsta);
     871                 :          0 :         IGC_WRITE_FLUSH(hw);
     872                 :            : 
     873                 :          0 :         usec_delay(2);
     874                 :            : 
     875                 :          0 :         kmrnctrlsta = IGC_READ_REG(hw, IGC_KMRNCTRLSTA);
     876                 :          0 :         *data = (u16)kmrnctrlsta;
     877                 :            : 
     878         [ #  # ]:          0 :         if (!locked)
     879                 :          0 :                 hw->phy.ops.release(hw);
     880                 :            : 
     881                 :            :         return IGC_SUCCESS;
     882                 :            : }
     883                 :            : 
     884                 :            : /**
     885                 :            :  *  igc_read_kmrn_reg_generic -  Read kumeran register
     886                 :            :  *  @hw: pointer to the HW structure
     887                 :            :  *  @offset: register offset to be read
     888                 :            :  *  @data: pointer to the read data
     889                 :            :  *
     890                 :            :  *  Acquires semaphore then reads the PHY register at offset using the
     891                 :            :  *  kumeran interface.  The information retrieved is stored in data.
     892                 :            :  *  Release the acquired semaphore before exiting.
     893                 :            :  **/
     894                 :          0 : s32 igc_read_kmrn_reg_generic(struct igc_hw *hw, u32 offset, u16 *data)
     895                 :            : {
     896                 :          0 :         return __igc_read_kmrn_reg(hw, offset, data, false);
     897                 :            : }
     898                 :            : 
     899                 :            : /**
     900                 :            :  *  igc_read_kmrn_reg_locked -  Read kumeran register
     901                 :            :  *  @hw: pointer to the HW structure
     902                 :            :  *  @offset: register offset to be read
     903                 :            :  *  @data: pointer to the read data
     904                 :            :  *
     905                 :            :  *  Reads the PHY register at offset using the kumeran interface.  The
     906                 :            :  *  information retrieved is stored in data.
     907                 :            :  *  Assumes semaphore already acquired.
     908                 :            :  **/
     909                 :          0 : s32 igc_read_kmrn_reg_locked(struct igc_hw *hw, u32 offset, u16 *data)
     910                 :            : {
     911                 :          0 :         return __igc_read_kmrn_reg(hw, offset, data, true);
     912                 :            : }
     913                 :            : 
     914                 :            : /**
     915                 :            :  *  __igc_write_kmrn_reg - Write kumeran register
     916                 :            :  *  @hw: pointer to the HW structure
     917                 :            :  *  @offset: register offset to write to
     918                 :            :  *  @data: data to write at register offset
     919                 :            :  *  @locked: semaphore has already been acquired or not
     920                 :            :  *
     921                 :            :  *  Acquires semaphore, if necessary.  Then write the data to PHY register
     922                 :            :  *  at the offset using the kumeran interface.  Release any acquired semaphores
     923                 :            :  *  before exiting.
     924                 :            :  **/
     925                 :          0 : static s32 __igc_write_kmrn_reg(struct igc_hw *hw, u32 offset, u16 data,
     926                 :            :                                   bool locked)
     927                 :            : {
     928                 :            :         u32 kmrnctrlsta;
     929                 :            : 
     930                 :          0 :         DEBUGFUNC("igc_write_kmrn_reg_generic");
     931                 :            : 
     932         [ #  # ]:          0 :         if (!locked) {
     933                 :            :                 s32 ret_val = IGC_SUCCESS;
     934                 :            : 
     935         [ #  # ]:          0 :                 if (!hw->phy.ops.acquire)
     936                 :            :                         return IGC_SUCCESS;
     937                 :            : 
     938                 :          0 :                 ret_val = hw->phy.ops.acquire(hw);
     939         [ #  # ]:          0 :                 if (ret_val)
     940                 :            :                         return ret_val;
     941                 :            :         }
     942                 :            : 
     943                 :          0 :         kmrnctrlsta = ((offset << IGC_KMRNCTRLSTA_OFFSET_SHIFT) &
     944                 :          0 :                        IGC_KMRNCTRLSTA_OFFSET) | data;
     945                 :          0 :         IGC_WRITE_REG(hw, IGC_KMRNCTRLSTA, kmrnctrlsta);
     946                 :          0 :         IGC_WRITE_FLUSH(hw);
     947                 :            : 
     948                 :          0 :         usec_delay(2);
     949                 :            : 
     950         [ #  # ]:          0 :         if (!locked)
     951                 :          0 :                 hw->phy.ops.release(hw);
     952                 :            : 
     953                 :            :         return IGC_SUCCESS;
     954                 :            : }
     955                 :            : 
     956                 :            : /**
     957                 :            :  *  igc_write_kmrn_reg_generic -  Write kumeran register
     958                 :            :  *  @hw: pointer to the HW structure
     959                 :            :  *  @offset: register offset to write to
     960                 :            :  *  @data: data to write at register offset
     961                 :            :  *
     962                 :            :  *  Acquires semaphore then writes the data to the PHY register at the offset
     963                 :            :  *  using the kumeran interface.  Release the acquired semaphore before exiting.
     964                 :            :  **/
     965                 :          0 : s32 igc_write_kmrn_reg_generic(struct igc_hw *hw, u32 offset, u16 data)
     966                 :            : {
     967                 :          0 :         return __igc_write_kmrn_reg(hw, offset, data, false);
     968                 :            : }
     969                 :            : 
     970                 :            : /**
     971                 :            :  *  igc_write_kmrn_reg_locked -  Write kumeran register
     972                 :            :  *  @hw: pointer to the HW structure
     973                 :            :  *  @offset: register offset to write to
     974                 :            :  *  @data: data to write at register offset
     975                 :            :  *
     976                 :            :  *  Write the data to PHY register at the offset using the kumeran interface.
     977                 :            :  *  Assumes semaphore already acquired.
     978                 :            :  **/
     979                 :          0 : s32 igc_write_kmrn_reg_locked(struct igc_hw *hw, u32 offset, u16 data)
     980                 :            : {
     981                 :          0 :         return __igc_write_kmrn_reg(hw, offset, data, true);
     982                 :            : }
     983                 :            : 
     984                 :            : /**
     985                 :            :  *  igc_set_master_slave_mode - Setup PHY for Master/slave mode
     986                 :            :  *  @hw: pointer to the HW structure
     987                 :            :  *
     988                 :            :  *  Sets up Master/slave mode
     989                 :            :  **/
     990                 :          0 : static s32 igc_set_master_slave_mode(struct igc_hw *hw)
     991                 :            : {
     992                 :            :         s32 ret_val;
     993                 :            :         u16 phy_data;
     994                 :            : 
     995                 :            :         /* Resolve Master/Slave mode */
     996                 :          0 :         ret_val = hw->phy.ops.read_reg(hw, PHY_1000T_CTRL, &phy_data);
     997         [ #  # ]:          0 :         if (ret_val)
     998                 :            :                 return ret_val;
     999                 :            : 
    1000                 :            :         /* load defaults for future use */
    1001                 :          0 :         hw->phy.original_ms_type = (phy_data & CR_1000T_MS_ENABLE) ?
    1002                 :            :                                    ((phy_data & CR_1000T_MS_VALUE) ?
    1003                 :            :                                     igc_ms_force_master :
    1004   [ #  #  #  # ]:          0 :                                     igc_ms_force_slave) : igc_ms_auto;
    1005                 :            : 
    1006   [ #  #  #  # ]:          0 :         switch (hw->phy.ms_type) {
    1007                 :          0 :         case igc_ms_force_master:
    1008                 :          0 :                 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
    1009                 :          0 :                 break;
    1010                 :          0 :         case igc_ms_force_slave:
    1011                 :          0 :                 phy_data |= CR_1000T_MS_ENABLE;
    1012                 :          0 :                 phy_data &= ~(CR_1000T_MS_VALUE);
    1013                 :          0 :                 break;
    1014                 :          0 :         case igc_ms_auto:
    1015                 :          0 :                 phy_data &= ~CR_1000T_MS_ENABLE;
    1016                 :            :                 /* fall-through */
    1017                 :            :         default:
    1018                 :            :                 break;
    1019                 :            :         }
    1020                 :            : 
    1021                 :          0 :         return hw->phy.ops.write_reg(hw, PHY_1000T_CTRL, phy_data);
    1022                 :            : }
    1023                 :            : 
    1024                 :            : /**
    1025                 :            :  *  igc_copper_link_setup_82577 - Setup 82577 PHY for copper link
    1026                 :            :  *  @hw: pointer to the HW structure
    1027                 :            :  *
    1028                 :            :  *  Sets up Carrier-sense on Transmit and downshift values.
    1029                 :            :  **/
    1030                 :          0 : s32 igc_copper_link_setup_82577(struct igc_hw *hw)
    1031                 :            : {
    1032                 :            :         s32 ret_val;
    1033                 :            :         u16 phy_data;
    1034                 :            : 
    1035                 :          0 :         DEBUGFUNC("igc_copper_link_setup_82577");
    1036                 :            : 
    1037         [ #  # ]:          0 :         if (hw->phy.type == igc_phy_82580) {
    1038                 :          0 :                 ret_val = hw->phy.ops.reset(hw);
    1039         [ #  # ]:          0 :                 if (ret_val) {
    1040                 :          0 :                         DEBUGOUT("Error resetting the PHY.\n");
    1041                 :          0 :                         return ret_val;
    1042                 :            :                 }
    1043                 :            :         }
    1044                 :            : 
    1045                 :            :         /* Enable CRS on Tx. This must be set for half-duplex operation. */
    1046                 :          0 :         ret_val = hw->phy.ops.read_reg(hw, I82577_CFG_REG, &phy_data);
    1047         [ #  # ]:          0 :         if (ret_val)
    1048                 :            :                 return ret_val;
    1049                 :            : 
    1050                 :          0 :         phy_data |= I82577_CFG_ASSERT_CRS_ON_TX;
    1051                 :            : 
    1052                 :            :         /* Enable downshift */
    1053                 :          0 :         phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
    1054                 :            : 
    1055                 :          0 :         ret_val = hw->phy.ops.write_reg(hw, I82577_CFG_REG, phy_data);
    1056         [ #  # ]:          0 :         if (ret_val)
    1057                 :            :                 return ret_val;
    1058                 :            : 
    1059                 :            :         /* Set MDI/MDIX mode */
    1060                 :          0 :         ret_val = hw->phy.ops.read_reg(hw, I82577_PHY_CTRL_2, &phy_data);
    1061         [ #  # ]:          0 :         if (ret_val)
    1062                 :            :                 return ret_val;
    1063                 :          0 :         phy_data &= ~I82577_PHY_CTRL2_MDIX_CFG_MASK;
    1064                 :            :         /* Options:
    1065                 :            :          *   0 - Auto (default)
    1066                 :            :          *   1 - MDI mode
    1067                 :            :          *   2 - MDI-X mode
    1068                 :            :          */
    1069      [ #  #  # ]:          0 :         switch (hw->phy.mdix) {
    1070                 :            :         case 1:
    1071                 :            :                 break;
    1072                 :          0 :         case 2:
    1073                 :          0 :                 phy_data |= I82577_PHY_CTRL2_MANUAL_MDIX;
    1074                 :          0 :                 break;
    1075                 :          0 :         case 0:
    1076                 :            :         default:
    1077                 :          0 :                 phy_data |= I82577_PHY_CTRL2_AUTO_MDI_MDIX;
    1078                 :          0 :                 break;
    1079                 :            :         }
    1080                 :          0 :         ret_val = hw->phy.ops.write_reg(hw, I82577_PHY_CTRL_2, phy_data);
    1081         [ #  # ]:          0 :         if (ret_val)
    1082                 :            :                 return ret_val;
    1083                 :            : 
    1084                 :          0 :         return igc_set_master_slave_mode(hw);
    1085                 :            : }
    1086                 :            : 
    1087                 :            : /**
    1088                 :            :  *  igc_copper_link_setup_m88 - Setup m88 PHY's for copper link
    1089                 :            :  *  @hw: pointer to the HW structure
    1090                 :            :  *
    1091                 :            :  *  Sets up MDI/MDI-X and polarity for m88 PHY's.  If necessary, transmit clock
    1092                 :            :  *  and downshift values are set also.
    1093                 :            :  **/
    1094                 :          0 : s32 igc_copper_link_setup_m88(struct igc_hw *hw)
    1095                 :            : {
    1096                 :            :         struct igc_phy_info *phy = &hw->phy;
    1097                 :            :         s32 ret_val;
    1098                 :            :         u16 phy_data;
    1099                 :            : 
    1100                 :          0 :         DEBUGFUNC("igc_copper_link_setup_m88");
    1101                 :            : 
    1102                 :            : 
    1103                 :            :         /* Enable CRS on Tx. This must be set for half-duplex operation. */
    1104                 :          0 :         ret_val = phy->ops.read_reg(hw, M88IGC_PHY_SPEC_CTRL, &phy_data);
    1105         [ #  # ]:          0 :         if (ret_val)
    1106                 :            :                 return ret_val;
    1107                 :            : 
    1108                 :            :         /* For BM PHY this bit is downshift enable */
    1109         [ #  # ]:          0 :         if (phy->type != igc_phy_bm)
    1110                 :          0 :                 phy_data |= M88IGC_PSCR_ASSERT_CRS_ON_TX;
    1111                 :            : 
    1112                 :            :         /* Options:
    1113                 :            :          *   MDI/MDI-X = 0 (default)
    1114                 :            :          *   0 - Auto for all speeds
    1115                 :            :          *   1 - MDI mode
    1116                 :            :          *   2 - MDI-X mode
    1117                 :            :          *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
    1118                 :            :          */
    1119                 :          0 :         phy_data &= ~M88IGC_PSCR_AUTO_X_MODE;
    1120                 :            : 
    1121   [ #  #  #  # ]:          0 :         switch (phy->mdix) {
    1122                 :            :         case 1:
    1123                 :            :                 phy_data |= M88IGC_PSCR_MDI_MANUAL_MODE;
    1124                 :            :                 break;
    1125                 :          0 :         case 2:
    1126                 :          0 :                 phy_data |= M88IGC_PSCR_MDIX_MANUAL_MODE;
    1127                 :          0 :                 break;
    1128                 :          0 :         case 3:
    1129                 :          0 :                 phy_data |= M88IGC_PSCR_AUTO_X_1000T;
    1130                 :          0 :                 break;
    1131                 :          0 :         case 0:
    1132                 :            :         default:
    1133                 :          0 :                 phy_data |= M88IGC_PSCR_AUTO_X_MODE;
    1134                 :          0 :                 break;
    1135                 :            :         }
    1136                 :            : 
    1137                 :            :         /* Options:
    1138                 :            :          *   disable_polarity_correction = 0 (default)
    1139                 :            :          *       Automatic Correction for Reversed Cable Polarity
    1140                 :            :          *   0 - Disabled
    1141                 :            :          *   1 - Enabled
    1142                 :            :          */
    1143                 :          0 :         phy_data &= ~M88IGC_PSCR_POLARITY_REVERSAL;
    1144         [ #  # ]:          0 :         if (phy->disable_polarity_correction)
    1145                 :          0 :                 phy_data |= M88IGC_PSCR_POLARITY_REVERSAL;
    1146                 :            : 
    1147                 :            :         /* Enable downshift on BM (disabled by default) */
    1148         [ #  # ]:          0 :         if (phy->type == igc_phy_bm) {
    1149                 :            :                 /* For 82574/82583, first disable then enable downshift */
    1150         [ #  # ]:          0 :                 if (phy->id == BMIGC_E_PHY_ID_R2) {
    1151                 :          0 :                         phy_data &= ~BMIGC_PSCR_ENABLE_DOWNSHIFT;
    1152                 :          0 :                         ret_val = phy->ops.write_reg(hw, M88IGC_PHY_SPEC_CTRL,
    1153                 :            :                                                      phy_data);
    1154         [ #  # ]:          0 :                         if (ret_val)
    1155                 :            :                                 return ret_val;
    1156                 :            :                         /* Commit the changes. */
    1157                 :          0 :                         ret_val = phy->ops.commit(hw);
    1158         [ #  # ]:          0 :                         if (ret_val) {
    1159                 :          0 :                                 DEBUGOUT("Error committing the PHY changes\n");
    1160                 :          0 :                                 return ret_val;
    1161                 :            :                         }
    1162                 :            :                 }
    1163                 :            : 
    1164                 :          0 :                 phy_data |= BMIGC_PSCR_ENABLE_DOWNSHIFT;
    1165                 :            :         }
    1166                 :            : 
    1167                 :          0 :         ret_val = phy->ops.write_reg(hw, M88IGC_PHY_SPEC_CTRL, phy_data);
    1168         [ #  # ]:          0 :         if (ret_val)
    1169                 :            :                 return ret_val;
    1170                 :            : 
    1171   [ #  #  #  # ]:          0 :         if (phy->type == igc_phy_m88 && phy->revision < IGC_REVISION_4 &&
    1172         [ #  # ]:          0 :                         phy->id != BMIGC_E_PHY_ID_R2) {
    1173                 :            :                 /* Force TX_CLK in the Extended PHY Specific Control Register
    1174                 :            :                  * to 25MHz clock.
    1175                 :            :                  */
    1176                 :          0 :                 ret_val = phy->ops.read_reg(hw, M88IGC_EXT_PHY_SPEC_CTRL,
    1177                 :            :                                             &phy_data);
    1178         [ #  # ]:          0 :                 if (ret_val)
    1179                 :            :                         return ret_val;
    1180                 :            : 
    1181                 :          0 :                 phy_data |= M88IGC_EPSCR_TX_CLK_25;
    1182                 :            : 
    1183         [ #  # ]:          0 :                 if (phy->revision == IGC_REVISION_2 &&
    1184         [ #  # ]:          0 :                                 phy->id == M88E1111_I_PHY_ID) {
    1185                 :            :                         /* 82573L PHY - set the downshift counter to 5x. */
    1186                 :          0 :                         phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
    1187                 :          0 :                         phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
    1188                 :            :                 } else {
    1189                 :            :                         /* Configure Master and Slave downshift values */
    1190                 :          0 :                         phy_data &= ~(M88IGC_EPSCR_MASTER_DOWNSHIFT_MASK |
    1191                 :            :                                      M88IGC_EPSCR_SLAVE_DOWNSHIFT_MASK);
    1192                 :          0 :                         phy_data |= (M88IGC_EPSCR_MASTER_DOWNSHIFT_1X |
    1193                 :            :                                      M88IGC_EPSCR_SLAVE_DOWNSHIFT_1X);
    1194                 :            :                 }
    1195                 :          0 :                 ret_val = phy->ops.write_reg(hw, M88IGC_EXT_PHY_SPEC_CTRL,
    1196                 :            :                                              phy_data);
    1197         [ #  # ]:          0 :                 if (ret_val)
    1198                 :            :                         return ret_val;
    1199                 :            :         }
    1200                 :            : 
    1201   [ #  #  #  # ]:          0 :         if (phy->type == igc_phy_bm && phy->id == BMIGC_E_PHY_ID_R2) {
    1202                 :            :                 /* Set PHY page 0, register 29 to 0x0003 */
    1203                 :          0 :                 ret_val = phy->ops.write_reg(hw, 29, 0x0003);
    1204         [ #  # ]:          0 :                 if (ret_val)
    1205                 :            :                         return ret_val;
    1206                 :            : 
    1207                 :            :                 /* Set PHY page 0, register 30 to 0x0000 */
    1208                 :          0 :                 ret_val = phy->ops.write_reg(hw, 30, 0x0000);
    1209         [ #  # ]:          0 :                 if (ret_val)
    1210                 :            :                         return ret_val;
    1211                 :            :         }
    1212                 :            : 
    1213                 :            :         /* Commit the changes. */
    1214                 :          0 :         ret_val = phy->ops.commit(hw);
    1215         [ #  # ]:          0 :         if (ret_val) {
    1216                 :          0 :                 DEBUGOUT("Error committing the PHY changes\n");
    1217                 :          0 :                 return ret_val;
    1218                 :            :         }
    1219                 :            : 
    1220         [ #  # ]:          0 :         if (phy->type == igc_phy_82578) {
    1221                 :          0 :                 ret_val = phy->ops.read_reg(hw, M88IGC_EXT_PHY_SPEC_CTRL,
    1222                 :            :                                             &phy_data);
    1223         [ #  # ]:          0 :                 if (ret_val)
    1224                 :            :                         return ret_val;
    1225                 :            : 
    1226                 :            :                 /* 82578 PHY - set the downshift count to 1x. */
    1227                 :          0 :                 phy_data |= I82578_EPSCR_DOWNSHIFT_ENABLE;
    1228                 :          0 :                 phy_data &= ~I82578_EPSCR_DOWNSHIFT_COUNTER_MASK;
    1229                 :          0 :                 ret_val = phy->ops.write_reg(hw, M88IGC_EXT_PHY_SPEC_CTRL,
    1230                 :            :                                              phy_data);
    1231         [ #  # ]:          0 :                 if (ret_val)
    1232                 :          0 :                         return ret_val;
    1233                 :            :         }
    1234                 :            : 
    1235                 :            :         return IGC_SUCCESS;
    1236                 :            : }
    1237                 :            : 
    1238                 :            : /**
    1239                 :            :  *  igc_copper_link_setup_m88_gen2 - Setup m88 PHY's for copper link
    1240                 :            :  *  @hw: pointer to the HW structure
    1241                 :            :  *
    1242                 :            :  *  Sets up MDI/MDI-X and polarity for i347-AT4, m88e1322 and m88e1112 PHY's.
    1243                 :            :  *  Also enables and sets the downshift parameters.
    1244                 :            :  **/
    1245                 :          0 : s32 igc_copper_link_setup_m88_gen2(struct igc_hw *hw)
    1246                 :            : {
    1247                 :            :         struct igc_phy_info *phy = &hw->phy;
    1248                 :            :         s32 ret_val;
    1249                 :            :         u16 phy_data;
    1250                 :            : 
    1251                 :          0 :         DEBUGFUNC("igc_copper_link_setup_m88_gen2");
    1252                 :            : 
    1253                 :            : 
    1254                 :            :         /* Enable CRS on Tx. This must be set for half-duplex operation. */
    1255                 :          0 :         ret_val = phy->ops.read_reg(hw, M88IGC_PHY_SPEC_CTRL, &phy_data);
    1256         [ #  # ]:          0 :         if (ret_val)
    1257                 :            :                 return ret_val;
    1258                 :            : 
    1259                 :            :         /* Options:
    1260                 :            :          *   MDI/MDI-X = 0 (default)
    1261                 :            :          *   0 - Auto for all speeds
    1262                 :            :          *   1 - MDI mode
    1263                 :            :          *   2 - MDI-X mode
    1264                 :            :          *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
    1265                 :            :          */
    1266                 :          0 :         phy_data &= ~M88IGC_PSCR_AUTO_X_MODE;
    1267                 :            : 
    1268   [ #  #  #  # ]:          0 :         switch (phy->mdix) {
    1269                 :            :         case 1:
    1270                 :            :                 phy_data |= M88IGC_PSCR_MDI_MANUAL_MODE;
    1271                 :            :                 break;
    1272                 :          0 :         case 2:
    1273                 :          0 :                 phy_data |= M88IGC_PSCR_MDIX_MANUAL_MODE;
    1274                 :          0 :                 break;
    1275                 :          0 :         case 3:
    1276                 :            :                 /* M88E1112 does not support this mode) */
    1277         [ #  # ]:          0 :                 if (phy->id != M88E1112_E_PHY_ID) {
    1278                 :          0 :                         phy_data |= M88IGC_PSCR_AUTO_X_1000T;
    1279                 :          0 :                         break;
    1280                 :            :                 }
    1281                 :            :                 /* Fall through */
    1282                 :            :         case 0:
    1283                 :            :         default:
    1284                 :          0 :                 phy_data |= M88IGC_PSCR_AUTO_X_MODE;
    1285                 :          0 :                 break;
    1286                 :            :         }
    1287                 :            : 
    1288                 :            :         /* Options:
    1289                 :            :          *   disable_polarity_correction = 0 (default)
    1290                 :            :          *       Automatic Correction for Reversed Cable Polarity
    1291                 :            :          *   0 - Disabled
    1292                 :            :          *   1 - Enabled
    1293                 :            :          */
    1294                 :          0 :         phy_data &= ~M88IGC_PSCR_POLARITY_REVERSAL;
    1295         [ #  # ]:          0 :         if (phy->disable_polarity_correction)
    1296                 :          0 :                 phy_data |= M88IGC_PSCR_POLARITY_REVERSAL;
    1297                 :            : 
    1298                 :            :         /* Enable downshift and setting it to X6 */
    1299         [ #  # ]:          0 :         if (phy->id == M88E1543_E_PHY_ID) {
    1300                 :          0 :                 phy_data &= ~I347AT4_PSCR_DOWNSHIFT_ENABLE;
    1301                 :            :                 ret_val =
    1302                 :          0 :                     phy->ops.write_reg(hw, M88IGC_PHY_SPEC_CTRL, phy_data);
    1303         [ #  # ]:          0 :                 if (ret_val)
    1304                 :            :                         return ret_val;
    1305                 :            : 
    1306                 :          0 :                 ret_val = phy->ops.commit(hw);
    1307         [ #  # ]:          0 :                 if (ret_val) {
    1308                 :          0 :                         DEBUGOUT("Error committing the PHY changes\n");
    1309                 :          0 :                         return ret_val;
    1310                 :            :                 }
    1311                 :            :         }
    1312                 :            : 
    1313                 :          0 :         phy_data &= ~I347AT4_PSCR_DOWNSHIFT_MASK;
    1314                 :          0 :         phy_data |= I347AT4_PSCR_DOWNSHIFT_6X;
    1315                 :          0 :         phy_data |= I347AT4_PSCR_DOWNSHIFT_ENABLE;
    1316                 :            : 
    1317                 :          0 :         ret_val = phy->ops.write_reg(hw, M88IGC_PHY_SPEC_CTRL, phy_data);
    1318         [ #  # ]:          0 :         if (ret_val)
    1319                 :            :                 return ret_val;
    1320                 :            : 
    1321                 :            :         /* Commit the changes. */
    1322                 :          0 :         ret_val = phy->ops.commit(hw);
    1323         [ #  # ]:          0 :         if (ret_val) {
    1324                 :          0 :                 DEBUGOUT("Error committing the PHY changes\n");
    1325                 :          0 :                 return ret_val;
    1326                 :            :         }
    1327                 :            : 
    1328                 :          0 :         ret_val = igc_set_master_slave_mode(hw);
    1329         [ #  # ]:          0 :         if (ret_val)
    1330                 :          0 :                 return ret_val;
    1331                 :            : 
    1332                 :            :         return IGC_SUCCESS;
    1333                 :            : }
    1334                 :            : 
    1335                 :            : /**
    1336                 :            :  *  igc_copper_link_setup_igp - Setup igp PHY's for copper link
    1337                 :            :  *  @hw: pointer to the HW structure
    1338                 :            :  *
    1339                 :            :  *  Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
    1340                 :            :  *  igp PHY's.
    1341                 :            :  **/
    1342                 :          0 : s32 igc_copper_link_setup_igp(struct igc_hw *hw)
    1343                 :            : {
    1344                 :            :         struct igc_phy_info *phy = &hw->phy;
    1345                 :            :         s32 ret_val;
    1346                 :            :         u16 data;
    1347                 :            : 
    1348                 :          0 :         DEBUGFUNC("igc_copper_link_setup_igp");
    1349                 :            : 
    1350                 :            : 
    1351                 :          0 :         ret_val = hw->phy.ops.reset(hw);
    1352         [ #  # ]:          0 :         if (ret_val) {
    1353                 :          0 :                 DEBUGOUT("Error resetting the PHY.\n");
    1354                 :          0 :                 return ret_val;
    1355                 :            :         }
    1356                 :            : 
    1357                 :            :         /* Wait 100ms for MAC to configure PHY from NVM settings, to avoid
    1358                 :            :          * timeout issues when LFS is enabled.
    1359                 :            :          */
    1360                 :          0 :         msec_delay(100);
    1361                 :            : 
    1362                 :            :         /* The NVM settings will configure LPLU in D3 for
    1363                 :            :          * non-IGP1 PHYs.
    1364                 :            :          */
    1365         [ #  # ]:          0 :         if (phy->type == igc_phy_igp) {
    1366                 :            :                 /* disable lplu d3 during driver init */
    1367                 :          0 :                 ret_val = hw->phy.ops.set_d3_lplu_state(hw, false);
    1368         [ #  # ]:          0 :                 if (ret_val) {
    1369                 :          0 :                         DEBUGOUT("Error Disabling LPLU D3\n");
    1370                 :          0 :                         return ret_val;
    1371                 :            :                 }
    1372                 :            :         }
    1373                 :            : 
    1374                 :            :         /* disable lplu d0 during driver init */
    1375         [ #  # ]:          0 :         if (hw->phy.ops.set_d0_lplu_state) {
    1376                 :          0 :                 ret_val = hw->phy.ops.set_d0_lplu_state(hw, false);
    1377         [ #  # ]:          0 :                 if (ret_val) {
    1378                 :          0 :                         DEBUGOUT("Error Disabling LPLU D0\n");
    1379                 :          0 :                         return ret_val;
    1380                 :            :                 }
    1381                 :            :         }
    1382                 :            :         /* Configure mdi-mdix settings */
    1383                 :          0 :         ret_val = phy->ops.read_reg(hw, IGP01IGC_PHY_PORT_CTRL, &data);
    1384         [ #  # ]:          0 :         if (ret_val)
    1385                 :            :                 return ret_val;
    1386                 :            : 
    1387                 :          0 :         data &= ~IGP01IGC_PSCR_AUTO_MDIX;
    1388                 :            : 
    1389      [ #  #  # ]:          0 :         switch (phy->mdix) {
    1390                 :          0 :         case 1:
    1391                 :          0 :                 data &= ~IGP01IGC_PSCR_FORCE_MDI_MDIX;
    1392                 :          0 :                 break;
    1393                 :          0 :         case 2:
    1394                 :          0 :                 data |= IGP01IGC_PSCR_FORCE_MDI_MDIX;
    1395                 :          0 :                 break;
    1396                 :          0 :         case 0:
    1397                 :            :         default:
    1398                 :          0 :                 data |= IGP01IGC_PSCR_AUTO_MDIX;
    1399                 :          0 :                 break;
    1400                 :            :         }
    1401                 :          0 :         ret_val = phy->ops.write_reg(hw, IGP01IGC_PHY_PORT_CTRL, data);
    1402         [ #  # ]:          0 :         if (ret_val)
    1403                 :            :                 return ret_val;
    1404                 :            : 
    1405                 :            :         /* set auto-master slave resolution settings */
    1406         [ #  # ]:          0 :         if (hw->mac.autoneg) {
    1407                 :            :                 /* when autonegotiation advertisement is only 1000Mbps then we
    1408                 :            :                  * should disable SmartSpeed and enable Auto MasterSlave
    1409                 :            :                  * resolution as hardware default.
    1410                 :            :                  */
    1411         [ #  # ]:          0 :                 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
    1412                 :            :                         /* Disable SmartSpeed */
    1413                 :          0 :                         ret_val = phy->ops.read_reg(hw,
    1414                 :            :                                                     IGP01IGC_PHY_PORT_CONFIG,
    1415                 :            :                                                     &data);
    1416         [ #  # ]:          0 :                         if (ret_val)
    1417                 :            :                                 return ret_val;
    1418                 :            : 
    1419                 :          0 :                         data &= ~IGP01IGC_PSCFR_SMART_SPEED;
    1420                 :          0 :                         ret_val = phy->ops.write_reg(hw,
    1421                 :            :                                                      IGP01IGC_PHY_PORT_CONFIG,
    1422                 :            :                                                      data);
    1423         [ #  # ]:          0 :                         if (ret_val)
    1424                 :            :                                 return ret_val;
    1425                 :            : 
    1426                 :            :                         /* Set auto Master/Slave resolution process */
    1427                 :          0 :                         ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
    1428         [ #  # ]:          0 :                         if (ret_val)
    1429                 :            :                                 return ret_val;
    1430                 :            : 
    1431                 :          0 :                         data &= ~CR_1000T_MS_ENABLE;
    1432                 :          0 :                         ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
    1433         [ #  # ]:          0 :                         if (ret_val)
    1434                 :            :                                 return ret_val;
    1435                 :            :                 }
    1436                 :            : 
    1437                 :          0 :                 ret_val = igc_set_master_slave_mode(hw);
    1438                 :            :         }
    1439                 :            : 
    1440                 :            :         return ret_val;
    1441                 :            : }
    1442                 :            : 
    1443                 :            : /**
    1444                 :            :  *  igc_phy_setup_autoneg - Configure PHY for auto-negotiation
    1445                 :            :  *  @hw: pointer to the HW structure
    1446                 :            :  *
    1447                 :            :  *  Reads the MII auto-neg advertisement register and/or the 1000T control
    1448                 :            :  *  register and if the PHY is already setup for auto-negotiation, then
    1449                 :            :  *  return successful.  Otherwise, setup advertisement and flow control to
    1450                 :            :  *  the appropriate values for the wanted auto-negotiation.
    1451                 :            :  **/
    1452                 :          0 : s32 igc_phy_setup_autoneg(struct igc_hw *hw)
    1453                 :            : {
    1454                 :            :         struct igc_phy_info *phy = &hw->phy;
    1455                 :            :         s32 ret_val;
    1456                 :            :         u16 mii_autoneg_adv_reg;
    1457                 :          0 :         u16 mii_1000t_ctrl_reg = 0;
    1458                 :          0 :         u16 aneg_multigbt_an_ctrl = 0;
    1459                 :            : 
    1460                 :          0 :         DEBUGFUNC("igc_phy_setup_autoneg");
    1461                 :            : 
    1462                 :          0 :         phy->autoneg_advertised &= phy->autoneg_mask;
    1463                 :            : 
    1464                 :            :         /* Read the MII Auto-Neg Advertisement Register (Address 4). */
    1465                 :          0 :         ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
    1466         [ #  # ]:          0 :         if (ret_val)
    1467                 :            :                 return ret_val;
    1468                 :            : 
    1469         [ #  # ]:          0 :         if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
    1470                 :            :                 /* Read the MII 1000Base-T Control Register (Address 9). */
    1471                 :          0 :                 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
    1472                 :            :                                             &mii_1000t_ctrl_reg);
    1473         [ #  # ]:          0 :                 if (ret_val)
    1474                 :            :                         return ret_val;
    1475                 :            :         }
    1476                 :            : 
    1477         [ #  # ]:          0 :         if (phy->autoneg_mask & ADVERTISE_2500_FULL) {
    1478                 :            :         /* Read the MULTI GBT AN Control Register - reg 7.32 */
    1479                 :          0 :                 ret_val = phy->ops.read_reg(hw, (STANDARD_AN_REG_MASK <<
    1480                 :            :                                             MMD_DEVADDR_SHIFT) |
    1481                 :            :                                             ANEG_MULTIGBT_AN_CTRL,
    1482                 :            :                                             &aneg_multigbt_an_ctrl);
    1483                 :            : 
    1484         [ #  # ]:          0 :                 if (ret_val)
    1485                 :            :                         return ret_val;
    1486                 :            :         }
    1487                 :            : 
    1488                 :            :         /* Need to parse both autoneg_advertised and fc and set up
    1489                 :            :          * the appropriate PHY registers.  First we will parse for
    1490                 :            :          * autoneg_advertised software override.  Since we can advertise
    1491                 :            :          * a plethora of combinations, we need to check each bit
    1492                 :            :          * individually.
    1493                 :            :          */
    1494                 :            : 
    1495                 :            :         /* First we clear all the 10/100 mb speed bits in the Auto-Neg
    1496                 :            :          * Advertisement Register (Address 4) and the 1000 mb speed bits in
    1497                 :            :          * the  1000Base-T Control Register (Address 9).
    1498                 :            :          */
    1499                 :          0 :         mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
    1500                 :            :                                  NWAY_AR_100TX_HD_CAPS |
    1501                 :            :                                  NWAY_AR_10T_FD_CAPS   |
    1502                 :            :                                  NWAY_AR_10T_HD_CAPS);
    1503                 :          0 :         mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
    1504                 :            : 
    1505                 :          0 :         DEBUGOUT1("autoneg_advertised %x\n", phy->autoneg_advertised);
    1506                 :            : 
    1507                 :            :         /* Do we want to advertise 10 Mb Half Duplex? */
    1508         [ #  # ]:          0 :         if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
    1509                 :          0 :                 DEBUGOUT("Advertise 10mb Half duplex\n");
    1510                 :          0 :                 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
    1511                 :            :         }
    1512                 :            : 
    1513                 :            :         /* Do we want to advertise 10 Mb Full Duplex? */
    1514         [ #  # ]:          0 :         if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
    1515                 :          0 :                 DEBUGOUT("Advertise 10mb Full duplex\n");
    1516                 :          0 :                 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
    1517                 :            :         }
    1518                 :            : 
    1519                 :            :         /* Do we want to advertise 100 Mb Half Duplex? */
    1520         [ #  # ]:          0 :         if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
    1521                 :          0 :                 DEBUGOUT("Advertise 100mb Half duplex\n");
    1522                 :          0 :                 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
    1523                 :            :         }
    1524                 :            : 
    1525                 :            :         /* Do we want to advertise 100 Mb Full Duplex? */
    1526         [ #  # ]:          0 :         if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
    1527                 :          0 :                 DEBUGOUT("Advertise 100mb Full duplex\n");
    1528                 :          0 :                 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
    1529                 :            :         }
    1530                 :            : 
    1531                 :            :         /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
    1532         [ #  # ]:          0 :         if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
    1533                 :          0 :                 DEBUGOUT("Advertise 1000mb Half duplex request denied!\n");
    1534                 :            : 
    1535                 :            :         /* Do we want to advertise 1000 Mb Full Duplex? */
    1536         [ #  # ]:          0 :         if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
    1537                 :          0 :                 DEBUGOUT("Advertise 1000mb Full duplex\n");
    1538                 :          0 :                 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
    1539                 :            :         }
    1540                 :            : 
    1541                 :            :         /* We do not allow the Phy to advertise 2500 Mb Half Duplex */
    1542         [ #  # ]:          0 :         if (phy->autoneg_advertised & ADVERTISE_2500_HALF)
    1543                 :          0 :                 DEBUGOUT("Advertise 2500mb Half duplex request denied!\n");
    1544                 :            : 
    1545                 :            :         /* Do we want to advertise 2500 Mb Full Duplex? */
    1546         [ #  # ]:          0 :         if (phy->autoneg_advertised & ADVERTISE_2500_FULL) {
    1547                 :          0 :                 DEBUGOUT("Advertise 2500mb Full duplex\n");
    1548                 :          0 :                 aneg_multigbt_an_ctrl |= CR_2500T_FD_CAPS;
    1549                 :            :         } else {
    1550                 :          0 :                 aneg_multigbt_an_ctrl &= ~CR_2500T_FD_CAPS;
    1551                 :            :         }
    1552                 :            : 
    1553                 :            :         /* Check for a software override of the flow control settings, and
    1554                 :            :          * setup the PHY advertisement registers accordingly.  If
    1555                 :            :          * auto-negotiation is enabled, then software will have to set the
    1556                 :            :          * "PAUSE" bits to the correct value in the Auto-Negotiation
    1557                 :            :          * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
    1558                 :            :          * negotiation.
    1559                 :            :          *
    1560                 :            :          * The possible values of the "fc" parameter are:
    1561                 :            :          *      0:  Flow control is completely disabled
    1562                 :            :          *      1:  Rx flow control is enabled (we can receive pause frames
    1563                 :            :          *          but not send pause frames).
    1564                 :            :          *      2:  Tx flow control is enabled (we can send pause frames
    1565                 :            :          *          but we do not support receiving pause frames).
    1566                 :            :          *      3:  Both Rx and Tx flow control (symmetric) are enabled.
    1567                 :            :          *  other:  No software override.  The flow control configuration
    1568                 :            :          *          in the EEPROM is used.
    1569                 :            :          */
    1570   [ #  #  #  #  :          0 :         switch (hw->fc.current_mode) {
                      # ]
    1571                 :          0 :         case igc_fc_none:
    1572                 :            :                 /* Flow control (Rx & Tx) is completely disabled by a
    1573                 :            :                  * software over-ride.
    1574                 :            :                  */
    1575                 :          0 :                 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
    1576                 :          0 :                 break;
    1577                 :          0 :         case igc_fc_rx_pause:
    1578                 :            :                 /* Rx Flow control is enabled, and Tx Flow control is
    1579                 :            :                  * disabled, by a software over-ride.
    1580                 :            :                  *
    1581                 :            :                  * Since there really isn't a way to advertise that we are
    1582                 :            :                  * capable of Rx Pause ONLY, we will advertise that we
    1583                 :            :                  * support both symmetric and asymmetric Rx PAUSE.  Later
    1584                 :            :                  * (in igc_config_fc_after_link_up) we will disable the
    1585                 :            :                  * hw's ability to send PAUSE frames.
    1586                 :            :                  */
    1587                 :          0 :                 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
    1588                 :          0 :                 break;
    1589                 :          0 :         case igc_fc_tx_pause:
    1590                 :            :                 /* Tx Flow control is enabled, and Rx Flow control is
    1591                 :            :                  * disabled, by a software over-ride.
    1592                 :            :                  */
    1593                 :          0 :                 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
    1594                 :          0 :                 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
    1595                 :          0 :                 break;
    1596                 :          0 :         case igc_fc_full:
    1597                 :            :                 /* Flow control (both Rx and Tx) is enabled by a software
    1598                 :            :                  * over-ride.
    1599                 :            :                  */
    1600                 :          0 :                 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
    1601                 :          0 :                 break;
    1602                 :          0 :         default:
    1603                 :          0 :                 DEBUGOUT("Flow control param set incorrectly\n");
    1604                 :          0 :                 return -IGC_ERR_CONFIG;
    1605                 :            :         }
    1606                 :            : 
    1607                 :          0 :         ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
    1608         [ #  # ]:          0 :         if (ret_val)
    1609                 :            :                 return ret_val;
    1610                 :            : 
    1611                 :          0 :         DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
    1612                 :            : 
    1613         [ #  # ]:          0 :         if (phy->autoneg_mask & ADVERTISE_1000_FULL)
    1614                 :          0 :                 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL,
    1615                 :            :                                              mii_1000t_ctrl_reg);
    1616                 :            : 
    1617         [ #  # ]:          0 :         if (phy->autoneg_mask & ADVERTISE_2500_FULL)
    1618                 :          0 :                 ret_val = phy->ops.write_reg(hw,
    1619                 :            :                                              (STANDARD_AN_REG_MASK <<
    1620                 :            :                                              MMD_DEVADDR_SHIFT) |
    1621                 :            :                                              ANEG_MULTIGBT_AN_CTRL,
    1622                 :            :                                              aneg_multigbt_an_ctrl);
    1623                 :            : 
    1624                 :            :         return ret_val;
    1625                 :            : }
    1626                 :            : 
    1627                 :            : /**
    1628                 :            :  *  igc_copper_link_autoneg - Setup/Enable autoneg for copper link
    1629                 :            :  *  @hw: pointer to the HW structure
    1630                 :            :  *
    1631                 :            :  *  Performs initial bounds checking on autoneg advertisement parameter, then
    1632                 :            :  *  configure to advertise the full capability.  Setup the PHY to autoneg
    1633                 :            :  *  and restart the negotiation process between the link partner.  If
    1634                 :            :  *  autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
    1635                 :            :  **/
    1636                 :          0 : s32 igc_copper_link_autoneg(struct igc_hw *hw)
    1637                 :            : {
    1638                 :            :         struct igc_phy_info *phy = &hw->phy;
    1639                 :            :         s32 ret_val;
    1640                 :            :         u16 phy_ctrl;
    1641                 :            : 
    1642                 :          0 :         DEBUGFUNC("igc_copper_link_autoneg");
    1643                 :            : 
    1644                 :            :         /* Perform some bounds checking on the autoneg advertisement
    1645                 :            :          * parameter.
    1646                 :            :          */
    1647                 :          0 :         phy->autoneg_advertised &= phy->autoneg_mask;
    1648                 :            : 
    1649                 :            :         /* If autoneg_advertised is zero, we assume it was not defaulted
    1650                 :            :          * by the calling code so we set to advertise full capability.
    1651                 :            :          */
    1652         [ #  # ]:          0 :         if (!phy->autoneg_advertised)
    1653                 :          0 :                 phy->autoneg_advertised = phy->autoneg_mask;
    1654                 :            : 
    1655                 :          0 :         DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
    1656                 :          0 :         ret_val = igc_phy_setup_autoneg(hw);
    1657         [ #  # ]:          0 :         if (ret_val) {
    1658                 :          0 :                 DEBUGOUT("Error Setting up Auto-Negotiation\n");
    1659                 :          0 :                 return ret_val;
    1660                 :            :         }
    1661                 :          0 :         DEBUGOUT("Restarting Auto-Neg\n");
    1662                 :            : 
    1663                 :            :         /* Restart auto-negotiation by setting the Auto Neg Enable bit and
    1664                 :            :          * the Auto Neg Restart bit in the PHY control register.
    1665                 :            :          */
    1666                 :          0 :         ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
    1667         [ #  # ]:          0 :         if (ret_val)
    1668                 :            :                 return ret_val;
    1669                 :            : 
    1670                 :          0 :         phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
    1671                 :          0 :         ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
    1672         [ #  # ]:          0 :         if (ret_val)
    1673                 :            :                 return ret_val;
    1674                 :            : 
    1675                 :            :         /* Does the user want to wait for Auto-Neg to complete here, or
    1676                 :            :          * check at a later time (for example, callback routine).
    1677                 :            :          */
    1678         [ #  # ]:          0 :         if (phy->autoneg_wait_to_complete) {
    1679                 :          0 :                 ret_val = igc_wait_autoneg(hw);
    1680         [ #  # ]:          0 :                 if (ret_val) {
    1681                 :          0 :                         DEBUGOUT("Error while waiting for autoneg to complete\n");
    1682                 :          0 :                         return ret_val;
    1683                 :            :                 }
    1684                 :            :         }
    1685                 :            : 
    1686                 :          0 :         hw->mac.get_link_status = true;
    1687                 :            : 
    1688                 :          0 :         return ret_val;
    1689                 :            : }
    1690                 :            : 
    1691                 :            : /**
    1692                 :            :  *  igc_setup_copper_link_generic - Configure copper link settings
    1693                 :            :  *  @hw: pointer to the HW structure
    1694                 :            :  *
    1695                 :            :  *  Calls the appropriate function to configure the link for auto-neg or forced
    1696                 :            :  *  speed and duplex.  Then we check for link, once link is established calls
    1697                 :            :  *  to configure collision distance and flow control are called.  If link is
    1698                 :            :  *  not established, we return -IGC_ERR_PHY (-2).
    1699                 :            :  **/
    1700                 :          0 : s32 igc_setup_copper_link_generic(struct igc_hw *hw)
    1701                 :            : {
    1702                 :            :         s32 ret_val;
    1703                 :          0 :         bool link = false;
    1704                 :            : 
    1705                 :          0 :         DEBUGFUNC("igc_setup_copper_link_generic");
    1706                 :            : 
    1707         [ #  # ]:          0 :         if (hw->mac.autoneg) {
    1708                 :            :                 /* Setup autoneg and flow control advertisement and perform
    1709                 :            :                  * autonegotiation.
    1710                 :            :                  */
    1711                 :          0 :                 ret_val = igc_copper_link_autoneg(hw);
    1712         [ #  # ]:          0 :                 if (ret_val)
    1713                 :            :                         return ret_val;
    1714                 :            :         } else {
    1715                 :            :                 /* PHY will be set to 10H, 10F, 100H or 100F
    1716                 :            :                  * depending on user settings.
    1717                 :            :                  */
    1718                 :          0 :                 DEBUGOUT("Forcing Speed and Duplex\n");
    1719                 :          0 :                 ret_val = hw->phy.ops.force_speed_duplex(hw);
    1720         [ #  # ]:          0 :                 if (ret_val) {
    1721                 :          0 :                         DEBUGOUT("Error Forcing Speed and Duplex\n");
    1722                 :          0 :                         return ret_val;
    1723                 :            :                 }
    1724                 :            :         }
    1725                 :            : 
    1726                 :            :         /* Check link status. Wait up to 100 microseconds for link to become
    1727                 :            :          * valid.
    1728                 :            :          */
    1729                 :          0 :         ret_val = igc_phy_has_link_generic(hw, COPPER_LINK_UP_LIMIT, 10,
    1730                 :            :                                              &link);
    1731         [ #  # ]:          0 :         if (ret_val)
    1732                 :            :                 return ret_val;
    1733                 :            : 
    1734         [ #  # ]:          0 :         if (link) {
    1735                 :          0 :                 DEBUGOUT("Valid link established!!!\n");
    1736                 :          0 :                 hw->mac.ops.config_collision_dist(hw);
    1737                 :          0 :                 ret_val = igc_config_fc_after_link_up_generic(hw);
    1738                 :            :         } else {
    1739                 :          0 :                 DEBUGOUT("Unable to establish link!!!\n");
    1740                 :            :         }
    1741                 :            : 
    1742                 :            :         return ret_val;
    1743                 :            : }
    1744                 :            : 
    1745                 :            : /**
    1746                 :            :  *  igc_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
    1747                 :            :  *  @hw: pointer to the HW structure
    1748                 :            :  *
    1749                 :            :  *  Calls the PHY setup function to force speed and duplex.  Clears the
    1750                 :            :  *  auto-crossover to force MDI manually.  Waits for link and returns
    1751                 :            :  *  successful if link up is successful, else -IGC_ERR_PHY (-2).
    1752                 :            :  **/
    1753                 :          0 : s32 igc_phy_force_speed_duplex_igp(struct igc_hw *hw)
    1754                 :            : {
    1755                 :            :         struct igc_phy_info *phy = &hw->phy;
    1756                 :            :         s32 ret_val;
    1757                 :            :         u16 phy_data;
    1758                 :            :         bool link;
    1759                 :            : 
    1760                 :          0 :         DEBUGFUNC("igc_phy_force_speed_duplex_igp");
    1761                 :            : 
    1762                 :          0 :         ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
    1763         [ #  # ]:          0 :         if (ret_val)
    1764                 :            :                 return ret_val;
    1765                 :            : 
    1766                 :          0 :         igc_phy_force_speed_duplex_setup(hw, &phy_data);
    1767                 :            : 
    1768                 :          0 :         ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
    1769         [ #  # ]:          0 :         if (ret_val)
    1770                 :            :                 return ret_val;
    1771                 :            : 
    1772                 :            :         /* Clear Auto-Crossover to force MDI manually.  IGP requires MDI
    1773                 :            :          * forced whenever speed and duplex are forced.
    1774                 :            :          */
    1775                 :          0 :         ret_val = phy->ops.read_reg(hw, IGP01IGC_PHY_PORT_CTRL, &phy_data);
    1776         [ #  # ]:          0 :         if (ret_val)
    1777                 :            :                 return ret_val;
    1778                 :            : 
    1779                 :          0 :         phy_data &= ~IGP01IGC_PSCR_AUTO_MDIX;
    1780                 :          0 :         phy_data &= ~IGP01IGC_PSCR_FORCE_MDI_MDIX;
    1781                 :            : 
    1782                 :          0 :         ret_val = phy->ops.write_reg(hw, IGP01IGC_PHY_PORT_CTRL, phy_data);
    1783         [ #  # ]:          0 :         if (ret_val)
    1784                 :            :                 return ret_val;
    1785                 :            : 
    1786                 :          0 :         DEBUGOUT1("IGP PSCR: %X\n", phy_data);
    1787                 :            : 
    1788                 :          0 :         usec_delay(1);
    1789                 :            : 
    1790         [ #  # ]:          0 :         if (phy->autoneg_wait_to_complete) {
    1791                 :          0 :                 DEBUGOUT("Waiting for forced speed/duplex link on IGP phy.\n");
    1792                 :            : 
    1793                 :          0 :                 ret_val = igc_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
    1794                 :            :                                                      100000, &link);
    1795         [ #  # ]:          0 :                 if (ret_val)
    1796                 :            :                         return ret_val;
    1797                 :            : 
    1798         [ #  # ]:          0 :                 if (!link)
    1799                 :          0 :                         DEBUGOUT("Link taking longer than expected.\n");
    1800                 :            : 
    1801                 :            :                 /* Try once more */
    1802                 :          0 :                 ret_val = igc_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
    1803                 :            :                                                      100000, &link);
    1804                 :            :         }
    1805                 :            : 
    1806                 :            :         return ret_val;
    1807                 :            : }
    1808                 :            : 
    1809                 :            : /**
    1810                 :            :  *  igc_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
    1811                 :            :  *  @hw: pointer to the HW structure
    1812                 :            :  *
    1813                 :            :  *  Calls the PHY setup function to force speed and duplex.  Clears the
    1814                 :            :  *  auto-crossover to force MDI manually.  Resets the PHY to commit the
    1815                 :            :  *  changes.  If time expires while waiting for link up, we reset the DSP.
    1816                 :            :  *  After reset, TX_CLK and CRS on Tx must be set.  Return successful upon
    1817                 :            :  *  successful completion, else return corresponding error code.
    1818                 :            :  **/
    1819                 :          0 : s32 igc_phy_force_speed_duplex_m88(struct igc_hw *hw)
    1820                 :            : {
    1821                 :            :         struct igc_phy_info *phy = &hw->phy;
    1822                 :            :         s32 ret_val;
    1823                 :            :         u16 phy_data;
    1824                 :            :         bool link;
    1825                 :            : 
    1826                 :          0 :         DEBUGFUNC("igc_phy_force_speed_duplex_m88");
    1827                 :            : 
    1828                 :            :         /* I210 and I211 devices support Auto-Crossover in forced operation. */
    1829         [ #  # ]:          0 :         if (phy->type != igc_phy_i210) {
    1830                 :            :                 /* Clear Auto-Crossover to force MDI manually.  M88E1000
    1831                 :            :                  * requires MDI forced whenever speed and duplex are forced.
    1832                 :            :                  */
    1833                 :          0 :                 ret_val = phy->ops.read_reg(hw, M88IGC_PHY_SPEC_CTRL,
    1834                 :            :                                             &phy_data);
    1835         [ #  # ]:          0 :                 if (ret_val)
    1836                 :            :                         return ret_val;
    1837                 :            : 
    1838                 :          0 :                 phy_data &= ~M88IGC_PSCR_AUTO_X_MODE;
    1839                 :          0 :                 ret_val = phy->ops.write_reg(hw, M88IGC_PHY_SPEC_CTRL,
    1840                 :            :                                              phy_data);
    1841         [ #  # ]:          0 :                 if (ret_val)
    1842                 :            :                         return ret_val;
    1843                 :            : 
    1844                 :          0 :                 DEBUGOUT1("M88E1000 PSCR: %X\n", phy_data);
    1845                 :            :         }
    1846                 :            : 
    1847                 :          0 :         ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
    1848         [ #  # ]:          0 :         if (ret_val)
    1849                 :            :                 return ret_val;
    1850                 :            : 
    1851                 :          0 :         igc_phy_force_speed_duplex_setup(hw, &phy_data);
    1852                 :            : 
    1853                 :          0 :         ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
    1854         [ #  # ]:          0 :         if (ret_val)
    1855                 :            :                 return ret_val;
    1856                 :            : 
    1857                 :            :         /* Reset the phy to commit changes. */
    1858                 :          0 :         ret_val = hw->phy.ops.commit(hw);
    1859         [ #  # ]:          0 :         if (ret_val)
    1860                 :            :                 return ret_val;
    1861                 :            : 
    1862         [ #  # ]:          0 :         if (phy->autoneg_wait_to_complete) {
    1863                 :          0 :                 DEBUGOUT("Waiting for forced speed/duplex link on M88 phy.\n");
    1864                 :            : 
    1865                 :          0 :                 ret_val = igc_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
    1866                 :            :                                                      100000, &link);
    1867         [ #  # ]:          0 :                 if (ret_val)
    1868                 :            :                         return ret_val;
    1869                 :            : 
    1870         [ #  # ]:          0 :                 if (!link) {
    1871                 :            :                         bool reset_dsp = true;
    1872                 :            : 
    1873         [ #  # ]:          0 :                         switch (hw->phy.id) {
    1874                 :            :                         case I347AT4_E_PHY_ID:
    1875                 :            :                         case M88E1340M_E_PHY_ID:
    1876                 :            :                         case M88E1112_E_PHY_ID:
    1877                 :            :                         case M88E1543_E_PHY_ID:
    1878                 :            :                         case M88E1512_E_PHY_ID:
    1879                 :            :                         case I210_I_PHY_ID:
    1880                 :            :                         /* fall-through */
    1881                 :            :                         case I225_I_PHY_ID:
    1882                 :            :                         /* fall-through */
    1883                 :            :                                 reset_dsp = false;
    1884                 :            :                                 break;
    1885                 :          0 :                         default:
    1886         [ #  # ]:          0 :                                 if (hw->phy.type != igc_phy_m88)
    1887                 :            :                                         reset_dsp = false;
    1888                 :            :                                 break;
    1889                 :            :                         }
    1890                 :            : 
    1891                 :            :                         if (!reset_dsp) {
    1892                 :          0 :                                 DEBUGOUT("Link taking longer than expected.\n");
    1893                 :            :                         } else {
    1894                 :            :                                 /* We didn't get link.
    1895                 :            :                                  * Reset the DSP and cross our fingers.
    1896                 :            :                                  */
    1897                 :          0 :                                 ret_val = phy->ops.write_reg(hw,
    1898                 :            :                                                 M88IGC_PHY_PAGE_SELECT,
    1899                 :            :                                                 0x001d);
    1900         [ #  # ]:          0 :                                 if (ret_val)
    1901                 :            :                                         return ret_val;
    1902                 :          0 :                                 ret_val = igc_phy_reset_dsp_generic(hw);
    1903         [ #  # ]:          0 :                                 if (ret_val)
    1904                 :            :                                         return ret_val;
    1905                 :            :                         }
    1906                 :            :                 }
    1907                 :            : 
    1908                 :            :                 /* Try once more */
    1909                 :          0 :                 ret_val = igc_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
    1910                 :            :                                                      100000, &link);
    1911         [ #  # ]:          0 :                 if (ret_val)
    1912                 :            :                         return ret_val;
    1913                 :            :         }
    1914                 :            : 
    1915         [ #  # ]:          0 :         if (hw->phy.type != igc_phy_m88)
    1916                 :            :                 return IGC_SUCCESS;
    1917                 :            : 
    1918         [ #  # ]:          0 :         if (hw->phy.id == I347AT4_E_PHY_ID ||
    1919         [ #  # ]:          0 :                 hw->phy.id == M88E1340M_E_PHY_ID ||
    1920                 :            :                 hw->phy.id == M88E1112_E_PHY_ID)
    1921                 :            :                 return IGC_SUCCESS;
    1922         [ #  # ]:          0 :         if (hw->phy.id == I210_I_PHY_ID)
    1923                 :            :                 return IGC_SUCCESS;
    1924         [ #  # ]:          0 :         if (hw->phy.id == I225_I_PHY_ID)
    1925                 :            :                 return IGC_SUCCESS;
    1926         [ #  # ]:          0 :         if (hw->phy.id == M88E1543_E_PHY_ID || hw->phy.id == M88E1512_E_PHY_ID)
    1927                 :            :                 return IGC_SUCCESS;
    1928                 :          0 :         ret_val = phy->ops.read_reg(hw, M88IGC_EXT_PHY_SPEC_CTRL, &phy_data);
    1929         [ #  # ]:          0 :         if (ret_val)
    1930                 :            :                 return ret_val;
    1931                 :            : 
    1932                 :            :         /* Resetting the phy means we need to re-force TX_CLK in the
    1933                 :            :          * Extended PHY Specific Control Register to 25MHz clock from
    1934                 :            :          * the reset value of 2.5MHz.
    1935                 :            :          */
    1936                 :          0 :         phy_data |= M88IGC_EPSCR_TX_CLK_25;
    1937                 :          0 :         ret_val = phy->ops.write_reg(hw, M88IGC_EXT_PHY_SPEC_CTRL, phy_data);
    1938         [ #  # ]:          0 :         if (ret_val)
    1939                 :            :                 return ret_val;
    1940                 :            : 
    1941                 :            :         /* In addition, we must re-enable CRS on Tx for both half and full
    1942                 :            :          * duplex.
    1943                 :            :          */
    1944                 :          0 :         ret_val = phy->ops.read_reg(hw, M88IGC_PHY_SPEC_CTRL, &phy_data);
    1945         [ #  # ]:          0 :         if (ret_val)
    1946                 :            :                 return ret_val;
    1947                 :            : 
    1948                 :          0 :         phy_data |= M88IGC_PSCR_ASSERT_CRS_ON_TX;
    1949                 :          0 :         ret_val = phy->ops.write_reg(hw, M88IGC_PHY_SPEC_CTRL, phy_data);
    1950                 :            : 
    1951                 :          0 :         return ret_val;
    1952                 :            : }
    1953                 :            : 
    1954                 :            : /**
    1955                 :            :  *  igc_phy_force_speed_duplex_ife - Force PHY speed & duplex
    1956                 :            :  *  @hw: pointer to the HW structure
    1957                 :            :  *
    1958                 :            :  *  Forces the speed and duplex settings of the PHY.
    1959                 :            :  *  This is a function pointer entry point only called by
    1960                 :            :  *  PHY setup routines.
    1961                 :            :  **/
    1962                 :          0 : s32 igc_phy_force_speed_duplex_ife(struct igc_hw *hw)
    1963                 :            : {
    1964                 :            :         struct igc_phy_info *phy = &hw->phy;
    1965                 :            :         s32 ret_val;
    1966                 :            :         u16 data;
    1967                 :            :         bool link;
    1968                 :            : 
    1969                 :          0 :         DEBUGFUNC("igc_phy_force_speed_duplex_ife");
    1970                 :            : 
    1971                 :          0 :         ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &data);
    1972         [ #  # ]:          0 :         if (ret_val)
    1973                 :            :                 return ret_val;
    1974                 :            : 
    1975                 :          0 :         igc_phy_force_speed_duplex_setup(hw, &data);
    1976                 :            : 
    1977                 :          0 :         ret_val = phy->ops.write_reg(hw, PHY_CONTROL, data);
    1978         [ #  # ]:          0 :         if (ret_val)
    1979                 :            :                 return ret_val;
    1980                 :            : 
    1981                 :            :         /* Disable MDI-X support for 10/100 */
    1982                 :          0 :         ret_val = phy->ops.read_reg(hw, IFE_PHY_MDIX_CONTROL, &data);
    1983         [ #  # ]:          0 :         if (ret_val)
    1984                 :            :                 return ret_val;
    1985                 :            : 
    1986                 :          0 :         data &= ~IFE_PMC_AUTO_MDIX;
    1987                 :          0 :         data &= ~IFE_PMC_FORCE_MDIX;
    1988                 :            : 
    1989                 :          0 :         ret_val = phy->ops.write_reg(hw, IFE_PHY_MDIX_CONTROL, data);
    1990         [ #  # ]:          0 :         if (ret_val)
    1991                 :            :                 return ret_val;
    1992                 :            : 
    1993                 :          0 :         DEBUGOUT1("IFE PMC: %X\n", data);
    1994                 :            : 
    1995                 :          0 :         usec_delay(1);
    1996                 :            : 
    1997         [ #  # ]:          0 :         if (phy->autoneg_wait_to_complete) {
    1998                 :          0 :                 DEBUGOUT("Waiting for forced speed/duplex link on IFE phy.\n");
    1999                 :            : 
    2000                 :          0 :                 ret_val = igc_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
    2001                 :            :                                                      100000, &link);
    2002         [ #  # ]:          0 :                 if (ret_val)
    2003                 :            :                         return ret_val;
    2004                 :            : 
    2005         [ #  # ]:          0 :                 if (!link)
    2006                 :          0 :                         DEBUGOUT("Link taking longer than expected.\n");
    2007                 :            : 
    2008                 :            :                 /* Try once more */
    2009                 :          0 :                 ret_val = igc_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
    2010                 :            :                                                      100000, &link);
    2011         [ #  # ]:          0 :                 if (ret_val)
    2012                 :          0 :                         return ret_val;
    2013                 :            :         }
    2014                 :            : 
    2015                 :            :         return IGC_SUCCESS;
    2016                 :            : }
    2017                 :            : 
    2018                 :            : /**
    2019                 :            :  *  igc_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
    2020                 :            :  *  @hw: pointer to the HW structure
    2021                 :            :  *  @phy_ctrl: pointer to current value of PHY_CONTROL
    2022                 :            :  *
    2023                 :            :  *  Forces speed and duplex on the PHY by doing the following: disable flow
    2024                 :            :  *  control, force speed/duplex on the MAC, disable auto speed detection,
    2025                 :            :  *  disable auto-negotiation, configure duplex, configure speed, configure
    2026                 :            :  *  the collision distance, write configuration to CTRL register.  The
    2027                 :            :  *  caller must write to the PHY_CONTROL register for these settings to
    2028                 :            :  *  take affect.
    2029                 :            :  **/
    2030                 :          0 : void igc_phy_force_speed_duplex_setup(struct igc_hw *hw, u16 *phy_ctrl)
    2031                 :            : {
    2032                 :            :         struct igc_mac_info *mac = &hw->mac;
    2033                 :            :         u32 ctrl;
    2034                 :            : 
    2035                 :          0 :         DEBUGFUNC("igc_phy_force_speed_duplex_setup");
    2036                 :            : 
    2037                 :            :         /* Turn off flow control when forcing speed/duplex */
    2038                 :          0 :         hw->fc.current_mode = igc_fc_none;
    2039                 :            : 
    2040                 :            :         /* Force speed/duplex on the mac */
    2041                 :          0 :         ctrl = IGC_READ_REG(hw, IGC_CTRL);
    2042                 :            :         ctrl |= (IGC_CTRL_FRCSPD | IGC_CTRL_FRCDPX);
    2043                 :            :         ctrl &= ~IGC_CTRL_SPD_SEL;
    2044                 :            : 
    2045                 :            :         /* Disable Auto Speed Detection */
    2046                 :            :         ctrl &= ~IGC_CTRL_ASDE;
    2047                 :            : 
    2048                 :            :         /* Disable autoneg on the phy */
    2049                 :          0 :         *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
    2050                 :            : 
    2051                 :            :         /* Forcing Full or Half Duplex? */
    2052         [ #  # ]:          0 :         if (mac->forced_speed_duplex & IGC_ALL_HALF_DUPLEX) {
    2053                 :          0 :                 ctrl &= ~IGC_CTRL_FD;
    2054                 :          0 :                 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
    2055                 :          0 :                 DEBUGOUT("Half Duplex\n");
    2056                 :            :         } else {
    2057                 :          0 :                 ctrl |= IGC_CTRL_FD;
    2058                 :          0 :                 *phy_ctrl |= MII_CR_FULL_DUPLEX;
    2059                 :          0 :                 DEBUGOUT("Full Duplex\n");
    2060                 :            :         }
    2061                 :            : 
    2062                 :            :         /* Forcing 10mb or 100mb? */
    2063         [ #  # ]:          0 :         if (mac->forced_speed_duplex & IGC_ALL_100_SPEED) {
    2064                 :          0 :                 ctrl |= IGC_CTRL_SPD_100;
    2065                 :          0 :                 *phy_ctrl |= MII_CR_SPEED_100;
    2066                 :          0 :                 *phy_ctrl &= ~MII_CR_SPEED_1000;
    2067                 :          0 :                 DEBUGOUT("Forcing 100mb\n");
    2068                 :            :         } else {
    2069                 :            :                 ctrl &= ~(IGC_CTRL_SPD_1000 | IGC_CTRL_SPD_100);
    2070                 :          0 :                 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
    2071                 :          0 :                 DEBUGOUT("Forcing 10mb\n");
    2072                 :            :         }
    2073                 :            : 
    2074                 :          0 :         hw->mac.ops.config_collision_dist(hw);
    2075                 :            : 
    2076                 :          0 :         IGC_WRITE_REG(hw, IGC_CTRL, ctrl);
    2077                 :          0 : }
    2078                 :            : 
    2079                 :            : /**
    2080                 :            :  *  igc_set_d3_lplu_state_generic - Sets low power link up state for D3
    2081                 :            :  *  @hw: pointer to the HW structure
    2082                 :            :  *  @active: boolean used to enable/disable lplu
    2083                 :            :  *
    2084                 :            :  *  Success returns 0, Failure returns 1
    2085                 :            :  *
    2086                 :            :  *  The low power link up (lplu) state is set to the power management level D3
    2087                 :            :  *  and SmartSpeed is disabled when active is true, else clear lplu for D3
    2088                 :            :  *  and enable Smartspeed.  LPLU and Smartspeed are mutually exclusive.  LPLU
    2089                 :            :  *  is used during Dx states where the power conservation is most important.
    2090                 :            :  *  During driver activity, SmartSpeed should be enabled so performance is
    2091                 :            :  *  maintained.
    2092                 :            :  **/
    2093                 :          0 : s32 igc_set_d3_lplu_state_generic(struct igc_hw *hw, bool active)
    2094                 :            : {
    2095                 :            :         struct igc_phy_info *phy = &hw->phy;
    2096                 :            :         s32 ret_val;
    2097                 :            :         u16 data;
    2098                 :            : 
    2099                 :          0 :         DEBUGFUNC("igc_set_d3_lplu_state_generic");
    2100                 :            : 
    2101         [ #  # ]:          0 :         if (!hw->phy.ops.read_reg)
    2102                 :            :                 return IGC_SUCCESS;
    2103                 :            : 
    2104                 :          0 :         ret_val = phy->ops.read_reg(hw, IGP02IGC_PHY_POWER_MGMT, &data);
    2105         [ #  # ]:          0 :         if (ret_val)
    2106                 :            :                 return ret_val;
    2107                 :            : 
    2108         [ #  # ]:          0 :         if (!active) {
    2109                 :          0 :                 data &= ~IGP02IGC_PM_D3_LPLU;
    2110                 :          0 :                 ret_val = phy->ops.write_reg(hw, IGP02IGC_PHY_POWER_MGMT,
    2111                 :            :                                              data);
    2112         [ #  # ]:          0 :                 if (ret_val)
    2113                 :            :                         return ret_val;
    2114                 :            :                 /* LPLU and SmartSpeed are mutually exclusive.  LPLU is used
    2115                 :            :                  * during Dx states where the power conservation is most
    2116                 :            :                  * important.  During driver activity we should enable
    2117                 :            :                  * SmartSpeed, so performance is maintained.
    2118                 :            :                  */
    2119         [ #  # ]:          0 :                 if (phy->smart_speed == igc_smart_speed_on) {
    2120                 :          0 :                         ret_val = phy->ops.read_reg(hw,
    2121                 :            :                                                     IGP01IGC_PHY_PORT_CONFIG,
    2122                 :            :                                                     &data);
    2123         [ #  # ]:          0 :                         if (ret_val)
    2124                 :            :                                 return ret_val;
    2125                 :            : 
    2126                 :          0 :                         data |= IGP01IGC_PSCFR_SMART_SPEED;
    2127                 :          0 :                         ret_val = phy->ops.write_reg(hw,
    2128                 :            :                                                      IGP01IGC_PHY_PORT_CONFIG,
    2129                 :            :                                                      data);
    2130         [ #  # ]:          0 :                         if (ret_val)
    2131                 :          0 :                                 return ret_val;
    2132         [ #  # ]:          0 :                 } else if (phy->smart_speed == igc_smart_speed_off) {
    2133                 :          0 :                         ret_val = phy->ops.read_reg(hw,
    2134                 :            :                                                     IGP01IGC_PHY_PORT_CONFIG,
    2135                 :            :                                                     &data);
    2136         [ #  # ]:          0 :                         if (ret_val)
    2137                 :            :                                 return ret_val;
    2138                 :            : 
    2139                 :          0 :                         data &= ~IGP01IGC_PSCFR_SMART_SPEED;
    2140                 :          0 :                         ret_val = phy->ops.write_reg(hw,
    2141                 :            :                                                      IGP01IGC_PHY_PORT_CONFIG,
    2142                 :            :                                                      data);
    2143         [ #  # ]:          0 :                         if (ret_val)
    2144                 :          0 :                                 return ret_val;
    2145                 :            :                 }
    2146         [ #  # ]:          0 :         } else if ((phy->autoneg_advertised == IGC_ALL_SPEED_DUPLEX) ||
    2147         [ #  # ]:          0 :                    (phy->autoneg_advertised == IGC_ALL_NOT_GIG) ||
    2148                 :            :                    (phy->autoneg_advertised == IGC_ALL_10_SPEED)) {
    2149                 :          0 :                 data |= IGP02IGC_PM_D3_LPLU;
    2150                 :          0 :                 ret_val = phy->ops.write_reg(hw, IGP02IGC_PHY_POWER_MGMT,
    2151                 :            :                                              data);
    2152         [ #  # ]:          0 :                 if (ret_val)
    2153                 :            :                         return ret_val;
    2154                 :            : 
    2155                 :            :                 /* When LPLU is enabled, we should disable SmartSpeed */
    2156                 :          0 :                 ret_val = phy->ops.read_reg(hw, IGP01IGC_PHY_PORT_CONFIG,
    2157                 :            :                                             &data);
    2158         [ #  # ]:          0 :                 if (ret_val)
    2159                 :            :                         return ret_val;
    2160                 :            : 
    2161                 :          0 :                 data &= ~IGP01IGC_PSCFR_SMART_SPEED;
    2162                 :          0 :                 ret_val = phy->ops.write_reg(hw, IGP01IGC_PHY_PORT_CONFIG,
    2163                 :            :                                              data);
    2164                 :            :         }
    2165                 :            : 
    2166                 :            :         return ret_val;
    2167                 :            : }
    2168                 :            : 
    2169                 :            : /**
    2170                 :            :  *  igc_check_downshift_generic - Checks whether a downshift in speed occurred
    2171                 :            :  *  @hw: pointer to the HW structure
    2172                 :            :  *
    2173                 :            :  *  Success returns 0, Failure returns 1
    2174                 :            :  *
    2175                 :            :  *  A downshift is detected by querying the PHY link health.
    2176                 :            :  **/
    2177                 :          0 : s32 igc_check_downshift_generic(struct igc_hw *hw)
    2178                 :            : {
    2179                 :            :         struct igc_phy_info *phy = &hw->phy;
    2180                 :            :         s32 ret_val;
    2181                 :            :         u16 phy_data, offset, mask;
    2182                 :            : 
    2183                 :          0 :         DEBUGFUNC("igc_check_downshift_generic");
    2184                 :            : 
    2185      [ #  #  # ]:          0 :         switch (phy->type) {
    2186                 :            :         case igc_phy_i210:
    2187                 :            :         case igc_phy_m88:
    2188                 :            :         case igc_phy_gg82563:
    2189                 :            :         case igc_phy_bm:
    2190                 :            :         case igc_phy_82578:
    2191                 :            :                 offset = M88IGC_PHY_SPEC_STATUS;
    2192                 :            :                 mask = M88IGC_PSSR_DOWNSHIFT;
    2193                 :            :                 break;
    2194                 :          0 :         case igc_phy_igp:
    2195                 :            :         case igc_phy_igp_2:
    2196                 :            :         case igc_phy_igp_3:
    2197                 :            :                 offset = IGP01IGC_PHY_LINK_HEALTH;
    2198                 :            :                 mask = IGP01IGC_PLHR_SS_DOWNGRADE;
    2199                 :          0 :                 break;
    2200                 :          0 :         default:
    2201                 :            :                 /* speed downshift not supported */
    2202                 :          0 :                 phy->speed_downgraded = false;
    2203                 :          0 :                 return IGC_SUCCESS;
    2204                 :            :         }
    2205                 :            : 
    2206                 :          0 :         ret_val = phy->ops.read_reg(hw, offset, &phy_data);
    2207                 :            : 
    2208         [ #  # ]:          0 :         if (!ret_val)
    2209                 :          0 :                 phy->speed_downgraded = !!(phy_data & mask);
    2210                 :            : 
    2211                 :            :         return ret_val;
    2212                 :            : }
    2213                 :            : 
    2214                 :            : /**
    2215                 :            :  *  igc_check_polarity_m88 - Checks the polarity.
    2216                 :            :  *  @hw: pointer to the HW structure
    2217                 :            :  *
    2218                 :            :  *  Success returns 0, Failure returns -IGC_ERR_PHY (-2)
    2219                 :            :  *
    2220                 :            :  *  Polarity is determined based on the PHY specific status register.
    2221                 :            :  **/
    2222                 :          0 : s32 igc_check_polarity_m88(struct igc_hw *hw)
    2223                 :            : {
    2224                 :            :         struct igc_phy_info *phy = &hw->phy;
    2225                 :            :         s32 ret_val;
    2226                 :            :         u16 data;
    2227                 :            : 
    2228                 :          0 :         DEBUGFUNC("igc_check_polarity_m88");
    2229                 :            : 
    2230                 :          0 :         ret_val = phy->ops.read_reg(hw, M88IGC_PHY_SPEC_STATUS, &data);
    2231                 :            : 
    2232         [ #  # ]:          0 :         if (!ret_val)
    2233                 :          0 :                 phy->cable_polarity = ((data & M88IGC_PSSR_REV_POLARITY)
    2234                 :            :                                        ? igc_rev_polarity_reversed
    2235                 :          0 :                                        : igc_rev_polarity_normal);
    2236                 :            : 
    2237                 :          0 :         return ret_val;
    2238                 :            : }
    2239                 :            : 
    2240                 :            : /**
    2241                 :            :  *  igc_check_polarity_igp - Checks the polarity.
    2242                 :            :  *  @hw: pointer to the HW structure
    2243                 :            :  *
    2244                 :            :  *  Success returns 0, Failure returns -IGC_ERR_PHY (-2)
    2245                 :            :  *
    2246                 :            :  *  Polarity is determined based on the PHY port status register, and the
    2247                 :            :  *  current speed (since there is no polarity at 100Mbps).
    2248                 :            :  **/
    2249                 :          0 : s32 igc_check_polarity_igp(struct igc_hw *hw)
    2250                 :            : {
    2251                 :            :         struct igc_phy_info *phy = &hw->phy;
    2252                 :            :         s32 ret_val;
    2253                 :            :         u16 data, offset, mask;
    2254                 :            : 
    2255                 :          0 :         DEBUGFUNC("igc_check_polarity_igp");
    2256                 :            : 
    2257                 :            :         /* Polarity is determined based on the speed of
    2258                 :            :          * our connection.
    2259                 :            :          */
    2260                 :          0 :         ret_val = phy->ops.read_reg(hw, IGP01IGC_PHY_PORT_STATUS, &data);
    2261         [ #  # ]:          0 :         if (ret_val)
    2262                 :            :                 return ret_val;
    2263                 :            : 
    2264         [ #  # ]:          0 :         if ((data & IGP01IGC_PSSR_SPEED_MASK) ==
    2265                 :            :             IGP01IGC_PSSR_SPEED_1000MBPS) {
    2266                 :            :                 offset = IGP01IGC_PHY_PCS_INIT_REG;
    2267                 :            :                 mask = IGP01IGC_PHY_POLARITY_MASK;
    2268                 :            :         } else {
    2269                 :            :                 /* This really only applies to 10Mbps since
    2270                 :            :                  * there is no polarity for 100Mbps (always 0).
    2271                 :            :                  */
    2272                 :            :                 offset = IGP01IGC_PHY_PORT_STATUS;
    2273                 :            :                 mask = IGP01IGC_PSSR_POLARITY_REVERSED;
    2274                 :            :         }
    2275                 :            : 
    2276                 :          0 :         ret_val = phy->ops.read_reg(hw, offset, &data);
    2277                 :            : 
    2278         [ #  # ]:          0 :         if (!ret_val)
    2279                 :          0 :                 phy->cable_polarity = ((data & mask)
    2280                 :            :                                        ? igc_rev_polarity_reversed
    2281                 :          0 :                                        : igc_rev_polarity_normal);
    2282                 :            : 
    2283                 :            :         return ret_val;
    2284                 :            : }
    2285                 :            : 
    2286                 :            : /**
    2287                 :            :  *  igc_check_polarity_ife - Check cable polarity for IFE PHY
    2288                 :            :  *  @hw: pointer to the HW structure
    2289                 :            :  *
    2290                 :            :  *  Polarity is determined on the polarity reversal feature being enabled.
    2291                 :            :  **/
    2292                 :          0 : s32 igc_check_polarity_ife(struct igc_hw *hw)
    2293                 :            : {
    2294                 :            :         struct igc_phy_info *phy = &hw->phy;
    2295                 :            :         s32 ret_val;
    2296                 :            :         u16 phy_data, offset, mask;
    2297                 :            : 
    2298                 :          0 :         DEBUGFUNC("igc_check_polarity_ife");
    2299                 :            : 
    2300                 :            :         /* Polarity is determined based on the reversal feature being enabled.
    2301                 :            :          */
    2302         [ #  # ]:          0 :         if (phy->polarity_correction) {
    2303                 :            :                 offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
    2304                 :            :                 mask = IFE_PESC_POLARITY_REVERSED;
    2305                 :            :         } else {
    2306                 :            :                 offset = IFE_PHY_SPECIAL_CONTROL;
    2307                 :            :                 mask = IFE_PSC_FORCE_POLARITY;
    2308                 :            :         }
    2309                 :            : 
    2310                 :          0 :         ret_val = phy->ops.read_reg(hw, offset, &phy_data);
    2311                 :            : 
    2312         [ #  # ]:          0 :         if (!ret_val)
    2313                 :          0 :                 phy->cable_polarity = ((phy_data & mask)
    2314                 :            :                                        ? igc_rev_polarity_reversed
    2315                 :          0 :                                        : igc_rev_polarity_normal);
    2316                 :            : 
    2317                 :          0 :         return ret_val;
    2318                 :            : }
    2319                 :            : 
    2320                 :            : /**
    2321                 :            :  *  igc_wait_autoneg - Wait for auto-neg completion
    2322                 :            :  *  @hw: pointer to the HW structure
    2323                 :            :  *
    2324                 :            :  *  Waits for auto-negotiation to complete or for the auto-negotiation time
    2325                 :            :  *  limit to expire, which ever happens first.
    2326                 :            :  **/
    2327                 :          0 : static s32 igc_wait_autoneg(struct igc_hw *hw)
    2328                 :            : {
    2329                 :            :         s32 ret_val = IGC_SUCCESS;
    2330                 :            :         u16 i, phy_status;
    2331                 :            : 
    2332                 :          0 :         DEBUGFUNC("igc_wait_autoneg");
    2333                 :            : 
    2334         [ #  # ]:          0 :         if (!hw->phy.ops.read_reg)
    2335                 :            :                 return IGC_SUCCESS;
    2336                 :            : 
    2337                 :            :         /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
    2338         [ #  # ]:          0 :         for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
    2339                 :          0 :                 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
    2340         [ #  # ]:          0 :                 if (ret_val)
    2341                 :            :                         break;
    2342                 :          0 :                 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
    2343         [ #  # ]:          0 :                 if (ret_val)
    2344                 :            :                         break;
    2345         [ #  # ]:          0 :                 if (phy_status & MII_SR_AUTONEG_COMPLETE)
    2346                 :            :                         break;
    2347                 :          0 :                 msec_delay(100);
    2348                 :            :         }
    2349                 :            : 
    2350                 :            :         /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
    2351                 :            :          * has completed.
    2352                 :            :          */
    2353                 :            :         return ret_val;
    2354                 :            : }
    2355                 :            : 
    2356                 :            : /**
    2357                 :            :  *  igc_phy_has_link_generic - Polls PHY for link
    2358                 :            :  *  @hw: pointer to the HW structure
    2359                 :            :  *  @iterations: number of times to poll for link
    2360                 :            :  *  @usec_interval: delay between polling attempts
    2361                 :            :  *  @success: pointer to whether polling was successful or not
    2362                 :            :  *
    2363                 :            :  *  Polls the PHY status register for link, 'iterations' number of times.
    2364                 :            :  **/
    2365                 :          0 : s32 igc_phy_has_link_generic(struct igc_hw *hw, u32 iterations,
    2366                 :            :                                u32 usec_interval, bool *success)
    2367                 :            : {
    2368                 :            :         s32 ret_val = IGC_SUCCESS;
    2369                 :            :         u16 i, phy_status;
    2370                 :            : 
    2371                 :          0 :         DEBUGFUNC("igc_phy_has_link_generic");
    2372                 :            : 
    2373         [ #  # ]:          0 :         if (!hw->phy.ops.read_reg)
    2374                 :            :                 return IGC_SUCCESS;
    2375                 :            : 
    2376         [ #  # ]:          0 :         for (i = 0; i < iterations; i++) {
    2377                 :            :                 /* Some PHYs require the PHY_STATUS register to be read
    2378                 :            :                  * twice due to the link bit being sticky.  No harm doing
    2379                 :            :                  * it across the board.
    2380                 :            :                  */
    2381                 :          0 :                 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
    2382         [ #  # ]:          0 :                 if (ret_val) {
    2383                 :            :                         /* If the first read fails, another entity may have
    2384                 :            :                          * ownership of the resources, wait and try again to
    2385                 :            :                          * see if they have relinquished the resources yet.
    2386                 :            :                          */
    2387         [ #  # ]:          0 :                         if (usec_interval >= 1000)
    2388                 :          0 :                                 msec_delay(usec_interval / 1000);
    2389                 :            :                         else
    2390                 :          0 :                                 usec_delay(usec_interval);
    2391                 :            :                 }
    2392                 :          0 :                 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
    2393         [ #  # ]:          0 :                 if (ret_val)
    2394                 :            :                         break;
    2395         [ #  # ]:          0 :                 if (phy_status & MII_SR_LINK_STATUS)
    2396                 :            :                         break;
    2397         [ #  # ]:          0 :                 if (usec_interval >= 1000)
    2398                 :          0 :                         msec_delay(usec_interval / 1000);
    2399                 :            :                 else
    2400                 :          0 :                         usec_delay(usec_interval);
    2401                 :            :         }
    2402                 :            : 
    2403                 :          0 :         *success = (i < iterations);
    2404                 :            : 
    2405                 :          0 :         return ret_val;
    2406                 :            : }
    2407                 :            : 
    2408                 :            : /**
    2409                 :            :  *  igc_get_cable_length_m88 - Determine cable length for m88 PHY
    2410                 :            :  *  @hw: pointer to the HW structure
    2411                 :            :  *
    2412                 :            :  *  Reads the PHY specific status register to retrieve the cable length
    2413                 :            :  *  information.  The cable length is determined by averaging the minimum and
    2414                 :            :  *  maximum values to get the "average" cable length.  The m88 PHY has four
    2415                 :            :  *  possible cable length values, which are:
    2416                 :            :  *      Register Value          Cable Length
    2417                 :            :  *      0                       < 50 meters
    2418                 :            :  *      1                       50 - 80 meters
    2419                 :            :  *      2                       80 - 110 meters
    2420                 :            :  *      3                       110 - 140 meters
    2421                 :            :  *      4                       > 140 meters
    2422                 :            :  **/
    2423                 :          0 : s32 igc_get_cable_length_m88(struct igc_hw *hw)
    2424                 :            : {
    2425                 :            :         struct igc_phy_info *phy = &hw->phy;
    2426                 :            :         s32 ret_val;
    2427                 :            :         u16 phy_data, index;
    2428                 :            : 
    2429                 :          0 :         DEBUGFUNC("igc_get_cable_length_m88");
    2430                 :            : 
    2431                 :          0 :         ret_val = phy->ops.read_reg(hw, M88IGC_PHY_SPEC_STATUS, &phy_data);
    2432         [ #  # ]:          0 :         if (ret_val)
    2433                 :            :                 return ret_val;
    2434                 :            : 
    2435                 :          0 :         index = ((phy_data & M88IGC_PSSR_CABLE_LENGTH) >>
    2436                 :            :                  M88IGC_PSSR_CABLE_LENGTH_SHIFT);
    2437                 :            : 
    2438         [ #  # ]:          0 :         if (index >= M88IGC_CABLE_LENGTH_TABLE_SIZE - 1)
    2439                 :            :                 return -IGC_ERR_PHY;
    2440                 :            : 
    2441                 :          0 :         phy->min_cable_length = igc_m88_cable_length_table[index];
    2442                 :          0 :         phy->max_cable_length = igc_m88_cable_length_table[index + 1];
    2443                 :            : 
    2444                 :          0 :         phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
    2445                 :            : 
    2446                 :          0 :         return IGC_SUCCESS;
    2447                 :            : }
    2448                 :            : 
    2449                 :          0 : s32 igc_get_cable_length_m88_gen2(struct igc_hw *hw)
    2450                 :            : {
    2451                 :            :         struct igc_phy_info *phy = &hw->phy;
    2452                 :            :         s32 ret_val  = 0;
    2453                 :            :         u16 phy_data, phy_data2, is_cm;
    2454                 :            :         u16 index, default_page;
    2455                 :            : 
    2456                 :          0 :         DEBUGFUNC("igc_get_cable_length_m88_gen2");
    2457                 :            : 
    2458   [ #  #  #  #  :          0 :         switch (hw->phy.id) {
                      # ]
    2459                 :          0 :         case I210_I_PHY_ID:
    2460                 :            :                 /* Get cable length from PHY Cable Diagnostics Control Reg */
    2461                 :          0 :                 ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
    2462                 :          0 :                                             (I347AT4_PCDL + phy->addr),
    2463                 :            :                                             &phy_data);
    2464         [ #  # ]:          0 :                 if (ret_val)
    2465                 :            :                         return ret_val;
    2466                 :            : 
    2467                 :            :                 /* Check if the unit of cable length is meters or cm */
    2468                 :          0 :                 ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
    2469                 :            :                                             I347AT4_PCDC, &phy_data2);
    2470         [ #  # ]:          0 :                 if (ret_val)
    2471                 :            :                         return ret_val;
    2472                 :            : 
    2473                 :          0 :                 is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
    2474                 :            : 
    2475                 :            :                 /* Populate the phy structure with cable length in meters */
    2476         [ #  # ]:          0 :                 phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
    2477                 :          0 :                 phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
    2478                 :          0 :                 phy->cable_length = phy_data / (is_cm ? 100 : 1);
    2479                 :          0 :                 break;
    2480                 :            :         case I225_I_PHY_ID:
    2481                 :            :                 if (ret_val)
    2482                 :            :                         return ret_val;
    2483                 :            :                 /* TODO - complete with Foxville data */
    2484                 :            :                 break;
    2485                 :          0 :         case M88E1543_E_PHY_ID:
    2486                 :            :         case M88E1512_E_PHY_ID:
    2487                 :            :         case M88E1340M_E_PHY_ID:
    2488                 :            :         case I347AT4_E_PHY_ID:
    2489                 :            :                 /* Remember the original page select and set it to 7 */
    2490                 :          0 :                 ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
    2491                 :            :                                             &default_page);
    2492         [ #  # ]:          0 :                 if (ret_val)
    2493                 :            :                         return ret_val;
    2494                 :            : 
    2495                 :          0 :                 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x07);
    2496         [ #  # ]:          0 :                 if (ret_val)
    2497                 :            :                         return ret_val;
    2498                 :            : 
    2499                 :            :                 /* Get cable length from PHY Cable Diagnostics Control Reg */
    2500                 :          0 :                 ret_val = phy->ops.read_reg(hw, (I347AT4_PCDL + phy->addr),
    2501                 :            :                                             &phy_data);
    2502         [ #  # ]:          0 :                 if (ret_val)
    2503                 :            :                         return ret_val;
    2504                 :            : 
    2505                 :            :                 /* Check if the unit of cable length is meters or cm */
    2506                 :          0 :                 ret_val = phy->ops.read_reg(hw, I347AT4_PCDC, &phy_data2);
    2507         [ #  # ]:          0 :                 if (ret_val)
    2508                 :            :                         return ret_val;
    2509                 :            : 
    2510                 :          0 :                 is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
    2511                 :            : 
    2512                 :            :                 /* Populate the phy structure with cable length in meters */
    2513         [ #  # ]:          0 :                 phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
    2514                 :          0 :                 phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
    2515                 :          0 :                 phy->cable_length = phy_data / (is_cm ? 100 : 1);
    2516                 :            : 
    2517                 :            :                 /* Reset the page select to its original value */
    2518                 :          0 :                 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
    2519                 :            :                                              default_page);
    2520         [ #  # ]:          0 :                 if (ret_val)
    2521                 :          0 :                         return ret_val;
    2522                 :            :                 break;
    2523                 :            : 
    2524                 :          0 :         case M88E1112_E_PHY_ID:
    2525                 :            :                 /* Remember the original page select and set it to 5 */
    2526                 :          0 :                 ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
    2527                 :            :                                             &default_page);
    2528         [ #  # ]:          0 :                 if (ret_val)
    2529                 :            :                         return ret_val;
    2530                 :            : 
    2531                 :          0 :                 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x05);
    2532         [ #  # ]:          0 :                 if (ret_val)
    2533                 :            :                         return ret_val;
    2534                 :            : 
    2535                 :          0 :                 ret_val = phy->ops.read_reg(hw, M88E1112_VCT_DSP_DISTANCE,
    2536                 :            :                                             &phy_data);
    2537         [ #  # ]:          0 :                 if (ret_val)
    2538                 :            :                         return ret_val;
    2539                 :            : 
    2540                 :          0 :                 index = (phy_data & M88IGC_PSSR_CABLE_LENGTH) >>
    2541                 :            :                         M88IGC_PSSR_CABLE_LENGTH_SHIFT;
    2542                 :            : 
    2543         [ #  # ]:          0 :                 if (index >= M88IGC_CABLE_LENGTH_TABLE_SIZE - 1)
    2544                 :            :                         return -IGC_ERR_PHY;
    2545                 :            : 
    2546                 :          0 :                 phy->min_cable_length = igc_m88_cable_length_table[index];
    2547                 :          0 :                 phy->max_cable_length = igc_m88_cable_length_table[index + 1];
    2548                 :            : 
    2549                 :          0 :                 phy->cable_length = (phy->min_cable_length +
    2550                 :          0 :                                      phy->max_cable_length) / 2;
    2551                 :            : 
    2552                 :            :                 /* Reset the page select to its original value */
    2553                 :          0 :                 ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
    2554                 :            :                                              default_page);
    2555         [ #  # ]:          0 :                 if (ret_val)
    2556                 :          0 :                         return ret_val;
    2557                 :            : 
    2558                 :            :                 break;
    2559                 :            :         default:
    2560                 :            :                 return -IGC_ERR_PHY;
    2561                 :            :         }
    2562                 :            : 
    2563                 :            :         return ret_val;
    2564                 :            : }
    2565                 :            : 
    2566                 :            : /**
    2567                 :            :  *  igc_get_cable_length_igp_2 - Determine cable length for igp2 PHY
    2568                 :            :  *  @hw: pointer to the HW structure
    2569                 :            :  *
    2570                 :            :  *  The automatic gain control (agc) normalizes the amplitude of the
    2571                 :            :  *  received signal, adjusting for the attenuation produced by the
    2572                 :            :  *  cable.  By reading the AGC registers, which represent the
    2573                 :            :  *  combination of coarse and fine gain value, the value can be put
    2574                 :            :  *  into a lookup table to obtain the approximate cable length
    2575                 :            :  *  for each channel.
    2576                 :            :  **/
    2577                 :          0 : s32 igc_get_cable_length_igp_2(struct igc_hw *hw)
    2578                 :            : {
    2579                 :            :         struct igc_phy_info *phy = &hw->phy;
    2580                 :            :         s32 ret_val;
    2581                 :            :         u16 phy_data, i, agc_value = 0;
    2582                 :            :         u16 cur_agc_index, max_agc_index = 0;
    2583                 :            :         u16 min_agc_index = IGP02IGC_CABLE_LENGTH_TABLE_SIZE - 1;
    2584                 :            :         static const u16 agc_reg_array[IGP02IGC_PHY_CHANNEL_NUM] = {
    2585                 :            :                 IGP02IGC_PHY_AGC_A,
    2586                 :            :                 IGP02IGC_PHY_AGC_B,
    2587                 :            :                 IGP02IGC_PHY_AGC_C,
    2588                 :            :                 IGP02IGC_PHY_AGC_D
    2589                 :            :         };
    2590                 :            : 
    2591                 :          0 :         DEBUGFUNC("igc_get_cable_length_igp_2");
    2592                 :            : 
    2593                 :            :         /* Read the AGC registers for all channels */
    2594         [ #  # ]:          0 :         for (i = 0; i < IGP02IGC_PHY_CHANNEL_NUM; i++) {
    2595                 :          0 :                 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
    2596         [ #  # ]:          0 :                 if (ret_val)
    2597                 :          0 :                         return ret_val;
    2598                 :            : 
    2599                 :            :                 /* Getting bits 15:9, which represent the combination of
    2600                 :            :                  * coarse and fine gain values.  The result is a number
    2601                 :            :                  * that can be put into the lookup table to obtain the
    2602                 :            :                  * approximate cable length.
    2603                 :            :                  */
    2604                 :          0 :                 cur_agc_index = ((phy_data >> IGP02IGC_AGC_LENGTH_SHIFT) &
    2605                 :            :                                  IGP02IGC_AGC_LENGTH_MASK);
    2606                 :            : 
    2607                 :            :                 /* Array index bound check. */
    2608         [ #  # ]:          0 :                 if (cur_agc_index >= IGP02IGC_CABLE_LENGTH_TABLE_SIZE ||
    2609                 :            :                                 cur_agc_index == 0)
    2610                 :            :                         return -IGC_ERR_PHY;
    2611                 :            : 
    2612                 :            :                 /* Remove min & max AGC values from calculation. */
    2613                 :          0 :                 if (igc_igp_2_cable_length_table[min_agc_index] >
    2614         [ #  # ]:          0 :                     igc_igp_2_cable_length_table[cur_agc_index])
    2615                 :            :                         min_agc_index = cur_agc_index;
    2616         [ #  # ]:          0 :                 if (igc_igp_2_cable_length_table[max_agc_index] <
    2617                 :            :                     igc_igp_2_cable_length_table[cur_agc_index])
    2618                 :            :                         max_agc_index = cur_agc_index;
    2619                 :            : 
    2620                 :          0 :                 agc_value += igc_igp_2_cable_length_table[cur_agc_index];
    2621                 :            :         }
    2622                 :            : 
    2623                 :          0 :         agc_value -= (igc_igp_2_cable_length_table[min_agc_index] +
    2624                 :          0 :                       igc_igp_2_cable_length_table[max_agc_index]);
    2625                 :          0 :         agc_value /= (IGP02IGC_PHY_CHANNEL_NUM - 2);
    2626                 :            : 
    2627                 :            :         /* Calculate cable length with the error range of +/- 10 meters. */
    2628                 :          0 :         phy->min_cable_length = (((agc_value - IGP02IGC_AGC_RANGE) > 0) ?
    2629                 :            :                                  (agc_value - IGP02IGC_AGC_RANGE) : 0);
    2630                 :          0 :         phy->max_cable_length = agc_value + IGP02IGC_AGC_RANGE;
    2631                 :            : 
    2632                 :          0 :         phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
    2633                 :            : 
    2634                 :          0 :         return IGC_SUCCESS;
    2635                 :            : }
    2636                 :            : 
    2637                 :            : /**
    2638                 :            :  *  igc_get_phy_info_m88 - Retrieve PHY information
    2639                 :            :  *  @hw: pointer to the HW structure
    2640                 :            :  *
    2641                 :            :  *  Valid for only copper links.  Read the PHY status register (sticky read)
    2642                 :            :  *  to verify that link is up.  Read the PHY special control register to
    2643                 :            :  *  determine the polarity and 10base-T extended distance.  Read the PHY
    2644                 :            :  *  special status register to determine MDI/MDIx and current speed.  If
    2645                 :            :  *  speed is 1000, then determine cable length, local and remote receiver.
    2646                 :            :  **/
    2647                 :          0 : s32 igc_get_phy_info_m88(struct igc_hw *hw)
    2648                 :            : {
    2649                 :            :         struct igc_phy_info *phy = &hw->phy;
    2650                 :            :         s32  ret_val;
    2651                 :            :         u16 phy_data;
    2652                 :            :         bool link;
    2653                 :            : 
    2654                 :          0 :         DEBUGFUNC("igc_get_phy_info_m88");
    2655                 :            : 
    2656         [ #  # ]:          0 :         if (phy->media_type != igc_media_type_copper) {
    2657                 :          0 :                 DEBUGOUT("Phy info is only valid for copper media\n");
    2658                 :          0 :                 return -IGC_ERR_CONFIG;
    2659                 :            :         }
    2660                 :            : 
    2661                 :          0 :         ret_val = igc_phy_has_link_generic(hw, 1, 0, &link);
    2662         [ #  # ]:          0 :         if (ret_val)
    2663                 :            :                 return ret_val;
    2664                 :            : 
    2665         [ #  # ]:          0 :         if (!link) {
    2666                 :          0 :                 DEBUGOUT("Phy info is only valid if link is up\n");
    2667                 :          0 :                 return -IGC_ERR_CONFIG;
    2668                 :            :         }
    2669                 :            : 
    2670                 :          0 :         ret_val = phy->ops.read_reg(hw, M88IGC_PHY_SPEC_CTRL, &phy_data);
    2671         [ #  # ]:          0 :         if (ret_val)
    2672                 :            :                 return ret_val;
    2673                 :            : 
    2674                 :          0 :         phy->polarity_correction = !!(phy_data &
    2675                 :            :                                       M88IGC_PSCR_POLARITY_REVERSAL);
    2676                 :            : 
    2677                 :          0 :         ret_val = igc_check_polarity_m88(hw);
    2678         [ #  # ]:          0 :         if (ret_val)
    2679                 :            :                 return ret_val;
    2680                 :            : 
    2681                 :          0 :         ret_val = phy->ops.read_reg(hw, M88IGC_PHY_SPEC_STATUS, &phy_data);
    2682         [ #  # ]:          0 :         if (ret_val)
    2683                 :            :                 return ret_val;
    2684                 :            : 
    2685                 :          0 :         phy->is_mdix = !!(phy_data & M88IGC_PSSR_MDIX);
    2686                 :            : 
    2687         [ #  # ]:          0 :         if ((phy_data & M88IGC_PSSR_SPEED) == M88IGC_PSSR_1000MBS) {
    2688                 :          0 :                 ret_val = hw->phy.ops.get_cable_length(hw);
    2689         [ #  # ]:          0 :                 if (ret_val)
    2690                 :            :                         return ret_val;
    2691                 :            : 
    2692                 :          0 :                 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
    2693         [ #  # ]:          0 :                 if (ret_val)
    2694                 :            :                         return ret_val;
    2695                 :            : 
    2696                 :          0 :                 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
    2697                 :            :                                 ? igc_1000t_rx_status_ok
    2698                 :          0 :                                 : igc_1000t_rx_status_not_ok;
    2699                 :            : 
    2700                 :          0 :                 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
    2701                 :            :                                  ? igc_1000t_rx_status_ok
    2702                 :          0 :                                  : igc_1000t_rx_status_not_ok;
    2703                 :            :         } else {
    2704                 :            :                 /* Set values to "undefined" */
    2705                 :          0 :                 phy->cable_length = IGC_CABLE_LENGTH_UNDEFINED;
    2706                 :          0 :                 phy->local_rx = igc_1000t_rx_status_undefined;
    2707                 :          0 :                 phy->remote_rx = igc_1000t_rx_status_undefined;
    2708                 :            :         }
    2709                 :            : 
    2710                 :            :         return ret_val;
    2711                 :            : }
    2712                 :            : 
    2713                 :            : /**
    2714                 :            :  *  igc_get_phy_info_igp - Retrieve igp PHY information
    2715                 :            :  *  @hw: pointer to the HW structure
    2716                 :            :  *
    2717                 :            :  *  Read PHY status to determine if link is up.  If link is up, then
    2718                 :            :  *  set/determine 10base-T extended distance and polarity correction.  Read
    2719                 :            :  *  PHY port status to determine MDI/MDIx and speed.  Based on the speed,
    2720                 :            :  *  determine on the cable length, local and remote receiver.
    2721                 :            :  **/
    2722                 :          0 : s32 igc_get_phy_info_igp(struct igc_hw *hw)
    2723                 :            : {
    2724                 :            :         struct igc_phy_info *phy = &hw->phy;
    2725                 :            :         s32 ret_val;
    2726                 :            :         u16 data;
    2727                 :            :         bool link;
    2728                 :            : 
    2729                 :          0 :         DEBUGFUNC("igc_get_phy_info_igp");
    2730                 :            : 
    2731                 :          0 :         ret_val = igc_phy_has_link_generic(hw, 1, 0, &link);
    2732         [ #  # ]:          0 :         if (ret_val)
    2733                 :            :                 return ret_val;
    2734                 :            : 
    2735         [ #  # ]:          0 :         if (!link) {
    2736                 :          0 :                 DEBUGOUT("Phy info is only valid if link is up\n");
    2737                 :          0 :                 return -IGC_ERR_CONFIG;
    2738                 :            :         }
    2739                 :            : 
    2740                 :          0 :         phy->polarity_correction = true;
    2741                 :            : 
    2742                 :          0 :         ret_val = igc_check_polarity_igp(hw);
    2743         [ #  # ]:          0 :         if (ret_val)
    2744                 :            :                 return ret_val;
    2745                 :            : 
    2746                 :          0 :         ret_val = phy->ops.read_reg(hw, IGP01IGC_PHY_PORT_STATUS, &data);
    2747         [ #  # ]:          0 :         if (ret_val)
    2748                 :            :                 return ret_val;
    2749                 :            : 
    2750                 :          0 :         phy->is_mdix = !!(data & IGP01IGC_PSSR_MDIX);
    2751                 :            : 
    2752         [ #  # ]:          0 :         if ((data & IGP01IGC_PSSR_SPEED_MASK) ==
    2753                 :            :             IGP01IGC_PSSR_SPEED_1000MBPS) {
    2754                 :          0 :                 ret_val = phy->ops.get_cable_length(hw);
    2755         [ #  # ]:          0 :                 if (ret_val)
    2756                 :            :                         return ret_val;
    2757                 :            : 
    2758                 :          0 :                 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
    2759         [ #  # ]:          0 :                 if (ret_val)
    2760                 :            :                         return ret_val;
    2761                 :            : 
    2762                 :          0 :                 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
    2763                 :            :                                 ? igc_1000t_rx_status_ok
    2764                 :          0 :                                 : igc_1000t_rx_status_not_ok;
    2765                 :            : 
    2766                 :          0 :                 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
    2767                 :            :                                  ? igc_1000t_rx_status_ok
    2768                 :          0 :                                  : igc_1000t_rx_status_not_ok;
    2769                 :            :         } else {
    2770                 :          0 :                 phy->cable_length = IGC_CABLE_LENGTH_UNDEFINED;
    2771                 :          0 :                 phy->local_rx = igc_1000t_rx_status_undefined;
    2772                 :          0 :                 phy->remote_rx = igc_1000t_rx_status_undefined;
    2773                 :            :         }
    2774                 :            : 
    2775                 :            :         return ret_val;
    2776                 :            : }
    2777                 :            : 
    2778                 :            : /**
    2779                 :            :  *  igc_get_phy_info_ife - Retrieves various IFE PHY states
    2780                 :            :  *  @hw: pointer to the HW structure
    2781                 :            :  *
    2782                 :            :  *  Populates "phy" structure with various feature states.
    2783                 :            :  **/
    2784                 :          0 : s32 igc_get_phy_info_ife(struct igc_hw *hw)
    2785                 :            : {
    2786                 :            :         struct igc_phy_info *phy = &hw->phy;
    2787                 :            :         s32 ret_val;
    2788                 :            :         u16 data;
    2789                 :            :         bool link;
    2790                 :            : 
    2791                 :          0 :         DEBUGFUNC("igc_get_phy_info_ife");
    2792                 :            : 
    2793                 :          0 :         ret_val = igc_phy_has_link_generic(hw, 1, 0, &link);
    2794         [ #  # ]:          0 :         if (ret_val)
    2795                 :            :                 return ret_val;
    2796                 :            : 
    2797         [ #  # ]:          0 :         if (!link) {
    2798                 :          0 :                 DEBUGOUT("Phy info is only valid if link is up\n");
    2799                 :          0 :                 return -IGC_ERR_CONFIG;
    2800                 :            :         }
    2801                 :            : 
    2802                 :          0 :         ret_val = phy->ops.read_reg(hw, IFE_PHY_SPECIAL_CONTROL, &data);
    2803         [ #  # ]:          0 :         if (ret_val)
    2804                 :            :                 return ret_val;
    2805                 :          0 :         phy->polarity_correction = !(data & IFE_PSC_AUTO_POLARITY_DISABLE);
    2806                 :            : 
    2807         [ #  # ]:          0 :         if (phy->polarity_correction) {
    2808                 :          0 :                 ret_val = igc_check_polarity_ife(hw);
    2809         [ #  # ]:          0 :                 if (ret_val)
    2810                 :            :                         return ret_val;
    2811                 :            :         } else {
    2812                 :            :                 /* Polarity is forced */
    2813                 :          0 :                 phy->cable_polarity = ((data & IFE_PSC_FORCE_POLARITY)
    2814                 :            :                                        ? igc_rev_polarity_reversed
    2815                 :          0 :                                        : igc_rev_polarity_normal);
    2816                 :            :         }
    2817                 :            : 
    2818                 :          0 :         ret_val = phy->ops.read_reg(hw, IFE_PHY_MDIX_CONTROL, &data);
    2819         [ #  # ]:          0 :         if (ret_val)
    2820                 :            :                 return ret_val;
    2821                 :            : 
    2822                 :          0 :         phy->is_mdix = !!(data & IFE_PMC_MDIX_STATUS);
    2823                 :            : 
    2824                 :            :         /* The following parameters are undefined for 10/100 operation. */
    2825                 :          0 :         phy->cable_length = IGC_CABLE_LENGTH_UNDEFINED;
    2826                 :          0 :         phy->local_rx = igc_1000t_rx_status_undefined;
    2827                 :          0 :         phy->remote_rx = igc_1000t_rx_status_undefined;
    2828                 :            : 
    2829                 :          0 :         return IGC_SUCCESS;
    2830                 :            : }
    2831                 :            : 
    2832                 :            : /**
    2833                 :            :  *  igc_phy_sw_reset_generic - PHY software reset
    2834                 :            :  *  @hw: pointer to the HW structure
    2835                 :            :  *
    2836                 :            :  *  Does a software reset of the PHY by reading the PHY control register and
    2837                 :            :  *  setting/write the control register reset bit to the PHY.
    2838                 :            :  **/
    2839                 :          0 : s32 igc_phy_sw_reset_generic(struct igc_hw *hw)
    2840                 :            : {
    2841                 :            :         s32 ret_val;
    2842                 :            :         u16 phy_ctrl;
    2843                 :            : 
    2844                 :          0 :         DEBUGFUNC("igc_phy_sw_reset_generic");
    2845                 :            : 
    2846         [ #  # ]:          0 :         if (!hw->phy.ops.read_reg)
    2847                 :            :                 return IGC_SUCCESS;
    2848                 :            : 
    2849                 :          0 :         ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
    2850         [ #  # ]:          0 :         if (ret_val)
    2851                 :            :                 return ret_val;
    2852                 :            : 
    2853                 :          0 :         phy_ctrl |= MII_CR_RESET;
    2854                 :          0 :         ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
    2855         [ #  # ]:          0 :         if (ret_val)
    2856                 :            :                 return ret_val;
    2857                 :            : 
    2858                 :          0 :         usec_delay(1);
    2859                 :            : 
    2860                 :          0 :         return ret_val;
    2861                 :            : }
    2862                 :            : 
    2863                 :            : /**
    2864                 :            :  *  igc_phy_hw_reset_generic - PHY hardware reset
    2865                 :            :  *  @hw: pointer to the HW structure
    2866                 :            :  *
    2867                 :            :  *  Verify the reset block is not blocking us from resetting.  Acquire
    2868                 :            :  *  semaphore (if necessary) and read/set/write the device control reset
    2869                 :            :  *  bit in the PHY.  Wait the appropriate delay time for the device to
    2870                 :            :  *  reset and release the semaphore (if necessary).
    2871                 :            :  **/
    2872                 :          0 : s32 igc_phy_hw_reset_generic(struct igc_hw *hw)
    2873                 :            : {
    2874                 :            :         struct igc_phy_info *phy = &hw->phy;
    2875                 :            :         s32 ret_val;
    2876                 :            :         u32 ctrl;
    2877                 :            : 
    2878                 :          0 :         DEBUGFUNC("igc_phy_hw_reset_generic");
    2879                 :            : 
    2880         [ #  # ]:          0 :         if (phy->ops.check_reset_block) {
    2881                 :          0 :                 ret_val = phy->ops.check_reset_block(hw);
    2882         [ #  # ]:          0 :                 if (ret_val)
    2883                 :            :                         return IGC_SUCCESS;
    2884                 :            :         }
    2885                 :            : 
    2886                 :          0 :         ret_val = phy->ops.acquire(hw);
    2887         [ #  # ]:          0 :         if (ret_val)
    2888                 :            :                 return ret_val;
    2889                 :            : 
    2890                 :          0 :         ctrl = IGC_READ_REG(hw, IGC_CTRL);
    2891                 :          0 :         IGC_WRITE_REG(hw, IGC_CTRL, ctrl | IGC_CTRL_PHY_RST);
    2892                 :          0 :         IGC_WRITE_FLUSH(hw);
    2893                 :            : 
    2894                 :          0 :         usec_delay(phy->reset_delay_us);
    2895                 :            : 
    2896                 :          0 :         IGC_WRITE_REG(hw, IGC_CTRL, ctrl);
    2897                 :          0 :         IGC_WRITE_FLUSH(hw);
    2898                 :            : 
    2899                 :          0 :         usec_delay(150);
    2900                 :            : 
    2901                 :          0 :         phy->ops.release(hw);
    2902                 :            : 
    2903                 :          0 :         return ret_val;
    2904                 :            : }
    2905                 :            : 
    2906                 :            : /**
    2907                 :            :  *  igc_get_cfg_done_generic - Generic configuration done
    2908                 :            :  *  @hw: pointer to the HW structure
    2909                 :            :  *
    2910                 :            :  *  Generic function to wait 10 milli-seconds for configuration to complete
    2911                 :            :  *  and return success.
    2912                 :            :  **/
    2913                 :          0 : s32 igc_get_cfg_done_generic(struct igc_hw IGC_UNUSEDARG * hw)
    2914                 :            : {
    2915                 :          0 :         DEBUGFUNC("igc_get_cfg_done_generic");
    2916                 :            :         UNREFERENCED_1PARAMETER(hw);
    2917                 :            : 
    2918                 :          0 :         msec_delay_irq(10);
    2919                 :            : 
    2920                 :          0 :         return IGC_SUCCESS;
    2921                 :            : }
    2922                 :            : 
    2923                 :            : /**
    2924                 :            :  *  igc_phy_init_script_igp3 - Inits the IGP3 PHY
    2925                 :            :  *  @hw: pointer to the HW structure
    2926                 :            :  *
    2927                 :            :  *  Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
    2928                 :            :  **/
    2929                 :          0 : s32 igc_phy_init_script_igp3(struct igc_hw *hw)
    2930                 :            : {
    2931                 :          0 :         DEBUGOUT("Running IGP 3 PHY init script\n");
    2932                 :            : 
    2933                 :            :         /* PHY init IGP 3 */
    2934                 :            :         /* Enable rise/fall, 10-mode work in class-A */
    2935                 :          0 :         hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
    2936                 :            :         /* Remove all caps from Replica path filter */
    2937                 :          0 :         hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
    2938                 :            :         /* Bias trimming for ADC, AFE and Driver (Default) */
    2939                 :          0 :         hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
    2940                 :            :         /* Increase Hybrid poly bias */
    2941                 :          0 :         hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
    2942                 :            :         /* Add 4% to Tx amplitude in Gig mode */
    2943                 :          0 :         hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
    2944                 :            :         /* Disable trimming (TTT) */
    2945                 :          0 :         hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
    2946                 :            :         /* Poly DC correction to 94.6% + 2% for all channels */
    2947                 :          0 :         hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
    2948                 :            :         /* ABS DC correction to 95.9% */
    2949                 :          0 :         hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
    2950                 :            :         /* BG temp curve trim */
    2951                 :          0 :         hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
    2952                 :            :         /* Increasing ADC OPAMP stage 1 currents to max */
    2953                 :          0 :         hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
    2954                 :            :         /* Force 1000 ( required for enabling PHY regs configuration) */
    2955                 :          0 :         hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
    2956                 :            :         /* Set upd_freq to 6 */
    2957                 :          0 :         hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
    2958                 :            :         /* Disable NPDFE */
    2959                 :          0 :         hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
    2960                 :            :         /* Disable adaptive fixed FFE (Default) */
    2961                 :          0 :         hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
    2962                 :            :         /* Enable FFE hysteresis */
    2963                 :          0 :         hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
    2964                 :            :         /* Fixed FFE for short cable lengths */
    2965                 :          0 :         hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
    2966                 :            :         /* Fixed FFE for medium cable lengths */
    2967                 :          0 :         hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
    2968                 :            :         /* Fixed FFE for long cable lengths */
    2969                 :          0 :         hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
    2970                 :            :         /* Enable Adaptive Clip Threshold */
    2971                 :          0 :         hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
    2972                 :            :         /* AHT reset limit to 1 */
    2973                 :          0 :         hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
    2974                 :            :         /* Set AHT master delay to 127 msec */
    2975                 :          0 :         hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
    2976                 :            :         /* Set scan bits for AHT */
    2977                 :          0 :         hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
    2978                 :            :         /* Set AHT Preset bits */
    2979                 :          0 :         hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
    2980                 :            :         /* Change integ_factor of channel A to 3 */
    2981                 :          0 :         hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
    2982                 :            :         /* Change prop_factor of channels BCD to 8 */
    2983                 :          0 :         hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
    2984                 :            :         /* Change cg_icount + enable integbp for channels BCD */
    2985                 :          0 :         hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
    2986                 :            :         /* Change cg_icount + enable integbp + change prop_factor_master
    2987                 :            :          * to 8 for channel A
    2988                 :            :          */
    2989                 :          0 :         hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
    2990                 :            :         /* Disable AHT in Slave mode on channel A */
    2991                 :          0 :         hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
    2992                 :            :         /* Enable LPLU and disable AN to 1000 in non-D0a states,
    2993                 :            :          * Enable SPD+B2B
    2994                 :            :          */
    2995                 :          0 :         hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
    2996                 :            :         /* Enable restart AN on an1000_dis change */
    2997                 :          0 :         hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
    2998                 :            :         /* Enable wh_fifo read clock in 10/100 modes */
    2999                 :          0 :         hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
    3000                 :            :         /* Restart AN, Speed selection is 1000 */
    3001                 :          0 :         hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
    3002                 :            : 
    3003                 :          0 :         return IGC_SUCCESS;
    3004                 :            : }
    3005                 :            : 
    3006                 :            : /**
    3007                 :            :  *  igc_get_phy_type_from_id - Get PHY type from id
    3008                 :            :  *  @phy_id: phy_id read from the phy
    3009                 :            :  *
    3010                 :            :  *  Returns the phy type from the id.
    3011                 :            :  **/
    3012                 :          0 : enum igc_phy_type igc_get_phy_type_from_id(u32 phy_id)
    3013                 :            : {
    3014                 :            :         enum igc_phy_type phy_type = igc_phy_unknown;
    3015                 :            : 
    3016   [ #  #  #  #  :          0 :         switch (phy_id) {
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    3017                 :            :         case M88IGC_I_PHY_ID:
    3018                 :            :         case M88IGC_E_PHY_ID:
    3019                 :            :         case M88E1111_I_PHY_ID:
    3020                 :            :         case M88E1011_I_PHY_ID:
    3021                 :            :         case M88E1543_E_PHY_ID:
    3022                 :            :         case M88E1512_E_PHY_ID:
    3023                 :            :         case I347AT4_E_PHY_ID:
    3024                 :            :         case M88E1112_E_PHY_ID:
    3025                 :            :         case M88E1340M_E_PHY_ID:
    3026                 :            :                 phy_type = igc_phy_m88;
    3027                 :            :                 break;
    3028                 :          0 :         case IGP01IGC_I_PHY_ID: /* IGP 1 & 2 share this */
    3029                 :            :                 phy_type = igc_phy_igp_2;
    3030                 :          0 :                 break;
    3031                 :          0 :         case GG82563_E_PHY_ID:
    3032                 :            :                 phy_type = igc_phy_gg82563;
    3033                 :          0 :                 break;
    3034                 :          0 :         case IGP03IGC_E_PHY_ID:
    3035                 :            :                 phy_type = igc_phy_igp_3;
    3036                 :          0 :                 break;
    3037                 :          0 :         case IFE_E_PHY_ID:
    3038                 :            :         case IFE_PLUS_E_PHY_ID:
    3039                 :            :         case IFE_C_E_PHY_ID:
    3040                 :            :                 phy_type = igc_phy_ife;
    3041                 :          0 :                 break;
    3042                 :          0 :         case BMIGC_E_PHY_ID:
    3043                 :            :         case BMIGC_E_PHY_ID_R2:
    3044                 :            :                 phy_type = igc_phy_bm;
    3045                 :          0 :                 break;
    3046                 :          0 :         case I82578_E_PHY_ID:
    3047                 :            :                 phy_type = igc_phy_82578;
    3048                 :          0 :                 break;
    3049                 :          0 :         case I82577_E_PHY_ID:
    3050                 :            :                 phy_type = igc_phy_82577;
    3051                 :          0 :                 break;
    3052                 :          0 :         case I82579_E_PHY_ID:
    3053                 :            :                 phy_type = igc_phy_82579;
    3054                 :          0 :                 break;
    3055                 :          0 :         case I217_E_PHY_ID:
    3056                 :            :                 phy_type = igc_phy_i217;
    3057                 :          0 :                 break;
    3058                 :          0 :         case I82580_I_PHY_ID:
    3059                 :            :                 phy_type = igc_phy_82580;
    3060                 :          0 :                 break;
    3061                 :          0 :         case I210_I_PHY_ID:
    3062                 :            :                 phy_type = igc_phy_i210;
    3063                 :          0 :                 break;
    3064                 :          0 :         case I225_I_PHY_ID:
    3065                 :            :                 phy_type = igc_phy_i225;
    3066                 :          0 :                 break;
    3067                 :          0 :         default:
    3068                 :            :                 phy_type = igc_phy_unknown;
    3069                 :          0 :                 break;
    3070                 :            :         }
    3071                 :          0 :         return phy_type;
    3072                 :            : }
    3073                 :            : 
    3074                 :            : /**
    3075                 :            :  *  igc_determine_phy_address - Determines PHY address.
    3076                 :            :  *  @hw: pointer to the HW structure
    3077                 :            :  *
    3078                 :            :  *  This uses a trial and error method to loop through possible PHY
    3079                 :            :  *  addresses. It tests each by reading the PHY ID registers and
    3080                 :            :  *  checking for a match.
    3081                 :            :  **/
    3082                 :          0 : s32 igc_determine_phy_address(struct igc_hw *hw)
    3083                 :            : {
    3084                 :            :         u32 phy_addr = 0;
    3085                 :            :         u32 i;
    3086                 :            :         enum igc_phy_type phy_type = igc_phy_unknown;
    3087                 :            : 
    3088                 :          0 :         hw->phy.id = phy_type;
    3089                 :            : 
    3090         [ #  # ]:          0 :         for (phy_addr = 0; phy_addr < IGC_MAX_PHY_ADDR; phy_addr++) {
    3091                 :          0 :                 hw->phy.addr = phy_addr;
    3092                 :            :                 i = 0;
    3093                 :            : 
    3094                 :            :                 do {
    3095                 :          0 :                         igc_get_phy_id(hw);
    3096                 :          0 :                         phy_type = igc_get_phy_type_from_id(hw->phy.id);
    3097                 :            : 
    3098                 :            :                         /* If phy_type is valid, break - we found our
    3099                 :            :                          * PHY address
    3100                 :            :                          */
    3101         [ #  # ]:          0 :                         if (phy_type != igc_phy_unknown)
    3102                 :            :                                 return IGC_SUCCESS;
    3103                 :            : 
    3104                 :          0 :                         msec_delay(1);
    3105                 :          0 :                         i++;
    3106         [ #  # ]:          0 :                 } while (i < 10);
    3107                 :            :         }
    3108                 :            : 
    3109                 :            :         return -IGC_ERR_PHY_TYPE;
    3110                 :            : }
    3111                 :            : 
    3112                 :            : /**
    3113                 :            :  *  igc_get_phy_addr_for_bm_page - Retrieve PHY page address
    3114                 :            :  *  @page: page to access
    3115                 :            :  *  @reg: register to access
    3116                 :            :  *
    3117                 :            :  *  Returns the phy address for the page requested.
    3118                 :            :  **/
    3119                 :            : static u32 igc_get_phy_addr_for_bm_page(u32 page, u32 reg)
    3120                 :            : {
    3121                 :            :         u32 phy_addr = 2;
    3122                 :            : 
    3123   [ #  #  #  #  :          0 :         if (page >= 768 || (page == 0 && reg == 25) || reg == 31)
          #  #  #  #  #  
                #  #  # ]
    3124                 :            :                 phy_addr = 1;
    3125                 :            : 
    3126                 :            :         return phy_addr;
    3127                 :            : }
    3128                 :            : 
    3129                 :            : /**
    3130                 :            :  *  igc_write_phy_reg_bm - Write BM PHY register
    3131                 :            :  *  @hw: pointer to the HW structure
    3132                 :            :  *  @offset: register offset to write to
    3133                 :            :  *  @data: data to write at register offset
    3134                 :            :  *
    3135                 :            :  *  Acquires semaphore, if necessary, then writes the data to PHY register
    3136                 :            :  *  at the offset.  Release any acquired semaphores before exiting.
    3137                 :            :  **/
    3138                 :          0 : s32 igc_write_phy_reg_bm(struct igc_hw *hw, u32 offset, u16 data)
    3139                 :            : {
    3140                 :            :         s32 ret_val;
    3141                 :          0 :         u32 page = offset >> IGP_PAGE_SHIFT;
    3142                 :            : 
    3143                 :          0 :         DEBUGFUNC("igc_write_phy_reg_bm");
    3144                 :            : 
    3145                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    3146         [ #  # ]:          0 :         if (ret_val)
    3147                 :            :                 return ret_val;
    3148                 :            : 
    3149                 :            :         /* Page 800 works differently than the rest so it has its own func */
    3150         [ #  # ]:          0 :         if (page == BM_WUC_PAGE) {
    3151                 :          0 :                 ret_val = igc_access_phy_wakeup_reg_bm(hw, offset, &data,
    3152                 :            :                                                          false, false);
    3153                 :          0 :                 goto release;
    3154                 :            :         }
    3155                 :            : 
    3156                 :          0 :         hw->phy.addr = igc_get_phy_addr_for_bm_page(page, offset);
    3157                 :            : 
    3158         [ #  # ]:          0 :         if (offset > MAX_PHY_MULTI_PAGE_REG) {
    3159                 :            :                 u32 page_shift, page_select;
    3160                 :            : 
    3161                 :            :                 /* Page select is register 31 for phy address 1 and 22 for
    3162                 :            :                  * phy address 2 and 3. Page select is shifted only for
    3163                 :            :                  * phy address 1.
    3164                 :            :                  */
    3165         [ #  # ]:          0 :                 if (hw->phy.addr == 1) {
    3166                 :            :                         page_shift = IGP_PAGE_SHIFT;
    3167                 :            :                         page_select = IGP01IGC_PHY_PAGE_SELECT;
    3168                 :            :                 } else {
    3169                 :            :                         page_shift = 0;
    3170                 :            :                         page_select = BM_PHY_PAGE_SELECT;
    3171                 :            :                 }
    3172                 :            : 
    3173                 :            :                 /* Page is shifted left, PHY expects (page x 32) */
    3174                 :          0 :                 ret_val = igc_write_phy_reg_mdic(hw, page_select,
    3175                 :          0 :                                                    (page << page_shift));
    3176         [ #  # ]:          0 :                 if (ret_val)
    3177                 :          0 :                         goto release;
    3178                 :            :         }
    3179                 :            : 
    3180                 :          0 :         ret_val = igc_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
    3181                 :            :                                            data);
    3182                 :            : 
    3183                 :          0 : release:
    3184                 :          0 :         hw->phy.ops.release(hw);
    3185                 :          0 :         return ret_val;
    3186                 :            : }
    3187                 :            : 
    3188                 :            : /**
    3189                 :            :  *  igc_read_phy_reg_bm - Read BM PHY register
    3190                 :            :  *  @hw: pointer to the HW structure
    3191                 :            :  *  @offset: register offset to be read
    3192                 :            :  *  @data: pointer to the read data
    3193                 :            :  *
    3194                 :            :  *  Acquires semaphore, if necessary, then reads the PHY register at offset
    3195                 :            :  *  and storing the retrieved information in data.  Release any acquired
    3196                 :            :  *  semaphores before exiting.
    3197                 :            :  **/
    3198                 :          0 : s32 igc_read_phy_reg_bm(struct igc_hw *hw, u32 offset, u16 *data)
    3199                 :            : {
    3200                 :            :         s32 ret_val;
    3201                 :          0 :         u32 page = offset >> IGP_PAGE_SHIFT;
    3202                 :            : 
    3203                 :          0 :         DEBUGFUNC("igc_read_phy_reg_bm");
    3204                 :            : 
    3205                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    3206         [ #  # ]:          0 :         if (ret_val)
    3207                 :            :                 return ret_val;
    3208                 :            : 
    3209                 :            :         /* Page 800 works differently than the rest so it has its own func */
    3210         [ #  # ]:          0 :         if (page == BM_WUC_PAGE) {
    3211                 :          0 :                 ret_val = igc_access_phy_wakeup_reg_bm(hw, offset, data,
    3212                 :            :                                                          true, false);
    3213                 :          0 :                 goto release;
    3214                 :            :         }
    3215                 :            : 
    3216                 :          0 :         hw->phy.addr = igc_get_phy_addr_for_bm_page(page, offset);
    3217                 :            : 
    3218         [ #  # ]:          0 :         if (offset > MAX_PHY_MULTI_PAGE_REG) {
    3219                 :            :                 u32 page_shift, page_select;
    3220                 :            : 
    3221                 :            :                 /* Page select is register 31 for phy address 1 and 22 for
    3222                 :            :                  * phy address 2 and 3. Page select is shifted only for
    3223                 :            :                  * phy address 1.
    3224                 :            :                  */
    3225         [ #  # ]:          0 :                 if (hw->phy.addr == 1) {
    3226                 :            :                         page_shift = IGP_PAGE_SHIFT;
    3227                 :            :                         page_select = IGP01IGC_PHY_PAGE_SELECT;
    3228                 :            :                 } else {
    3229                 :            :                         page_shift = 0;
    3230                 :            :                         page_select = BM_PHY_PAGE_SELECT;
    3231                 :            :                 }
    3232                 :            : 
    3233                 :            :                 /* Page is shifted left, PHY expects (page x 32) */
    3234                 :          0 :                 ret_val = igc_write_phy_reg_mdic(hw, page_select,
    3235                 :          0 :                                                    (page << page_shift));
    3236         [ #  # ]:          0 :                 if (ret_val)
    3237                 :          0 :                         goto release;
    3238                 :            :         }
    3239                 :            : 
    3240                 :          0 :         ret_val = igc_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
    3241                 :            :                                           data);
    3242                 :          0 : release:
    3243                 :          0 :         hw->phy.ops.release(hw);
    3244                 :          0 :         return ret_val;
    3245                 :            : }
    3246                 :            : 
    3247                 :            : /**
    3248                 :            :  *  igc_read_phy_reg_bm2 - Read BM PHY register
    3249                 :            :  *  @hw: pointer to the HW structure
    3250                 :            :  *  @offset: register offset to be read
    3251                 :            :  *  @data: pointer to the read data
    3252                 :            :  *
    3253                 :            :  *  Acquires semaphore, if necessary, then reads the PHY register at offset
    3254                 :            :  *  and storing the retrieved information in data.  Release any acquired
    3255                 :            :  *  semaphores before exiting.
    3256                 :            :  **/
    3257                 :          0 : s32 igc_read_phy_reg_bm2(struct igc_hw *hw, u32 offset, u16 *data)
    3258                 :            : {
    3259                 :            :         s32 ret_val;
    3260                 :          0 :         u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
    3261                 :            : 
    3262                 :          0 :         DEBUGFUNC("igc_read_phy_reg_bm2");
    3263                 :            : 
    3264                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    3265         [ #  # ]:          0 :         if (ret_val)
    3266                 :            :                 return ret_val;
    3267                 :            : 
    3268                 :            :         /* Page 800 works differently than the rest so it has its own func */
    3269         [ #  # ]:          0 :         if (page == BM_WUC_PAGE) {
    3270                 :          0 :                 ret_val = igc_access_phy_wakeup_reg_bm(hw, offset, data,
    3271                 :            :                                                          true, false);
    3272                 :          0 :                 goto release;
    3273                 :            :         }
    3274                 :            : 
    3275                 :          0 :         hw->phy.addr = 1;
    3276                 :            : 
    3277         [ #  # ]:          0 :         if (offset > MAX_PHY_MULTI_PAGE_REG) {
    3278                 :            :                 /* Page is shifted left, PHY expects (page x 32) */
    3279                 :          0 :                 ret_val = igc_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
    3280                 :            :                                                    page);
    3281                 :            : 
    3282         [ #  # ]:          0 :                 if (ret_val)
    3283                 :          0 :                         goto release;
    3284                 :            :         }
    3285                 :            : 
    3286                 :          0 :         ret_val = igc_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
    3287                 :            :                                           data);
    3288                 :          0 : release:
    3289                 :          0 :         hw->phy.ops.release(hw);
    3290                 :          0 :         return ret_val;
    3291                 :            : }
    3292                 :            : 
    3293                 :            : /**
    3294                 :            :  *  igc_write_phy_reg_bm2 - Write BM PHY register
    3295                 :            :  *  @hw: pointer to the HW structure
    3296                 :            :  *  @offset: register offset to write to
    3297                 :            :  *  @data: data to write at register offset
    3298                 :            :  *
    3299                 :            :  *  Acquires semaphore, if necessary, then writes the data to PHY register
    3300                 :            :  *  at the offset.  Release any acquired semaphores before exiting.
    3301                 :            :  **/
    3302                 :          0 : s32 igc_write_phy_reg_bm2(struct igc_hw *hw, u32 offset, u16 data)
    3303                 :            : {
    3304                 :            :         s32 ret_val;
    3305                 :          0 :         u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
    3306                 :            : 
    3307                 :          0 :         DEBUGFUNC("igc_write_phy_reg_bm2");
    3308                 :            : 
    3309                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    3310         [ #  # ]:          0 :         if (ret_val)
    3311                 :            :                 return ret_val;
    3312                 :            : 
    3313                 :            :         /* Page 800 works differently than the rest so it has its own func */
    3314         [ #  # ]:          0 :         if (page == BM_WUC_PAGE) {
    3315                 :          0 :                 ret_val = igc_access_phy_wakeup_reg_bm(hw, offset, &data,
    3316                 :            :                                                          false, false);
    3317                 :          0 :                 goto release;
    3318                 :            :         }
    3319                 :            : 
    3320                 :          0 :         hw->phy.addr = 1;
    3321                 :            : 
    3322         [ #  # ]:          0 :         if (offset > MAX_PHY_MULTI_PAGE_REG) {
    3323                 :            :                 /* Page is shifted left, PHY expects (page x 32) */
    3324                 :          0 :                 ret_val = igc_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
    3325                 :            :                                                    page);
    3326                 :            : 
    3327         [ #  # ]:          0 :                 if (ret_val)
    3328                 :          0 :                         goto release;
    3329                 :            :         }
    3330                 :            : 
    3331                 :          0 :         ret_val = igc_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
    3332                 :            :                                            data);
    3333                 :            : 
    3334                 :          0 : release:
    3335                 :          0 :         hw->phy.ops.release(hw);
    3336                 :          0 :         return ret_val;
    3337                 :            : }
    3338                 :            : 
    3339                 :            : /**
    3340                 :            :  *  igc_enable_phy_wakeup_reg_access_bm - enable access to BM wakeup registers
    3341                 :            :  *  @hw: pointer to the HW structure
    3342                 :            :  *  @phy_reg: pointer to store original contents of BM_WUC_ENABLE_REG
    3343                 :            :  *
    3344                 :            :  *  Assumes semaphore already acquired and phy_reg points to a valid memory
    3345                 :            :  *  address to store contents of the BM_WUC_ENABLE_REG register.
    3346                 :            :  **/
    3347                 :          0 : s32 igc_enable_phy_wakeup_reg_access_bm(struct igc_hw *hw, u16 *phy_reg)
    3348                 :            : {
    3349                 :            :         s32 ret_val;
    3350                 :            :         u16 temp;
    3351                 :            : 
    3352                 :          0 :         DEBUGFUNC("igc_enable_phy_wakeup_reg_access_bm");
    3353                 :            : 
    3354         [ #  # ]:          0 :         if (!phy_reg)
    3355                 :            :                 return -IGC_ERR_PARAM;
    3356                 :            : 
    3357                 :            :         /* All page select, port ctrl and wakeup registers use phy address 1 */
    3358                 :          0 :         hw->phy.addr = 1;
    3359                 :            : 
    3360                 :            :         /* Select Port Control Registers page */
    3361                 :          0 :         ret_val = igc_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
    3362         [ #  # ]:          0 :         if (ret_val) {
    3363                 :          0 :                 DEBUGOUT("Could not set Port Control page\n");
    3364                 :          0 :                 return ret_val;
    3365                 :            :         }
    3366                 :            : 
    3367                 :          0 :         ret_val = igc_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
    3368         [ #  # ]:          0 :         if (ret_val) {
    3369                 :          0 :                 DEBUGOUT2("Could not read PHY register %d.%d\n",
    3370                 :            :                           BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
    3371                 :          0 :                 return ret_val;
    3372                 :            :         }
    3373                 :            : 
    3374                 :            :         /* Enable both PHY wakeup mode and Wakeup register page writes.
    3375                 :            :          * Prevent a power state change by disabling ME and Host PHY wakeup.
    3376                 :            :          */
    3377                 :          0 :         temp = *phy_reg;
    3378                 :            :         temp |= BM_WUC_ENABLE_BIT;
    3379                 :          0 :         temp &= ~(BM_WUC_ME_WU_BIT | BM_WUC_HOST_WU_BIT);
    3380                 :            : 
    3381                 :          0 :         ret_val = igc_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, temp);
    3382         [ #  # ]:          0 :         if (ret_val) {
    3383                 :          0 :                 DEBUGOUT2("Could not write PHY register %d.%d\n",
    3384                 :            :                           BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
    3385                 :          0 :                 return ret_val;
    3386                 :            :         }
    3387                 :            : 
    3388                 :            :         /* Select Host Wakeup Registers page - caller now able to write
    3389                 :            :          * registers on the Wakeup registers page
    3390                 :            :          */
    3391                 :          0 :         return igc_set_page_igp(hw, (BM_WUC_PAGE << IGP_PAGE_SHIFT));
    3392                 :            : }
    3393                 :            : 
    3394                 :            : /**
    3395                 :            :  *  igc_disable_phy_wakeup_reg_access_bm - disable access to BM wakeup regs
    3396                 :            :  *  @hw: pointer to the HW structure
    3397                 :            :  *  @phy_reg: pointer to original contents of BM_WUC_ENABLE_REG
    3398                 :            :  *
    3399                 :            :  *  Restore BM_WUC_ENABLE_REG to its original value.
    3400                 :            :  *
    3401                 :            :  *  Assumes semaphore already acquired and *phy_reg is the contents of the
    3402                 :            :  *  BM_WUC_ENABLE_REG before register(s) on BM_WUC_PAGE were accessed by
    3403                 :            :  *  caller.
    3404                 :            :  **/
    3405                 :          0 : s32 igc_disable_phy_wakeup_reg_access_bm(struct igc_hw *hw, u16 *phy_reg)
    3406                 :            : {
    3407                 :            :         s32 ret_val;
    3408                 :            : 
    3409                 :          0 :         DEBUGFUNC("igc_disable_phy_wakeup_reg_access_bm");
    3410                 :            : 
    3411         [ #  # ]:          0 :         if (!phy_reg)
    3412                 :            :                 return -IGC_ERR_PARAM;
    3413                 :            : 
    3414                 :            :         /* Select Port Control Registers page */
    3415                 :          0 :         ret_val = igc_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
    3416         [ #  # ]:          0 :         if (ret_val) {
    3417                 :          0 :                 DEBUGOUT("Could not set Port Control page\n");
    3418                 :          0 :                 return ret_val;
    3419                 :            :         }
    3420                 :            : 
    3421                 :            :         /* Restore 769.17 to its original value */
    3422                 :          0 :         ret_val = igc_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, *phy_reg);
    3423         [ #  # ]:          0 :         if (ret_val)
    3424                 :          0 :                 DEBUGOUT2("Could not restore PHY register %d.%d\n",
    3425                 :            :                           BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
    3426                 :            : 
    3427                 :            :         return ret_val;
    3428                 :            : }
    3429                 :            : 
    3430                 :            : /**
    3431                 :            :  *  igc_access_phy_wakeup_reg_bm - Read/write BM PHY wakeup register
    3432                 :            :  *  @hw: pointer to the HW structure
    3433                 :            :  *  @offset: register offset to be read or written
    3434                 :            :  *  @data: pointer to the data to read or write
    3435                 :            :  *  @read: determines if operation is read or write
    3436                 :            :  *  @page_set: BM_WUC_PAGE already set and access enabled
    3437                 :            :  *
    3438                 :            :  *  Read the PHY register at offset and store the retrieved information in
    3439                 :            :  *  data, or write data to PHY register at offset.  Note the procedure to
    3440                 :            :  *  access the PHY wakeup registers is different than reading the other PHY
    3441                 :            :  *  registers. It works as such:
    3442                 :            :  *  1) Set 769.17.2 (page 769, register 17, bit 2) = 1
    3443                 :            :  *  2) Set page to 800 for host (801 if we were manageability)
    3444                 :            :  *  3) Write the address using the address opcode (0x11)
    3445                 :            :  *  4) Read or write the data using the data opcode (0x12)
    3446                 :            :  *  5) Restore 769.17.2 to its original value
    3447                 :            :  *
    3448                 :            :  *  Steps 1 and 2 are done by igc_enable_phy_wakeup_reg_access_bm() and
    3449                 :            :  *  step 5 is done by igc_disable_phy_wakeup_reg_access_bm().
    3450                 :            :  *
    3451                 :            :  *  Assumes semaphore is already acquired.  When page_set==true, assumes
    3452                 :            :  *  the PHY page is set to BM_WUC_PAGE (i.e. a function in the call stack
    3453                 :            :  *  is responsible for calls to igc_[enable|disable]_phy_wakeup_reg_bm()).
    3454                 :            :  **/
    3455                 :          0 : static s32 igc_access_phy_wakeup_reg_bm(struct igc_hw *hw, u32 offset,
    3456                 :            :                                           u16 *data, bool read, bool page_set)
    3457                 :            : {
    3458                 :            :         s32 ret_val;
    3459                 :          0 :         u16 reg = BM_PHY_REG_NUM(offset);
    3460                 :          0 :         u16 page = BM_PHY_REG_PAGE(offset);
    3461                 :          0 :         u16 phy_reg = 0;
    3462                 :            : 
    3463                 :          0 :         DEBUGFUNC("igc_access_phy_wakeup_reg_bm");
    3464                 :            : 
    3465                 :            :         /* Gig must be disabled for MDIO accesses to Host Wakeup reg page */
    3466         [ #  # ]:          0 :         if (hw->mac.type == igc_pchlan &&
    3467         [ #  # ]:          0 :                 !(IGC_READ_REG(hw, IGC_PHY_CTRL) & IGC_PHY_CTRL_GBE_DISABLE))
    3468                 :          0 :                 DEBUGOUT1("Attempting to access page %d while gig enabled.\n",
    3469                 :            :                           page);
    3470                 :            : 
    3471         [ #  # ]:          0 :         if (!page_set) {
    3472                 :            :                 /* Enable access to PHY wakeup registers */
    3473                 :          0 :                 ret_val = igc_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
    3474         [ #  # ]:          0 :                 if (ret_val) {
    3475                 :          0 :                         DEBUGOUT("Could not enable PHY wakeup reg access\n");
    3476                 :          0 :                         return ret_val;
    3477                 :            :                 }
    3478                 :            :         }
    3479                 :            : 
    3480                 :          0 :         DEBUGOUT2("Accessing PHY page %d reg 0x%x\n", page, reg);
    3481                 :            : 
    3482                 :            :         /* Write the Wakeup register page offset value using opcode 0x11 */
    3483                 :          0 :         ret_val = igc_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
    3484         [ #  # ]:          0 :         if (ret_val) {
    3485                 :          0 :                 DEBUGOUT1("Could not write address opcode to page %d\n", page);
    3486                 :          0 :                 return ret_val;
    3487                 :            :         }
    3488                 :            : 
    3489         [ #  # ]:          0 :         if (read) {
    3490                 :            :                 /* Read the Wakeup register page value using opcode 0x12 */
    3491                 :          0 :                 ret_val = igc_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
    3492                 :            :                                                   data);
    3493                 :            :         } else {
    3494                 :            :                 /* Write the Wakeup register page value using opcode 0x12 */
    3495                 :          0 :                 ret_val = igc_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
    3496                 :          0 :                                                    *data);
    3497                 :            :         }
    3498                 :            : 
    3499         [ #  # ]:          0 :         if (ret_val) {
    3500                 :          0 :                 DEBUGOUT2("Could not access PHY reg %d.%d\n", page, reg);
    3501                 :          0 :                 return ret_val;
    3502                 :            :         }
    3503                 :            : 
    3504         [ #  # ]:          0 :         if (!page_set)
    3505                 :          0 :                 ret_val = igc_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
    3506                 :            : 
    3507                 :            :         return ret_val;
    3508                 :            : }
    3509                 :            : 
    3510                 :            : /**
    3511                 :            :  * igc_power_up_phy_copper - Restore copper link in case of PHY power down
    3512                 :            :  * @hw: pointer to the HW structure
    3513                 :            :  *
    3514                 :            :  * In the case of a PHY power down to save power, or to turn off link during a
    3515                 :            :  * driver unload, or wake on lan is not enabled, restore the link to previous
    3516                 :            :  * settings.
    3517                 :            :  **/
    3518                 :          0 : void igc_power_up_phy_copper(struct igc_hw *hw)
    3519                 :            : {
    3520                 :          0 :         u16 mii_reg = 0;
    3521                 :            : 
    3522                 :            :         /* The PHY will retain its settings across a power down/up cycle */
    3523                 :          0 :         hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
    3524                 :          0 :         mii_reg &= ~MII_CR_POWER_DOWN;
    3525                 :          0 :         hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
    3526                 :          0 : }
    3527                 :            : 
    3528                 :            : /**
    3529                 :            :  * igc_power_down_phy_copper - Restore copper link in case of PHY power down
    3530                 :            :  * @hw: pointer to the HW structure
    3531                 :            :  *
    3532                 :            :  * In the case of a PHY power down to save power, or to turn off link during a
    3533                 :            :  * driver unload, or wake on lan is not enabled, restore the link to previous
    3534                 :            :  * settings.
    3535                 :            :  **/
    3536                 :          0 : void igc_power_down_phy_copper(struct igc_hw *hw)
    3537                 :            : {
    3538                 :          0 :         u16 mii_reg = 0;
    3539                 :            : 
    3540                 :            :         /* The PHY will retain its settings across a power down/up cycle */
    3541                 :          0 :         hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
    3542                 :          0 :         mii_reg |= MII_CR_POWER_DOWN;
    3543                 :          0 :         hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
    3544                 :          0 :         msec_delay(1);
    3545                 :          0 : }
    3546                 :            : 
    3547                 :            : /**
    3548                 :            :  *  __igc_read_phy_reg_hv -  Read HV PHY register
    3549                 :            :  *  @hw: pointer to the HW structure
    3550                 :            :  *  @offset: register offset to be read
    3551                 :            :  *  @data: pointer to the read data
    3552                 :            :  *  @locked: semaphore has already been acquired or not
    3553                 :            :  *  @page_set: BM_WUC_PAGE already set and access enabled
    3554                 :            :  *
    3555                 :            :  *  Acquires semaphore, if necessary, then reads the PHY register at offset
    3556                 :            :  *  and stores the retrieved information in data.  Release any acquired
    3557                 :            :  *  semaphore before exiting.
    3558                 :            :  **/
    3559                 :          0 : static s32 __igc_read_phy_reg_hv(struct igc_hw *hw, u32 offset, u16 *data,
    3560                 :            :                                    bool locked, bool page_set)
    3561                 :            : {
    3562                 :            :         s32 ret_val;
    3563                 :          0 :         u16 page = BM_PHY_REG_PAGE(offset);
    3564                 :          0 :         u16 reg = BM_PHY_REG_NUM(offset);
    3565                 :          0 :         u32 phy_addr = hw->phy.addr = igc_get_phy_addr_for_hv_page(page);
    3566                 :            : 
    3567                 :          0 :         DEBUGFUNC("__igc_read_phy_reg_hv");
    3568                 :            : 
    3569         [ #  # ]:          0 :         if (!locked) {
    3570                 :          0 :                 ret_val = hw->phy.ops.acquire(hw);
    3571         [ #  # ]:          0 :                 if (ret_val)
    3572                 :            :                         return ret_val;
    3573                 :            :         }
    3574                 :            :         /* Page 800 works differently than the rest so it has its own func */
    3575         [ #  # ]:          0 :         if (page == BM_WUC_PAGE) {
    3576                 :          0 :                 ret_val = igc_access_phy_wakeup_reg_bm(hw, offset, data,
    3577                 :            :                                                          true, page_set);
    3578                 :          0 :                 goto out;
    3579                 :            :         }
    3580                 :            : 
    3581         [ #  # ]:          0 :         if (page > 0 && page < HV_INTC_FC_PAGE_START) {
    3582                 :          0 :                 ret_val = igc_access_phy_debug_regs_hv(hw, offset,
    3583                 :            :                                                          data, true);
    3584                 :          0 :                 goto out;
    3585                 :            :         }
    3586                 :            : 
    3587         [ #  # ]:          0 :         if (!page_set) {
    3588         [ #  # ]:          0 :                 if (page == HV_INTC_FC_PAGE_START)
    3589                 :            :                         page = 0;
    3590                 :            : 
    3591         [ #  # ]:          0 :                 if (reg > MAX_PHY_MULTI_PAGE_REG) {
    3592                 :            :                         /* Page is shifted left, PHY expects (page x 32) */
    3593                 :          0 :                         ret_val = igc_set_page_igp(hw,
    3594                 :          0 :                                                      (page << IGP_PAGE_SHIFT));
    3595                 :            : 
    3596                 :          0 :                         hw->phy.addr = phy_addr;
    3597                 :            : 
    3598         [ #  # ]:          0 :                         if (ret_val)
    3599                 :          0 :                                 goto out;
    3600                 :            :                 }
    3601                 :            :         }
    3602                 :            : 
    3603                 :          0 :         DEBUGOUT3("reading PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
    3604                 :            :                   page << IGP_PAGE_SHIFT, reg);
    3605                 :            : 
    3606                 :          0 :         ret_val = igc_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
    3607                 :            :                                           data);
    3608                 :          0 : out:
    3609         [ #  # ]:          0 :         if (!locked)
    3610                 :          0 :                 hw->phy.ops.release(hw);
    3611                 :            : 
    3612                 :            :         return ret_val;
    3613                 :            : }
    3614                 :            : 
    3615                 :            : /**
    3616                 :            :  *  igc_read_phy_reg_hv -  Read HV PHY register
    3617                 :            :  *  @hw: pointer to the HW structure
    3618                 :            :  *  @offset: register offset to be read
    3619                 :            :  *  @data: pointer to the read data
    3620                 :            :  *
    3621                 :            :  *  Acquires semaphore then reads the PHY register at offset and stores
    3622                 :            :  *  the retrieved information in data.  Release the acquired semaphore
    3623                 :            :  *  before exiting.
    3624                 :            :  **/
    3625                 :          0 : s32 igc_read_phy_reg_hv(struct igc_hw *hw, u32 offset, u16 *data)
    3626                 :            : {
    3627                 :          0 :         return __igc_read_phy_reg_hv(hw, offset, data, false, false);
    3628                 :            : }
    3629                 :            : 
    3630                 :            : /**
    3631                 :            :  *  igc_read_phy_reg_hv_locked -  Read HV PHY register
    3632                 :            :  *  @hw: pointer to the HW structure
    3633                 :            :  *  @offset: register offset to be read
    3634                 :            :  *  @data: pointer to the read data
    3635                 :            :  *
    3636                 :            :  *  Reads the PHY register at offset and stores the retrieved information
    3637                 :            :  *  in data.  Assumes semaphore already acquired.
    3638                 :            :  **/
    3639                 :          0 : s32 igc_read_phy_reg_hv_locked(struct igc_hw *hw, u32 offset, u16 *data)
    3640                 :            : {
    3641                 :          0 :         return __igc_read_phy_reg_hv(hw, offset, data, true, false);
    3642                 :            : }
    3643                 :            : 
    3644                 :            : /**
    3645                 :            :  *  igc_read_phy_reg_page_hv - Read HV PHY register
    3646                 :            :  *  @hw: pointer to the HW structure
    3647                 :            :  *  @offset: register offset to write to
    3648                 :            :  *  @data: data to write at register offset
    3649                 :            :  *
    3650                 :            :  *  Reads the PHY register at offset and stores the retrieved information
    3651                 :            :  *  in data.  Assumes semaphore already acquired and page already set.
    3652                 :            :  **/
    3653                 :          0 : s32 igc_read_phy_reg_page_hv(struct igc_hw *hw, u32 offset, u16 *data)
    3654                 :            : {
    3655                 :          0 :         return __igc_read_phy_reg_hv(hw, offset, data, true, true);
    3656                 :            : }
    3657                 :            : 
    3658                 :            : /**
    3659                 :            :  *  __igc_write_phy_reg_hv - Write HV PHY register
    3660                 :            :  *  @hw: pointer to the HW structure
    3661                 :            :  *  @offset: register offset to write to
    3662                 :            :  *  @data: data to write at register offset
    3663                 :            :  *  @locked: semaphore has already been acquired or not
    3664                 :            :  *  @page_set: BM_WUC_PAGE already set and access enabled
    3665                 :            :  *
    3666                 :            :  *  Acquires semaphore, if necessary, then writes the data to PHY register
    3667                 :            :  *  at the offset.  Release any acquired semaphores before exiting.
    3668                 :            :  **/
    3669                 :          0 : static s32 __igc_write_phy_reg_hv(struct igc_hw *hw, u32 offset, u16 data,
    3670                 :            :                                     bool locked, bool page_set)
    3671                 :            : {
    3672                 :            :         s32 ret_val;
    3673                 :          0 :         u16 page = BM_PHY_REG_PAGE(offset);
    3674                 :          0 :         u16 reg = BM_PHY_REG_NUM(offset);
    3675                 :          0 :         u32 phy_addr = hw->phy.addr = igc_get_phy_addr_for_hv_page(page);
    3676                 :            : 
    3677                 :          0 :         DEBUGFUNC("__igc_write_phy_reg_hv");
    3678                 :            : 
    3679         [ #  # ]:          0 :         if (!locked) {
    3680                 :          0 :                 ret_val = hw->phy.ops.acquire(hw);
    3681         [ #  # ]:          0 :                 if (ret_val)
    3682                 :            :                         return ret_val;
    3683                 :            :         }
    3684                 :            :         /* Page 800 works differently than the rest so it has its own func */
    3685         [ #  # ]:          0 :         if (page == BM_WUC_PAGE) {
    3686                 :          0 :                 ret_val = igc_access_phy_wakeup_reg_bm(hw, offset, &data,
    3687                 :            :                                                          false, page_set);
    3688                 :          0 :                 goto out;
    3689                 :            :         }
    3690                 :            : 
    3691         [ #  # ]:          0 :         if (page > 0 && page < HV_INTC_FC_PAGE_START) {
    3692                 :          0 :                 ret_val = igc_access_phy_debug_regs_hv(hw, offset,
    3693                 :            :                                                          &data, false);
    3694                 :          0 :                 goto out;
    3695                 :            :         }
    3696                 :            : 
    3697         [ #  # ]:          0 :         if (!page_set) {
    3698         [ #  # ]:          0 :                 if (page == HV_INTC_FC_PAGE_START)
    3699                 :            :                         page = 0;
    3700                 :            : 
    3701                 :            :                 /*
    3702                 :            :                  * Workaround MDIO accesses being disabled after entering IEEE
    3703                 :            :                  * Power Down (when bit 11 of the PHY Control register is set)
    3704                 :            :                  */
    3705         [ #  # ]:          0 :                 if (hw->phy.type == igc_phy_82578 &&
    3706         [ #  # ]:          0 :                                 hw->phy.revision >= 1 &&
    3707         [ #  # ]:          0 :                                 hw->phy.addr == 2 &&
    3708         [ #  # ]:          0 :                                 !(MAX_PHY_REG_ADDRESS & reg) &&
    3709         [ #  # ]:          0 :                                 (data & (1 << 11))) {
    3710                 :          0 :                         u16 data2 = 0x7EFF;
    3711                 :          0 :                         ret_val = igc_access_phy_debug_regs_hv(hw,
    3712                 :            :                                                                 (1 << 6) | 0x3,
    3713                 :            :                                                                 &data2, false);
    3714         [ #  # ]:          0 :                         if (ret_val)
    3715                 :          0 :                                 goto out;
    3716                 :            :                 }
    3717                 :            : 
    3718         [ #  # ]:          0 :                 if (reg > MAX_PHY_MULTI_PAGE_REG) {
    3719                 :            :                         /* Page is shifted left, PHY expects (page x 32) */
    3720                 :          0 :                         ret_val = igc_set_page_igp(hw,
    3721                 :          0 :                                                      (page << IGP_PAGE_SHIFT));
    3722                 :            : 
    3723                 :          0 :                         hw->phy.addr = phy_addr;
    3724                 :            : 
    3725         [ #  # ]:          0 :                         if (ret_val)
    3726                 :          0 :                                 goto out;
    3727                 :            :                 }
    3728                 :            :         }
    3729                 :            : 
    3730                 :          0 :         DEBUGOUT3("writing PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
    3731                 :            :                   page << IGP_PAGE_SHIFT, reg);
    3732                 :            : 
    3733                 :          0 :         ret_val = igc_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
    3734                 :            :                                            data);
    3735                 :            : 
    3736                 :          0 : out:
    3737         [ #  # ]:          0 :         if (!locked)
    3738                 :          0 :                 hw->phy.ops.release(hw);
    3739                 :            : 
    3740                 :            :         return ret_val;
    3741                 :            : }
    3742                 :            : 
    3743                 :            : /**
    3744                 :            :  *  igc_write_phy_reg_hv - Write HV PHY register
    3745                 :            :  *  @hw: pointer to the HW structure
    3746                 :            :  *  @offset: register offset to write to
    3747                 :            :  *  @data: data to write at register offset
    3748                 :            :  *
    3749                 :            :  *  Acquires semaphore then writes the data to PHY register at the offset.
    3750                 :            :  *  Release the acquired semaphores before exiting.
    3751                 :            :  **/
    3752                 :          0 : s32 igc_write_phy_reg_hv(struct igc_hw *hw, u32 offset, u16 data)
    3753                 :            : {
    3754                 :          0 :         return __igc_write_phy_reg_hv(hw, offset, data, false, false);
    3755                 :            : }
    3756                 :            : 
    3757                 :            : /**
    3758                 :            :  *  igc_write_phy_reg_hv_locked - Write HV PHY register
    3759                 :            :  *  @hw: pointer to the HW structure
    3760                 :            :  *  @offset: register offset to write to
    3761                 :            :  *  @data: data to write at register offset
    3762                 :            :  *
    3763                 :            :  *  Writes the data to PHY register at the offset.  Assumes semaphore
    3764                 :            :  *  already acquired.
    3765                 :            :  **/
    3766                 :          0 : s32 igc_write_phy_reg_hv_locked(struct igc_hw *hw, u32 offset, u16 data)
    3767                 :            : {
    3768                 :          0 :         return __igc_write_phy_reg_hv(hw, offset, data, true, false);
    3769                 :            : }
    3770                 :            : 
    3771                 :            : /**
    3772                 :            :  *  igc_write_phy_reg_page_hv - Write HV PHY register
    3773                 :            :  *  @hw: pointer to the HW structure
    3774                 :            :  *  @offset: register offset to write to
    3775                 :            :  *  @data: data to write at register offset
    3776                 :            :  *
    3777                 :            :  *  Writes the data to PHY register at the offset.  Assumes semaphore
    3778                 :            :  *  already acquired and page already set.
    3779                 :            :  **/
    3780                 :          0 : s32 igc_write_phy_reg_page_hv(struct igc_hw *hw, u32 offset, u16 data)
    3781                 :            : {
    3782                 :          0 :         return __igc_write_phy_reg_hv(hw, offset, data, true, true);
    3783                 :            : }
    3784                 :            : 
    3785                 :            : /**
    3786                 :            :  *  igc_get_phy_addr_for_hv_page - Get PHY address based on page
    3787                 :            :  *  @page: page to be accessed
    3788                 :            :  **/
    3789                 :            : static u32 igc_get_phy_addr_for_hv_page(u32 page)
    3790                 :            : {
    3791                 :            :         u32 phy_addr = 2;
    3792                 :            : 
    3793   [ #  #  #  # ]:          0 :         if (page >= HV_INTC_FC_PAGE_START)
    3794                 :            :                 phy_addr = 1;
    3795                 :            : 
    3796                 :            :         return phy_addr;
    3797                 :            : }
    3798                 :            : 
    3799                 :            : /**
    3800                 :            :  * igc_access_phy_debug_regs_hv - Read HV PHY vendor specific high registers
    3801                 :            :  * @hw: pointer to the HW structure
    3802                 :            :  * @offset: register offset to be read or written
    3803                 :            :  * @data: pointer to the data to be read or written
    3804                 :            :  * @read: determines if operation is read or write
    3805                 :            :  *
    3806                 :            :  * Reads the PHY register at offset and stores the retrieved information
    3807                 :            :  * in data.  Assumes semaphore already acquired.  Note that the procedure
    3808                 :            :  * to access these regs uses the address port and data port to read/write.
    3809                 :            :  * These accesses done with PHY address 2 and without using pages.
    3810                 :            :  **/
    3811                 :          0 : static s32 igc_access_phy_debug_regs_hv(struct igc_hw *hw, u32 offset,
    3812                 :            :                                           u16 *data, bool read)
    3813                 :            : {
    3814                 :            :         s32 ret_val;
    3815                 :            :         u32 addr_reg;
    3816                 :            :         u32 data_reg;
    3817                 :            : 
    3818                 :          0 :         DEBUGFUNC("igc_access_phy_debug_regs_hv");
    3819                 :            : 
    3820                 :            :         /* This takes care of the difference with desktop vs mobile phy */
    3821                 :          0 :         addr_reg = ((hw->phy.type == igc_phy_82578) ?
    3822         [ #  # ]:          0 :                     I82578_ADDR_REG : I82577_ADDR_REG);
    3823                 :          0 :         data_reg = addr_reg + 1;
    3824                 :            : 
    3825                 :            :         /* All operations in this function are phy address 2 */
    3826                 :          0 :         hw->phy.addr = 2;
    3827                 :            : 
    3828                 :            :         /* masking with 0x3F to remove the page from offset */
    3829                 :          0 :         ret_val = igc_write_phy_reg_mdic(hw, addr_reg, (u16)offset & 0x3F);
    3830         [ #  # ]:          0 :         if (ret_val) {
    3831                 :          0 :                 DEBUGOUT("Could not write the Address Offset port register\n");
    3832                 :          0 :                 return ret_val;
    3833                 :            :         }
    3834                 :            : 
    3835                 :            :         /* Read or write the data value next */
    3836         [ #  # ]:          0 :         if (read)
    3837                 :          0 :                 ret_val = igc_read_phy_reg_mdic(hw, data_reg, data);
    3838                 :            :         else
    3839                 :          0 :                 ret_val = igc_write_phy_reg_mdic(hw, data_reg, *data);
    3840                 :            : 
    3841         [ #  # ]:          0 :         if (ret_val)
    3842                 :          0 :                 DEBUGOUT("Could not access the Data port register\n");
    3843                 :            : 
    3844                 :            :         return ret_val;
    3845                 :            : }
    3846                 :            : 
    3847                 :            : /**
    3848                 :            :  *  igc_link_stall_workaround_hv - Si workaround
    3849                 :            :  *  @hw: pointer to the HW structure
    3850                 :            :  *
    3851                 :            :  *  This function works around a Si bug where the link partner can get
    3852                 :            :  *  a link up indication before the PHY does.  If small packets are sent
    3853                 :            :  *  by the link partner they can be placed in the packet buffer without
    3854                 :            :  *  being properly accounted for by the PHY and will stall preventing
    3855                 :            :  *  further packets from being received.  The workaround is to clear the
    3856                 :            :  *  packet buffer after the PHY detects link up.
    3857                 :            :  **/
    3858                 :          0 : s32 igc_link_stall_workaround_hv(struct igc_hw *hw)
    3859                 :            : {
    3860                 :            :         s32 ret_val = IGC_SUCCESS;
    3861                 :            :         u16 data;
    3862                 :            : 
    3863                 :          0 :         DEBUGFUNC("igc_link_stall_workaround_hv");
    3864                 :            : 
    3865         [ #  # ]:          0 :         if (hw->phy.type != igc_phy_82578)
    3866                 :            :                 return IGC_SUCCESS;
    3867                 :            : 
    3868                 :            :         /* Do not apply workaround if in PHY loopback bit 14 set */
    3869                 :          0 :         hw->phy.ops.read_reg(hw, PHY_CONTROL, &data);
    3870         [ #  # ]:          0 :         if (data & PHY_CONTROL_LB)
    3871                 :            :                 return IGC_SUCCESS;
    3872                 :            : 
    3873                 :            :         /* check if link is up and at 1Gbps */
    3874                 :          0 :         ret_val = hw->phy.ops.read_reg(hw, BM_CS_STATUS, &data);
    3875         [ #  # ]:          0 :         if (ret_val)
    3876                 :            :                 return ret_val;
    3877                 :            : 
    3878                 :          0 :         data &= (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
    3879                 :            :                  BM_CS_STATUS_SPEED_MASK);
    3880                 :            : 
    3881         [ #  # ]:          0 :         if (data != (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
    3882                 :            :                      BM_CS_STATUS_SPEED_1000))
    3883                 :            :                 return IGC_SUCCESS;
    3884                 :            : 
    3885                 :          0 :         msec_delay(200);
    3886                 :            : 
    3887                 :            :         /* flush the packets in the fifo buffer */
    3888                 :          0 :         ret_val = hw->phy.ops.write_reg(hw, HV_MUX_DATA_CTRL,
    3889                 :            :                                         (HV_MUX_DATA_CTRL_GEN_TO_MAC |
    3890                 :            :                                          HV_MUX_DATA_CTRL_FORCE_SPEED));
    3891         [ #  # ]:          0 :         if (ret_val)
    3892                 :            :                 return ret_val;
    3893                 :            : 
    3894                 :          0 :         return hw->phy.ops.write_reg(hw, HV_MUX_DATA_CTRL,
    3895                 :            :                                      HV_MUX_DATA_CTRL_GEN_TO_MAC);
    3896                 :            : }
    3897                 :            : 
    3898                 :            : /**
    3899                 :            :  *  igc_check_polarity_82577 - Checks the polarity.
    3900                 :            :  *  @hw: pointer to the HW structure
    3901                 :            :  *
    3902                 :            :  *  Success returns 0, Failure returns -IGC_ERR_PHY (-2)
    3903                 :            :  *
    3904                 :            :  *  Polarity is determined based on the PHY specific status register.
    3905                 :            :  **/
    3906                 :          0 : s32 igc_check_polarity_82577(struct igc_hw *hw)
    3907                 :            : {
    3908                 :            :         struct igc_phy_info *phy = &hw->phy;
    3909                 :            :         s32 ret_val;
    3910                 :            :         u16 data;
    3911                 :            : 
    3912                 :          0 :         DEBUGFUNC("igc_check_polarity_82577");
    3913                 :            : 
    3914                 :          0 :         ret_val = phy->ops.read_reg(hw, I82577_PHY_STATUS_2, &data);
    3915                 :            : 
    3916         [ #  # ]:          0 :         if (!ret_val)
    3917                 :          0 :                 phy->cable_polarity = ((data & I82577_PHY_STATUS2_REV_POLARITY)
    3918                 :            :                                        ? igc_rev_polarity_reversed
    3919                 :          0 :                                        : igc_rev_polarity_normal);
    3920                 :            : 
    3921                 :          0 :         return ret_val;
    3922                 :            : }
    3923                 :            : 
    3924                 :            : /**
    3925                 :            :  *  igc_phy_force_speed_duplex_82577 - Force speed/duplex for I82577 PHY
    3926                 :            :  *  @hw: pointer to the HW structure
    3927                 :            :  *
    3928                 :            :  *  Calls the PHY setup function to force speed and duplex.
    3929                 :            :  **/
    3930                 :          0 : s32 igc_phy_force_speed_duplex_82577(struct igc_hw *hw)
    3931                 :            : {
    3932                 :            :         struct igc_phy_info *phy = &hw->phy;
    3933                 :            :         s32 ret_val;
    3934                 :            :         u16 phy_data;
    3935                 :          0 :         bool link = false;
    3936                 :            : 
    3937                 :          0 :         DEBUGFUNC("igc_phy_force_speed_duplex_82577");
    3938                 :            : 
    3939                 :          0 :         ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
    3940         [ #  # ]:          0 :         if (ret_val)
    3941                 :            :                 return ret_val;
    3942                 :            : 
    3943                 :          0 :         igc_phy_force_speed_duplex_setup(hw, &phy_data);
    3944                 :            : 
    3945                 :          0 :         ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
    3946         [ #  # ]:          0 :         if (ret_val)
    3947                 :            :                 return ret_val;
    3948                 :            : 
    3949                 :          0 :         usec_delay(1);
    3950                 :            : 
    3951         [ #  # ]:          0 :         if (phy->autoneg_wait_to_complete) {
    3952                 :          0 :                 DEBUGOUT("Waiting for forced speed/duplex link on 82577 phy\n");
    3953                 :            : 
    3954                 :          0 :                 ret_val = igc_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
    3955                 :            :                                                      100000, &link);
    3956         [ #  # ]:          0 :                 if (ret_val)
    3957                 :            :                         return ret_val;
    3958                 :            : 
    3959         [ #  # ]:          0 :                 if (!link)
    3960                 :          0 :                         DEBUGOUT("Link taking longer than expected.\n");
    3961                 :            : 
    3962                 :            :                 /* Try once more */
    3963                 :          0 :                 ret_val = igc_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
    3964                 :            :                                                      100000, &link);
    3965                 :            :         }
    3966                 :            : 
    3967                 :            :         return ret_val;
    3968                 :            : }
    3969                 :            : 
    3970                 :            : /**
    3971                 :            :  *  igc_get_phy_info_82577 - Retrieve I82577 PHY information
    3972                 :            :  *  @hw: pointer to the HW structure
    3973                 :            :  *
    3974                 :            :  *  Read PHY status to determine if link is up.  If link is up, then
    3975                 :            :  *  set/determine 10base-T extended distance and polarity correction.  Read
    3976                 :            :  *  PHY port status to determine MDI/MDIx and speed.  Based on the speed,
    3977                 :            :  *  determine on the cable length, local and remote receiver.
    3978                 :            :  **/
    3979                 :          0 : s32 igc_get_phy_info_82577(struct igc_hw *hw)
    3980                 :            : {
    3981                 :            :         struct igc_phy_info *phy = &hw->phy;
    3982                 :            :         s32 ret_val;
    3983                 :            :         u16 data;
    3984                 :            :         bool link;
    3985                 :            : 
    3986                 :          0 :         DEBUGFUNC("igc_get_phy_info_82577");
    3987                 :            : 
    3988                 :          0 :         ret_val = igc_phy_has_link_generic(hw, 1, 0, &link);
    3989         [ #  # ]:          0 :         if (ret_val)
    3990                 :            :                 return ret_val;
    3991                 :            : 
    3992         [ #  # ]:          0 :         if (!link) {
    3993                 :          0 :                 DEBUGOUT("Phy info is only valid if link is up\n");
    3994                 :          0 :                 return -IGC_ERR_CONFIG;
    3995                 :            :         }
    3996                 :            : 
    3997                 :          0 :         phy->polarity_correction = true;
    3998                 :            : 
    3999                 :          0 :         ret_val = igc_check_polarity_82577(hw);
    4000         [ #  # ]:          0 :         if (ret_val)
    4001                 :            :                 return ret_val;
    4002                 :            : 
    4003                 :          0 :         ret_val = phy->ops.read_reg(hw, I82577_PHY_STATUS_2, &data);
    4004         [ #  # ]:          0 :         if (ret_val)
    4005                 :            :                 return ret_val;
    4006                 :            : 
    4007                 :          0 :         phy->is_mdix = !!(data & I82577_PHY_STATUS2_MDIX);
    4008                 :            : 
    4009         [ #  # ]:          0 :         if ((data & I82577_PHY_STATUS2_SPEED_MASK) ==
    4010                 :            :             I82577_PHY_STATUS2_SPEED_1000MBPS) {
    4011                 :          0 :                 ret_val = hw->phy.ops.get_cable_length(hw);
    4012         [ #  # ]:          0 :                 if (ret_val)
    4013                 :            :                         return ret_val;
    4014                 :            : 
    4015                 :          0 :                 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
    4016         [ #  # ]:          0 :                 if (ret_val)
    4017                 :            :                         return ret_val;
    4018                 :            : 
    4019                 :          0 :                 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
    4020                 :            :                                 ? igc_1000t_rx_status_ok
    4021                 :          0 :                                 : igc_1000t_rx_status_not_ok;
    4022                 :            : 
    4023                 :          0 :                 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
    4024                 :            :                                  ? igc_1000t_rx_status_ok
    4025                 :          0 :                                  : igc_1000t_rx_status_not_ok;
    4026                 :            :         } else {
    4027                 :          0 :                 phy->cable_length = IGC_CABLE_LENGTH_UNDEFINED;
    4028                 :          0 :                 phy->local_rx = igc_1000t_rx_status_undefined;
    4029                 :          0 :                 phy->remote_rx = igc_1000t_rx_status_undefined;
    4030                 :            :         }
    4031                 :            : 
    4032                 :            :         return IGC_SUCCESS;
    4033                 :            : }
    4034                 :            : 
    4035                 :            : /**
    4036                 :            :  *  igc_get_cable_length_82577 - Determine cable length for 82577 PHY
    4037                 :            :  *  @hw: pointer to the HW structure
    4038                 :            :  *
    4039                 :            :  * Reads the diagnostic status register and verifies result is valid before
    4040                 :            :  * placing it in the phy_cable_length field.
    4041                 :            :  **/
    4042                 :          0 : s32 igc_get_cable_length_82577(struct igc_hw *hw)
    4043                 :            : {
    4044                 :            :         struct igc_phy_info *phy = &hw->phy;
    4045                 :            :         s32 ret_val;
    4046                 :            :         u16 phy_data, length;
    4047                 :            : 
    4048                 :          0 :         DEBUGFUNC("igc_get_cable_length_82577");
    4049                 :            : 
    4050                 :          0 :         ret_val = phy->ops.read_reg(hw, I82577_PHY_DIAG_STATUS, &phy_data);
    4051         [ #  # ]:          0 :         if (ret_val)
    4052                 :            :                 return ret_val;
    4053                 :            : 
    4054                 :          0 :         length = ((phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
    4055                 :            :                   I82577_DSTATUS_CABLE_LENGTH_SHIFT);
    4056                 :            : 
    4057         [ #  # ]:          0 :         if (length == IGC_CABLE_LENGTH_UNDEFINED)
    4058                 :            :                 return -IGC_ERR_PHY;
    4059                 :            : 
    4060                 :          0 :         phy->cable_length = length;
    4061                 :            : 
    4062                 :          0 :         return IGC_SUCCESS;
    4063                 :            : }
    4064                 :            : 
    4065                 :            : /**
    4066                 :            :  *  igc_write_phy_reg_gs40g - Write GS40G  PHY register
    4067                 :            :  *  @hw: pointer to the HW structure
    4068                 :            :  *  @offset: register offset to write to
    4069                 :            :  *  @data: data to write at register offset
    4070                 :            :  *
    4071                 :            :  *  Acquires semaphore, if necessary, then writes the data to PHY register
    4072                 :            :  *  at the offset.  Release any acquired semaphores before exiting.
    4073                 :            :  **/
    4074                 :          0 : s32 igc_write_phy_reg_gs40g(struct igc_hw *hw, u32 offset, u16 data)
    4075                 :            : {
    4076                 :            :         s32 ret_val;
    4077                 :          0 :         u16 page = offset >> GS40G_PAGE_SHIFT;
    4078                 :            : 
    4079                 :          0 :         DEBUGFUNC("igc_write_phy_reg_gs40g");
    4080                 :            : 
    4081                 :          0 :         offset = offset & GS40G_OFFSET_MASK;
    4082                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    4083         [ #  # ]:          0 :         if (ret_val)
    4084                 :            :                 return ret_val;
    4085                 :            : 
    4086                 :          0 :         ret_val = igc_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page);
    4087         [ #  # ]:          0 :         if (ret_val)
    4088                 :          0 :                 goto release;
    4089                 :          0 :         ret_val = igc_write_phy_reg_mdic(hw, offset, data);
    4090                 :            : 
    4091                 :          0 : release:
    4092                 :          0 :         hw->phy.ops.release(hw);
    4093                 :          0 :         return ret_val;
    4094                 :            : }
    4095                 :            : 
    4096                 :            : /**
    4097                 :            :  *  igc_read_phy_reg_gs40g - Read GS40G  PHY register
    4098                 :            :  *  @hw: pointer to the HW structure
    4099                 :            :  *  @offset: lower half is register offset to read to
    4100                 :            :  *     upper half is page to use.
    4101                 :            :  *  @data: data to read at register offset
    4102                 :            :  *
    4103                 :            :  *  Acquires semaphore, if necessary, then reads the data in the PHY register
    4104                 :            :  *  at the offset.  Release any acquired semaphores before exiting.
    4105                 :            :  **/
    4106                 :          0 : s32 igc_read_phy_reg_gs40g(struct igc_hw *hw, u32 offset, u16 *data)
    4107                 :            : {
    4108                 :            :         s32 ret_val;
    4109                 :          0 :         u16 page = offset >> GS40G_PAGE_SHIFT;
    4110                 :            : 
    4111                 :          0 :         DEBUGFUNC("igc_read_phy_reg_gs40g");
    4112                 :            : 
    4113                 :          0 :         offset = offset & GS40G_OFFSET_MASK;
    4114                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    4115         [ #  # ]:          0 :         if (ret_val)
    4116                 :            :                 return ret_val;
    4117                 :            : 
    4118                 :          0 :         ret_val = igc_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page);
    4119         [ #  # ]:          0 :         if (ret_val)
    4120                 :          0 :                 goto release;
    4121                 :          0 :         ret_val = igc_read_phy_reg_mdic(hw, offset, data);
    4122                 :            : 
    4123                 :          0 : release:
    4124                 :          0 :         hw->phy.ops.release(hw);
    4125                 :          0 :         return ret_val;
    4126                 :            : }
    4127                 :            : 
    4128                 :            : /**
    4129                 :            :  *  igc_write_phy_reg_gpy - Write GPY PHY register
    4130                 :            :  *  @hw: pointer to the HW structure
    4131                 :            :  *  @offset: register offset to write to
    4132                 :            :  *  @data: data to write at register offset
    4133                 :            :  *
    4134                 :            :  *  Acquires semaphore, if necessary, then writes the data to PHY register
    4135                 :            :  *  at the offset.  Release any acquired semaphores before exiting.
    4136                 :            :  **/
    4137                 :          0 : s32 igc_write_phy_reg_gpy(struct igc_hw *hw, u32 offset, u16 data)
    4138                 :            : {
    4139                 :            :         s32 ret_val;
    4140                 :          0 :         u8 dev_addr = (offset & GPY_MMD_MASK) >> GPY_MMD_SHIFT;
    4141                 :            : 
    4142                 :          0 :         DEBUGFUNC("igc_write_phy_reg_gpy");
    4143                 :            : 
    4144                 :          0 :         offset = offset & GPY_REG_MASK;
    4145                 :            : 
    4146         [ #  # ]:          0 :         if (!dev_addr) {
    4147                 :          0 :                 ret_val = hw->phy.ops.acquire(hw);
    4148         [ #  # ]:          0 :                 if (ret_val)
    4149                 :            :                         return ret_val;
    4150                 :          0 :                 ret_val = igc_write_phy_reg_mdic(hw, offset, data);
    4151         [ #  # ]:          0 :                 if (ret_val)
    4152                 :            :                         return ret_val;
    4153                 :          0 :                 hw->phy.ops.release(hw);
    4154                 :            :         } else {
    4155                 :          0 :                 ret_val = igc_write_xmdio_reg(hw, (u16)offset, dev_addr,
    4156                 :            :                                                 data);
    4157                 :            :         }
    4158                 :            :         return ret_val;
    4159                 :            : }
    4160                 :            : 
    4161                 :            : /**
    4162                 :            :  *  igc_read_phy_reg_gpy - Read GPY PHY register
    4163                 :            :  *  @hw: pointer to the HW structure
    4164                 :            :  *  @offset: lower half is register offset to read to
    4165                 :            :  *     upper half is MMD to use.
    4166                 :            :  *  @data: data to read at register offset
    4167                 :            :  *
    4168                 :            :  *  Acquires semaphore, if necessary, then reads the data in the PHY register
    4169                 :            :  *  at the offset.  Release any acquired semaphores before exiting.
    4170                 :            :  **/
    4171                 :          0 : s32 igc_read_phy_reg_gpy(struct igc_hw *hw, u32 offset, u16 *data)
    4172                 :            : {
    4173                 :            :         s32 ret_val;
    4174                 :          0 :         u8 dev_addr = (offset & GPY_MMD_MASK) >> GPY_MMD_SHIFT;
    4175                 :            : 
    4176                 :          0 :         DEBUGFUNC("igc_read_phy_reg_gpy");
    4177                 :            : 
    4178                 :          0 :         offset = offset & GPY_REG_MASK;
    4179                 :            : 
    4180         [ #  # ]:          0 :         if (!dev_addr) {
    4181                 :          0 :                 ret_val = hw->phy.ops.acquire(hw);
    4182         [ #  # ]:          0 :                 if (ret_val)
    4183                 :            :                         return ret_val;
    4184                 :          0 :                 ret_val = igc_read_phy_reg_mdic(hw, offset, data);
    4185         [ #  # ]:          0 :                 if (ret_val)
    4186                 :            :                         return ret_val;
    4187                 :          0 :                 hw->phy.ops.release(hw);
    4188                 :            :         } else {
    4189                 :          0 :                 ret_val = igc_read_xmdio_reg(hw, (u16)offset, dev_addr,
    4190                 :            :                                                data);
    4191                 :            :         }
    4192                 :            :         return ret_val;
    4193                 :            : }
    4194                 :            : 
    4195                 :            : /**
    4196                 :            :  *  igc_read_phy_reg_mphy - Read mPHY control register
    4197                 :            :  *  @hw: pointer to the HW structure
    4198                 :            :  *  @address: address to be read
    4199                 :            :  *  @data: pointer to the read data
    4200                 :            :  *
    4201                 :            :  *  Reads the mPHY control register in the PHY at offset and stores the
    4202                 :            :  *  information read to data.
    4203                 :            :  **/
    4204                 :          0 : s32 igc_read_phy_reg_mphy(struct igc_hw *hw, u32 address, u32 *data)
    4205                 :            : {
    4206                 :            :         u32 mphy_ctrl = 0;
    4207                 :            :         bool locked = false;
    4208                 :            :         bool ready;
    4209                 :            : 
    4210                 :          0 :         DEBUGFUNC("igc_read_phy_reg_mphy");
    4211                 :            : 
    4212                 :            :         /* Check if mPHY is ready to read/write operations */
    4213                 :          0 :         ready = igc_is_mphy_ready(hw);
    4214         [ #  # ]:          0 :         if (!ready)
    4215                 :            :                 return -IGC_ERR_PHY;
    4216                 :            : 
    4217                 :            :         /* Check if mPHY access is disabled and enable it if so */
    4218                 :          0 :         mphy_ctrl = IGC_READ_REG(hw, IGC_MPHY_ADDR_CTRL);
    4219         [ #  # ]:          0 :         if (mphy_ctrl & IGC_MPHY_DIS_ACCESS) {
    4220                 :            :                 locked = true;
    4221                 :          0 :                 ready = igc_is_mphy_ready(hw);
    4222         [ #  # ]:          0 :                 if (!ready)
    4223                 :            :                         return -IGC_ERR_PHY;
    4224                 :          0 :                 mphy_ctrl |= IGC_MPHY_ENA_ACCESS;
    4225                 :          0 :                 IGC_WRITE_REG(hw, IGC_MPHY_ADDR_CTRL, mphy_ctrl);
    4226                 :            :         }
    4227                 :            : 
    4228                 :            :         /* Set the address that we want to read */
    4229                 :          0 :         ready = igc_is_mphy_ready(hw);
    4230         [ #  # ]:          0 :         if (!ready)
    4231                 :            :                 return -IGC_ERR_PHY;
    4232                 :            : 
    4233                 :            :         /* We mask address, because we want to use only current lane */
    4234                 :          0 :         mphy_ctrl = (mphy_ctrl & ~IGC_MPHY_ADDRESS_MASK &
    4235                 :            :                 ~IGC_MPHY_ADDRESS_FNC_OVERRIDE) |
    4236                 :          0 :                 (address & IGC_MPHY_ADDRESS_MASK);
    4237                 :          0 :         IGC_WRITE_REG(hw, IGC_MPHY_ADDR_CTRL, mphy_ctrl);
    4238                 :            : 
    4239                 :            :         /* Read data from the address */
    4240                 :          0 :         ready = igc_is_mphy_ready(hw);
    4241         [ #  # ]:          0 :         if (!ready)
    4242                 :            :                 return -IGC_ERR_PHY;
    4243                 :          0 :         *data = IGC_READ_REG(hw, IGC_MPHY_DATA);
    4244                 :            : 
    4245                 :            :         /* Disable access to mPHY if it was originally disabled */
    4246         [ #  # ]:          0 :         if (locked)
    4247                 :          0 :                 ready = igc_is_mphy_ready(hw);
    4248         [ #  # ]:          0 :         if (!ready)
    4249                 :            :                 return -IGC_ERR_PHY;
    4250                 :          0 :         IGC_WRITE_REG(hw, IGC_MPHY_ADDR_CTRL,
    4251                 :            :                         IGC_MPHY_DIS_ACCESS);
    4252                 :            : 
    4253                 :          0 :         return IGC_SUCCESS;
    4254                 :            : }
    4255                 :            : 
    4256                 :            : /**
    4257                 :            :  *  igc_write_phy_reg_mphy - Write mPHY control register
    4258                 :            :  *  @hw: pointer to the HW structure
    4259                 :            :  *  @address: address to write to
    4260                 :            :  *  @data: data to write to register at offset
    4261                 :            :  *  @line_override: used when we want to use different line than default one
    4262                 :            :  *
    4263                 :            :  *  Writes data to mPHY control register.
    4264                 :            :  **/
    4265                 :          0 : s32 igc_write_phy_reg_mphy(struct igc_hw *hw, u32 address, u32 data,
    4266                 :            :                              bool line_override)
    4267                 :            : {
    4268                 :            :         u32 mphy_ctrl = 0;
    4269                 :            :         bool locked = false;
    4270                 :            :         bool ready;
    4271                 :            : 
    4272                 :          0 :         DEBUGFUNC("igc_write_phy_reg_mphy");
    4273                 :            : 
    4274                 :            :         /* Check if mPHY is ready to read/write operations */
    4275                 :          0 :         ready = igc_is_mphy_ready(hw);
    4276         [ #  # ]:          0 :         if (!ready)
    4277                 :            :                 return -IGC_ERR_PHY;
    4278                 :            : 
    4279                 :            :         /* Check if mPHY access is disabled and enable it if so */
    4280                 :          0 :         mphy_ctrl = IGC_READ_REG(hw, IGC_MPHY_ADDR_CTRL);
    4281         [ #  # ]:          0 :         if (mphy_ctrl & IGC_MPHY_DIS_ACCESS) {
    4282                 :            :                 locked = true;
    4283                 :          0 :                 ready = igc_is_mphy_ready(hw);
    4284         [ #  # ]:          0 :                 if (!ready)
    4285                 :            :                         return -IGC_ERR_PHY;
    4286                 :          0 :                 mphy_ctrl |= IGC_MPHY_ENA_ACCESS;
    4287                 :          0 :                 IGC_WRITE_REG(hw, IGC_MPHY_ADDR_CTRL, mphy_ctrl);
    4288                 :            :         }
    4289                 :            : 
    4290                 :            :         /* Set the address that we want to read */
    4291                 :          0 :         ready = igc_is_mphy_ready(hw);
    4292         [ #  # ]:          0 :         if (!ready)
    4293                 :            :                 return -IGC_ERR_PHY;
    4294                 :            : 
    4295                 :            :         /* We mask address, because we want to use only current lane */
    4296         [ #  # ]:          0 :         if (line_override)
    4297                 :          0 :                 mphy_ctrl |= IGC_MPHY_ADDRESS_FNC_OVERRIDE;
    4298                 :            :         else
    4299                 :          0 :                 mphy_ctrl &= ~IGC_MPHY_ADDRESS_FNC_OVERRIDE;
    4300                 :          0 :         mphy_ctrl = (mphy_ctrl & ~IGC_MPHY_ADDRESS_MASK) |
    4301                 :          0 :                 (address & IGC_MPHY_ADDRESS_MASK);
    4302                 :          0 :         IGC_WRITE_REG(hw, IGC_MPHY_ADDR_CTRL, mphy_ctrl);
    4303                 :            : 
    4304                 :            :         /* Read data from the address */
    4305                 :          0 :         ready = igc_is_mphy_ready(hw);
    4306         [ #  # ]:          0 :         if (!ready)
    4307                 :            :                 return -IGC_ERR_PHY;
    4308                 :          0 :         IGC_WRITE_REG(hw, IGC_MPHY_DATA, data);
    4309                 :            : 
    4310                 :            :         /* Disable access to mPHY if it was originally disabled */
    4311         [ #  # ]:          0 :         if (locked)
    4312                 :          0 :                 ready = igc_is_mphy_ready(hw);
    4313         [ #  # ]:          0 :         if (!ready)
    4314                 :            :                 return -IGC_ERR_PHY;
    4315                 :          0 :         IGC_WRITE_REG(hw, IGC_MPHY_ADDR_CTRL,
    4316                 :            :                         IGC_MPHY_DIS_ACCESS);
    4317                 :            : 
    4318                 :          0 :         return IGC_SUCCESS;
    4319                 :            : }
    4320                 :            : 
    4321                 :            : /**
    4322                 :            :  *  igc_is_mphy_ready - Check if mPHY control register is not busy
    4323                 :            :  *  @hw: pointer to the HW structure
    4324                 :            :  *
    4325                 :            :  *  Returns mPHY control register status.
    4326                 :            :  **/
    4327                 :          0 : bool igc_is_mphy_ready(struct igc_hw *hw)
    4328                 :            : {
    4329                 :            :         u16 retry_count = 0;
    4330                 :            :         u32 mphy_ctrl = 0;
    4331                 :            :         bool ready = false;
    4332                 :            : 
    4333         [ #  # ]:          0 :         while (retry_count < 2) {
    4334                 :          0 :                 mphy_ctrl = IGC_READ_REG(hw, IGC_MPHY_ADDR_CTRL);
    4335         [ #  # ]:          0 :                 if (mphy_ctrl & IGC_MPHY_BUSY) {
    4336                 :          0 :                         usec_delay(20);
    4337                 :          0 :                         retry_count++;
    4338                 :          0 :                         continue;
    4339                 :            :                 }
    4340                 :            :                 ready = true;
    4341                 :            :                 break;
    4342                 :            :         }
    4343                 :            : 
    4344         [ #  # ]:          0 :         if (!ready)
    4345                 :          0 :                 DEBUGOUT("ERROR READING mPHY control register, phy is busy.\n");
    4346                 :            : 
    4347                 :          0 :         return ready;
    4348                 :            : }
    4349                 :            : 
    4350                 :            : /**
    4351                 :            :  *  __igc_access_xmdio_reg - Read/write XMDIO register
    4352                 :            :  *  @hw: pointer to the HW structure
    4353                 :            :  *  @address: XMDIO address to program
    4354                 :            :  *  @dev_addr: device address to program
    4355                 :            :  *  @data: pointer to value to read/write from/to the XMDIO address
    4356                 :            :  *  @read: boolean flag to indicate read or write
    4357                 :            :  **/
    4358                 :          0 : static s32 __igc_access_xmdio_reg(struct igc_hw *hw, u16 address,
    4359                 :            :                                     u8 dev_addr, u16 *data, bool read)
    4360                 :            : {
    4361                 :            :         s32 ret_val;
    4362                 :            : 
    4363                 :          0 :         DEBUGFUNC("__igc_access_xmdio_reg");
    4364                 :            : 
    4365                 :          0 :         ret_val = hw->phy.ops.write_reg(hw, IGC_MMDAC, dev_addr);
    4366         [ #  # ]:          0 :         if (ret_val)
    4367                 :            :                 return ret_val;
    4368                 :            : 
    4369                 :          0 :         ret_val = hw->phy.ops.write_reg(hw, IGC_MMDAAD, address);
    4370         [ #  # ]:          0 :         if (ret_val)
    4371                 :            :                 return ret_val;
    4372                 :            : 
    4373                 :          0 :         ret_val = hw->phy.ops.write_reg(hw, IGC_MMDAC, IGC_MMDAC_FUNC_DATA |
    4374                 :            :                                         dev_addr);
    4375         [ #  # ]:          0 :         if (ret_val)
    4376                 :            :                 return ret_val;
    4377                 :            : 
    4378         [ #  # ]:          0 :         if (read)
    4379                 :          0 :                 ret_val = hw->phy.ops.read_reg(hw, IGC_MMDAAD, data);
    4380                 :            :         else
    4381                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw, IGC_MMDAAD, *data);
    4382         [ #  # ]:          0 :         if (ret_val)
    4383                 :            :                 return ret_val;
    4384                 :            : 
    4385                 :            :         /* Recalibrate the device back to 0 */
    4386                 :          0 :         ret_val = hw->phy.ops.write_reg(hw, IGC_MMDAC, 0);
    4387         [ #  # ]:          0 :         if (ret_val)
    4388                 :          0 :                 return ret_val;
    4389                 :            : 
    4390                 :            :         return ret_val;
    4391                 :            : }
    4392                 :            : 
    4393                 :            : /**
    4394                 :            :  *  igc_read_xmdio_reg - Read XMDIO register
    4395                 :            :  *  @hw: pointer to the HW structure
    4396                 :            :  *  @addr: XMDIO address to program
    4397                 :            :  *  @dev_addr: device address to program
    4398                 :            :  *  @data: value to be read from the EMI address
    4399                 :            :  **/
    4400                 :          0 : s32 igc_read_xmdio_reg(struct igc_hw *hw, u16 addr, u8 dev_addr, u16 *data)
    4401                 :            : {
    4402                 :          0 :         DEBUGFUNC("igc_read_xmdio_reg");
    4403                 :            : 
    4404                 :          0 :         return __igc_access_xmdio_reg(hw, addr, dev_addr, data, true);
    4405                 :            : }
    4406                 :            : 
    4407                 :            : /**
    4408                 :            :  *  igc_write_xmdio_reg - Write XMDIO register
    4409                 :            :  *  @hw: pointer to the HW structure
    4410                 :            :  *  @addr: XMDIO address to program
    4411                 :            :  *  @dev_addr: device address to program
    4412                 :            :  *  @data: value to be written to the XMDIO address
    4413                 :            :  **/
    4414                 :          0 : s32 igc_write_xmdio_reg(struct igc_hw *hw, u16 addr, u8 dev_addr, u16 data)
    4415                 :            : {
    4416                 :          0 :         DEBUGFUNC("igc_write_xmdio_reg");
    4417                 :            : 
    4418                 :          0 :         return __igc_access_xmdio_reg(hw, addr, dev_addr, &data,
    4419                 :            :                                 false);
    4420                 :            : }

Generated by: LCOV version 1.14