igb_phy.c

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003   Intel(R) Gigabit Ethernet Linux driver
00004   Copyright(c) 2007-2009 Intel Corporation.
00005 
00006   This program is free software; you can redistribute it and/or modify it
00007   under the terms and conditions of the GNU General Public License,
00008   version 2, as published by the Free Software Foundation.
00009 
00010   This program is distributed in the hope it will be useful, but WITHOUT
00011   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00013   more details.
00014 
00015   You should have received a copy of the GNU General Public License along with
00016   this program; if not, write to the Free Software Foundation, Inc.,
00017   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019   The full GNU General Public License is included in this distribution in
00020   the file called "COPYING".
00021 
00022   Contact Information:
00023   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
00024   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
00025 
00026 *******************************************************************************/
00027 
00028 FILE_LICENCE ( GPL2_ONLY );
00029 
00030 #include "igb.h"
00031 
00032 static s32 igb_phy_setup_autoneg(struct e1000_hw *hw);
00033 
00034 #if 0
00035 /* Cable length tables */
00036 static const u16 e1000_m88_cable_length_table[] =
00037         { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
00038 #define M88E1000_CABLE_LENGTH_TABLE_SIZE \
00039                 (sizeof(e1000_m88_cable_length_table) / \
00040                  sizeof(e1000_m88_cable_length_table[0]))
00041 
00042 static const u16 e1000_igp_2_cable_length_table[] =
00043     { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
00044       0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
00045       6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
00046       21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
00047       40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
00048       60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
00049       83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
00050       104, 109, 114, 118, 121, 124};
00051 #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
00052                 (sizeof(e1000_igp_2_cable_length_table) / \
00053                  sizeof(e1000_igp_2_cable_length_table[0]))
00054 #endif
00055 
00056 /**
00057  *  igb_check_reset_block_generic - Check if PHY reset is blocked
00058  *  @hw: pointer to the HW structure
00059  *
00060  *  Read the PHY management control register and check whether a PHY reset
00061  *  is blocked.  If a reset is not blocked return E1000_SUCCESS, otherwise
00062  *  return E1000_BLK_PHY_RESET (12).
00063  **/
00064 s32 igb_check_reset_block_generic(struct e1000_hw *hw)
00065 {
00066         u32 manc;
00067 
00068         DEBUGFUNC("igb_check_reset_block");
00069 
00070         manc = E1000_READ_REG(hw, E1000_MANC);
00071 
00072         return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
00073                E1000_BLK_PHY_RESET : E1000_SUCCESS;
00074 }
00075 
00076 /**
00077  *  igb_get_phy_id - Retrieve the PHY ID and revision
00078  *  @hw: pointer to the HW structure
00079  *
00080  *  Reads the PHY registers and stores the PHY ID and possibly the PHY
00081  *  revision in the hardware structure.
00082  **/
00083 s32 igb_get_phy_id(struct e1000_hw *hw)
00084 {
00085         struct e1000_phy_info *phy = &hw->phy;
00086         s32 ret_val = E1000_SUCCESS;
00087         u16 phy_id;
00088 
00089         DEBUGFUNC("igb_get_phy_id");
00090 
00091         if (!(phy->ops.read_reg))
00092                 goto out;
00093 
00094                 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
00095                 if (ret_val)
00096                         goto out;
00097 
00098                 phy->id = (u32)(phy_id << 16);
00099                 usec_delay(20);
00100                 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
00101                 if (ret_val)
00102                         goto out;
00103 
00104                 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
00105                 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
00106 
00107 out:
00108         return ret_val;
00109 }
00110 
00111 /**
00112  *  igb_phy_reset_dsp_generic - Reset PHY DSP
00113  *  @hw: pointer to the HW structure
00114  *
00115  *  Reset the digital signal processor.
00116  **/
00117 s32 igb_phy_reset_dsp_generic(struct e1000_hw *hw)
00118 {
00119         s32 ret_val = E1000_SUCCESS;
00120 
00121         DEBUGFUNC("igb_phy_reset_dsp_generic");
00122 
00123         if (!(hw->phy.ops.write_reg))
00124                 goto out;
00125 
00126         ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
00127         if (ret_val)
00128                 goto out;
00129 
00130         ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
00131 
00132 out:
00133         return ret_val;
00134 }
00135 
00136 /**
00137  *  igb_read_phy_reg_mdic - Read MDI control register
00138  *  @hw: pointer to the HW structure
00139  *  @offset: register offset to be read
00140  *  @data: pointer to the read data
00141  *
00142  *  Reads the MDI control register in the PHY at offset and stores the
00143  *  information read to data.
00144  **/
00145 s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
00146 {
00147         struct e1000_phy_info *phy = &hw->phy;
00148         u32 i, mdic = 0;
00149         s32 ret_val = E1000_SUCCESS;
00150 
00151         DEBUGFUNC("igb_read_phy_reg_mdic");
00152 
00153         /*
00154          * Set up Op-code, Phy Address, and register offset in the MDI
00155          * Control register.  The MAC will take care of interfacing with the
00156          * PHY to retrieve the desired data.
00157          */
00158         mdic = ((offset << E1000_MDIC_REG_SHIFT) |
00159                 (phy->addr << E1000_MDIC_PHY_SHIFT) |
00160                 (E1000_MDIC_OP_READ));
00161 
00162         E1000_WRITE_REG(hw, E1000_MDIC, mdic);
00163 
00164         /*
00165          * Poll the ready bit to see if the MDI read completed
00166          * Increasing the time out as testing showed failures with
00167          * the lower time out
00168          */
00169         for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
00170                 usec_delay(50);
00171                 mdic = E1000_READ_REG(hw, E1000_MDIC);
00172                 if (mdic & E1000_MDIC_READY)
00173                         break;
00174         }
00175         if (!(mdic & E1000_MDIC_READY)) {
00176                 DEBUGOUT("MDI Read did not complete\n");
00177                 ret_val = -E1000_ERR_PHY;
00178                 goto out;
00179         }
00180         if (mdic & E1000_MDIC_ERROR) {
00181                 DEBUGOUT("MDI Error\n");
00182                 ret_val = -E1000_ERR_PHY;
00183                 goto out;
00184         }
00185         *data = (u16) mdic;
00186 
00187 out:
00188         return ret_val;
00189 }
00190 
00191 /**
00192  *  igb_write_phy_reg_mdic - Write MDI control register
00193  *  @hw: pointer to the HW structure
00194  *  @offset: register offset to write to
00195  *  @data: data to write to register at offset
00196  *
00197  *  Writes data to MDI control register in the PHY at offset.
00198  **/
00199 s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
00200 {
00201         struct e1000_phy_info *phy = &hw->phy;
00202         u32 i, mdic = 0;
00203         s32 ret_val = E1000_SUCCESS;
00204 
00205         DEBUGFUNC("igb_write_phy_reg_mdic");
00206 
00207         /*
00208          * Set up Op-code, Phy Address, and register offset in the MDI
00209          * Control register.  The MAC will take care of interfacing with the
00210          * PHY to retrieve the desired data.
00211          */
00212         mdic = (((u32)data) |
00213                 (offset << E1000_MDIC_REG_SHIFT) |
00214                 (phy->addr << E1000_MDIC_PHY_SHIFT) |
00215                 (E1000_MDIC_OP_WRITE));
00216 
00217         E1000_WRITE_REG(hw, E1000_MDIC, mdic);
00218 
00219         /*
00220          * Poll the ready bit to see if the MDI read completed
00221          * Increasing the time out as testing showed failures with
00222          * the lower time out
00223          */
00224         for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
00225                 usec_delay(50);
00226                 mdic = E1000_READ_REG(hw, E1000_MDIC);
00227                 if (mdic & E1000_MDIC_READY)
00228                         break;
00229         }
00230         if (!(mdic & E1000_MDIC_READY)) {
00231                 DEBUGOUT("MDI Write did not complete\n");
00232                 ret_val = -E1000_ERR_PHY;
00233                 goto out;
00234         }
00235         if (mdic & E1000_MDIC_ERROR) {
00236                 DEBUGOUT("MDI Error\n");
00237                 ret_val = -E1000_ERR_PHY;
00238                 goto out;
00239         }
00240 
00241 out:
00242         return ret_val;
00243 }
00244 
00245 /**
00246  *  igb_read_phy_reg_i2c - Read PHY register using i2c
00247  *  @hw: pointer to the HW structure
00248  *  @offset: register offset to be read
00249  *  @data: pointer to the read data
00250  *
00251  *  Reads the PHY register at offset using the i2c interface and stores the
00252  *  retrieved information in data.
00253  **/
00254 s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
00255 {
00256         struct e1000_phy_info *phy = &hw->phy;
00257         u32 i, i2ccmd = 0;
00258 
00259         DEBUGFUNC("igb_read_phy_reg_i2c");
00260 
00261         /*
00262          * Set up Op-code, Phy Address, and register address in the I2CCMD
00263          * register.  The MAC will take care of interfacing with the
00264          * PHY to retrieve the desired data.
00265          */
00266         i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
00267                   (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
00268                   (E1000_I2CCMD_OPCODE_READ));
00269 
00270         E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
00271 
00272         /* Poll the ready bit to see if the I2C read completed */
00273         for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
00274                 usec_delay(50);
00275                 i2ccmd = E1000_READ_REG(hw, E1000_I2CCMD);
00276                 if (i2ccmd & E1000_I2CCMD_READY)
00277                         break;
00278         }
00279         if (!(i2ccmd & E1000_I2CCMD_READY)) {
00280                 DEBUGOUT("I2CCMD Read did not complete\n");
00281                 return -E1000_ERR_PHY;
00282         }
00283         if (i2ccmd & E1000_I2CCMD_ERROR) {
00284                 DEBUGOUT("I2CCMD Error bit set\n");
00285                 return -E1000_ERR_PHY;
00286         }
00287 
00288         /* Need to byte-swap the 16-bit value. */
00289         *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
00290 
00291         return E1000_SUCCESS;
00292 }
00293 
00294 /**
00295  *  igb_write_phy_reg_i2c - Write PHY register using i2c
00296  *  @hw: pointer to the HW structure
00297  *  @offset: register offset to write to
00298  *  @data: data to write at register offset
00299  *
00300  *  Writes the data to PHY register at the offset using the i2c interface.
00301  **/
00302 s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
00303 {
00304         struct e1000_phy_info *phy = &hw->phy;
00305         u32 i, i2ccmd = 0;
00306         u16 phy_data_swapped;
00307 
00308         DEBUGFUNC("igb_write_phy_reg_i2c");
00309 
00310         /* Swap the data bytes for the I2C interface */
00311         phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
00312 
00313         /*
00314          * Set up Op-code, Phy Address, and register address in the I2CCMD
00315          * register.  The MAC will take care of interfacing with the
00316          * PHY to retrieve the desired data.
00317          */
00318         i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
00319                   (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
00320                   E1000_I2CCMD_OPCODE_WRITE |
00321                   phy_data_swapped);
00322 
00323         E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
00324 
00325         /* Poll the ready bit to see if the I2C read completed */
00326         for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
00327                 usec_delay(50);
00328                 i2ccmd = E1000_READ_REG(hw, E1000_I2CCMD);
00329                 if (i2ccmd & E1000_I2CCMD_READY)
00330                         break;
00331         }
00332         if (!(i2ccmd & E1000_I2CCMD_READY)) {
00333                 DEBUGOUT("I2CCMD Write did not complete\n");
00334                 return -E1000_ERR_PHY;
00335         }
00336         if (i2ccmd & E1000_I2CCMD_ERROR) {
00337                 DEBUGOUT("I2CCMD Error bit set\n");
00338                 return -E1000_ERR_PHY;
00339         }
00340 
00341         return E1000_SUCCESS;
00342 }
00343 
00344 /**
00345  *  igb_read_phy_reg_m88 - Read m88 PHY register
00346  *  @hw: pointer to the HW structure
00347  *  @offset: register offset to be read
00348  *  @data: pointer to the read data
00349  *
00350  *  Acquires semaphore, if necessary, then reads the PHY register at offset
00351  *  and storing the retrieved information in data.  Release any acquired
00352  *  semaphores before exiting.
00353  **/
00354 s32 igb_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
00355 {
00356         s32 ret_val = E1000_SUCCESS;
00357 
00358         DEBUGFUNC("igb_read_phy_reg_m88");
00359 
00360         if (!(hw->phy.ops.acquire))
00361                 goto out;
00362 
00363         ret_val = hw->phy.ops.acquire(hw);
00364         if (ret_val)
00365                 goto out;
00366 
00367         ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
00368                                           data);
00369 
00370         hw->phy.ops.release(hw);
00371 
00372 out:
00373         return ret_val;
00374 }
00375 
00376 /**
00377  *  igb_write_phy_reg_m88 - Write m88 PHY register
00378  *  @hw: pointer to the HW structure
00379  *  @offset: register offset to write to
00380  *  @data: data to write at register offset
00381  *
00382  *  Acquires semaphore, if necessary, then writes the data to PHY register
00383  *  at the offset.  Release any acquired semaphores before exiting.
00384  **/
00385 s32 igb_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
00386 {
00387         s32 ret_val = E1000_SUCCESS;
00388 
00389         DEBUGFUNC("igb_write_phy_reg_m88");
00390 
00391         if (!(hw->phy.ops.acquire))
00392                 goto out;
00393 
00394         ret_val = hw->phy.ops.acquire(hw);
00395         if (ret_val)
00396                 goto out;
00397 
00398         ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
00399                                            data);
00400 
00401         hw->phy.ops.release(hw);
00402 
00403 out:
00404         return ret_val;
00405 }
00406 
00407 /**
00408  *  __igb_read_phy_reg_igp - Read igp PHY register
00409  *  @hw: pointer to the HW structure
00410  *  @offset: register offset to be read
00411  *  @data: pointer to the read data
00412  *  @locked: semaphore has already been acquired or not
00413  *
00414  *  Acquires semaphore, if necessary, then reads the PHY register at offset
00415  *  and stores the retrieved information in data.  Release any acquired
00416  *  semaphores before exiting.
00417  **/
00418 static s32 __igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
00419                                     bool locked)
00420 {
00421         s32 ret_val = E1000_SUCCESS;
00422 
00423         DEBUGFUNC("__igb_read_phy_reg_igp");
00424 
00425         if (!locked) {
00426                 if (!(hw->phy.ops.acquire))
00427                         goto out;
00428 
00429                 ret_val = hw->phy.ops.acquire(hw);
00430                 if (ret_val)
00431                         goto out;
00432         }
00433 
00434         if (offset > MAX_PHY_MULTI_PAGE_REG) {
00435                 ret_val = igb_write_phy_reg_mdic(hw,
00436                                                    IGP01E1000_PHY_PAGE_SELECT,
00437                                                    (u16)offset);
00438                 if (ret_val)
00439                         goto release;
00440         }
00441 
00442         ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
00443                                           data);
00444 
00445 release:
00446         if (!locked)
00447                 hw->phy.ops.release(hw);
00448 out:
00449         return ret_val;
00450 }
00451 /**
00452  *  igb_read_phy_reg_igp - Read igp PHY register
00453  *  @hw: pointer to the HW structure
00454  *  @offset: register offset to be read
00455  *  @data: pointer to the read data
00456  *
00457  *  Acquires semaphore then reads the PHY register at offset and stores the
00458  *  retrieved information in data.
00459  *  Release the acquired semaphore before exiting.
00460  **/
00461 s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
00462 {
00463         return __igb_read_phy_reg_igp(hw, offset, data, false);
00464 }
00465 
00466 /**
00467  *  igb_read_phy_reg_igp_locked - Read igp PHY register
00468  *  @hw: pointer to the HW structure
00469  *  @offset: register offset to be read
00470  *  @data: pointer to the read data
00471  *
00472  *  Reads the PHY register at offset and stores the retrieved information
00473  *  in data.  Assumes semaphore already acquired.
00474  **/
00475 s32 igb_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
00476 {
00477         return __igb_read_phy_reg_igp(hw, offset, data, true);
00478 }
00479 
00480 /**
00481  *  igb_write_phy_reg_igp - Write igp PHY register
00482  *  @hw: pointer to the HW structure
00483  *  @offset: register offset to write to
00484  *  @data: data to write at register offset
00485  *  @locked: semaphore has already been acquired or not
00486  *
00487  *  Acquires semaphore, if necessary, then writes the data to PHY register
00488  *  at the offset.  Release any acquired semaphores before exiting.
00489  **/
00490 static s32 __igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
00491                                      bool locked)
00492 {
00493         s32 ret_val = E1000_SUCCESS;
00494 
00495         DEBUGFUNC("igb_write_phy_reg_igp");
00496 
00497         if (!locked) {
00498                 if (!(hw->phy.ops.acquire))
00499                         goto out;
00500 
00501                 ret_val = hw->phy.ops.acquire(hw);
00502                 if (ret_val)
00503                         goto out;
00504         }
00505 
00506         if (offset > MAX_PHY_MULTI_PAGE_REG) {
00507                 ret_val = igb_write_phy_reg_mdic(hw,
00508                                                    IGP01E1000_PHY_PAGE_SELECT,
00509                                                    (u16)offset);
00510                 if (ret_val)
00511                         goto release;
00512         }
00513 
00514         ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
00515                                            data);
00516 
00517 release:
00518         if (!locked)
00519                 hw->phy.ops.release(hw);
00520 
00521 out:
00522         return ret_val;
00523 }
00524 
00525 /**
00526  *  igb_write_phy_reg_igp - Write igp PHY register
00527  *  @hw: pointer to the HW structure
00528  *  @offset: register offset to write to
00529  *  @data: data to write at register offset
00530  *
00531  *  Acquires semaphore then writes the data to PHY register
00532  *  at the offset.  Release any acquired semaphores before exiting.
00533  **/
00534 s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
00535 {
00536         return __igb_write_phy_reg_igp(hw, offset, data, false);
00537 }
00538 
00539 /**
00540  *  igb_write_phy_reg_igp_locked - Write igp PHY register
00541  *  @hw: pointer to the HW structure
00542  *  @offset: register offset to write to
00543  *  @data: data to write at register offset
00544  *
00545  *  Writes the data to PHY register at the offset.
00546  *  Assumes semaphore already acquired.
00547  **/
00548 s32 igb_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
00549 {
00550         return __igb_write_phy_reg_igp(hw, offset, data, true);
00551 }
00552 
00553 /**
00554  *  __igb_read_kmrn_reg - Read kumeran register
00555  *  @hw: pointer to the HW structure
00556  *  @offset: register offset to be read
00557  *  @data: pointer to the read data
00558  *  @locked: semaphore has already been acquired or not
00559  *
00560  *  Acquires semaphore, if necessary.  Then reads the PHY register at offset
00561  *  using the kumeran interface.  The information retrieved is stored in data.
00562  *  Release any acquired semaphores before exiting.
00563  **/
00564 static s32 __igb_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
00565                                  bool locked)
00566 {
00567         u32 kmrnctrlsta;
00568         s32 ret_val = E1000_SUCCESS;
00569 
00570         DEBUGFUNC("__igb_read_kmrn_reg");
00571 
00572         if (!locked) {
00573                 if (!(hw->phy.ops.acquire))
00574                         goto out;
00575 
00576                 ret_val = hw->phy.ops.acquire(hw);
00577                 if (ret_val)
00578                         goto out;
00579         }
00580 
00581         kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
00582                        E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
00583         E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
00584 
00585         usec_delay(2);
00586 
00587         kmrnctrlsta = E1000_READ_REG(hw, E1000_KMRNCTRLSTA);
00588         *data = (u16)kmrnctrlsta;
00589 
00590         if (!locked)
00591                 hw->phy.ops.release(hw);
00592 
00593 out:
00594         return ret_val;
00595 }
00596 
00597 /**
00598  *  igb_read_kmrn_reg_generic -  Read kumeran register
00599  *  @hw: pointer to the HW structure
00600  *  @offset: register offset to be read
00601  *  @data: pointer to the read data
00602  *
00603  *  Acquires semaphore then reads the PHY register at offset using the
00604  *  kumeran interface.  The information retrieved is stored in data.
00605  *  Release the acquired semaphore before exiting.
00606  **/
00607 s32 igb_read_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 *data)
00608 {
00609         return __igb_read_kmrn_reg(hw, offset, data, false);
00610 }
00611 
00612 /**
00613  *  igb_read_kmrn_reg_locked -  Read kumeran register
00614  *  @hw: pointer to the HW structure
00615  *  @offset: register offset to be read
00616  *  @data: pointer to the read data
00617  *
00618  *  Reads the PHY register at offset using the kumeran interface.  The
00619  *  information retrieved is stored in data.
00620  *  Assumes semaphore already acquired.
00621  **/
00622 s32 igb_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
00623 {
00624         return __igb_read_kmrn_reg(hw, offset, data, true);
00625 }
00626 
00627 /**
00628  *  __igb_write_kmrn_reg - Write kumeran register
00629  *  @hw: pointer to the HW structure
00630  *  @offset: register offset to write to
00631  *  @data: data to write at register offset
00632  *  @locked: semaphore has already been acquired or not
00633  *
00634  *  Acquires semaphore, if necessary.  Then write the data to PHY register
00635  *  at the offset using the kumeran interface.  Release any acquired semaphores
00636  *  before exiting.
00637  **/
00638 static s32 __igb_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
00639                                   bool locked)
00640 {
00641         u32 kmrnctrlsta;
00642         s32 ret_val = E1000_SUCCESS;
00643 
00644         DEBUGFUNC("igb_write_kmrn_reg_generic");
00645 
00646         if (!locked) {
00647                 if (!(hw->phy.ops.acquire))
00648                         goto out;
00649 
00650                 ret_val = hw->phy.ops.acquire(hw);
00651                 if (ret_val)
00652                         goto out;
00653         }
00654 
00655         kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
00656                        E1000_KMRNCTRLSTA_OFFSET) | data;
00657         E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
00658 
00659         usec_delay(2);
00660 
00661         if (!locked)
00662                 hw->phy.ops.release(hw);
00663 
00664 out:
00665         return ret_val;
00666 }
00667 
00668 /**
00669  *  igb_write_kmrn_reg_generic -  Write kumeran register
00670  *  @hw: pointer to the HW structure
00671  *  @offset: register offset to write to
00672  *  @data: data to write at register offset
00673  *
00674  *  Acquires semaphore then writes the data to the PHY register at the offset
00675  *  using the kumeran interface.  Release the acquired semaphore before exiting.
00676  **/
00677 s32 igb_write_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 data)
00678 {
00679         return __igb_write_kmrn_reg(hw, offset, data, false);
00680 }
00681 
00682 /**
00683  *  igb_write_kmrn_reg_locked -  Write kumeran register
00684  *  @hw: pointer to the HW structure
00685  *  @offset: register offset to write to
00686  *  @data: data to write at register offset
00687  *
00688  *  Write the data to PHY register at the offset using the kumeran interface.
00689  *  Assumes semaphore already acquired.
00690  **/
00691 s32 igb_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
00692 {
00693         return __igb_write_kmrn_reg(hw, offset, data, true);
00694 }
00695 
00696 /**
00697  *  igb_copper_link_setup_m88 - Setup m88 PHY's for copper link
00698  *  @hw: pointer to the HW structure
00699  *
00700  *  Sets up MDI/MDI-X and polarity for m88 PHY's.  If necessary, transmit clock
00701  *  and downshift values are set also.
00702  **/
00703 s32 igb_copper_link_setup_m88(struct e1000_hw *hw)
00704 {
00705         struct e1000_phy_info *phy = &hw->phy;
00706         s32 ret_val;
00707         u16 phy_data;
00708 
00709         DEBUGFUNC("igb_copper_link_setup_m88");
00710 
00711         if (phy->reset_disable) {
00712                 ret_val = E1000_SUCCESS;
00713                 goto out;
00714         }
00715 
00716         /* Enable CRS on TX. This must be set for half-duplex operation. */
00717         ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
00718         if (ret_val)
00719                 goto out;
00720 
00721         phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
00722 
00723         /*
00724          * Options:
00725          *   MDI/MDI-X = 0 (default)
00726          *   0 - Auto for all speeds
00727          *   1 - MDI mode
00728          *   2 - MDI-X mode
00729          *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
00730          */
00731         phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
00732 
00733         switch (phy->mdix) {
00734         case 1:
00735                 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
00736                 break;
00737         case 2:
00738                 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
00739                 break;
00740         case 3:
00741                 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
00742                 break;
00743         case 0:
00744         default:
00745                 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
00746                 break;
00747         }
00748 
00749         /*
00750          * Options:
00751          *   disable_polarity_correction = 0 (default)
00752          *       Automatic Correction for Reversed Cable Polarity
00753          *   0 - Disabled
00754          *   1 - Enabled
00755          */
00756         phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
00757         if (phy->disable_polarity_correction == 1)
00758                 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
00759 
00760         ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
00761         if (ret_val)
00762                 goto out;
00763 
00764         if (phy->revision < E1000_REVISION_4) {
00765                 /*
00766                  * Force TX_CLK in the Extended PHY Specific Control Register
00767                  * to 25MHz clock.
00768                  */
00769                 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
00770                                              &phy_data);
00771                 if (ret_val)
00772                         goto out;
00773 
00774                 phy_data |= M88E1000_EPSCR_TX_CLK_25;
00775 
00776                 if ((phy->revision == E1000_REVISION_2) &&
00777                     (phy->id == M88E1111_I_PHY_ID)) {
00778                         /* 82573L PHY - set the downshift counter to 5x. */
00779                         phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
00780                         phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
00781                 } else {
00782                         /* Configure Master and Slave downshift values */
00783                         phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
00784                                      M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
00785                         phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
00786                                      M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
00787                 }
00788                 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
00789                                              phy_data);
00790                 if (ret_val)
00791                         goto out;
00792         }
00793 
00794         /* Commit the changes. */
00795         ret_val = phy->ops.commit(hw);
00796         if (ret_val) {
00797                 DEBUGOUT("Error committing the PHY changes\n");
00798                 goto out;
00799         }
00800 
00801 out:
00802         return ret_val;
00803 }
00804 
00805 /**
00806  *  igb_copper_link_setup_igp - Setup igp PHY's for copper link
00807  *  @hw: pointer to the HW structure
00808  *
00809  *  Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
00810  *  igp PHY's.
00811  **/
00812 s32 igb_copper_link_setup_igp(struct e1000_hw *hw)
00813 {
00814         struct e1000_phy_info *phy = &hw->phy;
00815         s32 ret_val;
00816         u16 data;
00817 
00818         DEBUGFUNC("igb_copper_link_setup_igp");
00819 
00820         if (phy->reset_disable) {
00821                 ret_val = E1000_SUCCESS;
00822                 goto out;
00823         }
00824 
00825         ret_val = hw->phy.ops.reset(hw);
00826         if (ret_val) {
00827                 DEBUGOUT("Error resetting the PHY.\n");
00828                 goto out;
00829         }
00830 
00831         /*
00832          * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
00833          * timeout issues when LFS is enabled.
00834          */
00835         msec_delay(100);
00836 
00837         /*
00838          * The NVM settings will configure LPLU in D3 for
00839          * non-IGP1 PHYs.
00840          */
00841         if (phy->type == e1000_phy_igp) {
00842                 /* disable lplu d3 during driver init */
00843                 ret_val = hw->phy.ops.set_d3_lplu_state(hw, false);
00844                 if (ret_val) {
00845                         DEBUGOUT("Error Disabling LPLU D3\n");
00846                         goto out;
00847                 }
00848         }
00849 
00850         /* disable lplu d0 during driver init */
00851         if (hw->phy.ops.set_d0_lplu_state) {
00852                 ret_val = hw->phy.ops.set_d0_lplu_state(hw, false);
00853                 if (ret_val) {
00854                         DEBUGOUT("Error Disabling LPLU D0\n");
00855                         goto out;
00856                 }
00857         }
00858         /* Configure mdi-mdix settings */
00859         ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
00860         if (ret_val)
00861                 goto out;
00862 
00863         data &= ~IGP01E1000_PSCR_AUTO_MDIX;
00864 
00865         switch (phy->mdix) {
00866         case 1:
00867                 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
00868                 break;
00869         case 2:
00870                 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
00871                 break;
00872         case 0:
00873         default:
00874                 data |= IGP01E1000_PSCR_AUTO_MDIX;
00875                 break;
00876         }
00877         ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
00878         if (ret_val)
00879                 goto out;
00880 
00881         /* set auto-master slave resolution settings */
00882         if (hw->mac.autoneg) {
00883                 /*
00884                  * when autonegotiation advertisement is only 1000Mbps then we
00885                  * should disable SmartSpeed and enable Auto MasterSlave
00886                  * resolution as hardware default.
00887                  */
00888                 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
00889                         /* Disable SmartSpeed */
00890                         ret_val = phy->ops.read_reg(hw,
00891                                                      IGP01E1000_PHY_PORT_CONFIG,
00892                                                      &data);
00893                         if (ret_val)
00894                                 goto out;
00895 
00896                         data &= ~IGP01E1000_PSCFR_SMART_SPEED;
00897                         ret_val = phy->ops.write_reg(hw,
00898                                                      IGP01E1000_PHY_PORT_CONFIG,
00899                                                      data);
00900                         if (ret_val)
00901                                 goto out;
00902 
00903                         /* Set auto Master/Slave resolution process */
00904                         ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
00905                         if (ret_val)
00906                                 goto out;
00907 
00908                         data &= ~CR_1000T_MS_ENABLE;
00909                         ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
00910                         if (ret_val)
00911                                 goto out;
00912                 }
00913 
00914                 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
00915                 if (ret_val)
00916                         goto out;
00917 
00918                 /* load defaults for future use */
00919                 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
00920                         ((data & CR_1000T_MS_VALUE) ?
00921                         e1000_ms_force_master :
00922                         e1000_ms_force_slave) :
00923                         e1000_ms_auto;
00924 
00925                 switch (phy->ms_type) {
00926                 case e1000_ms_force_master:
00927                         data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
00928                         break;
00929                 case e1000_ms_force_slave:
00930                         data |= CR_1000T_MS_ENABLE;
00931                         data &= ~(CR_1000T_MS_VALUE);
00932                         break;
00933                 case e1000_ms_auto:
00934                         data &= ~CR_1000T_MS_ENABLE;
00935                 default:
00936                         break;
00937                 }
00938                 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
00939                 if (ret_val)
00940                         goto out;
00941         }
00942 
00943 out:
00944         return ret_val;
00945 }
00946 
00947 /**
00948  *  igb_copper_link_autoneg - Setup/Enable autoneg for copper link
00949  *  @hw: pointer to the HW structure
00950  *
00951  *  Performs initial bounds checking on autoneg advertisement parameter, then
00952  *  configure to advertise the full capability.  Setup the PHY to autoneg
00953  *  and restart the negotiation process between the link partner.  If
00954  *  autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
00955  **/
00956 s32 igb_copper_link_autoneg(struct e1000_hw *hw)
00957 {
00958         struct e1000_phy_info *phy = &hw->phy;
00959         s32 ret_val;
00960         u16 phy_ctrl;
00961 
00962         DEBUGFUNC("igb_copper_link_autoneg");
00963 
00964         /*
00965          * Perform some bounds checking on the autoneg advertisement
00966          * parameter.
00967          */
00968         phy->autoneg_advertised &= phy->autoneg_mask;
00969 
00970         /*
00971          * If autoneg_advertised is zero, we assume it was not defaulted
00972          * by the calling code so we set to advertise full capability.
00973          */
00974         if (phy->autoneg_advertised == 0)
00975                 phy->autoneg_advertised = phy->autoneg_mask;
00976 
00977         DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
00978         ret_val = igb_phy_setup_autoneg(hw);
00979         if (ret_val) {
00980                 DEBUGOUT("Error Setting up Auto-Negotiation\n");
00981                 goto out;
00982         }
00983         DEBUGOUT("Restarting Auto-Neg\n");
00984 
00985         /*
00986          * Restart auto-negotiation by setting the Auto Neg Enable bit and
00987          * the Auto Neg Restart bit in the PHY control register.
00988          */
00989         ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
00990         if (ret_val)
00991                 goto out;
00992 
00993         phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
00994         ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
00995         if (ret_val)
00996                 goto out;
00997 
00998         /*
00999          * Does the user want to wait for Auto-Neg to complete here, or
01000          * check at a later time (for example, callback routine).
01001          */
01002         if (phy->autoneg_wait_to_complete) {
01003                 ret_val = hw->mac.ops.wait_autoneg(hw);
01004                 if (ret_val) {
01005                         DEBUGOUT("Error while waiting for "
01006                                  "autoneg to complete\n");
01007                         goto out;
01008                 }
01009         }
01010 
01011         hw->mac.get_link_status = true;
01012 
01013 out:
01014         return ret_val;
01015 }
01016 
01017 /**
01018  *  igb_phy_setup_autoneg - Configure PHY for auto-negotiation
01019  *  @hw: pointer to the HW structure
01020  *
01021  *  Reads the MII auto-neg advertisement register and/or the 1000T control
01022  *  register and if the PHY is already setup for auto-negotiation, then
01023  *  return successful.  Otherwise, setup advertisement and flow control to
01024  *  the appropriate values for the wanted auto-negotiation.
01025  **/
01026 static s32 igb_phy_setup_autoneg(struct e1000_hw *hw)
01027 {
01028         struct e1000_phy_info *phy = &hw->phy;
01029         s32 ret_val;
01030         u16 mii_autoneg_adv_reg;
01031         u16 mii_1000t_ctrl_reg = 0;
01032 
01033         DEBUGFUNC("igb_phy_setup_autoneg");
01034 
01035         phy->autoneg_advertised &= phy->autoneg_mask;
01036 
01037         /* Read the MII Auto-Neg Advertisement Register (Address 4). */
01038         ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
01039         if (ret_val)
01040                 goto out;
01041 
01042         if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
01043                 /* Read the MII 1000Base-T Control Register (Address 9). */
01044                 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
01045                                             &mii_1000t_ctrl_reg);
01046                 if (ret_val)
01047                         goto out;
01048         }
01049 
01050         /*
01051          * Need to parse both autoneg_advertised and fc and set up
01052          * the appropriate PHY registers.  First we will parse for
01053          * autoneg_advertised software override.  Since we can advertise
01054          * a plethora of combinations, we need to check each bit
01055          * individually.
01056          */
01057 
01058         /*
01059          * First we clear all the 10/100 mb speed bits in the Auto-Neg
01060          * Advertisement Register (Address 4) and the 1000 mb speed bits in
01061          * the  1000Base-T Control Register (Address 9).
01062          */
01063         mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
01064                                  NWAY_AR_100TX_HD_CAPS |
01065                                  NWAY_AR_10T_FD_CAPS   |
01066                                  NWAY_AR_10T_HD_CAPS);
01067         mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
01068 
01069         DEBUGOUT1("autoneg_advertised %x\n", phy->autoneg_advertised);
01070 
01071         /* Do we want to advertise 10 Mb Half Duplex? */
01072         if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
01073                 DEBUGOUT("Advertise 10mb Half duplex\n");
01074                 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
01075         }
01076 
01077         /* Do we want to advertise 10 Mb Full Duplex? */
01078         if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
01079                 DEBUGOUT("Advertise 10mb Full duplex\n");
01080                 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
01081         }
01082 
01083         /* Do we want to advertise 100 Mb Half Duplex? */
01084         if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
01085                 DEBUGOUT("Advertise 100mb Half duplex\n");
01086                 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
01087         }
01088 
01089         /* Do we want to advertise 100 Mb Full Duplex? */
01090         if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
01091                 DEBUGOUT("Advertise 100mb Full duplex\n");
01092                 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
01093         }
01094 
01095         /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
01096         if (phy->autoneg_advertised & ADVERTISE_1000_HALF) {
01097                 DEBUGOUT("Advertise 1000mb Half duplex request denied!\n");
01098         }
01099         /* Do we want to advertise 1000 Mb Full Duplex? */
01100         if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
01101                 DEBUGOUT("Advertise 1000mb Full duplex\n");
01102                 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
01103         }
01104 
01105         /*
01106          * Check for a software override of the flow control settings, and
01107          * setup the PHY advertisement registers accordingly.  If
01108          * auto-negotiation is enabled, then software will have to set the
01109          * "PAUSE" bits to the correct value in the Auto-Negotiation
01110          * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
01111          * negotiation.
01112          *
01113          * The possible values of the "fc" parameter are:
01114          *      0:  Flow control is completely disabled
01115          *      1:  Rx flow control is enabled (we can receive pause frames
01116          *          but not send pause frames).
01117          *      2:  Tx flow control is enabled (we can send pause frames
01118          *          but we do not support receiving pause frames).
01119          *      3:  Both Rx and Tx flow control (symmetric) are enabled.
01120          *  other:  No software override.  The flow control configuration
01121          *          in the EEPROM is used.
01122          */
01123         switch (hw->fc.current_mode) {
01124         case e1000_fc_none:
01125                 /*
01126                  * Flow control (Rx & Tx) is completely disabled by a
01127                  * software over-ride.
01128                  */
01129                 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
01130                 break;
01131         case e1000_fc_rx_pause:
01132                 /*
01133                  * Rx Flow control is enabled, and Tx Flow control is
01134                  * disabled, by a software over-ride.
01135                  *
01136                  * Since there really isn't a way to advertise that we are
01137                  * capable of Rx Pause ONLY, we will advertise that we
01138                  * support both symmetric and asymmetric Rx PAUSE.  Later
01139                  * (in e1000_config_fc_after_link_up) we will disable the
01140                  * hw's ability to send PAUSE frames.
01141                  */
01142                 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
01143                 break;
01144         case e1000_fc_tx_pause:
01145                 /*
01146                  * Tx Flow control is enabled, and Rx Flow control is
01147                  * disabled, by a software over-ride.
01148                  */
01149                 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
01150                 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
01151                 break;
01152         case e1000_fc_full:
01153                 /*
01154                  * Flow control (both Rx and Tx) is enabled by a software
01155                  * over-ride.
01156                  */
01157                 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
01158                 break;
01159         default:
01160                 DEBUGOUT("Flow control param set incorrectly\n");
01161                 ret_val = -E1000_ERR_CONFIG;
01162                 goto out;
01163         }
01164 
01165         ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
01166         if (ret_val)
01167                 goto out;
01168 
01169         DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
01170 
01171         if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
01172                 ret_val = phy->ops.write_reg(hw,
01173                                               PHY_1000T_CTRL,
01174                                               mii_1000t_ctrl_reg);
01175                 if (ret_val)
01176                         goto out;
01177         }
01178 
01179 out:
01180         return ret_val;
01181 }
01182 
01183 /**
01184  *  igb_setup_copper_link_generic - Configure copper link settings
01185  *  @hw: pointer to the HW structure
01186  *
01187  *  Calls the appropriate function to configure the link for auto-neg or forced
01188  *  speed and duplex.  Then we check for link, once link is established calls
01189  *  to configure collision distance and flow control are called.  If link is
01190  *  not established, we return -E1000_ERR_PHY (-2).
01191  **/
01192 s32 igb_setup_copper_link_generic(struct e1000_hw *hw)
01193 {
01194         s32 ret_val;
01195         bool link;
01196 
01197         DEBUGFUNC("igb_setup_copper_link_generic");
01198 
01199         if (hw->mac.autoneg) {
01200                 /*
01201                  * Setup autoneg and flow control advertisement and perform
01202                  * autonegotiation.
01203                  */
01204                 ret_val = igb_copper_link_autoneg(hw);
01205                 if (ret_val)
01206                         goto out;
01207         } else {
01208 #if 0
01209                 /*
01210                  * PHY will be set to 10H, 10F, 100H or 100F
01211                  * depending on user settings.
01212                  */
01213                 DEBUGOUT("Forcing Speed and Duplex\n");
01214                 ret_val = hw->phy.ops.force_speed_duplex(hw);
01215                 if (ret_val) {
01216                         DEBUGOUT("Error Forcing Speed and Duplex\n");
01217                         goto out;
01218                 }
01219 #endif
01220         }
01221 
01222         /*
01223          * Check link status. Wait up to 100 microseconds for link to become
01224          * valid.
01225          */
01226         ret_val = igb_phy_has_link_generic(hw,
01227                                              COPPER_LINK_UP_LIMIT,
01228                                              10,
01229                                              &link);
01230         if (ret_val)
01231                 goto out;
01232 
01233         if (link) {
01234                 DEBUGOUT("Valid link established!!!\n");
01235                 igb_config_collision_dist_generic(hw);
01236                 ret_val = igb_config_fc_after_link_up_generic(hw);
01237         } else {
01238                 DEBUGOUT("Unable to establish link!!!\n");
01239         }
01240 
01241 out:
01242         return ret_val;
01243 }
01244 
01245 #if 0
01246 /**
01247  *  igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
01248  *  @hw: pointer to the HW structure
01249  *
01250  *  Calls the PHY setup function to force speed and duplex.  Clears the
01251  *  auto-crossover to force MDI manually.  Waits for link and returns
01252  *  successful if link up is successful, else -E1000_ERR_PHY (-2).
01253  **/
01254 s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
01255 {
01256         struct e1000_phy_info *phy = &hw->phy;
01257         s32 ret_val;
01258         u16 phy_data;
01259         bool link;
01260 
01261         DEBUGFUNC("igb_phy_force_speed_duplex_igp");
01262 
01263         ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
01264         if (ret_val)
01265                 goto out;
01266 
01267         igb_phy_force_speed_duplex_setup(hw, &phy_data);
01268 
01269         ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
01270         if (ret_val)
01271                 goto out;
01272 
01273         /*
01274          * Clear Auto-Crossover to force MDI manually.  IGP requires MDI
01275          * forced whenever speed and duplex are forced.
01276          */
01277         ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
01278         if (ret_val)
01279                 goto out;
01280 
01281         phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
01282         phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
01283 
01284         ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
01285         if (ret_val)
01286                 goto out;
01287 
01288         DEBUGOUT1("IGP PSCR: %X\n", phy_data);
01289 
01290         usec_delay(1);
01291 
01292         if (phy->autoneg_wait_to_complete) {
01293                 DEBUGOUT("Waiting for forced speed/duplex link on IGP phy.\n");
01294 
01295                 ret_val = igb_phy_has_link_generic(hw,
01296                                                      PHY_FORCE_LIMIT,
01297                                                      100000,
01298                                                      &link);
01299                 if (ret_val)
01300                         goto out;
01301 
01302                 if (!link) {
01303                         DEBUGOUT("Link taking longer than expected.\n");
01304                 }
01305                 /* Try once more */
01306                 ret_val = igb_phy_has_link_generic(hw,
01307                                                      PHY_FORCE_LIMIT,
01308                                                      100000,
01309                                                      &link);
01310                 if (ret_val)
01311                         goto out;
01312         }
01313 
01314 out:
01315         return ret_val;
01316 }
01317 #endif
01318 
01319 #if 0
01320 /**
01321  *  igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
01322  *  @hw: pointer to the HW structure
01323  *
01324  *  Calls the PHY setup function to force speed and duplex.  Clears the
01325  *  auto-crossover to force MDI manually.  Resets the PHY to commit the
01326  *  changes.  If time expires while waiting for link up, we reset the DSP.
01327  *  After reset, TX_CLK and CRS on Tx must be set.  Return successful upon
01328  *  successful completion, else return corresponding error code.
01329  **/
01330 s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
01331 {
01332         struct e1000_phy_info *phy = &hw->phy;
01333         s32 ret_val;
01334         u16 phy_data;
01335         bool link;
01336 
01337         DEBUGFUNC("igb_phy_force_speed_duplex_m88");
01338 
01339         /*
01340          * Clear Auto-Crossover to force MDI manually.  M88E1000 requires MDI
01341          * forced whenever speed and duplex are forced.
01342          */
01343         ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
01344         if (ret_val)
01345                 goto out;
01346 
01347         phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
01348         ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
01349         if (ret_val)
01350                 goto out;
01351 
01352         DEBUGOUT1("M88E1000 PSCR: %X\n", phy_data);
01353 
01354         ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
01355         if (ret_val)
01356                 goto out;
01357 
01358         igb_phy_force_speed_duplex_setup(hw, &phy_data);
01359 
01360         ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
01361         if (ret_val)
01362                 goto out;
01363 
01364         /* Reset the phy to commit changes. */
01365         ret_val = hw->phy.ops.commit(hw);
01366         if (ret_val)
01367                 goto out;
01368 
01369         if (phy->autoneg_wait_to_complete) {
01370                 DEBUGOUT("Waiting for forced speed/duplex link on M88 phy.\n");
01371 
01372                 ret_val = igb_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
01373                                                      100000, &link);
01374                 if (ret_val)
01375                         goto out;
01376 
01377                 if (!link) {
01378                         /*
01379                          * We didn't get link.
01380                          * Reset the DSP and cross our fingers.
01381                          */
01382                         ret_val = phy->ops.write_reg(hw,
01383                                                       M88E1000_PHY_PAGE_SELECT,
01384                                                       0x001d);
01385                         if (ret_val)
01386                                 goto out;
01387                         ret_val = igb_phy_reset_dsp_generic(hw);
01388                         if (ret_val)
01389                                 goto out;
01390                 }
01391 
01392                 /* Try once more */
01393                 ret_val = igb_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
01394                                                      100000, &link);
01395                 if (ret_val)
01396                         goto out;
01397         }
01398 
01399         ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
01400         if (ret_val)
01401                 goto out;
01402 
01403         /*
01404          * Resetting the phy means we need to re-force TX_CLK in the
01405          * Extended PHY Specific Control Register to 25MHz clock from
01406          * the reset value of 2.5MHz.
01407          */
01408         phy_data |= M88E1000_EPSCR_TX_CLK_25;
01409         ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
01410         if (ret_val)
01411                 goto out;
01412 
01413         /*
01414          * In addition, we must re-enable CRS on Tx for both half and full
01415          * duplex.
01416          */
01417         ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
01418         if (ret_val)
01419                 goto out;
01420 
01421         phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
01422         ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
01423 
01424 out:
01425         return ret_val;
01426 }
01427 #endif
01428 
01429 #if 0
01430 /**
01431  *  igb_phy_force_speed_duplex_ife - Force PHY speed & duplex
01432  *  @hw: pointer to the HW structure
01433  *
01434  *  Forces the speed and duplex settings of the PHY.
01435  *  This is a function pointer entry point only called by
01436  *  PHY setup routines.
01437  **/
01438 s32 igb_phy_force_speed_duplex_ife(struct e1000_hw *hw)
01439 {
01440         struct e1000_phy_info *phy = &hw->phy;
01441         s32 ret_val;
01442         u16 data;
01443         bool link;
01444 
01445         DEBUGFUNC("igb_phy_force_speed_duplex_ife");
01446 
01447         if (phy->type != e1000_phy_ife) {
01448                 ret_val = igb_phy_force_speed_duplex_igp(hw);
01449                 goto out;
01450         }
01451 
01452         ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &data);
01453         if (ret_val)
01454                 goto out;
01455 
01456         igb_phy_force_speed_duplex_setup(hw, &data);
01457 
01458         ret_val = phy->ops.write_reg(hw, PHY_CONTROL, data);
01459         if (ret_val)
01460                 goto out;
01461 
01462         /* Disable MDI-X support for 10/100 */
01463         ret_val = phy->ops.read_reg(hw, IFE_PHY_MDIX_CONTROL, &data);
01464         if (ret_val)
01465                 goto out;
01466 
01467         data &= ~IFE_PMC_AUTO_MDIX;
01468         data &= ~IFE_PMC_FORCE_MDIX;
01469 
01470         ret_val = phy->ops.write_reg(hw, IFE_PHY_MDIX_CONTROL, data);
01471         if (ret_val)
01472                 goto out;
01473 
01474         DEBUGOUT1("IFE PMC: %X\n", data);
01475 
01476         usec_delay(1);
01477 
01478         if (phy->autoneg_wait_to_complete) {
01479                 DEBUGOUT("Waiting for forced speed/duplex link on IFE phy.\n");
01480 
01481                 ret_val = igb_phy_has_link_generic(hw,
01482                                                      PHY_FORCE_LIMIT,
01483                                                      100000,
01484                                                      &link);
01485                 if (ret_val)
01486                         goto out;
01487 
01488                 if (!link) {
01489                         DEBUGOUT("Link taking longer than expected.\n");
01490                 }
01491                 /* Try once more */
01492                 ret_val = igb_phy_has_link_generic(hw,
01493                                                      PHY_FORCE_LIMIT,
01494                                                      100000,
01495                                                      &link);
01496                 if (ret_val)
01497                         goto out;
01498         }
01499 
01500 out:
01501         return ret_val;
01502 }
01503 #endif
01504 
01505 #if 0
01506 /**
01507  *  igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
01508  *  @hw: pointer to the HW structure
01509  *  @phy_ctrl: pointer to current value of PHY_CONTROL
01510  *
01511  *  Forces speed and duplex on the PHY by doing the following: disable flow
01512  *  control, force speed/duplex on the MAC, disable auto speed detection,
01513  *  disable auto-negotiation, configure duplex, configure speed, configure
01514  *  the collision distance, write configuration to CTRL register.  The
01515  *  caller must write to the PHY_CONTROL register for these settings to
01516  *  take affect.
01517  **/
01518 void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
01519 {
01520         struct e1000_mac_info *mac = &hw->mac;
01521         u32 ctrl;
01522 
01523         DEBUGFUNC("igb_phy_force_speed_duplex_setup");
01524 
01525         /* Turn off flow control when forcing speed/duplex */
01526         hw->fc.current_mode = e1000_fc_none;
01527 
01528         /* Force speed/duplex on the mac */
01529         ctrl = E1000_READ_REG(hw, E1000_CTRL);
01530         ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
01531         ctrl &= ~E1000_CTRL_SPD_SEL;
01532 
01533         /* Disable Auto Speed Detection */
01534         ctrl &= ~E1000_CTRL_ASDE;
01535 
01536         /* Disable autoneg on the phy */
01537         *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
01538 
01539         /* Forcing Full or Half Duplex? */
01540         if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
01541                 ctrl &= ~E1000_CTRL_FD;
01542                 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
01543                 DEBUGOUT("Half Duplex\n");
01544         } else {
01545                 ctrl |= E1000_CTRL_FD;
01546                 *phy_ctrl |= MII_CR_FULL_DUPLEX;
01547                 DEBUGOUT("Full Duplex\n");
01548         }
01549 
01550         /* Forcing 10mb or 100mb? */
01551         if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
01552                 ctrl |= E1000_CTRL_SPD_100;
01553                 *phy_ctrl |= MII_CR_SPEED_100;
01554                 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
01555                 DEBUGOUT("Forcing 100mb\n");
01556         } else {
01557                 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
01558                 *phy_ctrl |= MII_CR_SPEED_10;
01559                 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
01560                 DEBUGOUT("Forcing 10mb\n");
01561         }
01562 
01563         igb_config_collision_dist_generic(hw);
01564 
01565         E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
01566 }
01567 #endif
01568 
01569 /**
01570  *  igb_set_d3_lplu_state_generic - Sets low power link up state for D3
01571  *  @hw: pointer to the HW structure
01572  *  @active: boolean used to enable/disable lplu
01573  *
01574  *  Success returns 0, Failure returns 1
01575  *
01576  *  The low power link up (lplu) state is set to the power management level D3
01577  *  and SmartSpeed is disabled when active is true, else clear lplu for D3
01578  *  and enable Smartspeed.  LPLU and Smartspeed are mutually exclusive.  LPLU
01579  *  is used during Dx states where the power conservation is most important.
01580  *  During driver activity, SmartSpeed should be enabled so performance is
01581  *  maintained.
01582  **/
01583 s32 igb_set_d3_lplu_state_generic(struct e1000_hw *hw, bool active)
01584 {
01585         struct e1000_phy_info *phy = &hw->phy;
01586         s32 ret_val = E1000_SUCCESS;
01587         u16 data;
01588 
01589         DEBUGFUNC("igb_set_d3_lplu_state_generic");
01590 
01591         if (!(hw->phy.ops.read_reg))
01592                 goto out;
01593 
01594         ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
01595         if (ret_val)
01596                 goto out;
01597 
01598         if (!active) {
01599                 data &= ~IGP02E1000_PM_D3_LPLU;
01600                 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
01601                                              data);
01602                 if (ret_val)
01603                         goto out;
01604                 /*
01605                  * LPLU and SmartSpeed are mutually exclusive.  LPLU is used
01606                  * during Dx states where the power conservation is most
01607                  * important.  During driver activity we should enable
01608                  * SmartSpeed, so performance is maintained.
01609                  */
01610                 if (phy->smart_speed == e1000_smart_speed_on) {
01611                         ret_val = phy->ops.read_reg(hw,
01612                                                     IGP01E1000_PHY_PORT_CONFIG,
01613                                                     &data);
01614                         if (ret_val)
01615                                 goto out;
01616 
01617                         data |= IGP01E1000_PSCFR_SMART_SPEED;
01618                         ret_val = phy->ops.write_reg(hw,
01619                                                      IGP01E1000_PHY_PORT_CONFIG,
01620                                                      data);
01621                         if (ret_val)
01622                                 goto out;
01623                 } else if (phy->smart_speed == e1000_smart_speed_off) {
01624                         ret_val = phy->ops.read_reg(hw,
01625                                                      IGP01E1000_PHY_PORT_CONFIG,
01626                                                      &data);
01627                         if (ret_val)
01628                                 goto out;
01629 
01630                         data &= ~IGP01E1000_PSCFR_SMART_SPEED;
01631                         ret_val = phy->ops.write_reg(hw,
01632                                                      IGP01E1000_PHY_PORT_CONFIG,
01633                                                      data);
01634                         if (ret_val)
01635                                 goto out;
01636                 }
01637         } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
01638                    (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
01639                    (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
01640                 data |= IGP02E1000_PM_D3_LPLU;
01641                 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
01642                                               data);
01643                 if (ret_val)
01644                         goto out;
01645 
01646                 /* When LPLU is enabled, we should disable SmartSpeed */
01647                 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
01648                                              &data);
01649                 if (ret_val)
01650                         goto out;
01651 
01652                 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
01653                 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
01654                                               data);
01655         }
01656 
01657 out:
01658         return ret_val;
01659 }
01660 
01661 /**
01662  *  igb_check_downshift_generic - Checks whether a downshift in speed occurred
01663  *  @hw: pointer to the HW structure
01664  *
01665  *  Success returns 0, Failure returns 1
01666  *
01667  *  A downshift is detected by querying the PHY link health.
01668  **/
01669 s32 igb_check_downshift_generic(struct e1000_hw *hw)
01670 {
01671         struct e1000_phy_info *phy = &hw->phy;
01672         s32 ret_val;
01673         u16 phy_data, offset, mask;
01674 
01675         DEBUGFUNC("igb_check_downshift_generic");
01676 
01677         switch (phy->type) {
01678         case e1000_phy_m88:
01679         case e1000_phy_gg82563:
01680                 offset  = M88E1000_PHY_SPEC_STATUS;
01681                 mask    = M88E1000_PSSR_DOWNSHIFT;
01682                 break;
01683         case e1000_phy_igp_2:
01684         case e1000_phy_igp:
01685         case e1000_phy_igp_3:
01686                 offset  = IGP01E1000_PHY_LINK_HEALTH;
01687                 mask    = IGP01E1000_PLHR_SS_DOWNGRADE;
01688                 break;
01689         default:
01690                 /* speed downshift not supported */
01691                 phy->speed_downgraded = false;
01692                 ret_val = E1000_SUCCESS;
01693                 goto out;
01694         }
01695 
01696         ret_val = phy->ops.read_reg(hw, offset, &phy_data);
01697 
01698         if (!ret_val)
01699                 phy->speed_downgraded = (phy_data & mask) ? true : false;
01700 
01701 out:
01702         return ret_val;
01703 }
01704 
01705 /**
01706  *  igb_check_polarity_m88 - Checks the polarity.
01707  *  @hw: pointer to the HW structure
01708  *
01709  *  Success returns 0, Failure returns -E1000_ERR_PHY (-2)
01710  *
01711  *  Polarity is determined based on the PHY specific status register.
01712  **/
01713 s32 igb_check_polarity_m88(struct e1000_hw *hw)
01714 {
01715         struct e1000_phy_info *phy = &hw->phy;
01716         s32 ret_val;
01717         u16 data;
01718 
01719         DEBUGFUNC("igb_check_polarity_m88");
01720 
01721         ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
01722 
01723         if (!ret_val)
01724                 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
01725                                       ? e1000_rev_polarity_reversed
01726                                       : e1000_rev_polarity_normal;
01727 
01728         return ret_val;
01729 }
01730 
01731 /**
01732  *  igb_check_polarity_igp - Checks the polarity.
01733  *  @hw: pointer to the HW structure
01734  *
01735  *  Success returns 0, Failure returns -E1000_ERR_PHY (-2)
01736  *
01737  *  Polarity is determined based on the PHY port status register, and the
01738  *  current speed (since there is no polarity at 100Mbps).
01739  **/
01740 s32 igb_check_polarity_igp(struct e1000_hw *hw)
01741 {
01742         struct e1000_phy_info *phy = &hw->phy;
01743         s32 ret_val;
01744         u16 data, offset, mask;
01745 
01746         DEBUGFUNC("igb_check_polarity_igp");
01747 
01748         /*
01749          * Polarity is determined based on the speed of
01750          * our connection.
01751          */
01752         ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
01753         if (ret_val)
01754                 goto out;
01755 
01756         if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
01757             IGP01E1000_PSSR_SPEED_1000MBPS) {
01758                 offset  = IGP01E1000_PHY_PCS_INIT_REG;
01759                 mask    = IGP01E1000_PHY_POLARITY_MASK;
01760         } else {
01761                 /*
01762                  * This really only applies to 10Mbps since
01763                  * there is no polarity for 100Mbps (always 0).
01764                  */
01765                 offset  = IGP01E1000_PHY_PORT_STATUS;
01766                 mask    = IGP01E1000_PSSR_POLARITY_REVERSED;
01767         }
01768 
01769         ret_val = phy->ops.read_reg(hw, offset, &data);
01770 
01771         if (!ret_val)
01772                 phy->cable_polarity = (data & mask)
01773                                       ? e1000_rev_polarity_reversed
01774                                       : e1000_rev_polarity_normal;
01775 
01776 out:
01777         return ret_val;
01778 }
01779 
01780 /**
01781  *  igb_check_polarity_ife - Check cable polarity for IFE PHY
01782  *  @hw: pointer to the HW structure
01783  *
01784  *  Polarity is determined on the polarity reversal feature being enabled.
01785  **/
01786 s32 igb_check_polarity_ife(struct e1000_hw *hw)
01787 {
01788         struct e1000_phy_info *phy = &hw->phy;
01789         s32 ret_val;
01790         u16 phy_data, offset, mask;
01791 
01792         DEBUGFUNC("igb_check_polarity_ife");
01793 
01794         /*
01795          * Polarity is determined based on the reversal feature being enabled.
01796          */
01797         if (phy->polarity_correction) {
01798                 offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
01799                 mask = IFE_PESC_POLARITY_REVERSED;
01800         } else {
01801                 offset = IFE_PHY_SPECIAL_CONTROL;
01802                 mask = IFE_PSC_FORCE_POLARITY;
01803         }
01804 
01805         ret_val = phy->ops.read_reg(hw, offset, &phy_data);
01806 
01807         if (!ret_val)
01808                 phy->cable_polarity = (phy_data & mask)
01809                                        ? e1000_rev_polarity_reversed
01810                                        : e1000_rev_polarity_normal;
01811 
01812         return ret_val;
01813 }
01814 
01815 /**
01816  *  igb_wait_autoneg_generic - Wait for auto-neg completion
01817  *  @hw: pointer to the HW structure
01818  *
01819  *  Waits for auto-negotiation to complete or for the auto-negotiation time
01820  *  limit to expire, which ever happens first.
01821  **/
01822 s32 igb_wait_autoneg_generic(struct e1000_hw *hw)
01823 {
01824         s32 ret_val = E1000_SUCCESS;
01825         u16 i, phy_status;
01826 
01827         DEBUGFUNC("igb_wait_autoneg_generic");
01828 
01829         if (!(hw->phy.ops.read_reg))
01830                 return E1000_SUCCESS;
01831 
01832         /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
01833         for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
01834                 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
01835                 if (ret_val)
01836                         break;
01837                 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
01838                 if (ret_val)
01839                         break;
01840                 if (phy_status & MII_SR_AUTONEG_COMPLETE)
01841                         break;
01842                 msec_delay(100);
01843         }
01844 
01845         /*
01846          * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
01847          * has completed.
01848          */
01849         return ret_val;
01850 }
01851 
01852 /**
01853  *  igb_phy_has_link_generic - Polls PHY for link
01854  *  @hw: pointer to the HW structure
01855  *  @iterations: number of times to poll for link
01856  *  @usec_interval: delay between polling attempts
01857  *  @success: pointer to whether polling was successful or not
01858  *
01859  *  Polls the PHY status register for link, 'iterations' number of times.
01860  **/
01861 s32 igb_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
01862                                u32 usec_interval, bool *success)
01863 {
01864         s32 ret_val = E1000_SUCCESS;
01865         u16 i, phy_status;
01866 
01867         DEBUGFUNC("igb_phy_has_link_generic");
01868 
01869         if (!(hw->phy.ops.read_reg))
01870                 return E1000_SUCCESS;
01871 
01872         for (i = 0; i < iterations; i++) {
01873                 /*
01874                  * Some PHYs require the PHY_STATUS register to be read
01875                  * twice due to the link bit being sticky.  No harm doing
01876                  * it across the board.
01877                  */
01878                 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
01879                 if (ret_val) {
01880                         /*
01881                          * If the first read fails, another entity may have
01882                          * ownership of the resources, wait and try again to
01883                          * see if they have relinquished the resources yet.
01884                          */
01885                         usec_delay(usec_interval);
01886                 }
01887                 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
01888                 if (ret_val)
01889                         break;
01890                 if (phy_status & MII_SR_LINK_STATUS)
01891                         break;
01892                 if (usec_interval >= 1000)
01893                         msec_delay_irq(usec_interval/1000);
01894                 else
01895                         usec_delay(usec_interval);
01896         }
01897 
01898         *success = (i < iterations) ? true : false;
01899 
01900         return ret_val;
01901 }
01902 
01903 #if 0
01904 /**
01905  *  igb_get_cable_length_m88 - Determine cable length for m88 PHY
01906  *  @hw: pointer to the HW structure
01907  *
01908  *  Reads the PHY specific status register to retrieve the cable length
01909  *  information.  The cable length is determined by averaging the minimum and
01910  *  maximum values to get the "average" cable length.  The m88 PHY has four
01911  *  possible cable length values, which are:
01912  *      Register Value          Cable Length
01913  *      0                       < 50 meters
01914  *      1                       50 - 80 meters
01915  *      2                       80 - 110 meters
01916  *      3                       110 - 140 meters
01917  *      4                       > 140 meters
01918  **/
01919 s32 igb_get_cable_length_m88(struct e1000_hw *hw)
01920 {
01921         struct e1000_phy_info *phy = &hw->phy;
01922         s32 ret_val;
01923         u16 phy_data, index;
01924 
01925         DEBUGFUNC("igb_get_cable_length_m88");
01926 
01927         ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
01928         if (ret_val)
01929                 goto out;
01930 
01931         index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
01932                 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
01933         if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
01934                 ret_val = -E1000_ERR_PHY;
01935                 goto out;
01936         }
01937 
01938         phy->min_cable_length = e1000_m88_cable_length_table[index];
01939         phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
01940 
01941         phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
01942 
01943 out:
01944         return ret_val;
01945 }
01946 
01947 /**
01948  *  igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY
01949  *  @hw: pointer to the HW structure
01950  *
01951  *  The automatic gain control (agc) normalizes the amplitude of the
01952  *  received signal, adjusting for the attenuation produced by the
01953  *  cable.  By reading the AGC registers, which represent the
01954  *  combination of coarse and fine gain value, the value can be put
01955  *  into a lookup table to obtain the approximate cable length
01956  *  for each channel.
01957  **/
01958 s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
01959 {
01960         struct e1000_phy_info *phy = &hw->phy;
01961         s32 ret_val = E1000_SUCCESS;
01962         u16 phy_data, i, agc_value = 0;
01963         u16 cur_agc_index, max_agc_index = 0;
01964         u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
01965         u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
01966                                                          {IGP02E1000_PHY_AGC_A,
01967                                                           IGP02E1000_PHY_AGC_B,
01968                                                           IGP02E1000_PHY_AGC_C,
01969                                                           IGP02E1000_PHY_AGC_D};
01970 
01971         DEBUGFUNC("igb_get_cable_length_igp_2");
01972 
01973         /* Read the AGC registers for all channels */
01974         for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
01975                 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
01976                 if (ret_val)
01977                         goto out;
01978 
01979                 /*
01980                  * Getting bits 15:9, which represent the combination of
01981                  * coarse and fine gain values.  The result is a number
01982                  * that can be put into the lookup table to obtain the
01983                  * approximate cable length.
01984                  */
01985                 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
01986                                 IGP02E1000_AGC_LENGTH_MASK;
01987 
01988                 /* Array index bound check. */
01989                 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
01990                     (cur_agc_index == 0)) {
01991                         ret_val = -E1000_ERR_PHY;
01992                         goto out;
01993                 }
01994 
01995                 /* Remove min & max AGC values from calculation. */
01996                 if (e1000_igp_2_cable_length_table[min_agc_index] >
01997                     e1000_igp_2_cable_length_table[cur_agc_index])
01998                         min_agc_index = cur_agc_index;
01999                 if (e1000_igp_2_cable_length_table[max_agc_index] <
02000                     e1000_igp_2_cable_length_table[cur_agc_index])
02001                         max_agc_index = cur_agc_index;
02002 
02003                 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
02004         }
02005 
02006         agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
02007                       e1000_igp_2_cable_length_table[max_agc_index]);
02008         agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
02009 
02010         /* Calculate cable length with the error range of +/- 10 meters. */
02011         phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
02012                                  (agc_value - IGP02E1000_AGC_RANGE) : 0;
02013         phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
02014 
02015         phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
02016 
02017 out:
02018         return ret_val;
02019 }
02020 #endif
02021 
02022 /**
02023  *  igb_get_phy_info_m88 - Retrieve PHY information
02024  *  @hw: pointer to the HW structure
02025  *
02026  *  Valid for only copper links.  Read the PHY status register (sticky read)
02027  *  to verify that link is up.  Read the PHY special control register to
02028  *  determine the polarity and 10base-T extended distance.  Read the PHY
02029  *  special status register to determine MDI/MDIx and current speed.  If
02030  *  speed is 1000, then determine cable length, local and remote receiver.
02031  **/
02032 s32 igb_get_phy_info_m88(struct e1000_hw *hw)
02033 {
02034         struct e1000_phy_info *phy = &hw->phy;
02035         s32  ret_val;
02036         u16 phy_data;
02037         bool link;
02038 
02039         DEBUGFUNC("igb_get_phy_info_m88");
02040 
02041         if (phy->media_type != e1000_media_type_copper) {
02042                 DEBUGOUT("Phy info is only valid for copper media\n");
02043                 ret_val = -E1000_ERR_CONFIG;
02044                 goto out;
02045         }
02046 
02047         ret_val = igb_phy_has_link_generic(hw, 1, 0, &link);
02048         if (ret_val)
02049                 goto out;
02050 
02051         if (!link) {
02052                 DEBUGOUT("Phy info is only valid if link is up\n");
02053                 ret_val = -E1000_ERR_CONFIG;
02054                 goto out;
02055         }
02056 
02057         ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
02058         if (ret_val)
02059                 goto out;
02060 
02061         phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
02062                                    ? true : false;
02063 
02064         ret_val = igb_check_polarity_m88(hw);
02065         if (ret_val)
02066                 goto out;
02067 
02068         ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
02069         if (ret_val)
02070                 goto out;
02071 
02072         phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
02073 
02074         if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
02075 #if 0
02076                 ret_val = hw->phy.ops.get_cable_length(hw);
02077 #endif
02078                 ret_val = -E1000_ERR_CONFIG;
02079                 if (ret_val)
02080                         goto out;
02081 #if 0
02082                 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
02083                 if (ret_val)
02084                         goto out;
02085 
02086                 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
02087                                 ? e1000_1000t_rx_status_ok
02088                                 : e1000_1000t_rx_status_not_ok;
02089 
02090                 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
02091                                  ? e1000_1000t_rx_status_ok
02092                                  : e1000_1000t_rx_status_not_ok;
02093 #endif
02094         } else {
02095                 /* Set values to "undefined" */
02096                 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
02097                 phy->local_rx = e1000_1000t_rx_status_undefined;
02098                 phy->remote_rx = e1000_1000t_rx_status_undefined;
02099         }
02100 
02101 out:
02102         return ret_val;
02103 }
02104 
02105 /**
02106  *  igb_get_phy_info_igp - Retrieve igp PHY information
02107  *  @hw: pointer to the HW structure
02108  *
02109  *  Read PHY status to determine if link is up.  If link is up, then
02110  *  set/determine 10base-T extended distance and polarity correction.  Read
02111  *  PHY port status to determine MDI/MDIx and speed.  Based on the speed,
02112  *  determine on the cable length, local and remote receiver.
02113  **/
02114 s32 igb_get_phy_info_igp(struct e1000_hw *hw)
02115 {
02116         struct e1000_phy_info *phy = &hw->phy;
02117         s32 ret_val;
02118         u16 data;
02119         bool link;
02120 
02121         DEBUGFUNC("igb_get_phy_info_igp");
02122 
02123         ret_val = igb_phy_has_link_generic(hw, 1, 0, &link);
02124         if (ret_val)
02125                 goto out;
02126 
02127         if (!link) {
02128                 DEBUGOUT("Phy info is only valid if link is up\n");
02129                 ret_val = -E1000_ERR_CONFIG;
02130                 goto out;
02131         }
02132 
02133         phy->polarity_correction = true;
02134 
02135         ret_val = igb_check_polarity_igp(hw);
02136         if (ret_val)
02137                 goto out;
02138 
02139         ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
02140         if (ret_val)
02141                 goto out;
02142 
02143         phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
02144 
02145         if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
02146             IGP01E1000_PSSR_SPEED_1000MBPS) {
02147 #if 0
02148                 ret_val = phy->ops.get_cable_length(hw);
02149 #endif
02150                 ret_val = -E1000_ERR_CONFIG;
02151                 if (ret_val)
02152                         goto out;
02153 #if 0
02154                 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
02155                 if (ret_val)
02156                         goto out;
02157 
02158                 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
02159                                 ? e1000_1000t_rx_status_ok
02160                                 : e1000_1000t_rx_status_not_ok;
02161 
02162                 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
02163                                  ? e1000_1000t_rx_status_ok
02164                                  : e1000_1000t_rx_status_not_ok;
02165 #endif
02166         } else {
02167                 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
02168                 phy->local_rx = e1000_1000t_rx_status_undefined;
02169                 phy->remote_rx = e1000_1000t_rx_status_undefined;
02170         }
02171 
02172 out:
02173         return ret_val;
02174 }
02175 
02176 /**
02177  *  igb_phy_sw_reset_generic - PHY software reset
02178  *  @hw: pointer to the HW structure
02179  *
02180  *  Does a software reset of the PHY by reading the PHY control register and
02181  *  setting/write the control register reset bit to the PHY.
02182  **/
02183 s32 igb_phy_sw_reset_generic(struct e1000_hw *hw)
02184 {
02185         s32 ret_val = E1000_SUCCESS;
02186         u16 phy_ctrl;
02187 
02188         DEBUGFUNC("igb_phy_sw_reset_generic");
02189 
02190         if (!(hw->phy.ops.read_reg))
02191                 goto out;
02192 
02193         ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
02194         if (ret_val)
02195                 goto out;
02196 
02197         phy_ctrl |= MII_CR_RESET;
02198         ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
02199         if (ret_val)
02200                 goto out;
02201 
02202         usec_delay(1);
02203 
02204 out:
02205         return ret_val;
02206 }
02207 
02208 /**
02209  *  igb_phy_hw_reset_generic - PHY hardware reset
02210  *  @hw: pointer to the HW structure
02211  *
02212  *  Verify the reset block is not blocking us from resetting.  Acquire
02213  *  semaphore (if necessary) and read/set/write the device control reset
02214  *  bit in the PHY.  Wait the appropriate delay time for the device to
02215  *  reset and release the semaphore (if necessary).
02216  **/
02217 s32 igb_phy_hw_reset_generic(struct e1000_hw *hw)
02218 {
02219         struct e1000_phy_info *phy = &hw->phy;
02220         s32 ret_val = E1000_SUCCESS;
02221         u32 ctrl;
02222 
02223         DEBUGFUNC("igb_phy_hw_reset_generic");
02224 
02225         ret_val = phy->ops.check_reset_block(hw);
02226         if (ret_val) {
02227                 ret_val = E1000_SUCCESS;
02228                 goto out;
02229         }
02230 
02231         ret_val = phy->ops.acquire(hw);
02232         if (ret_val)
02233                 goto out;
02234 
02235         ctrl = E1000_READ_REG(hw, E1000_CTRL);
02236         E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
02237         E1000_WRITE_FLUSH(hw);
02238 
02239         usec_delay(phy->reset_delay_us);
02240 
02241         E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
02242         E1000_WRITE_FLUSH(hw);
02243 
02244         usec_delay(150);
02245 
02246         phy->ops.release(hw);
02247 
02248         ret_val = phy->ops.get_cfg_done(hw);
02249 
02250 out:
02251         return ret_val;
02252 }
02253 
02254 /**
02255  *  igb_get_cfg_done_generic - Generic configuration done
02256  *  @hw: pointer to the HW structure
02257  *
02258  *  Generic function to wait 10 milli-seconds for configuration to complete
02259  *  and return success.
02260  **/
02261 s32 igb_get_cfg_done_generic(struct e1000_hw *hw __unused)
02262 {
02263         DEBUGFUNC("igb_get_cfg_done_generic");
02264 
02265         msec_delay_irq(10);
02266 
02267         return E1000_SUCCESS;
02268 }
02269 
02270 /**
02271  *  igb_phy_init_script_igp3 - Inits the IGP3 PHY
02272  *  @hw: pointer to the HW structure
02273  *
02274  *  Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
02275  **/
02276 s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
02277 {
02278         DEBUGOUT("Running IGP 3 PHY init script\n");
02279 
02280         /* PHY init IGP 3 */
02281         /* Enable rise/fall, 10-mode work in class-A */
02282         hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
02283         /* Remove all caps from Replica path filter */
02284         hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
02285         /* Bias trimming for ADC, AFE and Driver (Default) */
02286         hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
02287         /* Increase Hybrid poly bias */
02288         hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
02289         /* Add 4% to Tx amplitude in Gig mode */
02290         hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
02291         /* Disable trimming (TTT) */
02292         hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
02293         /* Poly DC correction to 94.6% + 2% for all channels */
02294         hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
02295         /* ABS DC correction to 95.9% */
02296         hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
02297         /* BG temp curve trim */
02298         hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
02299         /* Increasing ADC OPAMP stage 1 currents to max */
02300         hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
02301         /* Force 1000 ( required for enabling PHY regs configuration) */
02302         hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
02303         /* Set upd_freq to 6 */
02304         hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
02305         /* Disable NPDFE */
02306         hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
02307         /* Disable adaptive fixed FFE (Default) */
02308         hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
02309         /* Enable FFE hysteresis */
02310         hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
02311         /* Fixed FFE for short cable lengths */
02312         hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
02313         /* Fixed FFE for medium cable lengths */
02314         hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
02315         /* Fixed FFE for long cable lengths */
02316         hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
02317         /* Enable Adaptive Clip Threshold */
02318         hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
02319         /* AHT reset limit to 1 */
02320         hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
02321         /* Set AHT master delay to 127 msec */
02322         hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
02323         /* Set scan bits for AHT */
02324         hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
02325         /* Set AHT Preset bits */
02326         hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
02327         /* Change integ_factor of channel A to 3 */
02328         hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
02329         /* Change prop_factor of channels BCD to 8 */
02330         hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
02331         /* Change cg_icount + enable integbp for channels BCD */
02332         hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
02333         /*
02334          * Change cg_icount + enable integbp + change prop_factor_master
02335          * to 8 for channel A
02336          */
02337         hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
02338         /* Disable AHT in Slave mode on channel A */
02339         hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
02340         /*
02341          * Enable LPLU and disable AN to 1000 in non-D0a states,
02342          * Enable SPD+B2B
02343          */
02344         hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
02345         /* Enable restart AN on an1000_dis change */
02346         hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
02347         /* Enable wh_fifo read clock in 10/100 modes */
02348         hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
02349         /* Restart AN, Speed selection is 1000 */
02350         hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
02351 
02352         return E1000_SUCCESS;
02353 }
02354 
02355 /**
02356  *  igb_get_phy_type_from_id - Get PHY type from id
02357  *  @phy_id: phy_id read from the phy
02358  *
02359  *  Returns the phy type from the id.
02360  **/
02361 enum e1000_phy_type igb_get_phy_type_from_id(u32 phy_id)
02362 {
02363         enum e1000_phy_type phy_type = e1000_phy_unknown;
02364 
02365         switch (phy_id) {
02366         case M88E1000_I_PHY_ID:
02367         case M88E1000_E_PHY_ID:
02368         case M88E1111_I_PHY_ID:
02369         case M88E1011_I_PHY_ID:
02370                 phy_type = e1000_phy_m88;
02371                 break;
02372         case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
02373                 phy_type = e1000_phy_igp_2;
02374                 break;
02375         case GG82563_E_PHY_ID:
02376                 phy_type = e1000_phy_gg82563;
02377                 break;
02378         case IGP03E1000_E_PHY_ID:
02379                 phy_type = e1000_phy_igp_3;
02380                 break;
02381         case IFE_E_PHY_ID:
02382         case IFE_PLUS_E_PHY_ID:
02383         case IFE_C_E_PHY_ID:
02384                 phy_type = e1000_phy_ife;
02385                 break;
02386         default:
02387                 phy_type = e1000_phy_unknown;
02388                 break;
02389         }
02390         return phy_type;
02391 }
02392 
02393 /**
02394  *  igb_determine_phy_address - Determines PHY address.
02395  *  @hw: pointer to the HW structure
02396  *
02397  *  This uses a trial and error method to loop through possible PHY
02398  *  addresses. It tests each by reading the PHY ID registers and
02399  *  checking for a match.
02400  **/
02401 s32 igb_determine_phy_address(struct e1000_hw *hw)
02402 {
02403         s32 ret_val = -E1000_ERR_PHY_TYPE;
02404         u32 phy_addr = 0;
02405         u32 i;
02406         enum e1000_phy_type phy_type = e1000_phy_unknown;
02407 
02408         hw->phy.id = phy_type;
02409 
02410         for (phy_addr = 0; phy_addr < E1000_MAX_PHY_ADDR; phy_addr++) {
02411                 hw->phy.addr = phy_addr;
02412                 i = 0;
02413 
02414                 do {
02415                         igb_get_phy_id(hw);
02416                         phy_type = igb_get_phy_type_from_id(hw->phy.id);
02417 
02418                         /*
02419                          * If phy_type is valid, break - we found our
02420                          * PHY address
02421                          */
02422                         if (phy_type  != e1000_phy_unknown) {
02423                                 ret_val = E1000_SUCCESS;
02424                                 goto out;
02425                         }
02426                         msec_delay(1);
02427                         i++;
02428                 } while (i < 10);
02429         }
02430 
02431 out:
02432         return ret_val;
02433 }
02434 
02435 /**
02436  * igb_power_up_phy_copper - Restore copper link in case of PHY power down
02437  * @hw: pointer to the HW structure
02438  *
02439  * In the case of a PHY power down to save power, or to turn off link during a
02440  * driver unload, or wake on lan is not enabled, restore the link to previous
02441  * settings.
02442  **/
02443 void igb_power_up_phy_copper(struct e1000_hw *hw)
02444 {
02445         u16 mii_reg = 0;
02446 
02447         /* The PHY will retain its settings across a power down/up cycle */
02448         hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
02449         mii_reg &= ~MII_CR_POWER_DOWN;
02450         hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
02451 }
02452 
02453 /**
02454  * igb_power_down_phy_copper - Restore copper link in case of PHY power down
02455  * @hw: pointer to the HW structure
02456  *
02457  * In the case of a PHY power down to save power, or to turn off link during a
02458  * driver unload, or wake on lan is not enabled, restore the link to previous
02459  * settings.
02460  **/
02461 void igb_power_down_phy_copper(struct e1000_hw *hw)
02462 {
02463         u16 mii_reg = 0;
02464 
02465         /* The PHY will retain its settings across a power down/up cycle */
02466         hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
02467         mii_reg |= MII_CR_POWER_DOWN;
02468         hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
02469         msec_delay(1);
02470 }

Generated on Tue Apr 6 20:01:01 2010 for gPXE by  doxygen 1.5.7.1