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 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | /* e1000_hw.c |
| 30 | * Shared functions for accessing and configuring the MAC |
| 31 | */ |
| 32 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include "e1000_hw.h" |
| 35 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 36 | static s32 e1000_swfw_sync_acquire(struct e1000_hw *hw, u16 mask); |
| 37 | static void e1000_swfw_sync_release(struct e1000_hw *hw, u16 mask); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 38 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 39 | static s32 e1000_check_downshift(struct e1000_hw *hw); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 40 | static s32 e1000_check_polarity(struct e1000_hw *hw, |
| 41 | e1000_rev_polarity *polarity); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 42 | static void e1000_clear_hw_cntrs(struct e1000_hw *hw); |
| 43 | static void e1000_clear_vfta(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 44 | static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 45 | bool link_up); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 46 | static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw); |
| 47 | static s32 e1000_detect_gig_phy(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 48 | static s32 e1000_get_auto_rd_done(struct e1000_hw *hw); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 49 | static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length, |
| 50 | u16 *max_length); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 51 | static s32 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw); |
| 52 | static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 53 | static s32 e1000_id_led_init(struct e1000_hw *hw); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 54 | static void e1000_init_rx_addrs(struct e1000_hw *hw); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 55 | static s32 e1000_phy_igp_get_info(struct e1000_hw *hw, |
| 56 | struct e1000_phy_info *phy_info); |
| 57 | static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words, |
| 58 | u16 *data); |
| 59 | static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words, |
| 60 | u16 *data); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 61 | static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 62 | static s32 e1000_phy_m88_get_info(struct e1000_hw *hw, |
| 63 | struct e1000_phy_info *phy_info); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 64 | static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 65 | 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] | 66 | static s32 e1000_wait_autoneg(struct e1000_hw *hw); |
| 67 | static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value); |
| 68 | static s32 e1000_set_phy_type(struct e1000_hw *hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | static void e1000_phy_init_script(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 70 | static s32 e1000_setup_copper_link(struct e1000_hw *hw); |
| 71 | static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw); |
| 72 | static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw); |
| 73 | static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw); |
| 74 | static s32 e1000_config_mac_to_phy(struct e1000_hw *hw); |
| 75 | static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl); |
| 76 | static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl); |
| 77 | static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 78 | u16 count); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 79 | static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw); |
| 80 | static s32 e1000_phy_reset_dsp(struct e1000_hw *hw); |
| 81 | static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, |
| 82 | u16 words, u16 *data); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 83 | static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset, |
| 84 | u16 words, u16 *data); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 85 | static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw); |
| 86 | static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd); |
| 87 | static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 88 | 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] | 89 | 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] | 90 | u16 phy_data); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 91 | 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] | 92 | u16 *phy_data); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 93 | static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count); |
| 94 | static s32 e1000_acquire_eeprom(struct e1000_hw *hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | static void e1000_release_eeprom(struct e1000_hw *hw); |
| 96 | static void e1000_standby_eeprom(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 97 | static s32 e1000_set_vco_speed(struct e1000_hw *hw); |
| 98 | static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw); |
| 99 | static s32 e1000_set_phy_mode(struct e1000_hw *hw); |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 100 | static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data); |
| 101 | static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | /* IGP cable length table */ |
| 104 | static const |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 105 | u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
| 107 | 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25, |
| 108 | 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40, |
| 109 | 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, |
| 110 | 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90, |
| 111 | 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, |
| 112 | 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, |
| 113 | 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120}; |
| 114 | |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 115 | static DEFINE_SPINLOCK(e1000_eeprom_lock); |
| 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | /****************************************************************************** |
| 118 | * Set the phy type member in the hw struct. |
| 119 | * |
| 120 | * hw - Struct containing variables accessed by shared code |
| 121 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 122 | static s32 e1000_set_phy_type(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | DEBUGFUNC("e1000_set_phy_type"); |
| 125 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 126 | if (hw->mac_type == e1000_undefined) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 127 | return -E1000_ERR_PHY_TYPE; |
| 128 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 129 | switch (hw->phy_id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | case M88E1000_E_PHY_ID: |
| 131 | case M88E1000_I_PHY_ID: |
| 132 | case M88E1011_I_PHY_ID: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 133 | case M88E1111_I_PHY_ID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | hw->phy_type = e1000_phy_m88; |
| 135 | break; |
| 136 | case IGP01E1000_I_PHY_ID: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 137 | if (hw->mac_type == e1000_82541 || |
| 138 | hw->mac_type == e1000_82541_rev_2 || |
| 139 | hw->mac_type == e1000_82547 || |
| 140 | hw->mac_type == e1000_82547_rev_2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | hw->phy_type = e1000_phy_igp; |
| 142 | break; |
| 143 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | default: |
| 145 | /* Should never have loaded on this device */ |
| 146 | hw->phy_type = e1000_phy_undefined; |
| 147 | return -E1000_ERR_PHY_TYPE; |
| 148 | } |
| 149 | |
| 150 | return E1000_SUCCESS; |
| 151 | } |
| 152 | |
| 153 | /****************************************************************************** |
| 154 | * IGP phy init script - initializes the GbE PHY |
| 155 | * |
| 156 | * hw - Struct containing variables accessed by shared code |
| 157 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 158 | static void e1000_phy_init_script(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 160 | u32 ret_val; |
| 161 | u16 phy_saved_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | DEBUGFUNC("e1000_phy_init_script"); |
| 164 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 165 | if (hw->phy_init_script) { |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 166 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | /* Save off the current value of register 0x2F5B to be restored at |
| 169 | * the end of this routine. */ |
| 170 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
| 171 | |
| 172 | /* Disabled the PHY transmitter */ |
| 173 | e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 174 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 175 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | e1000_write_phy_reg(hw,0x0000,0x0140); |
| 178 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 179 | msleep(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 181 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | case e1000_82541: |
| 183 | case e1000_82547: |
| 184 | e1000_write_phy_reg(hw, 0x1F95, 0x0001); |
| 185 | |
| 186 | e1000_write_phy_reg(hw, 0x1F71, 0xBD21); |
| 187 | |
| 188 | e1000_write_phy_reg(hw, 0x1F79, 0x0018); |
| 189 | |
| 190 | e1000_write_phy_reg(hw, 0x1F30, 0x1600); |
| 191 | |
| 192 | e1000_write_phy_reg(hw, 0x1F31, 0x0014); |
| 193 | |
| 194 | e1000_write_phy_reg(hw, 0x1F32, 0x161C); |
| 195 | |
| 196 | e1000_write_phy_reg(hw, 0x1F94, 0x0003); |
| 197 | |
| 198 | e1000_write_phy_reg(hw, 0x1F96, 0x003F); |
| 199 | |
| 200 | e1000_write_phy_reg(hw, 0x2010, 0x0008); |
| 201 | break; |
| 202 | |
| 203 | case e1000_82541_rev_2: |
| 204 | case e1000_82547_rev_2: |
| 205 | e1000_write_phy_reg(hw, 0x1F73, 0x0099); |
| 206 | break; |
| 207 | default: |
| 208 | break; |
| 209 | } |
| 210 | |
| 211 | e1000_write_phy_reg(hw, 0x0000, 0x3300); |
| 212 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 213 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | /* Now enable the transmitter */ |
| 216 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
| 217 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 218 | if (hw->mac_type == e1000_82547) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 219 | u16 fused, fine, coarse; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | /* Move to analog registers page */ |
| 222 | e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused); |
| 223 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 224 | if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused); |
| 226 | |
| 227 | fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK; |
| 228 | coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK; |
| 229 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 230 | if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10; |
| 232 | fine -= IGP01E1000_ANALOG_FUSE_FINE_1; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 233 | } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | fine -= IGP01E1000_ANALOG_FUSE_FINE_10; |
| 235 | |
| 236 | fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) | |
| 237 | (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) | |
| 238 | (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK); |
| 239 | |
| 240 | e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused); |
| 241 | e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS, |
| 242 | IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL); |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /****************************************************************************** |
| 249 | * Set the mac type member in the hw struct. |
| 250 | * |
| 251 | * hw - Struct containing variables accessed by shared code |
| 252 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 253 | s32 e1000_set_mac_type(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 255 | DEBUGFUNC("e1000_set_mac_type"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 257 | switch (hw->device_id) { |
| 258 | case E1000_DEV_ID_82542: |
| 259 | switch (hw->revision_id) { |
| 260 | case E1000_82542_2_0_REV_ID: |
| 261 | hw->mac_type = e1000_82542_rev2_0; |
| 262 | break; |
| 263 | case E1000_82542_2_1_REV_ID: |
| 264 | hw->mac_type = e1000_82542_rev2_1; |
| 265 | break; |
| 266 | default: |
| 267 | /* Invalid 82542 revision ID */ |
| 268 | return -E1000_ERR_MAC_TYPE; |
| 269 | } |
| 270 | break; |
| 271 | case E1000_DEV_ID_82543GC_FIBER: |
| 272 | case E1000_DEV_ID_82543GC_COPPER: |
| 273 | hw->mac_type = e1000_82543; |
| 274 | break; |
| 275 | case E1000_DEV_ID_82544EI_COPPER: |
| 276 | case E1000_DEV_ID_82544EI_FIBER: |
| 277 | case E1000_DEV_ID_82544GC_COPPER: |
| 278 | case E1000_DEV_ID_82544GC_LOM: |
| 279 | hw->mac_type = e1000_82544; |
| 280 | break; |
| 281 | case E1000_DEV_ID_82540EM: |
| 282 | case E1000_DEV_ID_82540EM_LOM: |
| 283 | case E1000_DEV_ID_82540EP: |
| 284 | case E1000_DEV_ID_82540EP_LOM: |
| 285 | case E1000_DEV_ID_82540EP_LP: |
| 286 | hw->mac_type = e1000_82540; |
| 287 | break; |
| 288 | case E1000_DEV_ID_82545EM_COPPER: |
| 289 | case E1000_DEV_ID_82545EM_FIBER: |
| 290 | hw->mac_type = e1000_82545; |
| 291 | break; |
| 292 | case E1000_DEV_ID_82545GM_COPPER: |
| 293 | case E1000_DEV_ID_82545GM_FIBER: |
| 294 | case E1000_DEV_ID_82545GM_SERDES: |
| 295 | hw->mac_type = e1000_82545_rev_3; |
| 296 | break; |
| 297 | case E1000_DEV_ID_82546EB_COPPER: |
| 298 | case E1000_DEV_ID_82546EB_FIBER: |
| 299 | case E1000_DEV_ID_82546EB_QUAD_COPPER: |
| 300 | hw->mac_type = e1000_82546; |
| 301 | break; |
| 302 | case E1000_DEV_ID_82546GB_COPPER: |
| 303 | case E1000_DEV_ID_82546GB_FIBER: |
| 304 | case E1000_DEV_ID_82546GB_SERDES: |
| 305 | case E1000_DEV_ID_82546GB_PCIE: |
| 306 | case E1000_DEV_ID_82546GB_QUAD_COPPER: |
| 307 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
| 308 | hw->mac_type = e1000_82546_rev_3; |
| 309 | break; |
| 310 | case E1000_DEV_ID_82541EI: |
| 311 | case E1000_DEV_ID_82541EI_MOBILE: |
| 312 | case E1000_DEV_ID_82541ER_LOM: |
| 313 | hw->mac_type = e1000_82541; |
| 314 | break; |
| 315 | case E1000_DEV_ID_82541ER: |
| 316 | case E1000_DEV_ID_82541GI: |
| 317 | case E1000_DEV_ID_82541GI_LF: |
| 318 | case E1000_DEV_ID_82541GI_MOBILE: |
| 319 | hw->mac_type = e1000_82541_rev_2; |
| 320 | break; |
| 321 | case E1000_DEV_ID_82547EI: |
| 322 | case E1000_DEV_ID_82547EI_MOBILE: |
| 323 | hw->mac_type = e1000_82547; |
| 324 | break; |
| 325 | case E1000_DEV_ID_82547GI: |
| 326 | hw->mac_type = e1000_82547_rev_2; |
| 327 | break; |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 328 | default: |
| 329 | /* Should never have loaded on this device */ |
| 330 | return -E1000_ERR_MAC_TYPE; |
| 331 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 333 | switch (hw->mac_type) { |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 334 | case e1000_82541: |
| 335 | case e1000_82547: |
| 336 | case e1000_82541_rev_2: |
| 337 | case e1000_82547_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 338 | hw->asf_firmware_present = true; |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 339 | break; |
| 340 | default: |
| 341 | break; |
| 342 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 344 | /* The 82543 chip does not count tx_carrier_errors properly in |
| 345 | * FD mode |
| 346 | */ |
| 347 | if (hw->mac_type == e1000_82543) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 348 | hw->bad_tx_carr_stats_fd = true; |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 349 | |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 350 | if (hw->mac_type > e1000_82544) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 351 | hw->has_smbus = true; |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 352 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 353 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | /***************************************************************************** |
| 357 | * Set media type and TBI compatibility. |
| 358 | * |
| 359 | * hw - Struct containing variables accessed by shared code |
| 360 | * **************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 361 | void e1000_set_media_type(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 363 | u32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
| 365 | DEBUGFUNC("e1000_set_media_type"); |
| 366 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 367 | if (hw->mac_type != e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | /* tbi_compatibility is only valid on 82543 */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 369 | hw->tbi_compatibility_en = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | switch (hw->device_id) { |
| 373 | case E1000_DEV_ID_82545GM_SERDES: |
| 374 | case E1000_DEV_ID_82546GB_SERDES: |
| 375 | hw->media_type = e1000_media_type_internal_serdes; |
| 376 | break; |
| 377 | default: |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 378 | switch (hw->mac_type) { |
| 379 | case e1000_82542_rev2_0: |
| 380 | case e1000_82542_rev2_1: |
| 381 | hw->media_type = e1000_media_type_fiber; |
| 382 | break; |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 383 | default: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 384 | status = er32(STATUS); |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 385 | if (status & E1000_STATUS_TBIMODE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | hw->media_type = e1000_media_type_fiber; |
| 387 | /* tbi_compatibility not valid on fiber */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 388 | hw->tbi_compatibility_en = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } else { |
| 390 | hw->media_type = e1000_media_type_copper; |
| 391 | } |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 392 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | /****************************************************************************** |
| 398 | * Reset the transmit and receive units; mask and clear all interrupts. |
| 399 | * |
| 400 | * hw - Struct containing variables accessed by shared code |
| 401 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 402 | s32 e1000_reset_hw(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 404 | u32 ctrl; |
| 405 | u32 ctrl_ext; |
| 406 | u32 icr; |
| 407 | u32 manc; |
| 408 | u32 led_ctrl; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 409 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
| 411 | DEBUGFUNC("e1000_reset_hw"); |
| 412 | |
| 413 | /* For 82542 (rev 2.0), disable MWI before issuing a device reset */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 414 | if (hw->mac_type == e1000_82542_rev2_0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); |
| 416 | e1000_pci_clear_mwi(hw); |
| 417 | } |
| 418 | |
| 419 | /* Clear interrupt mask to stop board from generating interrupts */ |
| 420 | DEBUGOUT("Masking off all interrupts\n"); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 421 | ew32(IMC, 0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
| 423 | /* Disable the Transmit and Receive units. Then delay to allow |
| 424 | * any pending transactions to complete before we hit the MAC with |
| 425 | * the global reset. |
| 426 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 427 | ew32(RCTL, 0); |
| 428 | ew32(TCTL, E1000_TCTL_PSP); |
| 429 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
| 431 | /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 432 | hw->tbi_compatibility_on = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
| 434 | /* Delay to allow any outstanding PCI transactions to complete before |
| 435 | * resetting the device |
| 436 | */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 437 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 439 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
| 441 | /* Must reset the PHY before resetting the MAC */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 442 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 443 | ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST)); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 444 | msleep(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | /* Issue a global reset to the MAC. This will reset the chip's |
| 448 | * transmit, receive, DMA, and link units. It will not effect |
| 449 | * the current PCI configuration. The global reset bit is self- |
| 450 | * clearing, and should clear within a microsecond. |
| 451 | */ |
| 452 | DEBUGOUT("Issuing a global reset to MAC\n"); |
| 453 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 454 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | case e1000_82544: |
| 456 | case e1000_82540: |
| 457 | case e1000_82545: |
| 458 | case e1000_82546: |
| 459 | case e1000_82541: |
| 460 | case e1000_82541_rev_2: |
| 461 | /* These controllers can't ack the 64-bit write when issuing the |
| 462 | * reset, so use IO-mapping as a workaround to issue the reset */ |
| 463 | E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST)); |
| 464 | break; |
| 465 | case e1000_82545_rev_3: |
| 466 | case e1000_82546_rev_3: |
| 467 | /* Reset is performed on a shadow of the control register */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 468 | ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | break; |
| 470 | default: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 471 | ew32(CTRL, (ctrl | E1000_CTRL_RST)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | break; |
| 473 | } |
| 474 | |
| 475 | /* After MAC reset, force reload of EEPROM to restore power-on settings to |
| 476 | * device. Later controllers reload the EEPROM automatically, so just wait |
| 477 | * for reload to complete. |
| 478 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 479 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | case e1000_82542_rev2_0: |
| 481 | case e1000_82542_rev2_1: |
| 482 | case e1000_82543: |
| 483 | case e1000_82544: |
| 484 | /* Wait for reset to complete */ |
| 485 | udelay(10); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 486 | ctrl_ext = er32(CTRL_EXT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 488 | ew32(CTRL_EXT, ctrl_ext); |
| 489 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | /* Wait for EEPROM reload */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 491 | msleep(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | break; |
| 493 | case e1000_82541: |
| 494 | case e1000_82541_rev_2: |
| 495 | case e1000_82547: |
| 496 | case e1000_82547_rev_2: |
| 497 | /* Wait for EEPROM reload */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 498 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | break; |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 500 | default: |
| 501 | /* Auto read done will delay 5ms or poll based on mac type */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 502 | ret_val = e1000_get_auto_rd_done(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 503 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 504 | return ret_val; |
| 505 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | /* Disable HW ARPs on ASF enabled adapters */ |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 509 | if (hw->mac_type >= e1000_82540) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 510 | manc = er32(MANC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | manc &= ~(E1000_MANC_ARP_EN); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 512 | ew32(MANC, manc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 515 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | e1000_phy_init_script(hw); |
| 517 | |
| 518 | /* Configure activity LED after PHY reset */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 519 | led_ctrl = er32(LEDCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 521 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 522 | ew32(LEDCTL, led_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | /* Clear interrupt mask to stop board from generating interrupts */ |
| 526 | DEBUGOUT("Masking off all interrupts\n"); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 527 | ew32(IMC, 0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | /* Clear any pending interrupt events. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 530 | icr = er32(ICR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
| 532 | /* If MWI was previously enabled, reenable it. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 533 | if (hw->mac_type == e1000_82542_rev2_0) { |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 534 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | e1000_pci_set_mwi(hw); |
| 536 | } |
| 537 | |
| 538 | return E1000_SUCCESS; |
| 539 | } |
| 540 | |
| 541 | /****************************************************************************** |
| 542 | * Performs basic configuration of the adapter. |
| 543 | * |
| 544 | * hw - Struct containing variables accessed by shared code |
| 545 | * |
| 546 | * Assumes that the controller has previously been reset and is in a |
| 547 | * post-reset uninitialized state. Initializes the receive address registers, |
| 548 | * multicast table, and VLAN filter table. Calls routines to setup link |
| 549 | * configuration and flow control settings. Clears all on-chip counters. Leaves |
| 550 | * the transmit and receive units disabled and uninitialized. |
| 551 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 552 | s32 e1000_init_hw(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 554 | u32 ctrl; |
| 555 | u32 i; |
| 556 | s32 ret_val; |
| 557 | u32 mta_size; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 558 | u32 ctrl_ext; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | DEBUGFUNC("e1000_init_hw"); |
| 561 | |
| 562 | /* Initialize Identification LED */ |
| 563 | ret_val = e1000_id_led_init(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 564 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | DEBUGOUT("Error Initializing Identification LED\n"); |
| 566 | return ret_val; |
| 567 | } |
| 568 | |
| 569 | /* Set the media type and TBI compatibility */ |
| 570 | e1000_set_media_type(hw); |
| 571 | |
| 572 | /* Disabling VLAN filtering. */ |
| 573 | DEBUGOUT("Initializing the IEEE VLAN\n"); |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 574 | if (hw->mac_type < e1000_82545_rev_3) |
| 575 | ew32(VET, 0); |
| 576 | e1000_clear_vfta(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
| 578 | /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 579 | if (hw->mac_type == e1000_82542_rev2_0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); |
| 581 | e1000_pci_clear_mwi(hw); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 582 | ew32(RCTL, E1000_RCTL_RST); |
| 583 | E1000_WRITE_FLUSH(); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 584 | msleep(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /* Setup the receive address. This involves initializing all of the Receive |
| 588 | * Address Registers (RARs 0 - 15). |
| 589 | */ |
| 590 | e1000_init_rx_addrs(hw); |
| 591 | |
| 592 | /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 593 | if (hw->mac_type == e1000_82542_rev2_0) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 594 | ew32(RCTL, 0); |
| 595 | E1000_WRITE_FLUSH(); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 596 | msleep(1); |
| 597 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | e1000_pci_set_mwi(hw); |
| 599 | } |
| 600 | |
| 601 | /* Zero out the Multicast HASH table */ |
| 602 | DEBUGOUT("Zeroing the MTA\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 603 | mta_size = E1000_MC_TBL_SIZE; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 604 | for (i = 0; i < mta_size; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 606 | /* use write flush to prevent Memory Write Block (MWB) from |
| 607 | * occuring when accessing our register space */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 608 | E1000_WRITE_FLUSH(); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 609 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
| 611 | /* Set the PCI priority bit correctly in the CTRL register. This |
| 612 | * determines if the adapter gives priority to receives, or if it |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 613 | * gives equal priority to transmits and receives. Valid only on |
| 614 | * 82542 and 82543 silicon. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 616 | if (hw->dma_fairness && hw->mac_type <= e1000_82543) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 617 | ctrl = er32(CTRL); |
| 618 | ew32(CTRL, ctrl | E1000_CTRL_PRIOR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 621 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | case e1000_82545_rev_3: |
| 623 | case e1000_82546_rev_3: |
| 624 | break; |
| 625 | default: |
| 626 | /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */ |
Peter Oruba | 007755e | 2007-09-28 22:42:06 -0700 | [diff] [blame] | 627 | if (hw->bus_type == e1000_bus_type_pcix && e1000_pcix_get_mmrbc(hw) > 2048) |
| 628 | e1000_pcix_set_mmrbc(hw, 2048); |
| 629 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | /* Call a subroutine to configure the link and setup flow control. */ |
| 633 | ret_val = e1000_setup_link(hw); |
| 634 | |
| 635 | /* Set the transmit descriptor write-back policy */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 636 | if (hw->mac_type > e1000_82544) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 637 | ctrl = er32(TXDCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 639 | ew32(TXDCTL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | /* Clear all of the statistics registers (clear on read). It is |
| 643 | * important that we do this after we have tried to establish link |
| 644 | * because the symbol error count will increment wildly if there |
| 645 | * is no link. |
| 646 | */ |
| 647 | e1000_clear_hw_cntrs(hw); |
| 648 | |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 649 | if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER || |
| 650 | hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 651 | ctrl_ext = er32(CTRL_EXT); |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 652 | /* Relaxed ordering must be disabled to avoid a parity |
| 653 | * error crash in a PCI slot. */ |
| 654 | ctrl_ext |= E1000_CTRL_EXT_RO_DIS; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 655 | ew32(CTRL_EXT, ctrl_ext); |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 656 | } |
| 657 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | return ret_val; |
| 659 | } |
| 660 | |
| 661 | /****************************************************************************** |
| 662 | * Adjust SERDES output amplitude based on EEPROM setting. |
| 663 | * |
| 664 | * hw - Struct containing variables accessed by shared code. |
| 665 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 666 | static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 668 | u16 eeprom_data; |
| 669 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
| 671 | DEBUGFUNC("e1000_adjust_serdes_amplitude"); |
| 672 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 673 | if (hw->media_type != e1000_media_type_internal_serdes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | return E1000_SUCCESS; |
| 675 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 676 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | case e1000_82545_rev_3: |
| 678 | case e1000_82546_rev_3: |
| 679 | break; |
| 680 | default: |
| 681 | return E1000_SUCCESS; |
| 682 | } |
| 683 | |
| 684 | ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data); |
| 685 | if (ret_val) { |
| 686 | return ret_val; |
| 687 | } |
| 688 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 689 | if (eeprom_data != EEPROM_RESERVED_WORD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | /* Adjust SERDES output amplitude only. */ |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 691 | eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 693 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | return ret_val; |
| 695 | } |
| 696 | |
| 697 | return E1000_SUCCESS; |
| 698 | } |
| 699 | |
| 700 | /****************************************************************************** |
| 701 | * Configures flow control and link settings. |
| 702 | * |
| 703 | * hw - Struct containing variables accessed by shared code |
| 704 | * |
| 705 | * Determines which flow control settings to use. Calls the apropriate media- |
| 706 | * specific link configuration function. Configures the flow control settings. |
| 707 | * Assuming the adapter has a valid link partner, a valid link should be |
| 708 | * established. Assumes the hardware has previously been reset and the |
| 709 | * transmitter and receiver are not enabled. |
| 710 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 711 | s32 e1000_setup_link(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 713 | u32 ctrl_ext; |
| 714 | s32 ret_val; |
| 715 | u16 eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
| 717 | DEBUGFUNC("e1000_setup_link"); |
| 718 | |
| 719 | /* Read and store word 0x0F of the EEPROM. This word contains bits |
| 720 | * that determine the hardware's default PAUSE (flow control) mode, |
| 721 | * a bit that determines whether the HW defaults to enabling or |
| 722 | * disabling auto-negotiation, and the direction of the |
| 723 | * SW defined pins. If there is no SW over-ride of the flow |
| 724 | * control setting, then the variable hw->fc will |
| 725 | * be initialized based on a value in the EEPROM. |
| 726 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 727 | if (hw->fc == E1000_FC_DEFAULT) { |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 728 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, |
| 729 | 1, &eeprom_data); |
| 730 | if (ret_val) { |
| 731 | DEBUGOUT("EEPROM Read Error\n"); |
| 732 | return -E1000_ERR_EEPROM; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 733 | } |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 734 | if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0) |
| 735 | hw->fc = E1000_FC_NONE; |
| 736 | else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == |
| 737 | EEPROM_WORD0F_ASM_DIR) |
| 738 | hw->fc = E1000_FC_TX_PAUSE; |
| 739 | else |
| 740 | hw->fc = E1000_FC_FULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | /* We want to save off the original Flow Control configuration just |
| 744 | * in case we get disconnected and then reconnected into a different |
| 745 | * hub or switch with different Flow Control capabilities. |
| 746 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 747 | if (hw->mac_type == e1000_82542_rev2_0) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 748 | hw->fc &= (~E1000_FC_TX_PAUSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 750 | if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1)) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 751 | hw->fc &= (~E1000_FC_RX_PAUSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
| 753 | hw->original_fc = hw->fc; |
| 754 | |
| 755 | DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc); |
| 756 | |
| 757 | /* Take the 4 bits from EEPROM word 0x0F that determine the initial |
| 758 | * polarity value for the SW controlled pins, and setup the |
| 759 | * Extended Device Control reg with that info. |
| 760 | * This is needed because one of the SW controlled pins is used for |
| 761 | * signal detection. So this should be done before e1000_setup_pcs_link() |
| 762 | * or e1000_phy_setup() is called. |
| 763 | */ |
Jeff Kirsher | 497fce5 | 2006-03-02 18:18:20 -0800 | [diff] [blame] | 764 | if (hw->mac_type == e1000_82543) { |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 765 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, |
| 766 | 1, &eeprom_data); |
| 767 | if (ret_val) { |
| 768 | DEBUGOUT("EEPROM Read Error\n"); |
| 769 | return -E1000_ERR_EEPROM; |
| 770 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) << |
| 772 | SWDPIO__EXT_SHIFT); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 773 | ew32(CTRL_EXT, ctrl_ext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | /* Call the necessary subroutine to configure the link. */ |
| 777 | ret_val = (hw->media_type == e1000_media_type_copper) ? |
| 778 | e1000_setup_copper_link(hw) : |
| 779 | e1000_setup_fiber_serdes_link(hw); |
| 780 | |
| 781 | /* Initialize the flow control address, type, and PAUSE timer |
| 782 | * registers to their default values. This is done even if flow |
| 783 | * control is disabled, because it does not hurt anything to |
| 784 | * initialize these registers. |
| 785 | */ |
| 786 | DEBUGOUT("Initializing the Flow Control address, type and timer regs\n"); |
| 787 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 788 | ew32(FCT, FLOW_CONTROL_TYPE); |
| 789 | ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH); |
| 790 | ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 791 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 792 | ew32(FCTTV, hw->fc_pause_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
| 794 | /* Set the flow control receive threshold registers. Normally, |
| 795 | * these registers will be set to a default threshold that may be |
| 796 | * adjusted later by the driver's runtime code. However, if the |
| 797 | * ability to transmit pause frames in not enabled, then these |
| 798 | * registers will be set to 0. |
| 799 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 800 | if (!(hw->fc & E1000_FC_TX_PAUSE)) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 801 | ew32(FCRTL, 0); |
| 802 | ew32(FCRTH, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | } else { |
| 804 | /* We need to set up the Receive Threshold high and low water marks |
| 805 | * as well as (optionally) enabling the transmission of XON frames. |
| 806 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 807 | if (hw->fc_send_xon) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 808 | ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE)); |
| 809 | ew32(FCRTH, hw->fc_high_water); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } else { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 811 | ew32(FCRTL, hw->fc_low_water); |
| 812 | ew32(FCRTH, hw->fc_high_water); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | } |
| 814 | } |
| 815 | return ret_val; |
| 816 | } |
| 817 | |
| 818 | /****************************************************************************** |
| 819 | * Sets up link for a fiber based or serdes based adapter |
| 820 | * |
| 821 | * hw - Struct containing variables accessed by shared code |
| 822 | * |
| 823 | * Manipulates Physical Coding Sublayer functions in order to configure |
| 824 | * link. Assumes the hardware has been previously reset and the transmitter |
| 825 | * and receiver are not enabled. |
| 826 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 827 | static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 829 | u32 ctrl; |
| 830 | u32 status; |
| 831 | u32 txcw = 0; |
| 832 | u32 i; |
| 833 | u32 signal = 0; |
| 834 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
| 836 | DEBUGFUNC("e1000_setup_fiber_serdes_link"); |
| 837 | |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 838 | /* On adapters with a MAC newer than 82544, SWDP 1 will be |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | * set when the optics detect a signal. On older adapters, it will be |
| 840 | * cleared when there is a signal. This applies to fiber media only. |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 841 | * If we're on serdes media, adjust the output amplitude to value |
| 842 | * set in the EEPROM. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 844 | ctrl = er32(CTRL); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 845 | if (hw->media_type == e1000_media_type_fiber) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; |
| 847 | |
| 848 | ret_val = e1000_adjust_serdes_amplitude(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 849 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | return ret_val; |
| 851 | |
| 852 | /* Take the link out of reset */ |
| 853 | ctrl &= ~(E1000_CTRL_LRST); |
| 854 | |
| 855 | /* Adjust VCO speed to improve BER performance */ |
| 856 | ret_val = e1000_set_vco_speed(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 857 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | return ret_val; |
| 859 | |
| 860 | e1000_config_collision_dist(hw); |
| 861 | |
| 862 | /* Check for a software override of the flow control settings, and setup |
| 863 | * the device accordingly. If auto-negotiation is enabled, then software |
| 864 | * will have to set the "PAUSE" bits to the correct value in the Tranmsit |
| 865 | * Config Word Register (TXCW) and re-start auto-negotiation. However, if |
| 866 | * auto-negotiation is disabled, then software will have to manually |
| 867 | * configure the two flow control enable bits in the CTRL register. |
| 868 | * |
| 869 | * The possible values of the "fc" parameter are: |
| 870 | * 0: Flow control is completely disabled |
| 871 | * 1: Rx flow control is enabled (we can receive pause frames, but |
| 872 | * not send pause frames). |
| 873 | * 2: Tx flow control is enabled (we can send pause frames but we do |
| 874 | * not support receiving pause frames). |
| 875 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
| 876 | */ |
| 877 | switch (hw->fc) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 878 | case E1000_FC_NONE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | /* Flow control is completely disabled by a software over-ride. */ |
| 880 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); |
| 881 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 882 | case E1000_FC_RX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | /* RX Flow control is enabled and TX Flow control is disabled by a |
| 884 | * software over-ride. Since there really isn't a way to advertise |
| 885 | * that we are capable of RX Pause ONLY, we will advertise that we |
| 886 | * support both symmetric and asymmetric RX PAUSE. Later, we will |
| 887 | * disable the adapter's ability to send PAUSE frames. |
| 888 | */ |
| 889 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 890 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 891 | case E1000_FC_TX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | /* TX Flow control is enabled, and RX Flow control is disabled, by a |
| 893 | * software over-ride. |
| 894 | */ |
| 895 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); |
| 896 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 897 | case E1000_FC_FULL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | /* Flow control (both RX and TX) is enabled by a software over-ride. */ |
| 899 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 900 | break; |
| 901 | default: |
| 902 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 903 | return -E1000_ERR_CONFIG; |
| 904 | break; |
| 905 | } |
| 906 | |
| 907 | /* Since auto-negotiation is enabled, take the link out of reset (the link |
| 908 | * will be in reset, because we previously reset the chip). This will |
| 909 | * restart auto-negotiation. If auto-neogtiation is successful then the |
| 910 | * link-up status bit will be set and the flow control enable bits (RFCE |
| 911 | * and TFCE) will be set according to their negotiated value. |
| 912 | */ |
| 913 | DEBUGOUT("Auto-negotiation enabled\n"); |
| 914 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 915 | ew32(TXCW, txcw); |
| 916 | ew32(CTRL, ctrl); |
| 917 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
| 919 | hw->txcw = txcw; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 920 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
| 922 | /* If we have a signal (the cable is plugged in) then poll for a "Link-Up" |
| 923 | * indication in the Device Status Register. Time-out if a link isn't |
| 924 | * seen in 500 milliseconds seconds (Auto-negotiation should complete in |
| 925 | * less than 500 milliseconds even if the other end is doing it in SW). |
| 926 | * For internal serdes, we just assume a signal is present, then poll. |
| 927 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 928 | if (hw->media_type == e1000_media_type_internal_serdes || |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 929 | (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | DEBUGOUT("Looking for Link\n"); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 931 | for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) { |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 932 | msleep(10); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 933 | status = er32(STATUS); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 934 | if (status & E1000_STATUS_LU) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 936 | if (i == (LINK_UP_TIMEOUT / 10)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | DEBUGOUT("Never got a valid link from auto-neg!!!\n"); |
| 938 | hw->autoneg_failed = 1; |
| 939 | /* AutoNeg failed to achieve a link, so we'll call |
| 940 | * e1000_check_for_link. This routine will force the link up if |
| 941 | * we detect a signal. This will allow us to communicate with |
| 942 | * non-autonegotiating link partners. |
| 943 | */ |
| 944 | ret_val = e1000_check_for_link(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 945 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | DEBUGOUT("Error while checking for link\n"); |
| 947 | return ret_val; |
| 948 | } |
| 949 | hw->autoneg_failed = 0; |
| 950 | } else { |
| 951 | hw->autoneg_failed = 0; |
| 952 | DEBUGOUT("Valid Link Found\n"); |
| 953 | } |
| 954 | } else { |
| 955 | DEBUGOUT("No Signal Detected\n"); |
| 956 | } |
| 957 | return E1000_SUCCESS; |
| 958 | } |
| 959 | |
| 960 | /****************************************************************************** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 961 | * Make sure we have a valid PHY and change PHY mode before link setup. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | * |
| 963 | * hw - Struct containing variables accessed by shared code |
| 964 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 965 | static s32 e1000_copper_link_preconfig(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 967 | u32 ctrl; |
| 968 | s32 ret_val; |
| 969 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 971 | DEBUGFUNC("e1000_copper_link_preconfig"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 973 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | /* With 82543, we need to force speed and duplex on the MAC equal to what |
| 975 | * the PHY speed and duplex configuration is. In addition, we need to |
| 976 | * perform a hardware reset on the PHY to take it out of reset. |
| 977 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 978 | if (hw->mac_type > e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | ctrl |= E1000_CTRL_SLU; |
| 980 | ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 981 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | } else { |
| 983 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 984 | ew32(CTRL, ctrl); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 985 | ret_val = e1000_phy_hw_reset(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 986 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 987 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | /* Make sure we have a valid PHY */ |
| 991 | ret_val = e1000_detect_gig_phy(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 992 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | DEBUGOUT("Error, did not detect valid phy.\n"); |
| 994 | return ret_val; |
| 995 | } |
| 996 | DEBUGOUT1("Phy ID = %x \n", hw->phy_id); |
| 997 | |
| 998 | /* Set PHY to class A mode (if necessary) */ |
| 999 | ret_val = e1000_set_phy_mode(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1000 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | return ret_val; |
| 1002 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1003 | if ((hw->mac_type == e1000_82545_rev_3) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | (hw->mac_type == e1000_82546_rev_3)) { |
| 1005 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 1006 | phy_data |= 0x00000008; |
| 1007 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 1008 | } |
| 1009 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1010 | if (hw->mac_type <= e1000_82543 || |
| 1011 | hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 || |
| 1012 | hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1013 | hw->phy_reset_disable = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1015 | return E1000_SUCCESS; |
| 1016 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1019 | /******************************************************************** |
| 1020 | * Copper link setup for e1000_phy_igp series. |
| 1021 | * |
| 1022 | * hw - Struct containing variables accessed by shared code |
| 1023 | *********************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1024 | static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1025 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1026 | u32 led_ctrl; |
| 1027 | s32 ret_val; |
| 1028 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1030 | DEBUGFUNC("e1000_copper_link_igp_setup"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1032 | if (hw->phy_reset_disable) |
| 1033 | return E1000_SUCCESS; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1034 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1035 | ret_val = e1000_phy_reset(hw); |
| 1036 | if (ret_val) { |
| 1037 | DEBUGOUT("Error Resetting the PHY\n"); |
| 1038 | return ret_val; |
| 1039 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1041 | /* Wait 15ms for MAC to configure PHY from eeprom settings */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1042 | msleep(15); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1043 | /* Configure activity LED after PHY reset */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1044 | led_ctrl = er32(LEDCTL); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1045 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 1046 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1047 | ew32(LEDCTL, led_ctrl); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1048 | |
Jeff Kirsher | c9c1b83 | 2006-08-16 13:38:54 -0700 | [diff] [blame] | 1049 | /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */ |
| 1050 | if (hw->phy_type == e1000_phy_igp) { |
| 1051 | /* disable lplu d3 during driver init */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1052 | ret_val = e1000_set_d3_lplu_state(hw, false); |
Jeff Kirsher | c9c1b83 | 2006-08-16 13:38:54 -0700 | [diff] [blame] | 1053 | if (ret_val) { |
| 1054 | DEBUGOUT("Error Disabling LPLU D3\n"); |
| 1055 | return ret_val; |
| 1056 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1059 | /* Configure mdi-mdix settings */ |
| 1060 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); |
| 1061 | if (ret_val) |
| 1062 | return ret_val; |
| 1063 | |
| 1064 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 1065 | hw->dsp_config_state = e1000_dsp_config_disabled; |
| 1066 | /* Force MDI for earlier revs of the IGP PHY */ |
| 1067 | phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX); |
| 1068 | hw->mdix = 1; |
| 1069 | |
| 1070 | } else { |
| 1071 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 1072 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 1073 | |
| 1074 | switch (hw->mdix) { |
| 1075 | case 1: |
| 1076 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 1077 | break; |
| 1078 | case 2: |
| 1079 | phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 1080 | break; |
| 1081 | case 0: |
| 1082 | default: |
| 1083 | phy_data |= IGP01E1000_PSCR_AUTO_MDIX; |
| 1084 | break; |
| 1085 | } |
| 1086 | } |
| 1087 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1088 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1089 | return ret_val; |
| 1090 | |
| 1091 | /* set auto-master slave resolution settings */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1092 | if (hw->autoneg) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1093 | e1000_ms_type phy_ms_setting = hw->master_slave; |
| 1094 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1095 | if (hw->ffe_config_state == e1000_ffe_config_active) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1096 | hw->ffe_config_state = e1000_ffe_config_enabled; |
| 1097 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1098 | if (hw->dsp_config_state == e1000_dsp_config_activated) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1099 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 1100 | |
| 1101 | /* when autonegotiation advertisment is only 1000Mbps then we |
| 1102 | * should disable SmartSpeed and enable Auto MasterSlave |
| 1103 | * resolution as hardware default. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1104 | if (hw->autoneg_advertised == ADVERTISE_1000_FULL) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1105 | /* Disable SmartSpeed */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1106 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 1107 | &phy_data); |
| 1108 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1110 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1111 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 1112 | phy_data); |
| 1113 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1115 | /* Set auto Master/Slave resolution process */ |
| 1116 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1117 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1118 | return ret_val; |
| 1119 | phy_data &= ~CR_1000T_MS_ENABLE; |
| 1120 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1121 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1122 | return ret_val; |
| 1123 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1125 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1126 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1127 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1129 | /* load defaults for future use */ |
| 1130 | hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ? |
| 1131 | ((phy_data & CR_1000T_MS_VALUE) ? |
| 1132 | e1000_ms_force_master : |
| 1133 | e1000_ms_force_slave) : |
| 1134 | e1000_ms_auto; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1136 | switch (phy_ms_setting) { |
| 1137 | case e1000_ms_force_master: |
| 1138 | phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE); |
| 1139 | break; |
| 1140 | case e1000_ms_force_slave: |
| 1141 | phy_data |= CR_1000T_MS_ENABLE; |
| 1142 | phy_data &= ~(CR_1000T_MS_VALUE); |
| 1143 | break; |
| 1144 | case e1000_ms_auto: |
| 1145 | phy_data &= ~CR_1000T_MS_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | default: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1147 | break; |
| 1148 | } |
| 1149 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1150 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1151 | return ret_val; |
Malli Chilakala | 2b02893 | 2005-06-17 17:46:06 -0700 | [diff] [blame] | 1152 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | |
Malli Chilakala | 2b02893 | 2005-06-17 17:46:06 -0700 | [diff] [blame] | 1154 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1155 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1157 | /******************************************************************** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1158 | * Copper link setup for e1000_phy_m88 series. |
| 1159 | * |
| 1160 | * hw - Struct containing variables accessed by shared code |
| 1161 | *********************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1162 | static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1163 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1164 | s32 ret_val; |
| 1165 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1167 | DEBUGFUNC("e1000_copper_link_mgp_setup"); |
| 1168 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1169 | if (hw->phy_reset_disable) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1170 | return E1000_SUCCESS; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1171 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1172 | /* Enable CRS on TX. This must be set for half-duplex operation. */ |
| 1173 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1174 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1175 | return ret_val; |
| 1176 | |
| 1177 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 1178 | |
| 1179 | /* Options: |
| 1180 | * MDI/MDI-X = 0 (default) |
| 1181 | * 0 - Auto for all speeds |
| 1182 | * 1 - MDI mode |
| 1183 | * 2 - MDI-X mode |
| 1184 | * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) |
| 1185 | */ |
| 1186 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 1187 | |
| 1188 | switch (hw->mdix) { |
| 1189 | case 1: |
| 1190 | phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE; |
| 1191 | break; |
| 1192 | case 2: |
| 1193 | phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE; |
| 1194 | break; |
| 1195 | case 3: |
| 1196 | phy_data |= M88E1000_PSCR_AUTO_X_1000T; |
| 1197 | break; |
| 1198 | case 0: |
| 1199 | default: |
| 1200 | phy_data |= M88E1000_PSCR_AUTO_X_MODE; |
| 1201 | break; |
| 1202 | } |
| 1203 | |
| 1204 | /* Options: |
| 1205 | * disable_polarity_correction = 0 (default) |
| 1206 | * Automatic Correction for Reversed Cable Polarity |
| 1207 | * 0 - Disabled |
| 1208 | * 1 - Enabled |
| 1209 | */ |
| 1210 | phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1211 | if (hw->disable_polarity_correction == 1) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1212 | phy_data |= M88E1000_PSCR_POLARITY_REVERSAL; |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1213 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 1214 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1215 | return ret_val; |
| 1216 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1217 | if (hw->phy_revision < M88E1011_I_REV_4) { |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1218 | /* Force TX_CLK in the Extended PHY Specific Control Register |
| 1219 | * to 25MHz clock. |
| 1220 | */ |
| 1221 | ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data); |
| 1222 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1223 | return ret_val; |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1224 | |
| 1225 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
| 1226 | |
| 1227 | if ((hw->phy_revision == E1000_REVISION_2) && |
| 1228 | (hw->phy_id == M88E1111_I_PHY_ID)) { |
| 1229 | /* Vidalia Phy, set the downshift counter to 5x */ |
| 1230 | phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK); |
| 1231 | phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X; |
| 1232 | ret_val = e1000_write_phy_reg(hw, |
| 1233 | M88E1000_EXT_PHY_SPEC_CTRL, phy_data); |
| 1234 | if (ret_val) |
| 1235 | return ret_val; |
| 1236 | } else { |
| 1237 | /* Configure Master and Slave downshift values */ |
| 1238 | phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK | |
| 1239 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK); |
| 1240 | phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X | |
| 1241 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X); |
| 1242 | ret_val = e1000_write_phy_reg(hw, |
| 1243 | M88E1000_EXT_PHY_SPEC_CTRL, phy_data); |
| 1244 | if (ret_val) |
| 1245 | return ret_val; |
| 1246 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1249 | /* SW Reset the PHY so all changes take effect */ |
| 1250 | ret_val = e1000_phy_reset(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1251 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1252 | DEBUGOUT("Error Resetting the PHY\n"); |
| 1253 | return ret_val; |
| 1254 | } |
| 1255 | |
| 1256 | return E1000_SUCCESS; |
| 1257 | } |
| 1258 | |
| 1259 | /******************************************************************** |
| 1260 | * Setup auto-negotiation and flow control advertisements, |
| 1261 | * and then perform auto-negotiation. |
| 1262 | * |
| 1263 | * hw - Struct containing variables accessed by shared code |
| 1264 | *********************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1265 | static s32 e1000_copper_link_autoneg(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1266 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1267 | s32 ret_val; |
| 1268 | u16 phy_data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1269 | |
| 1270 | DEBUGFUNC("e1000_copper_link_autoneg"); |
| 1271 | |
| 1272 | /* Perform some bounds checking on the hw->autoneg_advertised |
| 1273 | * parameter. If this variable is zero, then set it to the default. |
| 1274 | */ |
| 1275 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT; |
| 1276 | |
| 1277 | /* If autoneg_advertised is zero, we assume it was not defaulted |
| 1278 | * by the calling code so we set to advertise full capability. |
| 1279 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1280 | if (hw->autoneg_advertised == 0) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1281 | hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT; |
| 1282 | |
| 1283 | DEBUGOUT("Reconfiguring auto-neg advertisement params\n"); |
| 1284 | ret_val = e1000_phy_setup_autoneg(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1285 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1286 | DEBUGOUT("Error Setting up Auto-Negotiation\n"); |
| 1287 | return ret_val; |
| 1288 | } |
| 1289 | DEBUGOUT("Restarting Auto-Neg\n"); |
| 1290 | |
| 1291 | /* Restart auto-negotiation by setting the Auto Neg Enable bit and |
| 1292 | * the Auto Neg Restart bit in the PHY control register. |
| 1293 | */ |
| 1294 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1295 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1296 | return ret_val; |
| 1297 | |
| 1298 | phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); |
| 1299 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1300 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1301 | return ret_val; |
| 1302 | |
| 1303 | /* Does the user want to wait for Auto-Neg to complete here, or |
| 1304 | * check at a later time (for example, callback routine). |
| 1305 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1306 | if (hw->wait_autoneg_complete) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1307 | ret_val = e1000_wait_autoneg(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1308 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1309 | DEBUGOUT("Error while waiting for autoneg to complete\n"); |
| 1310 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1312 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1314 | hw->get_link_status = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1316 | return E1000_SUCCESS; |
| 1317 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1319 | /****************************************************************************** |
| 1320 | * Config the MAC and the PHY after link is up. |
| 1321 | * 1) Set up the MAC to the current PHY speed/duplex |
| 1322 | * if we are on 82543. If we |
| 1323 | * are on newer silicon, we only need to configure |
| 1324 | * collision distance in the Transmit Control Register. |
| 1325 | * 2) Set up flow control on the MAC to that established with |
| 1326 | * the link partner. |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1327 | * 3) Config DSP to improve Gigabit link quality for some PHY revisions. |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1328 | * |
| 1329 | * hw - Struct containing variables accessed by shared code |
| 1330 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1331 | static s32 e1000_copper_link_postconfig(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1332 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1333 | s32 ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1334 | DEBUGFUNC("e1000_copper_link_postconfig"); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1335 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1336 | if (hw->mac_type >= e1000_82544) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1337 | e1000_config_collision_dist(hw); |
| 1338 | } else { |
| 1339 | ret_val = e1000_config_mac_to_phy(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1340 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1341 | DEBUGOUT("Error configuring MAC to PHY settings\n"); |
| 1342 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1344 | } |
| 1345 | ret_val = e1000_config_fc_after_link_up(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1346 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1347 | DEBUGOUT("Error Configuring Flow Control\n"); |
| 1348 | return ret_val; |
| 1349 | } |
| 1350 | |
| 1351 | /* Config DSP to improve Giga link quality */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1352 | if (hw->phy_type == e1000_phy_igp) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1353 | ret_val = e1000_config_dsp_after_link_change(hw, true); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1354 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1355 | DEBUGOUT("Error Configuring DSP after link up\n"); |
| 1356 | return ret_val; |
| 1357 | } |
| 1358 | } |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1359 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1360 | return E1000_SUCCESS; |
| 1361 | } |
| 1362 | |
| 1363 | /****************************************************************************** |
| 1364 | * Detects which PHY is present and setup the speed and duplex |
| 1365 | * |
| 1366 | * hw - Struct containing variables accessed by shared code |
| 1367 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1368 | static s32 e1000_setup_copper_link(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1369 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1370 | s32 ret_val; |
| 1371 | u16 i; |
| 1372 | u16 phy_data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1373 | |
| 1374 | DEBUGFUNC("e1000_setup_copper_link"); |
| 1375 | |
| 1376 | /* Check if it is a valid PHY and set PHY mode if necessary. */ |
| 1377 | ret_val = e1000_copper_link_preconfig(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1378 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1379 | return ret_val; |
| 1380 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 1381 | if (hw->phy_type == e1000_phy_igp) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1382 | ret_val = e1000_copper_link_igp_setup(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1383 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1384 | return ret_val; |
| 1385 | } else if (hw->phy_type == e1000_phy_m88) { |
| 1386 | ret_val = e1000_copper_link_mgp_setup(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1387 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1388 | return ret_val; |
| 1389 | } |
| 1390 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1391 | if (hw->autoneg) { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1392 | /* Setup autoneg and flow control advertisement |
| 1393 | * and perform autonegotiation */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1394 | ret_val = e1000_copper_link_autoneg(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1395 | if (ret_val) |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1396 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1397 | } else { |
| 1398 | /* PHY will be set to 10H, 10F, 100H,or 100F |
| 1399 | * depending on value from forced_speed_duplex. */ |
| 1400 | DEBUGOUT("Forcing speed and duplex\n"); |
| 1401 | ret_val = e1000_phy_force_speed_duplex(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1402 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1403 | DEBUGOUT("Error Forcing Speed and Duplex\n"); |
| 1404 | return ret_val; |
| 1405 | } |
| 1406 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | |
| 1408 | /* Check link status. Wait up to 100 microseconds for link to become |
| 1409 | * valid. |
| 1410 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1411 | for (i = 0; i < 10; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1413 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | return ret_val; |
| 1415 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1416 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | return ret_val; |
| 1418 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1419 | if (phy_data & MII_SR_LINK_STATUS) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1420 | /* Config the MAC and PHY after link is up */ |
| 1421 | ret_val = e1000_copper_link_postconfig(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1422 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | return ret_val; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | DEBUGOUT("Valid link established!!!\n"); |
| 1426 | return E1000_SUCCESS; |
| 1427 | } |
| 1428 | udelay(10); |
| 1429 | } |
| 1430 | |
| 1431 | DEBUGOUT("Unable to establish link!!!\n"); |
| 1432 | return E1000_SUCCESS; |
| 1433 | } |
| 1434 | |
| 1435 | /****************************************************************************** |
| 1436 | * Configures PHY autoneg and flow control advertisement settings |
| 1437 | * |
| 1438 | * hw - Struct containing variables accessed by shared code |
| 1439 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1440 | s32 e1000_phy_setup_autoneg(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1442 | s32 ret_val; |
| 1443 | u16 mii_autoneg_adv_reg; |
| 1444 | u16 mii_1000t_ctrl_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | |
| 1446 | DEBUGFUNC("e1000_phy_setup_autoneg"); |
| 1447 | |
| 1448 | /* Read the MII Auto-Neg Advertisement Register (Address 4). */ |
| 1449 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1450 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | return ret_val; |
| 1452 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 1453 | /* Read the MII 1000Base-T Control Register (Address 9). */ |
| 1454 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg); |
| 1455 | if (ret_val) |
| 1456 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | |
| 1458 | /* Need to parse both autoneg_advertised and fc and set up |
| 1459 | * the appropriate PHY registers. First we will parse for |
| 1460 | * autoneg_advertised software override. Since we can advertise |
| 1461 | * a plethora of combinations, we need to check each bit |
| 1462 | * individually. |
| 1463 | */ |
| 1464 | |
| 1465 | /* First we clear all the 10/100 mb speed bits in the Auto-Neg |
| 1466 | * Advertisement Register (Address 4) and the 1000 mb speed bits in |
| 1467 | * the 1000Base-T Control Register (Address 9). |
| 1468 | */ |
| 1469 | mii_autoneg_adv_reg &= ~REG4_SPEED_MASK; |
| 1470 | mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK; |
| 1471 | |
| 1472 | DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised); |
| 1473 | |
| 1474 | /* Do we want to advertise 10 Mb Half Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1475 | if (hw->autoneg_advertised & ADVERTISE_10_HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | DEBUGOUT("Advertise 10mb Half duplex\n"); |
| 1477 | mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS; |
| 1478 | } |
| 1479 | |
| 1480 | /* Do we want to advertise 10 Mb Full Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1481 | if (hw->autoneg_advertised & ADVERTISE_10_FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | DEBUGOUT("Advertise 10mb Full duplex\n"); |
| 1483 | mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS; |
| 1484 | } |
| 1485 | |
| 1486 | /* Do we want to advertise 100 Mb Half Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1487 | if (hw->autoneg_advertised & ADVERTISE_100_HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | DEBUGOUT("Advertise 100mb Half duplex\n"); |
| 1489 | mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS; |
| 1490 | } |
| 1491 | |
| 1492 | /* Do we want to advertise 100 Mb Full Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1493 | if (hw->autoneg_advertised & ADVERTISE_100_FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | DEBUGOUT("Advertise 100mb Full duplex\n"); |
| 1495 | mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS; |
| 1496 | } |
| 1497 | |
| 1498 | /* We do not allow the Phy to advertise 1000 Mb Half Duplex */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1499 | if (hw->autoneg_advertised & ADVERTISE_1000_HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n"); |
| 1501 | } |
| 1502 | |
| 1503 | /* Do we want to advertise 1000 Mb Full Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1504 | if (hw->autoneg_advertised & ADVERTISE_1000_FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | DEBUGOUT("Advertise 1000mb Full duplex\n"); |
| 1506 | mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS; |
| 1507 | } |
| 1508 | |
| 1509 | /* Check for a software override of the flow control settings, and |
| 1510 | * setup the PHY advertisement registers accordingly. If |
| 1511 | * auto-negotiation is enabled, then software will have to set the |
| 1512 | * "PAUSE" bits to the correct value in the Auto-Negotiation |
| 1513 | * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation. |
| 1514 | * |
| 1515 | * The possible values of the "fc" parameter are: |
| 1516 | * 0: Flow control is completely disabled |
| 1517 | * 1: Rx flow control is enabled (we can receive pause frames |
| 1518 | * but not send pause frames). |
| 1519 | * 2: Tx flow control is enabled (we can send pause frames |
| 1520 | * but we do not support receiving pause frames). |
| 1521 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
| 1522 | * other: No software override. The flow control configuration |
| 1523 | * in the EEPROM is used. |
| 1524 | */ |
| 1525 | switch (hw->fc) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1526 | case E1000_FC_NONE: /* 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | /* Flow control (RX & TX) is completely disabled by a |
| 1528 | * software over-ride. |
| 1529 | */ |
| 1530 | mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 1531 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1532 | case E1000_FC_RX_PAUSE: /* 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | /* RX Flow control is enabled, and TX Flow control is |
| 1534 | * disabled, by a software over-ride. |
| 1535 | */ |
| 1536 | /* Since there really isn't a way to advertise that we are |
| 1537 | * capable of RX Pause ONLY, we will advertise that we |
| 1538 | * support both symmetric and asymmetric RX PAUSE. Later |
| 1539 | * (in e1000_config_fc_after_link_up) we will disable the |
| 1540 | *hw's ability to send PAUSE frames. |
| 1541 | */ |
| 1542 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 1543 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1544 | case E1000_FC_TX_PAUSE: /* 2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | /* TX Flow control is enabled, and RX Flow control is |
| 1546 | * disabled, by a software over-ride. |
| 1547 | */ |
| 1548 | mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR; |
| 1549 | mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE; |
| 1550 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1551 | case E1000_FC_FULL: /* 3 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | /* Flow control (both RX and TX) is enabled by a software |
| 1553 | * over-ride. |
| 1554 | */ |
| 1555 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 1556 | break; |
| 1557 | default: |
| 1558 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 1559 | return -E1000_ERR_CONFIG; |
| 1560 | } |
| 1561 | |
| 1562 | ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1563 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | return ret_val; |
| 1565 | |
| 1566 | DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg); |
| 1567 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 1568 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg); |
| 1569 | if (ret_val) |
| 1570 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | |
| 1572 | return E1000_SUCCESS; |
| 1573 | } |
| 1574 | |
| 1575 | /****************************************************************************** |
| 1576 | * Force PHY speed and duplex settings to hw->forced_speed_duplex |
| 1577 | * |
| 1578 | * hw - Struct containing variables accessed by shared code |
| 1579 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1580 | static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1582 | u32 ctrl; |
| 1583 | s32 ret_val; |
| 1584 | u16 mii_ctrl_reg; |
| 1585 | u16 mii_status_reg; |
| 1586 | u16 phy_data; |
| 1587 | u16 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | |
| 1589 | DEBUGFUNC("e1000_phy_force_speed_duplex"); |
| 1590 | |
| 1591 | /* Turn off Flow control if we are forcing speed and duplex. */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1592 | hw->fc = E1000_FC_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | |
| 1594 | DEBUGOUT1("hw->fc = %d\n", hw->fc); |
| 1595 | |
| 1596 | /* Read the Device Control Register. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1597 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | |
| 1599 | /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */ |
| 1600 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 1601 | ctrl &= ~(DEVICE_SPEED_MASK); |
| 1602 | |
| 1603 | /* Clear the Auto Speed Detect Enable bit. */ |
| 1604 | ctrl &= ~E1000_CTRL_ASDE; |
| 1605 | |
| 1606 | /* Read the MII Control Register. */ |
| 1607 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1608 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | return ret_val; |
| 1610 | |
| 1611 | /* We need to disable autoneg in order to force link and duplex. */ |
| 1612 | |
| 1613 | mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN; |
| 1614 | |
| 1615 | /* Are we forcing Full or Half Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1616 | if (hw->forced_speed_duplex == e1000_100_full || |
| 1617 | hw->forced_speed_duplex == e1000_10_full) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | /* We want to force full duplex so we SET the full duplex bits in the |
| 1619 | * Device and MII Control Registers. |
| 1620 | */ |
| 1621 | ctrl |= E1000_CTRL_FD; |
| 1622 | mii_ctrl_reg |= MII_CR_FULL_DUPLEX; |
| 1623 | DEBUGOUT("Full Duplex\n"); |
| 1624 | } else { |
| 1625 | /* We want to force half duplex so we CLEAR the full duplex bits in |
| 1626 | * the Device and MII Control Registers. |
| 1627 | */ |
| 1628 | ctrl &= ~E1000_CTRL_FD; |
| 1629 | mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX; |
| 1630 | DEBUGOUT("Half Duplex\n"); |
| 1631 | } |
| 1632 | |
| 1633 | /* Are we forcing 100Mbps??? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1634 | if (hw->forced_speed_duplex == e1000_100_full || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | hw->forced_speed_duplex == e1000_100_half) { |
| 1636 | /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */ |
| 1637 | ctrl |= E1000_CTRL_SPD_100; |
| 1638 | mii_ctrl_reg |= MII_CR_SPEED_100; |
| 1639 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10); |
| 1640 | DEBUGOUT("Forcing 100mb "); |
| 1641 | } else { |
| 1642 | /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */ |
| 1643 | ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100); |
| 1644 | mii_ctrl_reg |= MII_CR_SPEED_10; |
| 1645 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100); |
| 1646 | DEBUGOUT("Forcing 10mb "); |
| 1647 | } |
| 1648 | |
| 1649 | e1000_config_collision_dist(hw); |
| 1650 | |
| 1651 | /* Write the configured values back to the Device Control Reg. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1652 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 1654 | if (hw->phy_type == e1000_phy_m88) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1656 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | return ret_val; |
| 1658 | |
| 1659 | /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI |
| 1660 | * forced whenever speed are duplex are forced. |
| 1661 | */ |
| 1662 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 1663 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1664 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | return ret_val; |
| 1666 | |
| 1667 | DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data); |
| 1668 | |
| 1669 | /* Need to reset the PHY or these changes will be ignored */ |
| 1670 | mii_ctrl_reg |= MII_CR_RESET; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 1671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | } else { |
| 1673 | /* Clear Auto-Crossover to force MDI manually. IGP requires MDI |
| 1674 | * forced whenever speed or duplex are forced. |
| 1675 | */ |
| 1676 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1677 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | return ret_val; |
| 1679 | |
| 1680 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 1681 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 1682 | |
| 1683 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1684 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | return ret_val; |
| 1686 | } |
| 1687 | |
| 1688 | /* Write back the modified PHY MII control register. */ |
| 1689 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1690 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | return ret_val; |
| 1692 | |
| 1693 | udelay(1); |
| 1694 | |
| 1695 | /* The wait_autoneg_complete flag may be a little misleading here. |
| 1696 | * Since we are forcing speed and duplex, Auto-Neg is not enabled. |
| 1697 | * But we do want to delay for a period while forcing only so we |
| 1698 | * don't generate false No Link messages. So we will wait here |
| 1699 | * only if the user has set wait_autoneg_complete to 1, which is |
| 1700 | * the default. |
| 1701 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1702 | if (hw->wait_autoneg_complete) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | /* We will wait for autoneg to complete. */ |
| 1704 | DEBUGOUT("Waiting for forced speed/duplex link.\n"); |
| 1705 | mii_status_reg = 0; |
| 1706 | |
| 1707 | /* We will wait for autoneg to complete or 4.5 seconds to expire. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1708 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | /* Read the MII Status Register and wait for Auto-Neg Complete bit |
| 1710 | * to be set. |
| 1711 | */ |
| 1712 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1713 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | return ret_val; |
| 1715 | |
| 1716 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1717 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | return ret_val; |
| 1719 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1720 | if (mii_status_reg & MII_SR_LINK_STATUS) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1721 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1723 | if ((i == 0) && |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 1724 | (hw->phy_type == e1000_phy_m88)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | /* We didn't get link. Reset the DSP and wait again for link. */ |
| 1726 | ret_val = e1000_phy_reset_dsp(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1727 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | DEBUGOUT("Error Resetting PHY DSP\n"); |
| 1729 | return ret_val; |
| 1730 | } |
| 1731 | } |
| 1732 | /* This loop will early-out if the link condition has been met. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1733 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
| 1734 | if (mii_status_reg & MII_SR_LINK_STATUS) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1735 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | /* Read the MII Status Register and wait for Auto-Neg Complete bit |
| 1737 | * to be set. |
| 1738 | */ |
| 1739 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1740 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | return ret_val; |
| 1742 | |
| 1743 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1744 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | return ret_val; |
| 1746 | } |
| 1747 | } |
| 1748 | |
| 1749 | if (hw->phy_type == e1000_phy_m88) { |
| 1750 | /* Because we reset the PHY above, we need to re-force TX_CLK in the |
| 1751 | * Extended PHY Specific Control Register to 25MHz clock. This value |
| 1752 | * defaults back to a 2.5MHz clock when the PHY is reset. |
| 1753 | */ |
| 1754 | ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1755 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | return ret_val; |
| 1757 | |
| 1758 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
| 1759 | ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1760 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | return ret_val; |
| 1762 | |
| 1763 | /* In addition, because of the s/w reset above, we need to enable CRS on |
| 1764 | * TX. This must be set for both full and half duplex operation. |
| 1765 | */ |
| 1766 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1767 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | return ret_val; |
| 1769 | |
| 1770 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 1771 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1772 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | return ret_val; |
| 1774 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1775 | if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) && |
| 1776 | (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full || |
| 1777 | hw->forced_speed_duplex == e1000_10_half)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | ret_val = e1000_polarity_reversal_workaround(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1779 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | return ret_val; |
| 1781 | } |
| 1782 | } |
| 1783 | return E1000_SUCCESS; |
| 1784 | } |
| 1785 | |
| 1786 | /****************************************************************************** |
| 1787 | * Sets the collision distance in the Transmit Control register |
| 1788 | * |
| 1789 | * hw - Struct containing variables accessed by shared code |
| 1790 | * |
| 1791 | * Link should have been established previously. Reads the speed and duplex |
| 1792 | * information from the Device Status register. |
| 1793 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1794 | void e1000_config_collision_dist(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1796 | u32 tctl, coll_dist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | |
| 1798 | DEBUGFUNC("e1000_config_collision_dist"); |
| 1799 | |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1800 | if (hw->mac_type < e1000_82543) |
| 1801 | coll_dist = E1000_COLLISION_DISTANCE_82542; |
| 1802 | else |
| 1803 | coll_dist = E1000_COLLISION_DISTANCE; |
| 1804 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1805 | tctl = er32(TCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | |
| 1807 | tctl &= ~E1000_TCTL_COLD; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1808 | tctl |= coll_dist << E1000_COLD_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1810 | ew32(TCTL, tctl); |
| 1811 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | /****************************************************************************** |
| 1815 | * Sets MAC speed and duplex settings to reflect the those in the PHY |
| 1816 | * |
| 1817 | * hw - Struct containing variables accessed by shared code |
| 1818 | * mii_reg - data to write to the MII control register |
| 1819 | * |
| 1820 | * The contents of the PHY register containing the needed information need to |
| 1821 | * be passed in. |
| 1822 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1823 | static s32 e1000_config_mac_to_phy(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1825 | u32 ctrl; |
| 1826 | s32 ret_val; |
| 1827 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | |
| 1829 | DEBUGFUNC("e1000_config_mac_to_phy"); |
| 1830 | |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1831 | /* 82544 or newer MAC, Auto Speed Detection takes care of |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1832 | * MAC speed/duplex configuration.*/ |
| 1833 | if (hw->mac_type >= e1000_82544) |
| 1834 | return E1000_SUCCESS; |
| 1835 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | /* Read the Device Control Register and set the bits to Force Speed |
| 1837 | * and Duplex. |
| 1838 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1839 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 1841 | ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS); |
| 1842 | |
| 1843 | /* Set up duplex in the Device Control and Transmit Control |
| 1844 | * registers depending on negotiated values. |
| 1845 | */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1846 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1847 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1848 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1850 | if (phy_data & M88E1000_PSSR_DPLX) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1851 | ctrl |= E1000_CTRL_FD; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1852 | else |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1853 | ctrl &= ~E1000_CTRL_FD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1855 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1857 | /* Set up speed in the Device Control register depending on |
| 1858 | * negotiated values. |
| 1859 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1860 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1861 | ctrl |= E1000_CTRL_SPD_1000; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1862 | else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1863 | ctrl |= E1000_CTRL_SPD_100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | /* Write the configured values back to the Device Control Reg. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1866 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | return E1000_SUCCESS; |
| 1868 | } |
| 1869 | |
| 1870 | /****************************************************************************** |
| 1871 | * Forces the MAC's flow control settings. |
| 1872 | * |
| 1873 | * hw - Struct containing variables accessed by shared code |
| 1874 | * |
| 1875 | * Sets the TFCE and RFCE bits in the device control register to reflect |
| 1876 | * the adapter settings. TFCE and RFCE need to be explicitly set by |
| 1877 | * software when a Copper PHY is used because autonegotiation is managed |
| 1878 | * by the PHY rather than the MAC. Software must also configure these |
| 1879 | * bits when link is forced on a fiber connection. |
| 1880 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1881 | s32 e1000_force_mac_fc(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1883 | u32 ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | |
| 1885 | DEBUGFUNC("e1000_force_mac_fc"); |
| 1886 | |
| 1887 | /* Get the current configuration of the Device Control Register */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1888 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | |
| 1890 | /* Because we didn't get link via the internal auto-negotiation |
| 1891 | * mechanism (we either forced link or we got link via PHY |
| 1892 | * auto-neg), we have to manually enable/disable transmit an |
| 1893 | * receive flow control. |
| 1894 | * |
| 1895 | * The "Case" statement below enables/disable flow control |
| 1896 | * according to the "hw->fc" parameter. |
| 1897 | * |
| 1898 | * The possible values of the "fc" parameter are: |
| 1899 | * 0: Flow control is completely disabled |
| 1900 | * 1: Rx flow control is enabled (we can receive pause |
| 1901 | * frames but not send pause frames). |
| 1902 | * 2: Tx flow control is enabled (we can send pause frames |
| 1903 | * frames but we do not receive pause frames). |
| 1904 | * 3: Both Rx and TX flow control (symmetric) is enabled. |
| 1905 | * other: No other values should be possible at this point. |
| 1906 | */ |
| 1907 | |
| 1908 | switch (hw->fc) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1909 | case E1000_FC_NONE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); |
| 1911 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1912 | case E1000_FC_RX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | ctrl &= (~E1000_CTRL_TFCE); |
| 1914 | ctrl |= E1000_CTRL_RFCE; |
| 1915 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1916 | case E1000_FC_TX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | ctrl &= (~E1000_CTRL_RFCE); |
| 1918 | ctrl |= E1000_CTRL_TFCE; |
| 1919 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1920 | case E1000_FC_FULL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); |
| 1922 | break; |
| 1923 | default: |
| 1924 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 1925 | return -E1000_ERR_CONFIG; |
| 1926 | } |
| 1927 | |
| 1928 | /* Disable TX Flow Control for 82542 (rev 2.0) */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1929 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | ctrl &= (~E1000_CTRL_TFCE); |
| 1931 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1932 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | return E1000_SUCCESS; |
| 1934 | } |
| 1935 | |
| 1936 | /****************************************************************************** |
| 1937 | * Configures flow control settings after link is established |
| 1938 | * |
| 1939 | * hw - Struct containing variables accessed by shared code |
| 1940 | * |
| 1941 | * Should be called immediately after a valid link has been established. |
| 1942 | * Forces MAC flow control settings if link was forced. When in MII/GMII mode |
| 1943 | * and autonegotiation is enabled, the MAC flow control settings will be set |
| 1944 | * based on the flow control negotiated by the PHY. In TBI mode, the TFCE |
| 1945 | * and RFCE bits will be automaticaly set to the negotiated flow control mode. |
| 1946 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1947 | static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1949 | s32 ret_val; |
| 1950 | u16 mii_status_reg; |
| 1951 | u16 mii_nway_adv_reg; |
| 1952 | u16 mii_nway_lp_ability_reg; |
| 1953 | u16 speed; |
| 1954 | u16 duplex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | |
| 1956 | DEBUGFUNC("e1000_config_fc_after_link_up"); |
| 1957 | |
| 1958 | /* Check for the case where we have fiber media and auto-neg failed |
| 1959 | * so we had to force link. In this case, we need to force the |
| 1960 | * configuration of the MAC to match the "fc" parameter. |
| 1961 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1962 | if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) || |
| 1963 | ((hw->media_type == e1000_media_type_internal_serdes) && |
| 1964 | (hw->autoneg_failed)) || |
| 1965 | ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | ret_val = e1000_force_mac_fc(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1967 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | DEBUGOUT("Error forcing flow control settings\n"); |
| 1969 | return ret_val; |
| 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | /* Check for the case where we have copper media and auto-neg is |
| 1974 | * enabled. In this case, we need to check and see if Auto-Neg |
| 1975 | * has completed, and if so, how the PHY and link partner has |
| 1976 | * flow control configured. |
| 1977 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1978 | if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | /* Read the MII Status Register and check to see if AutoNeg |
| 1980 | * has completed. We read this twice because this reg has |
| 1981 | * some "sticky" (latched) bits. |
| 1982 | */ |
| 1983 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1984 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | return ret_val; |
| 1986 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1987 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | return ret_val; |
| 1989 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1990 | if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | /* The AutoNeg process has completed, so we now need to |
| 1992 | * read both the Auto Negotiation Advertisement Register |
| 1993 | * (Address 4) and the Auto_Negotiation Base Page Ability |
| 1994 | * Register (Address 5) to determine how flow control was |
| 1995 | * negotiated. |
| 1996 | */ |
| 1997 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, |
| 1998 | &mii_nway_adv_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1999 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | return ret_val; |
| 2001 | ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, |
| 2002 | &mii_nway_lp_ability_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2003 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | return ret_val; |
| 2005 | |
| 2006 | /* Two bits in the Auto Negotiation Advertisement Register |
| 2007 | * (Address 4) and two bits in the Auto Negotiation Base |
| 2008 | * Page Ability Register (Address 5) determine flow control |
| 2009 | * for both the PHY and the link partner. The following |
| 2010 | * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, |
| 2011 | * 1999, describes these PAUSE resolution bits and how flow |
| 2012 | * control is determined based upon these settings. |
| 2013 | * NOTE: DC = Don't Care |
| 2014 | * |
| 2015 | * LOCAL DEVICE | LINK PARTNER |
| 2016 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution |
| 2017 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2018 | * 0 | 0 | DC | DC | E1000_FC_NONE |
| 2019 | * 0 | 1 | 0 | DC | E1000_FC_NONE |
| 2020 | * 0 | 1 | 1 | 0 | E1000_FC_NONE |
| 2021 | * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE |
| 2022 | * 1 | 0 | 0 | DC | E1000_FC_NONE |
| 2023 | * 1 | DC | 1 | DC | E1000_FC_FULL |
| 2024 | * 1 | 1 | 0 | 0 | E1000_FC_NONE |
| 2025 | * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | * |
| 2027 | */ |
| 2028 | /* Are both PAUSE bits set to 1? If so, this implies |
| 2029 | * Symmetric Flow Control is enabled at both ends. The |
| 2030 | * ASM_DIR bits are irrelevant per the spec. |
| 2031 | * |
| 2032 | * For Symmetric Flow Control: |
| 2033 | * |
| 2034 | * LOCAL DEVICE | LINK PARTNER |
| 2035 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 2036 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2037 | * 1 | DC | 1 | DC | E1000_FC_FULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | * |
| 2039 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2040 | if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2041 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | /* Now we need to check if the user selected RX ONLY |
| 2043 | * of pause frames. In this case, we had to advertise |
| 2044 | * FULL flow control because we could not advertise RX |
| 2045 | * ONLY. Hence, we must now check to see if we need to |
| 2046 | * turn OFF the TRANSMISSION of PAUSE frames. |
| 2047 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2048 | if (hw->original_fc == E1000_FC_FULL) { |
| 2049 | hw->fc = E1000_FC_FULL; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2050 | DEBUGOUT("Flow Control = FULL.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | } else { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2052 | hw->fc = E1000_FC_RX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2053 | DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | } |
| 2055 | } |
| 2056 | /* For receiving PAUSE frames ONLY. |
| 2057 | * |
| 2058 | * LOCAL DEVICE | LINK PARTNER |
| 2059 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 2060 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2061 | * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | * |
| 2063 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2064 | else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2065 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 2066 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 2067 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2068 | hw->fc = E1000_FC_TX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2069 | DEBUGOUT("Flow Control = TX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | } |
| 2071 | /* For transmitting PAUSE frames ONLY. |
| 2072 | * |
| 2073 | * LOCAL DEVICE | LINK PARTNER |
| 2074 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 2075 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2076 | * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | * |
| 2078 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2079 | else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2080 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 2081 | !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 2082 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2083 | hw->fc = E1000_FC_RX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2084 | DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | } |
| 2086 | /* Per the IEEE spec, at this point flow control should be |
| 2087 | * disabled. However, we want to consider that we could |
| 2088 | * be connected to a legacy switch that doesn't advertise |
| 2089 | * desired flow control, but can be forced on the link |
| 2090 | * partner. So if we advertised no flow control, that is |
| 2091 | * what we will resolve to. If we advertised some kind of |
| 2092 | * receive capability (Rx Pause Only or Full Flow Control) |
| 2093 | * and the link partner advertised none, we will configure |
| 2094 | * ourselves to enable Rx Flow Control only. We can do |
| 2095 | * this safely for two reasons: If the link partner really |
| 2096 | * didn't want flow control enabled, and we enable Rx, no |
| 2097 | * harm done since we won't be receiving any PAUSE frames |
| 2098 | * anyway. If the intent on the link partner was to have |
| 2099 | * flow control enabled, then by us enabling RX only, we |
| 2100 | * can at least receive pause frames and process them. |
| 2101 | * This is a good idea because in most cases, since we are |
| 2102 | * predominantly a server NIC, more times than not we will |
| 2103 | * be asked to delay transmission of packets than asking |
| 2104 | * our link partner to pause transmission of frames. |
| 2105 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2106 | else if ((hw->original_fc == E1000_FC_NONE || |
| 2107 | hw->original_fc == E1000_FC_TX_PAUSE) || |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2108 | hw->fc_strict_ieee) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2109 | hw->fc = E1000_FC_NONE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2110 | DEBUGOUT("Flow Control = NONE.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | } else { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2112 | hw->fc = E1000_FC_RX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2113 | DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | /* Now we need to do one last check... If we auto- |
| 2117 | * negotiated to HALF DUPLEX, flow control should not be |
| 2118 | * enabled per IEEE 802.3 spec. |
| 2119 | */ |
| 2120 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2121 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | DEBUGOUT("Error getting link speed and duplex\n"); |
| 2123 | return ret_val; |
| 2124 | } |
| 2125 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2126 | if (duplex == HALF_DUPLEX) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2127 | hw->fc = E1000_FC_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | |
| 2129 | /* Now we call a subroutine to actually force the MAC |
| 2130 | * controller to use the correct flow control settings. |
| 2131 | */ |
| 2132 | ret_val = e1000_force_mac_fc(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2133 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | DEBUGOUT("Error forcing flow control settings\n"); |
| 2135 | return ret_val; |
| 2136 | } |
| 2137 | } else { |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2138 | DEBUGOUT("Copper PHY and Auto Neg has not completed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | } |
| 2140 | } |
| 2141 | return E1000_SUCCESS; |
| 2142 | } |
| 2143 | |
| 2144 | /****************************************************************************** |
| 2145 | * Checks to see if the link status of the hardware has changed. |
| 2146 | * |
| 2147 | * hw - Struct containing variables accessed by shared code |
| 2148 | * |
| 2149 | * Called by any function that needs to check the link status of the adapter. |
| 2150 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2151 | s32 e1000_check_for_link(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2153 | u32 rxcw = 0; |
| 2154 | u32 ctrl; |
| 2155 | u32 status; |
| 2156 | u32 rctl; |
| 2157 | u32 icr; |
| 2158 | u32 signal = 0; |
| 2159 | s32 ret_val; |
| 2160 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | |
| 2162 | DEBUGFUNC("e1000_check_for_link"); |
| 2163 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2164 | ctrl = er32(CTRL); |
| 2165 | status = er32(STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | |
| 2167 | /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be |
| 2168 | * set when the optics detect a signal. On older adapters, it will be |
| 2169 | * cleared when there is a signal. This applies to fiber media only. |
| 2170 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2171 | if ((hw->media_type == e1000_media_type_fiber) || |
| 2172 | (hw->media_type == e1000_media_type_internal_serdes)) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2173 | rxcw = er32(RXCW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2175 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2177 | if (status & E1000_STATUS_LU) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2178 | hw->get_link_status = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | } |
| 2180 | } |
| 2181 | |
| 2182 | /* If we have a copper PHY then we only want to go out to the PHY |
| 2183 | * registers to see if Auto-Neg has completed and/or if our link |
| 2184 | * status has changed. The get_link_status flag will be set if we |
| 2185 | * receive a Link Status Change interrupt or we have Rx Sequence |
| 2186 | * Errors. |
| 2187 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2188 | if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | /* First we want to see if the MII Status Register reports |
| 2190 | * link. If so, then we want to get the current speed/duplex |
| 2191 | * of the PHY. |
| 2192 | * Read the register twice since the link bit is sticky. |
| 2193 | */ |
| 2194 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2195 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | return ret_val; |
| 2197 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2198 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | return ret_val; |
| 2200 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2201 | if (phy_data & MII_SR_LINK_STATUS) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2202 | hw->get_link_status = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | /* Check if there was DownShift, must be checked immediately after |
| 2204 | * link-up */ |
| 2205 | e1000_check_downshift(hw); |
| 2206 | |
| 2207 | /* If we are on 82544 or 82543 silicon and speed/duplex |
| 2208 | * are forced to 10H or 10F, then we will implement the polarity |
| 2209 | * reversal workaround. We disable interrupts first, and upon |
| 2210 | * returning, place the devices interrupt state to its previous |
| 2211 | * value except for the link status change interrupt which will |
| 2212 | * happen due to the execution of this workaround. |
| 2213 | */ |
| 2214 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2215 | if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) && |
| 2216 | (!hw->autoneg) && |
| 2217 | (hw->forced_speed_duplex == e1000_10_full || |
| 2218 | hw->forced_speed_duplex == e1000_10_half)) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2219 | ew32(IMC, 0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | ret_val = e1000_polarity_reversal_workaround(hw); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2221 | icr = er32(ICR); |
| 2222 | ew32(ICS, (icr & ~E1000_ICS_LSC)); |
| 2223 | ew32(IMS, IMS_ENABLE_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | } else { |
| 2227 | /* No link detected */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2228 | e1000_config_dsp_after_link_change(hw, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | return 0; |
| 2230 | } |
| 2231 | |
| 2232 | /* If we are forcing speed/duplex, then we simply return since |
| 2233 | * we have already determined whether we have link or not. |
| 2234 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2235 | if (!hw->autoneg) return -E1000_ERR_CONFIG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | |
| 2237 | /* optimize the dsp settings for the igp phy */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2238 | e1000_config_dsp_after_link_change(hw, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | |
| 2240 | /* We have a M88E1000 PHY and Auto-Neg is enabled. If we |
| 2241 | * have Si on board that is 82544 or newer, Auto |
| 2242 | * Speed Detection takes care of MAC speed/duplex |
| 2243 | * configuration. So we only need to configure Collision |
| 2244 | * Distance in the MAC. Otherwise, we need to force |
| 2245 | * speed/duplex on the MAC to the current PHY speed/duplex |
| 2246 | * settings. |
| 2247 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2248 | if (hw->mac_type >= e1000_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | e1000_config_collision_dist(hw); |
| 2250 | else { |
| 2251 | ret_val = e1000_config_mac_to_phy(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2252 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | DEBUGOUT("Error configuring MAC to PHY settings\n"); |
| 2254 | return ret_val; |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | /* Configure Flow Control now that Auto-Neg has completed. First, we |
| 2259 | * need to restore the desired flow control settings because we may |
| 2260 | * have had to re-autoneg with a different link partner. |
| 2261 | */ |
| 2262 | ret_val = e1000_config_fc_after_link_up(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2263 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | DEBUGOUT("Error configuring flow control\n"); |
| 2265 | return ret_val; |
| 2266 | } |
| 2267 | |
| 2268 | /* At this point we know that we are on copper and we have |
| 2269 | * auto-negotiated link. These are conditions for checking the link |
| 2270 | * partner capability register. We use the link speed to determine if |
| 2271 | * TBI compatibility needs to be turned on or off. If the link is not |
| 2272 | * at gigabit speed, then TBI compatibility is not needed. If we are |
| 2273 | * at gigabit speed, we turn on TBI compatibility. |
| 2274 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2275 | if (hw->tbi_compatibility_en) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2276 | u16 speed, duplex; |
Auke Kok | 592600a | 2006-06-27 09:08:09 -0700 | [diff] [blame] | 2277 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); |
| 2278 | if (ret_val) { |
| 2279 | DEBUGOUT("Error getting link speed and duplex\n"); |
| 2280 | return ret_val; |
| 2281 | } |
| 2282 | if (speed != SPEED_1000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | /* If link speed is not set to gigabit speed, we do not need |
| 2284 | * to enable TBI compatibility. |
| 2285 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2286 | if (hw->tbi_compatibility_on) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | /* If we previously were in the mode, turn it off. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2288 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | rctl &= ~E1000_RCTL_SBP; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2290 | ew32(RCTL, rctl); |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2291 | hw->tbi_compatibility_on = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | } |
| 2293 | } else { |
| 2294 | /* If TBI compatibility is was previously off, turn it on. For |
| 2295 | * compatibility with a TBI link partner, we will store bad |
| 2296 | * packets. Some frames have an additional byte on the end and |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 2297 | * will look like CRC errors to the hardware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2299 | if (!hw->tbi_compatibility_on) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2300 | hw->tbi_compatibility_on = true; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2301 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | rctl |= E1000_RCTL_SBP; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2303 | ew32(RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | } |
| 2305 | } |
| 2306 | } |
| 2307 | } |
| 2308 | /* If we don't have link (auto-negotiation failed or link partner cannot |
| 2309 | * auto-negotiate), the cable is plugged in (we have signal), and our |
| 2310 | * link partner is not trying to auto-negotiate with us (we are receiving |
| 2311 | * idles or data), we need to force link up. We also need to give |
| 2312 | * auto-negotiation time to complete, in case the cable was just plugged |
| 2313 | * in. The autoneg_failed flag does this. |
| 2314 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2315 | else if ((((hw->media_type == e1000_media_type_fiber) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | ((ctrl & E1000_CTRL_SWDPIN1) == signal)) || |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2317 | (hw->media_type == e1000_media_type_internal_serdes)) && |
| 2318 | (!(status & E1000_STATUS_LU)) && |
| 2319 | (!(rxcw & E1000_RXCW_C))) { |
| 2320 | if (hw->autoneg_failed == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | hw->autoneg_failed = 1; |
| 2322 | return 0; |
| 2323 | } |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2324 | DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | |
| 2326 | /* Disable auto-negotiation in the TXCW register */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2327 | ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | |
| 2329 | /* Force link-up and also force full-duplex. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2330 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2332 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | |
| 2334 | /* Configure Flow Control after forcing link up. */ |
| 2335 | ret_val = e1000_config_fc_after_link_up(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2336 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | DEBUGOUT("Error configuring flow control\n"); |
| 2338 | return ret_val; |
| 2339 | } |
| 2340 | } |
| 2341 | /* If we are forcing link and we are receiving /C/ ordered sets, re-enable |
| 2342 | * auto-negotiation in the TXCW register and disable forced link in the |
| 2343 | * Device Control register in an attempt to auto-negotiate with our link |
| 2344 | * partner. |
| 2345 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2346 | else if (((hw->media_type == e1000_media_type_fiber) || |
| 2347 | (hw->media_type == e1000_media_type_internal_serdes)) && |
| 2348 | (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2349 | DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n"); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2350 | ew32(TXCW, hw->txcw); |
| 2351 | ew32(CTRL, (ctrl & ~E1000_CTRL_SLU)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2353 | hw->serdes_link_down = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | } |
| 2355 | /* If we force link for non-auto-negotiation switch, check link status |
| 2356 | * based on MAC synchronization for internal serdes media type. |
| 2357 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2358 | else if ((hw->media_type == e1000_media_type_internal_serdes) && |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2359 | !(E1000_TXCW_ANE & er32(TXCW))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | /* SYNCH bit and IV bit are sticky. */ |
| 2361 | udelay(10); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2362 | if (E1000_RXCW_SYNCH & er32(RXCW)) { |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2363 | if (!(rxcw & E1000_RXCW_IV)) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2364 | hw->serdes_link_down = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | DEBUGOUT("SERDES: Link is up.\n"); |
| 2366 | } |
| 2367 | } else { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2368 | hw->serdes_link_down = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | DEBUGOUT("SERDES: Link is down.\n"); |
| 2370 | } |
| 2371 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2372 | if ((hw->media_type == e1000_media_type_internal_serdes) && |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2373 | (E1000_TXCW_ANE & er32(TXCW))) { |
| 2374 | hw->serdes_link_down = !(E1000_STATUS_LU & er32(STATUS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | } |
| 2376 | return E1000_SUCCESS; |
| 2377 | } |
| 2378 | |
| 2379 | /****************************************************************************** |
| 2380 | * Detects the current speed and duplex settings of the hardware. |
| 2381 | * |
| 2382 | * hw - Struct containing variables accessed by shared code |
| 2383 | * speed - Speed of the connection |
| 2384 | * duplex - Duplex setting of the connection |
| 2385 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2386 | 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] | 2387 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2388 | u32 status; |
| 2389 | s32 ret_val; |
| 2390 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | |
| 2392 | DEBUGFUNC("e1000_get_speed_and_duplex"); |
| 2393 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2394 | if (hw->mac_type >= e1000_82543) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2395 | status = er32(STATUS); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2396 | if (status & E1000_STATUS_SPEED_1000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | *speed = SPEED_1000; |
| 2398 | DEBUGOUT("1000 Mbs, "); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2399 | } else if (status & E1000_STATUS_SPEED_100) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | *speed = SPEED_100; |
| 2401 | DEBUGOUT("100 Mbs, "); |
| 2402 | } else { |
| 2403 | *speed = SPEED_10; |
| 2404 | DEBUGOUT("10 Mbs, "); |
| 2405 | } |
| 2406 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2407 | if (status & E1000_STATUS_FD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | *duplex = FULL_DUPLEX; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2409 | DEBUGOUT("Full Duplex\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | } else { |
| 2411 | *duplex = HALF_DUPLEX; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2412 | DEBUGOUT(" Half Duplex\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | } |
| 2414 | } else { |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2415 | DEBUGOUT("1000 Mbs, Full Duplex\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | *speed = SPEED_1000; |
| 2417 | *duplex = FULL_DUPLEX; |
| 2418 | } |
| 2419 | |
| 2420 | /* IGP01 PHY may advertise full duplex operation after speed downgrade even |
| 2421 | * if it is operating at half duplex. Here we set the duplex settings to |
| 2422 | * match the duplex in the link partner's capabilities. |
| 2423 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2424 | if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2426 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | return ret_val; |
| 2428 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2429 | if (!(phy_data & NWAY_ER_LP_NWAY_CAPS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | *duplex = HALF_DUPLEX; |
| 2431 | else { |
| 2432 | ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2433 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | return ret_val; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2435 | if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS))) |
| 2437 | *duplex = HALF_DUPLEX; |
| 2438 | } |
| 2439 | } |
| 2440 | |
| 2441 | return E1000_SUCCESS; |
| 2442 | } |
| 2443 | |
| 2444 | /****************************************************************************** |
| 2445 | * Blocks until autoneg completes or times out (~4.5 seconds) |
| 2446 | * |
| 2447 | * hw - Struct containing variables accessed by shared code |
| 2448 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2449 | static s32 e1000_wait_autoneg(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2451 | s32 ret_val; |
| 2452 | u16 i; |
| 2453 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | |
| 2455 | DEBUGFUNC("e1000_wait_autoneg"); |
| 2456 | DEBUGOUT("Waiting for Auto-Neg to complete.\n"); |
| 2457 | |
| 2458 | /* We will wait for autoneg to complete or 4.5 seconds to expire. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2459 | for (i = PHY_AUTO_NEG_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | /* Read the MII Status Register and wait for Auto-Neg |
| 2461 | * Complete bit to be set. |
| 2462 | */ |
| 2463 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2464 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | return ret_val; |
| 2466 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2467 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | return ret_val; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2469 | if (phy_data & MII_SR_AUTONEG_COMPLETE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | return E1000_SUCCESS; |
| 2471 | } |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 2472 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | } |
| 2474 | return E1000_SUCCESS; |
| 2475 | } |
| 2476 | |
| 2477 | /****************************************************************************** |
| 2478 | * Raises the Management Data Clock |
| 2479 | * |
| 2480 | * hw - Struct containing variables accessed by shared code |
| 2481 | * ctrl - Device control register's current value |
| 2482 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2483 | static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | { |
| 2485 | /* Raise the clock input to the Management Data Clock (by setting the MDC |
| 2486 | * bit), and then delay 10 microseconds. |
| 2487 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2488 | ew32(CTRL, (*ctrl | E1000_CTRL_MDC)); |
| 2489 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | udelay(10); |
| 2491 | } |
| 2492 | |
| 2493 | /****************************************************************************** |
| 2494 | * Lowers the Management Data Clock |
| 2495 | * |
| 2496 | * hw - Struct containing variables accessed by shared code |
| 2497 | * ctrl - Device control register's current value |
| 2498 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2499 | static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | { |
| 2501 | /* Lower the clock input to the Management Data Clock (by clearing the MDC |
| 2502 | * bit), and then delay 10 microseconds. |
| 2503 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2504 | ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC)); |
| 2505 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | udelay(10); |
| 2507 | } |
| 2508 | |
| 2509 | /****************************************************************************** |
| 2510 | * Shifts data bits out to the PHY |
| 2511 | * |
| 2512 | * hw - Struct containing variables accessed by shared code |
| 2513 | * data - Data to send out to the PHY |
| 2514 | * count - Number of bits to shift out |
| 2515 | * |
| 2516 | * Bits are shifted out in MSB to LSB order. |
| 2517 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2518 | 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] | 2519 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2520 | u32 ctrl; |
| 2521 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2522 | |
| 2523 | /* We need to shift "count" number of bits out to the PHY. So, the value |
| 2524 | * in the "data" parameter will be shifted out to the PHY one bit at a |
| 2525 | * time. In order to do this, "data" must be broken down into bits. |
| 2526 | */ |
| 2527 | mask = 0x01; |
| 2528 | mask <<= (count - 1); |
| 2529 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2530 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | |
| 2532 | /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */ |
| 2533 | ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR); |
| 2534 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2535 | while (mask) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and |
| 2537 | * then raising and lowering the Management Data Clock. A "0" is |
| 2538 | * shifted out to the PHY by setting the MDIO bit to "0" and then |
| 2539 | * raising and lowering the clock. |
| 2540 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2541 | if (data & mask) |
| 2542 | ctrl |= E1000_CTRL_MDIO; |
| 2543 | else |
| 2544 | ctrl &= ~E1000_CTRL_MDIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2546 | ew32(CTRL, ctrl); |
| 2547 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | |
| 2549 | udelay(10); |
| 2550 | |
| 2551 | e1000_raise_mdi_clk(hw, &ctrl); |
| 2552 | e1000_lower_mdi_clk(hw, &ctrl); |
| 2553 | |
| 2554 | mask = mask >> 1; |
| 2555 | } |
| 2556 | } |
| 2557 | |
| 2558 | /****************************************************************************** |
| 2559 | * Shifts data bits in from the PHY |
| 2560 | * |
| 2561 | * hw - Struct containing variables accessed by shared code |
| 2562 | * |
| 2563 | * Bits are shifted in in MSB to LSB order. |
| 2564 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2565 | static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2566 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2567 | u32 ctrl; |
| 2568 | u16 data = 0; |
| 2569 | u8 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | |
| 2571 | /* In order to read a register from the PHY, we need to shift in a total |
| 2572 | * of 18 bits from the PHY. The first two bit (turnaround) times are used |
| 2573 | * to avoid contention on the MDIO pin when a read operation is performed. |
| 2574 | * These two bits are ignored by us and thrown away. Bits are "shifted in" |
| 2575 | * by raising the input to the Management Data Clock (setting the MDC bit), |
| 2576 | * and then reading the value of the MDIO bit. |
| 2577 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2578 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | |
| 2580 | /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */ |
| 2581 | ctrl &= ~E1000_CTRL_MDIO_DIR; |
| 2582 | ctrl &= ~E1000_CTRL_MDIO; |
| 2583 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2584 | ew32(CTRL, ctrl); |
| 2585 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | |
| 2587 | /* Raise and Lower the clock before reading in the data. This accounts for |
| 2588 | * the turnaround bits. The first clock occurred when we clocked out the |
| 2589 | * last bit of the Register Address. |
| 2590 | */ |
| 2591 | e1000_raise_mdi_clk(hw, &ctrl); |
| 2592 | e1000_lower_mdi_clk(hw, &ctrl); |
| 2593 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2594 | for (data = 0, i = 0; i < 16; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | data = data << 1; |
| 2596 | e1000_raise_mdi_clk(hw, &ctrl); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2597 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | /* Check to see if we shifted in a "1". */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2599 | if (ctrl & E1000_CTRL_MDIO) |
| 2600 | data |= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | e1000_lower_mdi_clk(hw, &ctrl); |
| 2602 | } |
| 2603 | |
| 2604 | e1000_raise_mdi_clk(hw, &ctrl); |
| 2605 | e1000_lower_mdi_clk(hw, &ctrl); |
| 2606 | |
| 2607 | return data; |
| 2608 | } |
| 2609 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2610 | static s32 e1000_swfw_sync_acquire(struct e1000_hw *hw, u16 mask) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2611 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2612 | u32 swfw_sync = 0; |
| 2613 | u32 swmask = mask; |
| 2614 | u32 fwmask = mask << 16; |
| 2615 | s32 timeout = 200; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2616 | |
| 2617 | DEBUGFUNC("e1000_swfw_sync_acquire"); |
| 2618 | |
| 2619 | if (!hw->swfw_sync_present) |
| 2620 | return e1000_get_hw_eeprom_semaphore(hw); |
| 2621 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2622 | while (timeout) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2623 | if (e1000_get_hw_eeprom_semaphore(hw)) |
| 2624 | return -E1000_ERR_SWFW_SYNC; |
| 2625 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2626 | swfw_sync = er32(SW_FW_SYNC); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2627 | if (!(swfw_sync & (fwmask | swmask))) { |
| 2628 | break; |
| 2629 | } |
| 2630 | |
| 2631 | /* firmware currently using resource (fwmask) */ |
| 2632 | /* or other software thread currently using resource (swmask) */ |
| 2633 | e1000_put_hw_eeprom_semaphore(hw); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 2634 | mdelay(5); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2635 | timeout--; |
| 2636 | } |
| 2637 | |
| 2638 | if (!timeout) { |
| 2639 | DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n"); |
| 2640 | return -E1000_ERR_SWFW_SYNC; |
| 2641 | } |
| 2642 | |
| 2643 | swfw_sync |= swmask; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2644 | ew32(SW_FW_SYNC, swfw_sync); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2645 | |
| 2646 | e1000_put_hw_eeprom_semaphore(hw); |
| 2647 | return E1000_SUCCESS; |
| 2648 | } |
| 2649 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2650 | static void e1000_swfw_sync_release(struct e1000_hw *hw, u16 mask) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2651 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2652 | u32 swfw_sync; |
| 2653 | u32 swmask = mask; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2654 | |
| 2655 | DEBUGFUNC("e1000_swfw_sync_release"); |
| 2656 | |
| 2657 | if (!hw->swfw_sync_present) { |
| 2658 | e1000_put_hw_eeprom_semaphore(hw); |
| 2659 | return; |
| 2660 | } |
| 2661 | |
| 2662 | /* if (e1000_get_hw_eeprom_semaphore(hw)) |
| 2663 | * return -E1000_ERR_SWFW_SYNC; */ |
| 2664 | while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS); |
| 2665 | /* empty */ |
| 2666 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2667 | swfw_sync = er32(SW_FW_SYNC); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2668 | swfw_sync &= ~swmask; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2669 | ew32(SW_FW_SYNC, swfw_sync); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2670 | |
| 2671 | e1000_put_hw_eeprom_semaphore(hw); |
| 2672 | } |
| 2673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | /***************************************************************************** |
| 2675 | * Reads the value from a PHY register, if the value is on a specific non zero |
| 2676 | * page, sets the page first. |
| 2677 | * hw - Struct containing variables accessed by shared code |
| 2678 | * reg_addr - address of the PHY register to read |
| 2679 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2680 | 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] | 2681 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2682 | u32 ret_val; |
| 2683 | u16 swfw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | |
| 2685 | DEBUGFUNC("e1000_read_phy_reg"); |
| 2686 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 2687 | swfw = E1000_SWFW_PHY0_SM; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2688 | if (e1000_swfw_sync_acquire(hw, swfw)) |
| 2689 | return -E1000_ERR_SWFW_SYNC; |
| 2690 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 2691 | if ((hw->phy_type == e1000_phy_igp) && |
| 2692 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2694 | (u16)reg_addr); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2695 | if (ret_val) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2696 | e1000_swfw_sync_release(hw, swfw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | return ret_val; |
| 2698 | } |
| 2699 | } |
| 2700 | |
| 2701 | ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, |
| 2702 | phy_data); |
| 2703 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2704 | e1000_swfw_sync_release(hw, swfw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | return ret_val; |
| 2706 | } |
| 2707 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2708 | static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, |
| 2709 | u16 *phy_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2711 | u32 i; |
| 2712 | u32 mdic = 0; |
| 2713 | const u32 phy_addr = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | |
| 2715 | DEBUGFUNC("e1000_read_phy_reg_ex"); |
| 2716 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2717 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | DEBUGOUT1("PHY Address %d is out of range\n", reg_addr); |
| 2719 | return -E1000_ERR_PARAM; |
| 2720 | } |
| 2721 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2722 | if (hw->mac_type > e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | /* Set up Op-code, Phy Address, and register address in the MDI |
| 2724 | * Control register. The MAC will take care of interfacing with the |
| 2725 | * PHY to retrieve the desired data. |
| 2726 | */ |
| 2727 | mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) | |
| 2728 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 2729 | (E1000_MDIC_OP_READ)); |
| 2730 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2731 | ew32(MDIC, mdic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | |
| 2733 | /* Poll the ready bit to see if the MDI read completed */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2734 | for (i = 0; i < 64; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | udelay(50); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2736 | mdic = er32(MDIC); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2737 | if (mdic & E1000_MDIC_READY) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2739 | if (!(mdic & E1000_MDIC_READY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | DEBUGOUT("MDI Read did not complete\n"); |
| 2741 | return -E1000_ERR_PHY; |
| 2742 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2743 | if (mdic & E1000_MDIC_ERROR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | DEBUGOUT("MDI Error\n"); |
| 2745 | return -E1000_ERR_PHY; |
| 2746 | } |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2747 | *phy_data = (u16)mdic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | } else { |
| 2749 | /* We must first send a preamble through the MDIO pin to signal the |
| 2750 | * beginning of an MII instruction. This is done by sending 32 |
| 2751 | * consecutive "1" bits. |
| 2752 | */ |
| 2753 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
| 2754 | |
| 2755 | /* Now combine the next few fields that are required for a read |
| 2756 | * operation. We use this method instead of calling the |
| 2757 | * e1000_shift_out_mdi_bits routine five different times. The format of |
| 2758 | * a MII read instruction consists of a shift out of 14 bits and is |
| 2759 | * defined as follows: |
| 2760 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr> |
| 2761 | * followed by a shift in of 18 bits. This first two bits shifted in |
| 2762 | * are TurnAround bits used to avoid contention on the MDIO pin when a |
| 2763 | * READ operation is performed. These two bits are thrown away |
| 2764 | * followed by a shift in of 16 bits which contains the desired data. |
| 2765 | */ |
| 2766 | mdic = ((reg_addr) | (phy_addr << 5) | |
| 2767 | (PHY_OP_READ << 10) | (PHY_SOF << 12)); |
| 2768 | |
| 2769 | e1000_shift_out_mdi_bits(hw, mdic, 14); |
| 2770 | |
| 2771 | /* Now that we've shifted out the read command to the MII, we need to |
| 2772 | * "shift in" the 16-bit value (18 total bits) of the requested PHY |
| 2773 | * register address. |
| 2774 | */ |
| 2775 | *phy_data = e1000_shift_in_mdi_bits(hw); |
| 2776 | } |
| 2777 | return E1000_SUCCESS; |
| 2778 | } |
| 2779 | |
| 2780 | /****************************************************************************** |
| 2781 | * Writes a value to a PHY register |
| 2782 | * |
| 2783 | * hw - Struct containing variables accessed by shared code |
| 2784 | * reg_addr - address of the PHY register to write |
| 2785 | * data - data to write to the PHY |
| 2786 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2787 | 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] | 2788 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2789 | u32 ret_val; |
| 2790 | u16 swfw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | |
| 2792 | DEBUGFUNC("e1000_write_phy_reg"); |
| 2793 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 2794 | swfw = E1000_SWFW_PHY0_SM; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2795 | if (e1000_swfw_sync_acquire(hw, swfw)) |
| 2796 | return -E1000_ERR_SWFW_SYNC; |
| 2797 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 2798 | if ((hw->phy_type == e1000_phy_igp) && |
| 2799 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2801 | (u16)reg_addr); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2802 | if (ret_val) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2803 | e1000_swfw_sync_release(hw, swfw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | return ret_val; |
| 2805 | } |
| 2806 | } |
| 2807 | |
| 2808 | ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, |
| 2809 | phy_data); |
| 2810 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2811 | e1000_swfw_sync_release(hw, swfw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | return ret_val; |
| 2813 | } |
| 2814 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2815 | static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, |
| 2816 | u16 phy_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2818 | u32 i; |
| 2819 | u32 mdic = 0; |
| 2820 | const u32 phy_addr = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | |
| 2822 | DEBUGFUNC("e1000_write_phy_reg_ex"); |
| 2823 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2824 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | DEBUGOUT1("PHY Address %d is out of range\n", reg_addr); |
| 2826 | return -E1000_ERR_PARAM; |
| 2827 | } |
| 2828 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2829 | if (hw->mac_type > e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | /* Set up Op-code, Phy Address, register address, and data intended |
| 2831 | * for the PHY register in the MDI Control register. The MAC will take |
| 2832 | * care of interfacing with the PHY to send the desired data. |
| 2833 | */ |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2834 | mdic = (((u32)phy_data) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | (reg_addr << E1000_MDIC_REG_SHIFT) | |
| 2836 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 2837 | (E1000_MDIC_OP_WRITE)); |
| 2838 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2839 | ew32(MDIC, mdic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | |
| 2841 | /* Poll the ready bit to see if the MDI read completed */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2842 | for (i = 0; i < 641; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | udelay(5); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2844 | mdic = er32(MDIC); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2845 | if (mdic & E1000_MDIC_READY) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2847 | if (!(mdic & E1000_MDIC_READY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | DEBUGOUT("MDI Write did not complete\n"); |
| 2849 | return -E1000_ERR_PHY; |
| 2850 | } |
| 2851 | } else { |
| 2852 | /* We'll need to use the SW defined pins to shift the write command |
| 2853 | * out to the PHY. We first send a preamble to the PHY to signal the |
| 2854 | * beginning of the MII instruction. This is done by sending 32 |
| 2855 | * consecutive "1" bits. |
| 2856 | */ |
| 2857 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
| 2858 | |
| 2859 | /* Now combine the remaining required fields that will indicate a |
| 2860 | * write operation. We use this method instead of calling the |
| 2861 | * e1000_shift_out_mdi_bits routine for each field in the command. The |
| 2862 | * format of a MII write instruction is as follows: |
| 2863 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>. |
| 2864 | */ |
| 2865 | mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) | |
| 2866 | (PHY_OP_WRITE << 12) | (PHY_SOF << 14)); |
| 2867 | mdic <<= 16; |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2868 | mdic |= (u32)phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | |
| 2870 | e1000_shift_out_mdi_bits(hw, mdic, 32); |
| 2871 | } |
| 2872 | |
| 2873 | return E1000_SUCCESS; |
| 2874 | } |
| 2875 | |
| 2876 | /****************************************************************************** |
| 2877 | * Returns the PHY to the power-on reset state |
| 2878 | * |
| 2879 | * hw - Struct containing variables accessed by shared code |
| 2880 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2881 | s32 e1000_phy_hw_reset(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2883 | u32 ctrl, ctrl_ext; |
| 2884 | u32 led_ctrl; |
| 2885 | s32 ret_val; |
| 2886 | u16 swfw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | |
| 2888 | DEBUGFUNC("e1000_phy_hw_reset"); |
| 2889 | |
| 2890 | DEBUGOUT("Resetting Phy...\n"); |
| 2891 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2892 | if (hw->mac_type > e1000_82543) { |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 2893 | swfw = E1000_SWFW_PHY0_SM; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2894 | if (e1000_swfw_sync_acquire(hw, swfw)) { |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 2895 | DEBUGOUT("Unable to acquire swfw sync\n"); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2896 | return -E1000_ERR_SWFW_SYNC; |
| 2897 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | /* Read the device control register and assert the E1000_CTRL_PHY_RST |
| 2899 | * bit. Then, take it out of reset. |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 2900 | * For e1000 hardware, we delay for 10ms between the assert |
| 2901 | * and deassert. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2903 | ctrl = er32(CTRL); |
| 2904 | ew32(CTRL, ctrl | E1000_CTRL_PHY_RST); |
| 2905 | E1000_WRITE_FLUSH(); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2906 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 2907 | msleep(10); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2908 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2909 | ew32(CTRL, ctrl); |
| 2910 | E1000_WRITE_FLUSH(); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2911 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2912 | e1000_swfw_sync_release(hw, swfw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | } else { |
| 2914 | /* Read the Extended Device Control Register, assert the PHY_RESET_DIR |
| 2915 | * bit to put the PHY into reset. Then, take it out of reset. |
| 2916 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2917 | ctrl_ext = er32(CTRL_EXT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR; |
| 2919 | ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2920 | ew32(CTRL_EXT, ctrl_ext); |
| 2921 | E1000_WRITE_FLUSH(); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 2922 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2924 | ew32(CTRL_EXT, ctrl_ext); |
| 2925 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | } |
| 2927 | udelay(150); |
| 2928 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2929 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | /* Configure activity LED after PHY reset */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2931 | led_ctrl = er32(LEDCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 2933 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2934 | ew32(LEDCTL, led_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2936 | |
| 2937 | /* Wait for FW to finish PHY configuration. */ |
| 2938 | ret_val = e1000_get_phy_cfg_done(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2939 | if (ret_val != E1000_SUCCESS) |
| 2940 | return ret_val; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2941 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2942 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | /****************************************************************************** |
| 2946 | * Resets the PHY |
| 2947 | * |
| 2948 | * hw - Struct containing variables accessed by shared code |
| 2949 | * |
Matt LaPlante | 0779bf2 | 2006-11-30 05:24:39 +0100 | [diff] [blame] | 2950 | * Sets bit 15 of the MII Control register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2952 | s32 e1000_phy_reset(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2954 | s32 ret_val; |
| 2955 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | |
| 2957 | DEBUGFUNC("e1000_phy_reset"); |
| 2958 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 2959 | switch (hw->phy_type) { |
| 2960 | case e1000_phy_igp: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2961 | ret_val = e1000_phy_hw_reset(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2962 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2963 | return ret_val; |
| 2964 | break; |
| 2965 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2967 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | return ret_val; |
| 2969 | |
| 2970 | phy_data |= MII_CR_RESET; |
| 2971 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2972 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | return ret_val; |
| 2974 | |
| 2975 | udelay(1); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2976 | break; |
| 2977 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 2979 | if (hw->phy_type == e1000_phy_igp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | e1000_phy_init_script(hw); |
| 2981 | |
| 2982 | return E1000_SUCCESS; |
| 2983 | } |
| 2984 | |
| 2985 | /****************************************************************************** |
| 2986 | * Probes the expected PHY address for known PHY IDs |
| 2987 | * |
| 2988 | * hw - Struct containing variables accessed by shared code |
| 2989 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2990 | static s32 e1000_detect_gig_phy(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2992 | s32 phy_init_status, ret_val; |
| 2993 | u16 phy_id_high, phy_id_low; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2994 | bool match = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | |
| 2996 | DEBUGFUNC("e1000_detect_gig_phy"); |
| 2997 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 2998 | if (hw->phy_id != 0) |
| 2999 | return E1000_SUCCESS; |
| 3000 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | /* Read the PHY ID Registers to identify which PHY is onboard. */ |
| 3002 | ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3003 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | return ret_val; |
| 3005 | |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 3006 | hw->phy_id = (u32)(phy_id_high << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | udelay(20); |
| 3008 | ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3009 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | return ret_val; |
| 3011 | |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 3012 | hw->phy_id |= (u32)(phy_id_low & PHY_REVISION_MASK); |
| 3013 | hw->phy_revision = (u32)phy_id_low & ~PHY_REVISION_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3015 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | case e1000_82543: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3017 | if (hw->phy_id == M88E1000_E_PHY_ID) match = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | break; |
| 3019 | case e1000_82544: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3020 | if (hw->phy_id == M88E1000_I_PHY_ID) match = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | break; |
| 3022 | case e1000_82540: |
| 3023 | case e1000_82545: |
| 3024 | case e1000_82545_rev_3: |
| 3025 | case e1000_82546: |
| 3026 | case e1000_82546_rev_3: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3027 | if (hw->phy_id == M88E1011_I_PHY_ID) match = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | break; |
| 3029 | case e1000_82541: |
| 3030 | case e1000_82541_rev_2: |
| 3031 | case e1000_82547: |
| 3032 | case e1000_82547_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3033 | if (hw->phy_id == IGP01E1000_I_PHY_ID) match = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | break; |
| 3035 | default: |
| 3036 | DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type); |
| 3037 | return -E1000_ERR_CONFIG; |
| 3038 | } |
| 3039 | phy_init_status = e1000_set_phy_type(hw); |
| 3040 | |
| 3041 | if ((match) && (phy_init_status == E1000_SUCCESS)) { |
| 3042 | DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id); |
| 3043 | return E1000_SUCCESS; |
| 3044 | } |
| 3045 | DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id); |
| 3046 | return -E1000_ERR_PHY; |
| 3047 | } |
| 3048 | |
| 3049 | /****************************************************************************** |
| 3050 | * Resets the PHY's DSP |
| 3051 | * |
| 3052 | * hw - Struct containing variables accessed by shared code |
| 3053 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3054 | static s32 e1000_phy_reset_dsp(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3056 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | DEBUGFUNC("e1000_phy_reset_dsp"); |
| 3058 | |
| 3059 | do { |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 3060 | ret_val = e1000_write_phy_reg(hw, 29, 0x001d); |
| 3061 | if (ret_val) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | ret_val = e1000_write_phy_reg(hw, 30, 0x00c1); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3063 | if (ret_val) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | ret_val = e1000_write_phy_reg(hw, 30, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3065 | if (ret_val) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | ret_val = E1000_SUCCESS; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3067 | } while (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | |
| 3069 | return ret_val; |
| 3070 | } |
| 3071 | |
| 3072 | /****************************************************************************** |
| 3073 | * Get PHY information from various PHY registers for igp PHY only. |
| 3074 | * |
| 3075 | * hw - Struct containing variables accessed by shared code |
| 3076 | * phy_info - PHY information structure |
| 3077 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3078 | static s32 e1000_phy_igp_get_info(struct e1000_hw *hw, |
| 3079 | struct e1000_phy_info *phy_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3081 | s32 ret_val; |
| 3082 | u16 phy_data, min_length, max_length, average; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3083 | e1000_rev_polarity polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | |
| 3085 | DEBUGFUNC("e1000_phy_igp_get_info"); |
| 3086 | |
| 3087 | /* The downshift status is checked only once, after link is established, |
| 3088 | * and it stored in the hw->speed_downgraded parameter. */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3089 | phy_info->downshift = (e1000_downshift)hw->speed_downgraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | |
| 3091 | /* IGP01E1000 does not need to support it. */ |
| 3092 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal; |
| 3093 | |
| 3094 | /* IGP01E1000 always correct polarity reversal */ |
| 3095 | phy_info->polarity_correction = e1000_polarity_reversal_enabled; |
| 3096 | |
| 3097 | /* Check polarity status */ |
| 3098 | ret_val = e1000_check_polarity(hw, &polarity); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3099 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | return ret_val; |
| 3101 | |
| 3102 | phy_info->cable_polarity = polarity; |
| 3103 | |
| 3104 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3105 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | return ret_val; |
| 3107 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3108 | phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >> |
| 3109 | IGP01E1000_PSSR_MDIX_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3111 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
| 3113 | /* Local/Remote Receiver Information are only valid at 1000 Mbps */ |
| 3114 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3115 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | return ret_val; |
| 3117 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3118 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> |
| 3119 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? |
| 3120 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
| 3121 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> |
| 3122 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? |
| 3123 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | |
| 3125 | /* Get cable length */ |
| 3126 | ret_val = e1000_get_cable_length(hw, &min_length, &max_length); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3127 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | return ret_val; |
| 3129 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3130 | /* Translate to old method */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | average = (max_length + min_length) / 2; |
| 3132 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3133 | if (average <= e1000_igp_cable_length_50) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | phy_info->cable_length = e1000_cable_length_50; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3135 | else if (average <= e1000_igp_cable_length_80) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | phy_info->cable_length = e1000_cable_length_50_80; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3137 | else if (average <= e1000_igp_cable_length_110) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | phy_info->cable_length = e1000_cable_length_80_110; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3139 | else if (average <= e1000_igp_cable_length_140) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | phy_info->cable_length = e1000_cable_length_110_140; |
| 3141 | else |
| 3142 | phy_info->cable_length = e1000_cable_length_140; |
| 3143 | } |
| 3144 | |
| 3145 | return E1000_SUCCESS; |
| 3146 | } |
| 3147 | |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3148 | |
| 3149 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | * Get PHY information from various PHY registers fot m88 PHY only. |
| 3151 | * |
| 3152 | * hw - Struct containing variables accessed by shared code |
| 3153 | * phy_info - PHY information structure |
| 3154 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3155 | static s32 e1000_phy_m88_get_info(struct e1000_hw *hw, |
| 3156 | struct e1000_phy_info *phy_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3158 | s32 ret_val; |
| 3159 | u16 phy_data; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3160 | e1000_rev_polarity polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | |
| 3162 | DEBUGFUNC("e1000_phy_m88_get_info"); |
| 3163 | |
| 3164 | /* The downshift status is checked only once, after link is established, |
| 3165 | * and it stored in the hw->speed_downgraded parameter. */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3166 | phy_info->downshift = (e1000_downshift)hw->speed_downgraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | |
| 3168 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3169 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | return ret_val; |
| 3171 | |
| 3172 | phy_info->extended_10bt_distance = |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3173 | ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >> |
| 3174 | M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ? |
| 3175 | e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal; |
| 3176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | phy_info->polarity_correction = |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3178 | ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >> |
| 3179 | M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ? |
| 3180 | e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | |
| 3182 | /* Check polarity status */ |
| 3183 | ret_val = e1000_check_polarity(hw, &polarity); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3184 | if (ret_val) |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3185 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | phy_info->cable_polarity = polarity; |
| 3187 | |
| 3188 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3189 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | return ret_val; |
| 3191 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3192 | phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >> |
| 3193 | M88E1000_PSSR_MDIX_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | |
| 3195 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) { |
| 3196 | /* Cable Length Estimation and Local/Remote Receiver Information |
| 3197 | * are only valid at 1000 Mbps. |
| 3198 | */ |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 3199 | phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >> |
| 3200 | M88E1000_PSSR_CABLE_LENGTH_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | |
| 3202 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3203 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | return ret_val; |
| 3205 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3206 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> |
| 3207 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? |
| 3208 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
| 3209 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> |
| 3210 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? |
| 3211 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | } |
| 3214 | |
| 3215 | return E1000_SUCCESS; |
| 3216 | } |
| 3217 | |
| 3218 | /****************************************************************************** |
| 3219 | * Get PHY information from various PHY registers |
| 3220 | * |
| 3221 | * hw - Struct containing variables accessed by shared code |
| 3222 | * phy_info - PHY information structure |
| 3223 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3224 | 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] | 3225 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3226 | s32 ret_val; |
| 3227 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | |
| 3229 | DEBUGFUNC("e1000_phy_get_info"); |
| 3230 | |
| 3231 | phy_info->cable_length = e1000_cable_length_undefined; |
| 3232 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined; |
| 3233 | phy_info->cable_polarity = e1000_rev_polarity_undefined; |
| 3234 | phy_info->downshift = e1000_downshift_undefined; |
| 3235 | phy_info->polarity_correction = e1000_polarity_reversal_undefined; |
| 3236 | phy_info->mdix_mode = e1000_auto_x_mode_undefined; |
| 3237 | phy_info->local_rx = e1000_1000t_rx_status_undefined; |
| 3238 | phy_info->remote_rx = e1000_1000t_rx_status_undefined; |
| 3239 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3240 | if (hw->media_type != e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | DEBUGOUT("PHY info is only valid for copper media\n"); |
| 3242 | return -E1000_ERR_CONFIG; |
| 3243 | } |
| 3244 | |
| 3245 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3246 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | return ret_val; |
| 3248 | |
| 3249 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3250 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | return ret_val; |
| 3252 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3253 | if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | DEBUGOUT("PHY info is only valid if link is up\n"); |
| 3255 | return -E1000_ERR_CONFIG; |
| 3256 | } |
| 3257 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 3258 | if (hw->phy_type == e1000_phy_igp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | return e1000_phy_igp_get_info(hw, phy_info); |
| 3260 | else |
| 3261 | return e1000_phy_m88_get_info(hw, phy_info); |
| 3262 | } |
| 3263 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3264 | s32 e1000_validate_mdi_setting(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | { |
| 3266 | DEBUGFUNC("e1000_validate_mdi_settings"); |
| 3267 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3268 | if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | DEBUGOUT("Invalid MDI setting detected\n"); |
| 3270 | hw->mdix = 1; |
| 3271 | return -E1000_ERR_CONFIG; |
| 3272 | } |
| 3273 | return E1000_SUCCESS; |
| 3274 | } |
| 3275 | |
| 3276 | |
| 3277 | /****************************************************************************** |
| 3278 | * 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^] | 3279 | * is configured. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | * |
| 3281 | * hw - Struct containing variables accessed by shared code |
| 3282 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3283 | s32 e1000_init_eeprom_params(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | { |
| 3285 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3286 | u32 eecd = er32(EECD); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3287 | s32 ret_val = E1000_SUCCESS; |
| 3288 | u16 eeprom_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3289 | |
| 3290 | DEBUGFUNC("e1000_init_eeprom_params"); |
| 3291 | |
| 3292 | switch (hw->mac_type) { |
| 3293 | case e1000_82542_rev2_0: |
| 3294 | case e1000_82542_rev2_1: |
| 3295 | case e1000_82543: |
| 3296 | case e1000_82544: |
| 3297 | eeprom->type = e1000_eeprom_microwire; |
| 3298 | eeprom->word_size = 64; |
| 3299 | eeprom->opcode_bits = 3; |
| 3300 | eeprom->address_bits = 6; |
| 3301 | eeprom->delay_usec = 50; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3302 | eeprom->use_eerd = false; |
| 3303 | eeprom->use_eewr = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | break; |
| 3305 | case e1000_82540: |
| 3306 | case e1000_82545: |
| 3307 | case e1000_82545_rev_3: |
| 3308 | case e1000_82546: |
| 3309 | case e1000_82546_rev_3: |
| 3310 | eeprom->type = e1000_eeprom_microwire; |
| 3311 | eeprom->opcode_bits = 3; |
| 3312 | eeprom->delay_usec = 50; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3313 | if (eecd & E1000_EECD_SIZE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | eeprom->word_size = 256; |
| 3315 | eeprom->address_bits = 8; |
| 3316 | } else { |
| 3317 | eeprom->word_size = 64; |
| 3318 | eeprom->address_bits = 6; |
| 3319 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3320 | eeprom->use_eerd = false; |
| 3321 | eeprom->use_eewr = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | break; |
| 3323 | case e1000_82541: |
| 3324 | case e1000_82541_rev_2: |
| 3325 | case e1000_82547: |
| 3326 | case e1000_82547_rev_2: |
| 3327 | if (eecd & E1000_EECD_TYPE) { |
| 3328 | eeprom->type = e1000_eeprom_spi; |
| 3329 | eeprom->opcode_bits = 8; |
| 3330 | eeprom->delay_usec = 1; |
| 3331 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 3332 | eeprom->page_size = 32; |
| 3333 | eeprom->address_bits = 16; |
| 3334 | } else { |
| 3335 | eeprom->page_size = 8; |
| 3336 | eeprom->address_bits = 8; |
| 3337 | } |
| 3338 | } else { |
| 3339 | eeprom->type = e1000_eeprom_microwire; |
| 3340 | eeprom->opcode_bits = 3; |
| 3341 | eeprom->delay_usec = 50; |
| 3342 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 3343 | eeprom->word_size = 256; |
| 3344 | eeprom->address_bits = 8; |
| 3345 | } else { |
| 3346 | eeprom->word_size = 64; |
| 3347 | eeprom->address_bits = 6; |
| 3348 | } |
| 3349 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3350 | eeprom->use_eerd = false; |
| 3351 | eeprom->use_eewr = false; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3352 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | default: |
| 3354 | break; |
| 3355 | } |
| 3356 | |
| 3357 | if (eeprom->type == e1000_eeprom_spi) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3358 | /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to |
| 3359 | * 32KB (incremented by powers of 2). |
| 3360 | */ |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 3361 | /* Set to default value for initial eeprom read. */ |
| 3362 | eeprom->word_size = 64; |
| 3363 | ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size); |
| 3364 | if (ret_val) |
| 3365 | return ret_val; |
| 3366 | eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT; |
| 3367 | /* 256B eeprom size was not supported in earlier hardware, so we |
| 3368 | * bump eeprom_size up one to ensure that "1" (which maps to 256B) |
| 3369 | * is never the result used in the shifting logic below. */ |
| 3370 | if (eeprom_size) |
| 3371 | eeprom_size++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3372 | |
| 3373 | eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3375 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | /****************************************************************************** |
| 3379 | * Raises the EEPROM's clock input. |
| 3380 | * |
| 3381 | * hw - Struct containing variables accessed by shared code |
| 3382 | * eecd - EECD's current value |
| 3383 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3384 | static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | { |
| 3386 | /* Raise the clock input to the EEPROM (by setting the SK bit), and then |
| 3387 | * wait <delay> microseconds. |
| 3388 | */ |
| 3389 | *eecd = *eecd | E1000_EECD_SK; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3390 | ew32(EECD, *eecd); |
| 3391 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3392 | udelay(hw->eeprom.delay_usec); |
| 3393 | } |
| 3394 | |
| 3395 | /****************************************************************************** |
| 3396 | * Lowers the EEPROM's clock input. |
| 3397 | * |
| 3398 | * hw - Struct containing variables accessed by shared code |
| 3399 | * eecd - EECD's current value |
| 3400 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3401 | static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | { |
| 3403 | /* Lower the clock input to the EEPROM (by clearing the SK bit), and then |
| 3404 | * wait 50 microseconds. |
| 3405 | */ |
| 3406 | *eecd = *eecd & ~E1000_EECD_SK; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3407 | ew32(EECD, *eecd); |
| 3408 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3409 | udelay(hw->eeprom.delay_usec); |
| 3410 | } |
| 3411 | |
| 3412 | /****************************************************************************** |
| 3413 | * Shift data bits out to the EEPROM. |
| 3414 | * |
| 3415 | * hw - Struct containing variables accessed by shared code |
| 3416 | * data - data to send to the EEPROM |
| 3417 | * count - number of bits to shift out |
| 3418 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3419 | 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] | 3420 | { |
| 3421 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3422 | u32 eecd; |
| 3423 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | |
| 3425 | /* We need to shift "count" bits out to the EEPROM. So, value in the |
| 3426 | * "data" parameter will be shifted out to the EEPROM one bit at a time. |
| 3427 | * In order to do this, "data" must be broken down into bits. |
| 3428 | */ |
| 3429 | mask = 0x01 << (count - 1); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3430 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | if (eeprom->type == e1000_eeprom_microwire) { |
| 3432 | eecd &= ~E1000_EECD_DO; |
| 3433 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 3434 | eecd |= E1000_EECD_DO; |
| 3435 | } |
| 3436 | do { |
| 3437 | /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1", |
| 3438 | * and then raising and then lowering the clock (the SK bit controls |
| 3439 | * the clock input to the EEPROM). A "0" is shifted out to the EEPROM |
| 3440 | * by setting "DI" to "0" and then raising and then lowering the clock. |
| 3441 | */ |
| 3442 | eecd &= ~E1000_EECD_DI; |
| 3443 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3444 | if (data & mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3445 | eecd |= E1000_EECD_DI; |
| 3446 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3447 | ew32(EECD, eecd); |
| 3448 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | |
| 3450 | udelay(eeprom->delay_usec); |
| 3451 | |
| 3452 | e1000_raise_ee_clk(hw, &eecd); |
| 3453 | e1000_lower_ee_clk(hw, &eecd); |
| 3454 | |
| 3455 | mask = mask >> 1; |
| 3456 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3457 | } while (mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | |
| 3459 | /* We leave the "DI" bit set to "0" when we leave this routine. */ |
| 3460 | eecd &= ~E1000_EECD_DI; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3461 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3462 | } |
| 3463 | |
| 3464 | /****************************************************************************** |
| 3465 | * Shift data bits in from the EEPROM |
| 3466 | * |
| 3467 | * hw - Struct containing variables accessed by shared code |
| 3468 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3469 | 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] | 3470 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3471 | u32 eecd; |
| 3472 | u32 i; |
| 3473 | u16 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | |
| 3475 | /* In order to read a register from the EEPROM, we need to shift 'count' |
| 3476 | * bits in from the EEPROM. Bits are "shifted in" by raising the clock |
| 3477 | * input to the EEPROM (setting the SK bit), and then reading the value of |
| 3478 | * the "DO" bit. During this "shifting in" process the "DI" bit should |
| 3479 | * always be clear. |
| 3480 | */ |
| 3481 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3482 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | |
| 3484 | eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); |
| 3485 | data = 0; |
| 3486 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3487 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | data = data << 1; |
| 3489 | e1000_raise_ee_clk(hw, &eecd); |
| 3490 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3491 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3492 | |
| 3493 | eecd &= ~(E1000_EECD_DI); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3494 | if (eecd & E1000_EECD_DO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3495 | data |= 1; |
| 3496 | |
| 3497 | e1000_lower_ee_clk(hw, &eecd); |
| 3498 | } |
| 3499 | |
| 3500 | return data; |
| 3501 | } |
| 3502 | |
| 3503 | /****************************************************************************** |
| 3504 | * Prepares EEPROM for access |
| 3505 | * |
| 3506 | * hw - Struct containing variables accessed by shared code |
| 3507 | * |
| 3508 | * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This |
| 3509 | * function should be called before issuing a command to the EEPROM. |
| 3510 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3511 | static s32 e1000_acquire_eeprom(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | { |
| 3513 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3514 | u32 eecd, i=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | |
| 3516 | DEBUGFUNC("e1000_acquire_eeprom"); |
| 3517 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3518 | if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM)) |
| 3519 | return -E1000_ERR_SWFW_SYNC; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3520 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 3522 | /* Request EEPROM Access */ |
| 3523 | if (hw->mac_type > e1000_82544) { |
| 3524 | eecd |= E1000_EECD_REQ; |
| 3525 | ew32(EECD, eecd); |
| 3526 | eecd = er32(EECD); |
| 3527 | while ((!(eecd & E1000_EECD_GNT)) && |
| 3528 | (i < E1000_EEPROM_GRANT_ATTEMPTS)) { |
| 3529 | i++; |
| 3530 | udelay(5); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3531 | eecd = er32(EECD); |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 3532 | } |
| 3533 | if (!(eecd & E1000_EECD_GNT)) { |
| 3534 | eecd &= ~E1000_EECD_REQ; |
| 3535 | ew32(EECD, eecd); |
| 3536 | DEBUGOUT("Could not acquire EEPROM grant\n"); |
| 3537 | e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM); |
| 3538 | return -E1000_ERR_EEPROM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | } |
| 3540 | } |
| 3541 | |
| 3542 | /* Setup EEPROM for Read/Write */ |
| 3543 | |
| 3544 | if (eeprom->type == e1000_eeprom_microwire) { |
| 3545 | /* Clear SK and DI */ |
| 3546 | eecd &= ~(E1000_EECD_DI | E1000_EECD_SK); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3547 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | |
| 3549 | /* Set CS */ |
| 3550 | eecd |= E1000_EECD_CS; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3551 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 3553 | /* Clear SK and CS */ |
| 3554 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3555 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | udelay(1); |
| 3557 | } |
| 3558 | |
| 3559 | return E1000_SUCCESS; |
| 3560 | } |
| 3561 | |
| 3562 | /****************************************************************************** |
| 3563 | * Returns EEPROM to a "standby" state |
| 3564 | * |
| 3565 | * hw - Struct containing variables accessed by shared code |
| 3566 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3567 | static void e1000_standby_eeprom(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | { |
| 3569 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3570 | u32 eecd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3572 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3574 | if (eeprom->type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3575 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3576 | ew32(EECD, eecd); |
| 3577 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | udelay(eeprom->delay_usec); |
| 3579 | |
| 3580 | /* Clock high */ |
| 3581 | eecd |= E1000_EECD_SK; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3582 | ew32(EECD, eecd); |
| 3583 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | udelay(eeprom->delay_usec); |
| 3585 | |
| 3586 | /* Select EEPROM */ |
| 3587 | eecd |= E1000_EECD_CS; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3588 | ew32(EECD, eecd); |
| 3589 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | udelay(eeprom->delay_usec); |
| 3591 | |
| 3592 | /* Clock low */ |
| 3593 | eecd &= ~E1000_EECD_SK; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3594 | ew32(EECD, eecd); |
| 3595 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3596 | udelay(eeprom->delay_usec); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3597 | } else if (eeprom->type == e1000_eeprom_spi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3598 | /* Toggle CS to flush commands */ |
| 3599 | eecd |= E1000_EECD_CS; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3600 | ew32(EECD, eecd); |
| 3601 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3602 | udelay(eeprom->delay_usec); |
| 3603 | eecd &= ~E1000_EECD_CS; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3604 | ew32(EECD, eecd); |
| 3605 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | udelay(eeprom->delay_usec); |
| 3607 | } |
| 3608 | } |
| 3609 | |
| 3610 | /****************************************************************************** |
| 3611 | * Terminates a command by inverting the EEPROM's chip select pin |
| 3612 | * |
| 3613 | * hw - Struct containing variables accessed by shared code |
| 3614 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3615 | static void e1000_release_eeprom(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3617 | u32 eecd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3618 | |
| 3619 | DEBUGFUNC("e1000_release_eeprom"); |
| 3620 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3621 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3622 | |
| 3623 | if (hw->eeprom.type == e1000_eeprom_spi) { |
| 3624 | eecd |= E1000_EECD_CS; /* Pull CS high */ |
| 3625 | eecd &= ~E1000_EECD_SK; /* Lower SCK */ |
| 3626 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3627 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | |
| 3629 | udelay(hw->eeprom.delay_usec); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3630 | } else if (hw->eeprom.type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3631 | /* cleanup eeprom */ |
| 3632 | |
| 3633 | /* CS on Microwire is active-high */ |
| 3634 | eecd &= ~(E1000_EECD_CS | E1000_EECD_DI); |
| 3635 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3636 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3637 | |
| 3638 | /* Rising edge of clock */ |
| 3639 | eecd |= E1000_EECD_SK; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3640 | ew32(EECD, eecd); |
| 3641 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | udelay(hw->eeprom.delay_usec); |
| 3643 | |
| 3644 | /* Falling edge of clock */ |
| 3645 | eecd &= ~E1000_EECD_SK; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3646 | ew32(EECD, eecd); |
| 3647 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | udelay(hw->eeprom.delay_usec); |
| 3649 | } |
| 3650 | |
| 3651 | /* Stop requesting EEPROM access */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3652 | if (hw->mac_type > e1000_82544) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3653 | eecd &= ~E1000_EECD_REQ; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3654 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3656 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3657 | e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | /****************************************************************************** |
| 3661 | * Reads a 16 bit word from the EEPROM. |
| 3662 | * |
| 3663 | * hw - Struct containing variables accessed by shared code |
| 3664 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3665 | static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3666 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3667 | u16 retry_count = 0; |
| 3668 | u8 spi_stat_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | |
| 3670 | DEBUGFUNC("e1000_spi_eeprom_ready"); |
| 3671 | |
| 3672 | /* Read "Status Register" repeatedly until the LSB is cleared. The |
| 3673 | * EEPROM will signal that the command has been completed by clearing |
| 3674 | * bit 0 of the internal status register. If it's not cleared within |
| 3675 | * 5 milliseconds, then error out. |
| 3676 | */ |
| 3677 | retry_count = 0; |
| 3678 | do { |
| 3679 | e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI, |
| 3680 | hw->eeprom.opcode_bits); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3681 | spi_stat_reg = (u8)e1000_shift_in_ee_bits(hw, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI)) |
| 3683 | break; |
| 3684 | |
| 3685 | udelay(5); |
| 3686 | retry_count += 5; |
| 3687 | |
| 3688 | e1000_standby_eeprom(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3689 | } while (retry_count < EEPROM_MAX_RETRY_SPI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | |
| 3691 | /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and |
| 3692 | * only 0-5mSec on 5V devices) |
| 3693 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3694 | if (retry_count >= EEPROM_MAX_RETRY_SPI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3695 | DEBUGOUT("SPI EEPROM Status error\n"); |
| 3696 | return -E1000_ERR_EEPROM; |
| 3697 | } |
| 3698 | |
| 3699 | return E1000_SUCCESS; |
| 3700 | } |
| 3701 | |
| 3702 | /****************************************************************************** |
| 3703 | * Reads a 16 bit word from the EEPROM. |
| 3704 | * |
| 3705 | * hw - Struct containing variables accessed by shared code |
| 3706 | * offset - offset of word in the EEPROM to read |
| 3707 | * data - word read from the EEPROM |
| 3708 | * words - number of words to read |
| 3709 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3710 | 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] | 3711 | { |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 3712 | s32 ret; |
| 3713 | spin_lock(&e1000_eeprom_lock); |
| 3714 | ret = e1000_do_read_eeprom(hw, offset, words, data); |
| 3715 | spin_unlock(&e1000_eeprom_lock); |
| 3716 | return ret; |
| 3717 | } |
| 3718 | |
| 3719 | static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) |
| 3720 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3722 | u32 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3723 | |
| 3724 | DEBUGFUNC("e1000_read_eeprom"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3725 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3726 | /* If eeprom is not yet detected, do so now */ |
| 3727 | if (eeprom->word_size == 0) |
| 3728 | e1000_init_eeprom_params(hw); |
| 3729 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | /* A check for invalid values: offset too large, too many words, and not |
| 3731 | * enough words. |
| 3732 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3733 | if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | (words == 0)) { |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3735 | DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3736 | return -E1000_ERR_EEPROM; |
| 3737 | } |
| 3738 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3739 | /* EEPROM's that don't use EERD to read require us to bit-bang the SPI |
| 3740 | * directly. In this case, we need to acquire the EEPROM so that |
| 3741 | * FW or other port software does not interrupt. |
| 3742 | */ |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 3743 | if (!hw->eeprom.use_eerd) { |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3744 | /* Prepare the EEPROM for bit-bang reading */ |
| 3745 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) |
| 3746 | return -E1000_ERR_EEPROM; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3747 | } |
| 3748 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3749 | /* Eerd register EEPROM access requires no eeprom aquire/release */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3750 | if (eeprom->use_eerd) |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3751 | return e1000_read_eeprom_eerd(hw, offset, words, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3753 | /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have |
| 3754 | * acquired the EEPROM at this point, so any returns should relase it */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3755 | if (eeprom->type == e1000_eeprom_spi) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3756 | u16 word_in; |
| 3757 | u8 read_opcode = EEPROM_READ_OPCODE_SPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3759 | if (e1000_spi_eeprom_ready(hw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3760 | e1000_release_eeprom(hw); |
| 3761 | return -E1000_ERR_EEPROM; |
| 3762 | } |
| 3763 | |
| 3764 | e1000_standby_eeprom(hw); |
| 3765 | |
| 3766 | /* Some SPI eeproms use the 8th address bit embedded in the opcode */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3767 | if ((eeprom->address_bits == 8) && (offset >= 128)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | read_opcode |= EEPROM_A8_OPCODE_SPI; |
| 3769 | |
| 3770 | /* Send the READ command (opcode + addr) */ |
| 3771 | e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3772 | e1000_shift_out_ee_bits(hw, (u16)(offset*2), eeprom->address_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | |
| 3774 | /* Read the data. The address of the eeprom internally increments with |
| 3775 | * each byte (spi) being read, saving on the overhead of eeprom setup |
| 3776 | * and tear-down. The address counter will roll over if reading beyond |
| 3777 | * the size of the eeprom, thus allowing the entire memory to be read |
| 3778 | * starting from any offset. */ |
| 3779 | for (i = 0; i < words; i++) { |
| 3780 | word_in = e1000_shift_in_ee_bits(hw, 16); |
| 3781 | data[i] = (word_in >> 8) | (word_in << 8); |
| 3782 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3783 | } else if (eeprom->type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | for (i = 0; i < words; i++) { |
| 3785 | /* Send the READ command (opcode + addr) */ |
| 3786 | e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE, |
| 3787 | eeprom->opcode_bits); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3788 | e1000_shift_out_ee_bits(hw, (u16)(offset + i), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | eeprom->address_bits); |
| 3790 | |
| 3791 | /* Read the data. For microwire, each word requires the overhead |
| 3792 | * of eeprom setup and tear-down. */ |
| 3793 | data[i] = e1000_shift_in_ee_bits(hw, 16); |
| 3794 | e1000_standby_eeprom(hw); |
| 3795 | } |
| 3796 | } |
| 3797 | |
| 3798 | /* End this read operation */ |
| 3799 | e1000_release_eeprom(hw); |
| 3800 | |
| 3801 | return E1000_SUCCESS; |
| 3802 | } |
| 3803 | |
| 3804 | /****************************************************************************** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3805 | * Reads a 16 bit word from the EEPROM using the EERD register. |
| 3806 | * |
| 3807 | * hw - Struct containing variables accessed by shared code |
| 3808 | * offset - offset of word in the EEPROM to read |
| 3809 | * data - word read from the EEPROM |
| 3810 | * words - number of words to read |
| 3811 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3812 | static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words, |
| 3813 | u16 *data) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3814 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3815 | u32 i, eerd = 0; |
| 3816 | s32 error = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3817 | |
| 3818 | for (i = 0; i < words; i++) { |
| 3819 | eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) + |
| 3820 | E1000_EEPROM_RW_REG_START; |
| 3821 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3822 | ew32(EERD, eerd); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3823 | error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3824 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3825 | if (error) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3826 | break; |
| 3827 | } |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3828 | data[i] = (er32(EERD) >> E1000_EEPROM_RW_REG_DATA); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3829 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3830 | } |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3831 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3832 | return error; |
| 3833 | } |
| 3834 | |
| 3835 | /****************************************************************************** |
| 3836 | * Writes a 16 bit word from the EEPROM using the EEWR register. |
| 3837 | * |
| 3838 | * hw - Struct containing variables accessed by shared code |
| 3839 | * offset - offset of word in the EEPROM to read |
| 3840 | * data - word read from the EEPROM |
| 3841 | * words - number of words to read |
| 3842 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3843 | static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words, |
| 3844 | u16 *data) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3845 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3846 | u32 register_value = 0; |
| 3847 | u32 i = 0; |
| 3848 | s32 error = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3849 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3850 | if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM)) |
| 3851 | return -E1000_ERR_SWFW_SYNC; |
| 3852 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3853 | for (i = 0; i < words; i++) { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3854 | register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) | |
| 3855 | ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3856 | E1000_EEPROM_RW_REG_START; |
| 3857 | |
| 3858 | error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3859 | if (error) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3860 | break; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3861 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3862 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3863 | ew32(EEWR, register_value); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3864 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3865 | error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3866 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3867 | if (error) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3868 | break; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3869 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3870 | } |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3871 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3872 | e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3873 | return error; |
| 3874 | } |
| 3875 | |
| 3876 | /****************************************************************************** |
| 3877 | * Polls the status bit (bit 1) of the EERD to determine when the read is done. |
| 3878 | * |
| 3879 | * hw - Struct containing variables accessed by shared code |
| 3880 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3881 | static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3882 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3883 | u32 attempts = 100000; |
| 3884 | u32 i, reg = 0; |
| 3885 | s32 done = E1000_ERR_EEPROM; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3886 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3887 | for (i = 0; i < attempts; i++) { |
| 3888 | if (eerd == E1000_EEPROM_POLL_READ) |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3889 | reg = er32(EERD); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3890 | else |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3891 | reg = er32(EEWR); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3892 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3893 | if (reg & E1000_EEPROM_RW_REG_DONE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3894 | done = E1000_SUCCESS; |
| 3895 | break; |
| 3896 | } |
| 3897 | udelay(5); |
| 3898 | } |
| 3899 | |
| 3900 | return done; |
| 3901 | } |
| 3902 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3903 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | * Verifies that the EEPROM has a valid checksum |
| 3905 | * |
| 3906 | * hw - Struct containing variables accessed by shared code |
| 3907 | * |
| 3908 | * Reads the first 64 16 bit words of the EEPROM and sums the values read. |
| 3909 | * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is |
| 3910 | * valid. |
| 3911 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3912 | s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3914 | u16 checksum = 0; |
| 3915 | u16 i, eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3916 | |
| 3917 | DEBUGFUNC("e1000_validate_eeprom_checksum"); |
| 3918 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3919 | for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) { |
| 3920 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3921 | DEBUGOUT("EEPROM Read Error\n"); |
| 3922 | return -E1000_ERR_EEPROM; |
| 3923 | } |
| 3924 | checksum += eeprom_data; |
| 3925 | } |
| 3926 | |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 3927 | if (checksum == (u16)EEPROM_SUM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3928 | return E1000_SUCCESS; |
| 3929 | else { |
| 3930 | DEBUGOUT("EEPROM Checksum Invalid\n"); |
| 3931 | return -E1000_ERR_EEPROM; |
| 3932 | } |
| 3933 | } |
| 3934 | |
| 3935 | /****************************************************************************** |
| 3936 | * Calculates the EEPROM checksum and writes it to the EEPROM |
| 3937 | * |
| 3938 | * hw - Struct containing variables accessed by shared code |
| 3939 | * |
| 3940 | * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA. |
| 3941 | * Writes the difference to word offset 63 of the EEPROM. |
| 3942 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3943 | s32 e1000_update_eeprom_checksum(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3945 | u16 checksum = 0; |
| 3946 | u16 i, eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | |
| 3948 | DEBUGFUNC("e1000_update_eeprom_checksum"); |
| 3949 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3950 | for (i = 0; i < EEPROM_CHECKSUM_REG; i++) { |
| 3951 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | DEBUGOUT("EEPROM Read Error\n"); |
| 3953 | return -E1000_ERR_EEPROM; |
| 3954 | } |
| 3955 | checksum += eeprom_data; |
| 3956 | } |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 3957 | checksum = (u16)EEPROM_SUM - checksum; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3958 | if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3959 | DEBUGOUT("EEPROM Write Error\n"); |
| 3960 | return -E1000_ERR_EEPROM; |
| 3961 | } |
| 3962 | return E1000_SUCCESS; |
| 3963 | } |
| 3964 | |
| 3965 | /****************************************************************************** |
| 3966 | * Parent function for writing words to the different EEPROM types. |
| 3967 | * |
| 3968 | * hw - Struct containing variables accessed by shared code |
| 3969 | * offset - offset within the EEPROM to be written to |
| 3970 | * words - number of words to write |
| 3971 | * data - 16 bit word to be written to the EEPROM |
| 3972 | * |
| 3973 | * If e1000_update_eeprom_checksum is not called after this function, the |
| 3974 | * EEPROM will most likely contain an invalid checksum. |
| 3975 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3976 | 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] | 3977 | { |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 3978 | s32 ret; |
| 3979 | spin_lock(&e1000_eeprom_lock); |
| 3980 | ret = e1000_do_write_eeprom(hw, offset, words, data); |
| 3981 | spin_unlock(&e1000_eeprom_lock); |
| 3982 | return ret; |
| 3983 | } |
| 3984 | |
| 3985 | |
| 3986 | static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) |
| 3987 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3988 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3989 | s32 status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3990 | |
| 3991 | DEBUGFUNC("e1000_write_eeprom"); |
| 3992 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3993 | /* If eeprom is not yet detected, do so now */ |
| 3994 | if (eeprom->word_size == 0) |
| 3995 | e1000_init_eeprom_params(hw); |
| 3996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | /* A check for invalid values: offset too large, too many words, and not |
| 3998 | * enough words. |
| 3999 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4000 | if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | (words == 0)) { |
| 4002 | DEBUGOUT("\"words\" parameter out of bounds\n"); |
| 4003 | return -E1000_ERR_EEPROM; |
| 4004 | } |
| 4005 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4006 | if (eeprom->use_eewr) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4007 | return e1000_write_eeprom_eewr(hw, offset, words, data); |
| 4008 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4009 | /* Prepare the EEPROM for writing */ |
| 4010 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) |
| 4011 | return -E1000_ERR_EEPROM; |
| 4012 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4013 | if (eeprom->type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4014 | status = e1000_write_eeprom_microwire(hw, offset, words, data); |
| 4015 | } else { |
| 4016 | status = e1000_write_eeprom_spi(hw, offset, words, data); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 4017 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | } |
| 4019 | |
| 4020 | /* Done with writing */ |
| 4021 | e1000_release_eeprom(hw); |
| 4022 | |
| 4023 | return status; |
| 4024 | } |
| 4025 | |
| 4026 | /****************************************************************************** |
| 4027 | * Writes a 16 bit word to a given offset in an SPI EEPROM. |
| 4028 | * |
| 4029 | * hw - Struct containing variables accessed by shared code |
| 4030 | * offset - offset within the EEPROM to be written to |
| 4031 | * words - number of words to write |
| 4032 | * data - pointer to array of 8 bit words to be written to the EEPROM |
| 4033 | * |
| 4034 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4035 | static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words, |
| 4036 | u16 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | { |
| 4038 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4039 | u16 widx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | |
| 4041 | DEBUGFUNC("e1000_write_eeprom_spi"); |
| 4042 | |
| 4043 | while (widx < words) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4044 | u8 write_opcode = EEPROM_WRITE_OPCODE_SPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4046 | if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | |
| 4048 | e1000_standby_eeprom(hw); |
| 4049 | |
| 4050 | /* Send the WRITE ENABLE command (8 bit opcode ) */ |
| 4051 | e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI, |
| 4052 | eeprom->opcode_bits); |
| 4053 | |
| 4054 | e1000_standby_eeprom(hw); |
| 4055 | |
| 4056 | /* Some SPI eeproms use the 8th address bit embedded in the opcode */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4057 | if ((eeprom->address_bits == 8) && (offset >= 128)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | write_opcode |= EEPROM_A8_OPCODE_SPI; |
| 4059 | |
| 4060 | /* Send the Write command (8-bit opcode + addr) */ |
| 4061 | e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits); |
| 4062 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4063 | e1000_shift_out_ee_bits(hw, (u16)((offset + widx)*2), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | eeprom->address_bits); |
| 4065 | |
| 4066 | /* Send the data */ |
| 4067 | |
| 4068 | /* Loop to allow for up to whole page write (32 bytes) of eeprom */ |
| 4069 | while (widx < words) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4070 | u16 word_out = data[widx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | word_out = (word_out >> 8) | (word_out << 8); |
| 4072 | e1000_shift_out_ee_bits(hw, word_out, 16); |
| 4073 | widx++; |
| 4074 | |
| 4075 | /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE |
| 4076 | * operation, while the smaller eeproms are capable of an 8-byte |
| 4077 | * PAGE WRITE operation. Break the inner loop to pass new address |
| 4078 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4079 | if ((((offset + widx)*2) % eeprom->page_size) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | e1000_standby_eeprom(hw); |
| 4081 | break; |
| 4082 | } |
| 4083 | } |
| 4084 | } |
| 4085 | |
| 4086 | return E1000_SUCCESS; |
| 4087 | } |
| 4088 | |
| 4089 | /****************************************************************************** |
| 4090 | * Writes a 16 bit word to a given offset in a Microwire EEPROM. |
| 4091 | * |
| 4092 | * hw - Struct containing variables accessed by shared code |
| 4093 | * offset - offset within the EEPROM to be written to |
| 4094 | * words - number of words to write |
| 4095 | * data - pointer to array of 16 bit words to be written to the EEPROM |
| 4096 | * |
| 4097 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4098 | static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset, |
| 4099 | u16 words, u16 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | { |
| 4101 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4102 | u32 eecd; |
| 4103 | u16 words_written = 0; |
| 4104 | u16 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4105 | |
| 4106 | DEBUGFUNC("e1000_write_eeprom_microwire"); |
| 4107 | |
| 4108 | /* Send the write enable command to the EEPROM (3-bit opcode plus |
| 4109 | * 6/8-bit dummy address beginning with 11). It's less work to include |
| 4110 | * the 11 of the dummy address as part of the opcode than it is to shift |
| 4111 | * it over the correct number of bits for the address. This puts the |
| 4112 | * EEPROM into write/erase mode. |
| 4113 | */ |
| 4114 | e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4115 | (u16)(eeprom->opcode_bits + 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4117 | e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | |
| 4119 | /* Prepare the EEPROM */ |
| 4120 | e1000_standby_eeprom(hw); |
| 4121 | |
| 4122 | while (words_written < words) { |
| 4123 | /* Send the Write command (3-bit opcode + addr) */ |
| 4124 | e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE, |
| 4125 | eeprom->opcode_bits); |
| 4126 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4127 | e1000_shift_out_ee_bits(hw, (u16)(offset + words_written), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | eeprom->address_bits); |
| 4129 | |
| 4130 | /* Send the data */ |
| 4131 | e1000_shift_out_ee_bits(hw, data[words_written], 16); |
| 4132 | |
| 4133 | /* Toggle the CS line. This in effect tells the EEPROM to execute |
| 4134 | * the previous command. |
| 4135 | */ |
| 4136 | e1000_standby_eeprom(hw); |
| 4137 | |
| 4138 | /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will |
| 4139 | * signal that the command has been completed by raising the DO signal. |
| 4140 | * If DO does not go high in 10 milliseconds, then error out. |
| 4141 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4142 | for (i = 0; i < 200; i++) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4143 | eecd = er32(EECD); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4144 | if (eecd & E1000_EECD_DO) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4145 | udelay(50); |
| 4146 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4147 | if (i == 200) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | DEBUGOUT("EEPROM Write did not complete\n"); |
| 4149 | return -E1000_ERR_EEPROM; |
| 4150 | } |
| 4151 | |
| 4152 | /* Recover from write */ |
| 4153 | e1000_standby_eeprom(hw); |
| 4154 | |
| 4155 | words_written++; |
| 4156 | } |
| 4157 | |
| 4158 | /* Send the write disable command to the EEPROM (3-bit opcode plus |
| 4159 | * 6/8-bit dummy address beginning with 10). It's less work to include |
| 4160 | * the 10 of the dummy address as part of the opcode than it is to shift |
| 4161 | * it over the correct number of bits for the address. This takes the |
| 4162 | * EEPROM out of write/erase mode. |
| 4163 | */ |
| 4164 | e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4165 | (u16)(eeprom->opcode_bits + 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4167 | e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4168 | |
| 4169 | return E1000_SUCCESS; |
| 4170 | } |
| 4171 | |
| 4172 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the |
| 4174 | * second function of dual function devices |
| 4175 | * |
| 4176 | * hw - Struct containing variables accessed by shared code |
| 4177 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4178 | s32 e1000_read_mac_addr(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4180 | u16 offset; |
| 4181 | u16 eeprom_data, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4182 | |
| 4183 | DEBUGFUNC("e1000_read_mac_addr"); |
| 4184 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4185 | for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | offset = i >> 1; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4187 | if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | DEBUGOUT("EEPROM Read Error\n"); |
| 4189 | return -E1000_ERR_EEPROM; |
| 4190 | } |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 4191 | hw->perm_mac_addr[i] = (u8)(eeprom_data & 0x00FF); |
| 4192 | hw->perm_mac_addr[i+1] = (u8)(eeprom_data >> 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4193 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4194 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4195 | switch (hw->mac_type) { |
| 4196 | default: |
| 4197 | break; |
| 4198 | case e1000_82546: |
| 4199 | case e1000_82546_rev_3: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4200 | if (er32(STATUS) & E1000_STATUS_FUNC_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | hw->perm_mac_addr[5] ^= 0x01; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4202 | break; |
| 4203 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4205 | for (i = 0; i < NODE_ADDRESS_SIZE; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4206 | hw->mac_addr[i] = hw->perm_mac_addr[i]; |
| 4207 | return E1000_SUCCESS; |
| 4208 | } |
| 4209 | |
| 4210 | /****************************************************************************** |
| 4211 | * Initializes receive address filters. |
| 4212 | * |
| 4213 | * hw - Struct containing variables accessed by shared code |
| 4214 | * |
| 4215 | * Places the MAC address in receive address register 0 and clears the rest |
| 4216 | * of the receive addresss registers. Clears the multicast table. Assumes |
| 4217 | * the receiver is in reset when the routine is called. |
| 4218 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4219 | static void e1000_init_rx_addrs(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4221 | u32 i; |
| 4222 | u32 rar_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 | |
| 4224 | DEBUGFUNC("e1000_init_rx_addrs"); |
| 4225 | |
| 4226 | /* Setup the receive address. */ |
| 4227 | DEBUGOUT("Programming MAC Address into RAR[0]\n"); |
| 4228 | |
| 4229 | e1000_rar_set(hw, hw->mac_addr, 0); |
| 4230 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4231 | rar_num = E1000_RAR_ENTRIES; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | /* Zero out the other 15 receive addresses. */ |
| 4234 | DEBUGOUT("Clearing RAR[1-15]\n"); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4235 | for (i = 1; i < rar_num; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4236 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4237 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4239 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | } |
| 4241 | } |
| 4242 | |
| 4243 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | * Hashes an address to determine its location in the multicast table |
| 4245 | * |
| 4246 | * hw - Struct containing variables accessed by shared code |
| 4247 | * mc_addr - the multicast address to hash |
| 4248 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4249 | u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4251 | u32 hash_value = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | |
| 4253 | /* The portion of the address that is used for the hash table is |
| 4254 | * determined by the mc_filter_type setting. |
| 4255 | */ |
| 4256 | switch (hw->mc_filter_type) { |
| 4257 | /* [0] [1] [2] [3] [4] [5] |
| 4258 | * 01 AA 00 12 34 56 |
| 4259 | * LSB MSB |
| 4260 | */ |
| 4261 | case 0: |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 4262 | /* [47:36] i.e. 0x563 for above example address */ |
| 4263 | hash_value = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | break; |
| 4265 | case 1: |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 4266 | /* [46:35] i.e. 0xAC6 for above example address */ |
| 4267 | hash_value = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | break; |
| 4269 | case 2: |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 4270 | /* [45:34] i.e. 0x5D8 for above example address */ |
| 4271 | hash_value = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | break; |
| 4273 | case 3: |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 4274 | /* [43:32] i.e. 0x634 for above example address */ |
| 4275 | hash_value = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | break; |
| 4277 | } |
| 4278 | |
| 4279 | hash_value &= 0xFFF; |
| 4280 | return hash_value; |
| 4281 | } |
| 4282 | |
| 4283 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | * Puts an ethernet address into a receive address register. |
| 4285 | * |
| 4286 | * hw - Struct containing variables accessed by shared code |
| 4287 | * addr - Address to put into receive address register |
| 4288 | * index - Receive address register to write |
| 4289 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4290 | void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4292 | u32 rar_low, rar_high; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | |
| 4294 | /* HW expects these in little endian so we reverse the byte order |
| 4295 | * from network order (big endian) to little endian |
| 4296 | */ |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 4297 | rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) | |
| 4298 | ((u32)addr[2] << 16) | ((u32)addr[3] << 24)); |
| 4299 | rar_high = ((u32)addr[4] | ((u32)addr[5] << 8)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | |
Jeff Kirsher | 8df06e5 | 2006-03-02 18:18:32 -0800 | [diff] [blame] | 4301 | /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx |
| 4302 | * unit hang. |
| 4303 | * |
| 4304 | * Description: |
| 4305 | * If there are any Rx frames queued up or otherwise present in the HW |
| 4306 | * before RSS is enabled, and then we enable RSS, the HW Rx unit will |
| 4307 | * hang. To work around this issue, we have to disable receives and |
| 4308 | * flush out all Rx frames before we enable RSS. To do so, we modify we |
| 4309 | * redirect all Rx traffic to manageability and then reset the HW. |
| 4310 | * This flushes away Rx frames, and (since the redirections to |
| 4311 | * manageability persists across resets) keeps new ones from coming in |
| 4312 | * while we work. Then, we clear the Address Valid AV bit for all MAC |
| 4313 | * addresses and undo the re-direction to manageability. |
| 4314 | * Now, frames are coming in again, but the MAC won't accept them, so |
| 4315 | * far so good. We now proceed to initialize RSS (if necessary) and |
| 4316 | * configure the Rx unit. Last, we re-enable the AV bits and continue |
| 4317 | * on our merry way. |
| 4318 | */ |
| 4319 | switch (hw->mac_type) { |
Jeff Kirsher | 8df06e5 | 2006-03-02 18:18:32 -0800 | [diff] [blame] | 4320 | default: |
| 4321 | /* Indicate to hardware the Address is Valid. */ |
| 4322 | rar_high |= E1000_RAH_AV; |
| 4323 | break; |
| 4324 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | |
| 4326 | E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4327 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4329 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | } |
| 4331 | |
| 4332 | /****************************************************************************** |
| 4333 | * Writes a value to the specified offset in the VLAN filter table. |
| 4334 | * |
| 4335 | * hw - Struct containing variables accessed by shared code |
| 4336 | * offset - Offset in VLAN filer table to write |
| 4337 | * value - Value to write into VLAN filter table |
| 4338 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4339 | void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4341 | u32 temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4343 | if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4344 | temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1)); |
| 4345 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4346 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4348 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | } else { |
| 4350 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4351 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4352 | } |
| 4353 | } |
| 4354 | |
| 4355 | /****************************************************************************** |
| 4356 | * Clears the VLAN filer table |
| 4357 | * |
| 4358 | * hw - Struct containing variables accessed by shared code |
| 4359 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4360 | static void e1000_clear_vfta(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4362 | u32 offset; |
| 4363 | u32 vfta_value = 0; |
| 4364 | u32 vfta_offset = 0; |
| 4365 | u32 vfta_bit_in_reg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4367 | for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) { |
| 4368 | /* If the offset we want to clear is the same offset of the |
| 4369 | * manageability VLAN ID, then clear all bits except that of the |
| 4370 | * manageability unit */ |
| 4371 | vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0; |
| 4372 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4373 | E1000_WRITE_FLUSH(); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4374 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4375 | } |
| 4376 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4377 | static s32 e1000_id_led_init(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4378 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4379 | u32 ledctl; |
| 4380 | const u32 ledctl_mask = 0x000000FF; |
| 4381 | const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON; |
| 4382 | const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF; |
| 4383 | u16 eeprom_data, i, temp; |
| 4384 | const u16 led_mask = 0x0F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | |
| 4386 | DEBUGFUNC("e1000_id_led_init"); |
| 4387 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4388 | if (hw->mac_type < e1000_82540) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4389 | /* Nothing to do */ |
| 4390 | return E1000_SUCCESS; |
| 4391 | } |
| 4392 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4393 | ledctl = er32(LEDCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4394 | hw->ledctl_default = ledctl; |
| 4395 | hw->ledctl_mode1 = hw->ledctl_default; |
| 4396 | hw->ledctl_mode2 = hw->ledctl_default; |
| 4397 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4398 | if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | DEBUGOUT("EEPROM Read Error\n"); |
| 4400 | return -E1000_ERR_EEPROM; |
| 4401 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4402 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 4403 | if ((eeprom_data == ID_LED_RESERVED_0000) || |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4404 | (eeprom_data == ID_LED_RESERVED_FFFF)) { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4405 | eeprom_data = ID_LED_DEFAULT; |
| 4406 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4407 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4408 | for (i = 0; i < 4; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4409 | temp = (eeprom_data >> (i << 2)) & led_mask; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4410 | switch (temp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4411 | case ID_LED_ON1_DEF2: |
| 4412 | case ID_LED_ON1_ON2: |
| 4413 | case ID_LED_ON1_OFF2: |
| 4414 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); |
| 4415 | hw->ledctl_mode1 |= ledctl_on << (i << 3); |
| 4416 | break; |
| 4417 | case ID_LED_OFF1_DEF2: |
| 4418 | case ID_LED_OFF1_ON2: |
| 4419 | case ID_LED_OFF1_OFF2: |
| 4420 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); |
| 4421 | hw->ledctl_mode1 |= ledctl_off << (i << 3); |
| 4422 | break; |
| 4423 | default: |
| 4424 | /* Do nothing */ |
| 4425 | break; |
| 4426 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4427 | switch (temp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | case ID_LED_DEF1_ON2: |
| 4429 | case ID_LED_ON1_ON2: |
| 4430 | case ID_LED_OFF1_ON2: |
| 4431 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); |
| 4432 | hw->ledctl_mode2 |= ledctl_on << (i << 3); |
| 4433 | break; |
| 4434 | case ID_LED_DEF1_OFF2: |
| 4435 | case ID_LED_ON1_OFF2: |
| 4436 | case ID_LED_OFF1_OFF2: |
| 4437 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); |
| 4438 | hw->ledctl_mode2 |= ledctl_off << (i << 3); |
| 4439 | break; |
| 4440 | default: |
| 4441 | /* Do nothing */ |
| 4442 | break; |
| 4443 | } |
| 4444 | } |
| 4445 | return E1000_SUCCESS; |
| 4446 | } |
| 4447 | |
| 4448 | /****************************************************************************** |
| 4449 | * Prepares SW controlable LED for use and saves the current state of the LED. |
| 4450 | * |
| 4451 | * hw - Struct containing variables accessed by shared code |
| 4452 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4453 | s32 e1000_setup_led(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4454 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4455 | u32 ledctl; |
| 4456 | s32 ret_val = E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | |
| 4458 | DEBUGFUNC("e1000_setup_led"); |
| 4459 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4460 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | case e1000_82542_rev2_0: |
| 4462 | case e1000_82542_rev2_1: |
| 4463 | case e1000_82543: |
| 4464 | case e1000_82544: |
| 4465 | /* No setup necessary */ |
| 4466 | break; |
| 4467 | case e1000_82541: |
| 4468 | case e1000_82547: |
| 4469 | case e1000_82541_rev_2: |
| 4470 | case e1000_82547_rev_2: |
| 4471 | /* Turn off PHY Smart Power Down (if enabled) */ |
| 4472 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 4473 | &hw->phy_spd_default); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4474 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | return ret_val; |
| 4476 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4477 | (u16)(hw->phy_spd_default & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | ~IGP01E1000_GMII_SPD)); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4479 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | return ret_val; |
| 4481 | /* Fall Through */ |
| 4482 | default: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4483 | if (hw->media_type == e1000_media_type_fiber) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4484 | ledctl = er32(LEDCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | /* Save current LEDCTL settings */ |
| 4486 | hw->ledctl_default = ledctl; |
| 4487 | /* Turn off LED0 */ |
| 4488 | ledctl &= ~(E1000_LEDCTL_LED0_IVRT | |
| 4489 | E1000_LEDCTL_LED0_BLINK | |
| 4490 | E1000_LEDCTL_LED0_MODE_MASK); |
| 4491 | ledctl |= (E1000_LEDCTL_MODE_LED_OFF << |
| 4492 | E1000_LEDCTL_LED0_MODE_SHIFT); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4493 | ew32(LEDCTL, ledctl); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4494 | } else if (hw->media_type == e1000_media_type_copper) |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4495 | ew32(LEDCTL, hw->ledctl_mode1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | break; |
| 4497 | } |
| 4498 | |
| 4499 | return E1000_SUCCESS; |
| 4500 | } |
| 4501 | |
Auke Kok | f1b3a85 | 2006-06-27 09:07:56 -0700 | [diff] [blame] | 4502 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4503 | * Restores the saved state of the SW controlable LED. |
| 4504 | * |
| 4505 | * hw - Struct containing variables accessed by shared code |
| 4506 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4507 | s32 e1000_cleanup_led(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4508 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4509 | s32 ret_val = E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | |
| 4511 | DEBUGFUNC("e1000_cleanup_led"); |
| 4512 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4513 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | case e1000_82542_rev2_0: |
| 4515 | case e1000_82542_rev2_1: |
| 4516 | case e1000_82543: |
| 4517 | case e1000_82544: |
| 4518 | /* No cleanup necessary */ |
| 4519 | break; |
| 4520 | case e1000_82541: |
| 4521 | case e1000_82547: |
| 4522 | case e1000_82541_rev_2: |
| 4523 | case e1000_82547_rev_2: |
| 4524 | /* Turn on PHY Smart Power Down (if previously enabled) */ |
| 4525 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 4526 | hw->phy_spd_default); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4527 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4528 | return ret_val; |
| 4529 | /* Fall Through */ |
| 4530 | default: |
| 4531 | /* Restore LEDCTL settings */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4532 | ew32(LEDCTL, hw->ledctl_default); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4533 | break; |
| 4534 | } |
| 4535 | |
| 4536 | return E1000_SUCCESS; |
| 4537 | } |
| 4538 | |
| 4539 | /****************************************************************************** |
| 4540 | * Turns on the software controllable LED |
| 4541 | * |
| 4542 | * hw - Struct containing variables accessed by shared code |
| 4543 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4544 | s32 e1000_led_on(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4546 | u32 ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | |
| 4548 | DEBUGFUNC("e1000_led_on"); |
| 4549 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4550 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | case e1000_82542_rev2_0: |
| 4552 | case e1000_82542_rev2_1: |
| 4553 | case e1000_82543: |
| 4554 | /* Set SW Defineable Pin 0 to turn on the LED */ |
| 4555 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4556 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4557 | break; |
| 4558 | case e1000_82544: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4559 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | /* Set SW Defineable Pin 0 to turn on the LED */ |
| 4561 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4562 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4563 | } else { |
| 4564 | /* Clear SW Defineable Pin 0 to turn on the LED */ |
| 4565 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4566 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4567 | } |
| 4568 | break; |
| 4569 | default: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4570 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4571 | /* Clear SW Defineable Pin 0 to turn on the LED */ |
| 4572 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4573 | ctrl |= E1000_CTRL_SWDPIO0; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4574 | } else if (hw->media_type == e1000_media_type_copper) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4575 | ew32(LEDCTL, hw->ledctl_mode2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | return E1000_SUCCESS; |
| 4577 | } |
| 4578 | break; |
| 4579 | } |
| 4580 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4581 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4582 | |
| 4583 | return E1000_SUCCESS; |
| 4584 | } |
| 4585 | |
| 4586 | /****************************************************************************** |
| 4587 | * Turns off the software controllable LED |
| 4588 | * |
| 4589 | * hw - Struct containing variables accessed by shared code |
| 4590 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4591 | s32 e1000_led_off(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4593 | u32 ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4594 | |
| 4595 | DEBUGFUNC("e1000_led_off"); |
| 4596 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4597 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4598 | case e1000_82542_rev2_0: |
| 4599 | case e1000_82542_rev2_1: |
| 4600 | case e1000_82543: |
| 4601 | /* Clear SW Defineable Pin 0 to turn off the LED */ |
| 4602 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4603 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4604 | break; |
| 4605 | case e1000_82544: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4606 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4607 | /* Clear SW Defineable Pin 0 to turn off the LED */ |
| 4608 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4609 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4610 | } else { |
| 4611 | /* Set SW Defineable Pin 0 to turn off the LED */ |
| 4612 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4613 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4614 | } |
| 4615 | break; |
| 4616 | default: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4617 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | /* Set SW Defineable Pin 0 to turn off the LED */ |
| 4619 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4620 | ctrl |= E1000_CTRL_SWDPIO0; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4621 | } else if (hw->media_type == e1000_media_type_copper) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4622 | ew32(LEDCTL, hw->ledctl_mode1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | return E1000_SUCCESS; |
| 4624 | } |
| 4625 | break; |
| 4626 | } |
| 4627 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4628 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4629 | |
| 4630 | return E1000_SUCCESS; |
| 4631 | } |
| 4632 | |
| 4633 | /****************************************************************************** |
| 4634 | * Clears all hardware statistics counters. |
| 4635 | * |
| 4636 | * hw - Struct containing variables accessed by shared code |
| 4637 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4638 | static void e1000_clear_hw_cntrs(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4640 | volatile u32 temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4642 | temp = er32(CRCERRS); |
| 4643 | temp = er32(SYMERRS); |
| 4644 | temp = er32(MPC); |
| 4645 | temp = er32(SCC); |
| 4646 | temp = er32(ECOL); |
| 4647 | temp = er32(MCC); |
| 4648 | temp = er32(LATECOL); |
| 4649 | temp = er32(COLC); |
| 4650 | temp = er32(DC); |
| 4651 | temp = er32(SEC); |
| 4652 | temp = er32(RLEC); |
| 4653 | temp = er32(XONRXC); |
| 4654 | temp = er32(XONTXC); |
| 4655 | temp = er32(XOFFRXC); |
| 4656 | temp = er32(XOFFTXC); |
| 4657 | temp = er32(FCRUC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4658 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4659 | temp = er32(PRC64); |
| 4660 | temp = er32(PRC127); |
| 4661 | temp = er32(PRC255); |
| 4662 | temp = er32(PRC511); |
| 4663 | temp = er32(PRC1023); |
| 4664 | temp = er32(PRC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4665 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4666 | temp = er32(GPRC); |
| 4667 | temp = er32(BPRC); |
| 4668 | temp = er32(MPRC); |
| 4669 | temp = er32(GPTC); |
| 4670 | temp = er32(GORCL); |
| 4671 | temp = er32(GORCH); |
| 4672 | temp = er32(GOTCL); |
| 4673 | temp = er32(GOTCH); |
| 4674 | temp = er32(RNBC); |
| 4675 | temp = er32(RUC); |
| 4676 | temp = er32(RFC); |
| 4677 | temp = er32(ROC); |
| 4678 | temp = er32(RJC); |
| 4679 | temp = er32(TORL); |
| 4680 | temp = er32(TORH); |
| 4681 | temp = er32(TOTL); |
| 4682 | temp = er32(TOTH); |
| 4683 | temp = er32(TPR); |
| 4684 | temp = er32(TPT); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4685 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4686 | temp = er32(PTC64); |
| 4687 | temp = er32(PTC127); |
| 4688 | temp = er32(PTC255); |
| 4689 | temp = er32(PTC511); |
| 4690 | temp = er32(PTC1023); |
| 4691 | temp = er32(PTC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4692 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4693 | temp = er32(MPTC); |
| 4694 | temp = er32(BPTC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4695 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4696 | if (hw->mac_type < e1000_82543) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4698 | temp = er32(ALGNERRC); |
| 4699 | temp = er32(RXERRC); |
| 4700 | temp = er32(TNCRS); |
| 4701 | temp = er32(CEXTERR); |
| 4702 | temp = er32(TSCTC); |
| 4703 | temp = er32(TSCTFC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4704 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4705 | if (hw->mac_type <= e1000_82544) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4706 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4707 | temp = er32(MGTPRC); |
| 4708 | temp = er32(MGTPDC); |
| 4709 | temp = er32(MGTPTC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | } |
| 4711 | |
| 4712 | /****************************************************************************** |
| 4713 | * Resets Adaptive IFS to its default state. |
| 4714 | * |
| 4715 | * hw - Struct containing variables accessed by shared code |
| 4716 | * |
| 4717 | * 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] | 4718 | * hw->ifs_params_forced to true. However, you must initialize hw-> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio |
| 4720 | * before calling this function. |
| 4721 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4722 | void e1000_reset_adaptive(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4723 | { |
| 4724 | DEBUGFUNC("e1000_reset_adaptive"); |
| 4725 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4726 | if (hw->adaptive_ifs) { |
| 4727 | if (!hw->ifs_params_forced) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4728 | hw->current_ifs_val = 0; |
| 4729 | hw->ifs_min_val = IFS_MIN; |
| 4730 | hw->ifs_max_val = IFS_MAX; |
| 4731 | hw->ifs_step_size = IFS_STEP; |
| 4732 | hw->ifs_ratio = IFS_RATIO; |
| 4733 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4734 | hw->in_ifs_mode = false; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4735 | ew32(AIT, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4736 | } else { |
| 4737 | DEBUGOUT("Not in Adaptive IFS mode!\n"); |
| 4738 | } |
| 4739 | } |
| 4740 | |
| 4741 | /****************************************************************************** |
| 4742 | * Called during the callback/watchdog routine to update IFS value based on |
| 4743 | * the ratio of transmits to collisions. |
| 4744 | * |
| 4745 | * hw - Struct containing variables accessed by shared code |
| 4746 | * tx_packets - Number of transmits since last callback |
| 4747 | * total_collisions - Number of collisions since last callback |
| 4748 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4749 | void e1000_update_adaptive(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4750 | { |
| 4751 | DEBUGFUNC("e1000_update_adaptive"); |
| 4752 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4753 | if (hw->adaptive_ifs) { |
| 4754 | if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) { |
| 4755 | if (hw->tx_packet_delta > MIN_NUM_XMITS) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4756 | hw->in_ifs_mode = true; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4757 | if (hw->current_ifs_val < hw->ifs_max_val) { |
| 4758 | if (hw->current_ifs_val == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4759 | hw->current_ifs_val = hw->ifs_min_val; |
| 4760 | else |
| 4761 | hw->current_ifs_val += hw->ifs_step_size; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4762 | ew32(AIT, hw->current_ifs_val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4763 | } |
| 4764 | } |
| 4765 | } else { |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4766 | if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4767 | hw->current_ifs_val = 0; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4768 | hw->in_ifs_mode = false; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4769 | ew32(AIT, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4770 | } |
| 4771 | } |
| 4772 | } else { |
| 4773 | DEBUGOUT("Not in Adaptive IFS mode!\n"); |
| 4774 | } |
| 4775 | } |
| 4776 | |
| 4777 | /****************************************************************************** |
| 4778 | * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT |
| 4779 | * |
| 4780 | * hw - Struct containing variables accessed by shared code |
| 4781 | * frame_len - The length of the frame in question |
| 4782 | * mac_addr - The Ethernet destination address of the frame in question |
| 4783 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4784 | void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats, |
| 4785 | u32 frame_len, u8 *mac_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4787 | u64 carry_bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4788 | |
| 4789 | /* First adjust the frame length. */ |
| 4790 | frame_len--; |
| 4791 | /* We need to adjust the statistics counters, since the hardware |
| 4792 | * counters overcount this packet as a CRC error and undercount |
| 4793 | * the packet as a good packet |
| 4794 | */ |
| 4795 | /* This packet should not be counted as a CRC error. */ |
| 4796 | stats->crcerrs--; |
| 4797 | /* This packet does count as a Good Packet Received. */ |
| 4798 | stats->gprc++; |
| 4799 | |
| 4800 | /* Adjust the Good Octets received counters */ |
| 4801 | carry_bit = 0x80000000 & stats->gorcl; |
| 4802 | stats->gorcl += frame_len; |
| 4803 | /* If the high bit of Gorcl (the low 32 bits of the Good Octets |
| 4804 | * Received Count) was one before the addition, |
| 4805 | * AND it is zero after, then we lost the carry out, |
| 4806 | * need to add one to Gorch (Good Octets Received Count High). |
| 4807 | * This could be simplified if all environments supported |
| 4808 | * 64-bit integers. |
| 4809 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4810 | if (carry_bit && ((stats->gorcl & 0x80000000) == 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | stats->gorch++; |
| 4812 | /* Is this a broadcast or multicast? Check broadcast first, |
| 4813 | * since the test for a multicast frame will test positive on |
| 4814 | * a broadcast frame. |
| 4815 | */ |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 4816 | if ((mac_addr[0] == (u8)0xff) && (mac_addr[1] == (u8)0xff)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4817 | /* Broadcast packet */ |
| 4818 | stats->bprc++; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4819 | else if (*mac_addr & 0x01) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4820 | /* Multicast packet */ |
| 4821 | stats->mprc++; |
| 4822 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4823 | if (frame_len == hw->max_frame_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4824 | /* In this case, the hardware has overcounted the number of |
| 4825 | * oversize frames. |
| 4826 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4827 | if (stats->roc > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | stats->roc--; |
| 4829 | } |
| 4830 | |
| 4831 | /* Adjust the bin counters when the extra byte put the frame in the |
| 4832 | * wrong bin. Remember that the frame_len was adjusted above. |
| 4833 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4834 | if (frame_len == 64) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | stats->prc64++; |
| 4836 | stats->prc127--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4837 | } else if (frame_len == 127) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4838 | stats->prc127++; |
| 4839 | stats->prc255--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4840 | } else if (frame_len == 255) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4841 | stats->prc255++; |
| 4842 | stats->prc511--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4843 | } else if (frame_len == 511) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | stats->prc511++; |
| 4845 | stats->prc1023--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4846 | } else if (frame_len == 1023) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4847 | stats->prc1023++; |
| 4848 | stats->prc1522--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4849 | } else if (frame_len == 1522) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | stats->prc1522++; |
| 4851 | } |
| 4852 | } |
| 4853 | |
| 4854 | /****************************************************************************** |
| 4855 | * Gets the current PCI bus type, speed, and width of the hardware |
| 4856 | * |
| 4857 | * hw - Struct containing variables accessed by shared code |
| 4858 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4859 | void e1000_get_bus_info(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4860 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4861 | u32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | |
| 4863 | switch (hw->mac_type) { |
| 4864 | case e1000_82542_rev2_0: |
| 4865 | case e1000_82542_rev2_1: |
Jeff Kirsher | c3813ae | 2006-12-15 10:37:32 +0100 | [diff] [blame] | 4866 | hw->bus_type = e1000_bus_type_pci; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4867 | hw->bus_speed = e1000_bus_speed_unknown; |
| 4868 | hw->bus_width = e1000_bus_width_unknown; |
| 4869 | break; |
| 4870 | default: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4871 | status = er32(STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4872 | hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ? |
| 4873 | e1000_bus_type_pcix : e1000_bus_type_pci; |
| 4874 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4875 | if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4876 | hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ? |
| 4877 | e1000_bus_speed_66 : e1000_bus_speed_120; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4878 | } else if (hw->bus_type == e1000_bus_type_pci) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4879 | hw->bus_speed = (status & E1000_STATUS_PCI66) ? |
| 4880 | e1000_bus_speed_66 : e1000_bus_speed_33; |
| 4881 | } else { |
| 4882 | switch (status & E1000_STATUS_PCIX_SPEED) { |
| 4883 | case E1000_STATUS_PCIX_SPEED_66: |
| 4884 | hw->bus_speed = e1000_bus_speed_66; |
| 4885 | break; |
| 4886 | case E1000_STATUS_PCIX_SPEED_100: |
| 4887 | hw->bus_speed = e1000_bus_speed_100; |
| 4888 | break; |
| 4889 | case E1000_STATUS_PCIX_SPEED_133: |
| 4890 | hw->bus_speed = e1000_bus_speed_133; |
| 4891 | break; |
| 4892 | default: |
| 4893 | hw->bus_speed = e1000_bus_speed_reserved; |
| 4894 | break; |
| 4895 | } |
| 4896 | } |
| 4897 | hw->bus_width = (status & E1000_STATUS_BUS64) ? |
| 4898 | e1000_bus_width_64 : e1000_bus_width_32; |
| 4899 | break; |
| 4900 | } |
| 4901 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4902 | |
| 4903 | /****************************************************************************** |
| 4904 | * Writes a value to one of the devices registers using port I/O (as opposed to |
| 4905 | * memory mapped I/O). Only 82544 and newer devices support port I/O. |
| 4906 | * |
| 4907 | * hw - Struct containing variables accessed by shared code |
| 4908 | * offset - offset to write to |
| 4909 | * value - value to write |
| 4910 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4911 | 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] | 4912 | { |
| 4913 | unsigned long io_addr = hw->io_base; |
| 4914 | unsigned long io_data = hw->io_base + 4; |
| 4915 | |
| 4916 | e1000_io_write(hw, io_addr, offset); |
| 4917 | e1000_io_write(hw, io_data, value); |
| 4918 | } |
| 4919 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | /****************************************************************************** |
| 4921 | * Estimates the cable length. |
| 4922 | * |
| 4923 | * hw - Struct containing variables accessed by shared code |
| 4924 | * min_length - The estimated minimum length |
| 4925 | * max_length - The estimated maximum length |
| 4926 | * |
| 4927 | * returns: - E1000_ERR_XXX |
| 4928 | * E1000_SUCCESS |
| 4929 | * |
| 4930 | * This function always returns a ranged length (minimum & maximum). |
| 4931 | * So for M88 phy's, this function interprets the one value returned from the |
| 4932 | * register to the minimum and maximum range. |
| 4933 | * For IGP phy's, the function calculates the range by the AGC registers. |
| 4934 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4935 | static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length, |
| 4936 | u16 *max_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4938 | s32 ret_val; |
| 4939 | u16 agc_value = 0; |
| 4940 | u16 i, phy_data; |
| 4941 | u16 cable_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4942 | |
| 4943 | DEBUGFUNC("e1000_get_cable_length"); |
| 4944 | |
| 4945 | *min_length = *max_length = 0; |
| 4946 | |
| 4947 | /* Use old method for Phy older than IGP */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4948 | if (hw->phy_type == e1000_phy_m88) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4949 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4950 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 4951 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4952 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4953 | return ret_val; |
| 4954 | cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >> |
| 4955 | M88E1000_PSSR_CABLE_LENGTH_SHIFT; |
| 4956 | |
| 4957 | /* Convert the enum value to ranged values */ |
| 4958 | switch (cable_length) { |
| 4959 | case e1000_cable_length_50: |
| 4960 | *min_length = 0; |
| 4961 | *max_length = e1000_igp_cable_length_50; |
| 4962 | break; |
| 4963 | case e1000_cable_length_50_80: |
| 4964 | *min_length = e1000_igp_cable_length_50; |
| 4965 | *max_length = e1000_igp_cable_length_80; |
| 4966 | break; |
| 4967 | case e1000_cable_length_80_110: |
| 4968 | *min_length = e1000_igp_cable_length_80; |
| 4969 | *max_length = e1000_igp_cable_length_110; |
| 4970 | break; |
| 4971 | case e1000_cable_length_110_140: |
| 4972 | *min_length = e1000_igp_cable_length_110; |
| 4973 | *max_length = e1000_igp_cable_length_140; |
| 4974 | break; |
| 4975 | case e1000_cable_length_140: |
| 4976 | *min_length = e1000_igp_cable_length_140; |
| 4977 | *max_length = e1000_igp_cable_length_170; |
| 4978 | break; |
| 4979 | default: |
| 4980 | return -E1000_ERR_PHY; |
| 4981 | break; |
| 4982 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4983 | } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4984 | u16 cur_agc_value; |
| 4985 | u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE; |
| 4986 | u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4987 | {IGP01E1000_PHY_AGC_A, |
| 4988 | IGP01E1000_PHY_AGC_B, |
| 4989 | IGP01E1000_PHY_AGC_C, |
| 4990 | IGP01E1000_PHY_AGC_D}; |
| 4991 | /* Read the AGC registers for all channels */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4992 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4993 | |
| 4994 | ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4995 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4996 | return ret_val; |
| 4997 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4998 | cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4999 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5000 | /* Value bound check. */ |
| 5001 | if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) || |
| 5002 | (cur_agc_value == 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5003 | return -E1000_ERR_PHY; |
| 5004 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5005 | agc_value += cur_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5006 | |
| 5007 | /* Update minimal AGC value. */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5008 | if (min_agc_value > cur_agc_value) |
| 5009 | min_agc_value = cur_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5010 | } |
| 5011 | |
| 5012 | /* Remove the minimal AGC result for length < 50m */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5013 | if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) { |
| 5014 | agc_value -= min_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5015 | |
| 5016 | /* Get the average length of the remaining 3 channels */ |
| 5017 | agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1); |
| 5018 | } else { |
| 5019 | /* Get the average length of all the 4 channels. */ |
| 5020 | agc_value /= IGP01E1000_PHY_CHANNEL_NUM; |
| 5021 | } |
| 5022 | |
| 5023 | /* Set the range of the calculated length. */ |
| 5024 | *min_length = ((e1000_igp_cable_length_table[agc_value] - |
| 5025 | IGP01E1000_AGC_RANGE) > 0) ? |
| 5026 | (e1000_igp_cable_length_table[agc_value] - |
| 5027 | IGP01E1000_AGC_RANGE) : 0; |
| 5028 | *max_length = e1000_igp_cable_length_table[agc_value] + |
| 5029 | IGP01E1000_AGC_RANGE; |
| 5030 | } |
| 5031 | |
| 5032 | return E1000_SUCCESS; |
| 5033 | } |
| 5034 | |
| 5035 | /****************************************************************************** |
| 5036 | * Check the cable polarity |
| 5037 | * |
| 5038 | * hw - Struct containing variables accessed by shared code |
| 5039 | * polarity - output parameter : 0 - Polarity is not reversed |
| 5040 | * 1 - Polarity is reversed. |
| 5041 | * |
| 5042 | * returns: - E1000_ERR_XXX |
| 5043 | * E1000_SUCCESS |
| 5044 | * |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 5045 | * 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] | 5046 | * Phy Status register. For IGP phy's, this bit is valid only if link speed is |
| 5047 | * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will |
| 5048 | * return 0. If the link speed is 1000 Mbps the polarity status is in the |
| 5049 | * IGP01E1000_PHY_PCS_INIT_REG. |
| 5050 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5051 | static s32 e1000_check_polarity(struct e1000_hw *hw, |
| 5052 | e1000_rev_polarity *polarity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5053 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5054 | s32 ret_val; |
| 5055 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5056 | |
| 5057 | DEBUGFUNC("e1000_check_polarity"); |
| 5058 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 5059 | if (hw->phy_type == e1000_phy_m88) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5060 | /* return the Polarity bit in the Status register. */ |
| 5061 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 5062 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5063 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5064 | return ret_val; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 5065 | *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >> |
| 5066 | M88E1000_PSSR_REV_POLARITY_SHIFT) ? |
| 5067 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
| 5068 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 5069 | } else if (hw->phy_type == e1000_phy_igp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5070 | /* Read the Status register to check the speed */ |
| 5071 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, |
| 5072 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5073 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5074 | return ret_val; |
| 5075 | |
| 5076 | /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to |
| 5077 | * find the polarity status */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5078 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5079 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
| 5080 | |
| 5081 | /* Read the GIG initialization PCS register (0x00B4) */ |
| 5082 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG, |
| 5083 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5084 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5085 | return ret_val; |
| 5086 | |
| 5087 | /* Check the polarity bits */ |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 5088 | *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? |
| 5089 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5090 | } else { |
| 5091 | /* For 10 Mbps, read the polarity bit in the status register. (for |
| 5092 | * 100 Mbps this bit is always 0) */ |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 5093 | *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ? |
| 5094 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5095 | } |
| 5096 | } |
| 5097 | return E1000_SUCCESS; |
| 5098 | } |
| 5099 | |
| 5100 | /****************************************************************************** |
| 5101 | * Check if Downshift occured |
| 5102 | * |
| 5103 | * hw - Struct containing variables accessed by shared code |
| 5104 | * downshift - output parameter : 0 - No Downshift ocured. |
| 5105 | * 1 - Downshift ocured. |
| 5106 | * |
| 5107 | * returns: - E1000_ERR_XXX |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5108 | * E1000_SUCCESS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5109 | * |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 5110 | * 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] | 5111 | * Specific Status register. For IGP phy's, it reads the Downgrade bit in the |
| 5112 | * Link Health register. In IGP this bit is latched high, so the driver must |
| 5113 | * read it immediately after link is established. |
| 5114 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5115 | static s32 e1000_check_downshift(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5116 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5117 | s32 ret_val; |
| 5118 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5119 | |
| 5120 | DEBUGFUNC("e1000_check_downshift"); |
| 5121 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 5122 | if (hw->phy_type == e1000_phy_igp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5123 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH, |
| 5124 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5125 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5126 | return ret_val; |
| 5127 | |
| 5128 | hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0; |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 5129 | } else if (hw->phy_type == e1000_phy_m88) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 5131 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5132 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5133 | return ret_val; |
| 5134 | |
| 5135 | hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >> |
| 5136 | M88E1000_PSSR_DOWNSHIFT_SHIFT; |
| 5137 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5139 | return E1000_SUCCESS; |
| 5140 | } |
| 5141 | |
| 5142 | /***************************************************************************** |
| 5143 | * |
| 5144 | * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a |
| 5145 | * gigabit link is achieved to improve link quality. |
| 5146 | * |
| 5147 | * hw: Struct containing variables accessed by shared code |
| 5148 | * |
| 5149 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 5150 | * E1000_SUCCESS at any other case. |
| 5151 | * |
| 5152 | ****************************************************************************/ |
| 5153 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5154 | 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] | 5155 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5156 | s32 ret_val; |
| 5157 | u16 phy_data, phy_saved_data, speed, duplex, i; |
| 5158 | u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5159 | {IGP01E1000_PHY_AGC_PARAM_A, |
| 5160 | IGP01E1000_PHY_AGC_PARAM_B, |
| 5161 | IGP01E1000_PHY_AGC_PARAM_C, |
| 5162 | IGP01E1000_PHY_AGC_PARAM_D}; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5163 | u16 min_length, max_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | |
| 5165 | DEBUGFUNC("e1000_config_dsp_after_link_change"); |
| 5166 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5167 | if (hw->phy_type != e1000_phy_igp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5168 | return E1000_SUCCESS; |
| 5169 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5170 | if (link_up) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5171 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5172 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5173 | DEBUGOUT("Error getting link speed and duplex\n"); |
| 5174 | return ret_val; |
| 5175 | } |
| 5176 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5177 | if (speed == SPEED_1000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5178 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5179 | ret_val = e1000_get_cable_length(hw, &min_length, &max_length); |
| 5180 | if (ret_val) |
| 5181 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5182 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5183 | if ((hw->dsp_config_state == e1000_dsp_config_enabled) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5184 | min_length >= e1000_igp_cable_length_50) { |
| 5185 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5186 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5187 | ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], |
| 5188 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5189 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5190 | return ret_val; |
| 5191 | |
| 5192 | phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX; |
| 5193 | |
| 5194 | ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i], |
| 5195 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5196 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5197 | return ret_val; |
| 5198 | } |
| 5199 | hw->dsp_config_state = e1000_dsp_config_activated; |
| 5200 | } |
| 5201 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5202 | if ((hw->ffe_config_state == e1000_ffe_config_enabled) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5203 | (min_length < e1000_igp_cable_length_50)) { |
| 5204 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5205 | u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20; |
| 5206 | u32 idle_errs = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5207 | |
| 5208 | /* clear previous idle error counts */ |
| 5209 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, |
| 5210 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5211 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5212 | return ret_val; |
| 5213 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5214 | for (i = 0; i < ffe_idle_err_timeout; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5215 | udelay(1000); |
| 5216 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, |
| 5217 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5218 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5219 | return ret_val; |
| 5220 | |
| 5221 | idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5222 | if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5223 | hw->ffe_config_state = e1000_ffe_config_active; |
| 5224 | |
| 5225 | ret_val = e1000_write_phy_reg(hw, |
| 5226 | IGP01E1000_PHY_DSP_FFE, |
| 5227 | IGP01E1000_PHY_DSP_FFE_CM_CP); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5228 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5229 | return ret_val; |
| 5230 | break; |
| 5231 | } |
| 5232 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5233 | if (idle_errs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5234 | ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100; |
| 5235 | } |
| 5236 | } |
| 5237 | } |
| 5238 | } else { |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5239 | if (hw->dsp_config_state == e1000_dsp_config_activated) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5240 | /* Save off the current value of register 0x2F5B to be restored at |
| 5241 | * the end of the routines. */ |
| 5242 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
| 5243 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5244 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5245 | return ret_val; |
| 5246 | |
| 5247 | /* Disable the PHY transmitter */ |
| 5248 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 5249 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5250 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5251 | return ret_val; |
| 5252 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5253 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5254 | |
| 5255 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 5256 | IGP01E1000_IEEE_FORCE_GIGA); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5257 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5258 | return ret_val; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5259 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5260 | ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5261 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5262 | return ret_val; |
| 5263 | |
| 5264 | phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX; |
| 5265 | phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS; |
| 5266 | |
| 5267 | ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5268 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5269 | return ret_val; |
| 5270 | } |
| 5271 | |
| 5272 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 5273 | IGP01E1000_IEEE_RESTART_AUTONEG); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5274 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5275 | return ret_val; |
| 5276 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5277 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5278 | |
| 5279 | /* Now enable the transmitter */ |
| 5280 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
| 5281 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5282 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5283 | return ret_val; |
| 5284 | |
| 5285 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 5286 | } |
| 5287 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5288 | if (hw->ffe_config_state == e1000_ffe_config_active) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5289 | /* Save off the current value of register 0x2F5B to be restored at |
| 5290 | * the end of the routines. */ |
| 5291 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
| 5292 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5293 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5294 | return ret_val; |
| 5295 | |
| 5296 | /* Disable the PHY transmitter */ |
| 5297 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 5298 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5299 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5300 | return ret_val; |
| 5301 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5302 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5303 | |
| 5304 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 5305 | IGP01E1000_IEEE_FORCE_GIGA); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5306 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5307 | return ret_val; |
| 5308 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE, |
| 5309 | IGP01E1000_PHY_DSP_FFE_DEFAULT); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5310 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5311 | return ret_val; |
| 5312 | |
| 5313 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 5314 | IGP01E1000_IEEE_RESTART_AUTONEG); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5315 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5316 | return ret_val; |
| 5317 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5318 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5319 | |
| 5320 | /* Now enable the transmitter */ |
| 5321 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
| 5322 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5323 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5324 | return ret_val; |
| 5325 | |
| 5326 | hw->ffe_config_state = e1000_ffe_config_enabled; |
| 5327 | } |
| 5328 | } |
| 5329 | return E1000_SUCCESS; |
| 5330 | } |
| 5331 | |
| 5332 | /***************************************************************************** |
| 5333 | * Set PHY to class A mode |
| 5334 | * Assumes the following operations will follow to enable the new class mode. |
| 5335 | * 1. Do a PHY soft reset |
| 5336 | * 2. Restart auto-negotiation or force link. |
| 5337 | * |
| 5338 | * hw - Struct containing variables accessed by shared code |
| 5339 | ****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5340 | static s32 e1000_set_phy_mode(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5341 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5342 | s32 ret_val; |
| 5343 | u16 eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5344 | |
| 5345 | DEBUGFUNC("e1000_set_phy_mode"); |
| 5346 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5347 | if ((hw->mac_type == e1000_82545_rev_3) && |
| 5348 | (hw->media_type == e1000_media_type_copper)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5349 | ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5350 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5351 | return ret_val; |
| 5352 | } |
| 5353 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5354 | if ((eeprom_data != EEPROM_RESERVED_WORD) && |
| 5355 | (eeprom_data & EEPROM_PHY_CLASS_A)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5356 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5357 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5358 | return ret_val; |
| 5359 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5360 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5361 | return ret_val; |
| 5362 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5363 | hw->phy_reset_disable = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5364 | } |
| 5365 | } |
| 5366 | |
| 5367 | return E1000_SUCCESS; |
| 5368 | } |
| 5369 | |
| 5370 | /***************************************************************************** |
| 5371 | * |
| 5372 | * This function sets the lplu state according to the active flag. When |
| 5373 | * activating lplu this function also disables smart speed and vise versa. |
| 5374 | * lplu will not be activated unless the device autonegotiation advertisment |
| 5375 | * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes. |
| 5376 | * hw: Struct containing variables accessed by shared code |
| 5377 | * active - true to enable lplu false to disable lplu. |
| 5378 | * |
| 5379 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 5380 | * E1000_SUCCESS at any other case. |
| 5381 | * |
| 5382 | ****************************************************************************/ |
| 5383 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5384 | 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] | 5385 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5386 | s32 ret_val; |
| 5387 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5388 | DEBUGFUNC("e1000_set_d3_lplu_state"); |
| 5389 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 5390 | if (hw->phy_type != e1000_phy_igp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5391 | return E1000_SUCCESS; |
| 5392 | |
| 5393 | /* During driver activity LPLU should not be used or it will attain link |
| 5394 | * from the lowest speeds starting from 10Mbps. The capability is used for |
| 5395 | * Dx transitions and states */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5396 | if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5397 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5398 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5399 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5400 | } else { |
| 5401 | ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5402 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5403 | return ret_val; |
| 5404 | } |
| 5405 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5406 | if (!active) { |
| 5407 | if (hw->mac_type == e1000_82541_rev_2 || |
| 5408 | hw->mac_type == e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5409 | phy_data &= ~IGP01E1000_GMII_FLEX_SPD; |
| 5410 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5411 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5412 | return ret_val; |
| 5413 | } else { |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 5414 | phy_data &= ~IGP02E1000_PM_D3_LPLU; |
| 5415 | ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
| 5416 | phy_data); |
| 5417 | if (ret_val) |
| 5418 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5419 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5420 | |
| 5421 | /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during |
| 5422 | * Dx states where the power conservation is most important. During |
| 5423 | * driver activity we should enable SmartSpeed, so performance is |
| 5424 | * maintained. */ |
| 5425 | if (hw->smart_speed == e1000_smart_speed_on) { |
| 5426 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5427 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5428 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5429 | return ret_val; |
| 5430 | |
| 5431 | phy_data |= IGP01E1000_PSCFR_SMART_SPEED; |
| 5432 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5433 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5434 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5435 | return ret_val; |
| 5436 | } else if (hw->smart_speed == e1000_smart_speed_off) { |
| 5437 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5438 | &phy_data); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 5439 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5440 | return ret_val; |
| 5441 | |
| 5442 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 5443 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5444 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5445 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5446 | return ret_val; |
| 5447 | } |
| 5448 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5449 | } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) || |
| 5450 | (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) || |
| 5451 | (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5452 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5453 | if (hw->mac_type == e1000_82541_rev_2 || |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5454 | hw->mac_type == e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5455 | phy_data |= IGP01E1000_GMII_FLEX_SPD; |
| 5456 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5457 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5458 | return ret_val; |
| 5459 | } else { |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 5460 | phy_data |= IGP02E1000_PM_D3_LPLU; |
| 5461 | ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5462 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5463 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5464 | return ret_val; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5465 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5467 | /* When LPLU is enabled we should disable SmartSpeed */ |
| 5468 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5469 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5470 | return ret_val; |
| 5471 | |
| 5472 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 5473 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5474 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5475 | return ret_val; |
| 5476 | |
| 5477 | } |
| 5478 | return E1000_SUCCESS; |
| 5479 | } |
| 5480 | |
| 5481 | /****************************************************************************** |
| 5482 | * Change VCO speed register to improve Bit Error Rate performance of SERDES. |
| 5483 | * |
| 5484 | * hw - Struct containing variables accessed by shared code |
| 5485 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5486 | static s32 e1000_set_vco_speed(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5488 | s32 ret_val; |
| 5489 | u16 default_page = 0; |
| 5490 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5491 | |
| 5492 | DEBUGFUNC("e1000_set_vco_speed"); |
| 5493 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5494 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5495 | case e1000_82545_rev_3: |
| 5496 | case e1000_82546_rev_3: |
| 5497 | break; |
| 5498 | default: |
| 5499 | return E1000_SUCCESS; |
| 5500 | } |
| 5501 | |
| 5502 | /* Set PHY register 30, page 5, bit 8 to 0 */ |
| 5503 | |
| 5504 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5505 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | return ret_val; |
| 5507 | |
| 5508 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5509 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5510 | return ret_val; |
| 5511 | |
| 5512 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5513 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5514 | return ret_val; |
| 5515 | |
| 5516 | phy_data &= ~M88E1000_PHY_VCO_REG_BIT8; |
| 5517 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5518 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5519 | return ret_val; |
| 5520 | |
| 5521 | /* Set PHY register 30, page 4, bit 11 to 1 */ |
| 5522 | |
| 5523 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5524 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | return ret_val; |
| 5526 | |
| 5527 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5528 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5529 | return ret_val; |
| 5530 | |
| 5531 | phy_data |= M88E1000_PHY_VCO_REG_BIT11; |
| 5532 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5533 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5534 | return ret_val; |
| 5535 | |
| 5536 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5537 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5538 | return ret_val; |
| 5539 | |
| 5540 | return E1000_SUCCESS; |
| 5541 | } |
| 5542 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5543 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5544 | /****************************************************************************** |
| 5545 | * Verifies the hardware needs to allow ARPs to be processed by the host |
| 5546 | * |
| 5547 | * hw - Struct containing variables accessed by shared code |
| 5548 | * |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5549 | * returns: - true/false |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5550 | * |
| 5551 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5552 | u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5553 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5554 | u32 manc; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5555 | |
| 5556 | if (hw->asf_firmware_present) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5557 | manc = er32(MANC); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5558 | |
| 5559 | if (!(manc & E1000_MANC_RCV_TCO_EN) || |
| 5560 | !(manc & E1000_MANC_EN_MAC_ADDR_FILTER)) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5561 | return false; |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 5562 | if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN)) |
| 5563 | return true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5564 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5565 | return false; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5566 | } |
| 5567 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5568 | static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5569 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5570 | s32 ret_val; |
| 5571 | u16 mii_status_reg; |
| 5572 | u16 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5573 | |
| 5574 | /* Polarity reversal workaround for forced 10F/10H links. */ |
| 5575 | |
| 5576 | /* Disable the transmitter on the PHY */ |
| 5577 | |
| 5578 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5579 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5580 | return ret_val; |
| 5581 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5582 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5583 | return ret_val; |
| 5584 | |
| 5585 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5586 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5587 | return ret_val; |
| 5588 | |
| 5589 | /* This loop will early-out if the NO link condition has been met. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5590 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5591 | /* Read the MII Status Register and wait for Link Status bit |
| 5592 | * to be clear. |
| 5593 | */ |
| 5594 | |
| 5595 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5596 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5597 | return ret_val; |
| 5598 | |
| 5599 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5600 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5601 | return ret_val; |
| 5602 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5603 | if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5604 | mdelay(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5605 | } |
| 5606 | |
| 5607 | /* Recommended delay time after link has been lost */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5608 | mdelay(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5609 | |
| 5610 | /* Now we will re-enable th transmitter on the PHY */ |
| 5611 | |
| 5612 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5613 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5614 | return ret_val; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5615 | mdelay(50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5616 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5617 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5618 | return ret_val; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5619 | mdelay(50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5620 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5621 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5622 | return ret_val; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5623 | mdelay(50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5624 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5625 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5626 | return ret_val; |
| 5627 | |
| 5628 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5629 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5630 | return ret_val; |
| 5631 | |
| 5632 | /* This loop will early-out if the link condition has been met. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5633 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5634 | /* Read the MII Status Register and wait for Link Status bit |
| 5635 | * to be set. |
| 5636 | */ |
| 5637 | |
| 5638 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5639 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5640 | return ret_val; |
| 5641 | |
| 5642 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5643 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5644 | return ret_val; |
| 5645 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5646 | if (mii_status_reg & MII_SR_LINK_STATUS) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5647 | mdelay(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5648 | } |
| 5649 | return E1000_SUCCESS; |
| 5650 | } |
| 5651 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5652 | /******************************************************************************* |
| 5653 | * |
| 5654 | * Check for EEPROM Auto Read bit done. |
| 5655 | * |
| 5656 | * hw: Struct containing variables accessed by shared code |
| 5657 | * |
| 5658 | * returns: - E1000_ERR_RESET if fail to reset MAC |
| 5659 | * E1000_SUCCESS at any other case. |
| 5660 | * |
| 5661 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5662 | static s32 e1000_get_auto_rd_done(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5663 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5664 | DEBUGFUNC("e1000_get_auto_rd_done"); |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 5665 | msleep(5); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5666 | return E1000_SUCCESS; |
| 5667 | } |
| 5668 | |
| 5669 | /*************************************************************************** |
| 5670 | * Checks if the PHY configuration is done |
| 5671 | * |
| 5672 | * hw: Struct containing variables accessed by shared code |
| 5673 | * |
| 5674 | * returns: - E1000_ERR_RESET if fail to reset MAC |
| 5675 | * E1000_SUCCESS at any other case. |
| 5676 | * |
| 5677 | ***************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5678 | static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5679 | { |
| 5680 | DEBUGFUNC("e1000_get_phy_cfg_done"); |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 5681 | mdelay(10); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5682 | return E1000_SUCCESS; |
| 5683 | } |
| 5684 | |
| 5685 | /*************************************************************************** |
| 5686 | * |
| 5687 | * Using the combination of SMBI and SWESMBI semaphore bits when resetting |
| 5688 | * adapter or Eeprom access. |
| 5689 | * |
| 5690 | * hw: Struct containing variables accessed by shared code |
| 5691 | * |
| 5692 | * returns: - E1000_ERR_EEPROM if fail to access EEPROM. |
| 5693 | * E1000_SUCCESS at any other case. |
| 5694 | * |
| 5695 | ***************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5696 | static s32 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5697 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5698 | s32 timeout; |
| 5699 | u32 swsm; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5700 | |
| 5701 | DEBUGFUNC("e1000_get_hw_eeprom_semaphore"); |
| 5702 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5703 | if (!hw->eeprom_semaphore_present) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5704 | return E1000_SUCCESS; |
| 5705 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5706 | /* Get the FW semaphore. */ |
| 5707 | timeout = hw->eeprom.word_size + 1; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5708 | while (timeout) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5709 | swsm = er32(SWSM); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5710 | swsm |= E1000_SWSM_SWESMBI; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5711 | ew32(SWSM, swsm); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5712 | /* if we managed to set the bit we got the semaphore. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5713 | swsm = er32(SWSM); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5714 | if (swsm & E1000_SWSM_SWESMBI) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5715 | break; |
| 5716 | |
| 5717 | udelay(50); |
| 5718 | timeout--; |
| 5719 | } |
| 5720 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5721 | if (!timeout) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5722 | /* Release semaphores */ |
| 5723 | e1000_put_hw_eeprom_semaphore(hw); |
| 5724 | DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n"); |
| 5725 | return -E1000_ERR_EEPROM; |
| 5726 | } |
| 5727 | |
| 5728 | return E1000_SUCCESS; |
| 5729 | } |
| 5730 | |
| 5731 | /*************************************************************************** |
| 5732 | * This function clears HW semaphore bits. |
| 5733 | * |
| 5734 | * hw: Struct containing variables accessed by shared code |
| 5735 | * |
| 5736 | * returns: - None. |
| 5737 | * |
| 5738 | ***************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5739 | static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5740 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5741 | u32 swsm; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5742 | |
| 5743 | DEBUGFUNC("e1000_put_hw_eeprom_semaphore"); |
| 5744 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5745 | if (!hw->eeprom_semaphore_present) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5746 | return; |
| 5747 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5748 | swsm = er32(SWSM); |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame^] | 5749 | swsm &= ~(E1000_SWSM_SWESMBI); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5750 | ew32(SWSM, swsm); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5751 | } |