| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* | 
|  | 2 |  | 
| Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 3 | Intel PRO/1000 Linux driver | 
|  | 4 | Copyright(c) 1999 - 2006 Intel Corporation. | 
|  | 5 |  | 
|  | 6 | This program is free software; you can redistribute it and/or modify it | 
|  | 7 | under the terms and conditions of the GNU General Public License, | 
|  | 8 | version 2, as published by the Free Software Foundation. | 
|  | 9 |  | 
|  | 10 | This program is distributed in the hope it will be useful, but WITHOUT | 
|  | 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 
|  | 12 | FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | more details. | 
| Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 14 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | You should have received a copy of the GNU General Public License along with | 
| Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 16 | this program; if not, write to the Free Software Foundation, Inc., | 
|  | 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | 
|  | 18 |  | 
|  | 19 | The full GNU General Public License is included in this distribution in | 
|  | 20 | the file called "COPYING". | 
|  | 21 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | Contact Information: | 
|  | 23 | Linux NICS <linux.nics@intel.com> | 
| Auke Kok | 3d41e30 | 2006-04-14 19:05:31 -0700 | [diff] [blame] | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | 
|  | 26 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 27 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 |  | 
|  | 29 | /* e1000_hw.c | 
|  | 30 | * Shared functions for accessing and configuring the MAC | 
|  | 31 | */ | 
|  | 32 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 33 | #include "e1000.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 |  | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 35 | static s32 e1000_check_downshift(struct e1000_hw *hw); | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 36 | static s32 e1000_check_polarity(struct e1000_hw *hw, | 
|  | 37 | e1000_rev_polarity *polarity); | 
| Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 38 | static void e1000_clear_hw_cntrs(struct e1000_hw *hw); | 
|  | 39 | static void e1000_clear_vfta(struct e1000_hw *hw); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 40 | static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 41 | bool link_up); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 42 | static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw); | 
|  | 43 | static s32 e1000_detect_gig_phy(struct e1000_hw *hw); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 44 | static s32 e1000_get_auto_rd_done(struct e1000_hw *hw); | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 45 | static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length, | 
|  | 46 | u16 *max_length); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 47 | static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 48 | static s32 e1000_id_led_init(struct e1000_hw *hw); | 
| Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 49 | static void e1000_init_rx_addrs(struct e1000_hw *hw); | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 50 | static s32 e1000_phy_igp_get_info(struct e1000_hw *hw, | 
|  | 51 | struct e1000_phy_info *phy_info); | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 52 | static s32 e1000_phy_m88_get_info(struct e1000_hw *hw, | 
|  | 53 | struct e1000_phy_info *phy_info); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 54 | static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 55 | static s32 e1000_wait_autoneg(struct e1000_hw *hw); | 
|  | 56 | static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value); | 
|  | 57 | static s32 e1000_set_phy_type(struct e1000_hw *hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | static void e1000_phy_init_script(struct e1000_hw *hw); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 59 | static s32 e1000_setup_copper_link(struct e1000_hw *hw); | 
|  | 60 | static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw); | 
|  | 61 | static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw); | 
|  | 62 | static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw); | 
|  | 63 | static s32 e1000_config_mac_to_phy(struct e1000_hw *hw); | 
|  | 64 | static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl); | 
|  | 65 | static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 66 | static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 67 | static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw); | 
|  | 68 | static s32 e1000_phy_reset_dsp(struct e1000_hw *hw); | 
|  | 69 | static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 70 | u16 words, u16 *data); | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 71 | static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset, | 
|  | 72 | u16 words, u16 *data); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 73 | static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw); | 
|  | 74 | static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd); | 
|  | 75 | static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd); | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 76 | static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 77 | static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 78 | u16 phy_data); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 79 | static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 80 | u16 *phy_data); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 81 | static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count); | 
|  | 82 | static s32 e1000_acquire_eeprom(struct e1000_hw *hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | static void e1000_release_eeprom(struct e1000_hw *hw); | 
|  | 84 | static void e1000_standby_eeprom(struct e1000_hw *hw); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 85 | static s32 e1000_set_vco_speed(struct e1000_hw *hw); | 
|  | 86 | static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw); | 
|  | 87 | static s32 e1000_set_phy_mode(struct e1000_hw *hw); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 88 | static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, | 
|  | 89 | u16 *data); | 
|  | 90 | static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, | 
|  | 91 | u16 *data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 |  | 
|  | 93 | /* IGP cable length table */ | 
|  | 94 | static const | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 95 | u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = { | 
|  | 96 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | 
|  | 97 | 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25, | 
|  | 98 | 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40, | 
|  | 99 | 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, | 
|  | 100 | 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90, | 
|  | 101 | 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, | 
|  | 102 | 100, | 
|  | 103 | 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, | 
|  | 104 | 110, 110, | 
|  | 105 | 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, | 
|  | 106 | 120, 120 | 
|  | 107 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 |  | 
| Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 109 | static DEFINE_SPINLOCK(e1000_eeprom_lock); | 
|  | 110 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 111 | /** | 
|  | 112 | * e1000_set_phy_type - Set the phy type member in the hw struct. | 
|  | 113 | * @hw: Struct containing variables accessed by shared code | 
|  | 114 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 115 | static s32 e1000_set_phy_type(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 117 | e_dbg("e1000_set_phy_type"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 119 | if (hw->mac_type == e1000_undefined) | 
|  | 120 | return -E1000_ERR_PHY_TYPE; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 121 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 122 | switch (hw->phy_id) { | 
|  | 123 | case M88E1000_E_PHY_ID: | 
|  | 124 | case M88E1000_I_PHY_ID: | 
|  | 125 | case M88E1011_I_PHY_ID: | 
|  | 126 | case M88E1111_I_PHY_ID: | 
| Florian Fainelli | cf8e09b | 2011-01-24 14:48:03 +0000 | [diff] [blame] | 127 | case M88E1118_E_PHY_ID: | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 128 | hw->phy_type = e1000_phy_m88; | 
|  | 129 | break; | 
|  | 130 | case IGP01E1000_I_PHY_ID: | 
|  | 131 | if (hw->mac_type == e1000_82541 || | 
|  | 132 | hw->mac_type == e1000_82541_rev_2 || | 
|  | 133 | hw->mac_type == e1000_82547 || | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 134 | hw->mac_type == e1000_82547_rev_2) | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 135 | hw->phy_type = e1000_phy_igp; | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 136 | break; | 
|  | 137 | case RTL8211B_PHY_ID: | 
|  | 138 | hw->phy_type = e1000_phy_8211; | 
|  | 139 | break; | 
|  | 140 | case RTL8201N_PHY_ID: | 
|  | 141 | hw->phy_type = e1000_phy_8201; | 
|  | 142 | break; | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 143 | default: | 
|  | 144 | /* Should never have loaded on this device */ | 
|  | 145 | hw->phy_type = e1000_phy_undefined; | 
|  | 146 | return -E1000_ERR_PHY_TYPE; | 
|  | 147 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 149 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } | 
|  | 151 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 152 | /** | 
|  | 153 | * e1000_phy_init_script - IGP phy init script - initializes the GbE PHY | 
|  | 154 | * @hw: Struct containing variables accessed by shared code | 
|  | 155 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 156 | static void e1000_phy_init_script(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 158 | u32 ret_val; | 
|  | 159 | u16 phy_saved_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 161 | e_dbg("e1000_phy_init_script"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 163 | if (hw->phy_init_script) { | 
|  | 164 | msleep(20); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 166 | /* Save off the current value of register 0x2F5B to be restored at | 
|  | 167 | * the end of this routine. */ | 
|  | 168 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 170 | /* Disabled the PHY transmitter */ | 
|  | 171 | e1000_write_phy_reg(hw, 0x2F5B, 0x0003); | 
|  | 172 | msleep(20); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 174 | e1000_write_phy_reg(hw, 0x0000, 0x0140); | 
|  | 175 | msleep(5); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 177 | switch (hw->mac_type) { | 
|  | 178 | case e1000_82541: | 
|  | 179 | case e1000_82547: | 
|  | 180 | e1000_write_phy_reg(hw, 0x1F95, 0x0001); | 
|  | 181 | e1000_write_phy_reg(hw, 0x1F71, 0xBD21); | 
|  | 182 | e1000_write_phy_reg(hw, 0x1F79, 0x0018); | 
|  | 183 | e1000_write_phy_reg(hw, 0x1F30, 0x1600); | 
|  | 184 | e1000_write_phy_reg(hw, 0x1F31, 0x0014); | 
|  | 185 | e1000_write_phy_reg(hw, 0x1F32, 0x161C); | 
|  | 186 | e1000_write_phy_reg(hw, 0x1F94, 0x0003); | 
|  | 187 | e1000_write_phy_reg(hw, 0x1F96, 0x003F); | 
|  | 188 | e1000_write_phy_reg(hw, 0x2010, 0x0008); | 
|  | 189 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 191 | case e1000_82541_rev_2: | 
|  | 192 | case e1000_82547_rev_2: | 
|  | 193 | e1000_write_phy_reg(hw, 0x1F73, 0x0099); | 
|  | 194 | break; | 
|  | 195 | default: | 
|  | 196 | break; | 
|  | 197 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 199 | e1000_write_phy_reg(hw, 0x0000, 0x3300); | 
|  | 200 | msleep(20); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 202 | /* Now enable the transmitter */ | 
|  | 203 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 205 | if (hw->mac_type == e1000_82547) { | 
|  | 206 | u16 fused, fine, coarse; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 208 | /* Move to analog registers page */ | 
|  | 209 | e1000_read_phy_reg(hw, | 
|  | 210 | IGP01E1000_ANALOG_SPARE_FUSE_STATUS, | 
|  | 211 | &fused); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 213 | if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) { | 
|  | 214 | e1000_read_phy_reg(hw, | 
|  | 215 | IGP01E1000_ANALOG_FUSE_STATUS, | 
|  | 216 | &fused); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 218 | fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK; | 
|  | 219 | coarse = | 
|  | 220 | fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 222 | if (coarse > | 
|  | 223 | IGP01E1000_ANALOG_FUSE_COARSE_THRESH) { | 
|  | 224 | coarse -= | 
|  | 225 | IGP01E1000_ANALOG_FUSE_COARSE_10; | 
|  | 226 | fine -= IGP01E1000_ANALOG_FUSE_FINE_1; | 
|  | 227 | } else if (coarse == | 
|  | 228 | IGP01E1000_ANALOG_FUSE_COARSE_THRESH) | 
|  | 229 | fine -= IGP01E1000_ANALOG_FUSE_FINE_10; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 231 | fused = | 
|  | 232 | (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) | | 
|  | 233 | (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) | | 
|  | 234 | (coarse & | 
|  | 235 | IGP01E1000_ANALOG_FUSE_COARSE_MASK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 237 | e1000_write_phy_reg(hw, | 
|  | 238 | IGP01E1000_ANALOG_FUSE_CONTROL, | 
|  | 239 | fused); | 
|  | 240 | e1000_write_phy_reg(hw, | 
|  | 241 | IGP01E1000_ANALOG_FUSE_BYPASS, | 
|  | 242 | IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL); | 
|  | 243 | } | 
|  | 244 | } | 
|  | 245 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } | 
|  | 247 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 248 | /** | 
|  | 249 | * e1000_set_mac_type - Set the mac type member in the hw struct. | 
|  | 250 | * @hw: Struct containing variables accessed by shared code | 
|  | 251 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 252 | s32 e1000_set_mac_type(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 254 | e_dbg("e1000_set_mac_type"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 |  | 
| Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 256 | switch (hw->device_id) { | 
|  | 257 | case E1000_DEV_ID_82542: | 
|  | 258 | switch (hw->revision_id) { | 
|  | 259 | case E1000_82542_2_0_REV_ID: | 
|  | 260 | hw->mac_type = e1000_82542_rev2_0; | 
|  | 261 | break; | 
|  | 262 | case E1000_82542_2_1_REV_ID: | 
|  | 263 | hw->mac_type = e1000_82542_rev2_1; | 
|  | 264 | break; | 
|  | 265 | default: | 
|  | 266 | /* Invalid 82542 revision ID */ | 
|  | 267 | return -E1000_ERR_MAC_TYPE; | 
|  | 268 | } | 
|  | 269 | break; | 
|  | 270 | case E1000_DEV_ID_82543GC_FIBER: | 
|  | 271 | case E1000_DEV_ID_82543GC_COPPER: | 
|  | 272 | hw->mac_type = e1000_82543; | 
|  | 273 | break; | 
|  | 274 | case E1000_DEV_ID_82544EI_COPPER: | 
|  | 275 | case E1000_DEV_ID_82544EI_FIBER: | 
|  | 276 | case E1000_DEV_ID_82544GC_COPPER: | 
|  | 277 | case E1000_DEV_ID_82544GC_LOM: | 
|  | 278 | hw->mac_type = e1000_82544; | 
|  | 279 | break; | 
|  | 280 | case E1000_DEV_ID_82540EM: | 
|  | 281 | case E1000_DEV_ID_82540EM_LOM: | 
|  | 282 | case E1000_DEV_ID_82540EP: | 
|  | 283 | case E1000_DEV_ID_82540EP_LOM: | 
|  | 284 | case E1000_DEV_ID_82540EP_LP: | 
|  | 285 | hw->mac_type = e1000_82540; | 
|  | 286 | break; | 
|  | 287 | case E1000_DEV_ID_82545EM_COPPER: | 
|  | 288 | case E1000_DEV_ID_82545EM_FIBER: | 
|  | 289 | hw->mac_type = e1000_82545; | 
|  | 290 | break; | 
|  | 291 | case E1000_DEV_ID_82545GM_COPPER: | 
|  | 292 | case E1000_DEV_ID_82545GM_FIBER: | 
|  | 293 | case E1000_DEV_ID_82545GM_SERDES: | 
|  | 294 | hw->mac_type = e1000_82545_rev_3; | 
|  | 295 | break; | 
|  | 296 | case E1000_DEV_ID_82546EB_COPPER: | 
|  | 297 | case E1000_DEV_ID_82546EB_FIBER: | 
|  | 298 | case E1000_DEV_ID_82546EB_QUAD_COPPER: | 
|  | 299 | hw->mac_type = e1000_82546; | 
|  | 300 | break; | 
|  | 301 | case E1000_DEV_ID_82546GB_COPPER: | 
|  | 302 | case E1000_DEV_ID_82546GB_FIBER: | 
|  | 303 | case E1000_DEV_ID_82546GB_SERDES: | 
|  | 304 | case E1000_DEV_ID_82546GB_PCIE: | 
|  | 305 | case E1000_DEV_ID_82546GB_QUAD_COPPER: | 
|  | 306 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: | 
|  | 307 | hw->mac_type = e1000_82546_rev_3; | 
|  | 308 | break; | 
|  | 309 | case E1000_DEV_ID_82541EI: | 
|  | 310 | case E1000_DEV_ID_82541EI_MOBILE: | 
|  | 311 | case E1000_DEV_ID_82541ER_LOM: | 
|  | 312 | hw->mac_type = e1000_82541; | 
|  | 313 | break; | 
|  | 314 | case E1000_DEV_ID_82541ER: | 
|  | 315 | case E1000_DEV_ID_82541GI: | 
|  | 316 | case E1000_DEV_ID_82541GI_LF: | 
|  | 317 | case E1000_DEV_ID_82541GI_MOBILE: | 
|  | 318 | hw->mac_type = e1000_82541_rev_2; | 
|  | 319 | break; | 
|  | 320 | case E1000_DEV_ID_82547EI: | 
|  | 321 | case E1000_DEV_ID_82547EI_MOBILE: | 
|  | 322 | hw->mac_type = e1000_82547; | 
|  | 323 | break; | 
|  | 324 | case E1000_DEV_ID_82547GI: | 
|  | 325 | hw->mac_type = e1000_82547_rev_2; | 
|  | 326 | break; | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 327 | case E1000_DEV_ID_INTEL_CE4100_GBE: | 
|  | 328 | hw->mac_type = e1000_ce4100; | 
|  | 329 | break; | 
| Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 330 | default: | 
|  | 331 | /* Should never have loaded on this device */ | 
|  | 332 | return -E1000_ERR_MAC_TYPE; | 
|  | 333 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 |  | 
| Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 335 | switch (hw->mac_type) { | 
| Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 336 | case e1000_82541: | 
|  | 337 | case e1000_82547: | 
|  | 338 | case e1000_82541_rev_2: | 
|  | 339 | case e1000_82547_rev_2: | 
| Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 340 | hw->asf_firmware_present = true; | 
| Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 341 | break; | 
|  | 342 | default: | 
|  | 343 | break; | 
|  | 344 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 |  | 
| Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 346 | /* The 82543 chip does not count tx_carrier_errors properly in | 
|  | 347 | * FD mode | 
|  | 348 | */ | 
|  | 349 | if (hw->mac_type == e1000_82543) | 
| Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 350 | hw->bad_tx_carr_stats_fd = true; | 
| Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 351 |  | 
| Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 352 | if (hw->mac_type > e1000_82544) | 
| Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 353 | hw->has_smbus = true; | 
| Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 354 |  | 
| Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 355 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } | 
|  | 357 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 358 | /** | 
|  | 359 | * e1000_set_media_type - Set media type and TBI compatibility. | 
|  | 360 | * @hw: Struct containing variables accessed by shared code | 
|  | 361 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 362 | void e1000_set_media_type(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 364 | u32 status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 366 | e_dbg("e1000_set_media_type"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 368 | if (hw->mac_type != e1000_82543) { | 
|  | 369 | /* tbi_compatibility is only valid on 82543 */ | 
|  | 370 | hw->tbi_compatibility_en = false; | 
|  | 371 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 373 | switch (hw->device_id) { | 
|  | 374 | case E1000_DEV_ID_82545GM_SERDES: | 
|  | 375 | case E1000_DEV_ID_82546GB_SERDES: | 
|  | 376 | hw->media_type = e1000_media_type_internal_serdes; | 
|  | 377 | break; | 
|  | 378 | default: | 
|  | 379 | switch (hw->mac_type) { | 
|  | 380 | case e1000_82542_rev2_0: | 
|  | 381 | case e1000_82542_rev2_1: | 
|  | 382 | hw->media_type = e1000_media_type_fiber; | 
|  | 383 | break; | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 384 | case e1000_ce4100: | 
|  | 385 | hw->media_type = e1000_media_type_copper; | 
|  | 386 | break; | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 387 | default: | 
|  | 388 | status = er32(STATUS); | 
|  | 389 | if (status & E1000_STATUS_TBIMODE) { | 
|  | 390 | hw->media_type = e1000_media_type_fiber; | 
|  | 391 | /* tbi_compatibility not valid on fiber */ | 
|  | 392 | hw->tbi_compatibility_en = false; | 
|  | 393 | } else { | 
|  | 394 | hw->media_type = e1000_media_type_copper; | 
|  | 395 | } | 
|  | 396 | break; | 
|  | 397 | } | 
|  | 398 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } | 
|  | 400 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 401 | /** | 
|  | 402 | * e1000_reset_hw: reset the hardware completely | 
|  | 403 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | * | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 405 | * Reset the transmit and receive units; mask and clear all interrupts. | 
|  | 406 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 407 | s32 e1000_reset_hw(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 409 | u32 ctrl; | 
|  | 410 | u32 ctrl_ext; | 
|  | 411 | u32 icr; | 
|  | 412 | u32 manc; | 
|  | 413 | u32 led_ctrl; | 
|  | 414 | s32 ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 416 | e_dbg("e1000_reset_hw"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 418 | /* For 82542 (rev 2.0), disable MWI before issuing a device reset */ | 
|  | 419 | if (hw->mac_type == e1000_82542_rev2_0) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 420 | e_dbg("Disabling MWI on 82542 rev 2.0\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 421 | e1000_pci_clear_mwi(hw); | 
|  | 422 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 424 | /* Clear interrupt mask to stop board from generating interrupts */ | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 425 | e_dbg("Masking off all interrupts\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 426 | ew32(IMC, 0xffffffff); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 428 | /* Disable the Transmit and Receive units.  Then delay to allow | 
|  | 429 | * any pending transactions to complete before we hit the MAC with | 
|  | 430 | * the global reset. | 
|  | 431 | */ | 
|  | 432 | ew32(RCTL, 0); | 
|  | 433 | ew32(TCTL, E1000_TCTL_PSP); | 
|  | 434 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 436 | /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */ | 
|  | 437 | hw->tbi_compatibility_on = false; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 439 | /* Delay to allow any outstanding PCI transactions to complete before | 
|  | 440 | * resetting the device | 
|  | 441 | */ | 
|  | 442 | msleep(10); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 444 | ctrl = er32(CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 446 | /* Must reset the PHY before resetting the MAC */ | 
|  | 447 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { | 
|  | 448 | ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST)); | 
|  | 449 | msleep(5); | 
|  | 450 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 452 | /* Issue a global reset to the MAC.  This will reset the chip's | 
|  | 453 | * transmit, receive, DMA, and link units.  It will not effect | 
|  | 454 | * the current PCI configuration.  The global reset bit is self- | 
|  | 455 | * clearing, and should clear within a microsecond. | 
|  | 456 | */ | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 457 | e_dbg("Issuing a global reset to MAC\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 459 | switch (hw->mac_type) { | 
|  | 460 | case e1000_82544: | 
|  | 461 | case e1000_82540: | 
|  | 462 | case e1000_82545: | 
|  | 463 | case e1000_82546: | 
|  | 464 | case e1000_82541: | 
|  | 465 | case e1000_82541_rev_2: | 
|  | 466 | /* These controllers can't ack the 64-bit write when issuing the | 
|  | 467 | * reset, so use IO-mapping as a workaround to issue the reset */ | 
|  | 468 | E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST)); | 
|  | 469 | break; | 
|  | 470 | case e1000_82545_rev_3: | 
|  | 471 | case e1000_82546_rev_3: | 
|  | 472 | /* Reset is performed on a shadow of the control register */ | 
|  | 473 | ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST)); | 
|  | 474 | break; | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 475 | case e1000_ce4100: | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 476 | default: | 
|  | 477 | ew32(CTRL, (ctrl | E1000_CTRL_RST)); | 
|  | 478 | break; | 
|  | 479 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 481 | /* After MAC reset, force reload of EEPROM to restore power-on settings to | 
|  | 482 | * device.  Later controllers reload the EEPROM automatically, so just wait | 
|  | 483 | * for reload to complete. | 
|  | 484 | */ | 
|  | 485 | switch (hw->mac_type) { | 
|  | 486 | case e1000_82542_rev2_0: | 
|  | 487 | case e1000_82542_rev2_1: | 
|  | 488 | case e1000_82543: | 
|  | 489 | case e1000_82544: | 
|  | 490 | /* Wait for reset to complete */ | 
|  | 491 | udelay(10); | 
|  | 492 | ctrl_ext = er32(CTRL_EXT); | 
|  | 493 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; | 
|  | 494 | ew32(CTRL_EXT, ctrl_ext); | 
|  | 495 | E1000_WRITE_FLUSH(); | 
|  | 496 | /* Wait for EEPROM reload */ | 
|  | 497 | msleep(2); | 
|  | 498 | break; | 
|  | 499 | case e1000_82541: | 
|  | 500 | case e1000_82541_rev_2: | 
|  | 501 | case e1000_82547: | 
|  | 502 | case e1000_82547_rev_2: | 
|  | 503 | /* Wait for EEPROM reload */ | 
|  | 504 | msleep(20); | 
|  | 505 | break; | 
|  | 506 | default: | 
|  | 507 | /* Auto read done will delay 5ms or poll based on mac type */ | 
|  | 508 | ret_val = e1000_get_auto_rd_done(hw); | 
|  | 509 | if (ret_val) | 
|  | 510 | return ret_val; | 
|  | 511 | break; | 
|  | 512 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 514 | /* Disable HW ARPs on ASF enabled adapters */ | 
|  | 515 | if (hw->mac_type >= e1000_82540) { | 
|  | 516 | manc = er32(MANC); | 
|  | 517 | manc &= ~(E1000_MANC_ARP_EN); | 
|  | 518 | ew32(MANC, manc); | 
|  | 519 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 521 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { | 
|  | 522 | e1000_phy_init_script(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 524 | /* Configure activity LED after PHY reset */ | 
|  | 525 | led_ctrl = er32(LEDCTL); | 
|  | 526 | led_ctrl &= IGP_ACTIVITY_LED_MASK; | 
|  | 527 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); | 
|  | 528 | ew32(LEDCTL, led_ctrl); | 
|  | 529 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 531 | /* Clear interrupt mask to stop board from generating interrupts */ | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 532 | e_dbg("Masking off all interrupts\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 533 | ew32(IMC, 0xffffffff); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 535 | /* Clear any pending interrupt events. */ | 
|  | 536 | icr = er32(ICR); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 538 | /* If MWI was previously enabled, reenable it. */ | 
|  | 539 | if (hw->mac_type == e1000_82542_rev2_0) { | 
|  | 540 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) | 
|  | 541 | e1000_pci_set_mwi(hw); | 
|  | 542 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 544 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | } | 
|  | 546 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 547 | /** | 
|  | 548 | * e1000_init_hw: Performs basic configuration of the adapter. | 
|  | 549 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | * | 
|  | 551 | * Assumes that the controller has previously been reset and is in a | 
|  | 552 | * post-reset uninitialized state. Initializes the receive address registers, | 
|  | 553 | * multicast table, and VLAN filter table. Calls routines to setup link | 
|  | 554 | * configuration and flow control settings. Clears all on-chip counters. Leaves | 
|  | 555 | * the transmit and receive units disabled and uninitialized. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 556 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 557 | s32 e1000_init_hw(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 559 | u32 ctrl; | 
|  | 560 | u32 i; | 
|  | 561 | s32 ret_val; | 
|  | 562 | u32 mta_size; | 
|  | 563 | u32 ctrl_ext; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 564 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 565 | e_dbg("e1000_init_hw"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 567 | /* Initialize Identification LED */ | 
|  | 568 | ret_val = e1000_id_led_init(hw); | 
|  | 569 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 570 | e_dbg("Error Initializing Identification LED\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 571 | return ret_val; | 
|  | 572 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 574 | /* Set the media type and TBI compatibility */ | 
|  | 575 | e1000_set_media_type(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 577 | /* Disabling VLAN filtering. */ | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 578 | e_dbg("Initializing the IEEE VLAN\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 579 | if (hw->mac_type < e1000_82545_rev_3) | 
|  | 580 | ew32(VET, 0); | 
|  | 581 | e1000_clear_vfta(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 583 | /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */ | 
|  | 584 | if (hw->mac_type == e1000_82542_rev2_0) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 585 | e_dbg("Disabling MWI on 82542 rev 2.0\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 586 | e1000_pci_clear_mwi(hw); | 
|  | 587 | ew32(RCTL, E1000_RCTL_RST); | 
|  | 588 | E1000_WRITE_FLUSH(); | 
|  | 589 | msleep(5); | 
|  | 590 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 592 | /* Setup the receive address. This involves initializing all of the Receive | 
|  | 593 | * Address Registers (RARs 0 - 15). | 
|  | 594 | */ | 
|  | 595 | e1000_init_rx_addrs(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 597 | /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */ | 
|  | 598 | if (hw->mac_type == e1000_82542_rev2_0) { | 
|  | 599 | ew32(RCTL, 0); | 
|  | 600 | E1000_WRITE_FLUSH(); | 
|  | 601 | msleep(1); | 
|  | 602 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) | 
|  | 603 | e1000_pci_set_mwi(hw); | 
|  | 604 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 606 | /* Zero out the Multicast HASH table */ | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 607 | e_dbg("Zeroing the MTA\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 608 | mta_size = E1000_MC_TBL_SIZE; | 
|  | 609 | for (i = 0; i < mta_size; i++) { | 
|  | 610 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); | 
|  | 611 | /* use write flush to prevent Memory Write Block (MWB) from | 
|  | 612 | * occurring when accessing our register space */ | 
|  | 613 | E1000_WRITE_FLUSH(); | 
|  | 614 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 616 | /* Set the PCI priority bit correctly in the CTRL register.  This | 
|  | 617 | * determines if the adapter gives priority to receives, or if it | 
|  | 618 | * gives equal priority to transmits and receives.  Valid only on | 
|  | 619 | * 82542 and 82543 silicon. | 
|  | 620 | */ | 
|  | 621 | if (hw->dma_fairness && hw->mac_type <= e1000_82543) { | 
|  | 622 | ctrl = er32(CTRL); | 
|  | 623 | ew32(CTRL, ctrl | E1000_CTRL_PRIOR); | 
|  | 624 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 626 | switch (hw->mac_type) { | 
|  | 627 | case e1000_82545_rev_3: | 
|  | 628 | case e1000_82546_rev_3: | 
|  | 629 | break; | 
|  | 630 | default: | 
|  | 631 | /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */ | 
|  | 632 | if (hw->bus_type == e1000_bus_type_pcix | 
|  | 633 | && e1000_pcix_get_mmrbc(hw) > 2048) | 
|  | 634 | e1000_pcix_set_mmrbc(hw, 2048); | 
|  | 635 | break; | 
|  | 636 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 638 | /* Call a subroutine to configure the link and setup flow control. */ | 
|  | 639 | ret_val = e1000_setup_link(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 641 | /* Set the transmit descriptor write-back policy */ | 
|  | 642 | if (hw->mac_type > e1000_82544) { | 
|  | 643 | ctrl = er32(TXDCTL); | 
|  | 644 | ctrl = | 
|  | 645 | (ctrl & ~E1000_TXDCTL_WTHRESH) | | 
|  | 646 | E1000_TXDCTL_FULL_TX_DESC_WB; | 
|  | 647 | ew32(TXDCTL, ctrl); | 
|  | 648 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 650 | /* Clear all of the statistics registers (clear on read).  It is | 
|  | 651 | * important that we do this after we have tried to establish link | 
|  | 652 | * because the symbol error count will increment wildly if there | 
|  | 653 | * is no link. | 
|  | 654 | */ | 
|  | 655 | e1000_clear_hw_cntrs(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 657 | if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER || | 
|  | 658 | hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) { | 
|  | 659 | ctrl_ext = er32(CTRL_EXT); | 
|  | 660 | /* Relaxed ordering must be disabled to avoid a parity | 
|  | 661 | * error crash in a PCI slot. */ | 
|  | 662 | ctrl_ext |= E1000_CTRL_EXT_RO_DIS; | 
|  | 663 | ew32(CTRL_EXT, ctrl_ext); | 
|  | 664 | } | 
| Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 665 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 666 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | } | 
|  | 668 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 669 | /** | 
|  | 670 | * e1000_adjust_serdes_amplitude - Adjust SERDES output amplitude based on EEPROM setting. | 
|  | 671 | * @hw: Struct containing variables accessed by shared code. | 
|  | 672 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 673 | static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 675 | u16 eeprom_data; | 
|  | 676 | s32 ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 678 | e_dbg("e1000_adjust_serdes_amplitude"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 680 | if (hw->media_type != e1000_media_type_internal_serdes) | 
|  | 681 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 683 | switch (hw->mac_type) { | 
|  | 684 | case e1000_82545_rev_3: | 
|  | 685 | case e1000_82546_rev_3: | 
|  | 686 | break; | 
|  | 687 | default: | 
|  | 688 | return E1000_SUCCESS; | 
|  | 689 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 691 | ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, | 
|  | 692 | &eeprom_data); | 
|  | 693 | if (ret_val) { | 
|  | 694 | return ret_val; | 
|  | 695 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 697 | if (eeprom_data != EEPROM_RESERVED_WORD) { | 
|  | 698 | /* Adjust SERDES output amplitude only. */ | 
|  | 699 | eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK; | 
|  | 700 | ret_val = | 
|  | 701 | e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data); | 
|  | 702 | if (ret_val) | 
|  | 703 | return ret_val; | 
|  | 704 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 706 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | } | 
|  | 708 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 709 | /** | 
|  | 710 | * e1000_setup_link - Configures flow control and link settings. | 
|  | 711 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | * | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 713 | * Determines which flow control settings to use. Calls the appropriate media- | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | * specific link configuration function. Configures the flow control settings. | 
|  | 715 | * Assuming the adapter has a valid link partner, a valid link should be | 
|  | 716 | * established. Assumes the hardware has previously been reset and the | 
|  | 717 | * transmitter and receiver are not enabled. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 718 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 719 | s32 e1000_setup_link(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 721 | u32 ctrl_ext; | 
|  | 722 | s32 ret_val; | 
|  | 723 | u16 eeprom_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 725 | e_dbg("e1000_setup_link"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 727 | /* Read and store word 0x0F of the EEPROM. This word contains bits | 
|  | 728 | * that determine the hardware's default PAUSE (flow control) mode, | 
|  | 729 | * a bit that determines whether the HW defaults to enabling or | 
|  | 730 | * disabling auto-negotiation, and the direction of the | 
|  | 731 | * SW defined pins. If there is no SW over-ride of the flow | 
|  | 732 | * control setting, then the variable hw->fc will | 
|  | 733 | * be initialized based on a value in the EEPROM. | 
|  | 734 | */ | 
|  | 735 | if (hw->fc == E1000_FC_DEFAULT) { | 
|  | 736 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, | 
|  | 737 | 1, &eeprom_data); | 
|  | 738 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 739 | e_dbg("EEPROM Read Error\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 740 | return -E1000_ERR_EEPROM; | 
|  | 741 | } | 
|  | 742 | if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0) | 
|  | 743 | hw->fc = E1000_FC_NONE; | 
|  | 744 | else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == | 
|  | 745 | EEPROM_WORD0F_ASM_DIR) | 
|  | 746 | hw->fc = E1000_FC_TX_PAUSE; | 
|  | 747 | else | 
|  | 748 | hw->fc = E1000_FC_FULL; | 
|  | 749 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 751 | /* We want to save off the original Flow Control configuration just | 
|  | 752 | * in case we get disconnected and then reconnected into a different | 
|  | 753 | * hub or switch with different Flow Control capabilities. | 
|  | 754 | */ | 
|  | 755 | if (hw->mac_type == e1000_82542_rev2_0) | 
|  | 756 | hw->fc &= (~E1000_FC_TX_PAUSE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 758 | if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1)) | 
|  | 759 | hw->fc &= (~E1000_FC_RX_PAUSE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 761 | hw->original_fc = hw->fc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 763 | e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 765 | /* Take the 4 bits from EEPROM word 0x0F that determine the initial | 
|  | 766 | * polarity value for the SW controlled pins, and setup the | 
|  | 767 | * Extended Device Control reg with that info. | 
|  | 768 | * This is needed because one of the SW controlled pins is used for | 
|  | 769 | * signal detection.  So this should be done before e1000_setup_pcs_link() | 
|  | 770 | * or e1000_phy_setup() is called. | 
|  | 771 | */ | 
|  | 772 | if (hw->mac_type == e1000_82543) { | 
|  | 773 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, | 
|  | 774 | 1, &eeprom_data); | 
|  | 775 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 776 | e_dbg("EEPROM Read Error\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 777 | return -E1000_ERR_EEPROM; | 
|  | 778 | } | 
|  | 779 | ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) << | 
|  | 780 | SWDPIO__EXT_SHIFT); | 
|  | 781 | ew32(CTRL_EXT, ctrl_ext); | 
|  | 782 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 784 | /* Call the necessary subroutine to configure the link. */ | 
|  | 785 | ret_val = (hw->media_type == e1000_media_type_copper) ? | 
|  | 786 | e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 788 | /* Initialize the flow control address, type, and PAUSE timer | 
|  | 789 | * registers to their default values.  This is done even if flow | 
|  | 790 | * control is disabled, because it does not hurt anything to | 
|  | 791 | * initialize these registers. | 
|  | 792 | */ | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 793 | e_dbg("Initializing the Flow Control address, type and timer regs\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 795 | ew32(FCT, FLOW_CONTROL_TYPE); | 
|  | 796 | ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH); | 
|  | 797 | ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 798 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 799 | ew32(FCTTV, hw->fc_pause_time); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 801 | /* Set the flow control receive threshold registers.  Normally, | 
|  | 802 | * these registers will be set to a default threshold that may be | 
|  | 803 | * adjusted later by the driver's runtime code.  However, if the | 
|  | 804 | * ability to transmit pause frames in not enabled, then these | 
|  | 805 | * registers will be set to 0. | 
|  | 806 | */ | 
|  | 807 | if (!(hw->fc & E1000_FC_TX_PAUSE)) { | 
|  | 808 | ew32(FCRTL, 0); | 
|  | 809 | ew32(FCRTH, 0); | 
|  | 810 | } else { | 
|  | 811 | /* We need to set up the Receive Threshold high and low water marks | 
|  | 812 | * as well as (optionally) enabling the transmission of XON frames. | 
|  | 813 | */ | 
|  | 814 | if (hw->fc_send_xon) { | 
|  | 815 | ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE)); | 
|  | 816 | ew32(FCRTH, hw->fc_high_water); | 
|  | 817 | } else { | 
|  | 818 | ew32(FCRTL, hw->fc_low_water); | 
|  | 819 | ew32(FCRTH, hw->fc_high_water); | 
|  | 820 | } | 
|  | 821 | } | 
|  | 822 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | } | 
|  | 824 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 825 | /** | 
|  | 826 | * e1000_setup_fiber_serdes_link - prepare fiber or serdes link | 
|  | 827 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | * | 
|  | 829 | * Manipulates Physical Coding Sublayer functions in order to configure | 
|  | 830 | * link. Assumes the hardware has been previously reset and the transmitter | 
|  | 831 | * and receiver are not enabled. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 832 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 833 | static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 835 | u32 ctrl; | 
|  | 836 | u32 status; | 
|  | 837 | u32 txcw = 0; | 
|  | 838 | u32 i; | 
|  | 839 | u32 signal = 0; | 
|  | 840 | s32 ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 842 | e_dbg("e1000_setup_fiber_serdes_link"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 844 | /* On adapters with a MAC newer than 82544, SWDP 1 will be | 
|  | 845 | * set when the optics detect a signal. On older adapters, it will be | 
|  | 846 | * cleared when there is a signal.  This applies to fiber media only. | 
|  | 847 | * If we're on serdes media, adjust the output amplitude to value | 
|  | 848 | * set in the EEPROM. | 
|  | 849 | */ | 
|  | 850 | ctrl = er32(CTRL); | 
|  | 851 | if (hw->media_type == e1000_media_type_fiber) | 
|  | 852 | signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 854 | ret_val = e1000_adjust_serdes_amplitude(hw); | 
|  | 855 | if (ret_val) | 
|  | 856 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 858 | /* Take the link out of reset */ | 
|  | 859 | ctrl &= ~(E1000_CTRL_LRST); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 861 | /* Adjust VCO speed to improve BER performance */ | 
|  | 862 | ret_val = e1000_set_vco_speed(hw); | 
|  | 863 | if (ret_val) | 
|  | 864 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 866 | e1000_config_collision_dist(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 868 | /* Check for a software override of the flow control settings, and setup | 
|  | 869 | * the device accordingly.  If auto-negotiation is enabled, then software | 
|  | 870 | * will have to set the "PAUSE" bits to the correct value in the Tranmsit | 
|  | 871 | * Config Word Register (TXCW) and re-start auto-negotiation.  However, if | 
|  | 872 | * auto-negotiation is disabled, then software will have to manually | 
|  | 873 | * configure the two flow control enable bits in the CTRL register. | 
|  | 874 | * | 
|  | 875 | * The possible values of the "fc" parameter are: | 
|  | 876 | *      0:  Flow control is completely disabled | 
|  | 877 | *      1:  Rx flow control is enabled (we can receive pause frames, but | 
|  | 878 | *          not send pause frames). | 
|  | 879 | *      2:  Tx flow control is enabled (we can send pause frames but we do | 
|  | 880 | *          not support receiving pause frames). | 
|  | 881 | *      3:  Both Rx and TX flow control (symmetric) are enabled. | 
|  | 882 | */ | 
|  | 883 | switch (hw->fc) { | 
|  | 884 | case E1000_FC_NONE: | 
|  | 885 | /* Flow control is completely disabled by a software over-ride. */ | 
|  | 886 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); | 
|  | 887 | break; | 
|  | 888 | case E1000_FC_RX_PAUSE: | 
|  | 889 | /* RX Flow control is enabled and TX Flow control is disabled by a | 
|  | 890 | * software over-ride. Since there really isn't a way to advertise | 
|  | 891 | * that we are capable of RX Pause ONLY, we will advertise that we | 
|  | 892 | * support both symmetric and asymmetric RX PAUSE. Later, we will | 
|  | 893 | *  disable the adapter's ability to send PAUSE frames. | 
|  | 894 | */ | 
|  | 895 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); | 
|  | 896 | break; | 
|  | 897 | case E1000_FC_TX_PAUSE: | 
|  | 898 | /* TX Flow control is enabled, and RX Flow control is disabled, by a | 
|  | 899 | * software over-ride. | 
|  | 900 | */ | 
|  | 901 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); | 
|  | 902 | break; | 
|  | 903 | case E1000_FC_FULL: | 
|  | 904 | /* Flow control (both RX and TX) is enabled by a software over-ride. */ | 
|  | 905 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); | 
|  | 906 | break; | 
|  | 907 | default: | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 908 | e_dbg("Flow control param set incorrectly\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 909 | return -E1000_ERR_CONFIG; | 
|  | 910 | break; | 
|  | 911 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 913 | /* Since auto-negotiation is enabled, take the link out of reset (the link | 
|  | 914 | * will be in reset, because we previously reset the chip). This will | 
|  | 915 | * restart auto-negotiation.  If auto-negotiation is successful then the | 
|  | 916 | * link-up status bit will be set and the flow control enable bits (RFCE | 
|  | 917 | * and TFCE) will be set according to their negotiated value. | 
|  | 918 | */ | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 919 | e_dbg("Auto-negotiation enabled\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 921 | ew32(TXCW, txcw); | 
|  | 922 | ew32(CTRL, ctrl); | 
|  | 923 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 925 | hw->txcw = txcw; | 
|  | 926 | msleep(1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 928 | /* If we have a signal (the cable is plugged in) then poll for a "Link-Up" | 
|  | 929 | * indication in the Device Status Register.  Time-out if a link isn't | 
|  | 930 | * seen in 500 milliseconds seconds (Auto-negotiation should complete in | 
|  | 931 | * less than 500 milliseconds even if the other end is doing it in SW). | 
|  | 932 | * For internal serdes, we just assume a signal is present, then poll. | 
|  | 933 | */ | 
|  | 934 | if (hw->media_type == e1000_media_type_internal_serdes || | 
|  | 935 | (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 936 | e_dbg("Looking for Link\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 937 | for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) { | 
|  | 938 | msleep(10); | 
|  | 939 | status = er32(STATUS); | 
|  | 940 | if (status & E1000_STATUS_LU) | 
|  | 941 | break; | 
|  | 942 | } | 
|  | 943 | if (i == (LINK_UP_TIMEOUT / 10)) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 944 | e_dbg("Never got a valid link from auto-neg!!!\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 945 | hw->autoneg_failed = 1; | 
|  | 946 | /* AutoNeg failed to achieve a link, so we'll call | 
|  | 947 | * e1000_check_for_link. This routine will force the link up if | 
|  | 948 | * we detect a signal. This will allow us to communicate with | 
|  | 949 | * non-autonegotiating link partners. | 
|  | 950 | */ | 
|  | 951 | ret_val = e1000_check_for_link(hw); | 
|  | 952 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 953 | e_dbg("Error while checking for link\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 954 | return ret_val; | 
|  | 955 | } | 
|  | 956 | hw->autoneg_failed = 0; | 
|  | 957 | } else { | 
|  | 958 | hw->autoneg_failed = 0; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 959 | e_dbg("Valid Link Found\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 960 | } | 
|  | 961 | } else { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 962 | e_dbg("No Signal Detected\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 963 | } | 
|  | 964 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | } | 
|  | 966 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 967 | /** | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 968 | * e1000_copper_link_rtl_setup - Copper link setup for e1000_phy_rtl series. | 
|  | 969 | * @hw: Struct containing variables accessed by shared code | 
|  | 970 | * | 
|  | 971 | * Commits changes to PHY configuration by calling e1000_phy_reset(). | 
|  | 972 | */ | 
|  | 973 | static s32 e1000_copper_link_rtl_setup(struct e1000_hw *hw) | 
|  | 974 | { | 
|  | 975 | s32 ret_val; | 
|  | 976 |  | 
|  | 977 | /* SW reset the PHY so all changes take effect */ | 
|  | 978 | ret_val = e1000_phy_reset(hw); | 
|  | 979 | if (ret_val) { | 
|  | 980 | e_dbg("Error Resetting the PHY\n"); | 
|  | 981 | return ret_val; | 
|  | 982 | } | 
|  | 983 |  | 
|  | 984 | return E1000_SUCCESS; | 
|  | 985 | } | 
|  | 986 |  | 
|  | 987 | static s32 gbe_dhg_phy_setup(struct e1000_hw *hw) | 
|  | 988 | { | 
|  | 989 | s32 ret_val; | 
|  | 990 | u32 ctrl_aux; | 
|  | 991 |  | 
|  | 992 | switch (hw->phy_type) { | 
|  | 993 | case e1000_phy_8211: | 
|  | 994 | ret_val = e1000_copper_link_rtl_setup(hw); | 
|  | 995 | if (ret_val) { | 
|  | 996 | e_dbg("e1000_copper_link_rtl_setup failed!\n"); | 
|  | 997 | return ret_val; | 
|  | 998 | } | 
|  | 999 | break; | 
|  | 1000 | case e1000_phy_8201: | 
|  | 1001 | /* Set RMII mode */ | 
|  | 1002 | ctrl_aux = er32(CTL_AUX); | 
|  | 1003 | ctrl_aux |= E1000_CTL_AUX_RMII; | 
|  | 1004 | ew32(CTL_AUX, ctrl_aux); | 
|  | 1005 | E1000_WRITE_FLUSH(); | 
|  | 1006 |  | 
|  | 1007 | /* Disable the J/K bits required for receive */ | 
|  | 1008 | ctrl_aux = er32(CTL_AUX); | 
|  | 1009 | ctrl_aux |= 0x4; | 
|  | 1010 | ctrl_aux &= ~0x2; | 
|  | 1011 | ew32(CTL_AUX, ctrl_aux); | 
|  | 1012 | E1000_WRITE_FLUSH(); | 
|  | 1013 | ret_val = e1000_copper_link_rtl_setup(hw); | 
|  | 1014 |  | 
|  | 1015 | if (ret_val) { | 
|  | 1016 | e_dbg("e1000_copper_link_rtl_setup failed!\n"); | 
|  | 1017 | return ret_val; | 
|  | 1018 | } | 
|  | 1019 | break; | 
|  | 1020 | default: | 
|  | 1021 | e_dbg("Error Resetting the PHY\n"); | 
|  | 1022 | return E1000_ERR_PHY_TYPE; | 
|  | 1023 | } | 
|  | 1024 |  | 
|  | 1025 | return E1000_SUCCESS; | 
|  | 1026 | } | 
|  | 1027 |  | 
|  | 1028 | /** | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1029 | * e1000_copper_link_preconfig - early configuration for copper | 
|  | 1030 | * @hw: Struct containing variables accessed by shared code | 
|  | 1031 | * | 
|  | 1032 | * Make sure we have a valid PHY and change PHY mode before link setup. | 
|  | 1033 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1034 | static s32 e1000_copper_link_preconfig(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1036 | u32 ctrl; | 
|  | 1037 | s32 ret_val; | 
|  | 1038 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1040 | e_dbg("e1000_copper_link_preconfig"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1042 | ctrl = er32(CTRL); | 
|  | 1043 | /* With 82543, we need to force speed and duplex on the MAC equal to what | 
|  | 1044 | * the PHY speed and duplex configuration is. In addition, we need to | 
|  | 1045 | * perform a hardware reset on the PHY to take it out of reset. | 
|  | 1046 | */ | 
|  | 1047 | if (hw->mac_type > e1000_82543) { | 
|  | 1048 | ctrl |= E1000_CTRL_SLU; | 
|  | 1049 | ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); | 
|  | 1050 | ew32(CTRL, ctrl); | 
|  | 1051 | } else { | 
|  | 1052 | ctrl |= | 
|  | 1053 | (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU); | 
|  | 1054 | ew32(CTRL, ctrl); | 
|  | 1055 | ret_val = e1000_phy_hw_reset(hw); | 
|  | 1056 | if (ret_val) | 
|  | 1057 | return ret_val; | 
|  | 1058 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1060 | /* Make sure we have a valid PHY */ | 
|  | 1061 | ret_val = e1000_detect_gig_phy(hw); | 
|  | 1062 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1063 | e_dbg("Error, did not detect valid phy.\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1064 | return ret_val; | 
|  | 1065 | } | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1066 | e_dbg("Phy ID = %x\n", hw->phy_id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1068 | /* Set PHY to class A mode (if necessary) */ | 
|  | 1069 | ret_val = e1000_set_phy_mode(hw); | 
|  | 1070 | if (ret_val) | 
|  | 1071 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1073 | if ((hw->mac_type == e1000_82545_rev_3) || | 
|  | 1074 | (hw->mac_type == e1000_82546_rev_3)) { | 
|  | 1075 | ret_val = | 
|  | 1076 | e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); | 
|  | 1077 | phy_data |= 0x00000008; | 
|  | 1078 | ret_val = | 
|  | 1079 | e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); | 
|  | 1080 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1082 | if (hw->mac_type <= e1000_82543 || | 
|  | 1083 | hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 || | 
|  | 1084 | hw->mac_type == e1000_82541_rev_2 | 
|  | 1085 | || hw->mac_type == e1000_82547_rev_2) | 
|  | 1086 | hw->phy_reset_disable = false; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1088 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1089 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1091 | /** | 
|  | 1092 | * e1000_copper_link_igp_setup - Copper link setup for e1000_phy_igp series. | 
|  | 1093 | * @hw: Struct containing variables accessed by shared code | 
|  | 1094 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1095 | static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1096 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1097 | u32 led_ctrl; | 
|  | 1098 | s32 ret_val; | 
|  | 1099 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1101 | e_dbg("e1000_copper_link_igp_setup"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1103 | if (hw->phy_reset_disable) | 
|  | 1104 | return E1000_SUCCESS; | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1105 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1106 | ret_val = e1000_phy_reset(hw); | 
|  | 1107 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1108 | e_dbg("Error Resetting the PHY\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1109 | return ret_val; | 
|  | 1110 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1112 | /* Wait 15ms for MAC to configure PHY from eeprom settings */ | 
|  | 1113 | msleep(15); | 
|  | 1114 | /* Configure activity LED after PHY reset */ | 
|  | 1115 | led_ctrl = er32(LEDCTL); | 
|  | 1116 | led_ctrl &= IGP_ACTIVITY_LED_MASK; | 
|  | 1117 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); | 
|  | 1118 | ew32(LEDCTL, led_ctrl); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1119 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1120 | /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */ | 
|  | 1121 | if (hw->phy_type == e1000_phy_igp) { | 
|  | 1122 | /* disable lplu d3 during driver init */ | 
|  | 1123 | ret_val = e1000_set_d3_lplu_state(hw, false); | 
|  | 1124 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1125 | e_dbg("Error Disabling LPLU D3\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1126 | return ret_val; | 
|  | 1127 | } | 
|  | 1128 | } | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1129 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1130 | /* Configure mdi-mdix settings */ | 
|  | 1131 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); | 
|  | 1132 | if (ret_val) | 
|  | 1133 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1134 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1135 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { | 
|  | 1136 | hw->dsp_config_state = e1000_dsp_config_disabled; | 
|  | 1137 | /* Force MDI for earlier revs of the IGP PHY */ | 
|  | 1138 | phy_data &= | 
|  | 1139 | ~(IGP01E1000_PSCR_AUTO_MDIX | | 
|  | 1140 | IGP01E1000_PSCR_FORCE_MDI_MDIX); | 
|  | 1141 | hw->mdix = 1; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1142 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1143 | } else { | 
|  | 1144 | hw->dsp_config_state = e1000_dsp_config_enabled; | 
|  | 1145 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1146 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1147 | switch (hw->mdix) { | 
|  | 1148 | case 1: | 
|  | 1149 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; | 
|  | 1150 | break; | 
|  | 1151 | case 2: | 
|  | 1152 | phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX; | 
|  | 1153 | break; | 
|  | 1154 | case 0: | 
|  | 1155 | default: | 
|  | 1156 | phy_data |= IGP01E1000_PSCR_AUTO_MDIX; | 
|  | 1157 | break; | 
|  | 1158 | } | 
|  | 1159 | } | 
|  | 1160 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); | 
|  | 1161 | if (ret_val) | 
|  | 1162 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1163 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1164 | /* set auto-master slave resolution settings */ | 
|  | 1165 | if (hw->autoneg) { | 
|  | 1166 | e1000_ms_type phy_ms_setting = hw->master_slave; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1167 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1168 | if (hw->ffe_config_state == e1000_ffe_config_active) | 
|  | 1169 | hw->ffe_config_state = e1000_ffe_config_enabled; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1170 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1171 | if (hw->dsp_config_state == e1000_dsp_config_activated) | 
|  | 1172 | hw->dsp_config_state = e1000_dsp_config_enabled; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1173 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1174 | /* when autonegotiation advertisement is only 1000Mbps then we | 
|  | 1175 | * should disable SmartSpeed and enable Auto MasterSlave | 
|  | 1176 | * resolution as hardware default. */ | 
|  | 1177 | if (hw->autoneg_advertised == ADVERTISE_1000_FULL) { | 
|  | 1178 | /* Disable SmartSpeed */ | 
|  | 1179 | ret_val = | 
|  | 1180 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 1181 | &phy_data); | 
|  | 1182 | if (ret_val) | 
|  | 1183 | return ret_val; | 
|  | 1184 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; | 
|  | 1185 | ret_val = | 
|  | 1186 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 1187 | phy_data); | 
|  | 1188 | if (ret_val) | 
|  | 1189 | return ret_val; | 
|  | 1190 | /* Set auto Master/Slave resolution process */ | 
|  | 1191 | ret_val = | 
|  | 1192 | e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); | 
|  | 1193 | if (ret_val) | 
|  | 1194 | return ret_val; | 
|  | 1195 | phy_data &= ~CR_1000T_MS_ENABLE; | 
|  | 1196 | ret_val = | 
|  | 1197 | e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); | 
|  | 1198 | if (ret_val) | 
|  | 1199 | return ret_val; | 
|  | 1200 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1202 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); | 
|  | 1203 | if (ret_val) | 
|  | 1204 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1206 | /* load defaults for future use */ | 
|  | 1207 | hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ? | 
|  | 1208 | ((phy_data & CR_1000T_MS_VALUE) ? | 
|  | 1209 | e1000_ms_force_master : | 
|  | 1210 | e1000_ms_force_slave) : e1000_ms_auto; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1212 | switch (phy_ms_setting) { | 
|  | 1213 | case e1000_ms_force_master: | 
|  | 1214 | phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE); | 
|  | 1215 | break; | 
|  | 1216 | case e1000_ms_force_slave: | 
|  | 1217 | phy_data |= CR_1000T_MS_ENABLE; | 
|  | 1218 | phy_data &= ~(CR_1000T_MS_VALUE); | 
|  | 1219 | break; | 
|  | 1220 | case e1000_ms_auto: | 
|  | 1221 | phy_data &= ~CR_1000T_MS_ENABLE; | 
|  | 1222 | default: | 
|  | 1223 | break; | 
|  | 1224 | } | 
|  | 1225 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); | 
|  | 1226 | if (ret_val) | 
|  | 1227 | return ret_val; | 
|  | 1228 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1230 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1231 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1233 | /** | 
|  | 1234 | * e1000_copper_link_mgp_setup - Copper link setup for e1000_phy_m88 series. | 
|  | 1235 | * @hw: Struct containing variables accessed by shared code | 
|  | 1236 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1237 | static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1238 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1239 | s32 ret_val; | 
|  | 1240 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1242 | e_dbg("e1000_copper_link_mgp_setup"); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1243 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1244 | if (hw->phy_reset_disable) | 
|  | 1245 | return E1000_SUCCESS; | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1246 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1247 | /* Enable CRS on TX. This must be set for half-duplex operation. */ | 
|  | 1248 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); | 
|  | 1249 | if (ret_val) | 
|  | 1250 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1251 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1252 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1253 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1254 | /* Options: | 
|  | 1255 | *   MDI/MDI-X = 0 (default) | 
|  | 1256 | *   0 - Auto for all speeds | 
|  | 1257 | *   1 - MDI mode | 
|  | 1258 | *   2 - MDI-X mode | 
|  | 1259 | *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) | 
|  | 1260 | */ | 
|  | 1261 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1262 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1263 | switch (hw->mdix) { | 
|  | 1264 | case 1: | 
|  | 1265 | phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE; | 
|  | 1266 | break; | 
|  | 1267 | case 2: | 
|  | 1268 | phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE; | 
|  | 1269 | break; | 
|  | 1270 | case 3: | 
|  | 1271 | phy_data |= M88E1000_PSCR_AUTO_X_1000T; | 
|  | 1272 | break; | 
|  | 1273 | case 0: | 
|  | 1274 | default: | 
|  | 1275 | phy_data |= M88E1000_PSCR_AUTO_X_MODE; | 
|  | 1276 | break; | 
|  | 1277 | } | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1278 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1279 | /* Options: | 
|  | 1280 | *   disable_polarity_correction = 0 (default) | 
|  | 1281 | *       Automatic Correction for Reversed Cable Polarity | 
|  | 1282 | *   0 - Disabled | 
|  | 1283 | *   1 - Enabled | 
|  | 1284 | */ | 
|  | 1285 | phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL; | 
|  | 1286 | if (hw->disable_polarity_correction == 1) | 
|  | 1287 | phy_data |= M88E1000_PSCR_POLARITY_REVERSAL; | 
|  | 1288 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); | 
|  | 1289 | if (ret_val) | 
|  | 1290 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1291 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1292 | if (hw->phy_revision < M88E1011_I_REV_4) { | 
|  | 1293 | /* Force TX_CLK in the Extended PHY Specific Control Register | 
|  | 1294 | * to 25MHz clock. | 
|  | 1295 | */ | 
|  | 1296 | ret_val = | 
|  | 1297 | e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, | 
|  | 1298 | &phy_data); | 
|  | 1299 | if (ret_val) | 
|  | 1300 | return ret_val; | 
| Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1301 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1302 | phy_data |= M88E1000_EPSCR_TX_CLK_25; | 
| Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1303 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1304 | if ((hw->phy_revision == E1000_REVISION_2) && | 
|  | 1305 | (hw->phy_id == M88E1111_I_PHY_ID)) { | 
|  | 1306 | /* Vidalia Phy, set the downshift counter to 5x */ | 
|  | 1307 | phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK); | 
|  | 1308 | phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X; | 
|  | 1309 | ret_val = e1000_write_phy_reg(hw, | 
|  | 1310 | M88E1000_EXT_PHY_SPEC_CTRL, | 
|  | 1311 | phy_data); | 
|  | 1312 | if (ret_val) | 
|  | 1313 | return ret_val; | 
|  | 1314 | } else { | 
|  | 1315 | /* Configure Master and Slave downshift values */ | 
|  | 1316 | phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK | | 
|  | 1317 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK); | 
|  | 1318 | phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X | | 
|  | 1319 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X); | 
|  | 1320 | ret_val = e1000_write_phy_reg(hw, | 
|  | 1321 | M88E1000_EXT_PHY_SPEC_CTRL, | 
|  | 1322 | phy_data); | 
|  | 1323 | if (ret_val) | 
|  | 1324 | return ret_val; | 
|  | 1325 | } | 
|  | 1326 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1328 | /* SW Reset the PHY so all changes take effect */ | 
|  | 1329 | ret_val = e1000_phy_reset(hw); | 
|  | 1330 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1331 | e_dbg("Error Resetting the PHY\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1332 | return ret_val; | 
|  | 1333 | } | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1334 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1335 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1336 | } | 
|  | 1337 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1338 | /** | 
|  | 1339 | * e1000_copper_link_autoneg - setup auto-neg | 
|  | 1340 | * @hw: Struct containing variables accessed by shared code | 
|  | 1341 | * | 
|  | 1342 | * Setup auto-negotiation and flow control advertisements, | 
|  | 1343 | * and then perform auto-negotiation. | 
|  | 1344 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1345 | static s32 e1000_copper_link_autoneg(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1346 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1347 | s32 ret_val; | 
|  | 1348 | u16 phy_data; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1349 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1350 | e_dbg("e1000_copper_link_autoneg"); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1351 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1352 | /* Perform some bounds checking on the hw->autoneg_advertised | 
|  | 1353 | * parameter.  If this variable is zero, then set it to the default. | 
|  | 1354 | */ | 
|  | 1355 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1356 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1357 | /* If autoneg_advertised is zero, we assume it was not defaulted | 
|  | 1358 | * by the calling code so we set to advertise full capability. | 
|  | 1359 | */ | 
|  | 1360 | if (hw->autoneg_advertised == 0) | 
|  | 1361 | hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1362 |  | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1363 | /* IFE/RTL8201N PHY only supports 10/100 */ | 
|  | 1364 | if (hw->phy_type == e1000_phy_8201) | 
|  | 1365 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL; | 
|  | 1366 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1367 | e_dbg("Reconfiguring auto-neg advertisement params\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1368 | ret_val = e1000_phy_setup_autoneg(hw); | 
|  | 1369 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1370 | e_dbg("Error Setting up Auto-Negotiation\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1371 | return ret_val; | 
|  | 1372 | } | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1373 | e_dbg("Restarting Auto-Neg\n"); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1374 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1375 | /* Restart auto-negotiation by setting the Auto Neg Enable bit and | 
|  | 1376 | * the Auto Neg Restart bit in the PHY control register. | 
|  | 1377 | */ | 
|  | 1378 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); | 
|  | 1379 | if (ret_val) | 
|  | 1380 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1381 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1382 | phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); | 
|  | 1383 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); | 
|  | 1384 | if (ret_val) | 
|  | 1385 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1386 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1387 | /* Does the user want to wait for Auto-Neg to complete here, or | 
|  | 1388 | * check at a later time (for example, callback routine). | 
|  | 1389 | */ | 
|  | 1390 | if (hw->wait_autoneg_complete) { | 
|  | 1391 | ret_val = e1000_wait_autoneg(hw); | 
|  | 1392 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1393 | e_dbg | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1394 | ("Error while waiting for autoneg to complete\n"); | 
|  | 1395 | return ret_val; | 
|  | 1396 | } | 
|  | 1397 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1399 | hw->get_link_status = true; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1401 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1402 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1404 | /** | 
|  | 1405 | * e1000_copper_link_postconfig - post link setup | 
|  | 1406 | * @hw: Struct containing variables accessed by shared code | 
|  | 1407 | * | 
|  | 1408 | * Config the MAC and the PHY after link is up. | 
|  | 1409 | *   1) Set up the MAC to the current PHY speed/duplex | 
|  | 1410 | *      if we are on 82543.  If we | 
|  | 1411 | *      are on newer silicon, we only need to configure | 
|  | 1412 | *      collision distance in the Transmit Control Register. | 
|  | 1413 | *   2) Set up flow control on the MAC to that established with | 
|  | 1414 | *      the link partner. | 
|  | 1415 | *   3) Config DSP to improve Gigabit link quality for some PHY revisions. | 
|  | 1416 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1417 | static s32 e1000_copper_link_postconfig(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1418 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1419 | s32 ret_val; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1420 | e_dbg("e1000_copper_link_postconfig"); | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1421 |  | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1422 | if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100)) { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1423 | e1000_config_collision_dist(hw); | 
|  | 1424 | } else { | 
|  | 1425 | ret_val = e1000_config_mac_to_phy(hw); | 
|  | 1426 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1427 | e_dbg("Error configuring MAC to PHY settings\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1428 | return ret_val; | 
|  | 1429 | } | 
|  | 1430 | } | 
|  | 1431 | ret_val = e1000_config_fc_after_link_up(hw); | 
|  | 1432 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1433 | e_dbg("Error Configuring Flow Control\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1434 | return ret_val; | 
|  | 1435 | } | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1436 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1437 | /* Config DSP to improve Giga link quality */ | 
|  | 1438 | if (hw->phy_type == e1000_phy_igp) { | 
|  | 1439 | ret_val = e1000_config_dsp_after_link_change(hw, true); | 
|  | 1440 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1441 | e_dbg("Error Configuring DSP after link up\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1442 | return ret_val; | 
|  | 1443 | } | 
|  | 1444 | } | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1445 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1446 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1447 | } | 
|  | 1448 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1449 | /** | 
|  | 1450 | * e1000_setup_copper_link - phy/speed/duplex setting | 
|  | 1451 | * @hw: Struct containing variables accessed by shared code | 
|  | 1452 | * | 
|  | 1453 | * Detects which PHY is present and sets up the speed and duplex | 
|  | 1454 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1455 | static s32 e1000_setup_copper_link(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1456 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1457 | s32 ret_val; | 
|  | 1458 | u16 i; | 
|  | 1459 | u16 phy_data; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1460 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1461 | e_dbg("e1000_setup_copper_link"); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1462 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1463 | /* Check if it is a valid PHY and set PHY mode if necessary. */ | 
|  | 1464 | ret_val = e1000_copper_link_preconfig(hw); | 
|  | 1465 | if (ret_val) | 
|  | 1466 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1467 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1468 | if (hw->phy_type == e1000_phy_igp) { | 
|  | 1469 | ret_val = e1000_copper_link_igp_setup(hw); | 
|  | 1470 | if (ret_val) | 
|  | 1471 | return ret_val; | 
|  | 1472 | } else if (hw->phy_type == e1000_phy_m88) { | 
|  | 1473 | ret_val = e1000_copper_link_mgp_setup(hw); | 
|  | 1474 | if (ret_val) | 
|  | 1475 | return ret_val; | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1476 | } else { | 
|  | 1477 | ret_val = gbe_dhg_phy_setup(hw); | 
|  | 1478 | if (ret_val) { | 
|  | 1479 | e_dbg("gbe_dhg_phy_setup failed!\n"); | 
|  | 1480 | return ret_val; | 
|  | 1481 | } | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1482 | } | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1483 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1484 | if (hw->autoneg) { | 
|  | 1485 | /* Setup autoneg and flow control advertisement | 
|  | 1486 | * and perform autonegotiation */ | 
|  | 1487 | ret_val = e1000_copper_link_autoneg(hw); | 
|  | 1488 | if (ret_val) | 
|  | 1489 | return ret_val; | 
|  | 1490 | } else { | 
|  | 1491 | /* PHY will be set to 10H, 10F, 100H,or 100F | 
|  | 1492 | * depending on value from forced_speed_duplex. */ | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1493 | e_dbg("Forcing speed and duplex\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1494 | ret_val = e1000_phy_force_speed_duplex(hw); | 
|  | 1495 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1496 | e_dbg("Error Forcing Speed and Duplex\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1497 | return ret_val; | 
|  | 1498 | } | 
|  | 1499 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1501 | /* Check link status. Wait up to 100 microseconds for link to become | 
|  | 1502 | * valid. | 
|  | 1503 | */ | 
|  | 1504 | for (i = 0; i < 10; i++) { | 
|  | 1505 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 1506 | if (ret_val) | 
|  | 1507 | return ret_val; | 
|  | 1508 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 1509 | if (ret_val) | 
|  | 1510 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1512 | if (phy_data & MII_SR_LINK_STATUS) { | 
|  | 1513 | /* Config the MAC and PHY after link is up */ | 
|  | 1514 | ret_val = e1000_copper_link_postconfig(hw); | 
|  | 1515 | if (ret_val) | 
|  | 1516 | return ret_val; | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1517 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1518 | e_dbg("Valid link established!!!\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1519 | return E1000_SUCCESS; | 
|  | 1520 | } | 
|  | 1521 | udelay(10); | 
|  | 1522 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1524 | e_dbg("Unable to establish link!!!\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1525 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | } | 
|  | 1527 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1528 | /** | 
|  | 1529 | * e1000_phy_setup_autoneg - phy settings | 
|  | 1530 | * @hw: Struct containing variables accessed by shared code | 
|  | 1531 | * | 
|  | 1532 | * Configures PHY autoneg and flow control advertisement settings | 
|  | 1533 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1534 | s32 e1000_phy_setup_autoneg(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1536 | s32 ret_val; | 
|  | 1537 | u16 mii_autoneg_adv_reg; | 
|  | 1538 | u16 mii_1000t_ctrl_reg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1540 | e_dbg("e1000_phy_setup_autoneg"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1542 | /* Read the MII Auto-Neg Advertisement Register (Address 4). */ | 
|  | 1543 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg); | 
|  | 1544 | if (ret_val) | 
|  | 1545 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1547 | /* Read the MII 1000Base-T Control Register (Address 9). */ | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1548 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1549 | if (ret_val) | 
|  | 1550 | return ret_val; | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1551 | else if (hw->phy_type == e1000_phy_8201) | 
|  | 1552 | mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1554 | /* Need to parse both autoneg_advertised and fc and set up | 
|  | 1555 | * the appropriate PHY registers.  First we will parse for | 
|  | 1556 | * autoneg_advertised software override.  Since we can advertise | 
|  | 1557 | * a plethora of combinations, we need to check each bit | 
|  | 1558 | * individually. | 
|  | 1559 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1561 | /* First we clear all the 10/100 mb speed bits in the Auto-Neg | 
|  | 1562 | * Advertisement Register (Address 4) and the 1000 mb speed bits in | 
|  | 1563 | * the  1000Base-T Control Register (Address 9). | 
|  | 1564 | */ | 
|  | 1565 | mii_autoneg_adv_reg &= ~REG4_SPEED_MASK; | 
|  | 1566 | mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1568 | e_dbg("autoneg_advertised %x\n", hw->autoneg_advertised); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1570 | /* Do we want to advertise 10 Mb Half Duplex? */ | 
|  | 1571 | if (hw->autoneg_advertised & ADVERTISE_10_HALF) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1572 | e_dbg("Advertise 10mb Half duplex\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1573 | mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS; | 
|  | 1574 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1576 | /* Do we want to advertise 10 Mb Full Duplex? */ | 
|  | 1577 | if (hw->autoneg_advertised & ADVERTISE_10_FULL) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1578 | e_dbg("Advertise 10mb Full duplex\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1579 | mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS; | 
|  | 1580 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1582 | /* Do we want to advertise 100 Mb Half Duplex? */ | 
|  | 1583 | if (hw->autoneg_advertised & ADVERTISE_100_HALF) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1584 | e_dbg("Advertise 100mb Half duplex\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1585 | mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS; | 
|  | 1586 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1588 | /* Do we want to advertise 100 Mb Full Duplex? */ | 
|  | 1589 | if (hw->autoneg_advertised & ADVERTISE_100_FULL) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1590 | e_dbg("Advertise 100mb Full duplex\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1591 | mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS; | 
|  | 1592 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1594 | /* We do not allow the Phy to advertise 1000 Mb Half Duplex */ | 
|  | 1595 | if (hw->autoneg_advertised & ADVERTISE_1000_HALF) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1596 | e_dbg | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1597 | ("Advertise 1000mb Half duplex requested, request denied!\n"); | 
|  | 1598 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1600 | /* Do we want to advertise 1000 Mb Full Duplex? */ | 
|  | 1601 | if (hw->autoneg_advertised & ADVERTISE_1000_FULL) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1602 | e_dbg("Advertise 1000mb Full duplex\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1603 | mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS; | 
|  | 1604 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1606 | /* Check for a software override of the flow control settings, and | 
|  | 1607 | * setup the PHY advertisement registers accordingly.  If | 
|  | 1608 | * auto-negotiation is enabled, then software will have to set the | 
|  | 1609 | * "PAUSE" bits to the correct value in the Auto-Negotiation | 
|  | 1610 | * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation. | 
|  | 1611 | * | 
|  | 1612 | * The possible values of the "fc" parameter are: | 
|  | 1613 | *      0:  Flow control is completely disabled | 
|  | 1614 | *      1:  Rx flow control is enabled (we can receive pause frames | 
|  | 1615 | *          but not send pause frames). | 
|  | 1616 | *      2:  Tx flow control is enabled (we can send pause frames | 
|  | 1617 | *          but we do not support receiving pause frames). | 
|  | 1618 | *      3:  Both Rx and TX flow control (symmetric) are enabled. | 
|  | 1619 | *  other:  No software override.  The flow control configuration | 
|  | 1620 | *          in the EEPROM is used. | 
|  | 1621 | */ | 
|  | 1622 | switch (hw->fc) { | 
|  | 1623 | case E1000_FC_NONE:	/* 0 */ | 
|  | 1624 | /* Flow control (RX & TX) is completely disabled by a | 
|  | 1625 | * software over-ride. | 
|  | 1626 | */ | 
|  | 1627 | mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); | 
|  | 1628 | break; | 
|  | 1629 | case E1000_FC_RX_PAUSE:	/* 1 */ | 
|  | 1630 | /* RX Flow control is enabled, and TX Flow control is | 
|  | 1631 | * disabled, by a software over-ride. | 
|  | 1632 | */ | 
|  | 1633 | /* Since there really isn't a way to advertise that we are | 
|  | 1634 | * capable of RX Pause ONLY, we will advertise that we | 
|  | 1635 | * support both symmetric and asymmetric RX PAUSE.  Later | 
|  | 1636 | * (in e1000_config_fc_after_link_up) we will disable the | 
|  | 1637 | *hw's ability to send PAUSE frames. | 
|  | 1638 | */ | 
|  | 1639 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); | 
|  | 1640 | break; | 
|  | 1641 | case E1000_FC_TX_PAUSE:	/* 2 */ | 
|  | 1642 | /* TX Flow control is enabled, and RX Flow control is | 
|  | 1643 | * disabled, by a software over-ride. | 
|  | 1644 | */ | 
|  | 1645 | mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR; | 
|  | 1646 | mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE; | 
|  | 1647 | break; | 
|  | 1648 | case E1000_FC_FULL:	/* 3 */ | 
|  | 1649 | /* Flow control (both RX and TX) is enabled by a software | 
|  | 1650 | * over-ride. | 
|  | 1651 | */ | 
|  | 1652 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); | 
|  | 1653 | break; | 
|  | 1654 | default: | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1655 | e_dbg("Flow control param set incorrectly\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1656 | return -E1000_ERR_CONFIG; | 
|  | 1657 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1659 | ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg); | 
|  | 1660 | if (ret_val) | 
|  | 1661 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1663 | e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 |  | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1665 | if (hw->phy_type == e1000_phy_8201) { | 
|  | 1666 | mii_1000t_ctrl_reg = 0; | 
|  | 1667 | } else { | 
|  | 1668 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, | 
|  | 1669 | mii_1000t_ctrl_reg); | 
|  | 1670 | if (ret_val) | 
|  | 1671 | return ret_val; | 
|  | 1672 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1674 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | } | 
|  | 1676 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1677 | /** | 
|  | 1678 | * e1000_phy_force_speed_duplex - force link settings | 
|  | 1679 | * @hw: Struct containing variables accessed by shared code | 
|  | 1680 | * | 
|  | 1681 | * Force PHY speed and duplex settings to hw->forced_speed_duplex | 
|  | 1682 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1683 | static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1685 | u32 ctrl; | 
|  | 1686 | s32 ret_val; | 
|  | 1687 | u16 mii_ctrl_reg; | 
|  | 1688 | u16 mii_status_reg; | 
|  | 1689 | u16 phy_data; | 
|  | 1690 | u16 i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1692 | e_dbg("e1000_phy_force_speed_duplex"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1694 | /* Turn off Flow control if we are forcing speed and duplex. */ | 
|  | 1695 | hw->fc = E1000_FC_NONE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1697 | e_dbg("hw->fc = %d\n", hw->fc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1699 | /* Read the Device Control Register. */ | 
|  | 1700 | ctrl = er32(CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1702 | /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */ | 
|  | 1703 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); | 
|  | 1704 | ctrl &= ~(DEVICE_SPEED_MASK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1706 | /* Clear the Auto Speed Detect Enable bit. */ | 
|  | 1707 | ctrl &= ~E1000_CTRL_ASDE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1709 | /* Read the MII Control Register. */ | 
|  | 1710 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg); | 
|  | 1711 | if (ret_val) | 
|  | 1712 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1714 | /* We need to disable autoneg in order to force link and duplex. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1716 | mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1718 | /* Are we forcing Full or Half Duplex? */ | 
|  | 1719 | if (hw->forced_speed_duplex == e1000_100_full || | 
|  | 1720 | hw->forced_speed_duplex == e1000_10_full) { | 
|  | 1721 | /* We want to force full duplex so we SET the full duplex bits in the | 
|  | 1722 | * Device and MII Control Registers. | 
|  | 1723 | */ | 
|  | 1724 | ctrl |= E1000_CTRL_FD; | 
|  | 1725 | mii_ctrl_reg |= MII_CR_FULL_DUPLEX; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1726 | e_dbg("Full Duplex\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1727 | } else { | 
|  | 1728 | /* We want to force half duplex so we CLEAR the full duplex bits in | 
|  | 1729 | * the Device and MII Control Registers. | 
|  | 1730 | */ | 
|  | 1731 | ctrl &= ~E1000_CTRL_FD; | 
|  | 1732 | mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1733 | e_dbg("Half Duplex\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1734 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1736 | /* Are we forcing 100Mbps??? */ | 
|  | 1737 | if (hw->forced_speed_duplex == e1000_100_full || | 
|  | 1738 | hw->forced_speed_duplex == e1000_100_half) { | 
|  | 1739 | /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */ | 
|  | 1740 | ctrl |= E1000_CTRL_SPD_100; | 
|  | 1741 | mii_ctrl_reg |= MII_CR_SPEED_100; | 
|  | 1742 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10); | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1743 | e_dbg("Forcing 100mb "); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1744 | } else { | 
|  | 1745 | /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */ | 
|  | 1746 | ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100); | 
|  | 1747 | mii_ctrl_reg |= MII_CR_SPEED_10; | 
|  | 1748 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100); | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1749 | e_dbg("Forcing 10mb "); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1750 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1752 | e1000_config_collision_dist(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1754 | /* Write the configured values back to the Device Control Reg. */ | 
|  | 1755 | ew32(CTRL, ctrl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1757 | if (hw->phy_type == e1000_phy_m88) { | 
|  | 1758 | ret_val = | 
|  | 1759 | e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); | 
|  | 1760 | if (ret_val) | 
|  | 1761 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1763 | /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI | 
|  | 1764 | * forced whenever speed are duplex are forced. | 
|  | 1765 | */ | 
|  | 1766 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; | 
|  | 1767 | ret_val = | 
|  | 1768 | e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); | 
|  | 1769 | if (ret_val) | 
|  | 1770 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1772 | e_dbg("M88E1000 PSCR: %x\n", phy_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1774 | /* Need to reset the PHY or these changes will be ignored */ | 
|  | 1775 | mii_ctrl_reg |= MII_CR_RESET; | 
| Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 1776 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1777 | /* Disable MDI-X support for 10/100 */ | 
|  | 1778 | } else { | 
|  | 1779 | /* Clear Auto-Crossover to force MDI manually.  IGP requires MDI | 
|  | 1780 | * forced whenever speed or duplex are forced. | 
|  | 1781 | */ | 
|  | 1782 | ret_val = | 
|  | 1783 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); | 
|  | 1784 | if (ret_val) | 
|  | 1785 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1787 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; | 
|  | 1788 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1790 | ret_val = | 
|  | 1791 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); | 
|  | 1792 | if (ret_val) | 
|  | 1793 | return ret_val; | 
|  | 1794 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1796 | /* Write back the modified PHY MII control register. */ | 
|  | 1797 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg); | 
|  | 1798 | if (ret_val) | 
|  | 1799 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1801 | udelay(1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1803 | /* The wait_autoneg_complete flag may be a little misleading here. | 
|  | 1804 | * Since we are forcing speed and duplex, Auto-Neg is not enabled. | 
|  | 1805 | * But we do want to delay for a period while forcing only so we | 
|  | 1806 | * don't generate false No Link messages.  So we will wait here | 
|  | 1807 | * only if the user has set wait_autoneg_complete to 1, which is | 
|  | 1808 | * the default. | 
|  | 1809 | */ | 
|  | 1810 | if (hw->wait_autoneg_complete) { | 
|  | 1811 | /* We will wait for autoneg to complete. */ | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1812 | e_dbg("Waiting for forced speed/duplex link.\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1813 | mii_status_reg = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1815 | /* We will wait for autoneg to complete or 4.5 seconds to expire. */ | 
|  | 1816 | for (i = PHY_FORCE_TIME; i > 0; i--) { | 
|  | 1817 | /* Read the MII Status Register and wait for Auto-Neg Complete bit | 
|  | 1818 | * to be set. | 
|  | 1819 | */ | 
|  | 1820 | ret_val = | 
|  | 1821 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 1822 | if (ret_val) | 
|  | 1823 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1825 | ret_val = | 
|  | 1826 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 1827 | if (ret_val) | 
|  | 1828 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1830 | if (mii_status_reg & MII_SR_LINK_STATUS) | 
|  | 1831 | break; | 
|  | 1832 | msleep(100); | 
|  | 1833 | } | 
|  | 1834 | if ((i == 0) && (hw->phy_type == e1000_phy_m88)) { | 
|  | 1835 | /* We didn't get link.  Reset the DSP and wait again for link. */ | 
|  | 1836 | ret_val = e1000_phy_reset_dsp(hw); | 
|  | 1837 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1838 | e_dbg("Error Resetting PHY DSP\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1839 | return ret_val; | 
|  | 1840 | } | 
|  | 1841 | } | 
|  | 1842 | /* This loop will early-out if the link condition has been met.  */ | 
|  | 1843 | for (i = PHY_FORCE_TIME; i > 0; i--) { | 
|  | 1844 | if (mii_status_reg & MII_SR_LINK_STATUS) | 
|  | 1845 | break; | 
|  | 1846 | msleep(100); | 
|  | 1847 | /* Read the MII Status Register and wait for Auto-Neg Complete bit | 
|  | 1848 | * to be set. | 
|  | 1849 | */ | 
|  | 1850 | ret_val = | 
|  | 1851 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 1852 | if (ret_val) | 
|  | 1853 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1855 | ret_val = | 
|  | 1856 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 1857 | if (ret_val) | 
|  | 1858 | return ret_val; | 
|  | 1859 | } | 
|  | 1860 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1862 | if (hw->phy_type == e1000_phy_m88) { | 
|  | 1863 | /* Because we reset the PHY above, we need to re-force TX_CLK in the | 
|  | 1864 | * Extended PHY Specific Control Register to 25MHz clock.  This value | 
|  | 1865 | * defaults back to a 2.5MHz clock when the PHY is reset. | 
|  | 1866 | */ | 
|  | 1867 | ret_val = | 
|  | 1868 | e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, | 
|  | 1869 | &phy_data); | 
|  | 1870 | if (ret_val) | 
|  | 1871 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1873 | phy_data |= M88E1000_EPSCR_TX_CLK_25; | 
|  | 1874 | ret_val = | 
|  | 1875 | e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, | 
|  | 1876 | phy_data); | 
|  | 1877 | if (ret_val) | 
|  | 1878 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1880 | /* In addition, because of the s/w reset above, we need to enable CRS on | 
|  | 1881 | * TX.  This must be set for both full and half duplex operation. | 
|  | 1882 | */ | 
|  | 1883 | ret_val = | 
|  | 1884 | e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); | 
|  | 1885 | if (ret_val) | 
|  | 1886 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1888 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; | 
|  | 1889 | ret_val = | 
|  | 1890 | e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); | 
|  | 1891 | if (ret_val) | 
|  | 1892 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1894 | if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) | 
|  | 1895 | && (!hw->autoneg) | 
|  | 1896 | && (hw->forced_speed_duplex == e1000_10_full | 
|  | 1897 | || hw->forced_speed_duplex == e1000_10_half)) { | 
|  | 1898 | ret_val = e1000_polarity_reversal_workaround(hw); | 
|  | 1899 | if (ret_val) | 
|  | 1900 | return ret_val; | 
|  | 1901 | } | 
|  | 1902 | } | 
|  | 1903 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | } | 
|  | 1905 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1906 | /** | 
|  | 1907 | * e1000_config_collision_dist - set collision distance register | 
|  | 1908 | * @hw: Struct containing variables accessed by shared code | 
|  | 1909 | * | 
|  | 1910 | * Sets the collision distance in the Transmit Control register. | 
|  | 1911 | * Link should have been established previously. Reads the speed and duplex | 
|  | 1912 | * information from the Device Status register. | 
|  | 1913 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1914 | void e1000_config_collision_dist(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1916 | u32 tctl, coll_dist; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1918 | e_dbg("e1000_config_collision_dist"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1920 | if (hw->mac_type < e1000_82543) | 
|  | 1921 | coll_dist = E1000_COLLISION_DISTANCE_82542; | 
|  | 1922 | else | 
|  | 1923 | coll_dist = E1000_COLLISION_DISTANCE; | 
| Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1924 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1925 | tctl = er32(TCTL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1927 | tctl &= ~E1000_TCTL_COLD; | 
|  | 1928 | tctl |= coll_dist << E1000_COLD_SHIFT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1930 | ew32(TCTL, tctl); | 
|  | 1931 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | } | 
|  | 1933 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1934 | /** | 
|  | 1935 | * e1000_config_mac_to_phy - sync phy and mac settings | 
|  | 1936 | * @hw: Struct containing variables accessed by shared code | 
|  | 1937 | * @mii_reg: data to write to the MII control register | 
|  | 1938 | * | 
|  | 1939 | * Sets MAC speed and duplex settings to reflect the those in the PHY | 
|  | 1940 | * The contents of the PHY register containing the needed information need to | 
|  | 1941 | * be passed in. | 
|  | 1942 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1943 | static s32 e1000_config_mac_to_phy(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1945 | u32 ctrl; | 
|  | 1946 | s32 ret_val; | 
|  | 1947 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1949 | e_dbg("e1000_config_mac_to_phy"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1951 | /* 82544 or newer MAC, Auto Speed Detection takes care of | 
|  | 1952 | * MAC speed/duplex configuration.*/ | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1953 | if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100)) | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1954 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1955 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1956 | /* Read the Device Control Register and set the bits to Force Speed | 
|  | 1957 | * and Duplex. | 
|  | 1958 | */ | 
|  | 1959 | ctrl = er32(CTRL); | 
|  | 1960 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); | 
|  | 1961 | ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 |  | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1963 | switch (hw->phy_type) { | 
|  | 1964 | case e1000_phy_8201: | 
|  | 1965 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); | 
|  | 1966 | if (ret_val) | 
|  | 1967 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 |  | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1969 | if (phy_data & RTL_PHY_CTRL_FD) | 
|  | 1970 | ctrl |= E1000_CTRL_FD; | 
|  | 1971 | else | 
|  | 1972 | ctrl &= ~E1000_CTRL_FD; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 |  | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1974 | if (phy_data & RTL_PHY_CTRL_SPD_100) | 
|  | 1975 | ctrl |= E1000_CTRL_SPD_100; | 
|  | 1976 | else | 
|  | 1977 | ctrl |= E1000_CTRL_SPD_10; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 |  | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1979 | e1000_config_collision_dist(hw); | 
|  | 1980 | break; | 
|  | 1981 | default: | 
|  | 1982 | /* Set up duplex in the Device Control and Transmit Control | 
|  | 1983 | * registers depending on negotiated values. | 
|  | 1984 | */ | 
|  | 1985 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, | 
|  | 1986 | &phy_data); | 
|  | 1987 | if (ret_val) | 
|  | 1988 | return ret_val; | 
|  | 1989 |  | 
|  | 1990 | if (phy_data & M88E1000_PSSR_DPLX) | 
|  | 1991 | ctrl |= E1000_CTRL_FD; | 
|  | 1992 | else | 
|  | 1993 | ctrl &= ~E1000_CTRL_FD; | 
|  | 1994 |  | 
|  | 1995 | e1000_config_collision_dist(hw); | 
|  | 1996 |  | 
|  | 1997 | /* Set up speed in the Device Control register depending on | 
|  | 1998 | * negotiated values. | 
|  | 1999 | */ | 
|  | 2000 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) | 
|  | 2001 | ctrl |= E1000_CTRL_SPD_1000; | 
|  | 2002 | else if ((phy_data & M88E1000_PSSR_SPEED) == | 
|  | 2003 | M88E1000_PSSR_100MBS) | 
|  | 2004 | ctrl |= E1000_CTRL_SPD_100; | 
|  | 2005 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2007 | /* Write the configured values back to the Device Control Reg. */ | 
|  | 2008 | ew32(CTRL, ctrl); | 
|  | 2009 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | } | 
|  | 2011 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2012 | /** | 
|  | 2013 | * e1000_force_mac_fc - force flow control settings | 
|  | 2014 | * @hw: Struct containing variables accessed by shared code | 
|  | 2015 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | * Forces the MAC's flow control settings. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | * Sets the TFCE and RFCE bits in the device control register to reflect | 
|  | 2018 | * the adapter settings. TFCE and RFCE need to be explicitly set by | 
|  | 2019 | * software when a Copper PHY is used because autonegotiation is managed | 
|  | 2020 | * by the PHY rather than the MAC. Software must also configure these | 
|  | 2021 | * bits when link is forced on a fiber connection. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2022 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2023 | s32 e1000_force_mac_fc(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2025 | u32 ctrl; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2027 | e_dbg("e1000_force_mac_fc"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2029 | /* Get the current configuration of the Device Control Register */ | 
|  | 2030 | ctrl = er32(CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2032 | /* Because we didn't get link via the internal auto-negotiation | 
|  | 2033 | * mechanism (we either forced link or we got link via PHY | 
|  | 2034 | * auto-neg), we have to manually enable/disable transmit an | 
|  | 2035 | * receive flow control. | 
|  | 2036 | * | 
|  | 2037 | * The "Case" statement below enables/disable flow control | 
|  | 2038 | * according to the "hw->fc" parameter. | 
|  | 2039 | * | 
|  | 2040 | * The possible values of the "fc" parameter are: | 
|  | 2041 | *      0:  Flow control is completely disabled | 
|  | 2042 | *      1:  Rx flow control is enabled (we can receive pause | 
|  | 2043 | *          frames but not send pause frames). | 
|  | 2044 | *      2:  Tx flow control is enabled (we can send pause frames | 
|  | 2045 | *          frames but we do not receive pause frames). | 
|  | 2046 | *      3:  Both Rx and TX flow control (symmetric) is enabled. | 
|  | 2047 | *  other:  No other values should be possible at this point. | 
|  | 2048 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2050 | switch (hw->fc) { | 
|  | 2051 | case E1000_FC_NONE: | 
|  | 2052 | ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); | 
|  | 2053 | break; | 
|  | 2054 | case E1000_FC_RX_PAUSE: | 
|  | 2055 | ctrl &= (~E1000_CTRL_TFCE); | 
|  | 2056 | ctrl |= E1000_CTRL_RFCE; | 
|  | 2057 | break; | 
|  | 2058 | case E1000_FC_TX_PAUSE: | 
|  | 2059 | ctrl &= (~E1000_CTRL_RFCE); | 
|  | 2060 | ctrl |= E1000_CTRL_TFCE; | 
|  | 2061 | break; | 
|  | 2062 | case E1000_FC_FULL: | 
|  | 2063 | ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); | 
|  | 2064 | break; | 
|  | 2065 | default: | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2066 | e_dbg("Flow control param set incorrectly\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2067 | return -E1000_ERR_CONFIG; | 
|  | 2068 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2070 | /* Disable TX Flow Control for 82542 (rev 2.0) */ | 
|  | 2071 | if (hw->mac_type == e1000_82542_rev2_0) | 
|  | 2072 | ctrl &= (~E1000_CTRL_TFCE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2074 | ew32(CTRL, ctrl); | 
|  | 2075 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | } | 
|  | 2077 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2078 | /** | 
|  | 2079 | * e1000_config_fc_after_link_up - configure flow control after autoneg | 
|  | 2080 | * @hw: Struct containing variables accessed by shared code | 
|  | 2081 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | * Configures flow control settings after link is established | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | * Should be called immediately after a valid link has been established. | 
|  | 2084 | * Forces MAC flow control settings if link was forced. When in MII/GMII mode | 
|  | 2085 | * and autonegotiation is enabled, the MAC flow control settings will be set | 
|  | 2086 | * based on the flow control negotiated by the PHY. In TBI mode, the TFCE | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2087 | * and RFCE bits will be automatically set to the negotiated flow control mode. | 
|  | 2088 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2089 | static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2091 | s32 ret_val; | 
|  | 2092 | u16 mii_status_reg; | 
|  | 2093 | u16 mii_nway_adv_reg; | 
|  | 2094 | u16 mii_nway_lp_ability_reg; | 
|  | 2095 | u16 speed; | 
|  | 2096 | u16 duplex; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2098 | e_dbg("e1000_config_fc_after_link_up"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2100 | /* Check for the case where we have fiber media and auto-neg failed | 
|  | 2101 | * so we had to force link.  In this case, we need to force the | 
|  | 2102 | * configuration of the MAC to match the "fc" parameter. | 
|  | 2103 | */ | 
|  | 2104 | if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) | 
|  | 2105 | || ((hw->media_type == e1000_media_type_internal_serdes) | 
|  | 2106 | && (hw->autoneg_failed)) | 
|  | 2107 | || ((hw->media_type == e1000_media_type_copper) | 
|  | 2108 | && (!hw->autoneg))) { | 
|  | 2109 | ret_val = e1000_force_mac_fc(hw); | 
|  | 2110 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2111 | e_dbg("Error forcing flow control settings\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2112 | return ret_val; | 
|  | 2113 | } | 
|  | 2114 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2116 | /* Check for the case where we have copper media and auto-neg is | 
|  | 2117 | * enabled.  In this case, we need to check and see if Auto-Neg | 
|  | 2118 | * has completed, and if so, how the PHY and link partner has | 
|  | 2119 | * flow control configured. | 
|  | 2120 | */ | 
|  | 2121 | if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) { | 
|  | 2122 | /* Read the MII Status Register and check to see if AutoNeg | 
|  | 2123 | * has completed.  We read this twice because this reg has | 
|  | 2124 | * some "sticky" (latched) bits. | 
|  | 2125 | */ | 
|  | 2126 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 2127 | if (ret_val) | 
|  | 2128 | return ret_val; | 
|  | 2129 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 2130 | if (ret_val) | 
|  | 2131 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2133 | if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) { | 
|  | 2134 | /* The AutoNeg process has completed, so we now need to | 
|  | 2135 | * read both the Auto Negotiation Advertisement Register | 
|  | 2136 | * (Address 4) and the Auto_Negotiation Base Page Ability | 
|  | 2137 | * Register (Address 5) to determine how flow control was | 
|  | 2138 | * negotiated. | 
|  | 2139 | */ | 
|  | 2140 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, | 
|  | 2141 | &mii_nway_adv_reg); | 
|  | 2142 | if (ret_val) | 
|  | 2143 | return ret_val; | 
|  | 2144 | ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, | 
|  | 2145 | &mii_nway_lp_ability_reg); | 
|  | 2146 | if (ret_val) | 
|  | 2147 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2149 | /* Two bits in the Auto Negotiation Advertisement Register | 
|  | 2150 | * (Address 4) and two bits in the Auto Negotiation Base | 
|  | 2151 | * Page Ability Register (Address 5) determine flow control | 
|  | 2152 | * for both the PHY and the link partner.  The following | 
|  | 2153 | * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, | 
|  | 2154 | * 1999, describes these PAUSE resolution bits and how flow | 
|  | 2155 | * control is determined based upon these settings. | 
|  | 2156 | * NOTE:  DC = Don't Care | 
|  | 2157 | * | 
|  | 2158 | *   LOCAL DEVICE  |   LINK PARTNER | 
|  | 2159 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution | 
|  | 2160 | *-------|---------|-------|---------|-------------------- | 
|  | 2161 | *   0   |    0    |  DC   |   DC    | E1000_FC_NONE | 
|  | 2162 | *   0   |    1    |   0   |   DC    | E1000_FC_NONE | 
|  | 2163 | *   0   |    1    |   1   |    0    | E1000_FC_NONE | 
|  | 2164 | *   0   |    1    |   1   |    1    | E1000_FC_TX_PAUSE | 
|  | 2165 | *   1   |    0    |   0   |   DC    | E1000_FC_NONE | 
|  | 2166 | *   1   |   DC    |   1   |   DC    | E1000_FC_FULL | 
|  | 2167 | *   1   |    1    |   0   |    0    | E1000_FC_NONE | 
|  | 2168 | *   1   |    1    |   0   |    1    | E1000_FC_RX_PAUSE | 
|  | 2169 | * | 
|  | 2170 | */ | 
|  | 2171 | /* Are both PAUSE bits set to 1?  If so, this implies | 
|  | 2172 | * Symmetric Flow Control is enabled at both ends.  The | 
|  | 2173 | * ASM_DIR bits are irrelevant per the spec. | 
|  | 2174 | * | 
|  | 2175 | * For Symmetric Flow Control: | 
|  | 2176 | * | 
|  | 2177 | *   LOCAL DEVICE  |   LINK PARTNER | 
|  | 2178 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result | 
|  | 2179 | *-------|---------|-------|---------|-------------------- | 
|  | 2180 | *   1   |   DC    |   1   |   DC    | E1000_FC_FULL | 
|  | 2181 | * | 
|  | 2182 | */ | 
|  | 2183 | if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && | 
|  | 2184 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { | 
|  | 2185 | /* Now we need to check if the user selected RX ONLY | 
|  | 2186 | * of pause frames.  In this case, we had to advertise | 
|  | 2187 | * FULL flow control because we could not advertise RX | 
|  | 2188 | * ONLY. Hence, we must now check to see if we need to | 
|  | 2189 | * turn OFF  the TRANSMISSION of PAUSE frames. | 
|  | 2190 | */ | 
|  | 2191 | if (hw->original_fc == E1000_FC_FULL) { | 
|  | 2192 | hw->fc = E1000_FC_FULL; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2193 | e_dbg("Flow Control = FULL.\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2194 | } else { | 
|  | 2195 | hw->fc = E1000_FC_RX_PAUSE; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2196 | e_dbg | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2197 | ("Flow Control = RX PAUSE frames only.\n"); | 
|  | 2198 | } | 
|  | 2199 | } | 
|  | 2200 | /* For receiving PAUSE frames ONLY. | 
|  | 2201 | * | 
|  | 2202 | *   LOCAL DEVICE  |   LINK PARTNER | 
|  | 2203 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result | 
|  | 2204 | *-------|---------|-------|---------|-------------------- | 
|  | 2205 | *   0   |    1    |   1   |    1    | E1000_FC_TX_PAUSE | 
|  | 2206 | * | 
|  | 2207 | */ | 
|  | 2208 | else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && | 
|  | 2209 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && | 
|  | 2210 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && | 
|  | 2211 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) | 
|  | 2212 | { | 
|  | 2213 | hw->fc = E1000_FC_TX_PAUSE; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2214 | e_dbg | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2215 | ("Flow Control = TX PAUSE frames only.\n"); | 
|  | 2216 | } | 
|  | 2217 | /* For transmitting PAUSE frames ONLY. | 
|  | 2218 | * | 
|  | 2219 | *   LOCAL DEVICE  |   LINK PARTNER | 
|  | 2220 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result | 
|  | 2221 | *-------|---------|-------|---------|-------------------- | 
|  | 2222 | *   1   |    1    |   0   |    1    | E1000_FC_RX_PAUSE | 
|  | 2223 | * | 
|  | 2224 | */ | 
|  | 2225 | else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && | 
|  | 2226 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && | 
|  | 2227 | !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && | 
|  | 2228 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) | 
|  | 2229 | { | 
|  | 2230 | hw->fc = E1000_FC_RX_PAUSE; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2231 | e_dbg | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2232 | ("Flow Control = RX PAUSE frames only.\n"); | 
|  | 2233 | } | 
|  | 2234 | /* Per the IEEE spec, at this point flow control should be | 
|  | 2235 | * disabled.  However, we want to consider that we could | 
|  | 2236 | * be connected to a legacy switch that doesn't advertise | 
|  | 2237 | * desired flow control, but can be forced on the link | 
|  | 2238 | * partner.  So if we advertised no flow control, that is | 
|  | 2239 | * what we will resolve to.  If we advertised some kind of | 
|  | 2240 | * receive capability (Rx Pause Only or Full Flow Control) | 
|  | 2241 | * and the link partner advertised none, we will configure | 
|  | 2242 | * ourselves to enable Rx Flow Control only.  We can do | 
|  | 2243 | * this safely for two reasons:  If the link partner really | 
|  | 2244 | * didn't want flow control enabled, and we enable Rx, no | 
|  | 2245 | * harm done since we won't be receiving any PAUSE frames | 
|  | 2246 | * anyway.  If the intent on the link partner was to have | 
|  | 2247 | * flow control enabled, then by us enabling RX only, we | 
|  | 2248 | * can at least receive pause frames and process them. | 
|  | 2249 | * This is a good idea because in most cases, since we are | 
|  | 2250 | * predominantly a server NIC, more times than not we will | 
|  | 2251 | * be asked to delay transmission of packets than asking | 
|  | 2252 | * our link partner to pause transmission of frames. | 
|  | 2253 | */ | 
|  | 2254 | else if ((hw->original_fc == E1000_FC_NONE || | 
|  | 2255 | hw->original_fc == E1000_FC_TX_PAUSE) || | 
|  | 2256 | hw->fc_strict_ieee) { | 
|  | 2257 | hw->fc = E1000_FC_NONE; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2258 | e_dbg("Flow Control = NONE.\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2259 | } else { | 
|  | 2260 | hw->fc = E1000_FC_RX_PAUSE; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2261 | e_dbg | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2262 | ("Flow Control = RX PAUSE frames only.\n"); | 
|  | 2263 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2265 | /* Now we need to do one last check...  If we auto- | 
|  | 2266 | * negotiated to HALF DUPLEX, flow control should not be | 
|  | 2267 | * enabled per IEEE 802.3 spec. | 
|  | 2268 | */ | 
|  | 2269 | ret_val = | 
|  | 2270 | e1000_get_speed_and_duplex(hw, &speed, &duplex); | 
|  | 2271 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2272 | e_dbg | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2273 | ("Error getting link speed and duplex\n"); | 
|  | 2274 | return ret_val; | 
|  | 2275 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2277 | if (duplex == HALF_DUPLEX) | 
|  | 2278 | hw->fc = E1000_FC_NONE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2280 | /* Now we call a subroutine to actually force the MAC | 
|  | 2281 | * controller to use the correct flow control settings. | 
|  | 2282 | */ | 
|  | 2283 | ret_val = e1000_force_mac_fc(hw); | 
|  | 2284 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2285 | e_dbg | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2286 | ("Error forcing flow control settings\n"); | 
|  | 2287 | return ret_val; | 
|  | 2288 | } | 
|  | 2289 | } else { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2290 | e_dbg | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2291 | ("Copper PHY and Auto Neg has not completed.\n"); | 
|  | 2292 | } | 
|  | 2293 | } | 
|  | 2294 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | } | 
|  | 2296 |  | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2297 | /** | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2298 | * e1000_check_for_serdes_link_generic - Check for link (Serdes) | 
|  | 2299 | * @hw: pointer to the HW structure | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2300 | * | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2301 | * Checks for link up on the hardware.  If link is not up and we have | 
|  | 2302 | * a signal, then we need to force link up. | 
|  | 2303 | */ | 
| Jesse Brandeburg | 11b7f7b | 2009-09-25 12:20:33 +0000 | [diff] [blame] | 2304 | static s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw) | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2305 | { | 
|  | 2306 | u32 rxcw; | 
|  | 2307 | u32 ctrl; | 
|  | 2308 | u32 status; | 
|  | 2309 | s32 ret_val = E1000_SUCCESS; | 
|  | 2310 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2311 | e_dbg("e1000_check_for_serdes_link_generic"); | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2312 |  | 
|  | 2313 | ctrl = er32(CTRL); | 
|  | 2314 | status = er32(STATUS); | 
|  | 2315 | rxcw = er32(RXCW); | 
|  | 2316 |  | 
|  | 2317 | /* | 
|  | 2318 | * If we don't have link (auto-negotiation failed or link partner | 
|  | 2319 | * cannot auto-negotiate), and our link partner is not trying to | 
|  | 2320 | * auto-negotiate with us (we are receiving idles or data), | 
|  | 2321 | * we need to force link up. We also need to give auto-negotiation | 
|  | 2322 | * time to complete. | 
|  | 2323 | */ | 
|  | 2324 | /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */ | 
|  | 2325 | if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) { | 
|  | 2326 | if (hw->autoneg_failed == 0) { | 
|  | 2327 | hw->autoneg_failed = 1; | 
|  | 2328 | goto out; | 
|  | 2329 | } | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2330 | e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n"); | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2331 |  | 
|  | 2332 | /* Disable auto-negotiation in the TXCW register */ | 
|  | 2333 | ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE)); | 
|  | 2334 |  | 
|  | 2335 | /* Force link-up and also force full-duplex. */ | 
|  | 2336 | ctrl = er32(CTRL); | 
|  | 2337 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); | 
|  | 2338 | ew32(CTRL, ctrl); | 
|  | 2339 |  | 
|  | 2340 | /* Configure Flow Control after forcing link up. */ | 
|  | 2341 | ret_val = e1000_config_fc_after_link_up(hw); | 
|  | 2342 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2343 | e_dbg("Error configuring flow control\n"); | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2344 | goto out; | 
|  | 2345 | } | 
|  | 2346 | } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { | 
|  | 2347 | /* | 
|  | 2348 | * If we are forcing link and we are receiving /C/ ordered | 
|  | 2349 | * sets, re-enable auto-negotiation in the TXCW register | 
|  | 2350 | * and disable forced link in the Device Control register | 
|  | 2351 | * in an attempt to auto-negotiate with our link partner. | 
|  | 2352 | */ | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2353 | e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n"); | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2354 | ew32(TXCW, hw->txcw); | 
|  | 2355 | ew32(CTRL, (ctrl & ~E1000_CTRL_SLU)); | 
|  | 2356 |  | 
|  | 2357 | hw->serdes_has_link = true; | 
|  | 2358 | } else if (!(E1000_TXCW_ANE & er32(TXCW))) { | 
|  | 2359 | /* | 
|  | 2360 | * If we force link for non-auto-negotiation switch, check | 
|  | 2361 | * link status based on MAC synchronization for internal | 
|  | 2362 | * serdes media type. | 
|  | 2363 | */ | 
|  | 2364 | /* SYNCH bit and IV bit are sticky. */ | 
|  | 2365 | udelay(10); | 
|  | 2366 | rxcw = er32(RXCW); | 
|  | 2367 | if (rxcw & E1000_RXCW_SYNCH) { | 
|  | 2368 | if (!(rxcw & E1000_RXCW_IV)) { | 
|  | 2369 | hw->serdes_has_link = true; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2370 | e_dbg("SERDES: Link up - forced.\n"); | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2371 | } | 
|  | 2372 | } else { | 
|  | 2373 | hw->serdes_has_link = false; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2374 | e_dbg("SERDES: Link down - force failed.\n"); | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2375 | } | 
|  | 2376 | } | 
|  | 2377 |  | 
|  | 2378 | if (E1000_TXCW_ANE & er32(TXCW)) { | 
|  | 2379 | status = er32(STATUS); | 
|  | 2380 | if (status & E1000_STATUS_LU) { | 
|  | 2381 | /* SYNCH bit and IV bit are sticky, so reread rxcw. */ | 
|  | 2382 | udelay(10); | 
|  | 2383 | rxcw = er32(RXCW); | 
|  | 2384 | if (rxcw & E1000_RXCW_SYNCH) { | 
|  | 2385 | if (!(rxcw & E1000_RXCW_IV)) { | 
|  | 2386 | hw->serdes_has_link = true; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2387 | e_dbg("SERDES: Link up - autoneg " | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2388 | "completed successfully.\n"); | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2389 | } else { | 
|  | 2390 | hw->serdes_has_link = false; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2391 | e_dbg("SERDES: Link down - invalid" | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2392 | "codewords detected in autoneg.\n"); | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2393 | } | 
|  | 2394 | } else { | 
|  | 2395 | hw->serdes_has_link = false; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2396 | e_dbg("SERDES: Link down - no sync.\n"); | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2397 | } | 
|  | 2398 | } else { | 
|  | 2399 | hw->serdes_has_link = false; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2400 | e_dbg("SERDES: Link down - autoneg failed\n"); | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2401 | } | 
|  | 2402 | } | 
|  | 2403 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2404 | out: | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2405 | return ret_val; | 
|  | 2406 | } | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2407 |  | 
|  | 2408 | /** | 
|  | 2409 | * e1000_check_for_link | 
|  | 2410 | * @hw: Struct containing variables accessed by shared code | 
|  | 2411 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | * Checks to see if the link status of the hardware has changed. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | * Called by any function that needs to check the link status of the adapter. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2414 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2415 | s32 e1000_check_for_link(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2417 | u32 rxcw = 0; | 
|  | 2418 | u32 ctrl; | 
|  | 2419 | u32 status; | 
|  | 2420 | u32 rctl; | 
|  | 2421 | u32 icr; | 
|  | 2422 | u32 signal = 0; | 
|  | 2423 | s32 ret_val; | 
|  | 2424 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2426 | e_dbg("e1000_check_for_link"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2428 | ctrl = er32(CTRL); | 
|  | 2429 | status = er32(STATUS); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2431 | /* On adapters with a MAC newer than 82544, SW Definable pin 1 will be | 
|  | 2432 | * set when the optics detect a signal. On older adapters, it will be | 
|  | 2433 | * cleared when there is a signal.  This applies to fiber media only. | 
|  | 2434 | */ | 
|  | 2435 | if ((hw->media_type == e1000_media_type_fiber) || | 
|  | 2436 | (hw->media_type == e1000_media_type_internal_serdes)) { | 
|  | 2437 | rxcw = er32(RXCW); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2439 | if (hw->media_type == e1000_media_type_fiber) { | 
|  | 2440 | signal = | 
|  | 2441 | (hw->mac_type > | 
|  | 2442 | e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; | 
|  | 2443 | if (status & E1000_STATUS_LU) | 
|  | 2444 | hw->get_link_status = false; | 
|  | 2445 | } | 
|  | 2446 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2448 | /* If we have a copper PHY then we only want to go out to the PHY | 
|  | 2449 | * registers to see if Auto-Neg has completed and/or if our link | 
|  | 2450 | * status has changed.  The get_link_status flag will be set if we | 
|  | 2451 | * receive a Link Status Change interrupt or we have Rx Sequence | 
|  | 2452 | * Errors. | 
|  | 2453 | */ | 
|  | 2454 | if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) { | 
|  | 2455 | /* First we want to see if the MII Status Register reports | 
|  | 2456 | * link.  If so, then we want to get the current speed/duplex | 
|  | 2457 | * of the PHY. | 
|  | 2458 | * Read the register twice since the link bit is sticky. | 
|  | 2459 | */ | 
|  | 2460 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 2461 | if (ret_val) | 
|  | 2462 | return ret_val; | 
|  | 2463 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 2464 | if (ret_val) | 
|  | 2465 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2467 | if (phy_data & MII_SR_LINK_STATUS) { | 
|  | 2468 | hw->get_link_status = false; | 
|  | 2469 | /* Check if there was DownShift, must be checked immediately after | 
|  | 2470 | * link-up */ | 
|  | 2471 | e1000_check_downshift(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2473 | /* If we are on 82544 or 82543 silicon and speed/duplex | 
|  | 2474 | * are forced to 10H or 10F, then we will implement the polarity | 
|  | 2475 | * reversal workaround.  We disable interrupts first, and upon | 
|  | 2476 | * returning, place the devices interrupt state to its previous | 
|  | 2477 | * value except for the link status change interrupt which will | 
|  | 2478 | * happen due to the execution of this workaround. | 
|  | 2479 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2481 | if ((hw->mac_type == e1000_82544 | 
|  | 2482 | || hw->mac_type == e1000_82543) && (!hw->autoneg) | 
|  | 2483 | && (hw->forced_speed_duplex == e1000_10_full | 
|  | 2484 | || hw->forced_speed_duplex == e1000_10_half)) { | 
|  | 2485 | ew32(IMC, 0xffffffff); | 
|  | 2486 | ret_val = | 
|  | 2487 | e1000_polarity_reversal_workaround(hw); | 
|  | 2488 | icr = er32(ICR); | 
|  | 2489 | ew32(ICS, (icr & ~E1000_ICS_LSC)); | 
|  | 2490 | ew32(IMS, IMS_ENABLE_MASK); | 
|  | 2491 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2493 | } else { | 
|  | 2494 | /* No link detected */ | 
|  | 2495 | e1000_config_dsp_after_link_change(hw, false); | 
|  | 2496 | return 0; | 
|  | 2497 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2499 | /* If we are forcing speed/duplex, then we simply return since | 
|  | 2500 | * we have already determined whether we have link or not. | 
|  | 2501 | */ | 
|  | 2502 | if (!hw->autoneg) | 
|  | 2503 | return -E1000_ERR_CONFIG; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2504 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2505 | /* optimize the dsp settings for the igp phy */ | 
|  | 2506 | e1000_config_dsp_after_link_change(hw, true); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2508 | /* We have a M88E1000 PHY and Auto-Neg is enabled.  If we | 
|  | 2509 | * have Si on board that is 82544 or newer, Auto | 
|  | 2510 | * Speed Detection takes care of MAC speed/duplex | 
|  | 2511 | * configuration.  So we only need to configure Collision | 
|  | 2512 | * Distance in the MAC.  Otherwise, we need to force | 
|  | 2513 | * speed/duplex on the MAC to the current PHY speed/duplex | 
|  | 2514 | * settings. | 
|  | 2515 | */ | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2516 | if ((hw->mac_type >= e1000_82544) && | 
|  | 2517 | (hw->mac_type != e1000_ce4100)) | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2518 | e1000_config_collision_dist(hw); | 
|  | 2519 | else { | 
|  | 2520 | ret_val = e1000_config_mac_to_phy(hw); | 
|  | 2521 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2522 | e_dbg | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2523 | ("Error configuring MAC to PHY settings\n"); | 
|  | 2524 | return ret_val; | 
|  | 2525 | } | 
|  | 2526 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2528 | /* Configure Flow Control now that Auto-Neg has completed. First, we | 
|  | 2529 | * need to restore the desired flow control settings because we may | 
|  | 2530 | * have had to re-autoneg with a different link partner. | 
|  | 2531 | */ | 
|  | 2532 | ret_val = e1000_config_fc_after_link_up(hw); | 
|  | 2533 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2534 | e_dbg("Error configuring flow control\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2535 | return ret_val; | 
|  | 2536 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2538 | /* At this point we know that we are on copper and we have | 
|  | 2539 | * auto-negotiated link.  These are conditions for checking the link | 
|  | 2540 | * partner capability register.  We use the link speed to determine if | 
|  | 2541 | * TBI compatibility needs to be turned on or off.  If the link is not | 
|  | 2542 | * at gigabit speed, then TBI compatibility is not needed.  If we are | 
|  | 2543 | * at gigabit speed, we turn on TBI compatibility. | 
|  | 2544 | */ | 
|  | 2545 | if (hw->tbi_compatibility_en) { | 
|  | 2546 | u16 speed, duplex; | 
|  | 2547 | ret_val = | 
|  | 2548 | e1000_get_speed_and_duplex(hw, &speed, &duplex); | 
|  | 2549 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2550 | e_dbg | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2551 | ("Error getting link speed and duplex\n"); | 
|  | 2552 | return ret_val; | 
|  | 2553 | } | 
|  | 2554 | if (speed != SPEED_1000) { | 
|  | 2555 | /* If link speed is not set to gigabit speed, we do not need | 
|  | 2556 | * to enable TBI compatibility. | 
|  | 2557 | */ | 
|  | 2558 | if (hw->tbi_compatibility_on) { | 
|  | 2559 | /* If we previously were in the mode, turn it off. */ | 
|  | 2560 | rctl = er32(RCTL); | 
|  | 2561 | rctl &= ~E1000_RCTL_SBP; | 
|  | 2562 | ew32(RCTL, rctl); | 
|  | 2563 | hw->tbi_compatibility_on = false; | 
|  | 2564 | } | 
|  | 2565 | } else { | 
|  | 2566 | /* If TBI compatibility is was previously off, turn it on. For | 
|  | 2567 | * compatibility with a TBI link partner, we will store bad | 
|  | 2568 | * packets. Some frames have an additional byte on the end and | 
|  | 2569 | * will look like CRC errors to to the hardware. | 
|  | 2570 | */ | 
|  | 2571 | if (!hw->tbi_compatibility_on) { | 
|  | 2572 | hw->tbi_compatibility_on = true; | 
|  | 2573 | rctl = er32(RCTL); | 
|  | 2574 | rctl |= E1000_RCTL_SBP; | 
|  | 2575 | ew32(RCTL, rctl); | 
|  | 2576 | } | 
|  | 2577 | } | 
|  | 2578 | } | 
|  | 2579 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2581 | if ((hw->media_type == e1000_media_type_fiber) || | 
|  | 2582 | (hw->media_type == e1000_media_type_internal_serdes)) | 
|  | 2583 | e1000_check_for_serdes_link_generic(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2584 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2585 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | } | 
|  | 2587 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2588 | /** | 
|  | 2589 | * e1000_get_speed_and_duplex | 
|  | 2590 | * @hw: Struct containing variables accessed by shared code | 
|  | 2591 | * @speed: Speed of the connection | 
|  | 2592 | * @duplex: Duplex setting of the connection | 
|  | 2593 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 | * Detects the current speed and duplex settings of the hardware. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2595 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2596 | s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2598 | u32 status; | 
|  | 2599 | s32 ret_val; | 
|  | 2600 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2602 | e_dbg("e1000_get_speed_and_duplex"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2604 | if (hw->mac_type >= e1000_82543) { | 
|  | 2605 | status = er32(STATUS); | 
|  | 2606 | if (status & E1000_STATUS_SPEED_1000) { | 
|  | 2607 | *speed = SPEED_1000; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2608 | e_dbg("1000 Mbs, "); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2609 | } else if (status & E1000_STATUS_SPEED_100) { | 
|  | 2610 | *speed = SPEED_100; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2611 | e_dbg("100 Mbs, "); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2612 | } else { | 
|  | 2613 | *speed = SPEED_10; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2614 | e_dbg("10 Mbs, "); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2615 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2617 | if (status & E1000_STATUS_FD) { | 
|  | 2618 | *duplex = FULL_DUPLEX; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2619 | e_dbg("Full Duplex\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2620 | } else { | 
|  | 2621 | *duplex = HALF_DUPLEX; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2622 | e_dbg(" Half Duplex\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2623 | } | 
|  | 2624 | } else { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2625 | e_dbg("1000 Mbs, Full Duplex\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2626 | *speed = SPEED_1000; | 
|  | 2627 | *duplex = FULL_DUPLEX; | 
|  | 2628 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2630 | /* IGP01 PHY may advertise full duplex operation after speed downgrade even | 
|  | 2631 | * if it is operating at half duplex.  Here we set the duplex settings to | 
|  | 2632 | * match the duplex in the link partner's capabilities. | 
|  | 2633 | */ | 
|  | 2634 | if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) { | 
|  | 2635 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data); | 
|  | 2636 | if (ret_val) | 
|  | 2637 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2639 | if (!(phy_data & NWAY_ER_LP_NWAY_CAPS)) | 
|  | 2640 | *duplex = HALF_DUPLEX; | 
|  | 2641 | else { | 
|  | 2642 | ret_val = | 
|  | 2643 | e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data); | 
|  | 2644 | if (ret_val) | 
|  | 2645 | return ret_val; | 
|  | 2646 | if ((*speed == SPEED_100 | 
|  | 2647 | && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) | 
|  | 2648 | || (*speed == SPEED_10 | 
|  | 2649 | && !(phy_data & NWAY_LPAR_10T_FD_CAPS))) | 
|  | 2650 | *duplex = HALF_DUPLEX; | 
|  | 2651 | } | 
|  | 2652 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2654 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | } | 
|  | 2656 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2657 | /** | 
|  | 2658 | * e1000_wait_autoneg | 
|  | 2659 | * @hw: Struct containing variables accessed by shared code | 
|  | 2660 | * | 
|  | 2661 | * Blocks until autoneg completes or times out (~4.5 seconds) | 
|  | 2662 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2663 | static s32 e1000_wait_autoneg(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2665 | s32 ret_val; | 
|  | 2666 | u16 i; | 
|  | 2667 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2669 | e_dbg("e1000_wait_autoneg"); | 
|  | 2670 | e_dbg("Waiting for Auto-Neg to complete.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2672 | /* We will wait for autoneg to complete or 4.5 seconds to expire. */ | 
|  | 2673 | for (i = PHY_AUTO_NEG_TIME; i > 0; i--) { | 
|  | 2674 | /* Read the MII Status Register and wait for Auto-Neg | 
|  | 2675 | * Complete bit to be set. | 
|  | 2676 | */ | 
|  | 2677 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 2678 | if (ret_val) | 
|  | 2679 | return ret_val; | 
|  | 2680 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 2681 | if (ret_val) | 
|  | 2682 | return ret_val; | 
|  | 2683 | if (phy_data & MII_SR_AUTONEG_COMPLETE) { | 
|  | 2684 | return E1000_SUCCESS; | 
|  | 2685 | } | 
|  | 2686 | msleep(100); | 
|  | 2687 | } | 
|  | 2688 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | } | 
|  | 2690 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2691 | /** | 
|  | 2692 | * e1000_raise_mdi_clk - Raises the Management Data Clock | 
|  | 2693 | * @hw: Struct containing variables accessed by shared code | 
|  | 2694 | * @ctrl: Device control register's current value | 
|  | 2695 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2696 | static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2698 | /* Raise the clock input to the Management Data Clock (by setting the MDC | 
|  | 2699 | * bit), and then delay 10 microseconds. | 
|  | 2700 | */ | 
|  | 2701 | ew32(CTRL, (*ctrl | E1000_CTRL_MDC)); | 
|  | 2702 | E1000_WRITE_FLUSH(); | 
|  | 2703 | udelay(10); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | } | 
|  | 2705 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2706 | /** | 
|  | 2707 | * e1000_lower_mdi_clk - Lowers the Management Data Clock | 
|  | 2708 | * @hw: Struct containing variables accessed by shared code | 
|  | 2709 | * @ctrl: Device control register's current value | 
|  | 2710 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2711 | static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2713 | /* Lower the clock input to the Management Data Clock (by clearing the MDC | 
|  | 2714 | * bit), and then delay 10 microseconds. | 
|  | 2715 | */ | 
|  | 2716 | ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC)); | 
|  | 2717 | E1000_WRITE_FLUSH(); | 
|  | 2718 | udelay(10); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | } | 
|  | 2720 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2721 | /** | 
|  | 2722 | * e1000_shift_out_mdi_bits - Shifts data bits out to the PHY | 
|  | 2723 | * @hw: Struct containing variables accessed by shared code | 
|  | 2724 | * @data: Data to send out to the PHY | 
|  | 2725 | * @count: Number of bits to shift out | 
|  | 2726 | * | 
|  | 2727 | * Bits are shifted out in MSB to LSB order. | 
|  | 2728 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2729 | static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2731 | u32 ctrl; | 
|  | 2732 | u32 mask; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2734 | /* We need to shift "count" number of bits out to the PHY. So, the value | 
|  | 2735 | * in the "data" parameter will be shifted out to the PHY one bit at a | 
|  | 2736 | * time. In order to do this, "data" must be broken down into bits. | 
|  | 2737 | */ | 
|  | 2738 | mask = 0x01; | 
|  | 2739 | mask <<= (count - 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2741 | ctrl = er32(CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2743 | /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */ | 
|  | 2744 | ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2746 | while (mask) { | 
|  | 2747 | /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and | 
|  | 2748 | * then raising and lowering the Management Data Clock. A "0" is | 
|  | 2749 | * shifted out to the PHY by setting the MDIO bit to "0" and then | 
|  | 2750 | * raising and lowering the clock. | 
|  | 2751 | */ | 
|  | 2752 | if (data & mask) | 
|  | 2753 | ctrl |= E1000_CTRL_MDIO; | 
|  | 2754 | else | 
|  | 2755 | ctrl &= ~E1000_CTRL_MDIO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2757 | ew32(CTRL, ctrl); | 
|  | 2758 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2760 | udelay(10); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2762 | e1000_raise_mdi_clk(hw, &ctrl); | 
|  | 2763 | e1000_lower_mdi_clk(hw, &ctrl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2765 | mask = mask >> 1; | 
|  | 2766 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | } | 
|  | 2768 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2769 | /** | 
|  | 2770 | * e1000_shift_in_mdi_bits - Shifts data bits in from the PHY | 
|  | 2771 | * @hw: Struct containing variables accessed by shared code | 
|  | 2772 | * | 
|  | 2773 | * Bits are shifted in in MSB to LSB order. | 
|  | 2774 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2775 | static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2777 | u32 ctrl; | 
|  | 2778 | u16 data = 0; | 
|  | 2779 | u8 i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2781 | /* In order to read a register from the PHY, we need to shift in a total | 
|  | 2782 | * of 18 bits from the PHY. The first two bit (turnaround) times are used | 
|  | 2783 | * to avoid contention on the MDIO pin when a read operation is performed. | 
|  | 2784 | * These two bits are ignored by us and thrown away. Bits are "shifted in" | 
|  | 2785 | * by raising the input to the Management Data Clock (setting the MDC bit), | 
|  | 2786 | * and then reading the value of the MDIO bit. | 
|  | 2787 | */ | 
|  | 2788 | ctrl = er32(CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2790 | /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */ | 
|  | 2791 | ctrl &= ~E1000_CTRL_MDIO_DIR; | 
|  | 2792 | ctrl &= ~E1000_CTRL_MDIO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2794 | ew32(CTRL, ctrl); | 
|  | 2795 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2797 | /* Raise and Lower the clock before reading in the data. This accounts for | 
|  | 2798 | * the turnaround bits. The first clock occurred when we clocked out the | 
|  | 2799 | * last bit of the Register Address. | 
|  | 2800 | */ | 
|  | 2801 | e1000_raise_mdi_clk(hw, &ctrl); | 
|  | 2802 | e1000_lower_mdi_clk(hw, &ctrl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2804 | for (data = 0, i = 0; i < 16; i++) { | 
|  | 2805 | data = data << 1; | 
|  | 2806 | e1000_raise_mdi_clk(hw, &ctrl); | 
|  | 2807 | ctrl = er32(CTRL); | 
|  | 2808 | /* Check to see if we shifted in a "1". */ | 
|  | 2809 | if (ctrl & E1000_CTRL_MDIO) | 
|  | 2810 | data |= 1; | 
|  | 2811 | e1000_lower_mdi_clk(hw, &ctrl); | 
|  | 2812 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2814 | e1000_raise_mdi_clk(hw, &ctrl); | 
|  | 2815 | e1000_lower_mdi_clk(hw, &ctrl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2817 | return data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | } | 
|  | 2819 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2820 |  | 
|  | 2821 | /** | 
|  | 2822 | * e1000_read_phy_reg - read a phy register | 
|  | 2823 | * @hw: Struct containing variables accessed by shared code | 
|  | 2824 | * @reg_addr: address of the PHY register to read | 
|  | 2825 | * | 
|  | 2826 | * Reads the value from a PHY register, if the value is on a specific non zero | 
|  | 2827 | * page, sets the page first. | 
|  | 2828 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2829 | s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2831 | u32 ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2833 | e_dbg("e1000_read_phy_reg"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2835 | if ((hw->phy_type == e1000_phy_igp) && | 
|  | 2836 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { | 
|  | 2837 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, | 
|  | 2838 | (u16) reg_addr); | 
|  | 2839 | if (ret_val) | 
|  | 2840 | return ret_val; | 
|  | 2841 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2843 | ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, | 
|  | 2844 | phy_data); | 
|  | 2845 |  | 
|  | 2846 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | } | 
|  | 2848 |  | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2849 | static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, | 
|  | 2850 | u16 *phy_data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2852 | u32 i; | 
|  | 2853 | u32 mdic = 0; | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2854 | const u32 phy_addr = (hw->mac_type == e1000_ce4100) ? hw->phy_addr : 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2856 | e_dbg("e1000_read_phy_reg_ex"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2858 | if (reg_addr > MAX_PHY_REG_ADDRESS) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2859 | e_dbg("PHY Address %d is out of range\n", reg_addr); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2860 | return -E1000_ERR_PARAM; | 
|  | 2861 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2863 | if (hw->mac_type > e1000_82543) { | 
|  | 2864 | /* Set up Op-code, Phy Address, and register address in the MDI | 
|  | 2865 | * Control register.  The MAC will take care of interfacing with the | 
|  | 2866 | * PHY to retrieve the desired data. | 
|  | 2867 | */ | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2868 | if (hw->mac_type == e1000_ce4100) { | 
|  | 2869 | mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) | | 
|  | 2870 | (phy_addr << E1000_MDIC_PHY_SHIFT) | | 
|  | 2871 | (INTEL_CE_GBE_MDIC_OP_READ) | | 
|  | 2872 | (INTEL_CE_GBE_MDIC_GO)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2873 |  | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2874 | writel(mdic, E1000_MDIO_CMD); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 |  | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2876 | /* Poll the ready bit to see if the MDI read | 
|  | 2877 | * completed | 
|  | 2878 | */ | 
|  | 2879 | for (i = 0; i < 64; i++) { | 
|  | 2880 | udelay(50); | 
|  | 2881 | mdic = readl(E1000_MDIO_CMD); | 
|  | 2882 | if (!(mdic & INTEL_CE_GBE_MDIC_GO)) | 
|  | 2883 | break; | 
|  | 2884 | } | 
|  | 2885 |  | 
|  | 2886 | if (mdic & INTEL_CE_GBE_MDIC_GO) { | 
|  | 2887 | e_dbg("MDI Read did not complete\n"); | 
|  | 2888 | return -E1000_ERR_PHY; | 
|  | 2889 | } | 
|  | 2890 |  | 
|  | 2891 | mdic = readl(E1000_MDIO_STS); | 
|  | 2892 | if (mdic & INTEL_CE_GBE_MDIC_READ_ERROR) { | 
|  | 2893 | e_dbg("MDI Read Error\n"); | 
|  | 2894 | return -E1000_ERR_PHY; | 
|  | 2895 | } | 
|  | 2896 | *phy_data = (u16) mdic; | 
|  | 2897 | } else { | 
|  | 2898 | mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) | | 
|  | 2899 | (phy_addr << E1000_MDIC_PHY_SHIFT) | | 
|  | 2900 | (E1000_MDIC_OP_READ)); | 
|  | 2901 |  | 
|  | 2902 | ew32(MDIC, mdic); | 
|  | 2903 |  | 
|  | 2904 | /* Poll the ready bit to see if the MDI read | 
|  | 2905 | * completed | 
|  | 2906 | */ | 
|  | 2907 | for (i = 0; i < 64; i++) { | 
|  | 2908 | udelay(50); | 
|  | 2909 | mdic = er32(MDIC); | 
|  | 2910 | if (mdic & E1000_MDIC_READY) | 
|  | 2911 | break; | 
|  | 2912 | } | 
|  | 2913 | if (!(mdic & E1000_MDIC_READY)) { | 
|  | 2914 | e_dbg("MDI Read did not complete\n"); | 
|  | 2915 | return -E1000_ERR_PHY; | 
|  | 2916 | } | 
|  | 2917 | if (mdic & E1000_MDIC_ERROR) { | 
|  | 2918 | e_dbg("MDI Error\n"); | 
|  | 2919 | return -E1000_ERR_PHY; | 
|  | 2920 | } | 
|  | 2921 | *phy_data = (u16) mdic; | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2922 | } | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2923 | } else { | 
|  | 2924 | /* We must first send a preamble through the MDIO pin to signal the | 
|  | 2925 | * beginning of an MII instruction.  This is done by sending 32 | 
|  | 2926 | * consecutive "1" bits. | 
|  | 2927 | */ | 
|  | 2928 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2930 | /* Now combine the next few fields that are required for a read | 
|  | 2931 | * operation.  We use this method instead of calling the | 
|  | 2932 | * e1000_shift_out_mdi_bits routine five different times. The format of | 
|  | 2933 | * a MII read instruction consists of a shift out of 14 bits and is | 
|  | 2934 | * defined as follows: | 
|  | 2935 | *    <Preamble><SOF><Op Code><Phy Addr><Reg Addr> | 
|  | 2936 | * followed by a shift in of 18 bits.  This first two bits shifted in | 
|  | 2937 | * are TurnAround bits used to avoid contention on the MDIO pin when a | 
|  | 2938 | * READ operation is performed.  These two bits are thrown away | 
|  | 2939 | * followed by a shift in of 16 bits which contains the desired data. | 
|  | 2940 | */ | 
|  | 2941 | mdic = ((reg_addr) | (phy_addr << 5) | | 
|  | 2942 | (PHY_OP_READ << 10) | (PHY_SOF << 12)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2944 | e1000_shift_out_mdi_bits(hw, mdic, 14); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2946 | /* Now that we've shifted out the read command to the MII, we need to | 
|  | 2947 | * "shift in" the 16-bit value (18 total bits) of the requested PHY | 
|  | 2948 | * register address. | 
|  | 2949 | */ | 
|  | 2950 | *phy_data = e1000_shift_in_mdi_bits(hw); | 
|  | 2951 | } | 
|  | 2952 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | } | 
|  | 2954 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2955 | /** | 
|  | 2956 | * e1000_write_phy_reg - write a phy register | 
|  | 2957 | * | 
|  | 2958 | * @hw: Struct containing variables accessed by shared code | 
|  | 2959 | * @reg_addr: address of the PHY register to write | 
|  | 2960 | * @data: data to write to the PHY | 
|  | 2961 |  | 
|  | 2962 | * Writes a value to a PHY register | 
|  | 2963 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2964 | s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2966 | u32 ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2968 | e_dbg("e1000_write_phy_reg"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2970 | if ((hw->phy_type == e1000_phy_igp) && | 
|  | 2971 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { | 
|  | 2972 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, | 
|  | 2973 | (u16) reg_addr); | 
|  | 2974 | if (ret_val) | 
|  | 2975 | return ret_val; | 
|  | 2976 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2978 | ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, | 
|  | 2979 | phy_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2981 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | } | 
|  | 2983 |  | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2984 | static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, | 
|  | 2985 | u16 phy_data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2987 | u32 i; | 
|  | 2988 | u32 mdic = 0; | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2989 | const u32 phy_addr = (hw->mac_type == e1000_ce4100) ? hw->phy_addr : 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2991 | e_dbg("e1000_write_phy_reg_ex"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2993 | if (reg_addr > MAX_PHY_REG_ADDRESS) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2994 | e_dbg("PHY Address %d is out of range\n", reg_addr); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2995 | return -E1000_ERR_PARAM; | 
|  | 2996 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2998 | if (hw->mac_type > e1000_82543) { | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2999 | /* Set up Op-code, Phy Address, register address, and data | 
|  | 3000 | * intended for the PHY register in the MDI Control register. | 
|  | 3001 | * The MAC will take care of interfacing with the PHY to send | 
|  | 3002 | * the desired data. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3003 | */ | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3004 | if (hw->mac_type == e1000_ce4100) { | 
|  | 3005 | mdic = (((u32) phy_data) | | 
|  | 3006 | (reg_addr << E1000_MDIC_REG_SHIFT) | | 
|  | 3007 | (phy_addr << E1000_MDIC_PHY_SHIFT) | | 
|  | 3008 | (INTEL_CE_GBE_MDIC_OP_WRITE) | | 
|  | 3009 | (INTEL_CE_GBE_MDIC_GO)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 |  | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3011 | writel(mdic, E1000_MDIO_CMD); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 |  | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3013 | /* Poll the ready bit to see if the MDI read | 
|  | 3014 | * completed | 
|  | 3015 | */ | 
|  | 3016 | for (i = 0; i < 640; i++) { | 
|  | 3017 | udelay(5); | 
|  | 3018 | mdic = readl(E1000_MDIO_CMD); | 
|  | 3019 | if (!(mdic & INTEL_CE_GBE_MDIC_GO)) | 
|  | 3020 | break; | 
|  | 3021 | } | 
|  | 3022 | if (mdic & INTEL_CE_GBE_MDIC_GO) { | 
|  | 3023 | e_dbg("MDI Write did not complete\n"); | 
|  | 3024 | return -E1000_ERR_PHY; | 
|  | 3025 | } | 
|  | 3026 | } else { | 
|  | 3027 | mdic = (((u32) phy_data) | | 
|  | 3028 | (reg_addr << E1000_MDIC_REG_SHIFT) | | 
|  | 3029 | (phy_addr << E1000_MDIC_PHY_SHIFT) | | 
|  | 3030 | (E1000_MDIC_OP_WRITE)); | 
|  | 3031 |  | 
|  | 3032 | ew32(MDIC, mdic); | 
|  | 3033 |  | 
|  | 3034 | /* Poll the ready bit to see if the MDI read | 
|  | 3035 | * completed | 
|  | 3036 | */ | 
|  | 3037 | for (i = 0; i < 641; i++) { | 
|  | 3038 | udelay(5); | 
|  | 3039 | mdic = er32(MDIC); | 
|  | 3040 | if (mdic & E1000_MDIC_READY) | 
|  | 3041 | break; | 
|  | 3042 | } | 
|  | 3043 | if (!(mdic & E1000_MDIC_READY)) { | 
|  | 3044 | e_dbg("MDI Write did not complete\n"); | 
|  | 3045 | return -E1000_ERR_PHY; | 
|  | 3046 | } | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3047 | } | 
|  | 3048 | } else { | 
|  | 3049 | /* We'll need to use the SW defined pins to shift the write command | 
|  | 3050 | * out to the PHY. We first send a preamble to the PHY to signal the | 
|  | 3051 | * beginning of the MII instruction.  This is done by sending 32 | 
|  | 3052 | * consecutive "1" bits. | 
|  | 3053 | */ | 
|  | 3054 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3056 | /* Now combine the remaining required fields that will indicate a | 
|  | 3057 | * write operation. We use this method instead of calling the | 
|  | 3058 | * e1000_shift_out_mdi_bits routine for each field in the command. The | 
|  | 3059 | * format of a MII write instruction is as follows: | 
|  | 3060 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>. | 
|  | 3061 | */ | 
|  | 3062 | mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) | | 
|  | 3063 | (PHY_OP_WRITE << 12) | (PHY_SOF << 14)); | 
|  | 3064 | mdic <<= 16; | 
|  | 3065 | mdic |= (u32) phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3067 | e1000_shift_out_mdi_bits(hw, mdic, 32); | 
|  | 3068 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3070 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | } | 
|  | 3072 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3073 | /** | 
|  | 3074 | * e1000_phy_hw_reset - reset the phy, hardware style | 
|  | 3075 | * @hw: Struct containing variables accessed by shared code | 
|  | 3076 | * | 
|  | 3077 | * Returns the PHY to the power-on reset state | 
|  | 3078 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3079 | s32 e1000_phy_hw_reset(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3081 | u32 ctrl, ctrl_ext; | 
|  | 3082 | u32 led_ctrl; | 
|  | 3083 | s32 ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3085 | e_dbg("e1000_phy_hw_reset"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3087 | e_dbg("Resetting Phy...\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3089 | if (hw->mac_type > e1000_82543) { | 
|  | 3090 | /* Read the device control register and assert the E1000_CTRL_PHY_RST | 
|  | 3091 | * bit. Then, take it out of reset. | 
|  | 3092 | * For e1000 hardware, we delay for 10ms between the assert | 
|  | 3093 | * and deassert. | 
|  | 3094 | */ | 
|  | 3095 | ctrl = er32(CTRL); | 
|  | 3096 | ew32(CTRL, ctrl | E1000_CTRL_PHY_RST); | 
|  | 3097 | E1000_WRITE_FLUSH(); | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3098 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3099 | msleep(10); | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3100 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3101 | ew32(CTRL, ctrl); | 
|  | 3102 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3104 | } else { | 
|  | 3105 | /* Read the Extended Device Control Register, assert the PHY_RESET_DIR | 
|  | 3106 | * bit to put the PHY into reset. Then, take it out of reset. | 
|  | 3107 | */ | 
|  | 3108 | ctrl_ext = er32(CTRL_EXT); | 
|  | 3109 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR; | 
|  | 3110 | ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA; | 
|  | 3111 | ew32(CTRL_EXT, ctrl_ext); | 
|  | 3112 | E1000_WRITE_FLUSH(); | 
|  | 3113 | msleep(10); | 
|  | 3114 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA; | 
|  | 3115 | ew32(CTRL_EXT, ctrl_ext); | 
|  | 3116 | E1000_WRITE_FLUSH(); | 
|  | 3117 | } | 
|  | 3118 | udelay(150); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3119 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3120 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { | 
|  | 3121 | /* Configure activity LED after PHY reset */ | 
|  | 3122 | led_ctrl = er32(LEDCTL); | 
|  | 3123 | led_ctrl &= IGP_ACTIVITY_LED_MASK; | 
|  | 3124 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); | 
|  | 3125 | ew32(LEDCTL, led_ctrl); | 
|  | 3126 | } | 
| Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3127 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3128 | /* Wait for FW to finish PHY configuration. */ | 
|  | 3129 | ret_val = e1000_get_phy_cfg_done(hw); | 
|  | 3130 | if (ret_val != E1000_SUCCESS) | 
|  | 3131 | return ret_val; | 
|  | 3132 |  | 
|  | 3133 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | } | 
|  | 3135 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3136 | /** | 
|  | 3137 | * e1000_phy_reset - reset the phy to commit settings | 
|  | 3138 | * @hw: Struct containing variables accessed by shared code | 
|  | 3139 | * | 
|  | 3140 | * Resets the PHY | 
|  | 3141 | * Sets bit 15 of the MII Control register | 
|  | 3142 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3143 | s32 e1000_phy_reset(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3145 | s32 ret_val; | 
|  | 3146 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3148 | e_dbg("e1000_phy_reset"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3150 | switch (hw->phy_type) { | 
|  | 3151 | case e1000_phy_igp: | 
|  | 3152 | ret_val = e1000_phy_hw_reset(hw); | 
|  | 3153 | if (ret_val) | 
|  | 3154 | return ret_val; | 
|  | 3155 | break; | 
|  | 3156 | default: | 
|  | 3157 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); | 
|  | 3158 | if (ret_val) | 
|  | 3159 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3161 | phy_data |= MII_CR_RESET; | 
|  | 3162 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); | 
|  | 3163 | if (ret_val) | 
|  | 3164 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3165 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3166 | udelay(1); | 
|  | 3167 | break; | 
|  | 3168 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3170 | if (hw->phy_type == e1000_phy_igp) | 
|  | 3171 | e1000_phy_init_script(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3173 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | } | 
|  | 3175 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3176 | /** | 
|  | 3177 | * e1000_detect_gig_phy - check the phy type | 
|  | 3178 | * @hw: Struct containing variables accessed by shared code | 
|  | 3179 | * | 
|  | 3180 | * Probes the expected PHY address for known PHY IDs | 
|  | 3181 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3182 | static s32 e1000_detect_gig_phy(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3184 | s32 phy_init_status, ret_val; | 
|  | 3185 | u16 phy_id_high, phy_id_low; | 
|  | 3186 | bool match = false; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3188 | e_dbg("e1000_detect_gig_phy"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3190 | if (hw->phy_id != 0) | 
|  | 3191 | return E1000_SUCCESS; | 
| Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3192 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3193 | /* Read the PHY ID Registers to identify which PHY is onboard. */ | 
|  | 3194 | ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high); | 
|  | 3195 | if (ret_val) | 
|  | 3196 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3198 | hw->phy_id = (u32) (phy_id_high << 16); | 
|  | 3199 | udelay(20); | 
|  | 3200 | ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low); | 
|  | 3201 | if (ret_val) | 
|  | 3202 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3204 | hw->phy_id |= (u32) (phy_id_low & PHY_REVISION_MASK); | 
|  | 3205 | hw->phy_revision = (u32) phy_id_low & ~PHY_REVISION_MASK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3207 | switch (hw->mac_type) { | 
|  | 3208 | case e1000_82543: | 
|  | 3209 | if (hw->phy_id == M88E1000_E_PHY_ID) | 
|  | 3210 | match = true; | 
|  | 3211 | break; | 
|  | 3212 | case e1000_82544: | 
|  | 3213 | if (hw->phy_id == M88E1000_I_PHY_ID) | 
|  | 3214 | match = true; | 
|  | 3215 | break; | 
|  | 3216 | case e1000_82540: | 
|  | 3217 | case e1000_82545: | 
|  | 3218 | case e1000_82545_rev_3: | 
|  | 3219 | case e1000_82546: | 
|  | 3220 | case e1000_82546_rev_3: | 
|  | 3221 | if (hw->phy_id == M88E1011_I_PHY_ID) | 
|  | 3222 | match = true; | 
|  | 3223 | break; | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3224 | case e1000_ce4100: | 
|  | 3225 | if ((hw->phy_id == RTL8211B_PHY_ID) || | 
| Florian Fainelli | cf8e09b | 2011-01-24 14:48:03 +0000 | [diff] [blame] | 3226 | (hw->phy_id == RTL8201N_PHY_ID) || | 
|  | 3227 | (hw->phy_id == M88E1118_E_PHY_ID)) | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3228 | match = true; | 
|  | 3229 | break; | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3230 | case e1000_82541: | 
|  | 3231 | case e1000_82541_rev_2: | 
|  | 3232 | case e1000_82547: | 
|  | 3233 | case e1000_82547_rev_2: | 
|  | 3234 | if (hw->phy_id == IGP01E1000_I_PHY_ID) | 
|  | 3235 | match = true; | 
|  | 3236 | break; | 
|  | 3237 | default: | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3238 | e_dbg("Invalid MAC type %d\n", hw->mac_type); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3239 | return -E1000_ERR_CONFIG; | 
|  | 3240 | } | 
|  | 3241 | phy_init_status = e1000_set_phy_type(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3243 | if ((match) && (phy_init_status == E1000_SUCCESS)) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3244 | e_dbg("PHY ID 0x%X detected\n", hw->phy_id); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3245 | return E1000_SUCCESS; | 
|  | 3246 | } | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3247 | e_dbg("Invalid PHY ID 0x%X\n", hw->phy_id); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3248 | return -E1000_ERR_PHY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | } | 
|  | 3250 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3251 | /** | 
|  | 3252 | * e1000_phy_reset_dsp - reset DSP | 
|  | 3253 | * @hw: Struct containing variables accessed by shared code | 
|  | 3254 | * | 
|  | 3255 | * Resets the PHY's DSP | 
|  | 3256 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3257 | static s32 e1000_phy_reset_dsp(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3259 | s32 ret_val; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3260 | e_dbg("e1000_phy_reset_dsp"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3262 | do { | 
|  | 3263 | ret_val = e1000_write_phy_reg(hw, 29, 0x001d); | 
|  | 3264 | if (ret_val) | 
|  | 3265 | break; | 
|  | 3266 | ret_val = e1000_write_phy_reg(hw, 30, 0x00c1); | 
|  | 3267 | if (ret_val) | 
|  | 3268 | break; | 
|  | 3269 | ret_val = e1000_write_phy_reg(hw, 30, 0x0000); | 
|  | 3270 | if (ret_val) | 
|  | 3271 | break; | 
|  | 3272 | ret_val = E1000_SUCCESS; | 
|  | 3273 | } while (0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3275 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | } | 
|  | 3277 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3278 | /** | 
|  | 3279 | * e1000_phy_igp_get_info - get igp specific registers | 
|  | 3280 | * @hw: Struct containing variables accessed by shared code | 
|  | 3281 | * @phy_info: PHY information structure | 
|  | 3282 | * | 
|  | 3283 | * Get PHY information from various PHY registers for igp PHY only. | 
|  | 3284 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3285 | static s32 e1000_phy_igp_get_info(struct e1000_hw *hw, | 
|  | 3286 | struct e1000_phy_info *phy_info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3288 | s32 ret_val; | 
|  | 3289 | u16 phy_data, min_length, max_length, average; | 
|  | 3290 | e1000_rev_polarity polarity; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3292 | e_dbg("e1000_phy_igp_get_info"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3294 | /* The downshift status is checked only once, after link is established, | 
|  | 3295 | * and it stored in the hw->speed_downgraded parameter. */ | 
|  | 3296 | phy_info->downshift = (e1000_downshift) hw->speed_downgraded; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3298 | /* IGP01E1000 does not need to support it. */ | 
|  | 3299 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3301 | /* IGP01E1000 always correct polarity reversal */ | 
|  | 3302 | phy_info->polarity_correction = e1000_polarity_reversal_enabled; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3304 | /* Check polarity status */ | 
|  | 3305 | ret_val = e1000_check_polarity(hw, &polarity); | 
|  | 3306 | if (ret_val) | 
|  | 3307 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3309 | phy_info->cable_polarity = polarity; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3311 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data); | 
|  | 3312 | if (ret_val) | 
|  | 3313 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3315 | phy_info->mdix_mode = | 
|  | 3316 | (e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >> | 
|  | 3317 | IGP01E1000_PSSR_MDIX_SHIFT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3319 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == | 
|  | 3320 | IGP01E1000_PSSR_SPEED_1000MBPS) { | 
|  | 3321 | /* Local/Remote Receiver Information are only valid at 1000 Mbps */ | 
|  | 3322 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); | 
|  | 3323 | if (ret_val) | 
|  | 3324 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3326 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> | 
|  | 3327 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? | 
|  | 3328 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; | 
|  | 3329 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> | 
|  | 3330 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? | 
|  | 3331 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3333 | /* Get cable length */ | 
|  | 3334 | ret_val = e1000_get_cable_length(hw, &min_length, &max_length); | 
|  | 3335 | if (ret_val) | 
|  | 3336 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3338 | /* Translate to old method */ | 
|  | 3339 | average = (max_length + min_length) / 2; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3340 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3341 | if (average <= e1000_igp_cable_length_50) | 
|  | 3342 | phy_info->cable_length = e1000_cable_length_50; | 
|  | 3343 | else if (average <= e1000_igp_cable_length_80) | 
|  | 3344 | phy_info->cable_length = e1000_cable_length_50_80; | 
|  | 3345 | else if (average <= e1000_igp_cable_length_110) | 
|  | 3346 | phy_info->cable_length = e1000_cable_length_80_110; | 
|  | 3347 | else if (average <= e1000_igp_cable_length_140) | 
|  | 3348 | phy_info->cable_length = e1000_cable_length_110_140; | 
|  | 3349 | else | 
|  | 3350 | phy_info->cable_length = e1000_cable_length_140; | 
|  | 3351 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3353 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | } | 
|  | 3355 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3356 | /** | 
|  | 3357 | * e1000_phy_m88_get_info - get m88 specific registers | 
|  | 3358 | * @hw: Struct containing variables accessed by shared code | 
|  | 3359 | * @phy_info: PHY information structure | 
|  | 3360 | * | 
|  | 3361 | * Get PHY information from various PHY registers for m88 PHY only. | 
|  | 3362 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3363 | static s32 e1000_phy_m88_get_info(struct e1000_hw *hw, | 
|  | 3364 | struct e1000_phy_info *phy_info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3366 | s32 ret_val; | 
|  | 3367 | u16 phy_data; | 
|  | 3368 | e1000_rev_polarity polarity; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3370 | e_dbg("e1000_phy_m88_get_info"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3372 | /* The downshift status is checked only once, after link is established, | 
|  | 3373 | * and it stored in the hw->speed_downgraded parameter. */ | 
|  | 3374 | phy_info->downshift = (e1000_downshift) hw->speed_downgraded; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3376 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); | 
|  | 3377 | if (ret_val) | 
|  | 3378 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3380 | phy_info->extended_10bt_distance = | 
|  | 3381 | ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >> | 
|  | 3382 | M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ? | 
|  | 3383 | e1000_10bt_ext_dist_enable_lower : | 
|  | 3384 | e1000_10bt_ext_dist_enable_normal; | 
| Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3385 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3386 | phy_info->polarity_correction = | 
|  | 3387 | ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >> | 
|  | 3388 | M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ? | 
|  | 3389 | e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3391 | /* Check polarity status */ | 
|  | 3392 | ret_val = e1000_check_polarity(hw, &polarity); | 
|  | 3393 | if (ret_val) | 
|  | 3394 | return ret_val; | 
|  | 3395 | phy_info->cable_polarity = polarity; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3397 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); | 
|  | 3398 | if (ret_val) | 
|  | 3399 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3401 | phy_info->mdix_mode = | 
|  | 3402 | (e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >> | 
|  | 3403 | M88E1000_PSSR_MDIX_SHIFT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3405 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) { | 
|  | 3406 | /* Cable Length Estimation and Local/Remote Receiver Information | 
|  | 3407 | * are only valid at 1000 Mbps. | 
|  | 3408 | */ | 
|  | 3409 | phy_info->cable_length = | 
|  | 3410 | (e1000_cable_length) ((phy_data & | 
|  | 3411 | M88E1000_PSSR_CABLE_LENGTH) >> | 
|  | 3412 | M88E1000_PSSR_CABLE_LENGTH_SHIFT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3414 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); | 
|  | 3415 | if (ret_val) | 
|  | 3416 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3418 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> | 
|  | 3419 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? | 
|  | 3420 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; | 
|  | 3421 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> | 
|  | 3422 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? | 
|  | 3423 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3425 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3427 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | } | 
|  | 3429 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3430 | /** | 
|  | 3431 | * e1000_phy_get_info - request phy info | 
|  | 3432 | * @hw: Struct containing variables accessed by shared code | 
|  | 3433 | * @phy_info: PHY information structure | 
|  | 3434 | * | 
|  | 3435 | * Get PHY information from various PHY registers | 
|  | 3436 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3437 | s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3439 | s32 ret_val; | 
|  | 3440 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3441 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3442 | e_dbg("e1000_phy_get_info"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3444 | phy_info->cable_length = e1000_cable_length_undefined; | 
|  | 3445 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined; | 
|  | 3446 | phy_info->cable_polarity = e1000_rev_polarity_undefined; | 
|  | 3447 | phy_info->downshift = e1000_downshift_undefined; | 
|  | 3448 | phy_info->polarity_correction = e1000_polarity_reversal_undefined; | 
|  | 3449 | phy_info->mdix_mode = e1000_auto_x_mode_undefined; | 
|  | 3450 | phy_info->local_rx = e1000_1000t_rx_status_undefined; | 
|  | 3451 | phy_info->remote_rx = e1000_1000t_rx_status_undefined; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3453 | if (hw->media_type != e1000_media_type_copper) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3454 | e_dbg("PHY info is only valid for copper media\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3455 | return -E1000_ERR_CONFIG; | 
|  | 3456 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3458 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 3459 | if (ret_val) | 
|  | 3460 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3462 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 3463 | if (ret_val) | 
|  | 3464 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3466 | if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3467 | e_dbg("PHY info is only valid if link is up\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3468 | return -E1000_ERR_CONFIG; | 
|  | 3469 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3471 | if (hw->phy_type == e1000_phy_igp) | 
|  | 3472 | return e1000_phy_igp_get_info(hw, phy_info); | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3473 | else if ((hw->phy_type == e1000_phy_8211) || | 
|  | 3474 | (hw->phy_type == e1000_phy_8201)) | 
|  | 3475 | return E1000_SUCCESS; | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3476 | else | 
|  | 3477 | return e1000_phy_m88_get_info(hw, phy_info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | } | 
|  | 3479 |  | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3480 | s32 e1000_validate_mdi_setting(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3481 | { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3482 | e_dbg("e1000_validate_mdi_settings"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3484 | if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3485 | e_dbg("Invalid MDI setting detected\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3486 | hw->mdix = 1; | 
|  | 3487 | return -E1000_ERR_CONFIG; | 
|  | 3488 | } | 
|  | 3489 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3490 | } | 
|  | 3491 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3492 | /** | 
|  | 3493 | * e1000_init_eeprom_params - initialize sw eeprom vars | 
|  | 3494 | * @hw: Struct containing variables accessed by shared code | 
|  | 3495 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | * Sets up eeprom variables in the hw struct.  Must be called after mac_type | 
| Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 3497 | * is configured. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3498 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3499 | s32 e1000_init_eeprom_params(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3501 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 3502 | u32 eecd = er32(EECD); | 
|  | 3503 | s32 ret_val = E1000_SUCCESS; | 
|  | 3504 | u16 eeprom_size; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3505 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3506 | e_dbg("e1000_init_eeprom_params"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3507 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3508 | switch (hw->mac_type) { | 
|  | 3509 | case e1000_82542_rev2_0: | 
|  | 3510 | case e1000_82542_rev2_1: | 
|  | 3511 | case e1000_82543: | 
|  | 3512 | case e1000_82544: | 
|  | 3513 | eeprom->type = e1000_eeprom_microwire; | 
|  | 3514 | eeprom->word_size = 64; | 
|  | 3515 | eeprom->opcode_bits = 3; | 
|  | 3516 | eeprom->address_bits = 6; | 
|  | 3517 | eeprom->delay_usec = 50; | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3518 | break; | 
|  | 3519 | case e1000_82540: | 
|  | 3520 | case e1000_82545: | 
|  | 3521 | case e1000_82545_rev_3: | 
|  | 3522 | case e1000_82546: | 
|  | 3523 | case e1000_82546_rev_3: | 
|  | 3524 | eeprom->type = e1000_eeprom_microwire; | 
|  | 3525 | eeprom->opcode_bits = 3; | 
|  | 3526 | eeprom->delay_usec = 50; | 
|  | 3527 | if (eecd & E1000_EECD_SIZE) { | 
|  | 3528 | eeprom->word_size = 256; | 
|  | 3529 | eeprom->address_bits = 8; | 
|  | 3530 | } else { | 
|  | 3531 | eeprom->word_size = 64; | 
|  | 3532 | eeprom->address_bits = 6; | 
|  | 3533 | } | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3534 | break; | 
|  | 3535 | case e1000_82541: | 
|  | 3536 | case e1000_82541_rev_2: | 
|  | 3537 | case e1000_82547: | 
|  | 3538 | case e1000_82547_rev_2: | 
|  | 3539 | if (eecd & E1000_EECD_TYPE) { | 
|  | 3540 | eeprom->type = e1000_eeprom_spi; | 
|  | 3541 | eeprom->opcode_bits = 8; | 
|  | 3542 | eeprom->delay_usec = 1; | 
|  | 3543 | if (eecd & E1000_EECD_ADDR_BITS) { | 
|  | 3544 | eeprom->page_size = 32; | 
|  | 3545 | eeprom->address_bits = 16; | 
|  | 3546 | } else { | 
|  | 3547 | eeprom->page_size = 8; | 
|  | 3548 | eeprom->address_bits = 8; | 
|  | 3549 | } | 
|  | 3550 | } else { | 
|  | 3551 | eeprom->type = e1000_eeprom_microwire; | 
|  | 3552 | eeprom->opcode_bits = 3; | 
|  | 3553 | eeprom->delay_usec = 50; | 
|  | 3554 | if (eecd & E1000_EECD_ADDR_BITS) { | 
|  | 3555 | eeprom->word_size = 256; | 
|  | 3556 | eeprom->address_bits = 8; | 
|  | 3557 | } else { | 
|  | 3558 | eeprom->word_size = 64; | 
|  | 3559 | eeprom->address_bits = 6; | 
|  | 3560 | } | 
|  | 3561 | } | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3562 | break; | 
|  | 3563 | default: | 
|  | 3564 | break; | 
|  | 3565 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3567 | if (eeprom->type == e1000_eeprom_spi) { | 
|  | 3568 | /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to | 
|  | 3569 | * 32KB (incremented by powers of 2). | 
|  | 3570 | */ | 
|  | 3571 | /* Set to default value for initial eeprom read. */ | 
|  | 3572 | eeprom->word_size = 64; | 
|  | 3573 | ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size); | 
|  | 3574 | if (ret_val) | 
|  | 3575 | return ret_val; | 
|  | 3576 | eeprom_size = | 
|  | 3577 | (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT; | 
|  | 3578 | /* 256B eeprom size was not supported in earlier hardware, so we | 
|  | 3579 | * bump eeprom_size up one to ensure that "1" (which maps to 256B) | 
|  | 3580 | * is never the result used in the shifting logic below. */ | 
|  | 3581 | if (eeprom_size) | 
|  | 3582 | eeprom_size++; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3583 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3584 | eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT); | 
|  | 3585 | } | 
|  | 3586 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | } | 
|  | 3588 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3589 | /** | 
|  | 3590 | * e1000_raise_ee_clk - Raises the EEPROM's clock input. | 
|  | 3591 | * @hw: Struct containing variables accessed by shared code | 
|  | 3592 | * @eecd: EECD's current value | 
|  | 3593 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3594 | static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3596 | /* Raise the clock input to the EEPROM (by setting the SK bit), and then | 
|  | 3597 | * wait <delay> microseconds. | 
|  | 3598 | */ | 
|  | 3599 | *eecd = *eecd | E1000_EECD_SK; | 
|  | 3600 | ew32(EECD, *eecd); | 
|  | 3601 | E1000_WRITE_FLUSH(); | 
|  | 3602 | udelay(hw->eeprom.delay_usec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | } | 
|  | 3604 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3605 | /** | 
|  | 3606 | * e1000_lower_ee_clk - Lowers the EEPROM's clock input. | 
|  | 3607 | * @hw: Struct containing variables accessed by shared code | 
|  | 3608 | * @eecd: EECD's current value | 
|  | 3609 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3610 | static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3612 | /* Lower the clock input to the EEPROM (by clearing the SK bit), and then | 
|  | 3613 | * wait 50 microseconds. | 
|  | 3614 | */ | 
|  | 3615 | *eecd = *eecd & ~E1000_EECD_SK; | 
|  | 3616 | ew32(EECD, *eecd); | 
|  | 3617 | E1000_WRITE_FLUSH(); | 
|  | 3618 | udelay(hw->eeprom.delay_usec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | } | 
|  | 3620 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3621 | /** | 
|  | 3622 | * e1000_shift_out_ee_bits - Shift data bits out to the EEPROM. | 
|  | 3623 | * @hw: Struct containing variables accessed by shared code | 
|  | 3624 | * @data: data to send to the EEPROM | 
|  | 3625 | * @count: number of bits to shift out | 
|  | 3626 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3627 | static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3629 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 3630 | u32 eecd; | 
|  | 3631 | u32 mask; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3633 | /* We need to shift "count" bits out to the EEPROM. So, value in the | 
|  | 3634 | * "data" parameter will be shifted out to the EEPROM one bit at a time. | 
|  | 3635 | * In order to do this, "data" must be broken down into bits. | 
|  | 3636 | */ | 
|  | 3637 | mask = 0x01 << (count - 1); | 
|  | 3638 | eecd = er32(EECD); | 
|  | 3639 | if (eeprom->type == e1000_eeprom_microwire) { | 
|  | 3640 | eecd &= ~E1000_EECD_DO; | 
|  | 3641 | } else if (eeprom->type == e1000_eeprom_spi) { | 
|  | 3642 | eecd |= E1000_EECD_DO; | 
|  | 3643 | } | 
|  | 3644 | do { | 
|  | 3645 | /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1", | 
|  | 3646 | * and then raising and then lowering the clock (the SK bit controls | 
|  | 3647 | * the clock input to the EEPROM).  A "0" is shifted out to the EEPROM | 
|  | 3648 | * by setting "DI" to "0" and then raising and then lowering the clock. | 
|  | 3649 | */ | 
|  | 3650 | eecd &= ~E1000_EECD_DI; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3652 | if (data & mask) | 
|  | 3653 | eecd |= E1000_EECD_DI; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3655 | ew32(EECD, eecd); | 
|  | 3656 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3658 | udelay(eeprom->delay_usec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3660 | e1000_raise_ee_clk(hw, &eecd); | 
|  | 3661 | e1000_lower_ee_clk(hw, &eecd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3663 | mask = mask >> 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3665 | } while (mask); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3666 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3667 | /* We leave the "DI" bit set to "0" when we leave this routine. */ | 
|  | 3668 | eecd &= ~E1000_EECD_DI; | 
|  | 3669 | ew32(EECD, eecd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3670 | } | 
|  | 3671 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3672 | /** | 
|  | 3673 | * e1000_shift_in_ee_bits - Shift data bits in from the EEPROM | 
|  | 3674 | * @hw: Struct containing variables accessed by shared code | 
|  | 3675 | * @count: number of bits to shift in | 
|  | 3676 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3677 | static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3679 | u32 eecd; | 
|  | 3680 | u32 i; | 
|  | 3681 | u16 data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3683 | /* In order to read a register from the EEPROM, we need to shift 'count' | 
|  | 3684 | * bits in from the EEPROM. Bits are "shifted in" by raising the clock | 
|  | 3685 | * input to the EEPROM (setting the SK bit), and then reading the value of | 
|  | 3686 | * the "DO" bit.  During this "shifting in" process the "DI" bit should | 
|  | 3687 | * always be clear. | 
|  | 3688 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3690 | eecd = er32(EECD); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3692 | eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); | 
|  | 3693 | data = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3695 | for (i = 0; i < count; i++) { | 
|  | 3696 | data = data << 1; | 
|  | 3697 | e1000_raise_ee_clk(hw, &eecd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3699 | eecd = er32(EECD); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3700 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3701 | eecd &= ~(E1000_EECD_DI); | 
|  | 3702 | if (eecd & E1000_EECD_DO) | 
|  | 3703 | data |= 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3704 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3705 | e1000_lower_ee_clk(hw, &eecd); | 
|  | 3706 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3708 | return data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | } | 
|  | 3710 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3711 | /** | 
|  | 3712 | * e1000_acquire_eeprom - Prepares EEPROM for access | 
|  | 3713 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | * | 
|  | 3715 | * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This | 
|  | 3716 | * function should be called before issuing a command to the EEPROM. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3717 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3718 | static s32 e1000_acquire_eeprom(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3719 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3720 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 3721 | u32 eecd, i = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3722 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3723 | e_dbg("e1000_acquire_eeprom"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3724 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3725 | eecd = er32(EECD); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3726 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3727 | /* Request EEPROM Access */ | 
|  | 3728 | if (hw->mac_type > e1000_82544) { | 
|  | 3729 | eecd |= E1000_EECD_REQ; | 
|  | 3730 | ew32(EECD, eecd); | 
|  | 3731 | eecd = er32(EECD); | 
|  | 3732 | while ((!(eecd & E1000_EECD_GNT)) && | 
|  | 3733 | (i < E1000_EEPROM_GRANT_ATTEMPTS)) { | 
|  | 3734 | i++; | 
|  | 3735 | udelay(5); | 
|  | 3736 | eecd = er32(EECD); | 
|  | 3737 | } | 
|  | 3738 | if (!(eecd & E1000_EECD_GNT)) { | 
|  | 3739 | eecd &= ~E1000_EECD_REQ; | 
|  | 3740 | ew32(EECD, eecd); | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3741 | e_dbg("Could not acquire EEPROM grant\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3742 | return -E1000_ERR_EEPROM; | 
|  | 3743 | } | 
|  | 3744 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3746 | /* Setup EEPROM for Read/Write */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3748 | if (eeprom->type == e1000_eeprom_microwire) { | 
|  | 3749 | /* Clear SK and DI */ | 
|  | 3750 | eecd &= ~(E1000_EECD_DI | E1000_EECD_SK); | 
|  | 3751 | ew32(EECD, eecd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3753 | /* Set CS */ | 
|  | 3754 | eecd |= E1000_EECD_CS; | 
|  | 3755 | ew32(EECD, eecd); | 
|  | 3756 | } else if (eeprom->type == e1000_eeprom_spi) { | 
|  | 3757 | /* Clear SK and CS */ | 
|  | 3758 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); | 
|  | 3759 | ew32(EECD, eecd); | 
|  | 3760 | udelay(1); | 
|  | 3761 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3762 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3763 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | } | 
|  | 3765 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3766 | /** | 
|  | 3767 | * e1000_standby_eeprom - Returns EEPROM to a "standby" state | 
|  | 3768 | * @hw: Struct containing variables accessed by shared code | 
|  | 3769 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3770 | static void e1000_standby_eeprom(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3772 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 3773 | u32 eecd; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3775 | eecd = er32(EECD); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3777 | if (eeprom->type == e1000_eeprom_microwire) { | 
|  | 3778 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); | 
|  | 3779 | ew32(EECD, eecd); | 
|  | 3780 | E1000_WRITE_FLUSH(); | 
|  | 3781 | udelay(eeprom->delay_usec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3783 | /* Clock high */ | 
|  | 3784 | eecd |= E1000_EECD_SK; | 
|  | 3785 | ew32(EECD, eecd); | 
|  | 3786 | E1000_WRITE_FLUSH(); | 
|  | 3787 | udelay(eeprom->delay_usec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3789 | /* Select EEPROM */ | 
|  | 3790 | eecd |= E1000_EECD_CS; | 
|  | 3791 | ew32(EECD, eecd); | 
|  | 3792 | E1000_WRITE_FLUSH(); | 
|  | 3793 | udelay(eeprom->delay_usec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3795 | /* Clock low */ | 
|  | 3796 | eecd &= ~E1000_EECD_SK; | 
|  | 3797 | ew32(EECD, eecd); | 
|  | 3798 | E1000_WRITE_FLUSH(); | 
|  | 3799 | udelay(eeprom->delay_usec); | 
|  | 3800 | } else if (eeprom->type == e1000_eeprom_spi) { | 
|  | 3801 | /* Toggle CS to flush commands */ | 
|  | 3802 | eecd |= E1000_EECD_CS; | 
|  | 3803 | ew32(EECD, eecd); | 
|  | 3804 | E1000_WRITE_FLUSH(); | 
|  | 3805 | udelay(eeprom->delay_usec); | 
|  | 3806 | eecd &= ~E1000_EECD_CS; | 
|  | 3807 | ew32(EECD, eecd); | 
|  | 3808 | E1000_WRITE_FLUSH(); | 
|  | 3809 | udelay(eeprom->delay_usec); | 
|  | 3810 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | } | 
|  | 3812 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3813 | /** | 
|  | 3814 | * e1000_release_eeprom - drop chip select | 
|  | 3815 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3816 | * | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3817 | * Terminates a command by inverting the EEPROM's chip select pin | 
|  | 3818 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3819 | static void e1000_release_eeprom(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3821 | u32 eecd; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3823 | e_dbg("e1000_release_eeprom"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3825 | eecd = er32(EECD); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3826 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3827 | if (hw->eeprom.type == e1000_eeprom_spi) { | 
|  | 3828 | eecd |= E1000_EECD_CS;	/* Pull CS high */ | 
|  | 3829 | eecd &= ~E1000_EECD_SK;	/* Lower SCK */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3831 | ew32(EECD, eecd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3833 | udelay(hw->eeprom.delay_usec); | 
|  | 3834 | } else if (hw->eeprom.type == e1000_eeprom_microwire) { | 
|  | 3835 | /* cleanup eeprom */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3837 | /* CS on Microwire is active-high */ | 
|  | 3838 | eecd &= ~(E1000_EECD_CS | E1000_EECD_DI); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3840 | ew32(EECD, eecd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3842 | /* Rising edge of clock */ | 
|  | 3843 | eecd |= E1000_EECD_SK; | 
|  | 3844 | ew32(EECD, eecd); | 
|  | 3845 | E1000_WRITE_FLUSH(); | 
|  | 3846 | udelay(hw->eeprom.delay_usec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3847 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3848 | /* Falling edge of clock */ | 
|  | 3849 | eecd &= ~E1000_EECD_SK; | 
|  | 3850 | ew32(EECD, eecd); | 
|  | 3851 | E1000_WRITE_FLUSH(); | 
|  | 3852 | udelay(hw->eeprom.delay_usec); | 
|  | 3853 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3854 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3855 | /* Stop requesting EEPROM access */ | 
|  | 3856 | if (hw->mac_type > e1000_82544) { | 
|  | 3857 | eecd &= ~E1000_EECD_REQ; | 
|  | 3858 | ew32(EECD, eecd); | 
|  | 3859 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3860 | } | 
|  | 3861 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3862 | /** | 
|  | 3863 | * e1000_spi_eeprom_ready - Reads a 16 bit word from the EEPROM. | 
|  | 3864 | * @hw: Struct containing variables accessed by shared code | 
|  | 3865 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3866 | static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3867 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3868 | u16 retry_count = 0; | 
|  | 3869 | u8 spi_stat_reg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3871 | e_dbg("e1000_spi_eeprom_ready"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3873 | /* Read "Status Register" repeatedly until the LSB is cleared.  The | 
|  | 3874 | * EEPROM will signal that the command has been completed by clearing | 
|  | 3875 | * bit 0 of the internal status register.  If it's not cleared within | 
|  | 3876 | * 5 milliseconds, then error out. | 
|  | 3877 | */ | 
|  | 3878 | retry_count = 0; | 
|  | 3879 | do { | 
|  | 3880 | e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI, | 
|  | 3881 | hw->eeprom.opcode_bits); | 
|  | 3882 | spi_stat_reg = (u8) e1000_shift_in_ee_bits(hw, 8); | 
|  | 3883 | if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI)) | 
|  | 3884 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3885 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3886 | udelay(5); | 
|  | 3887 | retry_count += 5; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3889 | e1000_standby_eeprom(hw); | 
|  | 3890 | } while (retry_count < EEPROM_MAX_RETRY_SPI); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3892 | /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and | 
|  | 3893 | * only 0-5mSec on 5V devices) | 
|  | 3894 | */ | 
|  | 3895 | if (retry_count >= EEPROM_MAX_RETRY_SPI) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3896 | e_dbg("SPI EEPROM Status error\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3897 | return -E1000_ERR_EEPROM; | 
|  | 3898 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3900 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | } | 
|  | 3902 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3903 | /** | 
|  | 3904 | * e1000_read_eeprom - Reads a 16 bit word from the EEPROM. | 
|  | 3905 | * @hw: Struct containing variables accessed by shared code | 
|  | 3906 | * @offset: offset of  word in the EEPROM to read | 
|  | 3907 | * @data: word read from the EEPROM | 
|  | 3908 | * @words: number of words to read | 
|  | 3909 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3910 | s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3911 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3912 | s32 ret; | 
|  | 3913 | spin_lock(&e1000_eeprom_lock); | 
|  | 3914 | ret = e1000_do_read_eeprom(hw, offset, words, data); | 
|  | 3915 | spin_unlock(&e1000_eeprom_lock); | 
|  | 3916 | return ret; | 
| Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 3917 | } | 
|  | 3918 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3919 | static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, | 
|  | 3920 | u16 *data) | 
| Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 3921 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3922 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 3923 | u32 i = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3925 | e_dbg("e1000_read_eeprom"); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3926 |  | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3927 | if (hw->mac_type == e1000_ce4100) { | 
|  | 3928 | GBE_CONFIG_FLASH_READ(GBE_CONFIG_BASE_VIRT, offset, words, | 
|  | 3929 | data); | 
|  | 3930 | return E1000_SUCCESS; | 
|  | 3931 | } | 
|  | 3932 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3933 | /* If eeprom is not yet detected, do so now */ | 
|  | 3934 | if (eeprom->word_size == 0) | 
|  | 3935 | e1000_init_eeprom_params(hw); | 
| Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3936 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3937 | /* A check for invalid values:  offset too large, too many words, and not | 
|  | 3938 | * enough words. | 
|  | 3939 | */ | 
|  | 3940 | if ((offset >= eeprom->word_size) | 
|  | 3941 | || (words > eeprom->word_size - offset) || (words == 0)) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3942 | e_dbg("\"words\" parameter out of bounds. Words = %d," | 
|  | 3943 | "size = %d\n", offset, eeprom->word_size); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3944 | return -E1000_ERR_EEPROM; | 
|  | 3945 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3946 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3947 | /* EEPROM's that don't use EERD to read require us to bit-bang the SPI | 
|  | 3948 | * directly. In this case, we need to acquire the EEPROM so that | 
|  | 3949 | * FW or other port software does not interrupt. | 
|  | 3950 | */ | 
| Jesse Brandeburg | 8f601b2 | 2009-09-25 12:20:11 +0000 | [diff] [blame] | 3951 | /* Prepare the EEPROM for bit-bang reading */ | 
|  | 3952 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) | 
|  | 3953 | return -E1000_ERR_EEPROM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3955 | /* Set up the SPI or Microwire EEPROM for bit-bang reading.  We have | 
|  | 3956 | * acquired the EEPROM at this point, so any returns should release it */ | 
|  | 3957 | if (eeprom->type == e1000_eeprom_spi) { | 
|  | 3958 | u16 word_in; | 
|  | 3959 | u8 read_opcode = EEPROM_READ_OPCODE_SPI; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3961 | if (e1000_spi_eeprom_ready(hw)) { | 
|  | 3962 | e1000_release_eeprom(hw); | 
|  | 3963 | return -E1000_ERR_EEPROM; | 
|  | 3964 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3965 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3966 | e1000_standby_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3968 | /* Some SPI eeproms use the 8th address bit embedded in the opcode */ | 
|  | 3969 | if ((eeprom->address_bits == 8) && (offset >= 128)) | 
|  | 3970 | read_opcode |= EEPROM_A8_OPCODE_SPI; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3971 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3972 | /* Send the READ command (opcode + addr)  */ | 
|  | 3973 | e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits); | 
|  | 3974 | e1000_shift_out_ee_bits(hw, (u16) (offset * 2), | 
|  | 3975 | eeprom->address_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3976 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3977 | /* Read the data.  The address of the eeprom internally increments with | 
|  | 3978 | * each byte (spi) being read, saving on the overhead of eeprom setup | 
|  | 3979 | * and tear-down.  The address counter will roll over if reading beyond | 
|  | 3980 | * the size of the eeprom, thus allowing the entire memory to be read | 
|  | 3981 | * starting from any offset. */ | 
|  | 3982 | for (i = 0; i < words; i++) { | 
|  | 3983 | word_in = e1000_shift_in_ee_bits(hw, 16); | 
|  | 3984 | data[i] = (word_in >> 8) | (word_in << 8); | 
|  | 3985 | } | 
|  | 3986 | } else if (eeprom->type == e1000_eeprom_microwire) { | 
|  | 3987 | for (i = 0; i < words; i++) { | 
|  | 3988 | /* Send the READ command (opcode + addr)  */ | 
|  | 3989 | e1000_shift_out_ee_bits(hw, | 
|  | 3990 | EEPROM_READ_OPCODE_MICROWIRE, | 
|  | 3991 | eeprom->opcode_bits); | 
|  | 3992 | e1000_shift_out_ee_bits(hw, (u16) (offset + i), | 
|  | 3993 | eeprom->address_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3994 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3995 | /* Read the data.  For microwire, each word requires the overhead | 
|  | 3996 | * of eeprom setup and tear-down. */ | 
|  | 3997 | data[i] = e1000_shift_in_ee_bits(hw, 16); | 
|  | 3998 | e1000_standby_eeprom(hw); | 
|  | 3999 | } | 
|  | 4000 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4002 | /* End this read operation */ | 
|  | 4003 | e1000_release_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4005 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | } | 
|  | 4007 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4008 | /** | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4009 | * e1000_validate_eeprom_checksum - Verifies that the EEPROM has a valid checksum | 
|  | 4010 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4011 | * | 
|  | 4012 | * Reads the first 64 16 bit words of the EEPROM and sums the values read. | 
|  | 4013 | * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is | 
|  | 4014 | * valid. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4015 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4016 | s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4018 | u16 checksum = 0; | 
|  | 4019 | u16 i, eeprom_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4020 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4021 | e_dbg("e1000_validate_eeprom_checksum"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4023 | for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) { | 
|  | 4024 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4025 | e_dbg("EEPROM Read Error\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4026 | return -E1000_ERR_EEPROM; | 
|  | 4027 | } | 
|  | 4028 | checksum += eeprom_data; | 
|  | 4029 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4031 | if (checksum == (u16) EEPROM_SUM) | 
|  | 4032 | return E1000_SUCCESS; | 
|  | 4033 | else { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4034 | e_dbg("EEPROM Checksum Invalid\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4035 | return -E1000_ERR_EEPROM; | 
|  | 4036 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | } | 
|  | 4038 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4039 | /** | 
|  | 4040 | * e1000_update_eeprom_checksum - Calculates/writes the EEPROM checksum | 
|  | 4041 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | * | 
|  | 4043 | * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA. | 
|  | 4044 | * Writes the difference to word offset 63 of the EEPROM. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4045 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4046 | s32 e1000_update_eeprom_checksum(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4048 | u16 checksum = 0; | 
|  | 4049 | u16 i, eeprom_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4051 | e_dbg("e1000_update_eeprom_checksum"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4053 | for (i = 0; i < EEPROM_CHECKSUM_REG; i++) { | 
|  | 4054 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4055 | e_dbg("EEPROM Read Error\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4056 | return -E1000_ERR_EEPROM; | 
|  | 4057 | } | 
|  | 4058 | checksum += eeprom_data; | 
|  | 4059 | } | 
|  | 4060 | checksum = (u16) EEPROM_SUM - checksum; | 
|  | 4061 | if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4062 | e_dbg("EEPROM Write Error\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4063 | return -E1000_ERR_EEPROM; | 
|  | 4064 | } | 
|  | 4065 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | } | 
|  | 4067 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4068 | /** | 
|  | 4069 | * e1000_write_eeprom - write words to the different EEPROM types. | 
|  | 4070 | * @hw: Struct containing variables accessed by shared code | 
|  | 4071 | * @offset: offset within the EEPROM to be written to | 
|  | 4072 | * @words: number of words to write | 
|  | 4073 | * @data: 16 bit word to be written to the EEPROM | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | * | 
|  | 4075 | * If e1000_update_eeprom_checksum is not called after this function, the | 
|  | 4076 | * EEPROM will most likely contain an invalid checksum. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4077 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4078 | s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4080 | s32 ret; | 
|  | 4081 | spin_lock(&e1000_eeprom_lock); | 
|  | 4082 | ret = e1000_do_write_eeprom(hw, offset, words, data); | 
|  | 4083 | spin_unlock(&e1000_eeprom_lock); | 
|  | 4084 | return ret; | 
| Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 4085 | } | 
|  | 4086 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4087 | static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, | 
|  | 4088 | u16 *data) | 
| Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 4089 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4090 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 4091 | s32 status = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4092 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4093 | e_dbg("e1000_write_eeprom"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 |  | 
| Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 4095 | if (hw->mac_type == e1000_ce4100) { | 
|  | 4096 | GBE_CONFIG_FLASH_WRITE(GBE_CONFIG_BASE_VIRT, offset, words, | 
|  | 4097 | data); | 
|  | 4098 | return E1000_SUCCESS; | 
|  | 4099 | } | 
|  | 4100 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4101 | /* If eeprom is not yet detected, do so now */ | 
|  | 4102 | if (eeprom->word_size == 0) | 
|  | 4103 | e1000_init_eeprom_params(hw); | 
| Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4104 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4105 | /* A check for invalid values:  offset too large, too many words, and not | 
|  | 4106 | * enough words. | 
|  | 4107 | */ | 
|  | 4108 | if ((offset >= eeprom->word_size) | 
|  | 4109 | || (words > eeprom->word_size - offset) || (words == 0)) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4110 | e_dbg("\"words\" parameter out of bounds\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4111 | return -E1000_ERR_EEPROM; | 
|  | 4112 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4113 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4114 | /* Prepare the EEPROM for writing  */ | 
|  | 4115 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) | 
|  | 4116 | return -E1000_ERR_EEPROM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4118 | if (eeprom->type == e1000_eeprom_microwire) { | 
|  | 4119 | status = e1000_write_eeprom_microwire(hw, offset, words, data); | 
|  | 4120 | } else { | 
|  | 4121 | status = e1000_write_eeprom_spi(hw, offset, words, data); | 
|  | 4122 | msleep(10); | 
|  | 4123 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4125 | /* Done with writing */ | 
|  | 4126 | e1000_release_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4127 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4128 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4129 | } | 
|  | 4130 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4131 | /** | 
|  | 4132 | * e1000_write_eeprom_spi - Writes a 16 bit word to a given offset in an SPI EEPROM. | 
|  | 4133 | * @hw: Struct containing variables accessed by shared code | 
|  | 4134 | * @offset: offset within the EEPROM to be written to | 
|  | 4135 | * @words: number of words to write | 
|  | 4136 | * @data: pointer to array of 8 bit words to be written to the EEPROM | 
|  | 4137 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4138 | static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words, | 
|  | 4139 | u16 *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4140 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4141 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 4142 | u16 widx = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4143 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4144 | e_dbg("e1000_write_eeprom_spi"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4145 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4146 | while (widx < words) { | 
|  | 4147 | u8 write_opcode = EEPROM_WRITE_OPCODE_SPI; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4149 | if (e1000_spi_eeprom_ready(hw)) | 
|  | 4150 | return -E1000_ERR_EEPROM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4152 | e1000_standby_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4154 | /*  Send the WRITE ENABLE command (8 bit opcode )  */ | 
|  | 4155 | e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI, | 
|  | 4156 | eeprom->opcode_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4158 | e1000_standby_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4160 | /* Some SPI eeproms use the 8th address bit embedded in the opcode */ | 
|  | 4161 | if ((eeprom->address_bits == 8) && (offset >= 128)) | 
|  | 4162 | write_opcode |= EEPROM_A8_OPCODE_SPI; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4164 | /* Send the Write command (8-bit opcode + addr) */ | 
|  | 4165 | e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4167 | e1000_shift_out_ee_bits(hw, (u16) ((offset + widx) * 2), | 
|  | 4168 | eeprom->address_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4170 | /* Send the data */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4171 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4172 | /* Loop to allow for up to whole page write (32 bytes) of eeprom */ | 
|  | 4173 | while (widx < words) { | 
|  | 4174 | u16 word_out = data[widx]; | 
|  | 4175 | word_out = (word_out >> 8) | (word_out << 8); | 
|  | 4176 | e1000_shift_out_ee_bits(hw, word_out, 16); | 
|  | 4177 | widx++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4179 | /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE | 
|  | 4180 | * operation, while the smaller eeproms are capable of an 8-byte | 
|  | 4181 | * PAGE WRITE operation.  Break the inner loop to pass new address | 
|  | 4182 | */ | 
|  | 4183 | if ((((offset + widx) * 2) % eeprom->page_size) == 0) { | 
|  | 4184 | e1000_standby_eeprom(hw); | 
|  | 4185 | break; | 
|  | 4186 | } | 
|  | 4187 | } | 
|  | 4188 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4190 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | } | 
|  | 4192 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4193 | /** | 
|  | 4194 | * e1000_write_eeprom_microwire - Writes a 16 bit word to a given offset in a Microwire EEPROM. | 
|  | 4195 | * @hw: Struct containing variables accessed by shared code | 
|  | 4196 | * @offset: offset within the EEPROM to be written to | 
|  | 4197 | * @words: number of words to write | 
|  | 4198 | * @data: pointer to array of 8 bit words to be written to the EEPROM | 
|  | 4199 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4200 | static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset, | 
|  | 4201 | u16 words, u16 *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4203 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 4204 | u32 eecd; | 
|  | 4205 | u16 words_written = 0; | 
|  | 4206 | u16 i = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4208 | e_dbg("e1000_write_eeprom_microwire"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4209 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4210 | /* Send the write enable command to the EEPROM (3-bit opcode plus | 
|  | 4211 | * 6/8-bit dummy address beginning with 11).  It's less work to include | 
|  | 4212 | * the 11 of the dummy address as part of the opcode than it is to shift | 
|  | 4213 | * it over the correct number of bits for the address.  This puts the | 
|  | 4214 | * EEPROM into write/erase mode. | 
|  | 4215 | */ | 
|  | 4216 | e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE, | 
|  | 4217 | (u16) (eeprom->opcode_bits + 2)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4219 | e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4221 | /* Prepare the EEPROM */ | 
|  | 4222 | e1000_standby_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4224 | while (words_written < words) { | 
|  | 4225 | /* Send the Write command (3-bit opcode + addr) */ | 
|  | 4226 | e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE, | 
|  | 4227 | eeprom->opcode_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4229 | e1000_shift_out_ee_bits(hw, (u16) (offset + words_written), | 
|  | 4230 | eeprom->address_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4231 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4232 | /* Send the data */ | 
|  | 4233 | e1000_shift_out_ee_bits(hw, data[words_written], 16); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4234 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4235 | /* Toggle the CS line.  This in effect tells the EEPROM to execute | 
|  | 4236 | * the previous command. | 
|  | 4237 | */ | 
|  | 4238 | e1000_standby_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4239 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4240 | /* Read DO repeatedly until it is high (equal to '1').  The EEPROM will | 
|  | 4241 | * signal that the command has been completed by raising the DO signal. | 
|  | 4242 | * If DO does not go high in 10 milliseconds, then error out. | 
|  | 4243 | */ | 
|  | 4244 | for (i = 0; i < 200; i++) { | 
|  | 4245 | eecd = er32(EECD); | 
|  | 4246 | if (eecd & E1000_EECD_DO) | 
|  | 4247 | break; | 
|  | 4248 | udelay(50); | 
|  | 4249 | } | 
|  | 4250 | if (i == 200) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4251 | e_dbg("EEPROM Write did not complete\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4252 | return -E1000_ERR_EEPROM; | 
|  | 4253 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4255 | /* Recover from write */ | 
|  | 4256 | e1000_standby_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4257 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4258 | words_written++; | 
|  | 4259 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4261 | /* Send the write disable command to the EEPROM (3-bit opcode plus | 
|  | 4262 | * 6/8-bit dummy address beginning with 10).  It's less work to include | 
|  | 4263 | * the 10 of the dummy address as part of the opcode than it is to shift | 
|  | 4264 | * it over the correct number of bits for the address.  This takes the | 
|  | 4265 | * EEPROM out of write/erase mode. | 
|  | 4266 | */ | 
|  | 4267 | e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE, | 
|  | 4268 | (u16) (eeprom->opcode_bits + 2)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4270 | e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4272 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4273 | } | 
|  | 4274 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4275 | /** | 
|  | 4276 | * e1000_read_mac_addr - read the adapters MAC from eeprom | 
|  | 4277 | * @hw: Struct containing variables accessed by shared code | 
|  | 4278 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the | 
|  | 4280 | * second function of dual function devices | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4281 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4282 | s32 e1000_read_mac_addr(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4284 | u16 offset; | 
|  | 4285 | u16 eeprom_data, i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4287 | e_dbg("e1000_read_mac_addr"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4288 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4289 | for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) { | 
|  | 4290 | offset = i >> 1; | 
|  | 4291 | if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4292 | e_dbg("EEPROM Read Error\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4293 | return -E1000_ERR_EEPROM; | 
|  | 4294 | } | 
|  | 4295 | hw->perm_mac_addr[i] = (u8) (eeprom_data & 0x00FF); | 
|  | 4296 | hw->perm_mac_addr[i + 1] = (u8) (eeprom_data >> 8); | 
|  | 4297 | } | 
| Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4298 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4299 | switch (hw->mac_type) { | 
|  | 4300 | default: | 
|  | 4301 | break; | 
|  | 4302 | case e1000_82546: | 
|  | 4303 | case e1000_82546_rev_3: | 
|  | 4304 | if (er32(STATUS) & E1000_STATUS_FUNC_1) | 
|  | 4305 | hw->perm_mac_addr[5] ^= 0x01; | 
|  | 4306 | break; | 
|  | 4307 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4309 | for (i = 0; i < NODE_ADDRESS_SIZE; i++) | 
|  | 4310 | hw->mac_addr[i] = hw->perm_mac_addr[i]; | 
|  | 4311 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | } | 
|  | 4313 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4314 | /** | 
|  | 4315 | * e1000_init_rx_addrs - Initializes receive address filters. | 
|  | 4316 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4317 | * | 
|  | 4318 | * Places the MAC address in receive address register 0 and clears the rest | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4319 | * of the receive address registers. Clears the multicast table. Assumes | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4320 | * the receiver is in reset when the routine is called. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4321 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4322 | static void e1000_init_rx_addrs(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4324 | u32 i; | 
|  | 4325 | u32 rar_num; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4327 | e_dbg("e1000_init_rx_addrs"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4329 | /* Setup the receive address. */ | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4330 | e_dbg("Programming MAC Address into RAR[0]\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4331 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4332 | e1000_rar_set(hw, hw->mac_addr, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4334 | rar_num = E1000_RAR_ENTRIES; | 
| Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4335 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4336 | /* Zero out the other 15 receive addresses. */ | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4337 | e_dbg("Clearing RAR[1-15]\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4338 | for (i = 1; i < rar_num; i++) { | 
|  | 4339 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0); | 
|  | 4340 | E1000_WRITE_FLUSH(); | 
|  | 4341 | E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0); | 
|  | 4342 | E1000_WRITE_FLUSH(); | 
|  | 4343 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4344 | } | 
|  | 4345 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4346 | /** | 
|  | 4347 | * e1000_hash_mc_addr - Hashes an address to determine its location in the multicast table | 
|  | 4348 | * @hw: Struct containing variables accessed by shared code | 
|  | 4349 | * @mc_addr: the multicast address to hash | 
|  | 4350 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4351 | u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4352 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4353 | u32 hash_value = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4354 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4355 | /* The portion of the address that is used for the hash table is | 
|  | 4356 | * determined by the mc_filter_type setting. | 
|  | 4357 | */ | 
|  | 4358 | switch (hw->mc_filter_type) { | 
|  | 4359 | /* [0] [1] [2] [3] [4] [5] | 
|  | 4360 | * 01  AA  00  12  34  56 | 
|  | 4361 | * LSB                 MSB | 
|  | 4362 | */ | 
|  | 4363 | case 0: | 
|  | 4364 | /* [47:36] i.e. 0x563 for above example address */ | 
|  | 4365 | hash_value = ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4)); | 
|  | 4366 | break; | 
|  | 4367 | case 1: | 
|  | 4368 | /* [46:35] i.e. 0xAC6 for above example address */ | 
|  | 4369 | hash_value = ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5)); | 
|  | 4370 | break; | 
|  | 4371 | case 2: | 
|  | 4372 | /* [45:34] i.e. 0x5D8 for above example address */ | 
|  | 4373 | hash_value = ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6)); | 
|  | 4374 | break; | 
|  | 4375 | case 3: | 
|  | 4376 | /* [43:32] i.e. 0x634 for above example address */ | 
|  | 4377 | hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8)); | 
|  | 4378 | break; | 
|  | 4379 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4380 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4381 | hash_value &= 0xFFF; | 
|  | 4382 | return hash_value; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4383 | } | 
|  | 4384 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4385 | /** | 
|  | 4386 | * e1000_rar_set - Puts an ethernet address into a receive address register. | 
|  | 4387 | * @hw: Struct containing variables accessed by shared code | 
|  | 4388 | * @addr: Address to put into receive address register | 
|  | 4389 | * @index: Receive address register to write | 
|  | 4390 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4391 | void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4392 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4393 | u32 rar_low, rar_high; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4394 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4395 | /* HW expects these in little endian so we reverse the byte order | 
|  | 4396 | * from network order (big endian) to little endian | 
|  | 4397 | */ | 
|  | 4398 | rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) | | 
|  | 4399 | ((u32) addr[2] << 16) | ((u32) addr[3] << 24)); | 
|  | 4400 | rar_high = ((u32) addr[4] | ((u32) addr[5] << 8)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4402 | /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx | 
|  | 4403 | * unit hang. | 
|  | 4404 | * | 
|  | 4405 | * Description: | 
|  | 4406 | * If there are any Rx frames queued up or otherwise present in the HW | 
|  | 4407 | * before RSS is enabled, and then we enable RSS, the HW Rx unit will | 
|  | 4408 | * hang.  To work around this issue, we have to disable receives and | 
|  | 4409 | * flush out all Rx frames before we enable RSS. To do so, we modify we | 
|  | 4410 | * redirect all Rx traffic to manageability and then reset the HW. | 
|  | 4411 | * This flushes away Rx frames, and (since the redirections to | 
|  | 4412 | * manageability persists across resets) keeps new ones from coming in | 
|  | 4413 | * while we work.  Then, we clear the Address Valid AV bit for all MAC | 
|  | 4414 | * addresses and undo the re-direction to manageability. | 
|  | 4415 | * Now, frames are coming in again, but the MAC won't accept them, so | 
|  | 4416 | * far so good.  We now proceed to initialize RSS (if necessary) and | 
|  | 4417 | * configure the Rx unit.  Last, we re-enable the AV bits and continue | 
|  | 4418 | * on our merry way. | 
|  | 4419 | */ | 
|  | 4420 | switch (hw->mac_type) { | 
|  | 4421 | default: | 
|  | 4422 | /* Indicate to hardware the Address is Valid. */ | 
|  | 4423 | rar_high |= E1000_RAH_AV; | 
|  | 4424 | break; | 
|  | 4425 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4427 | E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low); | 
|  | 4428 | E1000_WRITE_FLUSH(); | 
|  | 4429 | E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high); | 
|  | 4430 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4431 | } | 
|  | 4432 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4433 | /** | 
|  | 4434 | * e1000_write_vfta - Writes a value to the specified offset in the VLAN filter table. | 
|  | 4435 | * @hw: Struct containing variables accessed by shared code | 
|  | 4436 | * @offset: Offset in VLAN filer table to write | 
|  | 4437 | * @value: Value to write into VLAN filter table | 
|  | 4438 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4439 | void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4440 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4441 | u32 temp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4442 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4443 | if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) { | 
|  | 4444 | temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1)); | 
|  | 4445 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); | 
|  | 4446 | E1000_WRITE_FLUSH(); | 
|  | 4447 | E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp); | 
|  | 4448 | E1000_WRITE_FLUSH(); | 
|  | 4449 | } else { | 
|  | 4450 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); | 
|  | 4451 | E1000_WRITE_FLUSH(); | 
|  | 4452 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | } | 
|  | 4454 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4455 | /** | 
|  | 4456 | * e1000_clear_vfta - Clears the VLAN filer table | 
|  | 4457 | * @hw: Struct containing variables accessed by shared code | 
|  | 4458 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4459 | static void e1000_clear_vfta(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4460 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4461 | u32 offset; | 
|  | 4462 | u32 vfta_value = 0; | 
|  | 4463 | u32 vfta_offset = 0; | 
|  | 4464 | u32 vfta_bit_in_reg = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4466 | for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) { | 
|  | 4467 | /* If the offset we want to clear is the same offset of the | 
|  | 4468 | * manageability VLAN ID, then clear all bits except that of the | 
|  | 4469 | * manageability unit */ | 
|  | 4470 | vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0; | 
|  | 4471 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value); | 
|  | 4472 | E1000_WRITE_FLUSH(); | 
|  | 4473 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | } | 
|  | 4475 |  | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4476 | static s32 e1000_id_led_init(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4478 | u32 ledctl; | 
|  | 4479 | const u32 ledctl_mask = 0x000000FF; | 
|  | 4480 | const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON; | 
|  | 4481 | const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF; | 
|  | 4482 | u16 eeprom_data, i, temp; | 
|  | 4483 | const u16 led_mask = 0x0F; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4484 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4485 | e_dbg("e1000_id_led_init"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4486 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4487 | if (hw->mac_type < e1000_82540) { | 
|  | 4488 | /* Nothing to do */ | 
|  | 4489 | return E1000_SUCCESS; | 
|  | 4490 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4491 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4492 | ledctl = er32(LEDCTL); | 
|  | 4493 | hw->ledctl_default = ledctl; | 
|  | 4494 | hw->ledctl_mode1 = hw->ledctl_default; | 
|  | 4495 | hw->ledctl_mode2 = hw->ledctl_default; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4497 | if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4498 | e_dbg("EEPROM Read Error\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4499 | return -E1000_ERR_EEPROM; | 
|  | 4500 | } | 
| Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4501 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4502 | if ((eeprom_data == ID_LED_RESERVED_0000) || | 
|  | 4503 | (eeprom_data == ID_LED_RESERVED_FFFF)) { | 
|  | 4504 | eeprom_data = ID_LED_DEFAULT; | 
|  | 4505 | } | 
| Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4506 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4507 | for (i = 0; i < 4; i++) { | 
|  | 4508 | temp = (eeprom_data >> (i << 2)) & led_mask; | 
|  | 4509 | switch (temp) { | 
|  | 4510 | case ID_LED_ON1_DEF2: | 
|  | 4511 | case ID_LED_ON1_ON2: | 
|  | 4512 | case ID_LED_ON1_OFF2: | 
|  | 4513 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); | 
|  | 4514 | hw->ledctl_mode1 |= ledctl_on << (i << 3); | 
|  | 4515 | break; | 
|  | 4516 | case ID_LED_OFF1_DEF2: | 
|  | 4517 | case ID_LED_OFF1_ON2: | 
|  | 4518 | case ID_LED_OFF1_OFF2: | 
|  | 4519 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); | 
|  | 4520 | hw->ledctl_mode1 |= ledctl_off << (i << 3); | 
|  | 4521 | break; | 
|  | 4522 | default: | 
|  | 4523 | /* Do nothing */ | 
|  | 4524 | break; | 
|  | 4525 | } | 
|  | 4526 | switch (temp) { | 
|  | 4527 | case ID_LED_DEF1_ON2: | 
|  | 4528 | case ID_LED_ON1_ON2: | 
|  | 4529 | case ID_LED_OFF1_ON2: | 
|  | 4530 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); | 
|  | 4531 | hw->ledctl_mode2 |= ledctl_on << (i << 3); | 
|  | 4532 | break; | 
|  | 4533 | case ID_LED_DEF1_OFF2: | 
|  | 4534 | case ID_LED_ON1_OFF2: | 
|  | 4535 | case ID_LED_OFF1_OFF2: | 
|  | 4536 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); | 
|  | 4537 | hw->ledctl_mode2 |= ledctl_off << (i << 3); | 
|  | 4538 | break; | 
|  | 4539 | default: | 
|  | 4540 | /* Do nothing */ | 
|  | 4541 | break; | 
|  | 4542 | } | 
|  | 4543 | } | 
|  | 4544 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | } | 
|  | 4546 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4547 | /** | 
|  | 4548 | * e1000_setup_led | 
|  | 4549 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4550 | * | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4551 | * Prepares SW controlable LED for use and saves the current state of the LED. | 
|  | 4552 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4553 | s32 e1000_setup_led(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4555 | u32 ledctl; | 
|  | 4556 | s32 ret_val = E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4558 | e_dbg("e1000_setup_led"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4560 | switch (hw->mac_type) { | 
|  | 4561 | case e1000_82542_rev2_0: | 
|  | 4562 | case e1000_82542_rev2_1: | 
|  | 4563 | case e1000_82543: | 
|  | 4564 | case e1000_82544: | 
|  | 4565 | /* No setup necessary */ | 
|  | 4566 | break; | 
|  | 4567 | case e1000_82541: | 
|  | 4568 | case e1000_82547: | 
|  | 4569 | case e1000_82541_rev_2: | 
|  | 4570 | case e1000_82547_rev_2: | 
|  | 4571 | /* Turn off PHY Smart Power Down (if enabled) */ | 
|  | 4572 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, | 
|  | 4573 | &hw->phy_spd_default); | 
|  | 4574 | if (ret_val) | 
|  | 4575 | return ret_val; | 
|  | 4576 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, | 
|  | 4577 | (u16) (hw->phy_spd_default & | 
|  | 4578 | ~IGP01E1000_GMII_SPD)); | 
|  | 4579 | if (ret_val) | 
|  | 4580 | return ret_val; | 
|  | 4581 | /* Fall Through */ | 
|  | 4582 | default: | 
|  | 4583 | if (hw->media_type == e1000_media_type_fiber) { | 
|  | 4584 | ledctl = er32(LEDCTL); | 
|  | 4585 | /* Save current LEDCTL settings */ | 
|  | 4586 | hw->ledctl_default = ledctl; | 
|  | 4587 | /* Turn off LED0 */ | 
|  | 4588 | ledctl &= ~(E1000_LEDCTL_LED0_IVRT | | 
|  | 4589 | E1000_LEDCTL_LED0_BLINK | | 
|  | 4590 | E1000_LEDCTL_LED0_MODE_MASK); | 
|  | 4591 | ledctl |= (E1000_LEDCTL_MODE_LED_OFF << | 
|  | 4592 | E1000_LEDCTL_LED0_MODE_SHIFT); | 
|  | 4593 | ew32(LEDCTL, ledctl); | 
|  | 4594 | } else if (hw->media_type == e1000_media_type_copper) | 
|  | 4595 | ew32(LEDCTL, hw->ledctl_mode1); | 
|  | 4596 | break; | 
|  | 4597 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4598 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4599 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4600 | } | 
|  | 4601 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4602 | /** | 
|  | 4603 | * e1000_cleanup_led - Restores the saved state of the SW controlable LED. | 
|  | 4604 | * @hw: Struct containing variables accessed by shared code | 
|  | 4605 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4606 | s32 e1000_cleanup_led(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4607 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4608 | s32 ret_val = E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4609 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4610 | e_dbg("e1000_cleanup_led"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4612 | switch (hw->mac_type) { | 
|  | 4613 | case e1000_82542_rev2_0: | 
|  | 4614 | case e1000_82542_rev2_1: | 
|  | 4615 | case e1000_82543: | 
|  | 4616 | case e1000_82544: | 
|  | 4617 | /* No cleanup necessary */ | 
|  | 4618 | break; | 
|  | 4619 | case e1000_82541: | 
|  | 4620 | case e1000_82547: | 
|  | 4621 | case e1000_82541_rev_2: | 
|  | 4622 | case e1000_82547_rev_2: | 
|  | 4623 | /* Turn on PHY Smart Power Down (if previously enabled) */ | 
|  | 4624 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, | 
|  | 4625 | hw->phy_spd_default); | 
|  | 4626 | if (ret_val) | 
|  | 4627 | return ret_val; | 
|  | 4628 | /* Fall Through */ | 
|  | 4629 | default: | 
|  | 4630 | /* Restore LEDCTL settings */ | 
|  | 4631 | ew32(LEDCTL, hw->ledctl_default); | 
|  | 4632 | break; | 
|  | 4633 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4634 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4635 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4636 | } | 
|  | 4637 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4638 | /** | 
|  | 4639 | * e1000_led_on - Turns on the software controllable LED | 
|  | 4640 | * @hw: Struct containing variables accessed by shared code | 
|  | 4641 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4642 | s32 e1000_led_on(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4643 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4644 | u32 ctrl = er32(CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4645 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4646 | e_dbg("e1000_led_on"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4648 | switch (hw->mac_type) { | 
|  | 4649 | case e1000_82542_rev2_0: | 
|  | 4650 | case e1000_82542_rev2_1: | 
|  | 4651 | case e1000_82543: | 
|  | 4652 | /* Set SW Defineable Pin 0 to turn on the LED */ | 
|  | 4653 | ctrl |= E1000_CTRL_SWDPIN0; | 
|  | 4654 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4655 | break; | 
|  | 4656 | case e1000_82544: | 
|  | 4657 | if (hw->media_type == e1000_media_type_fiber) { | 
|  | 4658 | /* Set SW Defineable Pin 0 to turn on the LED */ | 
|  | 4659 | ctrl |= E1000_CTRL_SWDPIN0; | 
|  | 4660 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4661 | } else { | 
|  | 4662 | /* Clear SW Defineable Pin 0 to turn on the LED */ | 
|  | 4663 | ctrl &= ~E1000_CTRL_SWDPIN0; | 
|  | 4664 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4665 | } | 
|  | 4666 | break; | 
|  | 4667 | default: | 
|  | 4668 | if (hw->media_type == e1000_media_type_fiber) { | 
|  | 4669 | /* Clear SW Defineable Pin 0 to turn on the LED */ | 
|  | 4670 | ctrl &= ~E1000_CTRL_SWDPIN0; | 
|  | 4671 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4672 | } else if (hw->media_type == e1000_media_type_copper) { | 
|  | 4673 | ew32(LEDCTL, hw->ledctl_mode2); | 
|  | 4674 | return E1000_SUCCESS; | 
|  | 4675 | } | 
|  | 4676 | break; | 
|  | 4677 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4678 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4679 | ew32(CTRL, ctrl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4681 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4682 | } | 
|  | 4683 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4684 | /** | 
|  | 4685 | * e1000_led_off - Turns off the software controllable LED | 
|  | 4686 | * @hw: Struct containing variables accessed by shared code | 
|  | 4687 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4688 | s32 e1000_led_off(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4689 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4690 | u32 ctrl = er32(CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4691 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4692 | e_dbg("e1000_led_off"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4693 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4694 | switch (hw->mac_type) { | 
|  | 4695 | case e1000_82542_rev2_0: | 
|  | 4696 | case e1000_82542_rev2_1: | 
|  | 4697 | case e1000_82543: | 
|  | 4698 | /* Clear SW Defineable Pin 0 to turn off the LED */ | 
|  | 4699 | ctrl &= ~E1000_CTRL_SWDPIN0; | 
|  | 4700 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4701 | break; | 
|  | 4702 | case e1000_82544: | 
|  | 4703 | if (hw->media_type == e1000_media_type_fiber) { | 
|  | 4704 | /* Clear SW Defineable Pin 0 to turn off the LED */ | 
|  | 4705 | ctrl &= ~E1000_CTRL_SWDPIN0; | 
|  | 4706 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4707 | } else { | 
|  | 4708 | /* Set SW Defineable Pin 0 to turn off the LED */ | 
|  | 4709 | ctrl |= E1000_CTRL_SWDPIN0; | 
|  | 4710 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4711 | } | 
|  | 4712 | break; | 
|  | 4713 | default: | 
|  | 4714 | if (hw->media_type == e1000_media_type_fiber) { | 
|  | 4715 | /* Set SW Defineable Pin 0 to turn off the LED */ | 
|  | 4716 | ctrl |= E1000_CTRL_SWDPIN0; | 
|  | 4717 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4718 | } else if (hw->media_type == e1000_media_type_copper) { | 
|  | 4719 | ew32(LEDCTL, hw->ledctl_mode1); | 
|  | 4720 | return E1000_SUCCESS; | 
|  | 4721 | } | 
|  | 4722 | break; | 
|  | 4723 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4724 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4725 | ew32(CTRL, ctrl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4726 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4727 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4728 | } | 
|  | 4729 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4730 | /** | 
|  | 4731 | * e1000_clear_hw_cntrs - Clears all hardware statistics counters. | 
|  | 4732 | * @hw: Struct containing variables accessed by shared code | 
|  | 4733 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4734 | static void e1000_clear_hw_cntrs(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4735 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4736 | volatile u32 temp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4737 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4738 | temp = er32(CRCERRS); | 
|  | 4739 | temp = er32(SYMERRS); | 
|  | 4740 | temp = er32(MPC); | 
|  | 4741 | temp = er32(SCC); | 
|  | 4742 | temp = er32(ECOL); | 
|  | 4743 | temp = er32(MCC); | 
|  | 4744 | temp = er32(LATECOL); | 
|  | 4745 | temp = er32(COLC); | 
|  | 4746 | temp = er32(DC); | 
|  | 4747 | temp = er32(SEC); | 
|  | 4748 | temp = er32(RLEC); | 
|  | 4749 | temp = er32(XONRXC); | 
|  | 4750 | temp = er32(XONTXC); | 
|  | 4751 | temp = er32(XOFFRXC); | 
|  | 4752 | temp = er32(XOFFTXC); | 
|  | 4753 | temp = er32(FCRUC); | 
| Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4754 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4755 | temp = er32(PRC64); | 
|  | 4756 | temp = er32(PRC127); | 
|  | 4757 | temp = er32(PRC255); | 
|  | 4758 | temp = er32(PRC511); | 
|  | 4759 | temp = er32(PRC1023); | 
|  | 4760 | temp = er32(PRC1522); | 
| Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4761 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4762 | temp = er32(GPRC); | 
|  | 4763 | temp = er32(BPRC); | 
|  | 4764 | temp = er32(MPRC); | 
|  | 4765 | temp = er32(GPTC); | 
|  | 4766 | temp = er32(GORCL); | 
|  | 4767 | temp = er32(GORCH); | 
|  | 4768 | temp = er32(GOTCL); | 
|  | 4769 | temp = er32(GOTCH); | 
|  | 4770 | temp = er32(RNBC); | 
|  | 4771 | temp = er32(RUC); | 
|  | 4772 | temp = er32(RFC); | 
|  | 4773 | temp = er32(ROC); | 
|  | 4774 | temp = er32(RJC); | 
|  | 4775 | temp = er32(TORL); | 
|  | 4776 | temp = er32(TORH); | 
|  | 4777 | temp = er32(TOTL); | 
|  | 4778 | temp = er32(TOTH); | 
|  | 4779 | temp = er32(TPR); | 
|  | 4780 | temp = er32(TPT); | 
| Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4781 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4782 | temp = er32(PTC64); | 
|  | 4783 | temp = er32(PTC127); | 
|  | 4784 | temp = er32(PTC255); | 
|  | 4785 | temp = er32(PTC511); | 
|  | 4786 | temp = er32(PTC1023); | 
|  | 4787 | temp = er32(PTC1522); | 
| Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4788 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4789 | temp = er32(MPTC); | 
|  | 4790 | temp = er32(BPTC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4791 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4792 | if (hw->mac_type < e1000_82543) | 
|  | 4793 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4794 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4795 | temp = er32(ALGNERRC); | 
|  | 4796 | temp = er32(RXERRC); | 
|  | 4797 | temp = er32(TNCRS); | 
|  | 4798 | temp = er32(CEXTERR); | 
|  | 4799 | temp = er32(TSCTC); | 
|  | 4800 | temp = er32(TSCTFC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4801 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4802 | if (hw->mac_type <= e1000_82544) | 
|  | 4803 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4804 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4805 | temp = er32(MGTPRC); | 
|  | 4806 | temp = er32(MGTPDC); | 
|  | 4807 | temp = er32(MGTPTC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | } | 
|  | 4809 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4810 | /** | 
|  | 4811 | * e1000_reset_adaptive - Resets Adaptive IFS to its default state. | 
|  | 4812 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4813 | * | 
|  | 4814 | * Call this after e1000_init_hw. You may override the IFS defaults by setting | 
| Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4815 | * hw->ifs_params_forced to true. However, you must initialize hw-> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4816 | * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio | 
|  | 4817 | * before calling this function. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4818 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4819 | void e1000_reset_adaptive(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4820 | { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4821 | e_dbg("e1000_reset_adaptive"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4822 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4823 | if (hw->adaptive_ifs) { | 
|  | 4824 | if (!hw->ifs_params_forced) { | 
|  | 4825 | hw->current_ifs_val = 0; | 
|  | 4826 | hw->ifs_min_val = IFS_MIN; | 
|  | 4827 | hw->ifs_max_val = IFS_MAX; | 
|  | 4828 | hw->ifs_step_size = IFS_STEP; | 
|  | 4829 | hw->ifs_ratio = IFS_RATIO; | 
|  | 4830 | } | 
|  | 4831 | hw->in_ifs_mode = false; | 
|  | 4832 | ew32(AIT, 0); | 
|  | 4833 | } else { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4834 | e_dbg("Not in Adaptive IFS mode!\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4835 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | } | 
|  | 4837 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4838 | /** | 
|  | 4839 | * e1000_update_adaptive - update adaptive IFS | 
|  | 4840 | * @hw: Struct containing variables accessed by shared code | 
|  | 4841 | * @tx_packets: Number of transmits since last callback | 
|  | 4842 | * @total_collisions: Number of collisions since last callback | 
|  | 4843 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | * Called during the callback/watchdog routine to update IFS value based on | 
|  | 4845 | * the ratio of transmits to collisions. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4846 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4847 | void e1000_update_adaptive(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4848 | { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4849 | e_dbg("e1000_update_adaptive"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4851 | if (hw->adaptive_ifs) { | 
|  | 4852 | if ((hw->collision_delta *hw->ifs_ratio) > hw->tx_packet_delta) { | 
|  | 4853 | if (hw->tx_packet_delta > MIN_NUM_XMITS) { | 
|  | 4854 | hw->in_ifs_mode = true; | 
|  | 4855 | if (hw->current_ifs_val < hw->ifs_max_val) { | 
|  | 4856 | if (hw->current_ifs_val == 0) | 
|  | 4857 | hw->current_ifs_val = | 
|  | 4858 | hw->ifs_min_val; | 
|  | 4859 | else | 
|  | 4860 | hw->current_ifs_val += | 
|  | 4861 | hw->ifs_step_size; | 
|  | 4862 | ew32(AIT, hw->current_ifs_val); | 
|  | 4863 | } | 
|  | 4864 | } | 
|  | 4865 | } else { | 
|  | 4866 | if (hw->in_ifs_mode | 
|  | 4867 | && (hw->tx_packet_delta <= MIN_NUM_XMITS)) { | 
|  | 4868 | hw->current_ifs_val = 0; | 
|  | 4869 | hw->in_ifs_mode = false; | 
|  | 4870 | ew32(AIT, 0); | 
|  | 4871 | } | 
|  | 4872 | } | 
|  | 4873 | } else { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4874 | e_dbg("Not in Adaptive IFS mode!\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4875 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4876 | } | 
|  | 4877 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4878 | /** | 
|  | 4879 | * e1000_tbi_adjust_stats | 
|  | 4880 | * @hw: Struct containing variables accessed by shared code | 
|  | 4881 | * @frame_len: The length of the frame in question | 
|  | 4882 | * @mac_addr: The Ethernet destination address of the frame in question | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4883 | * | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4884 | * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT | 
|  | 4885 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4886 | void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats, | 
|  | 4887 | u32 frame_len, u8 *mac_addr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4888 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4889 | u64 carry_bit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4890 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4891 | /* First adjust the frame length. */ | 
|  | 4892 | frame_len--; | 
|  | 4893 | /* We need to adjust the statistics counters, since the hardware | 
|  | 4894 | * counters overcount this packet as a CRC error and undercount | 
|  | 4895 | * the packet as a good packet | 
|  | 4896 | */ | 
|  | 4897 | /* This packet should not be counted as a CRC error.    */ | 
|  | 4898 | stats->crcerrs--; | 
|  | 4899 | /* This packet does count as a Good Packet Received.    */ | 
|  | 4900 | stats->gprc++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4902 | /* Adjust the Good Octets received counters             */ | 
|  | 4903 | carry_bit = 0x80000000 & stats->gorcl; | 
|  | 4904 | stats->gorcl += frame_len; | 
|  | 4905 | /* If the high bit of Gorcl (the low 32 bits of the Good Octets | 
|  | 4906 | * Received Count) was one before the addition, | 
|  | 4907 | * AND it is zero after, then we lost the carry out, | 
|  | 4908 | * need to add one to Gorch (Good Octets Received Count High). | 
|  | 4909 | * This could be simplified if all environments supported | 
|  | 4910 | * 64-bit integers. | 
|  | 4911 | */ | 
|  | 4912 | if (carry_bit && ((stats->gorcl & 0x80000000) == 0)) | 
|  | 4913 | stats->gorch++; | 
|  | 4914 | /* Is this a broadcast or multicast?  Check broadcast first, | 
|  | 4915 | * since the test for a multicast frame will test positive on | 
|  | 4916 | * a broadcast frame. | 
|  | 4917 | */ | 
|  | 4918 | if ((mac_addr[0] == (u8) 0xff) && (mac_addr[1] == (u8) 0xff)) | 
|  | 4919 | /* Broadcast packet */ | 
|  | 4920 | stats->bprc++; | 
|  | 4921 | else if (*mac_addr & 0x01) | 
|  | 4922 | /* Multicast packet */ | 
|  | 4923 | stats->mprc++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4925 | if (frame_len == hw->max_frame_size) { | 
|  | 4926 | /* In this case, the hardware has overcounted the number of | 
|  | 4927 | * oversize frames. | 
|  | 4928 | */ | 
|  | 4929 | if (stats->roc > 0) | 
|  | 4930 | stats->roc--; | 
|  | 4931 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4932 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4933 | /* Adjust the bin counters when the extra byte put the frame in the | 
|  | 4934 | * wrong bin. Remember that the frame_len was adjusted above. | 
|  | 4935 | */ | 
|  | 4936 | if (frame_len == 64) { | 
|  | 4937 | stats->prc64++; | 
|  | 4938 | stats->prc127--; | 
|  | 4939 | } else if (frame_len == 127) { | 
|  | 4940 | stats->prc127++; | 
|  | 4941 | stats->prc255--; | 
|  | 4942 | } else if (frame_len == 255) { | 
|  | 4943 | stats->prc255++; | 
|  | 4944 | stats->prc511--; | 
|  | 4945 | } else if (frame_len == 511) { | 
|  | 4946 | stats->prc511++; | 
|  | 4947 | stats->prc1023--; | 
|  | 4948 | } else if (frame_len == 1023) { | 
|  | 4949 | stats->prc1023++; | 
|  | 4950 | stats->prc1522--; | 
|  | 4951 | } else if (frame_len == 1522) { | 
|  | 4952 | stats->prc1522++; | 
|  | 4953 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | } | 
|  | 4955 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4956 | /** | 
|  | 4957 | * e1000_get_bus_info | 
|  | 4958 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4959 | * | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4960 | * Gets the current PCI bus type, speed, and width of the hardware | 
|  | 4961 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4962 | void e1000_get_bus_info(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4963 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4964 | u32 status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4965 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4966 | switch (hw->mac_type) { | 
|  | 4967 | case e1000_82542_rev2_0: | 
|  | 4968 | case e1000_82542_rev2_1: | 
|  | 4969 | hw->bus_type = e1000_bus_type_pci; | 
|  | 4970 | hw->bus_speed = e1000_bus_speed_unknown; | 
|  | 4971 | hw->bus_width = e1000_bus_width_unknown; | 
|  | 4972 | break; | 
|  | 4973 | default: | 
|  | 4974 | status = er32(STATUS); | 
|  | 4975 | hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ? | 
|  | 4976 | e1000_bus_type_pcix : e1000_bus_type_pci; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4977 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4978 | if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) { | 
|  | 4979 | hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ? | 
|  | 4980 | e1000_bus_speed_66 : e1000_bus_speed_120; | 
|  | 4981 | } else if (hw->bus_type == e1000_bus_type_pci) { | 
|  | 4982 | hw->bus_speed = (status & E1000_STATUS_PCI66) ? | 
|  | 4983 | e1000_bus_speed_66 : e1000_bus_speed_33; | 
|  | 4984 | } else { | 
|  | 4985 | switch (status & E1000_STATUS_PCIX_SPEED) { | 
|  | 4986 | case E1000_STATUS_PCIX_SPEED_66: | 
|  | 4987 | hw->bus_speed = e1000_bus_speed_66; | 
|  | 4988 | break; | 
|  | 4989 | case E1000_STATUS_PCIX_SPEED_100: | 
|  | 4990 | hw->bus_speed = e1000_bus_speed_100; | 
|  | 4991 | break; | 
|  | 4992 | case E1000_STATUS_PCIX_SPEED_133: | 
|  | 4993 | hw->bus_speed = e1000_bus_speed_133; | 
|  | 4994 | break; | 
|  | 4995 | default: | 
|  | 4996 | hw->bus_speed = e1000_bus_speed_reserved; | 
|  | 4997 | break; | 
|  | 4998 | } | 
|  | 4999 | } | 
|  | 5000 | hw->bus_width = (status & E1000_STATUS_BUS64) ? | 
|  | 5001 | e1000_bus_width_64 : e1000_bus_width_32; | 
|  | 5002 | break; | 
|  | 5003 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5004 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5005 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5006 | /** | 
|  | 5007 | * e1000_write_reg_io | 
|  | 5008 | * @hw: Struct containing variables accessed by shared code | 
|  | 5009 | * @offset: offset to write to | 
|  | 5010 | * @value: value to write | 
|  | 5011 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5012 | * Writes a value to one of the devices registers using port I/O (as opposed to | 
|  | 5013 | * memory mapped I/O). Only 82544 and newer devices support port I/O. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5014 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5015 | static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5016 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5017 | unsigned long io_addr = hw->io_base; | 
|  | 5018 | unsigned long io_data = hw->io_base + 4; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5019 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5020 | e1000_io_write(hw, io_addr, offset); | 
|  | 5021 | e1000_io_write(hw, io_data, value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5022 | } | 
|  | 5023 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5024 | /** | 
|  | 5025 | * e1000_get_cable_length - Estimates the cable length. | 
|  | 5026 | * @hw: Struct containing variables accessed by shared code | 
|  | 5027 | * @min_length: The estimated minimum length | 
|  | 5028 | * @max_length: The estimated maximum length | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5029 | * | 
|  | 5030 | * returns: - E1000_ERR_XXX | 
|  | 5031 | *            E1000_SUCCESS | 
|  | 5032 | * | 
|  | 5033 | * This function always returns a ranged length (minimum & maximum). | 
|  | 5034 | * So for M88 phy's, this function interprets the one value returned from the | 
|  | 5035 | * register to the minimum and maximum range. | 
|  | 5036 | * For IGP phy's, the function calculates the range by the AGC registers. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5037 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5038 | static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length, | 
|  | 5039 | u16 *max_length) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5040 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5041 | s32 ret_val; | 
|  | 5042 | u16 agc_value = 0; | 
|  | 5043 | u16 i, phy_data; | 
|  | 5044 | u16 cable_length; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5046 | e_dbg("e1000_get_cable_length"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5047 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5048 | *min_length = *max_length = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5049 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5050 | /* Use old method for Phy older than IGP */ | 
|  | 5051 | if (hw->phy_type == e1000_phy_m88) { | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5052 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5053 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, | 
|  | 5054 | &phy_data); | 
|  | 5055 | if (ret_val) | 
|  | 5056 | return ret_val; | 
|  | 5057 | cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >> | 
|  | 5058 | M88E1000_PSSR_CABLE_LENGTH_SHIFT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5059 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5060 | /* Convert the enum value to ranged values */ | 
|  | 5061 | switch (cable_length) { | 
|  | 5062 | case e1000_cable_length_50: | 
|  | 5063 | *min_length = 0; | 
|  | 5064 | *max_length = e1000_igp_cable_length_50; | 
|  | 5065 | break; | 
|  | 5066 | case e1000_cable_length_50_80: | 
|  | 5067 | *min_length = e1000_igp_cable_length_50; | 
|  | 5068 | *max_length = e1000_igp_cable_length_80; | 
|  | 5069 | break; | 
|  | 5070 | case e1000_cable_length_80_110: | 
|  | 5071 | *min_length = e1000_igp_cable_length_80; | 
|  | 5072 | *max_length = e1000_igp_cable_length_110; | 
|  | 5073 | break; | 
|  | 5074 | case e1000_cable_length_110_140: | 
|  | 5075 | *min_length = e1000_igp_cable_length_110; | 
|  | 5076 | *max_length = e1000_igp_cable_length_140; | 
|  | 5077 | break; | 
|  | 5078 | case e1000_cable_length_140: | 
|  | 5079 | *min_length = e1000_igp_cable_length_140; | 
|  | 5080 | *max_length = e1000_igp_cable_length_170; | 
|  | 5081 | break; | 
|  | 5082 | default: | 
|  | 5083 | return -E1000_ERR_PHY; | 
|  | 5084 | break; | 
|  | 5085 | } | 
|  | 5086 | } else if (hw->phy_type == e1000_phy_igp) {	/* For IGP PHY */ | 
|  | 5087 | u16 cur_agc_value; | 
|  | 5088 | u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE; | 
| Jeff Kirsher | 6674450 | 2010-12-01 19:59:50 +0000 | [diff] [blame] | 5089 | static const u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = { | 
|  | 5090 | IGP01E1000_PHY_AGC_A, | 
|  | 5091 | IGP01E1000_PHY_AGC_B, | 
|  | 5092 | IGP01E1000_PHY_AGC_C, | 
|  | 5093 | IGP01E1000_PHY_AGC_D | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5094 | }; | 
|  | 5095 | /* Read the AGC registers for all channels */ | 
|  | 5096 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5097 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5098 | ret_val = | 
|  | 5099 | e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data); | 
|  | 5100 | if (ret_val) | 
|  | 5101 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5102 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5103 | cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5104 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5105 | /* Value bound check. */ | 
|  | 5106 | if ((cur_agc_value >= | 
|  | 5107 | IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) | 
|  | 5108 | || (cur_agc_value == 0)) | 
|  | 5109 | return -E1000_ERR_PHY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5110 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5111 | agc_value += cur_agc_value; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5112 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5113 | /* Update minimal AGC value. */ | 
|  | 5114 | if (min_agc_value > cur_agc_value) | 
|  | 5115 | min_agc_value = cur_agc_value; | 
|  | 5116 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5117 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5118 | /* Remove the minimal AGC result for length < 50m */ | 
|  | 5119 | if (agc_value < | 
|  | 5120 | IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) { | 
|  | 5121 | agc_value -= min_agc_value; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5122 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5123 | /* Get the average length of the remaining 3 channels */ | 
|  | 5124 | agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1); | 
|  | 5125 | } else { | 
|  | 5126 | /* Get the average length of all the 4 channels. */ | 
|  | 5127 | agc_value /= IGP01E1000_PHY_CHANNEL_NUM; | 
|  | 5128 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5129 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5130 | /* Set the range of the calculated length. */ | 
|  | 5131 | *min_length = ((e1000_igp_cable_length_table[agc_value] - | 
|  | 5132 | IGP01E1000_AGC_RANGE) > 0) ? | 
|  | 5133 | (e1000_igp_cable_length_table[agc_value] - | 
|  | 5134 | IGP01E1000_AGC_RANGE) : 0; | 
|  | 5135 | *max_length = e1000_igp_cable_length_table[agc_value] + | 
|  | 5136 | IGP01E1000_AGC_RANGE; | 
|  | 5137 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5138 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5139 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5140 | } | 
|  | 5141 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5142 | /** | 
|  | 5143 | * e1000_check_polarity - Check the cable polarity | 
|  | 5144 | * @hw: Struct containing variables accessed by shared code | 
|  | 5145 | * @polarity: output parameter : 0 - Polarity is not reversed | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5146 | *                               1 - Polarity is reversed. | 
|  | 5147 | * | 
|  | 5148 | * returns: - E1000_ERR_XXX | 
|  | 5149 | *            E1000_SUCCESS | 
|  | 5150 | * | 
| Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 5151 | * For phy's older than IGP, this function simply reads the polarity bit in the | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5152 | * Phy Status register.  For IGP phy's, this bit is valid only if link speed is | 
|  | 5153 | * 10 Mbps.  If the link speed is 100 Mbps there is no polarity so this bit will | 
|  | 5154 | * return 0.  If the link speed is 1000 Mbps the polarity status is in the | 
|  | 5155 | * IGP01E1000_PHY_PCS_INIT_REG. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5156 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5157 | static s32 e1000_check_polarity(struct e1000_hw *hw, | 
|  | 5158 | e1000_rev_polarity *polarity) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5159 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5160 | s32 ret_val; | 
|  | 5161 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5163 | e_dbg("e1000_check_polarity"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5165 | if (hw->phy_type == e1000_phy_m88) { | 
|  | 5166 | /* return the Polarity bit in the Status register. */ | 
|  | 5167 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, | 
|  | 5168 | &phy_data); | 
|  | 5169 | if (ret_val) | 
|  | 5170 | return ret_val; | 
|  | 5171 | *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >> | 
|  | 5172 | M88E1000_PSSR_REV_POLARITY_SHIFT) ? | 
|  | 5173 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; | 
| Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 5174 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5175 | } else if (hw->phy_type == e1000_phy_igp) { | 
|  | 5176 | /* Read the Status register to check the speed */ | 
|  | 5177 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, | 
|  | 5178 | &phy_data); | 
|  | 5179 | if (ret_val) | 
|  | 5180 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5181 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5182 | /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to | 
|  | 5183 | * find the polarity status */ | 
|  | 5184 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == | 
|  | 5185 | IGP01E1000_PSSR_SPEED_1000MBPS) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5186 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5187 | /* Read the GIG initialization PCS register (0x00B4) */ | 
|  | 5188 | ret_val = | 
|  | 5189 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG, | 
|  | 5190 | &phy_data); | 
|  | 5191 | if (ret_val) | 
|  | 5192 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5193 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5194 | /* Check the polarity bits */ | 
|  | 5195 | *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? | 
|  | 5196 | e1000_rev_polarity_reversed : | 
|  | 5197 | e1000_rev_polarity_normal; | 
|  | 5198 | } else { | 
|  | 5199 | /* For 10 Mbps, read the polarity bit in the status register. (for | 
|  | 5200 | * 100 Mbps this bit is always 0) */ | 
|  | 5201 | *polarity = | 
|  | 5202 | (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ? | 
|  | 5203 | e1000_rev_polarity_reversed : | 
|  | 5204 | e1000_rev_polarity_normal; | 
|  | 5205 | } | 
|  | 5206 | } | 
|  | 5207 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5208 | } | 
|  | 5209 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5210 | /** | 
|  | 5211 | * e1000_check_downshift - Check if Downshift occurred | 
|  | 5212 | * @hw: Struct containing variables accessed by shared code | 
|  | 5213 | * @downshift: output parameter : 0 - No Downshift occurred. | 
|  | 5214 | *                                1 - Downshift occurred. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5215 | * | 
|  | 5216 | * returns: - E1000_ERR_XXX | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5217 | *            E1000_SUCCESS | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5218 | * | 
| Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 5219 | * For phy's older than IGP, this function reads the Downshift bit in the Phy | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5220 | * Specific Status register.  For IGP phy's, it reads the Downgrade bit in the | 
|  | 5221 | * Link Health register.  In IGP this bit is latched high, so the driver must | 
|  | 5222 | * read it immediately after link is established. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5223 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5224 | static s32 e1000_check_downshift(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5225 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5226 | s32 ret_val; | 
|  | 5227 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5228 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5229 | e_dbg("e1000_check_downshift"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5230 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5231 | if (hw->phy_type == e1000_phy_igp) { | 
|  | 5232 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH, | 
|  | 5233 | &phy_data); | 
|  | 5234 | if (ret_val) | 
|  | 5235 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5236 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5237 | hw->speed_downgraded = | 
|  | 5238 | (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0; | 
|  | 5239 | } else if (hw->phy_type == e1000_phy_m88) { | 
|  | 5240 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, | 
|  | 5241 | &phy_data); | 
|  | 5242 | if (ret_val) | 
|  | 5243 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5244 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5245 | hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >> | 
|  | 5246 | M88E1000_PSSR_DOWNSHIFT_SHIFT; | 
|  | 5247 | } | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5248 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5249 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5250 | } | 
|  | 5251 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5252 | /** | 
|  | 5253 | * e1000_config_dsp_after_link_change | 
|  | 5254 | * @hw: Struct containing variables accessed by shared code | 
|  | 5255 | * @link_up: was link up at the time this was called | 
|  | 5256 | * | 
|  | 5257 | * returns: - E1000_ERR_PHY if fail to read/write the PHY | 
|  | 5258 | *            E1000_SUCCESS at any other case. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5259 | * | 
|  | 5260 | * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a | 
|  | 5261 | * gigabit link is achieved to improve link quality. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5262 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5263 |  | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5264 | static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5265 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5266 | s32 ret_val; | 
|  | 5267 | u16 phy_data, phy_saved_data, speed, duplex, i; | 
| Jeff Kirsher | 6674450 | 2010-12-01 19:59:50 +0000 | [diff] [blame] | 5268 | static const u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = { | 
|  | 5269 | IGP01E1000_PHY_AGC_PARAM_A, | 
|  | 5270 | IGP01E1000_PHY_AGC_PARAM_B, | 
|  | 5271 | IGP01E1000_PHY_AGC_PARAM_C, | 
|  | 5272 | IGP01E1000_PHY_AGC_PARAM_D | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5273 | }; | 
|  | 5274 | u16 min_length, max_length; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5275 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5276 | e_dbg("e1000_config_dsp_after_link_change"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5277 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5278 | if (hw->phy_type != e1000_phy_igp) | 
|  | 5279 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5280 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5281 | if (link_up) { | 
|  | 5282 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); | 
|  | 5283 | if (ret_val) { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5284 | e_dbg("Error getting link speed and duplex\n"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5285 | return ret_val; | 
|  | 5286 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5287 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5288 | if (speed == SPEED_1000) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5289 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5290 | ret_val = | 
|  | 5291 | e1000_get_cable_length(hw, &min_length, | 
|  | 5292 | &max_length); | 
|  | 5293 | if (ret_val) | 
|  | 5294 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5295 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5296 | if ((hw->dsp_config_state == e1000_dsp_config_enabled) | 
|  | 5297 | && min_length >= e1000_igp_cable_length_50) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5298 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5299 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { | 
|  | 5300 | ret_val = | 
|  | 5301 | e1000_read_phy_reg(hw, | 
|  | 5302 | dsp_reg_array[i], | 
|  | 5303 | &phy_data); | 
|  | 5304 | if (ret_val) | 
|  | 5305 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5306 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5307 | phy_data &= | 
|  | 5308 | ~IGP01E1000_PHY_EDAC_MU_INDEX; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5309 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5310 | ret_val = | 
|  | 5311 | e1000_write_phy_reg(hw, | 
|  | 5312 | dsp_reg_array | 
|  | 5313 | [i], phy_data); | 
|  | 5314 | if (ret_val) | 
|  | 5315 | return ret_val; | 
|  | 5316 | } | 
|  | 5317 | hw->dsp_config_state = | 
|  | 5318 | e1000_dsp_config_activated; | 
|  | 5319 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5320 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5321 | if ((hw->ffe_config_state == e1000_ffe_config_enabled) | 
|  | 5322 | && (min_length < e1000_igp_cable_length_50)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5323 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5324 | u16 ffe_idle_err_timeout = | 
|  | 5325 | FFE_IDLE_ERR_COUNT_TIMEOUT_20; | 
|  | 5326 | u32 idle_errs = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5327 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5328 | /* clear previous idle error counts */ | 
|  | 5329 | ret_val = | 
|  | 5330 | e1000_read_phy_reg(hw, PHY_1000T_STATUS, | 
|  | 5331 | &phy_data); | 
|  | 5332 | if (ret_val) | 
|  | 5333 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5334 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5335 | for (i = 0; i < ffe_idle_err_timeout; i++) { | 
|  | 5336 | udelay(1000); | 
|  | 5337 | ret_val = | 
|  | 5338 | e1000_read_phy_reg(hw, | 
|  | 5339 | PHY_1000T_STATUS, | 
|  | 5340 | &phy_data); | 
|  | 5341 | if (ret_val) | 
|  | 5342 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5343 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5344 | idle_errs += | 
|  | 5345 | (phy_data & | 
|  | 5346 | SR_1000T_IDLE_ERROR_CNT); | 
|  | 5347 | if (idle_errs > | 
|  | 5348 | SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) | 
|  | 5349 | { | 
|  | 5350 | hw->ffe_config_state = | 
|  | 5351 | e1000_ffe_config_active; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5352 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5353 | ret_val = | 
|  | 5354 | e1000_write_phy_reg(hw, | 
|  | 5355 | IGP01E1000_PHY_DSP_FFE, | 
|  | 5356 | IGP01E1000_PHY_DSP_FFE_CM_CP); | 
|  | 5357 | if (ret_val) | 
|  | 5358 | return ret_val; | 
|  | 5359 | break; | 
|  | 5360 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5361 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5362 | if (idle_errs) | 
|  | 5363 | ffe_idle_err_timeout = | 
|  | 5364 | FFE_IDLE_ERR_COUNT_TIMEOUT_100; | 
|  | 5365 | } | 
|  | 5366 | } | 
|  | 5367 | } | 
|  | 5368 | } else { | 
|  | 5369 | if (hw->dsp_config_state == e1000_dsp_config_activated) { | 
|  | 5370 | /* Save off the current value of register 0x2F5B to be restored at | 
|  | 5371 | * the end of the routines. */ | 
|  | 5372 | ret_val = | 
|  | 5373 | e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5374 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5375 | if (ret_val) | 
|  | 5376 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5377 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5378 | /* Disable the PHY transmitter */ | 
|  | 5379 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5380 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5381 | if (ret_val) | 
|  | 5382 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5383 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5384 | mdelay(20); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5385 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5386 | ret_val = e1000_write_phy_reg(hw, 0x0000, | 
|  | 5387 | IGP01E1000_IEEE_FORCE_GIGA); | 
|  | 5388 | if (ret_val) | 
|  | 5389 | return ret_val; | 
|  | 5390 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { | 
|  | 5391 | ret_val = | 
|  | 5392 | e1000_read_phy_reg(hw, dsp_reg_array[i], | 
|  | 5393 | &phy_data); | 
|  | 5394 | if (ret_val) | 
|  | 5395 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5396 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5397 | phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX; | 
|  | 5398 | phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5399 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5400 | ret_val = | 
|  | 5401 | e1000_write_phy_reg(hw, dsp_reg_array[i], | 
|  | 5402 | phy_data); | 
|  | 5403 | if (ret_val) | 
|  | 5404 | return ret_val; | 
|  | 5405 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5406 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5407 | ret_val = e1000_write_phy_reg(hw, 0x0000, | 
|  | 5408 | IGP01E1000_IEEE_RESTART_AUTONEG); | 
|  | 5409 | if (ret_val) | 
|  | 5410 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5411 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5412 | mdelay(20); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5413 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5414 | /* Now enable the transmitter */ | 
|  | 5415 | ret_val = | 
|  | 5416 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5417 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5418 | if (ret_val) | 
|  | 5419 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5420 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5421 | hw->dsp_config_state = e1000_dsp_config_enabled; | 
|  | 5422 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5423 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5424 | if (hw->ffe_config_state == e1000_ffe_config_active) { | 
|  | 5425 | /* Save off the current value of register 0x2F5B to be restored at | 
|  | 5426 | * the end of the routines. */ | 
|  | 5427 | ret_val = | 
|  | 5428 | e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5429 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5430 | if (ret_val) | 
|  | 5431 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5432 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5433 | /* Disable the PHY transmitter */ | 
|  | 5434 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5435 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5436 | if (ret_val) | 
|  | 5437 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5438 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5439 | mdelay(20); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5440 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5441 | ret_val = e1000_write_phy_reg(hw, 0x0000, | 
|  | 5442 | IGP01E1000_IEEE_FORCE_GIGA); | 
|  | 5443 | if (ret_val) | 
|  | 5444 | return ret_val; | 
|  | 5445 | ret_val = | 
|  | 5446 | e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE, | 
|  | 5447 | IGP01E1000_PHY_DSP_FFE_DEFAULT); | 
|  | 5448 | if (ret_val) | 
|  | 5449 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5450 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5451 | ret_val = e1000_write_phy_reg(hw, 0x0000, | 
|  | 5452 | IGP01E1000_IEEE_RESTART_AUTONEG); | 
|  | 5453 | if (ret_val) | 
|  | 5454 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5455 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5456 | mdelay(20); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5457 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5458 | /* Now enable the transmitter */ | 
|  | 5459 | ret_val = | 
|  | 5460 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5461 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5462 | if (ret_val) | 
|  | 5463 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5464 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5465 | hw->ffe_config_state = e1000_ffe_config_enabled; | 
|  | 5466 | } | 
|  | 5467 | } | 
|  | 5468 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5469 | } | 
|  | 5470 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5471 | /** | 
|  | 5472 | * e1000_set_phy_mode - Set PHY to class A mode | 
|  | 5473 | * @hw: Struct containing variables accessed by shared code | 
|  | 5474 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5475 | * Assumes the following operations will follow to enable the new class mode. | 
|  | 5476 | *  1. Do a PHY soft reset | 
|  | 5477 | *  2. Restart auto-negotiation or force link. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5478 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5479 | static s32 e1000_set_phy_mode(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5480 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5481 | s32 ret_val; | 
|  | 5482 | u16 eeprom_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5483 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5484 | e_dbg("e1000_set_phy_mode"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5485 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5486 | if ((hw->mac_type == e1000_82545_rev_3) && | 
|  | 5487 | (hw->media_type == e1000_media_type_copper)) { | 
|  | 5488 | ret_val = | 
|  | 5489 | e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, | 
|  | 5490 | &eeprom_data); | 
|  | 5491 | if (ret_val) { | 
|  | 5492 | return ret_val; | 
|  | 5493 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5494 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5495 | if ((eeprom_data != EEPROM_RESERVED_WORD) && | 
|  | 5496 | (eeprom_data & EEPROM_PHY_CLASS_A)) { | 
|  | 5497 | ret_val = | 
|  | 5498 | e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, | 
|  | 5499 | 0x000B); | 
|  | 5500 | if (ret_val) | 
|  | 5501 | return ret_val; | 
|  | 5502 | ret_val = | 
|  | 5503 | e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, | 
|  | 5504 | 0x8104); | 
|  | 5505 | if (ret_val) | 
|  | 5506 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5507 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5508 | hw->phy_reset_disable = false; | 
|  | 5509 | } | 
|  | 5510 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5511 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5512 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5513 | } | 
|  | 5514 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5515 | /** | 
|  | 5516 | * e1000_set_d3_lplu_state - set d3 link power state | 
|  | 5517 | * @hw: Struct containing variables accessed by shared code | 
|  | 5518 | * @active: true to enable lplu false to disable lplu. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5519 | * | 
|  | 5520 | * This function sets the lplu state according to the active flag.  When | 
|  | 5521 | * activating lplu this function also disables smart speed and vise versa. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5522 | * lplu will not be activated unless the device autonegotiation advertisement | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5523 | * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5524 | * | 
|  | 5525 | * returns: - E1000_ERR_PHY if fail to read/write the PHY | 
|  | 5526 | *            E1000_SUCCESS at any other case. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5527 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5528 | static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5529 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5530 | s32 ret_val; | 
|  | 5531 | u16 phy_data; | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5532 | e_dbg("e1000_set_d3_lplu_state"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5533 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5534 | if (hw->phy_type != e1000_phy_igp) | 
|  | 5535 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5536 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5537 | /* During driver activity LPLU should not be used or it will attain link | 
|  | 5538 | * from the lowest speeds starting from 10Mbps. The capability is used for | 
|  | 5539 | * Dx transitions and states */ | 
|  | 5540 | if (hw->mac_type == e1000_82541_rev_2 | 
|  | 5541 | || hw->mac_type == e1000_82547_rev_2) { | 
|  | 5542 | ret_val = | 
|  | 5543 | e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data); | 
|  | 5544 | if (ret_val) | 
|  | 5545 | return ret_val; | 
|  | 5546 | } | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5547 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5548 | if (!active) { | 
|  | 5549 | if (hw->mac_type == e1000_82541_rev_2 || | 
|  | 5550 | hw->mac_type == e1000_82547_rev_2) { | 
|  | 5551 | phy_data &= ~IGP01E1000_GMII_FLEX_SPD; | 
|  | 5552 | ret_val = | 
|  | 5553 | e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, | 
|  | 5554 | phy_data); | 
|  | 5555 | if (ret_val) | 
|  | 5556 | return ret_val; | 
|  | 5557 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5558 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5559 | /* LPLU and SmartSpeed are mutually exclusive.  LPLU is used during | 
|  | 5560 | * Dx states where the power conservation is most important.  During | 
|  | 5561 | * driver activity we should enable SmartSpeed, so performance is | 
|  | 5562 | * maintained. */ | 
|  | 5563 | if (hw->smart_speed == e1000_smart_speed_on) { | 
|  | 5564 | ret_val = | 
|  | 5565 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 5566 | &phy_data); | 
|  | 5567 | if (ret_val) | 
|  | 5568 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5569 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5570 | phy_data |= IGP01E1000_PSCFR_SMART_SPEED; | 
|  | 5571 | ret_val = | 
|  | 5572 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 5573 | phy_data); | 
|  | 5574 | if (ret_val) | 
|  | 5575 | return ret_val; | 
|  | 5576 | } else if (hw->smart_speed == e1000_smart_speed_off) { | 
|  | 5577 | ret_val = | 
|  | 5578 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 5579 | &phy_data); | 
|  | 5580 | if (ret_val) | 
|  | 5581 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5582 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5583 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; | 
|  | 5584 | ret_val = | 
|  | 5585 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 5586 | phy_data); | 
|  | 5587 | if (ret_val) | 
|  | 5588 | return ret_val; | 
|  | 5589 | } | 
|  | 5590 | } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) | 
|  | 5591 | || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) | 
|  | 5592 | || (hw->autoneg_advertised == | 
|  | 5593 | AUTONEG_ADVERTISE_10_100_ALL)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5594 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5595 | if (hw->mac_type == e1000_82541_rev_2 || | 
|  | 5596 | hw->mac_type == e1000_82547_rev_2) { | 
|  | 5597 | phy_data |= IGP01E1000_GMII_FLEX_SPD; | 
|  | 5598 | ret_val = | 
|  | 5599 | e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, | 
|  | 5600 | phy_data); | 
|  | 5601 | if (ret_val) | 
|  | 5602 | return ret_val; | 
|  | 5603 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5604 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5605 | /* When LPLU is enabled we should disable SmartSpeed */ | 
|  | 5606 | ret_val = | 
|  | 5607 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 5608 | &phy_data); | 
|  | 5609 | if (ret_val) | 
|  | 5610 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5611 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5612 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; | 
|  | 5613 | ret_val = | 
|  | 5614 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 5615 | phy_data); | 
|  | 5616 | if (ret_val) | 
|  | 5617 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5618 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5619 | } | 
|  | 5620 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5621 | } | 
|  | 5622 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5623 | /** | 
|  | 5624 | * e1000_set_vco_speed | 
|  | 5625 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5626 | * | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5627 | * Change VCO speed register to improve Bit Error Rate performance of SERDES. | 
|  | 5628 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5629 | static s32 e1000_set_vco_speed(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5630 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5631 | s32 ret_val; | 
|  | 5632 | u16 default_page = 0; | 
|  | 5633 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5634 |  | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5635 | e_dbg("e1000_set_vco_speed"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5636 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5637 | switch (hw->mac_type) { | 
|  | 5638 | case e1000_82545_rev_3: | 
|  | 5639 | case e1000_82546_rev_3: | 
|  | 5640 | break; | 
|  | 5641 | default: | 
|  | 5642 | return E1000_SUCCESS; | 
|  | 5643 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5644 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5645 | /* Set PHY register 30, page 5, bit 8 to 0 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5646 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5647 | ret_val = | 
|  | 5648 | e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page); | 
|  | 5649 | if (ret_val) | 
|  | 5650 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5651 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5652 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005); | 
|  | 5653 | if (ret_val) | 
|  | 5654 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5655 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5656 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data); | 
|  | 5657 | if (ret_val) | 
|  | 5658 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5659 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5660 | phy_data &= ~M88E1000_PHY_VCO_REG_BIT8; | 
|  | 5661 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data); | 
|  | 5662 | if (ret_val) | 
|  | 5663 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5664 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5665 | /* Set PHY register 30, page 4, bit 11 to 1 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5666 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5667 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004); | 
|  | 5668 | if (ret_val) | 
|  | 5669 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5670 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5671 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data); | 
|  | 5672 | if (ret_val) | 
|  | 5673 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5674 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5675 | phy_data |= M88E1000_PHY_VCO_REG_BIT11; | 
|  | 5676 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data); | 
|  | 5677 | if (ret_val) | 
|  | 5678 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5679 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5680 | ret_val = | 
|  | 5681 | e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page); | 
|  | 5682 | if (ret_val) | 
|  | 5683 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5684 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5685 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5686 | } | 
|  | 5687 |  | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5688 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5689 | /** | 
|  | 5690 | * e1000_enable_mng_pass_thru - check for bmc pass through | 
|  | 5691 | * @hw: Struct containing variables accessed by shared code | 
|  | 5692 | * | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5693 | * Verifies the hardware needs to allow ARPs to be processed by the host | 
| Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5694 | * returns: - true/false | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5695 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5696 | u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5697 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5698 | u32 manc; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5699 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5700 | if (hw->asf_firmware_present) { | 
|  | 5701 | manc = er32(MANC); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5702 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5703 | if (!(manc & E1000_MANC_RCV_TCO_EN) || | 
|  | 5704 | !(manc & E1000_MANC_EN_MAC_ADDR_FILTER)) | 
|  | 5705 | return false; | 
|  | 5706 | if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN)) | 
|  | 5707 | return true; | 
|  | 5708 | } | 
|  | 5709 | return false; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5710 | } | 
|  | 5711 |  | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5712 | static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5713 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5714 | s32 ret_val; | 
|  | 5715 | u16 mii_status_reg; | 
|  | 5716 | u16 i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5717 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5718 | /* Polarity reversal workaround for forced 10F/10H links. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5719 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5720 | /* Disable the transmitter on the PHY */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5721 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5722 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); | 
|  | 5723 | if (ret_val) | 
|  | 5724 | return ret_val; | 
|  | 5725 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF); | 
|  | 5726 | if (ret_val) | 
|  | 5727 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5728 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5729 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); | 
|  | 5730 | if (ret_val) | 
|  | 5731 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5732 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5733 | /* This loop will early-out if the NO link condition has been met. */ | 
|  | 5734 | for (i = PHY_FORCE_TIME; i > 0; i--) { | 
|  | 5735 | /* Read the MII Status Register and wait for Link Status bit | 
|  | 5736 | * to be clear. | 
|  | 5737 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5738 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5739 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 5740 | if (ret_val) | 
|  | 5741 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5743 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 5744 | if (ret_val) | 
|  | 5745 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5746 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5747 | if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) | 
|  | 5748 | break; | 
|  | 5749 | mdelay(100); | 
|  | 5750 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5751 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5752 | /* Recommended delay time after link has been lost */ | 
|  | 5753 | mdelay(1000); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5754 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5755 | /* Now we will re-enable th transmitter on the PHY */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5756 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5757 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); | 
|  | 5758 | if (ret_val) | 
|  | 5759 | return ret_val; | 
|  | 5760 | mdelay(50); | 
|  | 5761 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0); | 
|  | 5762 | if (ret_val) | 
|  | 5763 | return ret_val; | 
|  | 5764 | mdelay(50); | 
|  | 5765 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00); | 
|  | 5766 | if (ret_val) | 
|  | 5767 | return ret_val; | 
|  | 5768 | mdelay(50); | 
|  | 5769 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000); | 
|  | 5770 | if (ret_val) | 
|  | 5771 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5772 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5773 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); | 
|  | 5774 | if (ret_val) | 
|  | 5775 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5776 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5777 | /* This loop will early-out if the link condition has been met. */ | 
|  | 5778 | for (i = PHY_FORCE_TIME; i > 0; i--) { | 
|  | 5779 | /* Read the MII Status Register and wait for Link Status bit | 
|  | 5780 | * to be set. | 
|  | 5781 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5782 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5783 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 5784 | if (ret_val) | 
|  | 5785 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5786 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5787 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 5788 | if (ret_val) | 
|  | 5789 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5790 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5791 | if (mii_status_reg & MII_SR_LINK_STATUS) | 
|  | 5792 | break; | 
|  | 5793 | mdelay(100); | 
|  | 5794 | } | 
|  | 5795 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5796 | } | 
|  | 5797 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5798 | /** | 
|  | 5799 | * e1000_get_auto_rd_done | 
|  | 5800 | * @hw: Struct containing variables accessed by shared code | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5801 | * | 
|  | 5802 | * Check for EEPROM Auto Read bit done. | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5803 | * returns: - E1000_ERR_RESET if fail to reset MAC | 
|  | 5804 | *            E1000_SUCCESS at any other case. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5805 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5806 | static s32 e1000_get_auto_rd_done(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5807 | { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5808 | e_dbg("e1000_get_auto_rd_done"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5809 | msleep(5); | 
|  | 5810 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5811 | } | 
|  | 5812 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5813 | /** | 
|  | 5814 | * e1000_get_phy_cfg_done | 
|  | 5815 | * @hw: Struct containing variables accessed by shared code | 
|  | 5816 | * | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5817 | * Checks if the PHY configuration is done | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5818 | * returns: - E1000_ERR_RESET if fail to reset MAC | 
|  | 5819 | *            E1000_SUCCESS at any other case. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5820 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5821 | static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5822 | { | 
| Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5823 | e_dbg("e1000_get_phy_cfg_done"); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5824 | mdelay(10); | 
|  | 5825 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5826 | } |