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_check_downshift(struct e1000_hw *hw); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 37 | static s32 e1000_check_polarity(struct e1000_hw *hw, |
| 38 | e1000_rev_polarity *polarity); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 39 | static void e1000_clear_hw_cntrs(struct e1000_hw *hw); |
| 40 | static void e1000_clear_vfta(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 41 | static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 42 | bool link_up); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 43 | static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw); |
| 44 | static s32 e1000_detect_gig_phy(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 45 | static s32 e1000_get_auto_rd_done(struct e1000_hw *hw); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 46 | static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length, |
| 47 | u16 *max_length); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 48 | static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 49 | static s32 e1000_id_led_init(struct e1000_hw *hw); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 50 | static void e1000_init_rx_addrs(struct e1000_hw *hw); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 51 | static s32 e1000_phy_igp_get_info(struct e1000_hw *hw, |
| 52 | struct e1000_phy_info *phy_info); |
| 53 | static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words, |
| 54 | u16 *data); |
| 55 | static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words, |
| 56 | u16 *data); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 57 | 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] | 58 | static s32 e1000_phy_m88_get_info(struct e1000_hw *hw, |
| 59 | struct e1000_phy_info *phy_info); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 60 | 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] | 61 | static s32 e1000_wait_autoneg(struct e1000_hw *hw); |
| 62 | static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value); |
| 63 | static s32 e1000_set_phy_type(struct e1000_hw *hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | static void e1000_phy_init_script(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 65 | static s32 e1000_setup_copper_link(struct e1000_hw *hw); |
| 66 | static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw); |
| 67 | static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw); |
| 68 | static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw); |
| 69 | static s32 e1000_config_mac_to_phy(struct e1000_hw *hw); |
| 70 | static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl); |
| 71 | static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl); |
| 72 | 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] | 73 | u16 count); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 74 | static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw); |
| 75 | static s32 e1000_phy_reset_dsp(struct e1000_hw *hw); |
| 76 | static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, |
| 77 | u16 words, u16 *data); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 78 | static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset, |
| 79 | u16 words, u16 *data); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 80 | static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw); |
| 81 | static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd); |
| 82 | static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 83 | 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] | 84 | 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] | 85 | u16 phy_data); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 86 | 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] | 87 | u16 *phy_data); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 88 | static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count); |
| 89 | static s32 e1000_acquire_eeprom(struct e1000_hw *hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | static void e1000_release_eeprom(struct e1000_hw *hw); |
| 91 | static void e1000_standby_eeprom(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 92 | static s32 e1000_set_vco_speed(struct e1000_hw *hw); |
| 93 | static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw); |
| 94 | static s32 e1000_set_phy_mode(struct e1000_hw *hw); |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 95 | static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data); |
| 96 | 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] | 97 | |
| 98 | /* IGP cable length table */ |
| 99 | static const |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 100 | u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
| 102 | 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25, |
| 103 | 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40, |
| 104 | 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, |
| 105 | 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90, |
| 106 | 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, |
| 107 | 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, |
| 108 | 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120}; |
| 109 | |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 110 | static DEFINE_SPINLOCK(e1000_eeprom_lock); |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | /****************************************************************************** |
| 113 | * Set the phy type member in the hw struct. |
| 114 | * |
| 115 | * hw - Struct containing variables accessed by shared code |
| 116 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 117 | static s32 e1000_set_phy_type(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
| 119 | DEBUGFUNC("e1000_set_phy_type"); |
| 120 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 121 | if (hw->mac_type == e1000_undefined) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 122 | return -E1000_ERR_PHY_TYPE; |
| 123 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 124 | switch (hw->phy_id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | case M88E1000_E_PHY_ID: |
| 126 | case M88E1000_I_PHY_ID: |
| 127 | case M88E1011_I_PHY_ID: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 128 | case M88E1111_I_PHY_ID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | hw->phy_type = e1000_phy_m88; |
| 130 | break; |
| 131 | case IGP01E1000_I_PHY_ID: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 132 | if (hw->mac_type == e1000_82541 || |
| 133 | hw->mac_type == e1000_82541_rev_2 || |
| 134 | hw->mac_type == e1000_82547 || |
| 135 | hw->mac_type == e1000_82547_rev_2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | hw->phy_type = e1000_phy_igp; |
| 137 | break; |
| 138 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | default: |
| 140 | /* Should never have loaded on this device */ |
| 141 | hw->phy_type = e1000_phy_undefined; |
| 142 | return -E1000_ERR_PHY_TYPE; |
| 143 | } |
| 144 | |
| 145 | return E1000_SUCCESS; |
| 146 | } |
| 147 | |
| 148 | /****************************************************************************** |
| 149 | * IGP phy init script - initializes the GbE PHY |
| 150 | * |
| 151 | * hw - Struct containing variables accessed by shared code |
| 152 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 153 | static void e1000_phy_init_script(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 155 | u32 ret_val; |
| 156 | u16 phy_saved_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 158 | DEBUGFUNC("e1000_phy_init_script"); |
| 159 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 160 | if (hw->phy_init_script) { |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 161 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | /* Save off the current value of register 0x2F5B to be restored at |
| 164 | * the end of this routine. */ |
| 165 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
| 166 | |
| 167 | /* Disabled the PHY transmitter */ |
| 168 | e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 169 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 170 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | e1000_write_phy_reg(hw,0x0000,0x0140); |
| 173 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 174 | msleep(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 176 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | case e1000_82541: |
| 178 | case e1000_82547: |
| 179 | e1000_write_phy_reg(hw, 0x1F95, 0x0001); |
| 180 | |
| 181 | e1000_write_phy_reg(hw, 0x1F71, 0xBD21); |
| 182 | |
| 183 | e1000_write_phy_reg(hw, 0x1F79, 0x0018); |
| 184 | |
| 185 | e1000_write_phy_reg(hw, 0x1F30, 0x1600); |
| 186 | |
| 187 | e1000_write_phy_reg(hw, 0x1F31, 0x0014); |
| 188 | |
| 189 | e1000_write_phy_reg(hw, 0x1F32, 0x161C); |
| 190 | |
| 191 | e1000_write_phy_reg(hw, 0x1F94, 0x0003); |
| 192 | |
| 193 | e1000_write_phy_reg(hw, 0x1F96, 0x003F); |
| 194 | |
| 195 | e1000_write_phy_reg(hw, 0x2010, 0x0008); |
| 196 | break; |
| 197 | |
| 198 | case e1000_82541_rev_2: |
| 199 | case e1000_82547_rev_2: |
| 200 | e1000_write_phy_reg(hw, 0x1F73, 0x0099); |
| 201 | break; |
| 202 | default: |
| 203 | break; |
| 204 | } |
| 205 | |
| 206 | e1000_write_phy_reg(hw, 0x0000, 0x3300); |
| 207 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 208 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | /* Now enable the transmitter */ |
| 211 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
| 212 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 213 | if (hw->mac_type == e1000_82547) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 214 | u16 fused, fine, coarse; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | /* Move to analog registers page */ |
| 217 | e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused); |
| 218 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 219 | if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused); |
| 221 | |
| 222 | fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK; |
| 223 | coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK; |
| 224 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 225 | if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10; |
| 227 | fine -= IGP01E1000_ANALOG_FUSE_FINE_1; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 228 | } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | fine -= IGP01E1000_ANALOG_FUSE_FINE_10; |
| 230 | |
| 231 | fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) | |
| 232 | (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) | |
| 233 | (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK); |
| 234 | |
| 235 | e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused); |
| 236 | e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS, |
| 237 | IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL); |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | /****************************************************************************** |
| 244 | * Set the mac type member in the hw struct. |
| 245 | * |
| 246 | * hw - Struct containing variables accessed by shared code |
| 247 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 248 | s32 e1000_set_mac_type(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 250 | DEBUGFUNC("e1000_set_mac_type"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 252 | switch (hw->device_id) { |
| 253 | case E1000_DEV_ID_82542: |
| 254 | switch (hw->revision_id) { |
| 255 | case E1000_82542_2_0_REV_ID: |
| 256 | hw->mac_type = e1000_82542_rev2_0; |
| 257 | break; |
| 258 | case E1000_82542_2_1_REV_ID: |
| 259 | hw->mac_type = e1000_82542_rev2_1; |
| 260 | break; |
| 261 | default: |
| 262 | /* Invalid 82542 revision ID */ |
| 263 | return -E1000_ERR_MAC_TYPE; |
| 264 | } |
| 265 | break; |
| 266 | case E1000_DEV_ID_82543GC_FIBER: |
| 267 | case E1000_DEV_ID_82543GC_COPPER: |
| 268 | hw->mac_type = e1000_82543; |
| 269 | break; |
| 270 | case E1000_DEV_ID_82544EI_COPPER: |
| 271 | case E1000_DEV_ID_82544EI_FIBER: |
| 272 | case E1000_DEV_ID_82544GC_COPPER: |
| 273 | case E1000_DEV_ID_82544GC_LOM: |
| 274 | hw->mac_type = e1000_82544; |
| 275 | break; |
| 276 | case E1000_DEV_ID_82540EM: |
| 277 | case E1000_DEV_ID_82540EM_LOM: |
| 278 | case E1000_DEV_ID_82540EP: |
| 279 | case E1000_DEV_ID_82540EP_LOM: |
| 280 | case E1000_DEV_ID_82540EP_LP: |
| 281 | hw->mac_type = e1000_82540; |
| 282 | break; |
| 283 | case E1000_DEV_ID_82545EM_COPPER: |
| 284 | case E1000_DEV_ID_82545EM_FIBER: |
| 285 | hw->mac_type = e1000_82545; |
| 286 | break; |
| 287 | case E1000_DEV_ID_82545GM_COPPER: |
| 288 | case E1000_DEV_ID_82545GM_FIBER: |
| 289 | case E1000_DEV_ID_82545GM_SERDES: |
| 290 | hw->mac_type = e1000_82545_rev_3; |
| 291 | break; |
| 292 | case E1000_DEV_ID_82546EB_COPPER: |
| 293 | case E1000_DEV_ID_82546EB_FIBER: |
| 294 | case E1000_DEV_ID_82546EB_QUAD_COPPER: |
| 295 | hw->mac_type = e1000_82546; |
| 296 | break; |
| 297 | case E1000_DEV_ID_82546GB_COPPER: |
| 298 | case E1000_DEV_ID_82546GB_FIBER: |
| 299 | case E1000_DEV_ID_82546GB_SERDES: |
| 300 | case E1000_DEV_ID_82546GB_PCIE: |
| 301 | case E1000_DEV_ID_82546GB_QUAD_COPPER: |
| 302 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
| 303 | hw->mac_type = e1000_82546_rev_3; |
| 304 | break; |
| 305 | case E1000_DEV_ID_82541EI: |
| 306 | case E1000_DEV_ID_82541EI_MOBILE: |
| 307 | case E1000_DEV_ID_82541ER_LOM: |
| 308 | hw->mac_type = e1000_82541; |
| 309 | break; |
| 310 | case E1000_DEV_ID_82541ER: |
| 311 | case E1000_DEV_ID_82541GI: |
| 312 | case E1000_DEV_ID_82541GI_LF: |
| 313 | case E1000_DEV_ID_82541GI_MOBILE: |
| 314 | hw->mac_type = e1000_82541_rev_2; |
| 315 | break; |
| 316 | case E1000_DEV_ID_82547EI: |
| 317 | case E1000_DEV_ID_82547EI_MOBILE: |
| 318 | hw->mac_type = e1000_82547; |
| 319 | break; |
| 320 | case E1000_DEV_ID_82547GI: |
| 321 | hw->mac_type = e1000_82547_rev_2; |
| 322 | break; |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 323 | default: |
| 324 | /* Should never have loaded on this device */ |
| 325 | return -E1000_ERR_MAC_TYPE; |
| 326 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 328 | switch (hw->mac_type) { |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 329 | case e1000_82541: |
| 330 | case e1000_82547: |
| 331 | case e1000_82541_rev_2: |
| 332 | case e1000_82547_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 333 | hw->asf_firmware_present = true; |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 334 | break; |
| 335 | default: |
| 336 | break; |
| 337 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 339 | /* The 82543 chip does not count tx_carrier_errors properly in |
| 340 | * FD mode |
| 341 | */ |
| 342 | if (hw->mac_type == e1000_82543) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 343 | hw->bad_tx_carr_stats_fd = true; |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 344 | |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 345 | if (hw->mac_type > e1000_82544) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 346 | hw->has_smbus = true; |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 347 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 348 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /***************************************************************************** |
| 352 | * Set media type and TBI compatibility. |
| 353 | * |
| 354 | * hw - Struct containing variables accessed by shared code |
| 355 | * **************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 356 | void e1000_set_media_type(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 358 | u32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
| 360 | DEBUGFUNC("e1000_set_media_type"); |
| 361 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 362 | if (hw->mac_type != e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | /* tbi_compatibility is only valid on 82543 */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 364 | hw->tbi_compatibility_en = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | switch (hw->device_id) { |
| 368 | case E1000_DEV_ID_82545GM_SERDES: |
| 369 | case E1000_DEV_ID_82546GB_SERDES: |
| 370 | hw->media_type = e1000_media_type_internal_serdes; |
| 371 | break; |
| 372 | default: |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 373 | switch (hw->mac_type) { |
| 374 | case e1000_82542_rev2_0: |
| 375 | case e1000_82542_rev2_1: |
| 376 | hw->media_type = e1000_media_type_fiber; |
| 377 | break; |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 378 | default: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 379 | status = er32(STATUS); |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 380 | if (status & E1000_STATUS_TBIMODE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | hw->media_type = e1000_media_type_fiber; |
| 382 | /* tbi_compatibility not valid on fiber */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 383 | hw->tbi_compatibility_en = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | } else { |
| 385 | hw->media_type = e1000_media_type_copper; |
| 386 | } |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 387 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | /****************************************************************************** |
| 393 | * Reset the transmit and receive units; mask and clear all interrupts. |
| 394 | * |
| 395 | * hw - Struct containing variables accessed by shared code |
| 396 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 397 | s32 e1000_reset_hw(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 399 | u32 ctrl; |
| 400 | u32 ctrl_ext; |
| 401 | u32 icr; |
| 402 | u32 manc; |
| 403 | u32 led_ctrl; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 404 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
| 406 | DEBUGFUNC("e1000_reset_hw"); |
| 407 | |
| 408 | /* For 82542 (rev 2.0), disable MWI before issuing a device reset */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 409 | if (hw->mac_type == e1000_82542_rev2_0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); |
| 411 | e1000_pci_clear_mwi(hw); |
| 412 | } |
| 413 | |
| 414 | /* Clear interrupt mask to stop board from generating interrupts */ |
| 415 | DEBUGOUT("Masking off all interrupts\n"); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 416 | ew32(IMC, 0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
| 418 | /* Disable the Transmit and Receive units. Then delay to allow |
| 419 | * any pending transactions to complete before we hit the MAC with |
| 420 | * the global reset. |
| 421 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 422 | ew32(RCTL, 0); |
| 423 | ew32(TCTL, E1000_TCTL_PSP); |
| 424 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
| 426 | /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 427 | hw->tbi_compatibility_on = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
| 429 | /* Delay to allow any outstanding PCI transactions to complete before |
| 430 | * resetting the device |
| 431 | */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 432 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 434 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
| 436 | /* Must reset the PHY before resetting the MAC */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 437 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 438 | ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST)); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 439 | msleep(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /* Issue a global reset to the MAC. This will reset the chip's |
| 443 | * transmit, receive, DMA, and link units. It will not effect |
| 444 | * the current PCI configuration. The global reset bit is self- |
| 445 | * clearing, and should clear within a microsecond. |
| 446 | */ |
| 447 | DEBUGOUT("Issuing a global reset to MAC\n"); |
| 448 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 449 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | case e1000_82544: |
| 451 | case e1000_82540: |
| 452 | case e1000_82545: |
| 453 | case e1000_82546: |
| 454 | case e1000_82541: |
| 455 | case e1000_82541_rev_2: |
| 456 | /* These controllers can't ack the 64-bit write when issuing the |
| 457 | * reset, so use IO-mapping as a workaround to issue the reset */ |
| 458 | E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST)); |
| 459 | break; |
| 460 | case e1000_82545_rev_3: |
| 461 | case e1000_82546_rev_3: |
| 462 | /* Reset is performed on a shadow of the control register */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 463 | ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | break; |
| 465 | default: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 466 | ew32(CTRL, (ctrl | E1000_CTRL_RST)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | break; |
| 468 | } |
| 469 | |
| 470 | /* After MAC reset, force reload of EEPROM to restore power-on settings to |
| 471 | * device. Later controllers reload the EEPROM automatically, so just wait |
| 472 | * for reload to complete. |
| 473 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 474 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | case e1000_82542_rev2_0: |
| 476 | case e1000_82542_rev2_1: |
| 477 | case e1000_82543: |
| 478 | case e1000_82544: |
| 479 | /* Wait for reset to complete */ |
| 480 | udelay(10); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 481 | ctrl_ext = er32(CTRL_EXT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 483 | ew32(CTRL_EXT, ctrl_ext); |
| 484 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | /* Wait for EEPROM reload */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 486 | msleep(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | break; |
| 488 | case e1000_82541: |
| 489 | case e1000_82541_rev_2: |
| 490 | case e1000_82547: |
| 491 | case e1000_82547_rev_2: |
| 492 | /* Wait for EEPROM reload */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 493 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | break; |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 495 | default: |
| 496 | /* Auto read done will delay 5ms or poll based on mac type */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 497 | ret_val = e1000_get_auto_rd_done(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 498 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 499 | return ret_val; |
| 500 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | /* Disable HW ARPs on ASF enabled adapters */ |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 504 | if (hw->mac_type >= e1000_82540) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 505 | manc = er32(MANC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | manc &= ~(E1000_MANC_ARP_EN); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 507 | ew32(MANC, manc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 510 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | e1000_phy_init_script(hw); |
| 512 | |
| 513 | /* Configure activity LED after PHY reset */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 514 | led_ctrl = er32(LEDCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 516 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 517 | ew32(LEDCTL, led_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /* Clear interrupt mask to stop board from generating interrupts */ |
| 521 | DEBUGOUT("Masking off all interrupts\n"); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 522 | ew32(IMC, 0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |
| 524 | /* Clear any pending interrupt events. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 525 | icr = er32(ICR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
| 527 | /* If MWI was previously enabled, reenable it. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 528 | if (hw->mac_type == e1000_82542_rev2_0) { |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 529 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | e1000_pci_set_mwi(hw); |
| 531 | } |
| 532 | |
| 533 | return E1000_SUCCESS; |
| 534 | } |
| 535 | |
| 536 | /****************************************************************************** |
| 537 | * Performs basic configuration of the adapter. |
| 538 | * |
| 539 | * hw - Struct containing variables accessed by shared code |
| 540 | * |
| 541 | * Assumes that the controller has previously been reset and is in a |
| 542 | * post-reset uninitialized state. Initializes the receive address registers, |
| 543 | * multicast table, and VLAN filter table. Calls routines to setup link |
| 544 | * configuration and flow control settings. Clears all on-chip counters. Leaves |
| 545 | * the transmit and receive units disabled and uninitialized. |
| 546 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 547 | s32 e1000_init_hw(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 549 | u32 ctrl; |
| 550 | u32 i; |
| 551 | s32 ret_val; |
| 552 | u32 mta_size; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 553 | u32 ctrl_ext; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | DEBUGFUNC("e1000_init_hw"); |
| 556 | |
| 557 | /* Initialize Identification LED */ |
| 558 | ret_val = e1000_id_led_init(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 559 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | DEBUGOUT("Error Initializing Identification LED\n"); |
| 561 | return ret_val; |
| 562 | } |
| 563 | |
| 564 | /* Set the media type and TBI compatibility */ |
| 565 | e1000_set_media_type(hw); |
| 566 | |
| 567 | /* Disabling VLAN filtering. */ |
| 568 | DEBUGOUT("Initializing the IEEE VLAN\n"); |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 569 | if (hw->mac_type < e1000_82545_rev_3) |
| 570 | ew32(VET, 0); |
| 571 | e1000_clear_vfta(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
| 573 | /* 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] | 574 | if (hw->mac_type == e1000_82542_rev2_0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); |
| 576 | e1000_pci_clear_mwi(hw); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 577 | ew32(RCTL, E1000_RCTL_RST); |
| 578 | E1000_WRITE_FLUSH(); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 579 | msleep(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | /* Setup the receive address. This involves initializing all of the Receive |
| 583 | * Address Registers (RARs 0 - 15). |
| 584 | */ |
| 585 | e1000_init_rx_addrs(hw); |
| 586 | |
| 587 | /* 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] | 588 | if (hw->mac_type == e1000_82542_rev2_0) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 589 | ew32(RCTL, 0); |
| 590 | E1000_WRITE_FLUSH(); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 591 | msleep(1); |
| 592 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | e1000_pci_set_mwi(hw); |
| 594 | } |
| 595 | |
| 596 | /* Zero out the Multicast HASH table */ |
| 597 | DEBUGOUT("Zeroing the MTA\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 598 | mta_size = E1000_MC_TBL_SIZE; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 599 | for (i = 0; i < mta_size; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 601 | /* use write flush to prevent Memory Write Block (MWB) from |
| 602 | * occuring when accessing our register space */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 603 | E1000_WRITE_FLUSH(); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 604 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
| 606 | /* Set the PCI priority bit correctly in the CTRL register. This |
| 607 | * determines if the adapter gives priority to receives, or if it |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 608 | * gives equal priority to transmits and receives. Valid only on |
| 609 | * 82542 and 82543 silicon. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 611 | if (hw->dma_fairness && hw->mac_type <= e1000_82543) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 612 | ctrl = er32(CTRL); |
| 613 | ew32(CTRL, ctrl | E1000_CTRL_PRIOR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 616 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | case e1000_82545_rev_3: |
| 618 | case e1000_82546_rev_3: |
| 619 | break; |
| 620 | default: |
| 621 | /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */ |
Peter Oruba | 007755e | 2007-09-28 22:42:06 -0700 | [diff] [blame] | 622 | if (hw->bus_type == e1000_bus_type_pcix && e1000_pcix_get_mmrbc(hw) > 2048) |
| 623 | e1000_pcix_set_mmrbc(hw, 2048); |
| 624 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | /* Call a subroutine to configure the link and setup flow control. */ |
| 628 | ret_val = e1000_setup_link(hw); |
| 629 | |
| 630 | /* Set the transmit descriptor write-back policy */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 631 | if (hw->mac_type > e1000_82544) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 632 | ctrl = er32(TXDCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 634 | ew32(TXDCTL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | /* Clear all of the statistics registers (clear on read). It is |
| 638 | * important that we do this after we have tried to establish link |
| 639 | * because the symbol error count will increment wildly if there |
| 640 | * is no link. |
| 641 | */ |
| 642 | e1000_clear_hw_cntrs(hw); |
| 643 | |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 644 | if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER || |
| 645 | hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 646 | ctrl_ext = er32(CTRL_EXT); |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 647 | /* Relaxed ordering must be disabled to avoid a parity |
| 648 | * error crash in a PCI slot. */ |
| 649 | ctrl_ext |= E1000_CTRL_EXT_RO_DIS; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 650 | ew32(CTRL_EXT, ctrl_ext); |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 651 | } |
| 652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | return ret_val; |
| 654 | } |
| 655 | |
| 656 | /****************************************************************************** |
| 657 | * Adjust SERDES output amplitude based on EEPROM setting. |
| 658 | * |
| 659 | * hw - Struct containing variables accessed by shared code. |
| 660 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 661 | static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 663 | u16 eeprom_data; |
| 664 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | |
| 666 | DEBUGFUNC("e1000_adjust_serdes_amplitude"); |
| 667 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 668 | if (hw->media_type != e1000_media_type_internal_serdes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | return E1000_SUCCESS; |
| 670 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 671 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | case e1000_82545_rev_3: |
| 673 | case e1000_82546_rev_3: |
| 674 | break; |
| 675 | default: |
| 676 | return E1000_SUCCESS; |
| 677 | } |
| 678 | |
| 679 | ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data); |
| 680 | if (ret_val) { |
| 681 | return ret_val; |
| 682 | } |
| 683 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 684 | if (eeprom_data != EEPROM_RESERVED_WORD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | /* Adjust SERDES output amplitude only. */ |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 686 | eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | 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] | 688 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | return ret_val; |
| 690 | } |
| 691 | |
| 692 | return E1000_SUCCESS; |
| 693 | } |
| 694 | |
| 695 | /****************************************************************************** |
| 696 | * Configures flow control and link settings. |
| 697 | * |
| 698 | * hw - Struct containing variables accessed by shared code |
| 699 | * |
| 700 | * Determines which flow control settings to use. Calls the apropriate media- |
| 701 | * specific link configuration function. Configures the flow control settings. |
| 702 | * Assuming the adapter has a valid link partner, a valid link should be |
| 703 | * established. Assumes the hardware has previously been reset and the |
| 704 | * transmitter and receiver are not enabled. |
| 705 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 706 | s32 e1000_setup_link(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 708 | u32 ctrl_ext; |
| 709 | s32 ret_val; |
| 710 | u16 eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | |
| 712 | DEBUGFUNC("e1000_setup_link"); |
| 713 | |
| 714 | /* Read and store word 0x0F of the EEPROM. This word contains bits |
| 715 | * that determine the hardware's default PAUSE (flow control) mode, |
| 716 | * a bit that determines whether the HW defaults to enabling or |
| 717 | * disabling auto-negotiation, and the direction of the |
| 718 | * SW defined pins. If there is no SW over-ride of the flow |
| 719 | * control setting, then the variable hw->fc will |
| 720 | * be initialized based on a value in the EEPROM. |
| 721 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 722 | if (hw->fc == E1000_FC_DEFAULT) { |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 723 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, |
| 724 | 1, &eeprom_data); |
| 725 | if (ret_val) { |
| 726 | DEBUGOUT("EEPROM Read Error\n"); |
| 727 | return -E1000_ERR_EEPROM; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 728 | } |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 729 | if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0) |
| 730 | hw->fc = E1000_FC_NONE; |
| 731 | else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == |
| 732 | EEPROM_WORD0F_ASM_DIR) |
| 733 | hw->fc = E1000_FC_TX_PAUSE; |
| 734 | else |
| 735 | hw->fc = E1000_FC_FULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | /* We want to save off the original Flow Control configuration just |
| 739 | * in case we get disconnected and then reconnected into a different |
| 740 | * hub or switch with different Flow Control capabilities. |
| 741 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 742 | if (hw->mac_type == e1000_82542_rev2_0) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 743 | hw->fc &= (~E1000_FC_TX_PAUSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 745 | if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1)) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 746 | hw->fc &= (~E1000_FC_RX_PAUSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
| 748 | hw->original_fc = hw->fc; |
| 749 | |
| 750 | DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc); |
| 751 | |
| 752 | /* Take the 4 bits from EEPROM word 0x0F that determine the initial |
| 753 | * polarity value for the SW controlled pins, and setup the |
| 754 | * Extended Device Control reg with that info. |
| 755 | * This is needed because one of the SW controlled pins is used for |
| 756 | * signal detection. So this should be done before e1000_setup_pcs_link() |
| 757 | * or e1000_phy_setup() is called. |
| 758 | */ |
Jeff Kirsher | 497fce5 | 2006-03-02 18:18:20 -0800 | [diff] [blame] | 759 | if (hw->mac_type == e1000_82543) { |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 760 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, |
| 761 | 1, &eeprom_data); |
| 762 | if (ret_val) { |
| 763 | DEBUGOUT("EEPROM Read Error\n"); |
| 764 | return -E1000_ERR_EEPROM; |
| 765 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) << |
| 767 | SWDPIO__EXT_SHIFT); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 768 | ew32(CTRL_EXT, ctrl_ext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | /* Call the necessary subroutine to configure the link. */ |
| 772 | ret_val = (hw->media_type == e1000_media_type_copper) ? |
| 773 | e1000_setup_copper_link(hw) : |
| 774 | e1000_setup_fiber_serdes_link(hw); |
| 775 | |
| 776 | /* Initialize the flow control address, type, and PAUSE timer |
| 777 | * registers to their default values. This is done even if flow |
| 778 | * control is disabled, because it does not hurt anything to |
| 779 | * initialize these registers. |
| 780 | */ |
| 781 | DEBUGOUT("Initializing the Flow Control address, type and timer regs\n"); |
| 782 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 783 | ew32(FCT, FLOW_CONTROL_TYPE); |
| 784 | ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH); |
| 785 | ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 786 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 787 | ew32(FCTTV, hw->fc_pause_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
| 789 | /* Set the flow control receive threshold registers. Normally, |
| 790 | * these registers will be set to a default threshold that may be |
| 791 | * adjusted later by the driver's runtime code. However, if the |
| 792 | * ability to transmit pause frames in not enabled, then these |
| 793 | * registers will be set to 0. |
| 794 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 795 | if (!(hw->fc & E1000_FC_TX_PAUSE)) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 796 | ew32(FCRTL, 0); |
| 797 | ew32(FCRTH, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | } else { |
| 799 | /* We need to set up the Receive Threshold high and low water marks |
| 800 | * as well as (optionally) enabling the transmission of XON frames. |
| 801 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 802 | if (hw->fc_send_xon) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 803 | ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE)); |
| 804 | ew32(FCRTH, hw->fc_high_water); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | } else { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 806 | ew32(FCRTL, hw->fc_low_water); |
| 807 | ew32(FCRTH, hw->fc_high_water); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | return ret_val; |
| 811 | } |
| 812 | |
| 813 | /****************************************************************************** |
| 814 | * Sets up link for a fiber based or serdes based adapter |
| 815 | * |
| 816 | * hw - Struct containing variables accessed by shared code |
| 817 | * |
| 818 | * Manipulates Physical Coding Sublayer functions in order to configure |
| 819 | * link. Assumes the hardware has been previously reset and the transmitter |
| 820 | * and receiver are not enabled. |
| 821 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 822 | static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 824 | u32 ctrl; |
| 825 | u32 status; |
| 826 | u32 txcw = 0; |
| 827 | u32 i; |
| 828 | u32 signal = 0; |
| 829 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | |
| 831 | DEBUGFUNC("e1000_setup_fiber_serdes_link"); |
| 832 | |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 833 | /* On adapters with a MAC newer than 82544, SWDP 1 will be |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | * set when the optics detect a signal. On older adapters, it will be |
| 835 | * cleared when there is a signal. This applies to fiber media only. |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 836 | * If we're on serdes media, adjust the output amplitude to value |
| 837 | * set in the EEPROM. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 839 | ctrl = er32(CTRL); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 840 | if (hw->media_type == e1000_media_type_fiber) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; |
| 842 | |
| 843 | ret_val = e1000_adjust_serdes_amplitude(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 844 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | return ret_val; |
| 846 | |
| 847 | /* Take the link out of reset */ |
| 848 | ctrl &= ~(E1000_CTRL_LRST); |
| 849 | |
| 850 | /* Adjust VCO speed to improve BER performance */ |
| 851 | ret_val = e1000_set_vco_speed(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 852 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | return ret_val; |
| 854 | |
| 855 | e1000_config_collision_dist(hw); |
| 856 | |
| 857 | /* Check for a software override of the flow control settings, and setup |
| 858 | * the device accordingly. If auto-negotiation is enabled, then software |
| 859 | * will have to set the "PAUSE" bits to the correct value in the Tranmsit |
| 860 | * Config Word Register (TXCW) and re-start auto-negotiation. However, if |
| 861 | * auto-negotiation is disabled, then software will have to manually |
| 862 | * configure the two flow control enable bits in the CTRL register. |
| 863 | * |
| 864 | * The possible values of the "fc" parameter are: |
| 865 | * 0: Flow control is completely disabled |
| 866 | * 1: Rx flow control is enabled (we can receive pause frames, but |
| 867 | * not send pause frames). |
| 868 | * 2: Tx flow control is enabled (we can send pause frames but we do |
| 869 | * not support receiving pause frames). |
| 870 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
| 871 | */ |
| 872 | switch (hw->fc) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 873 | case E1000_FC_NONE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | /* Flow control is completely disabled by a software over-ride. */ |
| 875 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); |
| 876 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 877 | case E1000_FC_RX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | /* RX Flow control is enabled and TX Flow control is disabled by a |
| 879 | * software over-ride. Since there really isn't a way to advertise |
| 880 | * that we are capable of RX Pause ONLY, we will advertise that we |
| 881 | * support both symmetric and asymmetric RX PAUSE. Later, we will |
| 882 | * disable the adapter's ability to send PAUSE frames. |
| 883 | */ |
| 884 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 885 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 886 | case E1000_FC_TX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | /* TX Flow control is enabled, and RX Flow control is disabled, by a |
| 888 | * software over-ride. |
| 889 | */ |
| 890 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); |
| 891 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 892 | case E1000_FC_FULL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | /* Flow control (both RX and TX) is enabled by a software over-ride. */ |
| 894 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 895 | break; |
| 896 | default: |
| 897 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 898 | return -E1000_ERR_CONFIG; |
| 899 | break; |
| 900 | } |
| 901 | |
| 902 | /* Since auto-negotiation is enabled, take the link out of reset (the link |
| 903 | * will be in reset, because we previously reset the chip). This will |
| 904 | * restart auto-negotiation. If auto-neogtiation is successful then the |
| 905 | * link-up status bit will be set and the flow control enable bits (RFCE |
| 906 | * and TFCE) will be set according to their negotiated value. |
| 907 | */ |
| 908 | DEBUGOUT("Auto-negotiation enabled\n"); |
| 909 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 910 | ew32(TXCW, txcw); |
| 911 | ew32(CTRL, ctrl); |
| 912 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
| 914 | hw->txcw = txcw; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 915 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
| 917 | /* If we have a signal (the cable is plugged in) then poll for a "Link-Up" |
| 918 | * indication in the Device Status Register. Time-out if a link isn't |
| 919 | * seen in 500 milliseconds seconds (Auto-negotiation should complete in |
| 920 | * less than 500 milliseconds even if the other end is doing it in SW). |
| 921 | * For internal serdes, we just assume a signal is present, then poll. |
| 922 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 923 | if (hw->media_type == e1000_media_type_internal_serdes || |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 924 | (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | DEBUGOUT("Looking for Link\n"); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 926 | for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) { |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 927 | msleep(10); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 928 | status = er32(STATUS); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 929 | if (status & E1000_STATUS_LU) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 931 | if (i == (LINK_UP_TIMEOUT / 10)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | DEBUGOUT("Never got a valid link from auto-neg!!!\n"); |
| 933 | hw->autoneg_failed = 1; |
| 934 | /* AutoNeg failed to achieve a link, so we'll call |
| 935 | * e1000_check_for_link. This routine will force the link up if |
| 936 | * we detect a signal. This will allow us to communicate with |
| 937 | * non-autonegotiating link partners. |
| 938 | */ |
| 939 | ret_val = e1000_check_for_link(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 940 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | DEBUGOUT("Error while checking for link\n"); |
| 942 | return ret_val; |
| 943 | } |
| 944 | hw->autoneg_failed = 0; |
| 945 | } else { |
| 946 | hw->autoneg_failed = 0; |
| 947 | DEBUGOUT("Valid Link Found\n"); |
| 948 | } |
| 949 | } else { |
| 950 | DEBUGOUT("No Signal Detected\n"); |
| 951 | } |
| 952 | return E1000_SUCCESS; |
| 953 | } |
| 954 | |
| 955 | /****************************************************************************** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 956 | * 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] | 957 | * |
| 958 | * hw - Struct containing variables accessed by shared code |
| 959 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 960 | static s32 e1000_copper_link_preconfig(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 962 | u32 ctrl; |
| 963 | s32 ret_val; |
| 964 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 966 | DEBUGFUNC("e1000_copper_link_preconfig"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 968 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | /* With 82543, we need to force speed and duplex on the MAC equal to what |
| 970 | * the PHY speed and duplex configuration is. In addition, we need to |
| 971 | * perform a hardware reset on the PHY to take it out of reset. |
| 972 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 973 | if (hw->mac_type > e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | ctrl |= E1000_CTRL_SLU; |
| 975 | ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 976 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | } else { |
| 978 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 979 | ew32(CTRL, ctrl); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 980 | ret_val = e1000_phy_hw_reset(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 981 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 982 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | /* Make sure we have a valid PHY */ |
| 986 | ret_val = e1000_detect_gig_phy(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 987 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | DEBUGOUT("Error, did not detect valid phy.\n"); |
| 989 | return ret_val; |
| 990 | } |
| 991 | DEBUGOUT1("Phy ID = %x \n", hw->phy_id); |
| 992 | |
| 993 | /* Set PHY to class A mode (if necessary) */ |
| 994 | ret_val = e1000_set_phy_mode(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 995 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | return ret_val; |
| 997 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 998 | if ((hw->mac_type == e1000_82545_rev_3) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | (hw->mac_type == e1000_82546_rev_3)) { |
| 1000 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 1001 | phy_data |= 0x00000008; |
| 1002 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 1003 | } |
| 1004 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1005 | if (hw->mac_type <= e1000_82543 || |
| 1006 | hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 || |
| 1007 | 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] | 1008 | hw->phy_reset_disable = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1010 | return E1000_SUCCESS; |
| 1011 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1014 | /******************************************************************** |
| 1015 | * Copper link setup for e1000_phy_igp series. |
| 1016 | * |
| 1017 | * hw - Struct containing variables accessed by shared code |
| 1018 | *********************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1019 | static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1020 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1021 | u32 led_ctrl; |
| 1022 | s32 ret_val; |
| 1023 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1025 | DEBUGFUNC("e1000_copper_link_igp_setup"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1027 | if (hw->phy_reset_disable) |
| 1028 | return E1000_SUCCESS; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1029 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1030 | ret_val = e1000_phy_reset(hw); |
| 1031 | if (ret_val) { |
| 1032 | DEBUGOUT("Error Resetting the PHY\n"); |
| 1033 | return ret_val; |
| 1034 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1036 | /* Wait 15ms for MAC to configure PHY from eeprom settings */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1037 | msleep(15); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1038 | /* Configure activity LED after PHY reset */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1039 | led_ctrl = er32(LEDCTL); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1040 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 1041 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1042 | ew32(LEDCTL, led_ctrl); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1043 | |
Jeff Kirsher | c9c1b83 | 2006-08-16 13:38:54 -0700 | [diff] [blame] | 1044 | /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */ |
| 1045 | if (hw->phy_type == e1000_phy_igp) { |
| 1046 | /* disable lplu d3 during driver init */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1047 | ret_val = e1000_set_d3_lplu_state(hw, false); |
Jeff Kirsher | c9c1b83 | 2006-08-16 13:38:54 -0700 | [diff] [blame] | 1048 | if (ret_val) { |
| 1049 | DEBUGOUT("Error Disabling LPLU D3\n"); |
| 1050 | return ret_val; |
| 1051 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1054 | /* Configure mdi-mdix settings */ |
| 1055 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); |
| 1056 | if (ret_val) |
| 1057 | return ret_val; |
| 1058 | |
| 1059 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 1060 | hw->dsp_config_state = e1000_dsp_config_disabled; |
| 1061 | /* Force MDI for earlier revs of the IGP PHY */ |
| 1062 | phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX); |
| 1063 | hw->mdix = 1; |
| 1064 | |
| 1065 | } else { |
| 1066 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 1067 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 1068 | |
| 1069 | switch (hw->mdix) { |
| 1070 | case 1: |
| 1071 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 1072 | break; |
| 1073 | case 2: |
| 1074 | phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 1075 | break; |
| 1076 | case 0: |
| 1077 | default: |
| 1078 | phy_data |= IGP01E1000_PSCR_AUTO_MDIX; |
| 1079 | break; |
| 1080 | } |
| 1081 | } |
| 1082 | 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] | 1083 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1084 | return ret_val; |
| 1085 | |
| 1086 | /* set auto-master slave resolution settings */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1087 | if (hw->autoneg) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1088 | e1000_ms_type phy_ms_setting = hw->master_slave; |
| 1089 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1090 | if (hw->ffe_config_state == e1000_ffe_config_active) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1091 | hw->ffe_config_state = e1000_ffe_config_enabled; |
| 1092 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1093 | if (hw->dsp_config_state == e1000_dsp_config_activated) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1094 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 1095 | |
| 1096 | /* when autonegotiation advertisment is only 1000Mbps then we |
| 1097 | * should disable SmartSpeed and enable Auto MasterSlave |
| 1098 | * resolution as hardware default. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1099 | if (hw->autoneg_advertised == ADVERTISE_1000_FULL) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1100 | /* Disable SmartSpeed */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1101 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 1102 | &phy_data); |
| 1103 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1105 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1106 | ret_val = e1000_write_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 | /* Set auto Master/Slave resolution process */ |
| 1111 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1112 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1113 | return ret_val; |
| 1114 | phy_data &= ~CR_1000T_MS_ENABLE; |
| 1115 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1116 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1117 | return ret_val; |
| 1118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1120 | ret_val = e1000_read_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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1124 | /* load defaults for future use */ |
| 1125 | hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ? |
| 1126 | ((phy_data & CR_1000T_MS_VALUE) ? |
| 1127 | e1000_ms_force_master : |
| 1128 | e1000_ms_force_slave) : |
| 1129 | e1000_ms_auto; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1131 | switch (phy_ms_setting) { |
| 1132 | case e1000_ms_force_master: |
| 1133 | phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE); |
| 1134 | break; |
| 1135 | case e1000_ms_force_slave: |
| 1136 | phy_data |= CR_1000T_MS_ENABLE; |
| 1137 | phy_data &= ~(CR_1000T_MS_VALUE); |
| 1138 | break; |
| 1139 | case e1000_ms_auto: |
| 1140 | phy_data &= ~CR_1000T_MS_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | default: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1142 | break; |
| 1143 | } |
| 1144 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1145 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1146 | return ret_val; |
Malli Chilakala | 2b02893 | 2005-06-17 17:46:06 -0700 | [diff] [blame] | 1147 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
Malli Chilakala | 2b02893 | 2005-06-17 17:46:06 -0700 | [diff] [blame] | 1149 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1152 | /******************************************************************** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1153 | * Copper link setup for e1000_phy_m88 series. |
| 1154 | * |
| 1155 | * hw - Struct containing variables accessed by shared code |
| 1156 | *********************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1157 | static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1158 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1159 | s32 ret_val; |
| 1160 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1162 | DEBUGFUNC("e1000_copper_link_mgp_setup"); |
| 1163 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1164 | if (hw->phy_reset_disable) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1165 | return E1000_SUCCESS; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1166 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1167 | /* Enable CRS on TX. This must be set for half-duplex operation. */ |
| 1168 | 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] | 1169 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1170 | return ret_val; |
| 1171 | |
| 1172 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 1173 | |
| 1174 | /* Options: |
| 1175 | * MDI/MDI-X = 0 (default) |
| 1176 | * 0 - Auto for all speeds |
| 1177 | * 1 - MDI mode |
| 1178 | * 2 - MDI-X mode |
| 1179 | * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) |
| 1180 | */ |
| 1181 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 1182 | |
| 1183 | switch (hw->mdix) { |
| 1184 | case 1: |
| 1185 | phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE; |
| 1186 | break; |
| 1187 | case 2: |
| 1188 | phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE; |
| 1189 | break; |
| 1190 | case 3: |
| 1191 | phy_data |= M88E1000_PSCR_AUTO_X_1000T; |
| 1192 | break; |
| 1193 | case 0: |
| 1194 | default: |
| 1195 | phy_data |= M88E1000_PSCR_AUTO_X_MODE; |
| 1196 | break; |
| 1197 | } |
| 1198 | |
| 1199 | /* Options: |
| 1200 | * disable_polarity_correction = 0 (default) |
| 1201 | * Automatic Correction for Reversed Cable Polarity |
| 1202 | * 0 - Disabled |
| 1203 | * 1 - Enabled |
| 1204 | */ |
| 1205 | phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1206 | if (hw->disable_polarity_correction == 1) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1207 | phy_data |= M88E1000_PSCR_POLARITY_REVERSAL; |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1208 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 1209 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1210 | return ret_val; |
| 1211 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1212 | if (hw->phy_revision < M88E1011_I_REV_4) { |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1213 | /* Force TX_CLK in the Extended PHY Specific Control Register |
| 1214 | * to 25MHz clock. |
| 1215 | */ |
| 1216 | ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data); |
| 1217 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1218 | return ret_val; |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1219 | |
| 1220 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
| 1221 | |
| 1222 | if ((hw->phy_revision == E1000_REVISION_2) && |
| 1223 | (hw->phy_id == M88E1111_I_PHY_ID)) { |
| 1224 | /* Vidalia Phy, set the downshift counter to 5x */ |
| 1225 | phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK); |
| 1226 | phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X; |
| 1227 | ret_val = e1000_write_phy_reg(hw, |
| 1228 | M88E1000_EXT_PHY_SPEC_CTRL, phy_data); |
| 1229 | if (ret_val) |
| 1230 | return ret_val; |
| 1231 | } else { |
| 1232 | /* Configure Master and Slave downshift values */ |
| 1233 | phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK | |
| 1234 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK); |
| 1235 | phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X | |
| 1236 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X); |
| 1237 | ret_val = e1000_write_phy_reg(hw, |
| 1238 | M88E1000_EXT_PHY_SPEC_CTRL, phy_data); |
| 1239 | if (ret_val) |
| 1240 | return ret_val; |
| 1241 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1242 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1244 | /* SW Reset the PHY so all changes take effect */ |
| 1245 | ret_val = e1000_phy_reset(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1246 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1247 | DEBUGOUT("Error Resetting the PHY\n"); |
| 1248 | return ret_val; |
| 1249 | } |
| 1250 | |
| 1251 | return E1000_SUCCESS; |
| 1252 | } |
| 1253 | |
| 1254 | /******************************************************************** |
| 1255 | * Setup auto-negotiation and flow control advertisements, |
| 1256 | * and then perform auto-negotiation. |
| 1257 | * |
| 1258 | * hw - Struct containing variables accessed by shared code |
| 1259 | *********************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1260 | static s32 e1000_copper_link_autoneg(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1261 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1262 | s32 ret_val; |
| 1263 | u16 phy_data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1264 | |
| 1265 | DEBUGFUNC("e1000_copper_link_autoneg"); |
| 1266 | |
| 1267 | /* Perform some bounds checking on the hw->autoneg_advertised |
| 1268 | * parameter. If this variable is zero, then set it to the default. |
| 1269 | */ |
| 1270 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT; |
| 1271 | |
| 1272 | /* If autoneg_advertised is zero, we assume it was not defaulted |
| 1273 | * by the calling code so we set to advertise full capability. |
| 1274 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1275 | if (hw->autoneg_advertised == 0) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1276 | hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT; |
| 1277 | |
| 1278 | DEBUGOUT("Reconfiguring auto-neg advertisement params\n"); |
| 1279 | ret_val = e1000_phy_setup_autoneg(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1280 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1281 | DEBUGOUT("Error Setting up Auto-Negotiation\n"); |
| 1282 | return ret_val; |
| 1283 | } |
| 1284 | DEBUGOUT("Restarting Auto-Neg\n"); |
| 1285 | |
| 1286 | /* Restart auto-negotiation by setting the Auto Neg Enable bit and |
| 1287 | * the Auto Neg Restart bit in the PHY control register. |
| 1288 | */ |
| 1289 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1290 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1291 | return ret_val; |
| 1292 | |
| 1293 | phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); |
| 1294 | ret_val = e1000_write_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 | /* Does the user want to wait for Auto-Neg to complete here, or |
| 1299 | * check at a later time (for example, callback routine). |
| 1300 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1301 | if (hw->wait_autoneg_complete) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1302 | ret_val = e1000_wait_autoneg(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1303 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1304 | DEBUGOUT("Error while waiting for autoneg to complete\n"); |
| 1305 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1307 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1309 | hw->get_link_status = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1311 | return E1000_SUCCESS; |
| 1312 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1314 | /****************************************************************************** |
| 1315 | * Config the MAC and the PHY after link is up. |
| 1316 | * 1) Set up the MAC to the current PHY speed/duplex |
| 1317 | * if we are on 82543. If we |
| 1318 | * are on newer silicon, we only need to configure |
| 1319 | * collision distance in the Transmit Control Register. |
| 1320 | * 2) Set up flow control on the MAC to that established with |
| 1321 | * the link partner. |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1322 | * 3) Config DSP to improve Gigabit link quality for some PHY revisions. |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1323 | * |
| 1324 | * hw - Struct containing variables accessed by shared code |
| 1325 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1326 | static s32 e1000_copper_link_postconfig(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1327 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1328 | s32 ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1329 | DEBUGFUNC("e1000_copper_link_postconfig"); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1330 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1331 | if (hw->mac_type >= e1000_82544) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1332 | e1000_config_collision_dist(hw); |
| 1333 | } else { |
| 1334 | ret_val = e1000_config_mac_to_phy(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1335 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1336 | DEBUGOUT("Error configuring MAC to PHY settings\n"); |
| 1337 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1339 | } |
| 1340 | ret_val = e1000_config_fc_after_link_up(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1341 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1342 | DEBUGOUT("Error Configuring Flow Control\n"); |
| 1343 | return ret_val; |
| 1344 | } |
| 1345 | |
| 1346 | /* Config DSP to improve Giga link quality */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1347 | if (hw->phy_type == e1000_phy_igp) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1348 | ret_val = e1000_config_dsp_after_link_change(hw, true); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1349 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1350 | DEBUGOUT("Error Configuring DSP after link up\n"); |
| 1351 | return ret_val; |
| 1352 | } |
| 1353 | } |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1354 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1355 | return E1000_SUCCESS; |
| 1356 | } |
| 1357 | |
| 1358 | /****************************************************************************** |
| 1359 | * Detects which PHY is present and setup the speed and duplex |
| 1360 | * |
| 1361 | * hw - Struct containing variables accessed by shared code |
| 1362 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1363 | static s32 e1000_setup_copper_link(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1364 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1365 | s32 ret_val; |
| 1366 | u16 i; |
| 1367 | u16 phy_data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1368 | |
| 1369 | DEBUGFUNC("e1000_setup_copper_link"); |
| 1370 | |
| 1371 | /* Check if it is a valid PHY and set PHY mode if necessary. */ |
| 1372 | ret_val = e1000_copper_link_preconfig(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1373 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1374 | return ret_val; |
| 1375 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 1376 | if (hw->phy_type == e1000_phy_igp) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1377 | ret_val = e1000_copper_link_igp_setup(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 | } else if (hw->phy_type == e1000_phy_m88) { |
| 1381 | ret_val = e1000_copper_link_mgp_setup(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1382 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1383 | return ret_val; |
| 1384 | } |
| 1385 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1386 | if (hw->autoneg) { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1387 | /* Setup autoneg and flow control advertisement |
| 1388 | * and perform autonegotiation */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1389 | ret_val = e1000_copper_link_autoneg(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1390 | if (ret_val) |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1391 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1392 | } else { |
| 1393 | /* PHY will be set to 10H, 10F, 100H,or 100F |
| 1394 | * depending on value from forced_speed_duplex. */ |
| 1395 | DEBUGOUT("Forcing speed and duplex\n"); |
| 1396 | ret_val = e1000_phy_force_speed_duplex(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1397 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1398 | DEBUGOUT("Error Forcing Speed and Duplex\n"); |
| 1399 | return ret_val; |
| 1400 | } |
| 1401 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | |
| 1403 | /* Check link status. Wait up to 100 microseconds for link to become |
| 1404 | * valid. |
| 1405 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1406 | for (i = 0; i < 10; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1408 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | return ret_val; |
| 1410 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1411 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | return ret_val; |
| 1413 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1414 | if (phy_data & MII_SR_LINK_STATUS) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1415 | /* Config the MAC and PHY after link is up */ |
| 1416 | ret_val = e1000_copper_link_postconfig(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1417 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | return ret_val; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | DEBUGOUT("Valid link established!!!\n"); |
| 1421 | return E1000_SUCCESS; |
| 1422 | } |
| 1423 | udelay(10); |
| 1424 | } |
| 1425 | |
| 1426 | DEBUGOUT("Unable to establish link!!!\n"); |
| 1427 | return E1000_SUCCESS; |
| 1428 | } |
| 1429 | |
| 1430 | /****************************************************************************** |
| 1431 | * Configures PHY autoneg and flow control advertisement settings |
| 1432 | * |
| 1433 | * hw - Struct containing variables accessed by shared code |
| 1434 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1435 | s32 e1000_phy_setup_autoneg(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1437 | s32 ret_val; |
| 1438 | u16 mii_autoneg_adv_reg; |
| 1439 | u16 mii_1000t_ctrl_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | |
| 1441 | DEBUGFUNC("e1000_phy_setup_autoneg"); |
| 1442 | |
| 1443 | /* Read the MII Auto-Neg Advertisement Register (Address 4). */ |
| 1444 | 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] | 1445 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | return ret_val; |
| 1447 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 1448 | /* Read the MII 1000Base-T Control Register (Address 9). */ |
| 1449 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg); |
| 1450 | if (ret_val) |
| 1451 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | |
| 1453 | /* Need to parse both autoneg_advertised and fc and set up |
| 1454 | * the appropriate PHY registers. First we will parse for |
| 1455 | * autoneg_advertised software override. Since we can advertise |
| 1456 | * a plethora of combinations, we need to check each bit |
| 1457 | * individually. |
| 1458 | */ |
| 1459 | |
| 1460 | /* First we clear all the 10/100 mb speed bits in the Auto-Neg |
| 1461 | * Advertisement Register (Address 4) and the 1000 mb speed bits in |
| 1462 | * the 1000Base-T Control Register (Address 9). |
| 1463 | */ |
| 1464 | mii_autoneg_adv_reg &= ~REG4_SPEED_MASK; |
| 1465 | mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK; |
| 1466 | |
| 1467 | DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised); |
| 1468 | |
| 1469 | /* Do we want to advertise 10 Mb Half Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1470 | if (hw->autoneg_advertised & ADVERTISE_10_HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | DEBUGOUT("Advertise 10mb Half duplex\n"); |
| 1472 | mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS; |
| 1473 | } |
| 1474 | |
| 1475 | /* Do we want to advertise 10 Mb Full Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1476 | if (hw->autoneg_advertised & ADVERTISE_10_FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | DEBUGOUT("Advertise 10mb Full duplex\n"); |
| 1478 | mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS; |
| 1479 | } |
| 1480 | |
| 1481 | /* Do we want to advertise 100 Mb Half Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1482 | if (hw->autoneg_advertised & ADVERTISE_100_HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | DEBUGOUT("Advertise 100mb Half duplex\n"); |
| 1484 | mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS; |
| 1485 | } |
| 1486 | |
| 1487 | /* Do we want to advertise 100 Mb Full Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1488 | if (hw->autoneg_advertised & ADVERTISE_100_FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | DEBUGOUT("Advertise 100mb Full duplex\n"); |
| 1490 | mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS; |
| 1491 | } |
| 1492 | |
| 1493 | /* We do not allow the Phy to advertise 1000 Mb Half Duplex */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1494 | if (hw->autoneg_advertised & ADVERTISE_1000_HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n"); |
| 1496 | } |
| 1497 | |
| 1498 | /* Do we want to advertise 1000 Mb Full Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1499 | if (hw->autoneg_advertised & ADVERTISE_1000_FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | DEBUGOUT("Advertise 1000mb Full duplex\n"); |
| 1501 | mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS; |
| 1502 | } |
| 1503 | |
| 1504 | /* Check for a software override of the flow control settings, and |
| 1505 | * setup the PHY advertisement registers accordingly. If |
| 1506 | * auto-negotiation is enabled, then software will have to set the |
| 1507 | * "PAUSE" bits to the correct value in the Auto-Negotiation |
| 1508 | * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation. |
| 1509 | * |
| 1510 | * The possible values of the "fc" parameter are: |
| 1511 | * 0: Flow control is completely disabled |
| 1512 | * 1: Rx flow control is enabled (we can receive pause frames |
| 1513 | * but not send pause frames). |
| 1514 | * 2: Tx flow control is enabled (we can send pause frames |
| 1515 | * but we do not support receiving pause frames). |
| 1516 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
| 1517 | * other: No software override. The flow control configuration |
| 1518 | * in the EEPROM is used. |
| 1519 | */ |
| 1520 | switch (hw->fc) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1521 | case E1000_FC_NONE: /* 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | /* Flow control (RX & TX) is completely disabled by a |
| 1523 | * software over-ride. |
| 1524 | */ |
| 1525 | mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 1526 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1527 | case E1000_FC_RX_PAUSE: /* 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | /* RX Flow control is enabled, and TX Flow control is |
| 1529 | * disabled, by a software over-ride. |
| 1530 | */ |
| 1531 | /* Since there really isn't a way to advertise that we are |
| 1532 | * capable of RX Pause ONLY, we will advertise that we |
| 1533 | * support both symmetric and asymmetric RX PAUSE. Later |
| 1534 | * (in e1000_config_fc_after_link_up) we will disable the |
| 1535 | *hw's ability to send PAUSE frames. |
| 1536 | */ |
| 1537 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 1538 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1539 | case E1000_FC_TX_PAUSE: /* 2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | /* TX Flow control is enabled, and RX Flow control is |
| 1541 | * disabled, by a software over-ride. |
| 1542 | */ |
| 1543 | mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR; |
| 1544 | mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE; |
| 1545 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1546 | case E1000_FC_FULL: /* 3 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | /* Flow control (both RX and TX) is enabled by a software |
| 1548 | * over-ride. |
| 1549 | */ |
| 1550 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 1551 | break; |
| 1552 | default: |
| 1553 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 1554 | return -E1000_ERR_CONFIG; |
| 1555 | } |
| 1556 | |
| 1557 | 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] | 1558 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | return ret_val; |
| 1560 | |
| 1561 | DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg); |
| 1562 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 1563 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg); |
| 1564 | if (ret_val) |
| 1565 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | |
| 1567 | return E1000_SUCCESS; |
| 1568 | } |
| 1569 | |
| 1570 | /****************************************************************************** |
| 1571 | * Force PHY speed and duplex settings to hw->forced_speed_duplex |
| 1572 | * |
| 1573 | * hw - Struct containing variables accessed by shared code |
| 1574 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1575 | static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1577 | u32 ctrl; |
| 1578 | s32 ret_val; |
| 1579 | u16 mii_ctrl_reg; |
| 1580 | u16 mii_status_reg; |
| 1581 | u16 phy_data; |
| 1582 | u16 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | |
| 1584 | DEBUGFUNC("e1000_phy_force_speed_duplex"); |
| 1585 | |
| 1586 | /* Turn off Flow control if we are forcing speed and duplex. */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1587 | hw->fc = E1000_FC_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | |
| 1589 | DEBUGOUT1("hw->fc = %d\n", hw->fc); |
| 1590 | |
| 1591 | /* Read the Device Control Register. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1592 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | |
| 1594 | /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */ |
| 1595 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 1596 | ctrl &= ~(DEVICE_SPEED_MASK); |
| 1597 | |
| 1598 | /* Clear the Auto Speed Detect Enable bit. */ |
| 1599 | ctrl &= ~E1000_CTRL_ASDE; |
| 1600 | |
| 1601 | /* Read the MII Control Register. */ |
| 1602 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1603 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | return ret_val; |
| 1605 | |
| 1606 | /* We need to disable autoneg in order to force link and duplex. */ |
| 1607 | |
| 1608 | mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN; |
| 1609 | |
| 1610 | /* Are we forcing Full or Half Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1611 | if (hw->forced_speed_duplex == e1000_100_full || |
| 1612 | hw->forced_speed_duplex == e1000_10_full) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | /* We want to force full duplex so we SET the full duplex bits in the |
| 1614 | * Device and MII Control Registers. |
| 1615 | */ |
| 1616 | ctrl |= E1000_CTRL_FD; |
| 1617 | mii_ctrl_reg |= MII_CR_FULL_DUPLEX; |
| 1618 | DEBUGOUT("Full Duplex\n"); |
| 1619 | } else { |
| 1620 | /* We want to force half duplex so we CLEAR the full duplex bits in |
| 1621 | * the Device and MII Control Registers. |
| 1622 | */ |
| 1623 | ctrl &= ~E1000_CTRL_FD; |
| 1624 | mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX; |
| 1625 | DEBUGOUT("Half Duplex\n"); |
| 1626 | } |
| 1627 | |
| 1628 | /* Are we forcing 100Mbps??? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1629 | if (hw->forced_speed_duplex == e1000_100_full || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | hw->forced_speed_duplex == e1000_100_half) { |
| 1631 | /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */ |
| 1632 | ctrl |= E1000_CTRL_SPD_100; |
| 1633 | mii_ctrl_reg |= MII_CR_SPEED_100; |
| 1634 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10); |
| 1635 | DEBUGOUT("Forcing 100mb "); |
| 1636 | } else { |
| 1637 | /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */ |
| 1638 | ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100); |
| 1639 | mii_ctrl_reg |= MII_CR_SPEED_10; |
| 1640 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100); |
| 1641 | DEBUGOUT("Forcing 10mb "); |
| 1642 | } |
| 1643 | |
| 1644 | e1000_config_collision_dist(hw); |
| 1645 | |
| 1646 | /* Write the configured values back to the Device Control Reg. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1647 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 1649 | if (hw->phy_type == e1000_phy_m88) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | 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] | 1651 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | return ret_val; |
| 1653 | |
| 1654 | /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI |
| 1655 | * forced whenever speed are duplex are forced. |
| 1656 | */ |
| 1657 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 1658 | 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] | 1659 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | return ret_val; |
| 1661 | |
| 1662 | DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data); |
| 1663 | |
| 1664 | /* Need to reset the PHY or these changes will be ignored */ |
| 1665 | mii_ctrl_reg |= MII_CR_RESET; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 1666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | } else { |
| 1668 | /* Clear Auto-Crossover to force MDI manually. IGP requires MDI |
| 1669 | * forced whenever speed or duplex are forced. |
| 1670 | */ |
| 1671 | 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] | 1672 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | return ret_val; |
| 1674 | |
| 1675 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 1676 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 1677 | |
| 1678 | 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] | 1679 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | return ret_val; |
| 1681 | } |
| 1682 | |
| 1683 | /* Write back the modified PHY MII control register. */ |
| 1684 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1685 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | return ret_val; |
| 1687 | |
| 1688 | udelay(1); |
| 1689 | |
| 1690 | /* The wait_autoneg_complete flag may be a little misleading here. |
| 1691 | * Since we are forcing speed and duplex, Auto-Neg is not enabled. |
| 1692 | * But we do want to delay for a period while forcing only so we |
| 1693 | * don't generate false No Link messages. So we will wait here |
| 1694 | * only if the user has set wait_autoneg_complete to 1, which is |
| 1695 | * the default. |
| 1696 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1697 | if (hw->wait_autoneg_complete) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | /* We will wait for autoneg to complete. */ |
| 1699 | DEBUGOUT("Waiting for forced speed/duplex link.\n"); |
| 1700 | mii_status_reg = 0; |
| 1701 | |
| 1702 | /* 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] | 1703 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | /* Read the MII Status Register and wait for Auto-Neg Complete bit |
| 1705 | * to be set. |
| 1706 | */ |
| 1707 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1708 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | return ret_val; |
| 1710 | |
| 1711 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1712 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | return ret_val; |
| 1714 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1715 | if (mii_status_reg & MII_SR_LINK_STATUS) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1716 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1718 | if ((i == 0) && |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 1719 | (hw->phy_type == e1000_phy_m88)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | /* We didn't get link. Reset the DSP and wait again for link. */ |
| 1721 | ret_val = e1000_phy_reset_dsp(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1722 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | DEBUGOUT("Error Resetting PHY DSP\n"); |
| 1724 | return ret_val; |
| 1725 | } |
| 1726 | } |
| 1727 | /* This loop will early-out if the link condition has been met. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1728 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
| 1729 | if (mii_status_reg & MII_SR_LINK_STATUS) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1730 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | /* Read the MII Status Register and wait for Auto-Neg Complete bit |
| 1732 | * to be set. |
| 1733 | */ |
| 1734 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1735 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | return ret_val; |
| 1737 | |
| 1738 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1739 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | return ret_val; |
| 1741 | } |
| 1742 | } |
| 1743 | |
| 1744 | if (hw->phy_type == e1000_phy_m88) { |
| 1745 | /* Because we reset the PHY above, we need to re-force TX_CLK in the |
| 1746 | * Extended PHY Specific Control Register to 25MHz clock. This value |
| 1747 | * defaults back to a 2.5MHz clock when the PHY is reset. |
| 1748 | */ |
| 1749 | 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] | 1750 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | return ret_val; |
| 1752 | |
| 1753 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
| 1754 | 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] | 1755 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | return ret_val; |
| 1757 | |
| 1758 | /* In addition, because of the s/w reset above, we need to enable CRS on |
| 1759 | * TX. This must be set for both full and half duplex operation. |
| 1760 | */ |
| 1761 | 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] | 1762 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | return ret_val; |
| 1764 | |
| 1765 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 1766 | 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] | 1767 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | return ret_val; |
| 1769 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1770 | if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) && |
| 1771 | (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full || |
| 1772 | hw->forced_speed_duplex == e1000_10_half)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | ret_val = e1000_polarity_reversal_workaround(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1774 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | return ret_val; |
| 1776 | } |
| 1777 | } |
| 1778 | return E1000_SUCCESS; |
| 1779 | } |
| 1780 | |
| 1781 | /****************************************************************************** |
| 1782 | * Sets the collision distance in the Transmit Control register |
| 1783 | * |
| 1784 | * hw - Struct containing variables accessed by shared code |
| 1785 | * |
| 1786 | * Link should have been established previously. Reads the speed and duplex |
| 1787 | * information from the Device Status register. |
| 1788 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1789 | void e1000_config_collision_dist(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1791 | u32 tctl, coll_dist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | |
| 1793 | DEBUGFUNC("e1000_config_collision_dist"); |
| 1794 | |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1795 | if (hw->mac_type < e1000_82543) |
| 1796 | coll_dist = E1000_COLLISION_DISTANCE_82542; |
| 1797 | else |
| 1798 | coll_dist = E1000_COLLISION_DISTANCE; |
| 1799 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1800 | tctl = er32(TCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | |
| 1802 | tctl &= ~E1000_TCTL_COLD; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1803 | tctl |= coll_dist << E1000_COLD_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1805 | ew32(TCTL, tctl); |
| 1806 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | /****************************************************************************** |
| 1810 | * Sets MAC speed and duplex settings to reflect the those in the PHY |
| 1811 | * |
| 1812 | * hw - Struct containing variables accessed by shared code |
| 1813 | * mii_reg - data to write to the MII control register |
| 1814 | * |
| 1815 | * The contents of the PHY register containing the needed information need to |
| 1816 | * be passed in. |
| 1817 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1818 | static s32 e1000_config_mac_to_phy(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1820 | u32 ctrl; |
| 1821 | s32 ret_val; |
| 1822 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | |
| 1824 | DEBUGFUNC("e1000_config_mac_to_phy"); |
| 1825 | |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1826 | /* 82544 or newer MAC, Auto Speed Detection takes care of |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1827 | * MAC speed/duplex configuration.*/ |
| 1828 | if (hw->mac_type >= e1000_82544) |
| 1829 | return E1000_SUCCESS; |
| 1830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | /* Read the Device Control Register and set the bits to Force Speed |
| 1832 | * and Duplex. |
| 1833 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1834 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 1836 | ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS); |
| 1837 | |
| 1838 | /* Set up duplex in the Device Control and Transmit Control |
| 1839 | * registers depending on negotiated values. |
| 1840 | */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1841 | 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] | 1842 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1843 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1845 | if (phy_data & M88E1000_PSSR_DPLX) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1846 | ctrl |= E1000_CTRL_FD; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1847 | else |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1848 | ctrl &= ~E1000_CTRL_FD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1850 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1852 | /* Set up speed in the Device Control register depending on |
| 1853 | * negotiated values. |
| 1854 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1855 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1856 | ctrl |= E1000_CTRL_SPD_1000; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1857 | else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1858 | ctrl |= E1000_CTRL_SPD_100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | /* Write the configured values back to the Device Control Reg. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1861 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | return E1000_SUCCESS; |
| 1863 | } |
| 1864 | |
| 1865 | /****************************************************************************** |
| 1866 | * Forces the MAC's flow control settings. |
| 1867 | * |
| 1868 | * hw - Struct containing variables accessed by shared code |
| 1869 | * |
| 1870 | * Sets the TFCE and RFCE bits in the device control register to reflect |
| 1871 | * the adapter settings. TFCE and RFCE need to be explicitly set by |
| 1872 | * software when a Copper PHY is used because autonegotiation is managed |
| 1873 | * by the PHY rather than the MAC. Software must also configure these |
| 1874 | * bits when link is forced on a fiber connection. |
| 1875 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1876 | s32 e1000_force_mac_fc(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1878 | u32 ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | |
| 1880 | DEBUGFUNC("e1000_force_mac_fc"); |
| 1881 | |
| 1882 | /* Get the current configuration of the Device Control Register */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1883 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | |
| 1885 | /* Because we didn't get link via the internal auto-negotiation |
| 1886 | * mechanism (we either forced link or we got link via PHY |
| 1887 | * auto-neg), we have to manually enable/disable transmit an |
| 1888 | * receive flow control. |
| 1889 | * |
| 1890 | * The "Case" statement below enables/disable flow control |
| 1891 | * according to the "hw->fc" parameter. |
| 1892 | * |
| 1893 | * The possible values of the "fc" parameter are: |
| 1894 | * 0: Flow control is completely disabled |
| 1895 | * 1: Rx flow control is enabled (we can receive pause |
| 1896 | * frames but not send pause frames). |
| 1897 | * 2: Tx flow control is enabled (we can send pause frames |
| 1898 | * frames but we do not receive pause frames). |
| 1899 | * 3: Both Rx and TX flow control (symmetric) is enabled. |
| 1900 | * other: No other values should be possible at this point. |
| 1901 | */ |
| 1902 | |
| 1903 | switch (hw->fc) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1904 | case E1000_FC_NONE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); |
| 1906 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1907 | case E1000_FC_RX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | ctrl &= (~E1000_CTRL_TFCE); |
| 1909 | ctrl |= E1000_CTRL_RFCE; |
| 1910 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1911 | case E1000_FC_TX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | ctrl &= (~E1000_CTRL_RFCE); |
| 1913 | ctrl |= E1000_CTRL_TFCE; |
| 1914 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1915 | case E1000_FC_FULL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); |
| 1917 | break; |
| 1918 | default: |
| 1919 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 1920 | return -E1000_ERR_CONFIG; |
| 1921 | } |
| 1922 | |
| 1923 | /* Disable TX Flow Control for 82542 (rev 2.0) */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1924 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | ctrl &= (~E1000_CTRL_TFCE); |
| 1926 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1927 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | return E1000_SUCCESS; |
| 1929 | } |
| 1930 | |
| 1931 | /****************************************************************************** |
| 1932 | * Configures flow control settings after link is established |
| 1933 | * |
| 1934 | * hw - Struct containing variables accessed by shared code |
| 1935 | * |
| 1936 | * Should be called immediately after a valid link has been established. |
| 1937 | * Forces MAC flow control settings if link was forced. When in MII/GMII mode |
| 1938 | * and autonegotiation is enabled, the MAC flow control settings will be set |
| 1939 | * based on the flow control negotiated by the PHY. In TBI mode, the TFCE |
| 1940 | * and RFCE bits will be automaticaly set to the negotiated flow control mode. |
| 1941 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1942 | static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1944 | s32 ret_val; |
| 1945 | u16 mii_status_reg; |
| 1946 | u16 mii_nway_adv_reg; |
| 1947 | u16 mii_nway_lp_ability_reg; |
| 1948 | u16 speed; |
| 1949 | u16 duplex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | |
| 1951 | DEBUGFUNC("e1000_config_fc_after_link_up"); |
| 1952 | |
| 1953 | /* Check for the case where we have fiber media and auto-neg failed |
| 1954 | * so we had to force link. In this case, we need to force the |
| 1955 | * configuration of the MAC to match the "fc" parameter. |
| 1956 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1957 | if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) || |
| 1958 | ((hw->media_type == e1000_media_type_internal_serdes) && |
| 1959 | (hw->autoneg_failed)) || |
| 1960 | ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | ret_val = e1000_force_mac_fc(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1962 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | DEBUGOUT("Error forcing flow control settings\n"); |
| 1964 | return ret_val; |
| 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | /* Check for the case where we have copper media and auto-neg is |
| 1969 | * enabled. In this case, we need to check and see if Auto-Neg |
| 1970 | * has completed, and if so, how the PHY and link partner has |
| 1971 | * flow control configured. |
| 1972 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1973 | if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | /* Read the MII Status Register and check to see if AutoNeg |
| 1975 | * has completed. We read this twice because this reg has |
| 1976 | * some "sticky" (latched) bits. |
| 1977 | */ |
| 1978 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1979 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | return ret_val; |
| 1981 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1982 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | return ret_val; |
| 1984 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1985 | if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | /* The AutoNeg process has completed, so we now need to |
| 1987 | * read both the Auto Negotiation Advertisement Register |
| 1988 | * (Address 4) and the Auto_Negotiation Base Page Ability |
| 1989 | * Register (Address 5) to determine how flow control was |
| 1990 | * negotiated. |
| 1991 | */ |
| 1992 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, |
| 1993 | &mii_nway_adv_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1994 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | return ret_val; |
| 1996 | ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, |
| 1997 | &mii_nway_lp_ability_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1998 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | return ret_val; |
| 2000 | |
| 2001 | /* Two bits in the Auto Negotiation Advertisement Register |
| 2002 | * (Address 4) and two bits in the Auto Negotiation Base |
| 2003 | * Page Ability Register (Address 5) determine flow control |
| 2004 | * for both the PHY and the link partner. The following |
| 2005 | * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, |
| 2006 | * 1999, describes these PAUSE resolution bits and how flow |
| 2007 | * control is determined based upon these settings. |
| 2008 | * NOTE: DC = Don't Care |
| 2009 | * |
| 2010 | * LOCAL DEVICE | LINK PARTNER |
| 2011 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution |
| 2012 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2013 | * 0 | 0 | DC | DC | E1000_FC_NONE |
| 2014 | * 0 | 1 | 0 | DC | E1000_FC_NONE |
| 2015 | * 0 | 1 | 1 | 0 | E1000_FC_NONE |
| 2016 | * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE |
| 2017 | * 1 | 0 | 0 | DC | E1000_FC_NONE |
| 2018 | * 1 | DC | 1 | DC | E1000_FC_FULL |
| 2019 | * 1 | 1 | 0 | 0 | E1000_FC_NONE |
| 2020 | * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | * |
| 2022 | */ |
| 2023 | /* Are both PAUSE bits set to 1? If so, this implies |
| 2024 | * Symmetric Flow Control is enabled at both ends. The |
| 2025 | * ASM_DIR bits are irrelevant per the spec. |
| 2026 | * |
| 2027 | * For Symmetric Flow Control: |
| 2028 | * |
| 2029 | * LOCAL DEVICE | LINK PARTNER |
| 2030 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 2031 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2032 | * 1 | DC | 1 | DC | E1000_FC_FULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | * |
| 2034 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2035 | if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2036 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | /* Now we need to check if the user selected RX ONLY |
| 2038 | * of pause frames. In this case, we had to advertise |
| 2039 | * FULL flow control because we could not advertise RX |
| 2040 | * ONLY. Hence, we must now check to see if we need to |
| 2041 | * turn OFF the TRANSMISSION of PAUSE frames. |
| 2042 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2043 | if (hw->original_fc == E1000_FC_FULL) { |
| 2044 | hw->fc = E1000_FC_FULL; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2045 | DEBUGOUT("Flow Control = FULL.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | } else { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2047 | hw->fc = E1000_FC_RX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2048 | DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | } |
| 2050 | } |
| 2051 | /* For receiving PAUSE frames ONLY. |
| 2052 | * |
| 2053 | * LOCAL DEVICE | LINK PARTNER |
| 2054 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 2055 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2056 | * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | * |
| 2058 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2059 | else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2060 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 2061 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 2062 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2063 | hw->fc = E1000_FC_TX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2064 | DEBUGOUT("Flow Control = TX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | } |
| 2066 | /* For transmitting PAUSE frames ONLY. |
| 2067 | * |
| 2068 | * LOCAL DEVICE | LINK PARTNER |
| 2069 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 2070 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2071 | * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | * |
| 2073 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2074 | else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2075 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 2076 | !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 2077 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2078 | hw->fc = E1000_FC_RX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2079 | DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | } |
| 2081 | /* Per the IEEE spec, at this point flow control should be |
| 2082 | * disabled. However, we want to consider that we could |
| 2083 | * be connected to a legacy switch that doesn't advertise |
| 2084 | * desired flow control, but can be forced on the link |
| 2085 | * partner. So if we advertised no flow control, that is |
| 2086 | * what we will resolve to. If we advertised some kind of |
| 2087 | * receive capability (Rx Pause Only or Full Flow Control) |
| 2088 | * and the link partner advertised none, we will configure |
| 2089 | * ourselves to enable Rx Flow Control only. We can do |
| 2090 | * this safely for two reasons: If the link partner really |
| 2091 | * didn't want flow control enabled, and we enable Rx, no |
| 2092 | * harm done since we won't be receiving any PAUSE frames |
| 2093 | * anyway. If the intent on the link partner was to have |
| 2094 | * flow control enabled, then by us enabling RX only, we |
| 2095 | * can at least receive pause frames and process them. |
| 2096 | * This is a good idea because in most cases, since we are |
| 2097 | * predominantly a server NIC, more times than not we will |
| 2098 | * be asked to delay transmission of packets than asking |
| 2099 | * our link partner to pause transmission of frames. |
| 2100 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2101 | else if ((hw->original_fc == E1000_FC_NONE || |
| 2102 | hw->original_fc == E1000_FC_TX_PAUSE) || |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2103 | hw->fc_strict_ieee) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2104 | hw->fc = E1000_FC_NONE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2105 | DEBUGOUT("Flow Control = NONE.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | } else { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2107 | hw->fc = E1000_FC_RX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2108 | DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | /* Now we need to do one last check... If we auto- |
| 2112 | * negotiated to HALF DUPLEX, flow control should not be |
| 2113 | * enabled per IEEE 802.3 spec. |
| 2114 | */ |
| 2115 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2116 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | DEBUGOUT("Error getting link speed and duplex\n"); |
| 2118 | return ret_val; |
| 2119 | } |
| 2120 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2121 | if (duplex == HALF_DUPLEX) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2122 | hw->fc = E1000_FC_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | |
| 2124 | /* Now we call a subroutine to actually force the MAC |
| 2125 | * controller to use the correct flow control settings. |
| 2126 | */ |
| 2127 | ret_val = e1000_force_mac_fc(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2128 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | DEBUGOUT("Error forcing flow control settings\n"); |
| 2130 | return ret_val; |
| 2131 | } |
| 2132 | } else { |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2133 | DEBUGOUT("Copper PHY and Auto Neg has not completed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | } |
| 2135 | } |
| 2136 | return E1000_SUCCESS; |
| 2137 | } |
| 2138 | |
| 2139 | /****************************************************************************** |
| 2140 | * Checks to see if the link status of the hardware has changed. |
| 2141 | * |
| 2142 | * hw - Struct containing variables accessed by shared code |
| 2143 | * |
| 2144 | * Called by any function that needs to check the link status of the adapter. |
| 2145 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2146 | s32 e1000_check_for_link(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2148 | u32 rxcw = 0; |
| 2149 | u32 ctrl; |
| 2150 | u32 status; |
| 2151 | u32 rctl; |
| 2152 | u32 icr; |
| 2153 | u32 signal = 0; |
| 2154 | s32 ret_val; |
| 2155 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | |
| 2157 | DEBUGFUNC("e1000_check_for_link"); |
| 2158 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2159 | ctrl = er32(CTRL); |
| 2160 | status = er32(STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | |
| 2162 | /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be |
| 2163 | * set when the optics detect a signal. On older adapters, it will be |
| 2164 | * cleared when there is a signal. This applies to fiber media only. |
| 2165 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2166 | if ((hw->media_type == e1000_media_type_fiber) || |
| 2167 | (hw->media_type == e1000_media_type_internal_serdes)) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2168 | rxcw = er32(RXCW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2170 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2172 | if (status & E1000_STATUS_LU) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2173 | hw->get_link_status = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | /* If we have a copper PHY then we only want to go out to the PHY |
| 2178 | * registers to see if Auto-Neg has completed and/or if our link |
| 2179 | * status has changed. The get_link_status flag will be set if we |
| 2180 | * receive a Link Status Change interrupt or we have Rx Sequence |
| 2181 | * Errors. |
| 2182 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2183 | if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | /* First we want to see if the MII Status Register reports |
| 2185 | * link. If so, then we want to get the current speed/duplex |
| 2186 | * of the PHY. |
| 2187 | * Read the register twice since the link bit is sticky. |
| 2188 | */ |
| 2189 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2190 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | return ret_val; |
| 2192 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2193 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | return ret_val; |
| 2195 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2196 | if (phy_data & MII_SR_LINK_STATUS) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2197 | hw->get_link_status = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | /* Check if there was DownShift, must be checked immediately after |
| 2199 | * link-up */ |
| 2200 | e1000_check_downshift(hw); |
| 2201 | |
| 2202 | /* If we are on 82544 or 82543 silicon and speed/duplex |
| 2203 | * are forced to 10H or 10F, then we will implement the polarity |
| 2204 | * reversal workaround. We disable interrupts first, and upon |
| 2205 | * returning, place the devices interrupt state to its previous |
| 2206 | * value except for the link status change interrupt which will |
| 2207 | * happen due to the execution of this workaround. |
| 2208 | */ |
| 2209 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2210 | if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) && |
| 2211 | (!hw->autoneg) && |
| 2212 | (hw->forced_speed_duplex == e1000_10_full || |
| 2213 | hw->forced_speed_duplex == e1000_10_half)) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2214 | ew32(IMC, 0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | ret_val = e1000_polarity_reversal_workaround(hw); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2216 | icr = er32(ICR); |
| 2217 | ew32(ICS, (icr & ~E1000_ICS_LSC)); |
| 2218 | ew32(IMS, IMS_ENABLE_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | } else { |
| 2222 | /* No link detected */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2223 | e1000_config_dsp_after_link_change(hw, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | return 0; |
| 2225 | } |
| 2226 | |
| 2227 | /* If we are forcing speed/duplex, then we simply return since |
| 2228 | * we have already determined whether we have link or not. |
| 2229 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2230 | if (!hw->autoneg) return -E1000_ERR_CONFIG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | |
| 2232 | /* optimize the dsp settings for the igp phy */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2233 | e1000_config_dsp_after_link_change(hw, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | |
| 2235 | /* We have a M88E1000 PHY and Auto-Neg is enabled. If we |
| 2236 | * have Si on board that is 82544 or newer, Auto |
| 2237 | * Speed Detection takes care of MAC speed/duplex |
| 2238 | * configuration. So we only need to configure Collision |
| 2239 | * Distance in the MAC. Otherwise, we need to force |
| 2240 | * speed/duplex on the MAC to the current PHY speed/duplex |
| 2241 | * settings. |
| 2242 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2243 | if (hw->mac_type >= e1000_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | e1000_config_collision_dist(hw); |
| 2245 | else { |
| 2246 | ret_val = e1000_config_mac_to_phy(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2247 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | DEBUGOUT("Error configuring MAC to PHY settings\n"); |
| 2249 | return ret_val; |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | /* Configure Flow Control now that Auto-Neg has completed. First, we |
| 2254 | * need to restore the desired flow control settings because we may |
| 2255 | * have had to re-autoneg with a different link partner. |
| 2256 | */ |
| 2257 | ret_val = e1000_config_fc_after_link_up(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2258 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | DEBUGOUT("Error configuring flow control\n"); |
| 2260 | return ret_val; |
| 2261 | } |
| 2262 | |
| 2263 | /* At this point we know that we are on copper and we have |
| 2264 | * auto-negotiated link. These are conditions for checking the link |
| 2265 | * partner capability register. We use the link speed to determine if |
| 2266 | * TBI compatibility needs to be turned on or off. If the link is not |
| 2267 | * at gigabit speed, then TBI compatibility is not needed. If we are |
| 2268 | * at gigabit speed, we turn on TBI compatibility. |
| 2269 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2270 | if (hw->tbi_compatibility_en) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2271 | u16 speed, duplex; |
Auke Kok | 592600a | 2006-06-27 09:08:09 -0700 | [diff] [blame] | 2272 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); |
| 2273 | if (ret_val) { |
| 2274 | DEBUGOUT("Error getting link speed and duplex\n"); |
| 2275 | return ret_val; |
| 2276 | } |
| 2277 | if (speed != SPEED_1000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | /* If link speed is not set to gigabit speed, we do not need |
| 2279 | * to enable TBI compatibility. |
| 2280 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2281 | if (hw->tbi_compatibility_on) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | /* If we previously were in the mode, turn it off. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2283 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | rctl &= ~E1000_RCTL_SBP; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2285 | ew32(RCTL, rctl); |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2286 | hw->tbi_compatibility_on = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | } |
| 2288 | } else { |
| 2289 | /* If TBI compatibility is was previously off, turn it on. For |
| 2290 | * compatibility with a TBI link partner, we will store bad |
| 2291 | * packets. Some frames have an additional byte on the end and |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 2292 | * will look like CRC errors to the hardware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2294 | if (!hw->tbi_compatibility_on) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2295 | hw->tbi_compatibility_on = true; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2296 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | rctl |= E1000_RCTL_SBP; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2298 | ew32(RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | } |
| 2300 | } |
| 2301 | } |
| 2302 | } |
| 2303 | /* If we don't have link (auto-negotiation failed or link partner cannot |
| 2304 | * auto-negotiate), the cable is plugged in (we have signal), and our |
| 2305 | * link partner is not trying to auto-negotiate with us (we are receiving |
| 2306 | * idles or data), we need to force link up. We also need to give |
| 2307 | * auto-negotiation time to complete, in case the cable was just plugged |
| 2308 | * in. The autoneg_failed flag does this. |
| 2309 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2310 | else if ((((hw->media_type == e1000_media_type_fiber) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | ((ctrl & E1000_CTRL_SWDPIN1) == signal)) || |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2312 | (hw->media_type == e1000_media_type_internal_serdes)) && |
| 2313 | (!(status & E1000_STATUS_LU)) && |
| 2314 | (!(rxcw & E1000_RXCW_C))) { |
| 2315 | if (hw->autoneg_failed == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | hw->autoneg_failed = 1; |
| 2317 | return 0; |
| 2318 | } |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2319 | DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | |
| 2321 | /* Disable auto-negotiation in the TXCW register */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2322 | ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | |
| 2324 | /* Force link-up and also force full-duplex. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2325 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2327 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | |
| 2329 | /* Configure Flow Control after forcing link up. */ |
| 2330 | ret_val = e1000_config_fc_after_link_up(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2331 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | DEBUGOUT("Error configuring flow control\n"); |
| 2333 | return ret_val; |
| 2334 | } |
| 2335 | } |
| 2336 | /* If we are forcing link and we are receiving /C/ ordered sets, re-enable |
| 2337 | * auto-negotiation in the TXCW register and disable forced link in the |
| 2338 | * Device Control register in an attempt to auto-negotiate with our link |
| 2339 | * partner. |
| 2340 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2341 | else if (((hw->media_type == e1000_media_type_fiber) || |
| 2342 | (hw->media_type == e1000_media_type_internal_serdes)) && |
| 2343 | (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2344 | DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n"); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2345 | ew32(TXCW, hw->txcw); |
| 2346 | ew32(CTRL, (ctrl & ~E1000_CTRL_SLU)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2348 | hw->serdes_link_down = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | } |
| 2350 | /* If we force link for non-auto-negotiation switch, check link status |
| 2351 | * based on MAC synchronization for internal serdes media type. |
| 2352 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2353 | else if ((hw->media_type == e1000_media_type_internal_serdes) && |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2354 | !(E1000_TXCW_ANE & er32(TXCW))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | /* SYNCH bit and IV bit are sticky. */ |
| 2356 | udelay(10); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2357 | if (E1000_RXCW_SYNCH & er32(RXCW)) { |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2358 | if (!(rxcw & E1000_RXCW_IV)) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2359 | hw->serdes_link_down = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | DEBUGOUT("SERDES: Link is up.\n"); |
| 2361 | } |
| 2362 | } else { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2363 | hw->serdes_link_down = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | DEBUGOUT("SERDES: Link is down.\n"); |
| 2365 | } |
| 2366 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2367 | if ((hw->media_type == e1000_media_type_internal_serdes) && |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2368 | (E1000_TXCW_ANE & er32(TXCW))) { |
| 2369 | hw->serdes_link_down = !(E1000_STATUS_LU & er32(STATUS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | } |
| 2371 | return E1000_SUCCESS; |
| 2372 | } |
| 2373 | |
| 2374 | /****************************************************************************** |
| 2375 | * Detects the current speed and duplex settings of the hardware. |
| 2376 | * |
| 2377 | * hw - Struct containing variables accessed by shared code |
| 2378 | * speed - Speed of the connection |
| 2379 | * duplex - Duplex setting of the connection |
| 2380 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2381 | 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] | 2382 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2383 | u32 status; |
| 2384 | s32 ret_val; |
| 2385 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | |
| 2387 | DEBUGFUNC("e1000_get_speed_and_duplex"); |
| 2388 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2389 | if (hw->mac_type >= e1000_82543) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2390 | status = er32(STATUS); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2391 | if (status & E1000_STATUS_SPEED_1000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | *speed = SPEED_1000; |
| 2393 | DEBUGOUT("1000 Mbs, "); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2394 | } else if (status & E1000_STATUS_SPEED_100) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | *speed = SPEED_100; |
| 2396 | DEBUGOUT("100 Mbs, "); |
| 2397 | } else { |
| 2398 | *speed = SPEED_10; |
| 2399 | DEBUGOUT("10 Mbs, "); |
| 2400 | } |
| 2401 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2402 | if (status & E1000_STATUS_FD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | *duplex = FULL_DUPLEX; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2404 | DEBUGOUT("Full Duplex\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | } else { |
| 2406 | *duplex = HALF_DUPLEX; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2407 | DEBUGOUT(" Half Duplex\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | } |
| 2409 | } else { |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2410 | DEBUGOUT("1000 Mbs, Full Duplex\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | *speed = SPEED_1000; |
| 2412 | *duplex = FULL_DUPLEX; |
| 2413 | } |
| 2414 | |
| 2415 | /* IGP01 PHY may advertise full duplex operation after speed downgrade even |
| 2416 | * if it is operating at half duplex. Here we set the duplex settings to |
| 2417 | * match the duplex in the link partner's capabilities. |
| 2418 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2419 | if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2421 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | return ret_val; |
| 2423 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2424 | if (!(phy_data & NWAY_ER_LP_NWAY_CAPS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | *duplex = HALF_DUPLEX; |
| 2426 | else { |
| 2427 | ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2428 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | return ret_val; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2430 | if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS))) |
| 2432 | *duplex = HALF_DUPLEX; |
| 2433 | } |
| 2434 | } |
| 2435 | |
| 2436 | return E1000_SUCCESS; |
| 2437 | } |
| 2438 | |
| 2439 | /****************************************************************************** |
| 2440 | * Blocks until autoneg completes or times out (~4.5 seconds) |
| 2441 | * |
| 2442 | * hw - Struct containing variables accessed by shared code |
| 2443 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2444 | static s32 e1000_wait_autoneg(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2446 | s32 ret_val; |
| 2447 | u16 i; |
| 2448 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | |
| 2450 | DEBUGFUNC("e1000_wait_autoneg"); |
| 2451 | DEBUGOUT("Waiting for Auto-Neg to complete.\n"); |
| 2452 | |
| 2453 | /* 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] | 2454 | for (i = PHY_AUTO_NEG_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | /* Read the MII Status Register and wait for Auto-Neg |
| 2456 | * Complete bit to be set. |
| 2457 | */ |
| 2458 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2459 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | return ret_val; |
| 2461 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2462 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | return ret_val; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2464 | if (phy_data & MII_SR_AUTONEG_COMPLETE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | return E1000_SUCCESS; |
| 2466 | } |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 2467 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | } |
| 2469 | return E1000_SUCCESS; |
| 2470 | } |
| 2471 | |
| 2472 | /****************************************************************************** |
| 2473 | * Raises the Management Data Clock |
| 2474 | * |
| 2475 | * hw - Struct containing variables accessed by shared code |
| 2476 | * ctrl - Device control register's current value |
| 2477 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2478 | static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | { |
| 2480 | /* Raise the clock input to the Management Data Clock (by setting the MDC |
| 2481 | * bit), and then delay 10 microseconds. |
| 2482 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2483 | ew32(CTRL, (*ctrl | E1000_CTRL_MDC)); |
| 2484 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | udelay(10); |
| 2486 | } |
| 2487 | |
| 2488 | /****************************************************************************** |
| 2489 | * Lowers the Management Data Clock |
| 2490 | * |
| 2491 | * hw - Struct containing variables accessed by shared code |
| 2492 | * ctrl - Device control register's current value |
| 2493 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2494 | static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2495 | { |
| 2496 | /* Lower the clock input to the Management Data Clock (by clearing the MDC |
| 2497 | * bit), and then delay 10 microseconds. |
| 2498 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2499 | ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC)); |
| 2500 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | udelay(10); |
| 2502 | } |
| 2503 | |
| 2504 | /****************************************************************************** |
| 2505 | * Shifts data bits out to the PHY |
| 2506 | * |
| 2507 | * hw - Struct containing variables accessed by shared code |
| 2508 | * data - Data to send out to the PHY |
| 2509 | * count - Number of bits to shift out |
| 2510 | * |
| 2511 | * Bits are shifted out in MSB to LSB order. |
| 2512 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2513 | 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] | 2514 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2515 | u32 ctrl; |
| 2516 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | |
| 2518 | /* We need to shift "count" number of bits out to the PHY. So, the value |
| 2519 | * in the "data" parameter will be shifted out to the PHY one bit at a |
| 2520 | * time. In order to do this, "data" must be broken down into bits. |
| 2521 | */ |
| 2522 | mask = 0x01; |
| 2523 | mask <<= (count - 1); |
| 2524 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2525 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | |
| 2527 | /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */ |
| 2528 | ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR); |
| 2529 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2530 | while (mask) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and |
| 2532 | * then raising and lowering the Management Data Clock. A "0" is |
| 2533 | * shifted out to the PHY by setting the MDIO bit to "0" and then |
| 2534 | * raising and lowering the clock. |
| 2535 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2536 | if (data & mask) |
| 2537 | ctrl |= E1000_CTRL_MDIO; |
| 2538 | else |
| 2539 | ctrl &= ~E1000_CTRL_MDIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2541 | ew32(CTRL, ctrl); |
| 2542 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | |
| 2544 | udelay(10); |
| 2545 | |
| 2546 | e1000_raise_mdi_clk(hw, &ctrl); |
| 2547 | e1000_lower_mdi_clk(hw, &ctrl); |
| 2548 | |
| 2549 | mask = mask >> 1; |
| 2550 | } |
| 2551 | } |
| 2552 | |
| 2553 | /****************************************************************************** |
| 2554 | * Shifts data bits in from the PHY |
| 2555 | * |
| 2556 | * hw - Struct containing variables accessed by shared code |
| 2557 | * |
| 2558 | * Bits are shifted in in MSB to LSB order. |
| 2559 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2560 | static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2562 | u32 ctrl; |
| 2563 | u16 data = 0; |
| 2564 | u8 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | |
| 2566 | /* In order to read a register from the PHY, we need to shift in a total |
| 2567 | * of 18 bits from the PHY. The first two bit (turnaround) times are used |
| 2568 | * to avoid contention on the MDIO pin when a read operation is performed. |
| 2569 | * These two bits are ignored by us and thrown away. Bits are "shifted in" |
| 2570 | * by raising the input to the Management Data Clock (setting the MDC bit), |
| 2571 | * and then reading the value of the MDIO bit. |
| 2572 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2573 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2574 | |
| 2575 | /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */ |
| 2576 | ctrl &= ~E1000_CTRL_MDIO_DIR; |
| 2577 | ctrl &= ~E1000_CTRL_MDIO; |
| 2578 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2579 | ew32(CTRL, ctrl); |
| 2580 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | |
| 2582 | /* Raise and Lower the clock before reading in the data. This accounts for |
| 2583 | * the turnaround bits. The first clock occurred when we clocked out the |
| 2584 | * last bit of the Register Address. |
| 2585 | */ |
| 2586 | e1000_raise_mdi_clk(hw, &ctrl); |
| 2587 | e1000_lower_mdi_clk(hw, &ctrl); |
| 2588 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2589 | for (data = 0, i = 0; i < 16; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | data = data << 1; |
| 2591 | e1000_raise_mdi_clk(hw, &ctrl); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2592 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | /* Check to see if we shifted in a "1". */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2594 | if (ctrl & E1000_CTRL_MDIO) |
| 2595 | data |= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | e1000_lower_mdi_clk(hw, &ctrl); |
| 2597 | } |
| 2598 | |
| 2599 | e1000_raise_mdi_clk(hw, &ctrl); |
| 2600 | e1000_lower_mdi_clk(hw, &ctrl); |
| 2601 | |
| 2602 | return data; |
| 2603 | } |
| 2604 | |
| 2605 | /***************************************************************************** |
| 2606 | * Reads the value from a PHY register, if the value is on a specific non zero |
| 2607 | * page, sets the page first. |
| 2608 | * hw - Struct containing variables accessed by shared code |
| 2609 | * reg_addr - address of the PHY register to read |
| 2610 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2611 | 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] | 2612 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2613 | u32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2614 | |
| 2615 | DEBUGFUNC("e1000_read_phy_reg"); |
| 2616 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 2617 | if ((hw->phy_type == e1000_phy_igp) && |
| 2618 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2620 | (u16)reg_addr); |
Jesse Brandeburg | 282b177 | 2009-09-25 12:16:39 +0000 | [diff] [blame^] | 2621 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, |
| 2626 | phy_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | return ret_val; |
| 2628 | } |
| 2629 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2630 | static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, |
| 2631 | u16 *phy_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2633 | u32 i; |
| 2634 | u32 mdic = 0; |
| 2635 | const u32 phy_addr = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | |
| 2637 | DEBUGFUNC("e1000_read_phy_reg_ex"); |
| 2638 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2639 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | DEBUGOUT1("PHY Address %d is out of range\n", reg_addr); |
| 2641 | return -E1000_ERR_PARAM; |
| 2642 | } |
| 2643 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2644 | if (hw->mac_type > e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | /* Set up Op-code, Phy Address, and register address in the MDI |
| 2646 | * Control register. The MAC will take care of interfacing with the |
| 2647 | * PHY to retrieve the desired data. |
| 2648 | */ |
| 2649 | mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) | |
| 2650 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 2651 | (E1000_MDIC_OP_READ)); |
| 2652 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2653 | ew32(MDIC, mdic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | |
| 2655 | /* Poll the ready bit to see if the MDI read completed */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2656 | for (i = 0; i < 64; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | udelay(50); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2658 | mdic = er32(MDIC); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2659 | if (mdic & E1000_MDIC_READY) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2661 | if (!(mdic & E1000_MDIC_READY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | DEBUGOUT("MDI Read did not complete\n"); |
| 2663 | return -E1000_ERR_PHY; |
| 2664 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2665 | if (mdic & E1000_MDIC_ERROR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | DEBUGOUT("MDI Error\n"); |
| 2667 | return -E1000_ERR_PHY; |
| 2668 | } |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2669 | *phy_data = (u16)mdic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | } else { |
| 2671 | /* We must first send a preamble through the MDIO pin to signal the |
| 2672 | * beginning of an MII instruction. This is done by sending 32 |
| 2673 | * consecutive "1" bits. |
| 2674 | */ |
| 2675 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
| 2676 | |
| 2677 | /* Now combine the next few fields that are required for a read |
| 2678 | * operation. We use this method instead of calling the |
| 2679 | * e1000_shift_out_mdi_bits routine five different times. The format of |
| 2680 | * a MII read instruction consists of a shift out of 14 bits and is |
| 2681 | * defined as follows: |
| 2682 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr> |
| 2683 | * followed by a shift in of 18 bits. This first two bits shifted in |
| 2684 | * are TurnAround bits used to avoid contention on the MDIO pin when a |
| 2685 | * READ operation is performed. These two bits are thrown away |
| 2686 | * followed by a shift in of 16 bits which contains the desired data. |
| 2687 | */ |
| 2688 | mdic = ((reg_addr) | (phy_addr << 5) | |
| 2689 | (PHY_OP_READ << 10) | (PHY_SOF << 12)); |
| 2690 | |
| 2691 | e1000_shift_out_mdi_bits(hw, mdic, 14); |
| 2692 | |
| 2693 | /* Now that we've shifted out the read command to the MII, we need to |
| 2694 | * "shift in" the 16-bit value (18 total bits) of the requested PHY |
| 2695 | * register address. |
| 2696 | */ |
| 2697 | *phy_data = e1000_shift_in_mdi_bits(hw); |
| 2698 | } |
| 2699 | return E1000_SUCCESS; |
| 2700 | } |
| 2701 | |
| 2702 | /****************************************************************************** |
| 2703 | * Writes a value to a PHY register |
| 2704 | * |
| 2705 | * hw - Struct containing variables accessed by shared code |
| 2706 | * reg_addr - address of the PHY register to write |
| 2707 | * data - data to write to the PHY |
| 2708 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2709 | 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] | 2710 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2711 | u32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | |
| 2713 | DEBUGFUNC("e1000_write_phy_reg"); |
| 2714 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 2715 | if ((hw->phy_type == e1000_phy_igp) && |
| 2716 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2718 | (u16)reg_addr); |
Jesse Brandeburg | 282b177 | 2009-09-25 12:16:39 +0000 | [diff] [blame^] | 2719 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, |
| 2724 | phy_data); |
| 2725 | |
| 2726 | return ret_val; |
| 2727 | } |
| 2728 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2729 | static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, |
| 2730 | u16 phy_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2732 | u32 i; |
| 2733 | u32 mdic = 0; |
| 2734 | const u32 phy_addr = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | |
| 2736 | DEBUGFUNC("e1000_write_phy_reg_ex"); |
| 2737 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2738 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | DEBUGOUT1("PHY Address %d is out of range\n", reg_addr); |
| 2740 | return -E1000_ERR_PARAM; |
| 2741 | } |
| 2742 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2743 | if (hw->mac_type > e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | /* Set up Op-code, Phy Address, register address, and data intended |
| 2745 | * for the PHY register in the MDI Control register. The MAC will take |
| 2746 | * care of interfacing with the PHY to send the desired data. |
| 2747 | */ |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2748 | mdic = (((u32)phy_data) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | (reg_addr << E1000_MDIC_REG_SHIFT) | |
| 2750 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 2751 | (E1000_MDIC_OP_WRITE)); |
| 2752 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2753 | ew32(MDIC, mdic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2754 | |
| 2755 | /* Poll the ready bit to see if the MDI read completed */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2756 | for (i = 0; i < 641; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | udelay(5); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2758 | mdic = er32(MDIC); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2759 | if (mdic & E1000_MDIC_READY) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2761 | if (!(mdic & E1000_MDIC_READY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | DEBUGOUT("MDI Write did not complete\n"); |
| 2763 | return -E1000_ERR_PHY; |
| 2764 | } |
| 2765 | } else { |
| 2766 | /* We'll need to use the SW defined pins to shift the write command |
| 2767 | * out to the PHY. We first send a preamble to the PHY to signal the |
| 2768 | * beginning of the MII instruction. This is done by sending 32 |
| 2769 | * consecutive "1" bits. |
| 2770 | */ |
| 2771 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
| 2772 | |
| 2773 | /* Now combine the remaining required fields that will indicate a |
| 2774 | * write operation. We use this method instead of calling the |
| 2775 | * e1000_shift_out_mdi_bits routine for each field in the command. The |
| 2776 | * format of a MII write instruction is as follows: |
| 2777 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>. |
| 2778 | */ |
| 2779 | mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) | |
| 2780 | (PHY_OP_WRITE << 12) | (PHY_SOF << 14)); |
| 2781 | mdic <<= 16; |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2782 | mdic |= (u32)phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | |
| 2784 | e1000_shift_out_mdi_bits(hw, mdic, 32); |
| 2785 | } |
| 2786 | |
| 2787 | return E1000_SUCCESS; |
| 2788 | } |
| 2789 | |
| 2790 | /****************************************************************************** |
| 2791 | * Returns the PHY to the power-on reset state |
| 2792 | * |
| 2793 | * hw - Struct containing variables accessed by shared code |
| 2794 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2795 | s32 e1000_phy_hw_reset(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2797 | u32 ctrl, ctrl_ext; |
| 2798 | u32 led_ctrl; |
| 2799 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | |
| 2801 | DEBUGFUNC("e1000_phy_hw_reset"); |
| 2802 | |
| 2803 | DEBUGOUT("Resetting Phy...\n"); |
| 2804 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2805 | if (hw->mac_type > e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | /* Read the device control register and assert the E1000_CTRL_PHY_RST |
| 2807 | * bit. Then, take it out of reset. |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 2808 | * For e1000 hardware, we delay for 10ms between the assert |
| 2809 | * and deassert. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2811 | ctrl = er32(CTRL); |
| 2812 | ew32(CTRL, ctrl | E1000_CTRL_PHY_RST); |
| 2813 | E1000_WRITE_FLUSH(); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2814 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 2815 | msleep(10); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2816 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2817 | ew32(CTRL, ctrl); |
| 2818 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2819 | } else { |
| 2820 | /* Read the Extended Device Control Register, assert the PHY_RESET_DIR |
| 2821 | * bit to put the PHY into reset. Then, take it out of reset. |
| 2822 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2823 | ctrl_ext = er32(CTRL_EXT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR; |
| 2825 | ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2826 | ew32(CTRL_EXT, ctrl_ext); |
| 2827 | E1000_WRITE_FLUSH(); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 2828 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2830 | ew32(CTRL_EXT, ctrl_ext); |
| 2831 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | } |
| 2833 | udelay(150); |
| 2834 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2835 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | /* Configure activity LED after PHY reset */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2837 | led_ctrl = er32(LEDCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 2839 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2840 | ew32(LEDCTL, led_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2842 | |
| 2843 | /* Wait for FW to finish PHY configuration. */ |
| 2844 | ret_val = e1000_get_phy_cfg_done(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2845 | if (ret_val != E1000_SUCCESS) |
| 2846 | return ret_val; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2847 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2848 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | /****************************************************************************** |
| 2852 | * Resets the PHY |
| 2853 | * |
| 2854 | * hw - Struct containing variables accessed by shared code |
| 2855 | * |
Matt LaPlante | 0779bf2 | 2006-11-30 05:24:39 +0100 | [diff] [blame] | 2856 | * Sets bit 15 of the MII Control register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2858 | s32 e1000_phy_reset(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2860 | s32 ret_val; |
| 2861 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | |
| 2863 | DEBUGFUNC("e1000_phy_reset"); |
| 2864 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 2865 | switch (hw->phy_type) { |
| 2866 | case e1000_phy_igp: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2867 | ret_val = e1000_phy_hw_reset(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2868 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2869 | return ret_val; |
| 2870 | break; |
| 2871 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2873 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | return ret_val; |
| 2875 | |
| 2876 | phy_data |= MII_CR_RESET; |
| 2877 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2878 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | return ret_val; |
| 2880 | |
| 2881 | udelay(1); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2882 | break; |
| 2883 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 2885 | if (hw->phy_type == e1000_phy_igp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | e1000_phy_init_script(hw); |
| 2887 | |
| 2888 | return E1000_SUCCESS; |
| 2889 | } |
| 2890 | |
| 2891 | /****************************************************************************** |
| 2892 | * Probes the expected PHY address for known PHY IDs |
| 2893 | * |
| 2894 | * hw - Struct containing variables accessed by shared code |
| 2895 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2896 | static s32 e1000_detect_gig_phy(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2898 | s32 phy_init_status, ret_val; |
| 2899 | u16 phy_id_high, phy_id_low; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2900 | bool match = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | |
| 2902 | DEBUGFUNC("e1000_detect_gig_phy"); |
| 2903 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 2904 | if (hw->phy_id != 0) |
| 2905 | return E1000_SUCCESS; |
| 2906 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | /* Read the PHY ID Registers to identify which PHY is onboard. */ |
| 2908 | ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2909 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | return ret_val; |
| 2911 | |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2912 | hw->phy_id = (u32)(phy_id_high << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | udelay(20); |
| 2914 | ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2915 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | return ret_val; |
| 2917 | |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2918 | hw->phy_id |= (u32)(phy_id_low & PHY_REVISION_MASK); |
| 2919 | hw->phy_revision = (u32)phy_id_low & ~PHY_REVISION_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2921 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | case e1000_82543: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2923 | if (hw->phy_id == M88E1000_E_PHY_ID) match = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2924 | break; |
| 2925 | case e1000_82544: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2926 | if (hw->phy_id == M88E1000_I_PHY_ID) match = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | break; |
| 2928 | case e1000_82540: |
| 2929 | case e1000_82545: |
| 2930 | case e1000_82545_rev_3: |
| 2931 | case e1000_82546: |
| 2932 | case e1000_82546_rev_3: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2933 | if (hw->phy_id == M88E1011_I_PHY_ID) match = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | break; |
| 2935 | case e1000_82541: |
| 2936 | case e1000_82541_rev_2: |
| 2937 | case e1000_82547: |
| 2938 | case e1000_82547_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2939 | if (hw->phy_id == IGP01E1000_I_PHY_ID) match = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | break; |
| 2941 | default: |
| 2942 | DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type); |
| 2943 | return -E1000_ERR_CONFIG; |
| 2944 | } |
| 2945 | phy_init_status = e1000_set_phy_type(hw); |
| 2946 | |
| 2947 | if ((match) && (phy_init_status == E1000_SUCCESS)) { |
| 2948 | DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id); |
| 2949 | return E1000_SUCCESS; |
| 2950 | } |
| 2951 | DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id); |
| 2952 | return -E1000_ERR_PHY; |
| 2953 | } |
| 2954 | |
| 2955 | /****************************************************************************** |
| 2956 | * Resets the PHY's DSP |
| 2957 | * |
| 2958 | * hw - Struct containing variables accessed by shared code |
| 2959 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2960 | static s32 e1000_phy_reset_dsp(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2962 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | DEBUGFUNC("e1000_phy_reset_dsp"); |
| 2964 | |
| 2965 | do { |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 2966 | ret_val = e1000_write_phy_reg(hw, 29, 0x001d); |
| 2967 | if (ret_val) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | ret_val = e1000_write_phy_reg(hw, 30, 0x00c1); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2969 | if (ret_val) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | ret_val = e1000_write_phy_reg(hw, 30, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2971 | if (ret_val) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | ret_val = E1000_SUCCESS; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2973 | } while (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | |
| 2975 | return ret_val; |
| 2976 | } |
| 2977 | |
| 2978 | /****************************************************************************** |
| 2979 | * Get PHY information from various PHY registers for igp PHY only. |
| 2980 | * |
| 2981 | * hw - Struct containing variables accessed by shared code |
| 2982 | * phy_info - PHY information structure |
| 2983 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2984 | static s32 e1000_phy_igp_get_info(struct e1000_hw *hw, |
| 2985 | struct e1000_phy_info *phy_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2987 | s32 ret_val; |
| 2988 | u16 phy_data, min_length, max_length, average; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 2989 | e1000_rev_polarity polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | |
| 2991 | DEBUGFUNC("e1000_phy_igp_get_info"); |
| 2992 | |
| 2993 | /* The downshift status is checked only once, after link is established, |
| 2994 | * and it stored in the hw->speed_downgraded parameter. */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2995 | phy_info->downshift = (e1000_downshift)hw->speed_downgraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | |
| 2997 | /* IGP01E1000 does not need to support it. */ |
| 2998 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal; |
| 2999 | |
| 3000 | /* IGP01E1000 always correct polarity reversal */ |
| 3001 | phy_info->polarity_correction = e1000_polarity_reversal_enabled; |
| 3002 | |
| 3003 | /* Check polarity status */ |
| 3004 | ret_val = e1000_check_polarity(hw, &polarity); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3005 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | return ret_val; |
| 3007 | |
| 3008 | phy_info->cable_polarity = polarity; |
| 3009 | |
| 3010 | 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] | 3011 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | return ret_val; |
| 3013 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3014 | phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >> |
| 3015 | IGP01E1000_PSSR_MDIX_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3017 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
| 3019 | /* Local/Remote Receiver Information are only valid at 1000 Mbps */ |
| 3020 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3021 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | return ret_val; |
| 3023 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3024 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> |
| 3025 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? |
| 3026 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
| 3027 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> |
| 3028 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? |
| 3029 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | |
| 3031 | /* Get cable length */ |
| 3032 | ret_val = e1000_get_cable_length(hw, &min_length, &max_length); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3033 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | return ret_val; |
| 3035 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3036 | /* Translate to old method */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | average = (max_length + min_length) / 2; |
| 3038 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3039 | if (average <= e1000_igp_cable_length_50) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | phy_info->cable_length = e1000_cable_length_50; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3041 | else if (average <= e1000_igp_cable_length_80) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | phy_info->cable_length = e1000_cable_length_50_80; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3043 | else if (average <= e1000_igp_cable_length_110) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | phy_info->cable_length = e1000_cable_length_80_110; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3045 | else if (average <= e1000_igp_cable_length_140) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | phy_info->cable_length = e1000_cable_length_110_140; |
| 3047 | else |
| 3048 | phy_info->cable_length = e1000_cable_length_140; |
| 3049 | } |
| 3050 | |
| 3051 | return E1000_SUCCESS; |
| 3052 | } |
| 3053 | |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3054 | |
| 3055 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | * Get PHY information from various PHY registers fot m88 PHY only. |
| 3057 | * |
| 3058 | * hw - Struct containing variables accessed by shared code |
| 3059 | * phy_info - PHY information structure |
| 3060 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3061 | static s32 e1000_phy_m88_get_info(struct e1000_hw *hw, |
| 3062 | struct e1000_phy_info *phy_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3064 | s32 ret_val; |
| 3065 | u16 phy_data; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3066 | e1000_rev_polarity polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | |
| 3068 | DEBUGFUNC("e1000_phy_m88_get_info"); |
| 3069 | |
| 3070 | /* The downshift status is checked only once, after link is established, |
| 3071 | * and it stored in the hw->speed_downgraded parameter. */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3072 | phy_info->downshift = (e1000_downshift)hw->speed_downgraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | |
| 3074 | 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] | 3075 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | return ret_val; |
| 3077 | |
| 3078 | phy_info->extended_10bt_distance = |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3079 | ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >> |
| 3080 | M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ? |
| 3081 | e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal; |
| 3082 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | phy_info->polarity_correction = |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3084 | ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >> |
| 3085 | M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ? |
| 3086 | e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | |
| 3088 | /* Check polarity status */ |
| 3089 | ret_val = e1000_check_polarity(hw, &polarity); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3090 | if (ret_val) |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3091 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | phy_info->cable_polarity = polarity; |
| 3093 | |
| 3094 | 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] | 3095 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | return ret_val; |
| 3097 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3098 | phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >> |
| 3099 | M88E1000_PSSR_MDIX_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | |
| 3101 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) { |
| 3102 | /* Cable Length Estimation and Local/Remote Receiver Information |
| 3103 | * are only valid at 1000 Mbps. |
| 3104 | */ |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 3105 | phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >> |
| 3106 | M88E1000_PSSR_CABLE_LENGTH_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | |
| 3108 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3109 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | return ret_val; |
| 3111 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3112 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> |
| 3113 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? |
| 3114 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
| 3115 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> |
| 3116 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? |
| 3117 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | } |
| 3120 | |
| 3121 | return E1000_SUCCESS; |
| 3122 | } |
| 3123 | |
| 3124 | /****************************************************************************** |
| 3125 | * Get PHY information from various PHY registers |
| 3126 | * |
| 3127 | * hw - Struct containing variables accessed by shared code |
| 3128 | * phy_info - PHY information structure |
| 3129 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3130 | 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] | 3131 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3132 | s32 ret_val; |
| 3133 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | |
| 3135 | DEBUGFUNC("e1000_phy_get_info"); |
| 3136 | |
| 3137 | phy_info->cable_length = e1000_cable_length_undefined; |
| 3138 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined; |
| 3139 | phy_info->cable_polarity = e1000_rev_polarity_undefined; |
| 3140 | phy_info->downshift = e1000_downshift_undefined; |
| 3141 | phy_info->polarity_correction = e1000_polarity_reversal_undefined; |
| 3142 | phy_info->mdix_mode = e1000_auto_x_mode_undefined; |
| 3143 | phy_info->local_rx = e1000_1000t_rx_status_undefined; |
| 3144 | phy_info->remote_rx = e1000_1000t_rx_status_undefined; |
| 3145 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3146 | if (hw->media_type != e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | DEBUGOUT("PHY info is only valid for copper media\n"); |
| 3148 | return -E1000_ERR_CONFIG; |
| 3149 | } |
| 3150 | |
| 3151 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3152 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | return ret_val; |
| 3154 | |
| 3155 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3156 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | return ret_val; |
| 3158 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3159 | if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | DEBUGOUT("PHY info is only valid if link is up\n"); |
| 3161 | return -E1000_ERR_CONFIG; |
| 3162 | } |
| 3163 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 3164 | if (hw->phy_type == e1000_phy_igp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3165 | return e1000_phy_igp_get_info(hw, phy_info); |
| 3166 | else |
| 3167 | return e1000_phy_m88_get_info(hw, phy_info); |
| 3168 | } |
| 3169 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3170 | s32 e1000_validate_mdi_setting(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | { |
| 3172 | DEBUGFUNC("e1000_validate_mdi_settings"); |
| 3173 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3174 | if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | DEBUGOUT("Invalid MDI setting detected\n"); |
| 3176 | hw->mdix = 1; |
| 3177 | return -E1000_ERR_CONFIG; |
| 3178 | } |
| 3179 | return E1000_SUCCESS; |
| 3180 | } |
| 3181 | |
| 3182 | |
| 3183 | /****************************************************************************** |
| 3184 | * 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] | 3185 | * is configured. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | * |
| 3187 | * hw - Struct containing variables accessed by shared code |
| 3188 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3189 | s32 e1000_init_eeprom_params(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | { |
| 3191 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3192 | u32 eecd = er32(EECD); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3193 | s32 ret_val = E1000_SUCCESS; |
| 3194 | u16 eeprom_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | |
| 3196 | DEBUGFUNC("e1000_init_eeprom_params"); |
| 3197 | |
| 3198 | switch (hw->mac_type) { |
| 3199 | case e1000_82542_rev2_0: |
| 3200 | case e1000_82542_rev2_1: |
| 3201 | case e1000_82543: |
| 3202 | case e1000_82544: |
| 3203 | eeprom->type = e1000_eeprom_microwire; |
| 3204 | eeprom->word_size = 64; |
| 3205 | eeprom->opcode_bits = 3; |
| 3206 | eeprom->address_bits = 6; |
| 3207 | eeprom->delay_usec = 50; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3208 | eeprom->use_eerd = false; |
| 3209 | eeprom->use_eewr = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | break; |
| 3211 | case e1000_82540: |
| 3212 | case e1000_82545: |
| 3213 | case e1000_82545_rev_3: |
| 3214 | case e1000_82546: |
| 3215 | case e1000_82546_rev_3: |
| 3216 | eeprom->type = e1000_eeprom_microwire; |
| 3217 | eeprom->opcode_bits = 3; |
| 3218 | eeprom->delay_usec = 50; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3219 | if (eecd & E1000_EECD_SIZE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | eeprom->word_size = 256; |
| 3221 | eeprom->address_bits = 8; |
| 3222 | } else { |
| 3223 | eeprom->word_size = 64; |
| 3224 | eeprom->address_bits = 6; |
| 3225 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3226 | eeprom->use_eerd = false; |
| 3227 | eeprom->use_eewr = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | break; |
| 3229 | case e1000_82541: |
| 3230 | case e1000_82541_rev_2: |
| 3231 | case e1000_82547: |
| 3232 | case e1000_82547_rev_2: |
| 3233 | if (eecd & E1000_EECD_TYPE) { |
| 3234 | eeprom->type = e1000_eeprom_spi; |
| 3235 | eeprom->opcode_bits = 8; |
| 3236 | eeprom->delay_usec = 1; |
| 3237 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 3238 | eeprom->page_size = 32; |
| 3239 | eeprom->address_bits = 16; |
| 3240 | } else { |
| 3241 | eeprom->page_size = 8; |
| 3242 | eeprom->address_bits = 8; |
| 3243 | } |
| 3244 | } else { |
| 3245 | eeprom->type = e1000_eeprom_microwire; |
| 3246 | eeprom->opcode_bits = 3; |
| 3247 | eeprom->delay_usec = 50; |
| 3248 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 3249 | eeprom->word_size = 256; |
| 3250 | eeprom->address_bits = 8; |
| 3251 | } else { |
| 3252 | eeprom->word_size = 64; |
| 3253 | eeprom->address_bits = 6; |
| 3254 | } |
| 3255 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3256 | eeprom->use_eerd = false; |
| 3257 | eeprom->use_eewr = false; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3258 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | default: |
| 3260 | break; |
| 3261 | } |
| 3262 | |
| 3263 | if (eeprom->type == e1000_eeprom_spi) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3264 | /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to |
| 3265 | * 32KB (incremented by powers of 2). |
| 3266 | */ |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 3267 | /* Set to default value for initial eeprom read. */ |
| 3268 | eeprom->word_size = 64; |
| 3269 | ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size); |
| 3270 | if (ret_val) |
| 3271 | return ret_val; |
| 3272 | eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT; |
| 3273 | /* 256B eeprom size was not supported in earlier hardware, so we |
| 3274 | * bump eeprom_size up one to ensure that "1" (which maps to 256B) |
| 3275 | * is never the result used in the shifting logic below. */ |
| 3276 | if (eeprom_size) |
| 3277 | eeprom_size++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3278 | |
| 3279 | eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3281 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | /****************************************************************************** |
| 3285 | * Raises the EEPROM's clock input. |
| 3286 | * |
| 3287 | * hw - Struct containing variables accessed by shared code |
| 3288 | * eecd - EECD's current value |
| 3289 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3290 | static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | { |
| 3292 | /* Raise the clock input to the EEPROM (by setting the SK bit), and then |
| 3293 | * wait <delay> microseconds. |
| 3294 | */ |
| 3295 | *eecd = *eecd | E1000_EECD_SK; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3296 | ew32(EECD, *eecd); |
| 3297 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | udelay(hw->eeprom.delay_usec); |
| 3299 | } |
| 3300 | |
| 3301 | /****************************************************************************** |
| 3302 | * Lowers the EEPROM's clock input. |
| 3303 | * |
| 3304 | * hw - Struct containing variables accessed by shared code |
| 3305 | * eecd - EECD's current value |
| 3306 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3307 | static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | { |
| 3309 | /* Lower the clock input to the EEPROM (by clearing the SK bit), and then |
| 3310 | * wait 50 microseconds. |
| 3311 | */ |
| 3312 | *eecd = *eecd & ~E1000_EECD_SK; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3313 | ew32(EECD, *eecd); |
| 3314 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | udelay(hw->eeprom.delay_usec); |
| 3316 | } |
| 3317 | |
| 3318 | /****************************************************************************** |
| 3319 | * Shift data bits out to the EEPROM. |
| 3320 | * |
| 3321 | * hw - Struct containing variables accessed by shared code |
| 3322 | * data - data to send to the EEPROM |
| 3323 | * count - number of bits to shift out |
| 3324 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3325 | 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] | 3326 | { |
| 3327 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3328 | u32 eecd; |
| 3329 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | |
| 3331 | /* We need to shift "count" bits out to the EEPROM. So, value in the |
| 3332 | * "data" parameter will be shifted out to the EEPROM one bit at a time. |
| 3333 | * In order to do this, "data" must be broken down into bits. |
| 3334 | */ |
| 3335 | mask = 0x01 << (count - 1); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3336 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | if (eeprom->type == e1000_eeprom_microwire) { |
| 3338 | eecd &= ~E1000_EECD_DO; |
| 3339 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 3340 | eecd |= E1000_EECD_DO; |
| 3341 | } |
| 3342 | do { |
| 3343 | /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1", |
| 3344 | * and then raising and then lowering the clock (the SK bit controls |
| 3345 | * the clock input to the EEPROM). A "0" is shifted out to the EEPROM |
| 3346 | * by setting "DI" to "0" and then raising and then lowering the clock. |
| 3347 | */ |
| 3348 | eecd &= ~E1000_EECD_DI; |
| 3349 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3350 | if (data & mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | eecd |= E1000_EECD_DI; |
| 3352 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3353 | ew32(EECD, eecd); |
| 3354 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | |
| 3356 | udelay(eeprom->delay_usec); |
| 3357 | |
| 3358 | e1000_raise_ee_clk(hw, &eecd); |
| 3359 | e1000_lower_ee_clk(hw, &eecd); |
| 3360 | |
| 3361 | mask = mask >> 1; |
| 3362 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3363 | } while (mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | |
| 3365 | /* We leave the "DI" bit set to "0" when we leave this routine. */ |
| 3366 | eecd &= ~E1000_EECD_DI; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3367 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | /****************************************************************************** |
| 3371 | * Shift data bits in from the EEPROM |
| 3372 | * |
| 3373 | * hw - Struct containing variables accessed by shared code |
| 3374 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3375 | 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] | 3376 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3377 | u32 eecd; |
| 3378 | u32 i; |
| 3379 | u16 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | |
| 3381 | /* In order to read a register from the EEPROM, we need to shift 'count' |
| 3382 | * bits in from the EEPROM. Bits are "shifted in" by raising the clock |
| 3383 | * input to the EEPROM (setting the SK bit), and then reading the value of |
| 3384 | * the "DO" bit. During this "shifting in" process the "DI" bit should |
| 3385 | * always be clear. |
| 3386 | */ |
| 3387 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3388 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | |
| 3390 | eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); |
| 3391 | data = 0; |
| 3392 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3393 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | data = data << 1; |
| 3395 | e1000_raise_ee_clk(hw, &eecd); |
| 3396 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3397 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | |
| 3399 | eecd &= ~(E1000_EECD_DI); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3400 | if (eecd & E1000_EECD_DO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | data |= 1; |
| 3402 | |
| 3403 | e1000_lower_ee_clk(hw, &eecd); |
| 3404 | } |
| 3405 | |
| 3406 | return data; |
| 3407 | } |
| 3408 | |
| 3409 | /****************************************************************************** |
| 3410 | * Prepares EEPROM for access |
| 3411 | * |
| 3412 | * hw - Struct containing variables accessed by shared code |
| 3413 | * |
| 3414 | * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This |
| 3415 | * function should be called before issuing a command to the EEPROM. |
| 3416 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3417 | static s32 e1000_acquire_eeprom(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | { |
| 3419 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3420 | u32 eecd, i=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | |
| 3422 | DEBUGFUNC("e1000_acquire_eeprom"); |
| 3423 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3424 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 3426 | /* Request EEPROM Access */ |
| 3427 | if (hw->mac_type > e1000_82544) { |
| 3428 | eecd |= E1000_EECD_REQ; |
| 3429 | ew32(EECD, eecd); |
| 3430 | eecd = er32(EECD); |
| 3431 | while ((!(eecd & E1000_EECD_GNT)) && |
| 3432 | (i < E1000_EEPROM_GRANT_ATTEMPTS)) { |
| 3433 | i++; |
| 3434 | udelay(5); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3435 | eecd = er32(EECD); |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 3436 | } |
| 3437 | if (!(eecd & E1000_EECD_GNT)) { |
| 3438 | eecd &= ~E1000_EECD_REQ; |
| 3439 | ew32(EECD, eecd); |
| 3440 | DEBUGOUT("Could not acquire EEPROM grant\n"); |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 3441 | return -E1000_ERR_EEPROM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | } |
| 3443 | } |
| 3444 | |
| 3445 | /* Setup EEPROM for Read/Write */ |
| 3446 | |
| 3447 | if (eeprom->type == e1000_eeprom_microwire) { |
| 3448 | /* Clear SK and DI */ |
| 3449 | eecd &= ~(E1000_EECD_DI | E1000_EECD_SK); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3450 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | |
| 3452 | /* Set CS */ |
| 3453 | eecd |= E1000_EECD_CS; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3454 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 3456 | /* Clear SK and CS */ |
| 3457 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3458 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | udelay(1); |
| 3460 | } |
| 3461 | |
| 3462 | return E1000_SUCCESS; |
| 3463 | } |
| 3464 | |
| 3465 | /****************************************************************************** |
| 3466 | * Returns EEPROM to a "standby" state |
| 3467 | * |
| 3468 | * hw - Struct containing variables accessed by shared code |
| 3469 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3470 | static void e1000_standby_eeprom(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3471 | { |
| 3472 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3473 | u32 eecd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3475 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3477 | if (eeprom->type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3479 | ew32(EECD, eecd); |
| 3480 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3481 | udelay(eeprom->delay_usec); |
| 3482 | |
| 3483 | /* Clock high */ |
| 3484 | eecd |= E1000_EECD_SK; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3485 | ew32(EECD, eecd); |
| 3486 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3487 | udelay(eeprom->delay_usec); |
| 3488 | |
| 3489 | /* Select EEPROM */ |
| 3490 | eecd |= E1000_EECD_CS; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3491 | ew32(EECD, eecd); |
| 3492 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | udelay(eeprom->delay_usec); |
| 3494 | |
| 3495 | /* Clock low */ |
| 3496 | eecd &= ~E1000_EECD_SK; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3497 | ew32(EECD, eecd); |
| 3498 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | udelay(eeprom->delay_usec); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3500 | } else if (eeprom->type == e1000_eeprom_spi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | /* Toggle CS to flush commands */ |
| 3502 | eecd |= E1000_EECD_CS; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3503 | ew32(EECD, eecd); |
| 3504 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3505 | udelay(eeprom->delay_usec); |
| 3506 | eecd &= ~E1000_EECD_CS; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3507 | ew32(EECD, eecd); |
| 3508 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3509 | udelay(eeprom->delay_usec); |
| 3510 | } |
| 3511 | } |
| 3512 | |
| 3513 | /****************************************************************************** |
| 3514 | * Terminates a command by inverting the EEPROM's chip select pin |
| 3515 | * |
| 3516 | * hw - Struct containing variables accessed by shared code |
| 3517 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3518 | static void e1000_release_eeprom(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3520 | u32 eecd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | |
| 3522 | DEBUGFUNC("e1000_release_eeprom"); |
| 3523 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3524 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3525 | |
| 3526 | if (hw->eeprom.type == e1000_eeprom_spi) { |
| 3527 | eecd |= E1000_EECD_CS; /* Pull CS high */ |
| 3528 | eecd &= ~E1000_EECD_SK; /* Lower SCK */ |
| 3529 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3530 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | |
| 3532 | udelay(hw->eeprom.delay_usec); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3533 | } else if (hw->eeprom.type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | /* cleanup eeprom */ |
| 3535 | |
| 3536 | /* CS on Microwire is active-high */ |
| 3537 | eecd &= ~(E1000_EECD_CS | E1000_EECD_DI); |
| 3538 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3539 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | |
| 3541 | /* Rising edge of clock */ |
| 3542 | eecd |= E1000_EECD_SK; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3543 | ew32(EECD, eecd); |
| 3544 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3545 | udelay(hw->eeprom.delay_usec); |
| 3546 | |
| 3547 | /* Falling edge of clock */ |
| 3548 | eecd &= ~E1000_EECD_SK; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3549 | ew32(EECD, eecd); |
| 3550 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | udelay(hw->eeprom.delay_usec); |
| 3552 | } |
| 3553 | |
| 3554 | /* Stop requesting EEPROM access */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3555 | if (hw->mac_type > e1000_82544) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | eecd &= ~E1000_EECD_REQ; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3557 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3558 | } |
| 3559 | } |
| 3560 | |
| 3561 | /****************************************************************************** |
| 3562 | * Reads a 16 bit word from the EEPROM. |
| 3563 | * |
| 3564 | * hw - Struct containing variables accessed by shared code |
| 3565 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3566 | static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3568 | u16 retry_count = 0; |
| 3569 | u8 spi_stat_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | |
| 3571 | DEBUGFUNC("e1000_spi_eeprom_ready"); |
| 3572 | |
| 3573 | /* Read "Status Register" repeatedly until the LSB is cleared. The |
| 3574 | * EEPROM will signal that the command has been completed by clearing |
| 3575 | * bit 0 of the internal status register. If it's not cleared within |
| 3576 | * 5 milliseconds, then error out. |
| 3577 | */ |
| 3578 | retry_count = 0; |
| 3579 | do { |
| 3580 | e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI, |
| 3581 | hw->eeprom.opcode_bits); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3582 | spi_stat_reg = (u8)e1000_shift_in_ee_bits(hw, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI)) |
| 3584 | break; |
| 3585 | |
| 3586 | udelay(5); |
| 3587 | retry_count += 5; |
| 3588 | |
| 3589 | e1000_standby_eeprom(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3590 | } while (retry_count < EEPROM_MAX_RETRY_SPI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3591 | |
| 3592 | /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and |
| 3593 | * only 0-5mSec on 5V devices) |
| 3594 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3595 | if (retry_count >= EEPROM_MAX_RETRY_SPI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3596 | DEBUGOUT("SPI EEPROM Status error\n"); |
| 3597 | return -E1000_ERR_EEPROM; |
| 3598 | } |
| 3599 | |
| 3600 | return E1000_SUCCESS; |
| 3601 | } |
| 3602 | |
| 3603 | /****************************************************************************** |
| 3604 | * Reads a 16 bit word from the EEPROM. |
| 3605 | * |
| 3606 | * hw - Struct containing variables accessed by shared code |
| 3607 | * offset - offset of word in the EEPROM to read |
| 3608 | * data - word read from the EEPROM |
| 3609 | * words - number of words to read |
| 3610 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3611 | 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] | 3612 | { |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 3613 | s32 ret; |
| 3614 | spin_lock(&e1000_eeprom_lock); |
| 3615 | ret = e1000_do_read_eeprom(hw, offset, words, data); |
| 3616 | spin_unlock(&e1000_eeprom_lock); |
| 3617 | return ret; |
| 3618 | } |
| 3619 | |
| 3620 | static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) |
| 3621 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3622 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3623 | u32 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | |
| 3625 | DEBUGFUNC("e1000_read_eeprom"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3626 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3627 | /* If eeprom is not yet detected, do so now */ |
| 3628 | if (eeprom->word_size == 0) |
| 3629 | e1000_init_eeprom_params(hw); |
| 3630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3631 | /* A check for invalid values: offset too large, too many words, and not |
| 3632 | * enough words. |
| 3633 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3634 | if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | (words == 0)) { |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3636 | 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] | 3637 | return -E1000_ERR_EEPROM; |
| 3638 | } |
| 3639 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3640 | /* EEPROM's that don't use EERD to read require us to bit-bang the SPI |
| 3641 | * directly. In this case, we need to acquire the EEPROM so that |
| 3642 | * FW or other port software does not interrupt. |
| 3643 | */ |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 3644 | if (!hw->eeprom.use_eerd) { |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3645 | /* Prepare the EEPROM for bit-bang reading */ |
| 3646 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) |
| 3647 | return -E1000_ERR_EEPROM; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3648 | } |
| 3649 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3650 | /* Eerd register EEPROM access requires no eeprom aquire/release */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3651 | if (eeprom->use_eerd) |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3652 | return e1000_read_eeprom_eerd(hw, offset, words, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3653 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3654 | /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have |
| 3655 | * acquired the EEPROM at this point, so any returns should relase it */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3656 | if (eeprom->type == e1000_eeprom_spi) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3657 | u16 word_in; |
| 3658 | u8 read_opcode = EEPROM_READ_OPCODE_SPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3660 | if (e1000_spi_eeprom_ready(hw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3661 | e1000_release_eeprom(hw); |
| 3662 | return -E1000_ERR_EEPROM; |
| 3663 | } |
| 3664 | |
| 3665 | e1000_standby_eeprom(hw); |
| 3666 | |
| 3667 | /* Some SPI eeproms use the 8th address bit embedded in the opcode */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3668 | if ((eeprom->address_bits == 8) && (offset >= 128)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | read_opcode |= EEPROM_A8_OPCODE_SPI; |
| 3670 | |
| 3671 | /* Send the READ command (opcode + addr) */ |
| 3672 | e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3673 | e1000_shift_out_ee_bits(hw, (u16)(offset*2), eeprom->address_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | |
| 3675 | /* Read the data. The address of the eeprom internally increments with |
| 3676 | * each byte (spi) being read, saving on the overhead of eeprom setup |
| 3677 | * and tear-down. The address counter will roll over if reading beyond |
| 3678 | * the size of the eeprom, thus allowing the entire memory to be read |
| 3679 | * starting from any offset. */ |
| 3680 | for (i = 0; i < words; i++) { |
| 3681 | word_in = e1000_shift_in_ee_bits(hw, 16); |
| 3682 | data[i] = (word_in >> 8) | (word_in << 8); |
| 3683 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3684 | } else if (eeprom->type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | for (i = 0; i < words; i++) { |
| 3686 | /* Send the READ command (opcode + addr) */ |
| 3687 | e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE, |
| 3688 | eeprom->opcode_bits); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3689 | e1000_shift_out_ee_bits(hw, (u16)(offset + i), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | eeprom->address_bits); |
| 3691 | |
| 3692 | /* Read the data. For microwire, each word requires the overhead |
| 3693 | * of eeprom setup and tear-down. */ |
| 3694 | data[i] = e1000_shift_in_ee_bits(hw, 16); |
| 3695 | e1000_standby_eeprom(hw); |
| 3696 | } |
| 3697 | } |
| 3698 | |
| 3699 | /* End this read operation */ |
| 3700 | e1000_release_eeprom(hw); |
| 3701 | |
| 3702 | return E1000_SUCCESS; |
| 3703 | } |
| 3704 | |
| 3705 | /****************************************************************************** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3706 | * Reads a 16 bit word from the EEPROM using the EERD register. |
| 3707 | * |
| 3708 | * hw - Struct containing variables accessed by shared code |
| 3709 | * offset - offset of word in the EEPROM to read |
| 3710 | * data - word read from the EEPROM |
| 3711 | * words - number of words to read |
| 3712 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3713 | static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words, |
| 3714 | u16 *data) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3715 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3716 | u32 i, eerd = 0; |
| 3717 | s32 error = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3718 | |
| 3719 | for (i = 0; i < words; i++) { |
| 3720 | eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) + |
| 3721 | E1000_EEPROM_RW_REG_START; |
| 3722 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3723 | ew32(EERD, eerd); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3724 | error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3725 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3726 | if (error) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3727 | break; |
| 3728 | } |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3729 | data[i] = (er32(EERD) >> E1000_EEPROM_RW_REG_DATA); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3730 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3731 | } |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3732 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3733 | return error; |
| 3734 | } |
| 3735 | |
| 3736 | /****************************************************************************** |
| 3737 | * Writes a 16 bit word from the EEPROM using the EEWR register. |
| 3738 | * |
| 3739 | * hw - Struct containing variables accessed by shared code |
| 3740 | * offset - offset of word in the EEPROM to read |
| 3741 | * data - word read from the EEPROM |
| 3742 | * words - number of words to read |
| 3743 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3744 | static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words, |
| 3745 | u16 *data) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3746 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3747 | u32 register_value = 0; |
| 3748 | u32 i = 0; |
| 3749 | s32 error = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3750 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3751 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3752 | for (i = 0; i < words; i++) { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3753 | register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) | |
| 3754 | ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3755 | E1000_EEPROM_RW_REG_START; |
| 3756 | |
| 3757 | error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3758 | if (error) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3759 | break; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3760 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3761 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3762 | ew32(EEWR, register_value); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3763 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3764 | error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3765 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3766 | if (error) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3767 | break; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3768 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3769 | } |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3770 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3771 | return error; |
| 3772 | } |
| 3773 | |
| 3774 | /****************************************************************************** |
| 3775 | * Polls the status bit (bit 1) of the EERD to determine when the read is done. |
| 3776 | * |
| 3777 | * hw - Struct containing variables accessed by shared code |
| 3778 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3779 | 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] | 3780 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3781 | u32 attempts = 100000; |
| 3782 | u32 i, reg = 0; |
| 3783 | s32 done = E1000_ERR_EEPROM; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3784 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3785 | for (i = 0; i < attempts; i++) { |
| 3786 | if (eerd == E1000_EEPROM_POLL_READ) |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3787 | reg = er32(EERD); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3788 | else |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3789 | reg = er32(EEWR); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3790 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3791 | if (reg & E1000_EEPROM_RW_REG_DONE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3792 | done = E1000_SUCCESS; |
| 3793 | break; |
| 3794 | } |
| 3795 | udelay(5); |
| 3796 | } |
| 3797 | |
| 3798 | return done; |
| 3799 | } |
| 3800 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3801 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | * Verifies that the EEPROM has a valid checksum |
| 3803 | * |
| 3804 | * hw - Struct containing variables accessed by shared code |
| 3805 | * |
| 3806 | * Reads the first 64 16 bit words of the EEPROM and sums the values read. |
| 3807 | * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is |
| 3808 | * valid. |
| 3809 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3810 | s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3812 | u16 checksum = 0; |
| 3813 | u16 i, eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | |
| 3815 | DEBUGFUNC("e1000_validate_eeprom_checksum"); |
| 3816 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3817 | for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) { |
| 3818 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | DEBUGOUT("EEPROM Read Error\n"); |
| 3820 | return -E1000_ERR_EEPROM; |
| 3821 | } |
| 3822 | checksum += eeprom_data; |
| 3823 | } |
| 3824 | |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 3825 | if (checksum == (u16)EEPROM_SUM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3826 | return E1000_SUCCESS; |
| 3827 | else { |
| 3828 | DEBUGOUT("EEPROM Checksum Invalid\n"); |
| 3829 | return -E1000_ERR_EEPROM; |
| 3830 | } |
| 3831 | } |
| 3832 | |
| 3833 | /****************************************************************************** |
| 3834 | * Calculates the EEPROM checksum and writes it to the EEPROM |
| 3835 | * |
| 3836 | * hw - Struct containing variables accessed by shared code |
| 3837 | * |
| 3838 | * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA. |
| 3839 | * Writes the difference to word offset 63 of the EEPROM. |
| 3840 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3841 | s32 e1000_update_eeprom_checksum(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3843 | u16 checksum = 0; |
| 3844 | u16 i, eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | |
| 3846 | DEBUGFUNC("e1000_update_eeprom_checksum"); |
| 3847 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3848 | for (i = 0; i < EEPROM_CHECKSUM_REG; i++) { |
| 3849 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | DEBUGOUT("EEPROM Read Error\n"); |
| 3851 | return -E1000_ERR_EEPROM; |
| 3852 | } |
| 3853 | checksum += eeprom_data; |
| 3854 | } |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 3855 | checksum = (u16)EEPROM_SUM - checksum; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3856 | if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | DEBUGOUT("EEPROM Write Error\n"); |
| 3858 | return -E1000_ERR_EEPROM; |
| 3859 | } |
| 3860 | return E1000_SUCCESS; |
| 3861 | } |
| 3862 | |
| 3863 | /****************************************************************************** |
| 3864 | * Parent function for writing words to the different EEPROM types. |
| 3865 | * |
| 3866 | * hw - Struct containing variables accessed by shared code |
| 3867 | * offset - offset within the EEPROM to be written to |
| 3868 | * words - number of words to write |
| 3869 | * data - 16 bit word to be written to the EEPROM |
| 3870 | * |
| 3871 | * If e1000_update_eeprom_checksum is not called after this function, the |
| 3872 | * EEPROM will most likely contain an invalid checksum. |
| 3873 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3874 | 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] | 3875 | { |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 3876 | s32 ret; |
| 3877 | spin_lock(&e1000_eeprom_lock); |
| 3878 | ret = e1000_do_write_eeprom(hw, offset, words, data); |
| 3879 | spin_unlock(&e1000_eeprom_lock); |
| 3880 | return ret; |
| 3881 | } |
| 3882 | |
| 3883 | |
| 3884 | static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) |
| 3885 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3886 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3887 | s32 status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | |
| 3889 | DEBUGFUNC("e1000_write_eeprom"); |
| 3890 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3891 | /* If eeprom is not yet detected, do so now */ |
| 3892 | if (eeprom->word_size == 0) |
| 3893 | e1000_init_eeprom_params(hw); |
| 3894 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | /* A check for invalid values: offset too large, too many words, and not |
| 3896 | * enough words. |
| 3897 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3898 | if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | (words == 0)) { |
| 3900 | DEBUGOUT("\"words\" parameter out of bounds\n"); |
| 3901 | return -E1000_ERR_EEPROM; |
| 3902 | } |
| 3903 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3904 | if (eeprom->use_eewr) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3905 | return e1000_write_eeprom_eewr(hw, offset, words, data); |
| 3906 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | /* Prepare the EEPROM for writing */ |
| 3908 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) |
| 3909 | return -E1000_ERR_EEPROM; |
| 3910 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3911 | if (eeprom->type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | status = e1000_write_eeprom_microwire(hw, offset, words, data); |
| 3913 | } else { |
| 3914 | status = e1000_write_eeprom_spi(hw, offset, words, data); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 3915 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | /* Done with writing */ |
| 3919 | e1000_release_eeprom(hw); |
| 3920 | |
| 3921 | return status; |
| 3922 | } |
| 3923 | |
| 3924 | /****************************************************************************** |
| 3925 | * Writes a 16 bit word to a given offset in an SPI EEPROM. |
| 3926 | * |
| 3927 | * hw - Struct containing variables accessed by shared code |
| 3928 | * offset - offset within the EEPROM to be written to |
| 3929 | * words - number of words to write |
| 3930 | * data - pointer to array of 8 bit words to be written to the EEPROM |
| 3931 | * |
| 3932 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3933 | static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words, |
| 3934 | u16 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3935 | { |
| 3936 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3937 | u16 widx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | |
| 3939 | DEBUGFUNC("e1000_write_eeprom_spi"); |
| 3940 | |
| 3941 | while (widx < words) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3942 | u8 write_opcode = EEPROM_WRITE_OPCODE_SPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3944 | if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | |
| 3946 | e1000_standby_eeprom(hw); |
| 3947 | |
| 3948 | /* Send the WRITE ENABLE command (8 bit opcode ) */ |
| 3949 | e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI, |
| 3950 | eeprom->opcode_bits); |
| 3951 | |
| 3952 | e1000_standby_eeprom(hw); |
| 3953 | |
| 3954 | /* Some SPI eeproms use the 8th address bit embedded in the opcode */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3955 | if ((eeprom->address_bits == 8) && (offset >= 128)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 | write_opcode |= EEPROM_A8_OPCODE_SPI; |
| 3957 | |
| 3958 | /* Send the Write command (8-bit opcode + addr) */ |
| 3959 | e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits); |
| 3960 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3961 | e1000_shift_out_ee_bits(hw, (u16)((offset + widx)*2), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3962 | eeprom->address_bits); |
| 3963 | |
| 3964 | /* Send the data */ |
| 3965 | |
| 3966 | /* Loop to allow for up to whole page write (32 bytes) of eeprom */ |
| 3967 | while (widx < words) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3968 | u16 word_out = data[widx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | word_out = (word_out >> 8) | (word_out << 8); |
| 3970 | e1000_shift_out_ee_bits(hw, word_out, 16); |
| 3971 | widx++; |
| 3972 | |
| 3973 | /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE |
| 3974 | * operation, while the smaller eeproms are capable of an 8-byte |
| 3975 | * PAGE WRITE operation. Break the inner loop to pass new address |
| 3976 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3977 | if ((((offset + widx)*2) % eeprom->page_size) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | e1000_standby_eeprom(hw); |
| 3979 | break; |
| 3980 | } |
| 3981 | } |
| 3982 | } |
| 3983 | |
| 3984 | return E1000_SUCCESS; |
| 3985 | } |
| 3986 | |
| 3987 | /****************************************************************************** |
| 3988 | * Writes a 16 bit word to a given offset in a Microwire EEPROM. |
| 3989 | * |
| 3990 | * hw - Struct containing variables accessed by shared code |
| 3991 | * offset - offset within the EEPROM to be written to |
| 3992 | * words - number of words to write |
| 3993 | * data - pointer to array of 16 bit words to be written to the EEPROM |
| 3994 | * |
| 3995 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3996 | static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset, |
| 3997 | u16 words, u16 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | { |
| 3999 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4000 | u32 eecd; |
| 4001 | u16 words_written = 0; |
| 4002 | u16 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | |
| 4004 | DEBUGFUNC("e1000_write_eeprom_microwire"); |
| 4005 | |
| 4006 | /* Send the write enable command to the EEPROM (3-bit opcode plus |
| 4007 | * 6/8-bit dummy address beginning with 11). It's less work to include |
| 4008 | * the 11 of the dummy address as part of the opcode than it is to shift |
| 4009 | * it over the correct number of bits for the address. This puts the |
| 4010 | * EEPROM into write/erase mode. |
| 4011 | */ |
| 4012 | e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4013 | (u16)(eeprom->opcode_bits + 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4014 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4015 | e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4016 | |
| 4017 | /* Prepare the EEPROM */ |
| 4018 | e1000_standby_eeprom(hw); |
| 4019 | |
| 4020 | while (words_written < words) { |
| 4021 | /* Send the Write command (3-bit opcode + addr) */ |
| 4022 | e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE, |
| 4023 | eeprom->opcode_bits); |
| 4024 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4025 | e1000_shift_out_ee_bits(hw, (u16)(offset + words_written), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | eeprom->address_bits); |
| 4027 | |
| 4028 | /* Send the data */ |
| 4029 | e1000_shift_out_ee_bits(hw, data[words_written], 16); |
| 4030 | |
| 4031 | /* Toggle the CS line. This in effect tells the EEPROM to execute |
| 4032 | * the previous command. |
| 4033 | */ |
| 4034 | e1000_standby_eeprom(hw); |
| 4035 | |
| 4036 | /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will |
| 4037 | * signal that the command has been completed by raising the DO signal. |
| 4038 | * If DO does not go high in 10 milliseconds, then error out. |
| 4039 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4040 | for (i = 0; i < 200; i++) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4041 | eecd = er32(EECD); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4042 | if (eecd & E1000_EECD_DO) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | udelay(50); |
| 4044 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4045 | if (i == 200) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4046 | DEBUGOUT("EEPROM Write did not complete\n"); |
| 4047 | return -E1000_ERR_EEPROM; |
| 4048 | } |
| 4049 | |
| 4050 | /* Recover from write */ |
| 4051 | e1000_standby_eeprom(hw); |
| 4052 | |
| 4053 | words_written++; |
| 4054 | } |
| 4055 | |
| 4056 | /* Send the write disable command to the EEPROM (3-bit opcode plus |
| 4057 | * 6/8-bit dummy address beginning with 10). It's less work to include |
| 4058 | * the 10 of the dummy address as part of the opcode than it is to shift |
| 4059 | * it over the correct number of bits for the address. This takes the |
| 4060 | * EEPROM out of write/erase mode. |
| 4061 | */ |
| 4062 | e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4063 | (u16)(eeprom->opcode_bits + 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4065 | e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | |
| 4067 | return E1000_SUCCESS; |
| 4068 | } |
| 4069 | |
| 4070 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the |
| 4072 | * second function of dual function devices |
| 4073 | * |
| 4074 | * hw - Struct containing variables accessed by shared code |
| 4075 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4076 | s32 e1000_read_mac_addr(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4078 | u16 offset; |
| 4079 | u16 eeprom_data, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | |
| 4081 | DEBUGFUNC("e1000_read_mac_addr"); |
| 4082 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4083 | for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4084 | offset = i >> 1; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4085 | if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4086 | DEBUGOUT("EEPROM Read Error\n"); |
| 4087 | return -E1000_ERR_EEPROM; |
| 4088 | } |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 4089 | hw->perm_mac_addr[i] = (u8)(eeprom_data & 0x00FF); |
| 4090 | hw->perm_mac_addr[i+1] = (u8)(eeprom_data >> 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4092 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4093 | switch (hw->mac_type) { |
| 4094 | default: |
| 4095 | break; |
| 4096 | case e1000_82546: |
| 4097 | case e1000_82546_rev_3: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4098 | if (er32(STATUS) & E1000_STATUS_FUNC_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | hw->perm_mac_addr[5] ^= 0x01; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4100 | break; |
| 4101 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4102 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4103 | for (i = 0; i < NODE_ADDRESS_SIZE; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | hw->mac_addr[i] = hw->perm_mac_addr[i]; |
| 4105 | return E1000_SUCCESS; |
| 4106 | } |
| 4107 | |
| 4108 | /****************************************************************************** |
| 4109 | * Initializes receive address filters. |
| 4110 | * |
| 4111 | * hw - Struct containing variables accessed by shared code |
| 4112 | * |
| 4113 | * Places the MAC address in receive address register 0 and clears the rest |
| 4114 | * of the receive addresss registers. Clears the multicast table. Assumes |
| 4115 | * the receiver is in reset when the routine is called. |
| 4116 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4117 | static void e1000_init_rx_addrs(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4119 | u32 i; |
| 4120 | u32 rar_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4121 | |
| 4122 | DEBUGFUNC("e1000_init_rx_addrs"); |
| 4123 | |
| 4124 | /* Setup the receive address. */ |
| 4125 | DEBUGOUT("Programming MAC Address into RAR[0]\n"); |
| 4126 | |
| 4127 | e1000_rar_set(hw, hw->mac_addr, 0); |
| 4128 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4129 | rar_num = E1000_RAR_ENTRIES; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | /* Zero out the other 15 receive addresses. */ |
| 4132 | DEBUGOUT("Clearing RAR[1-15]\n"); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4133 | for (i = 1; i < rar_num; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4134 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4135 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4137 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | * Hashes an address to determine its location in the multicast table |
| 4143 | * |
| 4144 | * hw - Struct containing variables accessed by shared code |
| 4145 | * mc_addr - the multicast address to hash |
| 4146 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4147 | u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4149 | u32 hash_value = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | |
| 4151 | /* The portion of the address that is used for the hash table is |
| 4152 | * determined by the mc_filter_type setting. |
| 4153 | */ |
| 4154 | switch (hw->mc_filter_type) { |
| 4155 | /* [0] [1] [2] [3] [4] [5] |
| 4156 | * 01 AA 00 12 34 56 |
| 4157 | * LSB MSB |
| 4158 | */ |
| 4159 | case 0: |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 4160 | /* [47:36] i.e. 0x563 for above example address */ |
| 4161 | hash_value = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4162 | break; |
| 4163 | case 1: |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 4164 | /* [46:35] i.e. 0xAC6 for above example address */ |
| 4165 | hash_value = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | break; |
| 4167 | case 2: |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 4168 | /* [45:34] i.e. 0x5D8 for above example address */ |
| 4169 | hash_value = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | break; |
| 4171 | case 3: |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 4172 | /* [43:32] i.e. 0x634 for above example address */ |
| 4173 | hash_value = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | break; |
| 4175 | } |
| 4176 | |
| 4177 | hash_value &= 0xFFF; |
| 4178 | return hash_value; |
| 4179 | } |
| 4180 | |
| 4181 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4182 | * Puts an ethernet address into a receive address register. |
| 4183 | * |
| 4184 | * hw - Struct containing variables accessed by shared code |
| 4185 | * addr - Address to put into receive address register |
| 4186 | * index - Receive address register to write |
| 4187 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4188 | void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4190 | u32 rar_low, rar_high; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | |
| 4192 | /* HW expects these in little endian so we reverse the byte order |
| 4193 | * from network order (big endian) to little endian |
| 4194 | */ |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 4195 | rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) | |
| 4196 | ((u32)addr[2] << 16) | ((u32)addr[3] << 24)); |
| 4197 | rar_high = ((u32)addr[4] | ((u32)addr[5] << 8)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4198 | |
Jeff Kirsher | 8df06e5 | 2006-03-02 18:18:32 -0800 | [diff] [blame] | 4199 | /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx |
| 4200 | * unit hang. |
| 4201 | * |
| 4202 | * Description: |
| 4203 | * If there are any Rx frames queued up or otherwise present in the HW |
| 4204 | * before RSS is enabled, and then we enable RSS, the HW Rx unit will |
| 4205 | * hang. To work around this issue, we have to disable receives and |
| 4206 | * flush out all Rx frames before we enable RSS. To do so, we modify we |
| 4207 | * redirect all Rx traffic to manageability and then reset the HW. |
| 4208 | * This flushes away Rx frames, and (since the redirections to |
| 4209 | * manageability persists across resets) keeps new ones from coming in |
| 4210 | * while we work. Then, we clear the Address Valid AV bit for all MAC |
| 4211 | * addresses and undo the re-direction to manageability. |
| 4212 | * Now, frames are coming in again, but the MAC won't accept them, so |
| 4213 | * far so good. We now proceed to initialize RSS (if necessary) and |
| 4214 | * configure the Rx unit. Last, we re-enable the AV bits and continue |
| 4215 | * on our merry way. |
| 4216 | */ |
| 4217 | switch (hw->mac_type) { |
Jeff Kirsher | 8df06e5 | 2006-03-02 18:18:32 -0800 | [diff] [blame] | 4218 | default: |
| 4219 | /* Indicate to hardware the Address is Valid. */ |
| 4220 | rar_high |= E1000_RAH_AV; |
| 4221 | break; |
| 4222 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 | |
| 4224 | E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4225 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4227 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | } |
| 4229 | |
| 4230 | /****************************************************************************** |
| 4231 | * Writes a value to the specified offset in the VLAN filter table. |
| 4232 | * |
| 4233 | * hw - Struct containing variables accessed by shared code |
| 4234 | * offset - Offset in VLAN filer table to write |
| 4235 | * value - Value to write into VLAN filter table |
| 4236 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4237 | void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4239 | u32 temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4241 | if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1)); |
| 4243 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4244 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4246 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | } else { |
| 4248 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4249 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | } |
| 4251 | } |
| 4252 | |
| 4253 | /****************************************************************************** |
| 4254 | * Clears the VLAN filer table |
| 4255 | * |
| 4256 | * hw - Struct containing variables accessed by shared code |
| 4257 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4258 | static void e1000_clear_vfta(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4260 | u32 offset; |
| 4261 | u32 vfta_value = 0; |
| 4262 | u32 vfta_offset = 0; |
| 4263 | u32 vfta_bit_in_reg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4265 | for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) { |
| 4266 | /* If the offset we want to clear is the same offset of the |
| 4267 | * manageability VLAN ID, then clear all bits except that of the |
| 4268 | * manageability unit */ |
| 4269 | vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0; |
| 4270 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4271 | E1000_WRITE_FLUSH(); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4272 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4273 | } |
| 4274 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4275 | static s32 e1000_id_led_init(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4277 | u32 ledctl; |
| 4278 | const u32 ledctl_mask = 0x000000FF; |
| 4279 | const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON; |
| 4280 | const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF; |
| 4281 | u16 eeprom_data, i, temp; |
| 4282 | const u16 led_mask = 0x0F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | |
| 4284 | DEBUGFUNC("e1000_id_led_init"); |
| 4285 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4286 | if (hw->mac_type < e1000_82540) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | /* Nothing to do */ |
| 4288 | return E1000_SUCCESS; |
| 4289 | } |
| 4290 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4291 | ledctl = er32(LEDCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4292 | hw->ledctl_default = ledctl; |
| 4293 | hw->ledctl_mode1 = hw->ledctl_default; |
| 4294 | hw->ledctl_mode2 = hw->ledctl_default; |
| 4295 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4296 | 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] | 4297 | DEBUGOUT("EEPROM Read Error\n"); |
| 4298 | return -E1000_ERR_EEPROM; |
| 4299 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4300 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 4301 | if ((eeprom_data == ID_LED_RESERVED_0000) || |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4302 | (eeprom_data == ID_LED_RESERVED_FFFF)) { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4303 | eeprom_data = ID_LED_DEFAULT; |
| 4304 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4305 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4306 | for (i = 0; i < 4; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | temp = (eeprom_data >> (i << 2)) & led_mask; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4308 | switch (temp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | case ID_LED_ON1_DEF2: |
| 4310 | case ID_LED_ON1_ON2: |
| 4311 | case ID_LED_ON1_OFF2: |
| 4312 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); |
| 4313 | hw->ledctl_mode1 |= ledctl_on << (i << 3); |
| 4314 | break; |
| 4315 | case ID_LED_OFF1_DEF2: |
| 4316 | case ID_LED_OFF1_ON2: |
| 4317 | case ID_LED_OFF1_OFF2: |
| 4318 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); |
| 4319 | hw->ledctl_mode1 |= ledctl_off << (i << 3); |
| 4320 | break; |
| 4321 | default: |
| 4322 | /* Do nothing */ |
| 4323 | break; |
| 4324 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4325 | switch (temp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | case ID_LED_DEF1_ON2: |
| 4327 | case ID_LED_ON1_ON2: |
| 4328 | case ID_LED_OFF1_ON2: |
| 4329 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); |
| 4330 | hw->ledctl_mode2 |= ledctl_on << (i << 3); |
| 4331 | break; |
| 4332 | case ID_LED_DEF1_OFF2: |
| 4333 | case ID_LED_ON1_OFF2: |
| 4334 | case ID_LED_OFF1_OFF2: |
| 4335 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); |
| 4336 | hw->ledctl_mode2 |= ledctl_off << (i << 3); |
| 4337 | break; |
| 4338 | default: |
| 4339 | /* Do nothing */ |
| 4340 | break; |
| 4341 | } |
| 4342 | } |
| 4343 | return E1000_SUCCESS; |
| 4344 | } |
| 4345 | |
| 4346 | /****************************************************************************** |
| 4347 | * Prepares SW controlable LED for use and saves the current state of the LED. |
| 4348 | * |
| 4349 | * hw - Struct containing variables accessed by shared code |
| 4350 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4351 | s32 e1000_setup_led(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4352 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4353 | u32 ledctl; |
| 4354 | s32 ret_val = E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | |
| 4356 | DEBUGFUNC("e1000_setup_led"); |
| 4357 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4358 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | case e1000_82542_rev2_0: |
| 4360 | case e1000_82542_rev2_1: |
| 4361 | case e1000_82543: |
| 4362 | case e1000_82544: |
| 4363 | /* No setup necessary */ |
| 4364 | break; |
| 4365 | case e1000_82541: |
| 4366 | case e1000_82547: |
| 4367 | case e1000_82541_rev_2: |
| 4368 | case e1000_82547_rev_2: |
| 4369 | /* Turn off PHY Smart Power Down (if enabled) */ |
| 4370 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 4371 | &hw->phy_spd_default); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4372 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4373 | return ret_val; |
| 4374 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4375 | (u16)(hw->phy_spd_default & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | ~IGP01E1000_GMII_SPD)); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4377 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4378 | return ret_val; |
| 4379 | /* Fall Through */ |
| 4380 | default: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4381 | if (hw->media_type == e1000_media_type_fiber) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4382 | ledctl = er32(LEDCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4383 | /* Save current LEDCTL settings */ |
| 4384 | hw->ledctl_default = ledctl; |
| 4385 | /* Turn off LED0 */ |
| 4386 | ledctl &= ~(E1000_LEDCTL_LED0_IVRT | |
| 4387 | E1000_LEDCTL_LED0_BLINK | |
| 4388 | E1000_LEDCTL_LED0_MODE_MASK); |
| 4389 | ledctl |= (E1000_LEDCTL_MODE_LED_OFF << |
| 4390 | E1000_LEDCTL_LED0_MODE_SHIFT); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4391 | ew32(LEDCTL, ledctl); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4392 | } else if (hw->media_type == e1000_media_type_copper) |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4393 | ew32(LEDCTL, hw->ledctl_mode1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4394 | break; |
| 4395 | } |
| 4396 | |
| 4397 | return E1000_SUCCESS; |
| 4398 | } |
| 4399 | |
Auke Kok | f1b3a85 | 2006-06-27 09:07:56 -0700 | [diff] [blame] | 4400 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | * Restores the saved state of the SW controlable LED. |
| 4402 | * |
| 4403 | * hw - Struct containing variables accessed by shared code |
| 4404 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4405 | s32 e1000_cleanup_led(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4407 | s32 ret_val = E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | |
| 4409 | DEBUGFUNC("e1000_cleanup_led"); |
| 4410 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4411 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | case e1000_82542_rev2_0: |
| 4413 | case e1000_82542_rev2_1: |
| 4414 | case e1000_82543: |
| 4415 | case e1000_82544: |
| 4416 | /* No cleanup necessary */ |
| 4417 | break; |
| 4418 | case e1000_82541: |
| 4419 | case e1000_82547: |
| 4420 | case e1000_82541_rev_2: |
| 4421 | case e1000_82547_rev_2: |
| 4422 | /* Turn on PHY Smart Power Down (if previously enabled) */ |
| 4423 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 4424 | hw->phy_spd_default); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4425 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | return ret_val; |
| 4427 | /* Fall Through */ |
| 4428 | default: |
| 4429 | /* Restore LEDCTL settings */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4430 | ew32(LEDCTL, hw->ledctl_default); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4431 | break; |
| 4432 | } |
| 4433 | |
| 4434 | return E1000_SUCCESS; |
| 4435 | } |
| 4436 | |
| 4437 | /****************************************************************************** |
| 4438 | * Turns on the software controllable LED |
| 4439 | * |
| 4440 | * hw - Struct containing variables accessed by shared code |
| 4441 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4442 | s32 e1000_led_on(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4443 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4444 | u32 ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | |
| 4446 | DEBUGFUNC("e1000_led_on"); |
| 4447 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4448 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | case e1000_82542_rev2_0: |
| 4450 | case e1000_82542_rev2_1: |
| 4451 | case e1000_82543: |
| 4452 | /* Set SW Defineable Pin 0 to turn on the LED */ |
| 4453 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4454 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4455 | break; |
| 4456 | case e1000_82544: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4457 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4458 | /* Set SW Defineable Pin 0 to turn on the LED */ |
| 4459 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4460 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4461 | } else { |
| 4462 | /* Clear SW Defineable Pin 0 to turn on the LED */ |
| 4463 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4464 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4465 | } |
| 4466 | break; |
| 4467 | default: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4468 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | /* Clear SW Defineable Pin 0 to turn on the LED */ |
| 4470 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4471 | ctrl |= E1000_CTRL_SWDPIO0; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4472 | } else if (hw->media_type == e1000_media_type_copper) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4473 | ew32(LEDCTL, hw->ledctl_mode2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | return E1000_SUCCESS; |
| 4475 | } |
| 4476 | break; |
| 4477 | } |
| 4478 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4479 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | |
| 4481 | return E1000_SUCCESS; |
| 4482 | } |
| 4483 | |
| 4484 | /****************************************************************************** |
| 4485 | * Turns off the software controllable LED |
| 4486 | * |
| 4487 | * hw - Struct containing variables accessed by shared code |
| 4488 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4489 | s32 e1000_led_off(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4491 | u32 ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4492 | |
| 4493 | DEBUGFUNC("e1000_led_off"); |
| 4494 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4495 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | case e1000_82542_rev2_0: |
| 4497 | case e1000_82542_rev2_1: |
| 4498 | case e1000_82543: |
| 4499 | /* Clear SW Defineable Pin 0 to turn off the LED */ |
| 4500 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4501 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4502 | break; |
| 4503 | case e1000_82544: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4504 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4505 | /* Clear SW Defineable Pin 0 to turn off the LED */ |
| 4506 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4507 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4508 | } else { |
| 4509 | /* Set SW Defineable Pin 0 to turn off the LED */ |
| 4510 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4511 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4512 | } |
| 4513 | break; |
| 4514 | default: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4515 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4516 | /* Set SW Defineable Pin 0 to turn off the LED */ |
| 4517 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4518 | ctrl |= E1000_CTRL_SWDPIO0; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4519 | } else if (hw->media_type == e1000_media_type_copper) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4520 | ew32(LEDCTL, hw->ledctl_mode1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4521 | return E1000_SUCCESS; |
| 4522 | } |
| 4523 | break; |
| 4524 | } |
| 4525 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4526 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | |
| 4528 | return E1000_SUCCESS; |
| 4529 | } |
| 4530 | |
| 4531 | /****************************************************************************** |
| 4532 | * Clears all hardware statistics counters. |
| 4533 | * |
| 4534 | * hw - Struct containing variables accessed by shared code |
| 4535 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4536 | static void e1000_clear_hw_cntrs(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4537 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4538 | volatile u32 temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4539 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4540 | temp = er32(CRCERRS); |
| 4541 | temp = er32(SYMERRS); |
| 4542 | temp = er32(MPC); |
| 4543 | temp = er32(SCC); |
| 4544 | temp = er32(ECOL); |
| 4545 | temp = er32(MCC); |
| 4546 | temp = er32(LATECOL); |
| 4547 | temp = er32(COLC); |
| 4548 | temp = er32(DC); |
| 4549 | temp = er32(SEC); |
| 4550 | temp = er32(RLEC); |
| 4551 | temp = er32(XONRXC); |
| 4552 | temp = er32(XONTXC); |
| 4553 | temp = er32(XOFFRXC); |
| 4554 | temp = er32(XOFFTXC); |
| 4555 | temp = er32(FCRUC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4556 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4557 | temp = er32(PRC64); |
| 4558 | temp = er32(PRC127); |
| 4559 | temp = er32(PRC255); |
| 4560 | temp = er32(PRC511); |
| 4561 | temp = er32(PRC1023); |
| 4562 | temp = er32(PRC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4563 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4564 | temp = er32(GPRC); |
| 4565 | temp = er32(BPRC); |
| 4566 | temp = er32(MPRC); |
| 4567 | temp = er32(GPTC); |
| 4568 | temp = er32(GORCL); |
| 4569 | temp = er32(GORCH); |
| 4570 | temp = er32(GOTCL); |
| 4571 | temp = er32(GOTCH); |
| 4572 | temp = er32(RNBC); |
| 4573 | temp = er32(RUC); |
| 4574 | temp = er32(RFC); |
| 4575 | temp = er32(ROC); |
| 4576 | temp = er32(RJC); |
| 4577 | temp = er32(TORL); |
| 4578 | temp = er32(TORH); |
| 4579 | temp = er32(TOTL); |
| 4580 | temp = er32(TOTH); |
| 4581 | temp = er32(TPR); |
| 4582 | temp = er32(TPT); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4583 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4584 | temp = er32(PTC64); |
| 4585 | temp = er32(PTC127); |
| 4586 | temp = er32(PTC255); |
| 4587 | temp = er32(PTC511); |
| 4588 | temp = er32(PTC1023); |
| 4589 | temp = er32(PTC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4590 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4591 | temp = er32(MPTC); |
| 4592 | temp = er32(BPTC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4594 | if (hw->mac_type < e1000_82543) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4596 | temp = er32(ALGNERRC); |
| 4597 | temp = er32(RXERRC); |
| 4598 | temp = er32(TNCRS); |
| 4599 | temp = er32(CEXTERR); |
| 4600 | temp = er32(TSCTC); |
| 4601 | temp = er32(TSCTFC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4602 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4603 | if (hw->mac_type <= e1000_82544) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4604 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4605 | temp = er32(MGTPRC); |
| 4606 | temp = er32(MGTPDC); |
| 4607 | temp = er32(MGTPTC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4608 | } |
| 4609 | |
| 4610 | /****************************************************************************** |
| 4611 | * Resets Adaptive IFS to its default state. |
| 4612 | * |
| 4613 | * hw - Struct containing variables accessed by shared code |
| 4614 | * |
| 4615 | * 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] | 4616 | * hw->ifs_params_forced to true. However, you must initialize hw-> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio |
| 4618 | * before calling this function. |
| 4619 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4620 | void e1000_reset_adaptive(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | { |
| 4622 | DEBUGFUNC("e1000_reset_adaptive"); |
| 4623 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4624 | if (hw->adaptive_ifs) { |
| 4625 | if (!hw->ifs_params_forced) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4626 | hw->current_ifs_val = 0; |
| 4627 | hw->ifs_min_val = IFS_MIN; |
| 4628 | hw->ifs_max_val = IFS_MAX; |
| 4629 | hw->ifs_step_size = IFS_STEP; |
| 4630 | hw->ifs_ratio = IFS_RATIO; |
| 4631 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4632 | hw->in_ifs_mode = false; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4633 | ew32(AIT, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4634 | } else { |
| 4635 | DEBUGOUT("Not in Adaptive IFS mode!\n"); |
| 4636 | } |
| 4637 | } |
| 4638 | |
| 4639 | /****************************************************************************** |
| 4640 | * Called during the callback/watchdog routine to update IFS value based on |
| 4641 | * the ratio of transmits to collisions. |
| 4642 | * |
| 4643 | * hw - Struct containing variables accessed by shared code |
| 4644 | * tx_packets - Number of transmits since last callback |
| 4645 | * total_collisions - Number of collisions since last callback |
| 4646 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4647 | void e1000_update_adaptive(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4648 | { |
| 4649 | DEBUGFUNC("e1000_update_adaptive"); |
| 4650 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4651 | if (hw->adaptive_ifs) { |
| 4652 | if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) { |
| 4653 | if (hw->tx_packet_delta > MIN_NUM_XMITS) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4654 | hw->in_ifs_mode = true; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4655 | if (hw->current_ifs_val < hw->ifs_max_val) { |
| 4656 | if (hw->current_ifs_val == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | hw->current_ifs_val = hw->ifs_min_val; |
| 4658 | else |
| 4659 | hw->current_ifs_val += hw->ifs_step_size; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4660 | ew32(AIT, hw->current_ifs_val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4661 | } |
| 4662 | } |
| 4663 | } else { |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4664 | if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | hw->current_ifs_val = 0; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4666 | hw->in_ifs_mode = false; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4667 | ew32(AIT, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4668 | } |
| 4669 | } |
| 4670 | } else { |
| 4671 | DEBUGOUT("Not in Adaptive IFS mode!\n"); |
| 4672 | } |
| 4673 | } |
| 4674 | |
| 4675 | /****************************************************************************** |
| 4676 | * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT |
| 4677 | * |
| 4678 | * hw - Struct containing variables accessed by shared code |
| 4679 | * frame_len - The length of the frame in question |
| 4680 | * mac_addr - The Ethernet destination address of the frame in question |
| 4681 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4682 | void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats, |
| 4683 | u32 frame_len, u8 *mac_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4684 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4685 | u64 carry_bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4686 | |
| 4687 | /* First adjust the frame length. */ |
| 4688 | frame_len--; |
| 4689 | /* We need to adjust the statistics counters, since the hardware |
| 4690 | * counters overcount this packet as a CRC error and undercount |
| 4691 | * the packet as a good packet |
| 4692 | */ |
| 4693 | /* This packet should not be counted as a CRC error. */ |
| 4694 | stats->crcerrs--; |
| 4695 | /* This packet does count as a Good Packet Received. */ |
| 4696 | stats->gprc++; |
| 4697 | |
| 4698 | /* Adjust the Good Octets received counters */ |
| 4699 | carry_bit = 0x80000000 & stats->gorcl; |
| 4700 | stats->gorcl += frame_len; |
| 4701 | /* If the high bit of Gorcl (the low 32 bits of the Good Octets |
| 4702 | * Received Count) was one before the addition, |
| 4703 | * AND it is zero after, then we lost the carry out, |
| 4704 | * need to add one to Gorch (Good Octets Received Count High). |
| 4705 | * This could be simplified if all environments supported |
| 4706 | * 64-bit integers. |
| 4707 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4708 | if (carry_bit && ((stats->gorcl & 0x80000000) == 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4709 | stats->gorch++; |
| 4710 | /* Is this a broadcast or multicast? Check broadcast first, |
| 4711 | * since the test for a multicast frame will test positive on |
| 4712 | * a broadcast frame. |
| 4713 | */ |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 4714 | if ((mac_addr[0] == (u8)0xff) && (mac_addr[1] == (u8)0xff)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4715 | /* Broadcast packet */ |
| 4716 | stats->bprc++; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4717 | else if (*mac_addr & 0x01) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4718 | /* Multicast packet */ |
| 4719 | stats->mprc++; |
| 4720 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4721 | if (frame_len == hw->max_frame_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | /* In this case, the hardware has overcounted the number of |
| 4723 | * oversize frames. |
| 4724 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4725 | if (stats->roc > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4726 | stats->roc--; |
| 4727 | } |
| 4728 | |
| 4729 | /* Adjust the bin counters when the extra byte put the frame in the |
| 4730 | * wrong bin. Remember that the frame_len was adjusted above. |
| 4731 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4732 | if (frame_len == 64) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4733 | stats->prc64++; |
| 4734 | stats->prc127--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4735 | } else if (frame_len == 127) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4736 | stats->prc127++; |
| 4737 | stats->prc255--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4738 | } else if (frame_len == 255) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4739 | stats->prc255++; |
| 4740 | stats->prc511--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4741 | } else if (frame_len == 511) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4742 | stats->prc511++; |
| 4743 | stats->prc1023--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4744 | } else if (frame_len == 1023) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4745 | stats->prc1023++; |
| 4746 | stats->prc1522--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4747 | } else if (frame_len == 1522) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | stats->prc1522++; |
| 4749 | } |
| 4750 | } |
| 4751 | |
| 4752 | /****************************************************************************** |
| 4753 | * Gets the current PCI bus type, speed, and width of the hardware |
| 4754 | * |
| 4755 | * hw - Struct containing variables accessed by shared code |
| 4756 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4757 | void e1000_get_bus_info(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4758 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4759 | u32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4760 | |
| 4761 | switch (hw->mac_type) { |
| 4762 | case e1000_82542_rev2_0: |
| 4763 | case e1000_82542_rev2_1: |
Jeff Kirsher | c3813ae | 2006-12-15 10:37:32 +0100 | [diff] [blame] | 4764 | hw->bus_type = e1000_bus_type_pci; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4765 | hw->bus_speed = e1000_bus_speed_unknown; |
| 4766 | hw->bus_width = e1000_bus_width_unknown; |
| 4767 | break; |
| 4768 | default: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4769 | status = er32(STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4770 | hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ? |
| 4771 | e1000_bus_type_pcix : e1000_bus_type_pci; |
| 4772 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4773 | if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ? |
| 4775 | e1000_bus_speed_66 : e1000_bus_speed_120; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4776 | } else if (hw->bus_type == e1000_bus_type_pci) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4777 | hw->bus_speed = (status & E1000_STATUS_PCI66) ? |
| 4778 | e1000_bus_speed_66 : e1000_bus_speed_33; |
| 4779 | } else { |
| 4780 | switch (status & E1000_STATUS_PCIX_SPEED) { |
| 4781 | case E1000_STATUS_PCIX_SPEED_66: |
| 4782 | hw->bus_speed = e1000_bus_speed_66; |
| 4783 | break; |
| 4784 | case E1000_STATUS_PCIX_SPEED_100: |
| 4785 | hw->bus_speed = e1000_bus_speed_100; |
| 4786 | break; |
| 4787 | case E1000_STATUS_PCIX_SPEED_133: |
| 4788 | hw->bus_speed = e1000_bus_speed_133; |
| 4789 | break; |
| 4790 | default: |
| 4791 | hw->bus_speed = e1000_bus_speed_reserved; |
| 4792 | break; |
| 4793 | } |
| 4794 | } |
| 4795 | hw->bus_width = (status & E1000_STATUS_BUS64) ? |
| 4796 | e1000_bus_width_64 : e1000_bus_width_32; |
| 4797 | break; |
| 4798 | } |
| 4799 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4800 | |
| 4801 | /****************************************************************************** |
| 4802 | * Writes a value to one of the devices registers using port I/O (as opposed to |
| 4803 | * memory mapped I/O). Only 82544 and newer devices support port I/O. |
| 4804 | * |
| 4805 | * hw - Struct containing variables accessed by shared code |
| 4806 | * offset - offset to write to |
| 4807 | * value - value to write |
| 4808 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4809 | 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] | 4810 | { |
| 4811 | unsigned long io_addr = hw->io_base; |
| 4812 | unsigned long io_data = hw->io_base + 4; |
| 4813 | |
| 4814 | e1000_io_write(hw, io_addr, offset); |
| 4815 | e1000_io_write(hw, io_data, value); |
| 4816 | } |
| 4817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4818 | /****************************************************************************** |
| 4819 | * Estimates the cable length. |
| 4820 | * |
| 4821 | * hw - Struct containing variables accessed by shared code |
| 4822 | * min_length - The estimated minimum length |
| 4823 | * max_length - The estimated maximum length |
| 4824 | * |
| 4825 | * returns: - E1000_ERR_XXX |
| 4826 | * E1000_SUCCESS |
| 4827 | * |
| 4828 | * This function always returns a ranged length (minimum & maximum). |
| 4829 | * So for M88 phy's, this function interprets the one value returned from the |
| 4830 | * register to the minimum and maximum range. |
| 4831 | * For IGP phy's, the function calculates the range by the AGC registers. |
| 4832 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4833 | static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length, |
| 4834 | u16 *max_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4836 | s32 ret_val; |
| 4837 | u16 agc_value = 0; |
| 4838 | u16 i, phy_data; |
| 4839 | u16 cable_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4840 | |
| 4841 | DEBUGFUNC("e1000_get_cable_length"); |
| 4842 | |
| 4843 | *min_length = *max_length = 0; |
| 4844 | |
| 4845 | /* Use old method for Phy older than IGP */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4846 | if (hw->phy_type == e1000_phy_m88) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4848 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 4849 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4850 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4851 | return ret_val; |
| 4852 | cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >> |
| 4853 | M88E1000_PSSR_CABLE_LENGTH_SHIFT; |
| 4854 | |
| 4855 | /* Convert the enum value to ranged values */ |
| 4856 | switch (cable_length) { |
| 4857 | case e1000_cable_length_50: |
| 4858 | *min_length = 0; |
| 4859 | *max_length = e1000_igp_cable_length_50; |
| 4860 | break; |
| 4861 | case e1000_cable_length_50_80: |
| 4862 | *min_length = e1000_igp_cable_length_50; |
| 4863 | *max_length = e1000_igp_cable_length_80; |
| 4864 | break; |
| 4865 | case e1000_cable_length_80_110: |
| 4866 | *min_length = e1000_igp_cable_length_80; |
| 4867 | *max_length = e1000_igp_cable_length_110; |
| 4868 | break; |
| 4869 | case e1000_cable_length_110_140: |
| 4870 | *min_length = e1000_igp_cable_length_110; |
| 4871 | *max_length = e1000_igp_cable_length_140; |
| 4872 | break; |
| 4873 | case e1000_cable_length_140: |
| 4874 | *min_length = e1000_igp_cable_length_140; |
| 4875 | *max_length = e1000_igp_cable_length_170; |
| 4876 | break; |
| 4877 | default: |
| 4878 | return -E1000_ERR_PHY; |
| 4879 | break; |
| 4880 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4881 | } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4882 | u16 cur_agc_value; |
| 4883 | u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE; |
| 4884 | u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4885 | {IGP01E1000_PHY_AGC_A, |
| 4886 | IGP01E1000_PHY_AGC_B, |
| 4887 | IGP01E1000_PHY_AGC_C, |
| 4888 | IGP01E1000_PHY_AGC_D}; |
| 4889 | /* Read the AGC registers for all channels */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4890 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4891 | |
| 4892 | 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] | 4893 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4894 | return ret_val; |
| 4895 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4896 | cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4897 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4898 | /* Value bound check. */ |
| 4899 | if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) || |
| 4900 | (cur_agc_value == 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | return -E1000_ERR_PHY; |
| 4902 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4903 | agc_value += cur_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4904 | |
| 4905 | /* Update minimal AGC value. */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4906 | if (min_agc_value > cur_agc_value) |
| 4907 | min_agc_value = cur_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4908 | } |
| 4909 | |
| 4910 | /* Remove the minimal AGC result for length < 50m */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4911 | if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) { |
| 4912 | agc_value -= min_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4913 | |
| 4914 | /* Get the average length of the remaining 3 channels */ |
| 4915 | agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1); |
| 4916 | } else { |
| 4917 | /* Get the average length of all the 4 channels. */ |
| 4918 | agc_value /= IGP01E1000_PHY_CHANNEL_NUM; |
| 4919 | } |
| 4920 | |
| 4921 | /* Set the range of the calculated length. */ |
| 4922 | *min_length = ((e1000_igp_cable_length_table[agc_value] - |
| 4923 | IGP01E1000_AGC_RANGE) > 0) ? |
| 4924 | (e1000_igp_cable_length_table[agc_value] - |
| 4925 | IGP01E1000_AGC_RANGE) : 0; |
| 4926 | *max_length = e1000_igp_cable_length_table[agc_value] + |
| 4927 | IGP01E1000_AGC_RANGE; |
| 4928 | } |
| 4929 | |
| 4930 | return E1000_SUCCESS; |
| 4931 | } |
| 4932 | |
| 4933 | /****************************************************************************** |
| 4934 | * Check the cable polarity |
| 4935 | * |
| 4936 | * hw - Struct containing variables accessed by shared code |
| 4937 | * polarity - output parameter : 0 - Polarity is not reversed |
| 4938 | * 1 - Polarity is reversed. |
| 4939 | * |
| 4940 | * returns: - E1000_ERR_XXX |
| 4941 | * E1000_SUCCESS |
| 4942 | * |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4943 | * 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] | 4944 | * Phy Status register. For IGP phy's, this bit is valid only if link speed is |
| 4945 | * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will |
| 4946 | * return 0. If the link speed is 1000 Mbps the polarity status is in the |
| 4947 | * IGP01E1000_PHY_PCS_INIT_REG. |
| 4948 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4949 | static s32 e1000_check_polarity(struct e1000_hw *hw, |
| 4950 | e1000_rev_polarity *polarity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4951 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4952 | s32 ret_val; |
| 4953 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | |
| 4955 | DEBUGFUNC("e1000_check_polarity"); |
| 4956 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 4957 | if (hw->phy_type == e1000_phy_m88) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4958 | /* return the Polarity bit in the Status register. */ |
| 4959 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 4960 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4961 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | return ret_val; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4963 | *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >> |
| 4964 | M88E1000_PSSR_REV_POLARITY_SHIFT) ? |
| 4965 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
| 4966 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 4967 | } else if (hw->phy_type == e1000_phy_igp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4968 | /* Read the Status register to check the speed */ |
| 4969 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, |
| 4970 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4971 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 | return ret_val; |
| 4973 | |
| 4974 | /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to |
| 4975 | * find the polarity status */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4976 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4977 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
| 4978 | |
| 4979 | /* Read the GIG initialization PCS register (0x00B4) */ |
| 4980 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG, |
| 4981 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4982 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4983 | return ret_val; |
| 4984 | |
| 4985 | /* Check the polarity bits */ |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4986 | *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? |
| 4987 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4988 | } else { |
| 4989 | /* For 10 Mbps, read the polarity bit in the status register. (for |
| 4990 | * 100 Mbps this bit is always 0) */ |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4991 | *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ? |
| 4992 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4993 | } |
| 4994 | } |
| 4995 | return E1000_SUCCESS; |
| 4996 | } |
| 4997 | |
| 4998 | /****************************************************************************** |
| 4999 | * Check if Downshift occured |
| 5000 | * |
| 5001 | * hw - Struct containing variables accessed by shared code |
| 5002 | * downshift - output parameter : 0 - No Downshift ocured. |
| 5003 | * 1 - Downshift ocured. |
| 5004 | * |
| 5005 | * returns: - E1000_ERR_XXX |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5006 | * E1000_SUCCESS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5007 | * |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 5008 | * 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] | 5009 | * Specific Status register. For IGP phy's, it reads the Downgrade bit in the |
| 5010 | * Link Health register. In IGP this bit is latched high, so the driver must |
| 5011 | * read it immediately after link is established. |
| 5012 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5013 | static s32 e1000_check_downshift(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5014 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5015 | s32 ret_val; |
| 5016 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | |
| 5018 | DEBUGFUNC("e1000_check_downshift"); |
| 5019 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 5020 | if (hw->phy_type == e1000_phy_igp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5021 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH, |
| 5022 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5023 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5024 | return ret_val; |
| 5025 | |
| 5026 | hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0; |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 5027 | } else if (hw->phy_type == e1000_phy_m88) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5028 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 5029 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5030 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | return ret_val; |
| 5032 | |
| 5033 | hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >> |
| 5034 | M88E1000_PSSR_DOWNSHIFT_SHIFT; |
| 5035 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5037 | return E1000_SUCCESS; |
| 5038 | } |
| 5039 | |
| 5040 | /***************************************************************************** |
| 5041 | * |
| 5042 | * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a |
| 5043 | * gigabit link is achieved to improve link quality. |
| 5044 | * |
| 5045 | * hw: Struct containing variables accessed by shared code |
| 5046 | * |
| 5047 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 5048 | * E1000_SUCCESS at any other case. |
| 5049 | * |
| 5050 | ****************************************************************************/ |
| 5051 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5052 | 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] | 5053 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5054 | s32 ret_val; |
| 5055 | u16 phy_data, phy_saved_data, speed, duplex, i; |
| 5056 | u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5057 | {IGP01E1000_PHY_AGC_PARAM_A, |
| 5058 | IGP01E1000_PHY_AGC_PARAM_B, |
| 5059 | IGP01E1000_PHY_AGC_PARAM_C, |
| 5060 | IGP01E1000_PHY_AGC_PARAM_D}; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5061 | u16 min_length, max_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | |
| 5063 | DEBUGFUNC("e1000_config_dsp_after_link_change"); |
| 5064 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5065 | if (hw->phy_type != e1000_phy_igp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5066 | return E1000_SUCCESS; |
| 5067 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5068 | if (link_up) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5069 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5070 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5071 | DEBUGOUT("Error getting link speed and duplex\n"); |
| 5072 | return ret_val; |
| 5073 | } |
| 5074 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5075 | if (speed == SPEED_1000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5076 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5077 | ret_val = e1000_get_cable_length(hw, &min_length, &max_length); |
| 5078 | if (ret_val) |
| 5079 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5080 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5081 | if ((hw->dsp_config_state == e1000_dsp_config_enabled) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | min_length >= e1000_igp_cable_length_50) { |
| 5083 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5084 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5085 | ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], |
| 5086 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5087 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5088 | return ret_val; |
| 5089 | |
| 5090 | phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX; |
| 5091 | |
| 5092 | ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i], |
| 5093 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5094 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5095 | return ret_val; |
| 5096 | } |
| 5097 | hw->dsp_config_state = e1000_dsp_config_activated; |
| 5098 | } |
| 5099 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5100 | if ((hw->ffe_config_state == e1000_ffe_config_enabled) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5101 | (min_length < e1000_igp_cable_length_50)) { |
| 5102 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5103 | u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20; |
| 5104 | u32 idle_errs = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5105 | |
| 5106 | /* clear previous idle error counts */ |
| 5107 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, |
| 5108 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5109 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5110 | return ret_val; |
| 5111 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5112 | for (i = 0; i < ffe_idle_err_timeout; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5113 | udelay(1000); |
| 5114 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, |
| 5115 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5116 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5117 | return ret_val; |
| 5118 | |
| 5119 | idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5120 | if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5121 | hw->ffe_config_state = e1000_ffe_config_active; |
| 5122 | |
| 5123 | ret_val = e1000_write_phy_reg(hw, |
| 5124 | IGP01E1000_PHY_DSP_FFE, |
| 5125 | IGP01E1000_PHY_DSP_FFE_CM_CP); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5126 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5127 | return ret_val; |
| 5128 | break; |
| 5129 | } |
| 5130 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5131 | if (idle_errs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5132 | ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100; |
| 5133 | } |
| 5134 | } |
| 5135 | } |
| 5136 | } else { |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5137 | if (hw->dsp_config_state == e1000_dsp_config_activated) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5138 | /* Save off the current value of register 0x2F5B to be restored at |
| 5139 | * the end of the routines. */ |
| 5140 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
| 5141 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5142 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5143 | return ret_val; |
| 5144 | |
| 5145 | /* Disable the PHY transmitter */ |
| 5146 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 5147 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5148 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5149 | return ret_val; |
| 5150 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5151 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5152 | |
| 5153 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 5154 | IGP01E1000_IEEE_FORCE_GIGA); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5155 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5156 | return ret_val; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5157 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5158 | 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] | 5159 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5160 | return ret_val; |
| 5161 | |
| 5162 | phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX; |
| 5163 | phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS; |
| 5164 | |
| 5165 | 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] | 5166 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5167 | return ret_val; |
| 5168 | } |
| 5169 | |
| 5170 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 5171 | IGP01E1000_IEEE_RESTART_AUTONEG); |
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 | return ret_val; |
| 5174 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5175 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5176 | |
| 5177 | /* Now enable the transmitter */ |
| 5178 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
| 5179 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5180 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5181 | return ret_val; |
| 5182 | |
| 5183 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 5184 | } |
| 5185 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5186 | if (hw->ffe_config_state == e1000_ffe_config_active) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5187 | /* Save off the current value of register 0x2F5B to be restored at |
| 5188 | * the end of the routines. */ |
| 5189 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
| 5190 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5191 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5192 | return ret_val; |
| 5193 | |
| 5194 | /* Disable the PHY transmitter */ |
| 5195 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 5196 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5197 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5198 | return ret_val; |
| 5199 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5200 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5201 | |
| 5202 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 5203 | IGP01E1000_IEEE_FORCE_GIGA); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5204 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5205 | return ret_val; |
| 5206 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE, |
| 5207 | IGP01E1000_PHY_DSP_FFE_DEFAULT); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5208 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5209 | return ret_val; |
| 5210 | |
| 5211 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 5212 | IGP01E1000_IEEE_RESTART_AUTONEG); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5213 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5214 | return ret_val; |
| 5215 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5216 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5217 | |
| 5218 | /* Now enable the transmitter */ |
| 5219 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
| 5220 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5221 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5222 | return ret_val; |
| 5223 | |
| 5224 | hw->ffe_config_state = e1000_ffe_config_enabled; |
| 5225 | } |
| 5226 | } |
| 5227 | return E1000_SUCCESS; |
| 5228 | } |
| 5229 | |
| 5230 | /***************************************************************************** |
| 5231 | * Set PHY to class A mode |
| 5232 | * Assumes the following operations will follow to enable the new class mode. |
| 5233 | * 1. Do a PHY soft reset |
| 5234 | * 2. Restart auto-negotiation or force link. |
| 5235 | * |
| 5236 | * hw - Struct containing variables accessed by shared code |
| 5237 | ****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5238 | static s32 e1000_set_phy_mode(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5239 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5240 | s32 ret_val; |
| 5241 | u16 eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5242 | |
| 5243 | DEBUGFUNC("e1000_set_phy_mode"); |
| 5244 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5245 | if ((hw->mac_type == e1000_82545_rev_3) && |
| 5246 | (hw->media_type == e1000_media_type_copper)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5247 | 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] | 5248 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5249 | return ret_val; |
| 5250 | } |
| 5251 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5252 | if ((eeprom_data != EEPROM_RESERVED_WORD) && |
| 5253 | (eeprom_data & EEPROM_PHY_CLASS_A)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5254 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5255 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5256 | return ret_val; |
| 5257 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5258 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5259 | return ret_val; |
| 5260 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5261 | hw->phy_reset_disable = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5262 | } |
| 5263 | } |
| 5264 | |
| 5265 | return E1000_SUCCESS; |
| 5266 | } |
| 5267 | |
| 5268 | /***************************************************************************** |
| 5269 | * |
| 5270 | * This function sets the lplu state according to the active flag. When |
| 5271 | * activating lplu this function also disables smart speed and vise versa. |
| 5272 | * lplu will not be activated unless the device autonegotiation advertisment |
| 5273 | * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes. |
| 5274 | * hw: Struct containing variables accessed by shared code |
| 5275 | * active - true to enable lplu false to disable lplu. |
| 5276 | * |
| 5277 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 5278 | * E1000_SUCCESS at any other case. |
| 5279 | * |
| 5280 | ****************************************************************************/ |
| 5281 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5282 | 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] | 5283 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5284 | s32 ret_val; |
| 5285 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5286 | DEBUGFUNC("e1000_set_d3_lplu_state"); |
| 5287 | |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 5288 | if (hw->phy_type != e1000_phy_igp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5289 | return E1000_SUCCESS; |
| 5290 | |
| 5291 | /* During driver activity LPLU should not be used or it will attain link |
| 5292 | * from the lowest speeds starting from 10Mbps. The capability is used for |
| 5293 | * Dx transitions and states */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5294 | 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] | 5295 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5296 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5297 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5298 | } else { |
| 5299 | 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] | 5300 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5301 | return ret_val; |
| 5302 | } |
| 5303 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5304 | if (!active) { |
| 5305 | if (hw->mac_type == e1000_82541_rev_2 || |
| 5306 | hw->mac_type == e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5307 | phy_data &= ~IGP01E1000_GMII_FLEX_SPD; |
| 5308 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5309 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5310 | return ret_val; |
| 5311 | } else { |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 5312 | phy_data &= ~IGP02E1000_PM_D3_LPLU; |
| 5313 | ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
| 5314 | phy_data); |
| 5315 | if (ret_val) |
| 5316 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5317 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5318 | |
| 5319 | /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during |
| 5320 | * Dx states where the power conservation is most important. During |
| 5321 | * driver activity we should enable SmartSpeed, so performance is |
| 5322 | * maintained. */ |
| 5323 | if (hw->smart_speed == e1000_smart_speed_on) { |
| 5324 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5325 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5326 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5327 | return ret_val; |
| 5328 | |
| 5329 | phy_data |= IGP01E1000_PSCFR_SMART_SPEED; |
| 5330 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5331 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5332 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5333 | return ret_val; |
| 5334 | } else if (hw->smart_speed == e1000_smart_speed_off) { |
| 5335 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5336 | &phy_data); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 5337 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5338 | return ret_val; |
| 5339 | |
| 5340 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 5341 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5342 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5343 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5344 | return ret_val; |
| 5345 | } |
| 5346 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5347 | } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) || |
| 5348 | (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) || |
| 5349 | (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5350 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5351 | if (hw->mac_type == e1000_82541_rev_2 || |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5352 | hw->mac_type == e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5353 | phy_data |= IGP01E1000_GMII_FLEX_SPD; |
| 5354 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5355 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5356 | return ret_val; |
| 5357 | } else { |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 5358 | phy_data |= IGP02E1000_PM_D3_LPLU; |
| 5359 | ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5360 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5361 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5362 | return ret_val; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5363 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5365 | /* When LPLU is enabled we should disable SmartSpeed */ |
| 5366 | 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] | 5367 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5368 | return ret_val; |
| 5369 | |
| 5370 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 5371 | 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] | 5372 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5373 | return ret_val; |
| 5374 | |
| 5375 | } |
| 5376 | return E1000_SUCCESS; |
| 5377 | } |
| 5378 | |
| 5379 | /****************************************************************************** |
| 5380 | * Change VCO speed register to improve Bit Error Rate performance of SERDES. |
| 5381 | * |
| 5382 | * hw - Struct containing variables accessed by shared code |
| 5383 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5384 | static s32 e1000_set_vco_speed(struct e1000_hw *hw) |
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 default_page = 0; |
| 5388 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5389 | |
| 5390 | DEBUGFUNC("e1000_set_vco_speed"); |
| 5391 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5392 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5393 | case e1000_82545_rev_3: |
| 5394 | case e1000_82546_rev_3: |
| 5395 | break; |
| 5396 | default: |
| 5397 | return E1000_SUCCESS; |
| 5398 | } |
| 5399 | |
| 5400 | /* Set PHY register 30, page 5, bit 8 to 0 */ |
| 5401 | |
| 5402 | 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] | 5403 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5404 | return ret_val; |
| 5405 | |
| 5406 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5407 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5408 | return ret_val; |
| 5409 | |
| 5410 | 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] | 5411 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5412 | return ret_val; |
| 5413 | |
| 5414 | phy_data &= ~M88E1000_PHY_VCO_REG_BIT8; |
| 5415 | 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] | 5416 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5417 | return ret_val; |
| 5418 | |
| 5419 | /* Set PHY register 30, page 4, bit 11 to 1 */ |
| 5420 | |
| 5421 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5422 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5423 | return ret_val; |
| 5424 | |
| 5425 | 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] | 5426 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5427 | return ret_val; |
| 5428 | |
| 5429 | phy_data |= M88E1000_PHY_VCO_REG_BIT11; |
| 5430 | 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] | 5431 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5432 | return ret_val; |
| 5433 | |
| 5434 | 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] | 5435 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5436 | return ret_val; |
| 5437 | |
| 5438 | return E1000_SUCCESS; |
| 5439 | } |
| 5440 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5441 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5442 | /****************************************************************************** |
| 5443 | * Verifies the hardware needs to allow ARPs to be processed by the host |
| 5444 | * |
| 5445 | * hw - Struct containing variables accessed by shared code |
| 5446 | * |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5447 | * returns: - true/false |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5448 | * |
| 5449 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5450 | u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5451 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5452 | u32 manc; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5453 | |
| 5454 | if (hw->asf_firmware_present) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5455 | manc = er32(MANC); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5456 | |
| 5457 | if (!(manc & E1000_MANC_RCV_TCO_EN) || |
| 5458 | !(manc & E1000_MANC_EN_MAC_ADDR_FILTER)) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5459 | return false; |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 5460 | if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN)) |
| 5461 | return true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5462 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5463 | return false; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5464 | } |
| 5465 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5466 | static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5467 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5468 | s32 ret_val; |
| 5469 | u16 mii_status_reg; |
| 5470 | u16 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5471 | |
| 5472 | /* Polarity reversal workaround for forced 10F/10H links. */ |
| 5473 | |
| 5474 | /* Disable the transmitter on the PHY */ |
| 5475 | |
| 5476 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5477 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5478 | return ret_val; |
| 5479 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5480 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5481 | return ret_val; |
| 5482 | |
| 5483 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5484 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5485 | return ret_val; |
| 5486 | |
| 5487 | /* 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] | 5488 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5489 | /* Read the MII Status Register and wait for Link Status bit |
| 5490 | * to be clear. |
| 5491 | */ |
| 5492 | |
| 5493 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5494 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5495 | return ret_val; |
| 5496 | |
| 5497 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5498 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5499 | return ret_val; |
| 5500 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5501 | if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5502 | mdelay(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5503 | } |
| 5504 | |
| 5505 | /* Recommended delay time after link has been lost */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5506 | mdelay(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5507 | |
| 5508 | /* Now we will re-enable th transmitter on the PHY */ |
| 5509 | |
| 5510 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5511 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5512 | return ret_val; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5513 | mdelay(50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5514 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5515 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5516 | return ret_val; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5517 | mdelay(50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5518 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5519 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5520 | return ret_val; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5521 | mdelay(50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5522 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5523 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5524 | return ret_val; |
| 5525 | |
| 5526 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5527 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5528 | return ret_val; |
| 5529 | |
| 5530 | /* This loop will early-out if the link condition has been met. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5531 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5532 | /* Read the MII Status Register and wait for Link Status bit |
| 5533 | * to be set. |
| 5534 | */ |
| 5535 | |
| 5536 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
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 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5541 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5542 | return ret_val; |
| 5543 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5544 | if (mii_status_reg & MII_SR_LINK_STATUS) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5545 | mdelay(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5546 | } |
| 5547 | return E1000_SUCCESS; |
| 5548 | } |
| 5549 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5550 | /******************************************************************************* |
| 5551 | * |
| 5552 | * Check for EEPROM Auto Read bit done. |
| 5553 | * |
| 5554 | * hw: Struct containing variables accessed by shared code |
| 5555 | * |
| 5556 | * returns: - E1000_ERR_RESET if fail to reset MAC |
| 5557 | * E1000_SUCCESS at any other case. |
| 5558 | * |
| 5559 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5560 | static s32 e1000_get_auto_rd_done(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5561 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5562 | DEBUGFUNC("e1000_get_auto_rd_done"); |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 5563 | msleep(5); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5564 | return E1000_SUCCESS; |
| 5565 | } |
| 5566 | |
| 5567 | /*************************************************************************** |
| 5568 | * Checks if the PHY configuration is done |
| 5569 | * |
| 5570 | * hw: Struct containing variables accessed by shared code |
| 5571 | * |
| 5572 | * returns: - E1000_ERR_RESET if fail to reset MAC |
| 5573 | * E1000_SUCCESS at any other case. |
| 5574 | * |
| 5575 | ***************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5576 | static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5577 | { |
| 5578 | DEBUGFUNC("e1000_get_phy_cfg_done"); |
Jesse Brandeburg | 1532ece | 2009-09-25 12:16:14 +0000 | [diff] [blame] | 5579 | mdelay(10); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5580 | return E1000_SUCCESS; |
| 5581 | } |