Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 3 | Intel PRO/1000 Linux driver |
| 4 | Copyright(c) 1999 - 2006 Intel Corporation. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | more details. |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | You should have received a copy of the GNU General Public License along with |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | Contact Information: |
| 23 | Linux NICS <linux.nics@intel.com> |
Auke Kok | 3d41e30 | 2006-04-14 19:05:31 -0700 | [diff] [blame] | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 27 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | /* e1000_hw.c |
| 30 | * Shared functions for accessing and configuring the MAC |
| 31 | */ |
| 32 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 33 | #include "e1000.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 35 | static s32 e1000_check_downshift(struct e1000_hw *hw); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 36 | static s32 e1000_check_polarity(struct e1000_hw *hw, |
| 37 | e1000_rev_polarity *polarity); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 38 | static void e1000_clear_hw_cntrs(struct e1000_hw *hw); |
| 39 | static void e1000_clear_vfta(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 40 | static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 41 | bool link_up); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 42 | static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw); |
| 43 | static s32 e1000_detect_gig_phy(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 44 | static s32 e1000_get_auto_rd_done(struct e1000_hw *hw); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 45 | static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length, |
| 46 | u16 *max_length); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 47 | static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 48 | static s32 e1000_id_led_init(struct e1000_hw *hw); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 49 | static void e1000_init_rx_addrs(struct e1000_hw *hw); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 50 | static s32 e1000_phy_igp_get_info(struct e1000_hw *hw, |
| 51 | struct e1000_phy_info *phy_info); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 52 | static s32 e1000_phy_m88_get_info(struct e1000_hw *hw, |
| 53 | struct e1000_phy_info *phy_info); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 54 | static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 55 | static s32 e1000_wait_autoneg(struct e1000_hw *hw); |
| 56 | static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value); |
| 57 | static s32 e1000_set_phy_type(struct e1000_hw *hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | static void e1000_phy_init_script(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 59 | static s32 e1000_setup_copper_link(struct e1000_hw *hw); |
| 60 | static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw); |
| 61 | static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw); |
| 62 | static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw); |
| 63 | static s32 e1000_config_mac_to_phy(struct e1000_hw *hw); |
| 64 | static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl); |
| 65 | static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 66 | static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 67 | static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw); |
| 68 | static s32 e1000_phy_reset_dsp(struct e1000_hw *hw); |
| 69 | static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 70 | u16 words, u16 *data); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 71 | static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset, |
| 72 | u16 words, u16 *data); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 73 | static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw); |
| 74 | static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd); |
| 75 | static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 76 | static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 77 | static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 78 | u16 phy_data); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 79 | static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 80 | u16 *phy_data); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 81 | static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count); |
| 82 | static s32 e1000_acquire_eeprom(struct e1000_hw *hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | static void e1000_release_eeprom(struct e1000_hw *hw); |
| 84 | static void e1000_standby_eeprom(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 85 | static s32 e1000_set_vco_speed(struct e1000_hw *hw); |
| 86 | static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw); |
| 87 | static s32 e1000_set_phy_mode(struct e1000_hw *hw); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 88 | static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, |
| 89 | u16 *data); |
| 90 | static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, |
| 91 | u16 *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | /* IGP cable length table */ |
| 94 | static const |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 95 | u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = { |
| 96 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
| 97 | 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25, |
| 98 | 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40, |
| 99 | 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, |
| 100 | 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90, |
| 101 | 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, |
| 102 | 100, |
| 103 | 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, |
| 104 | 110, 110, |
| 105 | 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, |
| 106 | 120, 120 |
| 107 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 109 | static DEFINE_SPINLOCK(e1000_eeprom_lock); |
| 110 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 111 | /** |
| 112 | * e1000_set_phy_type - Set the phy type member in the hw struct. |
| 113 | * @hw: Struct containing variables accessed by shared code |
| 114 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 115 | static s32 e1000_set_phy_type(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 117 | e_dbg("e1000_set_phy_type"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 119 | if (hw->mac_type == e1000_undefined) |
| 120 | return -E1000_ERR_PHY_TYPE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 121 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 122 | switch (hw->phy_id) { |
| 123 | case M88E1000_E_PHY_ID: |
| 124 | case M88E1000_I_PHY_ID: |
| 125 | case M88E1011_I_PHY_ID: |
| 126 | case M88E1111_I_PHY_ID: |
| 127 | hw->phy_type = e1000_phy_m88; |
| 128 | break; |
| 129 | case IGP01E1000_I_PHY_ID: |
| 130 | if (hw->mac_type == e1000_82541 || |
| 131 | hw->mac_type == e1000_82541_rev_2 || |
| 132 | hw->mac_type == e1000_82547 || |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 133 | hw->mac_type == e1000_82547_rev_2) |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 134 | hw->phy_type = e1000_phy_igp; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 135 | break; |
| 136 | case RTL8211B_PHY_ID: |
| 137 | hw->phy_type = e1000_phy_8211; |
| 138 | break; |
| 139 | case RTL8201N_PHY_ID: |
| 140 | hw->phy_type = e1000_phy_8201; |
| 141 | break; |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 142 | default: |
| 143 | /* Should never have loaded on this device */ |
| 144 | hw->phy_type = e1000_phy_undefined; |
| 145 | return -E1000_ERR_PHY_TYPE; |
| 146 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 148 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 151 | /** |
| 152 | * e1000_phy_init_script - IGP phy init script - initializes the GbE PHY |
| 153 | * @hw: Struct containing variables accessed by shared code |
| 154 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 155 | static void e1000_phy_init_script(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 157 | u32 ret_val; |
| 158 | u16 phy_saved_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 160 | e_dbg("e1000_phy_init_script"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 162 | if (hw->phy_init_script) { |
| 163 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 165 | /* Save off the current value of register 0x2F5B to be restored at |
| 166 | * the end of this routine. */ |
| 167 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 169 | /* Disabled the PHY transmitter */ |
| 170 | e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 171 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 173 | e1000_write_phy_reg(hw, 0x0000, 0x0140); |
| 174 | msleep(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 176 | switch (hw->mac_type) { |
| 177 | case e1000_82541: |
| 178 | case e1000_82547: |
| 179 | e1000_write_phy_reg(hw, 0x1F95, 0x0001); |
| 180 | e1000_write_phy_reg(hw, 0x1F71, 0xBD21); |
| 181 | e1000_write_phy_reg(hw, 0x1F79, 0x0018); |
| 182 | e1000_write_phy_reg(hw, 0x1F30, 0x1600); |
| 183 | e1000_write_phy_reg(hw, 0x1F31, 0x0014); |
| 184 | e1000_write_phy_reg(hw, 0x1F32, 0x161C); |
| 185 | e1000_write_phy_reg(hw, 0x1F94, 0x0003); |
| 186 | e1000_write_phy_reg(hw, 0x1F96, 0x003F); |
| 187 | e1000_write_phy_reg(hw, 0x2010, 0x0008); |
| 188 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 190 | case e1000_82541_rev_2: |
| 191 | case e1000_82547_rev_2: |
| 192 | e1000_write_phy_reg(hw, 0x1F73, 0x0099); |
| 193 | break; |
| 194 | default: |
| 195 | break; |
| 196 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 198 | e1000_write_phy_reg(hw, 0x0000, 0x3300); |
| 199 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 201 | /* Now enable the transmitter */ |
| 202 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 204 | if (hw->mac_type == e1000_82547) { |
| 205 | u16 fused, fine, coarse; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 207 | /* Move to analog registers page */ |
| 208 | e1000_read_phy_reg(hw, |
| 209 | IGP01E1000_ANALOG_SPARE_FUSE_STATUS, |
| 210 | &fused); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 212 | if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) { |
| 213 | e1000_read_phy_reg(hw, |
| 214 | IGP01E1000_ANALOG_FUSE_STATUS, |
| 215 | &fused); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 217 | fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK; |
| 218 | coarse = |
| 219 | fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 221 | if (coarse > |
| 222 | IGP01E1000_ANALOG_FUSE_COARSE_THRESH) { |
| 223 | coarse -= |
| 224 | IGP01E1000_ANALOG_FUSE_COARSE_10; |
| 225 | fine -= IGP01E1000_ANALOG_FUSE_FINE_1; |
| 226 | } else if (coarse == |
| 227 | IGP01E1000_ANALOG_FUSE_COARSE_THRESH) |
| 228 | fine -= IGP01E1000_ANALOG_FUSE_FINE_10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 230 | fused = |
| 231 | (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) | |
| 232 | (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) | |
| 233 | (coarse & |
| 234 | IGP01E1000_ANALOG_FUSE_COARSE_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 236 | e1000_write_phy_reg(hw, |
| 237 | IGP01E1000_ANALOG_FUSE_CONTROL, |
| 238 | fused); |
| 239 | e1000_write_phy_reg(hw, |
| 240 | IGP01E1000_ANALOG_FUSE_BYPASS, |
| 241 | IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL); |
| 242 | } |
| 243 | } |
| 244 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 247 | /** |
| 248 | * e1000_set_mac_type - Set the mac type member in the hw struct. |
| 249 | * @hw: Struct containing variables accessed by shared code |
| 250 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 251 | s32 e1000_set_mac_type(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 253 | e_dbg("e1000_set_mac_type"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 255 | switch (hw->device_id) { |
| 256 | case E1000_DEV_ID_82542: |
| 257 | switch (hw->revision_id) { |
| 258 | case E1000_82542_2_0_REV_ID: |
| 259 | hw->mac_type = e1000_82542_rev2_0; |
| 260 | break; |
| 261 | case E1000_82542_2_1_REV_ID: |
| 262 | hw->mac_type = e1000_82542_rev2_1; |
| 263 | break; |
| 264 | default: |
| 265 | /* Invalid 82542 revision ID */ |
| 266 | return -E1000_ERR_MAC_TYPE; |
| 267 | } |
| 268 | break; |
| 269 | case E1000_DEV_ID_82543GC_FIBER: |
| 270 | case E1000_DEV_ID_82543GC_COPPER: |
| 271 | hw->mac_type = e1000_82543; |
| 272 | break; |
| 273 | case E1000_DEV_ID_82544EI_COPPER: |
| 274 | case E1000_DEV_ID_82544EI_FIBER: |
| 275 | case E1000_DEV_ID_82544GC_COPPER: |
| 276 | case E1000_DEV_ID_82544GC_LOM: |
| 277 | hw->mac_type = e1000_82544; |
| 278 | break; |
| 279 | case E1000_DEV_ID_82540EM: |
| 280 | case E1000_DEV_ID_82540EM_LOM: |
| 281 | case E1000_DEV_ID_82540EP: |
| 282 | case E1000_DEV_ID_82540EP_LOM: |
| 283 | case E1000_DEV_ID_82540EP_LP: |
| 284 | hw->mac_type = e1000_82540; |
| 285 | break; |
| 286 | case E1000_DEV_ID_82545EM_COPPER: |
| 287 | case E1000_DEV_ID_82545EM_FIBER: |
| 288 | hw->mac_type = e1000_82545; |
| 289 | break; |
| 290 | case E1000_DEV_ID_82545GM_COPPER: |
| 291 | case E1000_DEV_ID_82545GM_FIBER: |
| 292 | case E1000_DEV_ID_82545GM_SERDES: |
| 293 | hw->mac_type = e1000_82545_rev_3; |
| 294 | break; |
| 295 | case E1000_DEV_ID_82546EB_COPPER: |
| 296 | case E1000_DEV_ID_82546EB_FIBER: |
| 297 | case E1000_DEV_ID_82546EB_QUAD_COPPER: |
| 298 | hw->mac_type = e1000_82546; |
| 299 | break; |
| 300 | case E1000_DEV_ID_82546GB_COPPER: |
| 301 | case E1000_DEV_ID_82546GB_FIBER: |
| 302 | case E1000_DEV_ID_82546GB_SERDES: |
| 303 | case E1000_DEV_ID_82546GB_PCIE: |
| 304 | case E1000_DEV_ID_82546GB_QUAD_COPPER: |
| 305 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
| 306 | hw->mac_type = e1000_82546_rev_3; |
| 307 | break; |
| 308 | case E1000_DEV_ID_82541EI: |
| 309 | case E1000_DEV_ID_82541EI_MOBILE: |
| 310 | case E1000_DEV_ID_82541ER_LOM: |
| 311 | hw->mac_type = e1000_82541; |
| 312 | break; |
| 313 | case E1000_DEV_ID_82541ER: |
| 314 | case E1000_DEV_ID_82541GI: |
| 315 | case E1000_DEV_ID_82541GI_LF: |
| 316 | case E1000_DEV_ID_82541GI_MOBILE: |
| 317 | hw->mac_type = e1000_82541_rev_2; |
| 318 | break; |
| 319 | case E1000_DEV_ID_82547EI: |
| 320 | case E1000_DEV_ID_82547EI_MOBILE: |
| 321 | hw->mac_type = e1000_82547; |
| 322 | break; |
| 323 | case E1000_DEV_ID_82547GI: |
| 324 | hw->mac_type = e1000_82547_rev_2; |
| 325 | break; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 326 | case E1000_DEV_ID_INTEL_CE4100_GBE: |
| 327 | hw->mac_type = e1000_ce4100; |
| 328 | break; |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 329 | default: |
| 330 | /* Should never have loaded on this device */ |
| 331 | return -E1000_ERR_MAC_TYPE; |
| 332 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 334 | switch (hw->mac_type) { |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 335 | case e1000_82541: |
| 336 | case e1000_82547: |
| 337 | case e1000_82541_rev_2: |
| 338 | case e1000_82547_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 339 | hw->asf_firmware_present = true; |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 340 | break; |
| 341 | default: |
| 342 | break; |
| 343 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 345 | /* The 82543 chip does not count tx_carrier_errors properly in |
| 346 | * FD mode |
| 347 | */ |
| 348 | if (hw->mac_type == e1000_82543) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 349 | hw->bad_tx_carr_stats_fd = true; |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 350 | |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 351 | if (hw->mac_type > e1000_82544) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 352 | hw->has_smbus = true; |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 353 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 354 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 357 | /** |
| 358 | * e1000_set_media_type - Set media type and TBI compatibility. |
| 359 | * @hw: Struct containing variables accessed by shared code |
| 360 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 361 | void e1000_set_media_type(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 363 | u32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 365 | e_dbg("e1000_set_media_type"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 367 | if (hw->mac_type != e1000_82543) { |
| 368 | /* tbi_compatibility is only valid on 82543 */ |
| 369 | hw->tbi_compatibility_en = false; |
| 370 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 372 | switch (hw->device_id) { |
| 373 | case E1000_DEV_ID_82545GM_SERDES: |
| 374 | case E1000_DEV_ID_82546GB_SERDES: |
| 375 | hw->media_type = e1000_media_type_internal_serdes; |
| 376 | break; |
| 377 | default: |
| 378 | switch (hw->mac_type) { |
| 379 | case e1000_82542_rev2_0: |
| 380 | case e1000_82542_rev2_1: |
| 381 | hw->media_type = e1000_media_type_fiber; |
| 382 | break; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 383 | case e1000_ce4100: |
| 384 | hw->media_type = e1000_media_type_copper; |
| 385 | break; |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 386 | default: |
| 387 | status = er32(STATUS); |
| 388 | if (status & E1000_STATUS_TBIMODE) { |
| 389 | hw->media_type = e1000_media_type_fiber; |
| 390 | /* tbi_compatibility not valid on fiber */ |
| 391 | hw->tbi_compatibility_en = false; |
| 392 | } else { |
| 393 | hw->media_type = e1000_media_type_copper; |
| 394 | } |
| 395 | break; |
| 396 | } |
| 397 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 400 | /** |
| 401 | * e1000_reset_hw: reset the hardware completely |
| 402 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 404 | * Reset the transmit and receive units; mask and clear all interrupts. |
| 405 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 406 | s32 e1000_reset_hw(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 408 | u32 ctrl; |
| 409 | u32 ctrl_ext; |
| 410 | u32 icr; |
| 411 | u32 manc; |
| 412 | u32 led_ctrl; |
| 413 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 415 | e_dbg("e1000_reset_hw"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 417 | /* For 82542 (rev 2.0), disable MWI before issuing a device reset */ |
| 418 | if (hw->mac_type == e1000_82542_rev2_0) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 419 | e_dbg("Disabling MWI on 82542 rev 2.0\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 420 | e1000_pci_clear_mwi(hw); |
| 421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 423 | /* Clear interrupt mask to stop board from generating interrupts */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 424 | e_dbg("Masking off all interrupts\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 425 | ew32(IMC, 0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 427 | /* Disable the Transmit and Receive units. Then delay to allow |
| 428 | * any pending transactions to complete before we hit the MAC with |
| 429 | * the global reset. |
| 430 | */ |
| 431 | ew32(RCTL, 0); |
| 432 | ew32(TCTL, E1000_TCTL_PSP); |
| 433 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 435 | /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */ |
| 436 | hw->tbi_compatibility_on = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 438 | /* Delay to allow any outstanding PCI transactions to complete before |
| 439 | * resetting the device |
| 440 | */ |
| 441 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 443 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 445 | /* Must reset the PHY before resetting the MAC */ |
| 446 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 447 | ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST)); |
| 448 | msleep(5); |
| 449 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 451 | /* Issue a global reset to the MAC. This will reset the chip's |
| 452 | * transmit, receive, DMA, and link units. It will not effect |
| 453 | * the current PCI configuration. The global reset bit is self- |
| 454 | * clearing, and should clear within a microsecond. |
| 455 | */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 456 | e_dbg("Issuing a global reset to MAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 458 | switch (hw->mac_type) { |
| 459 | case e1000_82544: |
| 460 | case e1000_82540: |
| 461 | case e1000_82545: |
| 462 | case e1000_82546: |
| 463 | case e1000_82541: |
| 464 | case e1000_82541_rev_2: |
| 465 | /* These controllers can't ack the 64-bit write when issuing the |
| 466 | * reset, so use IO-mapping as a workaround to issue the reset */ |
| 467 | E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST)); |
| 468 | break; |
| 469 | case e1000_82545_rev_3: |
| 470 | case e1000_82546_rev_3: |
| 471 | /* Reset is performed on a shadow of the control register */ |
| 472 | ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST)); |
| 473 | break; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 474 | case e1000_ce4100: |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 475 | default: |
| 476 | ew32(CTRL, (ctrl | E1000_CTRL_RST)); |
| 477 | break; |
| 478 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 480 | /* After MAC reset, force reload of EEPROM to restore power-on settings to |
| 481 | * device. Later controllers reload the EEPROM automatically, so just wait |
| 482 | * for reload to complete. |
| 483 | */ |
| 484 | switch (hw->mac_type) { |
| 485 | case e1000_82542_rev2_0: |
| 486 | case e1000_82542_rev2_1: |
| 487 | case e1000_82543: |
| 488 | case e1000_82544: |
| 489 | /* Wait for reset to complete */ |
| 490 | udelay(10); |
| 491 | ctrl_ext = er32(CTRL_EXT); |
| 492 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; |
| 493 | ew32(CTRL_EXT, ctrl_ext); |
| 494 | E1000_WRITE_FLUSH(); |
| 495 | /* Wait for EEPROM reload */ |
| 496 | msleep(2); |
| 497 | break; |
| 498 | case e1000_82541: |
| 499 | case e1000_82541_rev_2: |
| 500 | case e1000_82547: |
| 501 | case e1000_82547_rev_2: |
| 502 | /* Wait for EEPROM reload */ |
| 503 | msleep(20); |
| 504 | break; |
| 505 | default: |
| 506 | /* Auto read done will delay 5ms or poll based on mac type */ |
| 507 | ret_val = e1000_get_auto_rd_done(hw); |
| 508 | if (ret_val) |
| 509 | return ret_val; |
| 510 | break; |
| 511 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 513 | /* Disable HW ARPs on ASF enabled adapters */ |
| 514 | if (hw->mac_type >= e1000_82540) { |
| 515 | manc = er32(MANC); |
| 516 | manc &= ~(E1000_MANC_ARP_EN); |
| 517 | ew32(MANC, manc); |
| 518 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 520 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 521 | e1000_phy_init_script(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 523 | /* Configure activity LED after PHY reset */ |
| 524 | led_ctrl = er32(LEDCTL); |
| 525 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 526 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 527 | ew32(LEDCTL, led_ctrl); |
| 528 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 530 | /* Clear interrupt mask to stop board from generating interrupts */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 531 | e_dbg("Masking off all interrupts\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 532 | ew32(IMC, 0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 534 | /* Clear any pending interrupt events. */ |
| 535 | icr = er32(ICR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 537 | /* If MWI was previously enabled, reenable it. */ |
| 538 | if (hw->mac_type == e1000_82542_rev2_0) { |
| 539 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
| 540 | e1000_pci_set_mwi(hw); |
| 541 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 543 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 546 | /** |
| 547 | * e1000_init_hw: Performs basic configuration of the adapter. |
| 548 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | * |
| 550 | * Assumes that the controller has previously been reset and is in a |
| 551 | * post-reset uninitialized state. Initializes the receive address registers, |
| 552 | * multicast table, and VLAN filter table. Calls routines to setup link |
| 553 | * configuration and flow control settings. Clears all on-chip counters. Leaves |
| 554 | * the transmit and receive units disabled and uninitialized. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 555 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 556 | s32 e1000_init_hw(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 558 | u32 ctrl; |
| 559 | u32 i; |
| 560 | s32 ret_val; |
| 561 | u32 mta_size; |
| 562 | u32 ctrl_ext; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 563 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 564 | e_dbg("e1000_init_hw"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 566 | /* Initialize Identification LED */ |
| 567 | ret_val = e1000_id_led_init(hw); |
| 568 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 569 | e_dbg("Error Initializing Identification LED\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 570 | return ret_val; |
| 571 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 573 | /* Set the media type and TBI compatibility */ |
| 574 | e1000_set_media_type(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 576 | /* Disabling VLAN filtering. */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 577 | e_dbg("Initializing the IEEE VLAN\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 578 | if (hw->mac_type < e1000_82545_rev_3) |
| 579 | ew32(VET, 0); |
| 580 | e1000_clear_vfta(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 582 | /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */ |
| 583 | if (hw->mac_type == e1000_82542_rev2_0) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 584 | e_dbg("Disabling MWI on 82542 rev 2.0\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 585 | e1000_pci_clear_mwi(hw); |
| 586 | ew32(RCTL, E1000_RCTL_RST); |
| 587 | E1000_WRITE_FLUSH(); |
| 588 | msleep(5); |
| 589 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 591 | /* Setup the receive address. This involves initializing all of the Receive |
| 592 | * Address Registers (RARs 0 - 15). |
| 593 | */ |
| 594 | e1000_init_rx_addrs(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 596 | /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */ |
| 597 | if (hw->mac_type == e1000_82542_rev2_0) { |
| 598 | ew32(RCTL, 0); |
| 599 | E1000_WRITE_FLUSH(); |
| 600 | msleep(1); |
| 601 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
| 602 | e1000_pci_set_mwi(hw); |
| 603 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 605 | /* Zero out the Multicast HASH table */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 606 | e_dbg("Zeroing the MTA\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 607 | mta_size = E1000_MC_TBL_SIZE; |
| 608 | for (i = 0; i < mta_size; i++) { |
| 609 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
| 610 | /* use write flush to prevent Memory Write Block (MWB) from |
| 611 | * occurring when accessing our register space */ |
| 612 | E1000_WRITE_FLUSH(); |
| 613 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 615 | /* Set the PCI priority bit correctly in the CTRL register. This |
| 616 | * determines if the adapter gives priority to receives, or if it |
| 617 | * gives equal priority to transmits and receives. Valid only on |
| 618 | * 82542 and 82543 silicon. |
| 619 | */ |
| 620 | if (hw->dma_fairness && hw->mac_type <= e1000_82543) { |
| 621 | ctrl = er32(CTRL); |
| 622 | ew32(CTRL, ctrl | E1000_CTRL_PRIOR); |
| 623 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 625 | switch (hw->mac_type) { |
| 626 | case e1000_82545_rev_3: |
| 627 | case e1000_82546_rev_3: |
| 628 | break; |
| 629 | default: |
| 630 | /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */ |
| 631 | if (hw->bus_type == e1000_bus_type_pcix |
| 632 | && e1000_pcix_get_mmrbc(hw) > 2048) |
| 633 | e1000_pcix_set_mmrbc(hw, 2048); |
| 634 | break; |
| 635 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 637 | /* Call a subroutine to configure the link and setup flow control. */ |
| 638 | ret_val = e1000_setup_link(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 640 | /* Set the transmit descriptor write-back policy */ |
| 641 | if (hw->mac_type > e1000_82544) { |
| 642 | ctrl = er32(TXDCTL); |
| 643 | ctrl = |
| 644 | (ctrl & ~E1000_TXDCTL_WTHRESH) | |
| 645 | E1000_TXDCTL_FULL_TX_DESC_WB; |
| 646 | ew32(TXDCTL, ctrl); |
| 647 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 649 | /* Clear all of the statistics registers (clear on read). It is |
| 650 | * important that we do this after we have tried to establish link |
| 651 | * because the symbol error count will increment wildly if there |
| 652 | * is no link. |
| 653 | */ |
| 654 | e1000_clear_hw_cntrs(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 656 | if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER || |
| 657 | hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) { |
| 658 | ctrl_ext = er32(CTRL_EXT); |
| 659 | /* Relaxed ordering must be disabled to avoid a parity |
| 660 | * error crash in a PCI slot. */ |
| 661 | ctrl_ext |= E1000_CTRL_EXT_RO_DIS; |
| 662 | ew32(CTRL_EXT, ctrl_ext); |
| 663 | } |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 664 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 665 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 668 | /** |
| 669 | * e1000_adjust_serdes_amplitude - Adjust SERDES output amplitude based on EEPROM setting. |
| 670 | * @hw: Struct containing variables accessed by shared code. |
| 671 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 672 | static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 674 | u16 eeprom_data; |
| 675 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 677 | e_dbg("e1000_adjust_serdes_amplitude"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 679 | if (hw->media_type != e1000_media_type_internal_serdes) |
| 680 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 682 | switch (hw->mac_type) { |
| 683 | case e1000_82545_rev_3: |
| 684 | case e1000_82546_rev_3: |
| 685 | break; |
| 686 | default: |
| 687 | return E1000_SUCCESS; |
| 688 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 690 | ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, |
| 691 | &eeprom_data); |
| 692 | if (ret_val) { |
| 693 | return ret_val; |
| 694 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 696 | if (eeprom_data != EEPROM_RESERVED_WORD) { |
| 697 | /* Adjust SERDES output amplitude only. */ |
| 698 | eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK; |
| 699 | ret_val = |
| 700 | e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data); |
| 701 | if (ret_val) |
| 702 | return ret_val; |
| 703 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 705 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 708 | /** |
| 709 | * e1000_setup_link - Configures flow control and link settings. |
| 710 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 712 | * Determines which flow control settings to use. Calls the appropriate media- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | * specific link configuration function. Configures the flow control settings. |
| 714 | * Assuming the adapter has a valid link partner, a valid link should be |
| 715 | * established. Assumes the hardware has previously been reset and the |
| 716 | * transmitter and receiver are not enabled. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 717 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 718 | s32 e1000_setup_link(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 720 | u32 ctrl_ext; |
| 721 | s32 ret_val; |
| 722 | u16 eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 724 | e_dbg("e1000_setup_link"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 726 | /* Read and store word 0x0F of the EEPROM. This word contains bits |
| 727 | * that determine the hardware's default PAUSE (flow control) mode, |
| 728 | * a bit that determines whether the HW defaults to enabling or |
| 729 | * disabling auto-negotiation, and the direction of the |
| 730 | * SW defined pins. If there is no SW over-ride of the flow |
| 731 | * control setting, then the variable hw->fc will |
| 732 | * be initialized based on a value in the EEPROM. |
| 733 | */ |
| 734 | if (hw->fc == E1000_FC_DEFAULT) { |
| 735 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, |
| 736 | 1, &eeprom_data); |
| 737 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 738 | e_dbg("EEPROM Read Error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 739 | return -E1000_ERR_EEPROM; |
| 740 | } |
| 741 | if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0) |
| 742 | hw->fc = E1000_FC_NONE; |
| 743 | else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == |
| 744 | EEPROM_WORD0F_ASM_DIR) |
| 745 | hw->fc = E1000_FC_TX_PAUSE; |
| 746 | else |
| 747 | hw->fc = E1000_FC_FULL; |
| 748 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 750 | /* We want to save off the original Flow Control configuration just |
| 751 | * in case we get disconnected and then reconnected into a different |
| 752 | * hub or switch with different Flow Control capabilities. |
| 753 | */ |
| 754 | if (hw->mac_type == e1000_82542_rev2_0) |
| 755 | hw->fc &= (~E1000_FC_TX_PAUSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 757 | if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1)) |
| 758 | hw->fc &= (~E1000_FC_RX_PAUSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 760 | hw->original_fc = hw->fc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 762 | e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 764 | /* Take the 4 bits from EEPROM word 0x0F that determine the initial |
| 765 | * polarity value for the SW controlled pins, and setup the |
| 766 | * Extended Device Control reg with that info. |
| 767 | * This is needed because one of the SW controlled pins is used for |
| 768 | * signal detection. So this should be done before e1000_setup_pcs_link() |
| 769 | * or e1000_phy_setup() is called. |
| 770 | */ |
| 771 | if (hw->mac_type == e1000_82543) { |
| 772 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, |
| 773 | 1, &eeprom_data); |
| 774 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 775 | e_dbg("EEPROM Read Error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 776 | return -E1000_ERR_EEPROM; |
| 777 | } |
| 778 | ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) << |
| 779 | SWDPIO__EXT_SHIFT); |
| 780 | ew32(CTRL_EXT, ctrl_ext); |
| 781 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 783 | /* Call the necessary subroutine to configure the link. */ |
| 784 | ret_val = (hw->media_type == e1000_media_type_copper) ? |
| 785 | e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 787 | /* Initialize the flow control address, type, and PAUSE timer |
| 788 | * registers to their default values. This is done even if flow |
| 789 | * control is disabled, because it does not hurt anything to |
| 790 | * initialize these registers. |
| 791 | */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 792 | e_dbg("Initializing the Flow Control address, type and timer regs\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 794 | ew32(FCT, FLOW_CONTROL_TYPE); |
| 795 | ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH); |
| 796 | ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 797 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 798 | ew32(FCTTV, hw->fc_pause_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 800 | /* Set the flow control receive threshold registers. Normally, |
| 801 | * these registers will be set to a default threshold that may be |
| 802 | * adjusted later by the driver's runtime code. However, if the |
| 803 | * ability to transmit pause frames in not enabled, then these |
| 804 | * registers will be set to 0. |
| 805 | */ |
| 806 | if (!(hw->fc & E1000_FC_TX_PAUSE)) { |
| 807 | ew32(FCRTL, 0); |
| 808 | ew32(FCRTH, 0); |
| 809 | } else { |
| 810 | /* We need to set up the Receive Threshold high and low water marks |
| 811 | * as well as (optionally) enabling the transmission of XON frames. |
| 812 | */ |
| 813 | if (hw->fc_send_xon) { |
| 814 | ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE)); |
| 815 | ew32(FCRTH, hw->fc_high_water); |
| 816 | } else { |
| 817 | ew32(FCRTL, hw->fc_low_water); |
| 818 | ew32(FCRTH, hw->fc_high_water); |
| 819 | } |
| 820 | } |
| 821 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 824 | /** |
| 825 | * e1000_setup_fiber_serdes_link - prepare fiber or serdes link |
| 826 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | * |
| 828 | * Manipulates Physical Coding Sublayer functions in order to configure |
| 829 | * link. Assumes the hardware has been previously reset and the transmitter |
| 830 | * and receiver are not enabled. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 831 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 832 | static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 834 | u32 ctrl; |
| 835 | u32 status; |
| 836 | u32 txcw = 0; |
| 837 | u32 i; |
| 838 | u32 signal = 0; |
| 839 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 841 | e_dbg("e1000_setup_fiber_serdes_link"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 843 | /* On adapters with a MAC newer than 82544, SWDP 1 will be |
| 844 | * set when the optics detect a signal. On older adapters, it will be |
| 845 | * cleared when there is a signal. This applies to fiber media only. |
| 846 | * If we're on serdes media, adjust the output amplitude to value |
| 847 | * set in the EEPROM. |
| 848 | */ |
| 849 | ctrl = er32(CTRL); |
| 850 | if (hw->media_type == e1000_media_type_fiber) |
| 851 | signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 853 | ret_val = e1000_adjust_serdes_amplitude(hw); |
| 854 | if (ret_val) |
| 855 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 857 | /* Take the link out of reset */ |
| 858 | ctrl &= ~(E1000_CTRL_LRST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 860 | /* Adjust VCO speed to improve BER performance */ |
| 861 | ret_val = e1000_set_vco_speed(hw); |
| 862 | if (ret_val) |
| 863 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 865 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 867 | /* Check for a software override of the flow control settings, and setup |
| 868 | * the device accordingly. If auto-negotiation is enabled, then software |
| 869 | * will have to set the "PAUSE" bits to the correct value in the Tranmsit |
| 870 | * Config Word Register (TXCW) and re-start auto-negotiation. However, if |
| 871 | * auto-negotiation is disabled, then software will have to manually |
| 872 | * configure the two flow control enable bits in the CTRL register. |
| 873 | * |
| 874 | * The possible values of the "fc" parameter are: |
| 875 | * 0: Flow control is completely disabled |
| 876 | * 1: Rx flow control is enabled (we can receive pause frames, but |
| 877 | * not send pause frames). |
| 878 | * 2: Tx flow control is enabled (we can send pause frames but we do |
| 879 | * not support receiving pause frames). |
| 880 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
| 881 | */ |
| 882 | switch (hw->fc) { |
| 883 | case E1000_FC_NONE: |
| 884 | /* Flow control is completely disabled by a software over-ride. */ |
| 885 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); |
| 886 | break; |
| 887 | case E1000_FC_RX_PAUSE: |
| 888 | /* RX Flow control is enabled and TX Flow control is disabled by a |
| 889 | * software over-ride. Since there really isn't a way to advertise |
| 890 | * that we are capable of RX Pause ONLY, we will advertise that we |
| 891 | * support both symmetric and asymmetric RX PAUSE. Later, we will |
| 892 | * disable the adapter's ability to send PAUSE frames. |
| 893 | */ |
| 894 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 895 | break; |
| 896 | case E1000_FC_TX_PAUSE: |
| 897 | /* TX Flow control is enabled, and RX Flow control is disabled, by a |
| 898 | * software over-ride. |
| 899 | */ |
| 900 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); |
| 901 | break; |
| 902 | case E1000_FC_FULL: |
| 903 | /* Flow control (both RX and TX) is enabled by a software over-ride. */ |
| 904 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 905 | break; |
| 906 | default: |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 907 | e_dbg("Flow control param set incorrectly\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 908 | return -E1000_ERR_CONFIG; |
| 909 | break; |
| 910 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 912 | /* Since auto-negotiation is enabled, take the link out of reset (the link |
| 913 | * will be in reset, because we previously reset the chip). This will |
| 914 | * restart auto-negotiation. If auto-negotiation is successful then the |
| 915 | * link-up status bit will be set and the flow control enable bits (RFCE |
| 916 | * and TFCE) will be set according to their negotiated value. |
| 917 | */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 918 | e_dbg("Auto-negotiation enabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 920 | ew32(TXCW, txcw); |
| 921 | ew32(CTRL, ctrl); |
| 922 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 924 | hw->txcw = txcw; |
| 925 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 927 | /* If we have a signal (the cable is plugged in) then poll for a "Link-Up" |
| 928 | * indication in the Device Status Register. Time-out if a link isn't |
| 929 | * seen in 500 milliseconds seconds (Auto-negotiation should complete in |
| 930 | * less than 500 milliseconds even if the other end is doing it in SW). |
| 931 | * For internal serdes, we just assume a signal is present, then poll. |
| 932 | */ |
| 933 | if (hw->media_type == e1000_media_type_internal_serdes || |
| 934 | (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 935 | e_dbg("Looking for Link\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 936 | for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) { |
| 937 | msleep(10); |
| 938 | status = er32(STATUS); |
| 939 | if (status & E1000_STATUS_LU) |
| 940 | break; |
| 941 | } |
| 942 | if (i == (LINK_UP_TIMEOUT / 10)) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 943 | e_dbg("Never got a valid link from auto-neg!!!\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 944 | hw->autoneg_failed = 1; |
| 945 | /* AutoNeg failed to achieve a link, so we'll call |
| 946 | * e1000_check_for_link. This routine will force the link up if |
| 947 | * we detect a signal. This will allow us to communicate with |
| 948 | * non-autonegotiating link partners. |
| 949 | */ |
| 950 | ret_val = e1000_check_for_link(hw); |
| 951 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 952 | e_dbg("Error while checking for link\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 953 | return ret_val; |
| 954 | } |
| 955 | hw->autoneg_failed = 0; |
| 956 | } else { |
| 957 | hw->autoneg_failed = 0; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 958 | e_dbg("Valid Link Found\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 959 | } |
| 960 | } else { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 961 | e_dbg("No Signal Detected\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 962 | } |
| 963 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | } |
| 965 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 966 | /** |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 967 | * e1000_copper_link_rtl_setup - Copper link setup for e1000_phy_rtl series. |
| 968 | * @hw: Struct containing variables accessed by shared code |
| 969 | * |
| 970 | * Commits changes to PHY configuration by calling e1000_phy_reset(). |
| 971 | */ |
| 972 | static s32 e1000_copper_link_rtl_setup(struct e1000_hw *hw) |
| 973 | { |
| 974 | s32 ret_val; |
| 975 | |
| 976 | /* SW reset the PHY so all changes take effect */ |
| 977 | ret_val = e1000_phy_reset(hw); |
| 978 | if (ret_val) { |
| 979 | e_dbg("Error Resetting the PHY\n"); |
| 980 | return ret_val; |
| 981 | } |
| 982 | |
| 983 | return E1000_SUCCESS; |
| 984 | } |
| 985 | |
| 986 | static s32 gbe_dhg_phy_setup(struct e1000_hw *hw) |
| 987 | { |
| 988 | s32 ret_val; |
| 989 | u32 ctrl_aux; |
| 990 | |
| 991 | switch (hw->phy_type) { |
| 992 | case e1000_phy_8211: |
| 993 | ret_val = e1000_copper_link_rtl_setup(hw); |
| 994 | if (ret_val) { |
| 995 | e_dbg("e1000_copper_link_rtl_setup failed!\n"); |
| 996 | return ret_val; |
| 997 | } |
| 998 | break; |
| 999 | case e1000_phy_8201: |
| 1000 | /* Set RMII mode */ |
| 1001 | ctrl_aux = er32(CTL_AUX); |
| 1002 | ctrl_aux |= E1000_CTL_AUX_RMII; |
| 1003 | ew32(CTL_AUX, ctrl_aux); |
| 1004 | E1000_WRITE_FLUSH(); |
| 1005 | |
| 1006 | /* Disable the J/K bits required for receive */ |
| 1007 | ctrl_aux = er32(CTL_AUX); |
| 1008 | ctrl_aux |= 0x4; |
| 1009 | ctrl_aux &= ~0x2; |
| 1010 | ew32(CTL_AUX, ctrl_aux); |
| 1011 | E1000_WRITE_FLUSH(); |
| 1012 | ret_val = e1000_copper_link_rtl_setup(hw); |
| 1013 | |
| 1014 | if (ret_val) { |
| 1015 | e_dbg("e1000_copper_link_rtl_setup failed!\n"); |
| 1016 | return ret_val; |
| 1017 | } |
| 1018 | break; |
| 1019 | default: |
| 1020 | e_dbg("Error Resetting the PHY\n"); |
| 1021 | return E1000_ERR_PHY_TYPE; |
| 1022 | } |
| 1023 | |
| 1024 | return E1000_SUCCESS; |
| 1025 | } |
| 1026 | |
| 1027 | /** |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1028 | * e1000_copper_link_preconfig - early configuration for copper |
| 1029 | * @hw: Struct containing variables accessed by shared code |
| 1030 | * |
| 1031 | * Make sure we have a valid PHY and change PHY mode before link setup. |
| 1032 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1033 | static s32 e1000_copper_link_preconfig(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1035 | u32 ctrl; |
| 1036 | s32 ret_val; |
| 1037 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1039 | e_dbg("e1000_copper_link_preconfig"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1041 | ctrl = er32(CTRL); |
| 1042 | /* With 82543, we need to force speed and duplex on the MAC equal to what |
| 1043 | * the PHY speed and duplex configuration is. In addition, we need to |
| 1044 | * perform a hardware reset on the PHY to take it out of reset. |
| 1045 | */ |
| 1046 | if (hw->mac_type > e1000_82543) { |
| 1047 | ctrl |= E1000_CTRL_SLU; |
| 1048 | ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 1049 | ew32(CTRL, ctrl); |
| 1050 | } else { |
| 1051 | ctrl |= |
| 1052 | (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU); |
| 1053 | ew32(CTRL, ctrl); |
| 1054 | ret_val = e1000_phy_hw_reset(hw); |
| 1055 | if (ret_val) |
| 1056 | return ret_val; |
| 1057 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1059 | /* Make sure we have a valid PHY */ |
| 1060 | ret_val = e1000_detect_gig_phy(hw); |
| 1061 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1062 | e_dbg("Error, did not detect valid phy.\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1063 | return ret_val; |
| 1064 | } |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1065 | e_dbg("Phy ID = %x\n", hw->phy_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1067 | /* Set PHY to class A mode (if necessary) */ |
| 1068 | ret_val = e1000_set_phy_mode(hw); |
| 1069 | if (ret_val) |
| 1070 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1072 | if ((hw->mac_type == e1000_82545_rev_3) || |
| 1073 | (hw->mac_type == e1000_82546_rev_3)) { |
| 1074 | ret_val = |
| 1075 | e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 1076 | phy_data |= 0x00000008; |
| 1077 | ret_val = |
| 1078 | e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 1079 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1081 | if (hw->mac_type <= e1000_82543 || |
| 1082 | hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 || |
| 1083 | hw->mac_type == e1000_82541_rev_2 |
| 1084 | || hw->mac_type == e1000_82547_rev_2) |
| 1085 | hw->phy_reset_disable = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1087 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1088 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1090 | /** |
| 1091 | * e1000_copper_link_igp_setup - Copper link setup for e1000_phy_igp series. |
| 1092 | * @hw: Struct containing variables accessed by shared code |
| 1093 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1094 | static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1095 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1096 | u32 led_ctrl; |
| 1097 | s32 ret_val; |
| 1098 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1100 | e_dbg("e1000_copper_link_igp_setup"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1102 | if (hw->phy_reset_disable) |
| 1103 | return E1000_SUCCESS; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1104 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1105 | ret_val = e1000_phy_reset(hw); |
| 1106 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1107 | e_dbg("Error Resetting the PHY\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1108 | return ret_val; |
| 1109 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1111 | /* Wait 15ms for MAC to configure PHY from eeprom settings */ |
| 1112 | msleep(15); |
| 1113 | /* Configure activity LED after PHY reset */ |
| 1114 | led_ctrl = er32(LEDCTL); |
| 1115 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 1116 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 1117 | ew32(LEDCTL, led_ctrl); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1118 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1119 | /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */ |
| 1120 | if (hw->phy_type == e1000_phy_igp) { |
| 1121 | /* disable lplu d3 during driver init */ |
| 1122 | ret_val = e1000_set_d3_lplu_state(hw, false); |
| 1123 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1124 | e_dbg("Error Disabling LPLU D3\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1125 | return ret_val; |
| 1126 | } |
| 1127 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1128 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1129 | /* Configure mdi-mdix settings */ |
| 1130 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); |
| 1131 | if (ret_val) |
| 1132 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1133 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1134 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 1135 | hw->dsp_config_state = e1000_dsp_config_disabled; |
| 1136 | /* Force MDI for earlier revs of the IGP PHY */ |
| 1137 | phy_data &= |
| 1138 | ~(IGP01E1000_PSCR_AUTO_MDIX | |
| 1139 | IGP01E1000_PSCR_FORCE_MDI_MDIX); |
| 1140 | hw->mdix = 1; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1141 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1142 | } else { |
| 1143 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 1144 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1145 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1146 | switch (hw->mdix) { |
| 1147 | case 1: |
| 1148 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 1149 | break; |
| 1150 | case 2: |
| 1151 | phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 1152 | break; |
| 1153 | case 0: |
| 1154 | default: |
| 1155 | phy_data |= IGP01E1000_PSCR_AUTO_MDIX; |
| 1156 | break; |
| 1157 | } |
| 1158 | } |
| 1159 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); |
| 1160 | if (ret_val) |
| 1161 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1162 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1163 | /* set auto-master slave resolution settings */ |
| 1164 | if (hw->autoneg) { |
| 1165 | e1000_ms_type phy_ms_setting = hw->master_slave; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1166 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1167 | if (hw->ffe_config_state == e1000_ffe_config_active) |
| 1168 | hw->ffe_config_state = e1000_ffe_config_enabled; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1169 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1170 | if (hw->dsp_config_state == e1000_dsp_config_activated) |
| 1171 | hw->dsp_config_state = e1000_dsp_config_enabled; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1172 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1173 | /* when autonegotiation advertisement is only 1000Mbps then we |
| 1174 | * should disable SmartSpeed and enable Auto MasterSlave |
| 1175 | * resolution as hardware default. */ |
| 1176 | if (hw->autoneg_advertised == ADVERTISE_1000_FULL) { |
| 1177 | /* Disable SmartSpeed */ |
| 1178 | ret_val = |
| 1179 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 1180 | &phy_data); |
| 1181 | if (ret_val) |
| 1182 | return ret_val; |
| 1183 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 1184 | ret_val = |
| 1185 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 1186 | phy_data); |
| 1187 | if (ret_val) |
| 1188 | return ret_val; |
| 1189 | /* Set auto Master/Slave resolution process */ |
| 1190 | ret_val = |
| 1191 | e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); |
| 1192 | if (ret_val) |
| 1193 | return ret_val; |
| 1194 | phy_data &= ~CR_1000T_MS_ENABLE; |
| 1195 | ret_val = |
| 1196 | e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); |
| 1197 | if (ret_val) |
| 1198 | return ret_val; |
| 1199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1201 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); |
| 1202 | if (ret_val) |
| 1203 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1205 | /* load defaults for future use */ |
| 1206 | hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ? |
| 1207 | ((phy_data & CR_1000T_MS_VALUE) ? |
| 1208 | e1000_ms_force_master : |
| 1209 | e1000_ms_force_slave) : e1000_ms_auto; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1211 | switch (phy_ms_setting) { |
| 1212 | case e1000_ms_force_master: |
| 1213 | phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE); |
| 1214 | break; |
| 1215 | case e1000_ms_force_slave: |
| 1216 | phy_data |= CR_1000T_MS_ENABLE; |
| 1217 | phy_data &= ~(CR_1000T_MS_VALUE); |
| 1218 | break; |
| 1219 | case e1000_ms_auto: |
| 1220 | phy_data &= ~CR_1000T_MS_ENABLE; |
| 1221 | default: |
| 1222 | break; |
| 1223 | } |
| 1224 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); |
| 1225 | if (ret_val) |
| 1226 | return ret_val; |
| 1227 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1229 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1230 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1232 | /** |
| 1233 | * e1000_copper_link_mgp_setup - Copper link setup for e1000_phy_m88 series. |
| 1234 | * @hw: Struct containing variables accessed by shared code |
| 1235 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1236 | static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1237 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1238 | s32 ret_val; |
| 1239 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1241 | e_dbg("e1000_copper_link_mgp_setup"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1242 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1243 | if (hw->phy_reset_disable) |
| 1244 | return E1000_SUCCESS; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1245 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1246 | /* Enable CRS on TX. This must be set for half-duplex operation. */ |
| 1247 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 1248 | if (ret_val) |
| 1249 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1250 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1251 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1252 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1253 | /* Options: |
| 1254 | * MDI/MDI-X = 0 (default) |
| 1255 | * 0 - Auto for all speeds |
| 1256 | * 1 - MDI mode |
| 1257 | * 2 - MDI-X mode |
| 1258 | * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) |
| 1259 | */ |
| 1260 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1261 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1262 | switch (hw->mdix) { |
| 1263 | case 1: |
| 1264 | phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE; |
| 1265 | break; |
| 1266 | case 2: |
| 1267 | phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE; |
| 1268 | break; |
| 1269 | case 3: |
| 1270 | phy_data |= M88E1000_PSCR_AUTO_X_1000T; |
| 1271 | break; |
| 1272 | case 0: |
| 1273 | default: |
| 1274 | phy_data |= M88E1000_PSCR_AUTO_X_MODE; |
| 1275 | break; |
| 1276 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1277 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1278 | /* Options: |
| 1279 | * disable_polarity_correction = 0 (default) |
| 1280 | * Automatic Correction for Reversed Cable Polarity |
| 1281 | * 0 - Disabled |
| 1282 | * 1 - Enabled |
| 1283 | */ |
| 1284 | phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL; |
| 1285 | if (hw->disable_polarity_correction == 1) |
| 1286 | phy_data |= M88E1000_PSCR_POLARITY_REVERSAL; |
| 1287 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 1288 | if (ret_val) |
| 1289 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1290 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1291 | if (hw->phy_revision < M88E1011_I_REV_4) { |
| 1292 | /* Force TX_CLK in the Extended PHY Specific Control Register |
| 1293 | * to 25MHz clock. |
| 1294 | */ |
| 1295 | ret_val = |
| 1296 | e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, |
| 1297 | &phy_data); |
| 1298 | if (ret_val) |
| 1299 | return ret_val; |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1300 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1301 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1302 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1303 | if ((hw->phy_revision == E1000_REVISION_2) && |
| 1304 | (hw->phy_id == M88E1111_I_PHY_ID)) { |
| 1305 | /* Vidalia Phy, set the downshift counter to 5x */ |
| 1306 | phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK); |
| 1307 | phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X; |
| 1308 | ret_val = e1000_write_phy_reg(hw, |
| 1309 | M88E1000_EXT_PHY_SPEC_CTRL, |
| 1310 | phy_data); |
| 1311 | if (ret_val) |
| 1312 | return ret_val; |
| 1313 | } else { |
| 1314 | /* Configure Master and Slave downshift values */ |
| 1315 | phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK | |
| 1316 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK); |
| 1317 | phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X | |
| 1318 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X); |
| 1319 | ret_val = e1000_write_phy_reg(hw, |
| 1320 | M88E1000_EXT_PHY_SPEC_CTRL, |
| 1321 | phy_data); |
| 1322 | if (ret_val) |
| 1323 | return ret_val; |
| 1324 | } |
| 1325 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1327 | /* SW Reset the PHY so all changes take effect */ |
| 1328 | ret_val = e1000_phy_reset(hw); |
| 1329 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1330 | e_dbg("Error Resetting the PHY\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1331 | return ret_val; |
| 1332 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1333 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1334 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1335 | } |
| 1336 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1337 | /** |
| 1338 | * e1000_copper_link_autoneg - setup auto-neg |
| 1339 | * @hw: Struct containing variables accessed by shared code |
| 1340 | * |
| 1341 | * Setup auto-negotiation and flow control advertisements, |
| 1342 | * and then perform auto-negotiation. |
| 1343 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1344 | static s32 e1000_copper_link_autoneg(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1345 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1346 | s32 ret_val; |
| 1347 | u16 phy_data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1348 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1349 | e_dbg("e1000_copper_link_autoneg"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1350 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1351 | /* Perform some bounds checking on the hw->autoneg_advertised |
| 1352 | * parameter. If this variable is zero, then set it to the default. |
| 1353 | */ |
| 1354 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1355 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1356 | /* If autoneg_advertised is zero, we assume it was not defaulted |
| 1357 | * by the calling code so we set to advertise full capability. |
| 1358 | */ |
| 1359 | if (hw->autoneg_advertised == 0) |
| 1360 | hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1361 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1362 | /* IFE/RTL8201N PHY only supports 10/100 */ |
| 1363 | if (hw->phy_type == e1000_phy_8201) |
| 1364 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL; |
| 1365 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1366 | e_dbg("Reconfiguring auto-neg advertisement params\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1367 | ret_val = e1000_phy_setup_autoneg(hw); |
| 1368 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1369 | e_dbg("Error Setting up Auto-Negotiation\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1370 | return ret_val; |
| 1371 | } |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1372 | e_dbg("Restarting Auto-Neg\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1373 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1374 | /* Restart auto-negotiation by setting the Auto Neg Enable bit and |
| 1375 | * the Auto Neg Restart bit in the PHY control register. |
| 1376 | */ |
| 1377 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
| 1378 | if (ret_val) |
| 1379 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1380 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1381 | phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); |
| 1382 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); |
| 1383 | if (ret_val) |
| 1384 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1385 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1386 | /* Does the user want to wait for Auto-Neg to complete here, or |
| 1387 | * check at a later time (for example, callback routine). |
| 1388 | */ |
| 1389 | if (hw->wait_autoneg_complete) { |
| 1390 | ret_val = e1000_wait_autoneg(hw); |
| 1391 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1392 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1393 | ("Error while waiting for autoneg to complete\n"); |
| 1394 | return ret_val; |
| 1395 | } |
| 1396 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1398 | hw->get_link_status = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1400 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1401 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1403 | /** |
| 1404 | * e1000_copper_link_postconfig - post link setup |
| 1405 | * @hw: Struct containing variables accessed by shared code |
| 1406 | * |
| 1407 | * Config the MAC and the PHY after link is up. |
| 1408 | * 1) Set up the MAC to the current PHY speed/duplex |
| 1409 | * if we are on 82543. If we |
| 1410 | * are on newer silicon, we only need to configure |
| 1411 | * collision distance in the Transmit Control Register. |
| 1412 | * 2) Set up flow control on the MAC to that established with |
| 1413 | * the link partner. |
| 1414 | * 3) Config DSP to improve Gigabit link quality for some PHY revisions. |
| 1415 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1416 | static s32 e1000_copper_link_postconfig(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1417 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1418 | s32 ret_val; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1419 | e_dbg("e1000_copper_link_postconfig"); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1420 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1421 | if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100)) { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1422 | e1000_config_collision_dist(hw); |
| 1423 | } else { |
| 1424 | ret_val = e1000_config_mac_to_phy(hw); |
| 1425 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1426 | e_dbg("Error configuring MAC to PHY settings\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1427 | return ret_val; |
| 1428 | } |
| 1429 | } |
| 1430 | ret_val = e1000_config_fc_after_link_up(hw); |
| 1431 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1432 | e_dbg("Error Configuring Flow Control\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1433 | return ret_val; |
| 1434 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1435 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1436 | /* Config DSP to improve Giga link quality */ |
| 1437 | if (hw->phy_type == e1000_phy_igp) { |
| 1438 | ret_val = e1000_config_dsp_after_link_change(hw, true); |
| 1439 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1440 | e_dbg("Error Configuring DSP after link up\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1441 | return ret_val; |
| 1442 | } |
| 1443 | } |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1444 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1445 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1448 | /** |
| 1449 | * e1000_setup_copper_link - phy/speed/duplex setting |
| 1450 | * @hw: Struct containing variables accessed by shared code |
| 1451 | * |
| 1452 | * Detects which PHY is present and sets up the speed and duplex |
| 1453 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1454 | static s32 e1000_setup_copper_link(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1455 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1456 | s32 ret_val; |
| 1457 | u16 i; |
| 1458 | u16 phy_data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1459 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1460 | e_dbg("e1000_setup_copper_link"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1461 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1462 | /* Check if it is a valid PHY and set PHY mode if necessary. */ |
| 1463 | ret_val = e1000_copper_link_preconfig(hw); |
| 1464 | if (ret_val) |
| 1465 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1466 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1467 | if (hw->phy_type == e1000_phy_igp) { |
| 1468 | ret_val = e1000_copper_link_igp_setup(hw); |
| 1469 | if (ret_val) |
| 1470 | return ret_val; |
| 1471 | } else if (hw->phy_type == e1000_phy_m88) { |
| 1472 | ret_val = e1000_copper_link_mgp_setup(hw); |
| 1473 | if (ret_val) |
| 1474 | return ret_val; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1475 | } else { |
| 1476 | ret_val = gbe_dhg_phy_setup(hw); |
| 1477 | if (ret_val) { |
| 1478 | e_dbg("gbe_dhg_phy_setup failed!\n"); |
| 1479 | return ret_val; |
| 1480 | } |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1481 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1482 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1483 | if (hw->autoneg) { |
| 1484 | /* Setup autoneg and flow control advertisement |
| 1485 | * and perform autonegotiation */ |
| 1486 | ret_val = e1000_copper_link_autoneg(hw); |
| 1487 | if (ret_val) |
| 1488 | return ret_val; |
| 1489 | } else { |
| 1490 | /* PHY will be set to 10H, 10F, 100H,or 100F |
| 1491 | * depending on value from forced_speed_duplex. */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1492 | e_dbg("Forcing speed and duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1493 | ret_val = e1000_phy_force_speed_duplex(hw); |
| 1494 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1495 | e_dbg("Error Forcing Speed and Duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1496 | return ret_val; |
| 1497 | } |
| 1498 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1500 | /* Check link status. Wait up to 100 microseconds for link to become |
| 1501 | * valid. |
| 1502 | */ |
| 1503 | for (i = 0; i < 10; i++) { |
| 1504 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 1505 | if (ret_val) |
| 1506 | return ret_val; |
| 1507 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 1508 | if (ret_val) |
| 1509 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1511 | if (phy_data & MII_SR_LINK_STATUS) { |
| 1512 | /* Config the MAC and PHY after link is up */ |
| 1513 | ret_val = e1000_copper_link_postconfig(hw); |
| 1514 | if (ret_val) |
| 1515 | return ret_val; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1516 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1517 | e_dbg("Valid link established!!!\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1518 | return E1000_SUCCESS; |
| 1519 | } |
| 1520 | udelay(10); |
| 1521 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1523 | e_dbg("Unable to establish link!!!\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1524 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1527 | /** |
| 1528 | * e1000_phy_setup_autoneg - phy settings |
| 1529 | * @hw: Struct containing variables accessed by shared code |
| 1530 | * |
| 1531 | * Configures PHY autoneg and flow control advertisement settings |
| 1532 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1533 | s32 e1000_phy_setup_autoneg(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1535 | s32 ret_val; |
| 1536 | u16 mii_autoneg_adv_reg; |
| 1537 | u16 mii_1000t_ctrl_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1539 | e_dbg("e1000_phy_setup_autoneg"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1541 | /* Read the MII Auto-Neg Advertisement Register (Address 4). */ |
| 1542 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg); |
| 1543 | if (ret_val) |
| 1544 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1546 | /* Read the MII 1000Base-T Control Register (Address 9). */ |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1547 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1548 | if (ret_val) |
| 1549 | return ret_val; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1550 | else if (hw->phy_type == e1000_phy_8201) |
| 1551 | mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1553 | /* Need to parse both autoneg_advertised and fc and set up |
| 1554 | * the appropriate PHY registers. First we will parse for |
| 1555 | * autoneg_advertised software override. Since we can advertise |
| 1556 | * a plethora of combinations, we need to check each bit |
| 1557 | * individually. |
| 1558 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1560 | /* First we clear all the 10/100 mb speed bits in the Auto-Neg |
| 1561 | * Advertisement Register (Address 4) and the 1000 mb speed bits in |
| 1562 | * the 1000Base-T Control Register (Address 9). |
| 1563 | */ |
| 1564 | mii_autoneg_adv_reg &= ~REG4_SPEED_MASK; |
| 1565 | mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1567 | e_dbg("autoneg_advertised %x\n", hw->autoneg_advertised); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1569 | /* Do we want to advertise 10 Mb Half Duplex? */ |
| 1570 | if (hw->autoneg_advertised & ADVERTISE_10_HALF) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1571 | e_dbg("Advertise 10mb Half duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1572 | mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS; |
| 1573 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1575 | /* Do we want to advertise 10 Mb Full Duplex? */ |
| 1576 | if (hw->autoneg_advertised & ADVERTISE_10_FULL) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1577 | e_dbg("Advertise 10mb Full duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1578 | mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS; |
| 1579 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1581 | /* Do we want to advertise 100 Mb Half Duplex? */ |
| 1582 | if (hw->autoneg_advertised & ADVERTISE_100_HALF) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1583 | e_dbg("Advertise 100mb Half duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1584 | mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS; |
| 1585 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1587 | /* Do we want to advertise 100 Mb Full Duplex? */ |
| 1588 | if (hw->autoneg_advertised & ADVERTISE_100_FULL) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1589 | e_dbg("Advertise 100mb Full duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1590 | mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS; |
| 1591 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1593 | /* We do not allow the Phy to advertise 1000 Mb Half Duplex */ |
| 1594 | if (hw->autoneg_advertised & ADVERTISE_1000_HALF) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1595 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1596 | ("Advertise 1000mb Half duplex requested, request denied!\n"); |
| 1597 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1599 | /* Do we want to advertise 1000 Mb Full Duplex? */ |
| 1600 | if (hw->autoneg_advertised & ADVERTISE_1000_FULL) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1601 | e_dbg("Advertise 1000mb Full duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1602 | mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS; |
| 1603 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1605 | /* Check for a software override of the flow control settings, and |
| 1606 | * setup the PHY advertisement registers accordingly. If |
| 1607 | * auto-negotiation is enabled, then software will have to set the |
| 1608 | * "PAUSE" bits to the correct value in the Auto-Negotiation |
| 1609 | * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation. |
| 1610 | * |
| 1611 | * The possible values of the "fc" parameter are: |
| 1612 | * 0: Flow control is completely disabled |
| 1613 | * 1: Rx flow control is enabled (we can receive pause frames |
| 1614 | * but not send pause frames). |
| 1615 | * 2: Tx flow control is enabled (we can send pause frames |
| 1616 | * but we do not support receiving pause frames). |
| 1617 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
| 1618 | * other: No software override. The flow control configuration |
| 1619 | * in the EEPROM is used. |
| 1620 | */ |
| 1621 | switch (hw->fc) { |
| 1622 | case E1000_FC_NONE: /* 0 */ |
| 1623 | /* Flow control (RX & TX) is completely disabled by a |
| 1624 | * software over-ride. |
| 1625 | */ |
| 1626 | mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 1627 | break; |
| 1628 | case E1000_FC_RX_PAUSE: /* 1 */ |
| 1629 | /* RX Flow control is enabled, and TX Flow control is |
| 1630 | * disabled, by a software over-ride. |
| 1631 | */ |
| 1632 | /* Since there really isn't a way to advertise that we are |
| 1633 | * capable of RX Pause ONLY, we will advertise that we |
| 1634 | * support both symmetric and asymmetric RX PAUSE. Later |
| 1635 | * (in e1000_config_fc_after_link_up) we will disable the |
| 1636 | *hw's ability to send PAUSE frames. |
| 1637 | */ |
| 1638 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 1639 | break; |
| 1640 | case E1000_FC_TX_PAUSE: /* 2 */ |
| 1641 | /* TX Flow control is enabled, and RX Flow control is |
| 1642 | * disabled, by a software over-ride. |
| 1643 | */ |
| 1644 | mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR; |
| 1645 | mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE; |
| 1646 | break; |
| 1647 | case E1000_FC_FULL: /* 3 */ |
| 1648 | /* Flow control (both RX and TX) is enabled by a software |
| 1649 | * over-ride. |
| 1650 | */ |
| 1651 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 1652 | break; |
| 1653 | default: |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1654 | e_dbg("Flow control param set incorrectly\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1655 | return -E1000_ERR_CONFIG; |
| 1656 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1658 | ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg); |
| 1659 | if (ret_val) |
| 1660 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1662 | e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1664 | if (hw->phy_type == e1000_phy_8201) { |
| 1665 | mii_1000t_ctrl_reg = 0; |
| 1666 | } else { |
| 1667 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, |
| 1668 | mii_1000t_ctrl_reg); |
| 1669 | if (ret_val) |
| 1670 | return ret_val; |
| 1671 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1673 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1676 | /** |
| 1677 | * e1000_phy_force_speed_duplex - force link settings |
| 1678 | * @hw: Struct containing variables accessed by shared code |
| 1679 | * |
| 1680 | * Force PHY speed and duplex settings to hw->forced_speed_duplex |
| 1681 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1682 | static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1684 | u32 ctrl; |
| 1685 | s32 ret_val; |
| 1686 | u16 mii_ctrl_reg; |
| 1687 | u16 mii_status_reg; |
| 1688 | u16 phy_data; |
| 1689 | u16 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1691 | e_dbg("e1000_phy_force_speed_duplex"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1693 | /* Turn off Flow control if we are forcing speed and duplex. */ |
| 1694 | hw->fc = E1000_FC_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1696 | e_dbg("hw->fc = %d\n", hw->fc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1698 | /* Read the Device Control Register. */ |
| 1699 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1701 | /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */ |
| 1702 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 1703 | ctrl &= ~(DEVICE_SPEED_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1705 | /* Clear the Auto Speed Detect Enable bit. */ |
| 1706 | ctrl &= ~E1000_CTRL_ASDE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1708 | /* Read the MII Control Register. */ |
| 1709 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg); |
| 1710 | if (ret_val) |
| 1711 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1713 | /* We need to disable autoneg in order to force link and duplex. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1715 | mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1717 | /* Are we forcing Full or Half Duplex? */ |
| 1718 | if (hw->forced_speed_duplex == e1000_100_full || |
| 1719 | hw->forced_speed_duplex == e1000_10_full) { |
| 1720 | /* We want to force full duplex so we SET the full duplex bits in the |
| 1721 | * Device and MII Control Registers. |
| 1722 | */ |
| 1723 | ctrl |= E1000_CTRL_FD; |
| 1724 | mii_ctrl_reg |= MII_CR_FULL_DUPLEX; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1725 | e_dbg("Full Duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1726 | } else { |
| 1727 | /* We want to force half duplex so we CLEAR the full duplex bits in |
| 1728 | * the Device and MII Control Registers. |
| 1729 | */ |
| 1730 | ctrl &= ~E1000_CTRL_FD; |
| 1731 | mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1732 | e_dbg("Half Duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1733 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1735 | /* Are we forcing 100Mbps??? */ |
| 1736 | if (hw->forced_speed_duplex == e1000_100_full || |
| 1737 | hw->forced_speed_duplex == e1000_100_half) { |
| 1738 | /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */ |
| 1739 | ctrl |= E1000_CTRL_SPD_100; |
| 1740 | mii_ctrl_reg |= MII_CR_SPEED_100; |
| 1741 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10); |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1742 | e_dbg("Forcing 100mb "); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1743 | } else { |
| 1744 | /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */ |
| 1745 | ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100); |
| 1746 | mii_ctrl_reg |= MII_CR_SPEED_10; |
| 1747 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100); |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1748 | e_dbg("Forcing 10mb "); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1749 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1751 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1753 | /* Write the configured values back to the Device Control Reg. */ |
| 1754 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1756 | if (hw->phy_type == e1000_phy_m88) { |
| 1757 | ret_val = |
| 1758 | e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 1759 | if (ret_val) |
| 1760 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1762 | /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI |
| 1763 | * forced whenever speed are duplex are forced. |
| 1764 | */ |
| 1765 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 1766 | ret_val = |
| 1767 | e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 1768 | if (ret_val) |
| 1769 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1771 | e_dbg("M88E1000 PSCR: %x\n", phy_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1773 | /* Need to reset the PHY or these changes will be ignored */ |
| 1774 | mii_ctrl_reg |= MII_CR_RESET; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 1775 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1776 | /* Disable MDI-X support for 10/100 */ |
| 1777 | } else { |
| 1778 | /* Clear Auto-Crossover to force MDI manually. IGP requires MDI |
| 1779 | * forced whenever speed or duplex are forced. |
| 1780 | */ |
| 1781 | ret_val = |
| 1782 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); |
| 1783 | if (ret_val) |
| 1784 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1786 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 1787 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1789 | ret_val = |
| 1790 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); |
| 1791 | if (ret_val) |
| 1792 | return ret_val; |
| 1793 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1795 | /* Write back the modified PHY MII control register. */ |
| 1796 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg); |
| 1797 | if (ret_val) |
| 1798 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1800 | udelay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1802 | /* The wait_autoneg_complete flag may be a little misleading here. |
| 1803 | * Since we are forcing speed and duplex, Auto-Neg is not enabled. |
| 1804 | * But we do want to delay for a period while forcing only so we |
| 1805 | * don't generate false No Link messages. So we will wait here |
| 1806 | * only if the user has set wait_autoneg_complete to 1, which is |
| 1807 | * the default. |
| 1808 | */ |
| 1809 | if (hw->wait_autoneg_complete) { |
| 1810 | /* We will wait for autoneg to complete. */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1811 | e_dbg("Waiting for forced speed/duplex link.\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1812 | mii_status_reg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1814 | /* We will wait for autoneg to complete or 4.5 seconds to expire. */ |
| 1815 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
| 1816 | /* Read the MII Status Register and wait for Auto-Neg Complete bit |
| 1817 | * to be set. |
| 1818 | */ |
| 1819 | ret_val = |
| 1820 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 1821 | if (ret_val) |
| 1822 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1824 | ret_val = |
| 1825 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 1826 | if (ret_val) |
| 1827 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1829 | if (mii_status_reg & MII_SR_LINK_STATUS) |
| 1830 | break; |
| 1831 | msleep(100); |
| 1832 | } |
| 1833 | if ((i == 0) && (hw->phy_type == e1000_phy_m88)) { |
| 1834 | /* We didn't get link. Reset the DSP and wait again for link. */ |
| 1835 | ret_val = e1000_phy_reset_dsp(hw); |
| 1836 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1837 | e_dbg("Error Resetting PHY DSP\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1838 | return ret_val; |
| 1839 | } |
| 1840 | } |
| 1841 | /* This loop will early-out if the link condition has been met. */ |
| 1842 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
| 1843 | if (mii_status_reg & MII_SR_LINK_STATUS) |
| 1844 | break; |
| 1845 | msleep(100); |
| 1846 | /* Read the MII Status Register and wait for Auto-Neg Complete bit |
| 1847 | * to be set. |
| 1848 | */ |
| 1849 | ret_val = |
| 1850 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 1851 | if (ret_val) |
| 1852 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1854 | ret_val = |
| 1855 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 1856 | if (ret_val) |
| 1857 | return ret_val; |
| 1858 | } |
| 1859 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1861 | if (hw->phy_type == e1000_phy_m88) { |
| 1862 | /* Because we reset the PHY above, we need to re-force TX_CLK in the |
| 1863 | * Extended PHY Specific Control Register to 25MHz clock. This value |
| 1864 | * defaults back to a 2.5MHz clock when the PHY is reset. |
| 1865 | */ |
| 1866 | ret_val = |
| 1867 | e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, |
| 1868 | &phy_data); |
| 1869 | if (ret_val) |
| 1870 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1872 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
| 1873 | ret_val = |
| 1874 | e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, |
| 1875 | phy_data); |
| 1876 | if (ret_val) |
| 1877 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1879 | /* In addition, because of the s/w reset above, we need to enable CRS on |
| 1880 | * TX. This must be set for both full and half duplex operation. |
| 1881 | */ |
| 1882 | ret_val = |
| 1883 | e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 1884 | if (ret_val) |
| 1885 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1887 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 1888 | ret_val = |
| 1889 | e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 1890 | if (ret_val) |
| 1891 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1893 | if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) |
| 1894 | && (!hw->autoneg) |
| 1895 | && (hw->forced_speed_duplex == e1000_10_full |
| 1896 | || hw->forced_speed_duplex == e1000_10_half)) { |
| 1897 | ret_val = e1000_polarity_reversal_workaround(hw); |
| 1898 | if (ret_val) |
| 1899 | return ret_val; |
| 1900 | } |
| 1901 | } |
| 1902 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1905 | /** |
| 1906 | * e1000_config_collision_dist - set collision distance register |
| 1907 | * @hw: Struct containing variables accessed by shared code |
| 1908 | * |
| 1909 | * Sets the collision distance in the Transmit Control register. |
| 1910 | * Link should have been established previously. Reads the speed and duplex |
| 1911 | * information from the Device Status register. |
| 1912 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1913 | void e1000_config_collision_dist(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1915 | u32 tctl, coll_dist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1917 | e_dbg("e1000_config_collision_dist"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1919 | if (hw->mac_type < e1000_82543) |
| 1920 | coll_dist = E1000_COLLISION_DISTANCE_82542; |
| 1921 | else |
| 1922 | coll_dist = E1000_COLLISION_DISTANCE; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1923 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1924 | tctl = er32(TCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1926 | tctl &= ~E1000_TCTL_COLD; |
| 1927 | tctl |= coll_dist << E1000_COLD_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1929 | ew32(TCTL, tctl); |
| 1930 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1933 | /** |
| 1934 | * e1000_config_mac_to_phy - sync phy and mac settings |
| 1935 | * @hw: Struct containing variables accessed by shared code |
| 1936 | * @mii_reg: data to write to the MII control register |
| 1937 | * |
| 1938 | * Sets MAC speed and duplex settings to reflect the those in the PHY |
| 1939 | * The contents of the PHY register containing the needed information need to |
| 1940 | * be passed in. |
| 1941 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1942 | static s32 e1000_config_mac_to_phy(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1944 | u32 ctrl; |
| 1945 | s32 ret_val; |
| 1946 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1948 | e_dbg("e1000_config_mac_to_phy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1950 | /* 82544 or newer MAC, Auto Speed Detection takes care of |
| 1951 | * MAC speed/duplex configuration.*/ |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1952 | if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100)) |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1953 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1954 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1955 | /* Read the Device Control Register and set the bits to Force Speed |
| 1956 | * and Duplex. |
| 1957 | */ |
| 1958 | ctrl = er32(CTRL); |
| 1959 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 1960 | ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1962 | switch (hw->phy_type) { |
| 1963 | case e1000_phy_8201: |
| 1964 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
| 1965 | if (ret_val) |
| 1966 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1968 | if (phy_data & RTL_PHY_CTRL_FD) |
| 1969 | ctrl |= E1000_CTRL_FD; |
| 1970 | else |
| 1971 | ctrl &= ~E1000_CTRL_FD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1973 | if (phy_data & RTL_PHY_CTRL_SPD_100) |
| 1974 | ctrl |= E1000_CTRL_SPD_100; |
| 1975 | else |
| 1976 | ctrl |= E1000_CTRL_SPD_10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1978 | e1000_config_collision_dist(hw); |
| 1979 | break; |
| 1980 | default: |
| 1981 | /* Set up duplex in the Device Control and Transmit Control |
| 1982 | * registers depending on negotiated values. |
| 1983 | */ |
| 1984 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 1985 | &phy_data); |
| 1986 | if (ret_val) |
| 1987 | return ret_val; |
| 1988 | |
| 1989 | if (phy_data & M88E1000_PSSR_DPLX) |
| 1990 | ctrl |= E1000_CTRL_FD; |
| 1991 | else |
| 1992 | ctrl &= ~E1000_CTRL_FD; |
| 1993 | |
| 1994 | e1000_config_collision_dist(hw); |
| 1995 | |
| 1996 | /* Set up speed in the Device Control register depending on |
| 1997 | * negotiated values. |
| 1998 | */ |
| 1999 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) |
| 2000 | ctrl |= E1000_CTRL_SPD_1000; |
| 2001 | else if ((phy_data & M88E1000_PSSR_SPEED) == |
| 2002 | M88E1000_PSSR_100MBS) |
| 2003 | ctrl |= E1000_CTRL_SPD_100; |
| 2004 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2006 | /* Write the configured values back to the Device Control Reg. */ |
| 2007 | ew32(CTRL, ctrl); |
| 2008 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2011 | /** |
| 2012 | * e1000_force_mac_fc - force flow control settings |
| 2013 | * @hw: Struct containing variables accessed by shared code |
| 2014 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | * Forces the MAC's flow control settings. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | * Sets the TFCE and RFCE bits in the device control register to reflect |
| 2017 | * the adapter settings. TFCE and RFCE need to be explicitly set by |
| 2018 | * software when a Copper PHY is used because autonegotiation is managed |
| 2019 | * by the PHY rather than the MAC. Software must also configure these |
| 2020 | * bits when link is forced on a fiber connection. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2021 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2022 | s32 e1000_force_mac_fc(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2024 | u32 ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2026 | e_dbg("e1000_force_mac_fc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2028 | /* Get the current configuration of the Device Control Register */ |
| 2029 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2031 | /* Because we didn't get link via the internal auto-negotiation |
| 2032 | * mechanism (we either forced link or we got link via PHY |
| 2033 | * auto-neg), we have to manually enable/disable transmit an |
| 2034 | * receive flow control. |
| 2035 | * |
| 2036 | * The "Case" statement below enables/disable flow control |
| 2037 | * according to the "hw->fc" parameter. |
| 2038 | * |
| 2039 | * The possible values of the "fc" parameter are: |
| 2040 | * 0: Flow control is completely disabled |
| 2041 | * 1: Rx flow control is enabled (we can receive pause |
| 2042 | * frames but not send pause frames). |
| 2043 | * 2: Tx flow control is enabled (we can send pause frames |
| 2044 | * frames but we do not receive pause frames). |
| 2045 | * 3: Both Rx and TX flow control (symmetric) is enabled. |
| 2046 | * other: No other values should be possible at this point. |
| 2047 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2049 | switch (hw->fc) { |
| 2050 | case E1000_FC_NONE: |
| 2051 | ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); |
| 2052 | break; |
| 2053 | case E1000_FC_RX_PAUSE: |
| 2054 | ctrl &= (~E1000_CTRL_TFCE); |
| 2055 | ctrl |= E1000_CTRL_RFCE; |
| 2056 | break; |
| 2057 | case E1000_FC_TX_PAUSE: |
| 2058 | ctrl &= (~E1000_CTRL_RFCE); |
| 2059 | ctrl |= E1000_CTRL_TFCE; |
| 2060 | break; |
| 2061 | case E1000_FC_FULL: |
| 2062 | ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); |
| 2063 | break; |
| 2064 | default: |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2065 | e_dbg("Flow control param set incorrectly\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2066 | return -E1000_ERR_CONFIG; |
| 2067 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2069 | /* Disable TX Flow Control for 82542 (rev 2.0) */ |
| 2070 | if (hw->mac_type == e1000_82542_rev2_0) |
| 2071 | ctrl &= (~E1000_CTRL_TFCE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2073 | ew32(CTRL, ctrl); |
| 2074 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | } |
| 2076 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2077 | /** |
| 2078 | * e1000_config_fc_after_link_up - configure flow control after autoneg |
| 2079 | * @hw: Struct containing variables accessed by shared code |
| 2080 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | * Configures flow control settings after link is established |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | * Should be called immediately after a valid link has been established. |
| 2083 | * Forces MAC flow control settings if link was forced. When in MII/GMII mode |
| 2084 | * and autonegotiation is enabled, the MAC flow control settings will be set |
| 2085 | * based on the flow control negotiated by the PHY. In TBI mode, the TFCE |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2086 | * and RFCE bits will be automatically set to the negotiated flow control mode. |
| 2087 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2088 | static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2090 | s32 ret_val; |
| 2091 | u16 mii_status_reg; |
| 2092 | u16 mii_nway_adv_reg; |
| 2093 | u16 mii_nway_lp_ability_reg; |
| 2094 | u16 speed; |
| 2095 | u16 duplex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2097 | e_dbg("e1000_config_fc_after_link_up"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2099 | /* Check for the case where we have fiber media and auto-neg failed |
| 2100 | * so we had to force link. In this case, we need to force the |
| 2101 | * configuration of the MAC to match the "fc" parameter. |
| 2102 | */ |
| 2103 | if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) |
| 2104 | || ((hw->media_type == e1000_media_type_internal_serdes) |
| 2105 | && (hw->autoneg_failed)) |
| 2106 | || ((hw->media_type == e1000_media_type_copper) |
| 2107 | && (!hw->autoneg))) { |
| 2108 | ret_val = e1000_force_mac_fc(hw); |
| 2109 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2110 | e_dbg("Error forcing flow control settings\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2111 | return ret_val; |
| 2112 | } |
| 2113 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2115 | /* Check for the case where we have copper media and auto-neg is |
| 2116 | * enabled. In this case, we need to check and see if Auto-Neg |
| 2117 | * has completed, and if so, how the PHY and link partner has |
| 2118 | * flow control configured. |
| 2119 | */ |
| 2120 | if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) { |
| 2121 | /* Read the MII Status Register and check to see if AutoNeg |
| 2122 | * has completed. We read this twice because this reg has |
| 2123 | * some "sticky" (latched) bits. |
| 2124 | */ |
| 2125 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 2126 | if (ret_val) |
| 2127 | return ret_val; |
| 2128 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 2129 | if (ret_val) |
| 2130 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2132 | if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) { |
| 2133 | /* The AutoNeg process has completed, so we now need to |
| 2134 | * read both the Auto Negotiation Advertisement Register |
| 2135 | * (Address 4) and the Auto_Negotiation Base Page Ability |
| 2136 | * Register (Address 5) to determine how flow control was |
| 2137 | * negotiated. |
| 2138 | */ |
| 2139 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, |
| 2140 | &mii_nway_adv_reg); |
| 2141 | if (ret_val) |
| 2142 | return ret_val; |
| 2143 | ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, |
| 2144 | &mii_nway_lp_ability_reg); |
| 2145 | if (ret_val) |
| 2146 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2148 | /* Two bits in the Auto Negotiation Advertisement Register |
| 2149 | * (Address 4) and two bits in the Auto Negotiation Base |
| 2150 | * Page Ability Register (Address 5) determine flow control |
| 2151 | * for both the PHY and the link partner. The following |
| 2152 | * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, |
| 2153 | * 1999, describes these PAUSE resolution bits and how flow |
| 2154 | * control is determined based upon these settings. |
| 2155 | * NOTE: DC = Don't Care |
| 2156 | * |
| 2157 | * LOCAL DEVICE | LINK PARTNER |
| 2158 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution |
| 2159 | *-------|---------|-------|---------|-------------------- |
| 2160 | * 0 | 0 | DC | DC | E1000_FC_NONE |
| 2161 | * 0 | 1 | 0 | DC | E1000_FC_NONE |
| 2162 | * 0 | 1 | 1 | 0 | E1000_FC_NONE |
| 2163 | * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE |
| 2164 | * 1 | 0 | 0 | DC | E1000_FC_NONE |
| 2165 | * 1 | DC | 1 | DC | E1000_FC_FULL |
| 2166 | * 1 | 1 | 0 | 0 | E1000_FC_NONE |
| 2167 | * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE |
| 2168 | * |
| 2169 | */ |
| 2170 | /* Are both PAUSE bits set to 1? If so, this implies |
| 2171 | * Symmetric Flow Control is enabled at both ends. The |
| 2172 | * ASM_DIR bits are irrelevant per the spec. |
| 2173 | * |
| 2174 | * For Symmetric Flow Control: |
| 2175 | * |
| 2176 | * LOCAL DEVICE | LINK PARTNER |
| 2177 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 2178 | *-------|---------|-------|---------|-------------------- |
| 2179 | * 1 | DC | 1 | DC | E1000_FC_FULL |
| 2180 | * |
| 2181 | */ |
| 2182 | if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2183 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { |
| 2184 | /* Now we need to check if the user selected RX ONLY |
| 2185 | * of pause frames. In this case, we had to advertise |
| 2186 | * FULL flow control because we could not advertise RX |
| 2187 | * ONLY. Hence, we must now check to see if we need to |
| 2188 | * turn OFF the TRANSMISSION of PAUSE frames. |
| 2189 | */ |
| 2190 | if (hw->original_fc == E1000_FC_FULL) { |
| 2191 | hw->fc = E1000_FC_FULL; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2192 | e_dbg("Flow Control = FULL.\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2193 | } else { |
| 2194 | hw->fc = E1000_FC_RX_PAUSE; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2195 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2196 | ("Flow Control = RX PAUSE frames only.\n"); |
| 2197 | } |
| 2198 | } |
| 2199 | /* For receiving PAUSE frames ONLY. |
| 2200 | * |
| 2201 | * LOCAL DEVICE | LINK PARTNER |
| 2202 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 2203 | *-------|---------|-------|---------|-------------------- |
| 2204 | * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE |
| 2205 | * |
| 2206 | */ |
| 2207 | else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2208 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 2209 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 2210 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) |
| 2211 | { |
| 2212 | hw->fc = E1000_FC_TX_PAUSE; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2213 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2214 | ("Flow Control = TX PAUSE frames only.\n"); |
| 2215 | } |
| 2216 | /* For transmitting PAUSE frames ONLY. |
| 2217 | * |
| 2218 | * LOCAL DEVICE | LINK PARTNER |
| 2219 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 2220 | *-------|---------|-------|---------|-------------------- |
| 2221 | * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE |
| 2222 | * |
| 2223 | */ |
| 2224 | else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2225 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 2226 | !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 2227 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) |
| 2228 | { |
| 2229 | hw->fc = E1000_FC_RX_PAUSE; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2230 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2231 | ("Flow Control = RX PAUSE frames only.\n"); |
| 2232 | } |
| 2233 | /* Per the IEEE spec, at this point flow control should be |
| 2234 | * disabled. However, we want to consider that we could |
| 2235 | * be connected to a legacy switch that doesn't advertise |
| 2236 | * desired flow control, but can be forced on the link |
| 2237 | * partner. So if we advertised no flow control, that is |
| 2238 | * what we will resolve to. If we advertised some kind of |
| 2239 | * receive capability (Rx Pause Only or Full Flow Control) |
| 2240 | * and the link partner advertised none, we will configure |
| 2241 | * ourselves to enable Rx Flow Control only. We can do |
| 2242 | * this safely for two reasons: If the link partner really |
| 2243 | * didn't want flow control enabled, and we enable Rx, no |
| 2244 | * harm done since we won't be receiving any PAUSE frames |
| 2245 | * anyway. If the intent on the link partner was to have |
| 2246 | * flow control enabled, then by us enabling RX only, we |
| 2247 | * can at least receive pause frames and process them. |
| 2248 | * This is a good idea because in most cases, since we are |
| 2249 | * predominantly a server NIC, more times than not we will |
| 2250 | * be asked to delay transmission of packets than asking |
| 2251 | * our link partner to pause transmission of frames. |
| 2252 | */ |
| 2253 | else if ((hw->original_fc == E1000_FC_NONE || |
| 2254 | hw->original_fc == E1000_FC_TX_PAUSE) || |
| 2255 | hw->fc_strict_ieee) { |
| 2256 | hw->fc = E1000_FC_NONE; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2257 | e_dbg("Flow Control = NONE.\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2258 | } else { |
| 2259 | hw->fc = E1000_FC_RX_PAUSE; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2260 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2261 | ("Flow Control = RX PAUSE frames only.\n"); |
| 2262 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2264 | /* Now we need to do one last check... If we auto- |
| 2265 | * negotiated to HALF DUPLEX, flow control should not be |
| 2266 | * enabled per IEEE 802.3 spec. |
| 2267 | */ |
| 2268 | ret_val = |
| 2269 | e1000_get_speed_and_duplex(hw, &speed, &duplex); |
| 2270 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2271 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2272 | ("Error getting link speed and duplex\n"); |
| 2273 | return ret_val; |
| 2274 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2276 | if (duplex == HALF_DUPLEX) |
| 2277 | hw->fc = E1000_FC_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2279 | /* Now we call a subroutine to actually force the MAC |
| 2280 | * controller to use the correct flow control settings. |
| 2281 | */ |
| 2282 | ret_val = e1000_force_mac_fc(hw); |
| 2283 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2284 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2285 | ("Error forcing flow control settings\n"); |
| 2286 | return ret_val; |
| 2287 | } |
| 2288 | } else { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2289 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2290 | ("Copper PHY and Auto Neg has not completed.\n"); |
| 2291 | } |
| 2292 | } |
| 2293 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2296 | /** |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2297 | * e1000_check_for_serdes_link_generic - Check for link (Serdes) |
| 2298 | * @hw: pointer to the HW structure |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2299 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2300 | * Checks for link up on the hardware. If link is not up and we have |
| 2301 | * a signal, then we need to force link up. |
| 2302 | */ |
Jesse Brandeburg | 11b7f7b | 2009-09-25 12:20:33 +0000 | [diff] [blame] | 2303 | static s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw) |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2304 | { |
| 2305 | u32 rxcw; |
| 2306 | u32 ctrl; |
| 2307 | u32 status; |
| 2308 | s32 ret_val = E1000_SUCCESS; |
| 2309 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2310 | e_dbg("e1000_check_for_serdes_link_generic"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2311 | |
| 2312 | ctrl = er32(CTRL); |
| 2313 | status = er32(STATUS); |
| 2314 | rxcw = er32(RXCW); |
| 2315 | |
| 2316 | /* |
| 2317 | * If we don't have link (auto-negotiation failed or link partner |
| 2318 | * cannot auto-negotiate), and our link partner is not trying to |
| 2319 | * auto-negotiate with us (we are receiving idles or data), |
| 2320 | * we need to force link up. We also need to give auto-negotiation |
| 2321 | * time to complete. |
| 2322 | */ |
| 2323 | /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */ |
| 2324 | if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) { |
| 2325 | if (hw->autoneg_failed == 0) { |
| 2326 | hw->autoneg_failed = 1; |
| 2327 | goto out; |
| 2328 | } |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2329 | e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2330 | |
| 2331 | /* Disable auto-negotiation in the TXCW register */ |
| 2332 | ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE)); |
| 2333 | |
| 2334 | /* Force link-up and also force full-duplex. */ |
| 2335 | ctrl = er32(CTRL); |
| 2336 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); |
| 2337 | ew32(CTRL, ctrl); |
| 2338 | |
| 2339 | /* Configure Flow Control after forcing link up. */ |
| 2340 | ret_val = e1000_config_fc_after_link_up(hw); |
| 2341 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2342 | e_dbg("Error configuring flow control\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2343 | goto out; |
| 2344 | } |
| 2345 | } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { |
| 2346 | /* |
| 2347 | * If we are forcing link and we are receiving /C/ ordered |
| 2348 | * sets, re-enable auto-negotiation in the TXCW register |
| 2349 | * and disable forced link in the Device Control register |
| 2350 | * in an attempt to auto-negotiate with our link partner. |
| 2351 | */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2352 | e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2353 | ew32(TXCW, hw->txcw); |
| 2354 | ew32(CTRL, (ctrl & ~E1000_CTRL_SLU)); |
| 2355 | |
| 2356 | hw->serdes_has_link = true; |
| 2357 | } else if (!(E1000_TXCW_ANE & er32(TXCW))) { |
| 2358 | /* |
| 2359 | * If we force link for non-auto-negotiation switch, check |
| 2360 | * link status based on MAC synchronization for internal |
| 2361 | * serdes media type. |
| 2362 | */ |
| 2363 | /* SYNCH bit and IV bit are sticky. */ |
| 2364 | udelay(10); |
| 2365 | rxcw = er32(RXCW); |
| 2366 | if (rxcw & E1000_RXCW_SYNCH) { |
| 2367 | if (!(rxcw & E1000_RXCW_IV)) { |
| 2368 | hw->serdes_has_link = true; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2369 | e_dbg("SERDES: Link up - forced.\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2370 | } |
| 2371 | } else { |
| 2372 | hw->serdes_has_link = false; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2373 | e_dbg("SERDES: Link down - force failed.\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2374 | } |
| 2375 | } |
| 2376 | |
| 2377 | if (E1000_TXCW_ANE & er32(TXCW)) { |
| 2378 | status = er32(STATUS); |
| 2379 | if (status & E1000_STATUS_LU) { |
| 2380 | /* SYNCH bit and IV bit are sticky, so reread rxcw. */ |
| 2381 | udelay(10); |
| 2382 | rxcw = er32(RXCW); |
| 2383 | if (rxcw & E1000_RXCW_SYNCH) { |
| 2384 | if (!(rxcw & E1000_RXCW_IV)) { |
| 2385 | hw->serdes_has_link = true; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2386 | e_dbg("SERDES: Link up - autoneg " |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2387 | "completed successfully.\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2388 | } else { |
| 2389 | hw->serdes_has_link = false; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2390 | e_dbg("SERDES: Link down - invalid" |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2391 | "codewords detected in autoneg.\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2392 | } |
| 2393 | } else { |
| 2394 | hw->serdes_has_link = false; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2395 | e_dbg("SERDES: Link down - no sync.\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2396 | } |
| 2397 | } else { |
| 2398 | hw->serdes_has_link = false; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2399 | e_dbg("SERDES: Link down - autoneg failed\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2400 | } |
| 2401 | } |
| 2402 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2403 | out: |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2404 | return ret_val; |
| 2405 | } |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2406 | |
| 2407 | /** |
| 2408 | * e1000_check_for_link |
| 2409 | * @hw: Struct containing variables accessed by shared code |
| 2410 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | * Checks to see if the link status of the hardware has changed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | * Called by any function that needs to check the link status of the adapter. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2413 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2414 | s32 e1000_check_for_link(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2416 | u32 rxcw = 0; |
| 2417 | u32 ctrl; |
| 2418 | u32 status; |
| 2419 | u32 rctl; |
| 2420 | u32 icr; |
| 2421 | u32 signal = 0; |
| 2422 | s32 ret_val; |
| 2423 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2425 | e_dbg("e1000_check_for_link"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2427 | ctrl = er32(CTRL); |
| 2428 | status = er32(STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2430 | /* On adapters with a MAC newer than 82544, SW Definable pin 1 will be |
| 2431 | * set when the optics detect a signal. On older adapters, it will be |
| 2432 | * cleared when there is a signal. This applies to fiber media only. |
| 2433 | */ |
| 2434 | if ((hw->media_type == e1000_media_type_fiber) || |
| 2435 | (hw->media_type == e1000_media_type_internal_serdes)) { |
| 2436 | rxcw = er32(RXCW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2438 | if (hw->media_type == e1000_media_type_fiber) { |
| 2439 | signal = |
| 2440 | (hw->mac_type > |
| 2441 | e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; |
| 2442 | if (status & E1000_STATUS_LU) |
| 2443 | hw->get_link_status = false; |
| 2444 | } |
| 2445 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2447 | /* If we have a copper PHY then we only want to go out to the PHY |
| 2448 | * registers to see if Auto-Neg has completed and/or if our link |
| 2449 | * status has changed. The get_link_status flag will be set if we |
| 2450 | * receive a Link Status Change interrupt or we have Rx Sequence |
| 2451 | * Errors. |
| 2452 | */ |
| 2453 | if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) { |
| 2454 | /* First we want to see if the MII Status Register reports |
| 2455 | * link. If so, then we want to get the current speed/duplex |
| 2456 | * of the PHY. |
| 2457 | * Read the register twice since the link bit is sticky. |
| 2458 | */ |
| 2459 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 2460 | if (ret_val) |
| 2461 | return ret_val; |
| 2462 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 2463 | if (ret_val) |
| 2464 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2466 | if (phy_data & MII_SR_LINK_STATUS) { |
| 2467 | hw->get_link_status = false; |
| 2468 | /* Check if there was DownShift, must be checked immediately after |
| 2469 | * link-up */ |
| 2470 | e1000_check_downshift(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2472 | /* If we are on 82544 or 82543 silicon and speed/duplex |
| 2473 | * are forced to 10H or 10F, then we will implement the polarity |
| 2474 | * reversal workaround. We disable interrupts first, and upon |
| 2475 | * returning, place the devices interrupt state to its previous |
| 2476 | * value except for the link status change interrupt which will |
| 2477 | * happen due to the execution of this workaround. |
| 2478 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2480 | if ((hw->mac_type == e1000_82544 |
| 2481 | || hw->mac_type == e1000_82543) && (!hw->autoneg) |
| 2482 | && (hw->forced_speed_duplex == e1000_10_full |
| 2483 | || hw->forced_speed_duplex == e1000_10_half)) { |
| 2484 | ew32(IMC, 0xffffffff); |
| 2485 | ret_val = |
| 2486 | e1000_polarity_reversal_workaround(hw); |
| 2487 | icr = er32(ICR); |
| 2488 | ew32(ICS, (icr & ~E1000_ICS_LSC)); |
| 2489 | ew32(IMS, IMS_ENABLE_MASK); |
| 2490 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2492 | } else { |
| 2493 | /* No link detected */ |
| 2494 | e1000_config_dsp_after_link_change(hw, false); |
| 2495 | return 0; |
| 2496 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2498 | /* If we are forcing speed/duplex, then we simply return since |
| 2499 | * we have already determined whether we have link or not. |
| 2500 | */ |
| 2501 | if (!hw->autoneg) |
| 2502 | return -E1000_ERR_CONFIG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2504 | /* optimize the dsp settings for the igp phy */ |
| 2505 | e1000_config_dsp_after_link_change(hw, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2507 | /* We have a M88E1000 PHY and Auto-Neg is enabled. If we |
| 2508 | * have Si on board that is 82544 or newer, Auto |
| 2509 | * Speed Detection takes care of MAC speed/duplex |
| 2510 | * configuration. So we only need to configure Collision |
| 2511 | * Distance in the MAC. Otherwise, we need to force |
| 2512 | * speed/duplex on the MAC to the current PHY speed/duplex |
| 2513 | * settings. |
| 2514 | */ |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2515 | if ((hw->mac_type >= e1000_82544) && |
| 2516 | (hw->mac_type != e1000_ce4100)) |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2517 | e1000_config_collision_dist(hw); |
| 2518 | else { |
| 2519 | ret_val = e1000_config_mac_to_phy(hw); |
| 2520 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2521 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2522 | ("Error configuring MAC to PHY settings\n"); |
| 2523 | return ret_val; |
| 2524 | } |
| 2525 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2527 | /* Configure Flow Control now that Auto-Neg has completed. First, we |
| 2528 | * need to restore the desired flow control settings because we may |
| 2529 | * have had to re-autoneg with a different link partner. |
| 2530 | */ |
| 2531 | ret_val = e1000_config_fc_after_link_up(hw); |
| 2532 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2533 | e_dbg("Error configuring flow control\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2534 | return ret_val; |
| 2535 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2537 | /* At this point we know that we are on copper and we have |
| 2538 | * auto-negotiated link. These are conditions for checking the link |
| 2539 | * partner capability register. We use the link speed to determine if |
| 2540 | * TBI compatibility needs to be turned on or off. If the link is not |
| 2541 | * at gigabit speed, then TBI compatibility is not needed. If we are |
| 2542 | * at gigabit speed, we turn on TBI compatibility. |
| 2543 | */ |
| 2544 | if (hw->tbi_compatibility_en) { |
| 2545 | u16 speed, duplex; |
| 2546 | ret_val = |
| 2547 | e1000_get_speed_and_duplex(hw, &speed, &duplex); |
| 2548 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2549 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2550 | ("Error getting link speed and duplex\n"); |
| 2551 | return ret_val; |
| 2552 | } |
| 2553 | if (speed != SPEED_1000) { |
| 2554 | /* If link speed is not set to gigabit speed, we do not need |
| 2555 | * to enable TBI compatibility. |
| 2556 | */ |
| 2557 | if (hw->tbi_compatibility_on) { |
| 2558 | /* If we previously were in the mode, turn it off. */ |
| 2559 | rctl = er32(RCTL); |
| 2560 | rctl &= ~E1000_RCTL_SBP; |
| 2561 | ew32(RCTL, rctl); |
| 2562 | hw->tbi_compatibility_on = false; |
| 2563 | } |
| 2564 | } else { |
| 2565 | /* If TBI compatibility is was previously off, turn it on. For |
| 2566 | * compatibility with a TBI link partner, we will store bad |
| 2567 | * packets. Some frames have an additional byte on the end and |
| 2568 | * will look like CRC errors to to the hardware. |
| 2569 | */ |
| 2570 | if (!hw->tbi_compatibility_on) { |
| 2571 | hw->tbi_compatibility_on = true; |
| 2572 | rctl = er32(RCTL); |
| 2573 | rctl |= E1000_RCTL_SBP; |
| 2574 | ew32(RCTL, rctl); |
| 2575 | } |
| 2576 | } |
| 2577 | } |
| 2578 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2580 | if ((hw->media_type == e1000_media_type_fiber) || |
| 2581 | (hw->media_type == e1000_media_type_internal_serdes)) |
| 2582 | e1000_check_for_serdes_link_generic(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2584 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | } |
| 2586 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2587 | /** |
| 2588 | * e1000_get_speed_and_duplex |
| 2589 | * @hw: Struct containing variables accessed by shared code |
| 2590 | * @speed: Speed of the connection |
| 2591 | * @duplex: Duplex setting of the connection |
| 2592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | * Detects the current speed and duplex settings of the hardware. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2594 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2595 | 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] | 2596 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2597 | u32 status; |
| 2598 | s32 ret_val; |
| 2599 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2601 | e_dbg("e1000_get_speed_and_duplex"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2603 | if (hw->mac_type >= e1000_82543) { |
| 2604 | status = er32(STATUS); |
| 2605 | if (status & E1000_STATUS_SPEED_1000) { |
| 2606 | *speed = SPEED_1000; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2607 | e_dbg("1000 Mbs, "); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2608 | } else if (status & E1000_STATUS_SPEED_100) { |
| 2609 | *speed = SPEED_100; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2610 | e_dbg("100 Mbs, "); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2611 | } else { |
| 2612 | *speed = SPEED_10; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2613 | e_dbg("10 Mbs, "); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2614 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2615 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2616 | if (status & E1000_STATUS_FD) { |
| 2617 | *duplex = FULL_DUPLEX; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2618 | e_dbg("Full Duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2619 | } else { |
| 2620 | *duplex = HALF_DUPLEX; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2621 | e_dbg(" Half Duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2622 | } |
| 2623 | } else { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2624 | e_dbg("1000 Mbs, Full Duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2625 | *speed = SPEED_1000; |
| 2626 | *duplex = FULL_DUPLEX; |
| 2627 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2629 | /* IGP01 PHY may advertise full duplex operation after speed downgrade even |
| 2630 | * if it is operating at half duplex. Here we set the duplex settings to |
| 2631 | * match the duplex in the link partner's capabilities. |
| 2632 | */ |
| 2633 | if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) { |
| 2634 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data); |
| 2635 | if (ret_val) |
| 2636 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2638 | if (!(phy_data & NWAY_ER_LP_NWAY_CAPS)) |
| 2639 | *duplex = HALF_DUPLEX; |
| 2640 | else { |
| 2641 | ret_val = |
| 2642 | e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data); |
| 2643 | if (ret_val) |
| 2644 | return ret_val; |
| 2645 | if ((*speed == SPEED_100 |
| 2646 | && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) |
| 2647 | || (*speed == SPEED_10 |
| 2648 | && !(phy_data & NWAY_LPAR_10T_FD_CAPS))) |
| 2649 | *duplex = HALF_DUPLEX; |
| 2650 | } |
| 2651 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2652 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2653 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | } |
| 2655 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2656 | /** |
| 2657 | * e1000_wait_autoneg |
| 2658 | * @hw: Struct containing variables accessed by shared code |
| 2659 | * |
| 2660 | * Blocks until autoneg completes or times out (~4.5 seconds) |
| 2661 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2662 | static s32 e1000_wait_autoneg(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2664 | s32 ret_val; |
| 2665 | u16 i; |
| 2666 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2668 | e_dbg("e1000_wait_autoneg"); |
| 2669 | e_dbg("Waiting for Auto-Neg to complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2671 | /* We will wait for autoneg to complete or 4.5 seconds to expire. */ |
| 2672 | for (i = PHY_AUTO_NEG_TIME; i > 0; i--) { |
| 2673 | /* Read the MII Status Register and wait for Auto-Neg |
| 2674 | * Complete bit to be set. |
| 2675 | */ |
| 2676 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 2677 | if (ret_val) |
| 2678 | return ret_val; |
| 2679 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 2680 | if (ret_val) |
| 2681 | return ret_val; |
| 2682 | if (phy_data & MII_SR_AUTONEG_COMPLETE) { |
| 2683 | return E1000_SUCCESS; |
| 2684 | } |
| 2685 | msleep(100); |
| 2686 | } |
| 2687 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | } |
| 2689 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2690 | /** |
| 2691 | * e1000_raise_mdi_clk - Raises the Management Data Clock |
| 2692 | * @hw: Struct containing variables accessed by shared code |
| 2693 | * @ctrl: Device control register's current value |
| 2694 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2695 | static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2697 | /* Raise the clock input to the Management Data Clock (by setting the MDC |
| 2698 | * bit), and then delay 10 microseconds. |
| 2699 | */ |
| 2700 | ew32(CTRL, (*ctrl | E1000_CTRL_MDC)); |
| 2701 | E1000_WRITE_FLUSH(); |
| 2702 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | } |
| 2704 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2705 | /** |
| 2706 | * e1000_lower_mdi_clk - Lowers the Management Data Clock |
| 2707 | * @hw: Struct containing variables accessed by shared code |
| 2708 | * @ctrl: Device control register's current value |
| 2709 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2710 | static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2712 | /* Lower the clock input to the Management Data Clock (by clearing the MDC |
| 2713 | * bit), and then delay 10 microseconds. |
| 2714 | */ |
| 2715 | ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC)); |
| 2716 | E1000_WRITE_FLUSH(); |
| 2717 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | } |
| 2719 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2720 | /** |
| 2721 | * e1000_shift_out_mdi_bits - Shifts data bits out to the PHY |
| 2722 | * @hw: Struct containing variables accessed by shared code |
| 2723 | * @data: Data to send out to the PHY |
| 2724 | * @count: Number of bits to shift out |
| 2725 | * |
| 2726 | * Bits are shifted out in MSB to LSB order. |
| 2727 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2728 | 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] | 2729 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2730 | u32 ctrl; |
| 2731 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2733 | /* We need to shift "count" number of bits out to the PHY. So, the value |
| 2734 | * in the "data" parameter will be shifted out to the PHY one bit at a |
| 2735 | * time. In order to do this, "data" must be broken down into bits. |
| 2736 | */ |
| 2737 | mask = 0x01; |
| 2738 | mask <<= (count - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2740 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2742 | /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */ |
| 2743 | ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2745 | while (mask) { |
| 2746 | /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and |
| 2747 | * then raising and lowering the Management Data Clock. A "0" is |
| 2748 | * shifted out to the PHY by setting the MDIO bit to "0" and then |
| 2749 | * raising and lowering the clock. |
| 2750 | */ |
| 2751 | if (data & mask) |
| 2752 | ctrl |= E1000_CTRL_MDIO; |
| 2753 | else |
| 2754 | ctrl &= ~E1000_CTRL_MDIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2756 | ew32(CTRL, ctrl); |
| 2757 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2759 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2761 | e1000_raise_mdi_clk(hw, &ctrl); |
| 2762 | e1000_lower_mdi_clk(hw, &ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2764 | mask = mask >> 1; |
| 2765 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | } |
| 2767 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2768 | /** |
| 2769 | * e1000_shift_in_mdi_bits - Shifts data bits in from the PHY |
| 2770 | * @hw: Struct containing variables accessed by shared code |
| 2771 | * |
| 2772 | * Bits are shifted in in MSB to LSB order. |
| 2773 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2774 | static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2776 | u32 ctrl; |
| 2777 | u16 data = 0; |
| 2778 | u8 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2780 | /* In order to read a register from the PHY, we need to shift in a total |
| 2781 | * of 18 bits from the PHY. The first two bit (turnaround) times are used |
| 2782 | * to avoid contention on the MDIO pin when a read operation is performed. |
| 2783 | * These two bits are ignored by us and thrown away. Bits are "shifted in" |
| 2784 | * by raising the input to the Management Data Clock (setting the MDC bit), |
| 2785 | * and then reading the value of the MDIO bit. |
| 2786 | */ |
| 2787 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2789 | /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */ |
| 2790 | ctrl &= ~E1000_CTRL_MDIO_DIR; |
| 2791 | ctrl &= ~E1000_CTRL_MDIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2793 | ew32(CTRL, ctrl); |
| 2794 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2796 | /* Raise and Lower the clock before reading in the data. This accounts for |
| 2797 | * the turnaround bits. The first clock occurred when we clocked out the |
| 2798 | * last bit of the Register Address. |
| 2799 | */ |
| 2800 | e1000_raise_mdi_clk(hw, &ctrl); |
| 2801 | e1000_lower_mdi_clk(hw, &ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2803 | for (data = 0, i = 0; i < 16; i++) { |
| 2804 | data = data << 1; |
| 2805 | e1000_raise_mdi_clk(hw, &ctrl); |
| 2806 | ctrl = er32(CTRL); |
| 2807 | /* Check to see if we shifted in a "1". */ |
| 2808 | if (ctrl & E1000_CTRL_MDIO) |
| 2809 | data |= 1; |
| 2810 | e1000_lower_mdi_clk(hw, &ctrl); |
| 2811 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2813 | e1000_raise_mdi_clk(hw, &ctrl); |
| 2814 | e1000_lower_mdi_clk(hw, &ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2816 | return data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | } |
| 2818 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2819 | |
| 2820 | /** |
| 2821 | * e1000_read_phy_reg - read a phy register |
| 2822 | * @hw: Struct containing variables accessed by shared code |
| 2823 | * @reg_addr: address of the PHY register to read |
| 2824 | * |
| 2825 | * Reads the value from a PHY register, if the value is on a specific non zero |
| 2826 | * page, sets the page first. |
| 2827 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2828 | 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] | 2829 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2830 | u32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2832 | e_dbg("e1000_read_phy_reg"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2834 | if ((hw->phy_type == e1000_phy_igp) && |
| 2835 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { |
| 2836 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 2837 | (u16) reg_addr); |
| 2838 | if (ret_val) |
| 2839 | return ret_val; |
| 2840 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2842 | ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, |
| 2843 | phy_data); |
| 2844 | |
| 2845 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | } |
| 2847 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2848 | static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, |
| 2849 | u16 *phy_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2851 | u32 i; |
| 2852 | u32 mdic = 0; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2853 | const u32 phy_addr = (hw->mac_type == e1000_ce4100) ? hw->phy_addr : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2855 | e_dbg("e1000_read_phy_reg_ex"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2857 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2858 | e_dbg("PHY Address %d is out of range\n", reg_addr); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2859 | return -E1000_ERR_PARAM; |
| 2860 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2862 | if (hw->mac_type > e1000_82543) { |
| 2863 | /* Set up Op-code, Phy Address, and register address in the MDI |
| 2864 | * Control register. The MAC will take care of interfacing with the |
| 2865 | * PHY to retrieve the desired data. |
| 2866 | */ |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2867 | if (hw->mac_type == e1000_ce4100) { |
| 2868 | mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) | |
| 2869 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 2870 | (INTEL_CE_GBE_MDIC_OP_READ) | |
| 2871 | (INTEL_CE_GBE_MDIC_GO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2873 | writel(mdic, E1000_MDIO_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2875 | /* Poll the ready bit to see if the MDI read |
| 2876 | * completed |
| 2877 | */ |
| 2878 | for (i = 0; i < 64; i++) { |
| 2879 | udelay(50); |
| 2880 | mdic = readl(E1000_MDIO_CMD); |
| 2881 | if (!(mdic & INTEL_CE_GBE_MDIC_GO)) |
| 2882 | break; |
| 2883 | } |
| 2884 | |
| 2885 | if (mdic & INTEL_CE_GBE_MDIC_GO) { |
| 2886 | e_dbg("MDI Read did not complete\n"); |
| 2887 | return -E1000_ERR_PHY; |
| 2888 | } |
| 2889 | |
| 2890 | mdic = readl(E1000_MDIO_STS); |
| 2891 | if (mdic & INTEL_CE_GBE_MDIC_READ_ERROR) { |
| 2892 | e_dbg("MDI Read Error\n"); |
| 2893 | return -E1000_ERR_PHY; |
| 2894 | } |
| 2895 | *phy_data = (u16) mdic; |
| 2896 | } else { |
| 2897 | mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) | |
| 2898 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 2899 | (E1000_MDIC_OP_READ)); |
| 2900 | |
| 2901 | ew32(MDIC, mdic); |
| 2902 | |
| 2903 | /* Poll the ready bit to see if the MDI read |
| 2904 | * completed |
| 2905 | */ |
| 2906 | for (i = 0; i < 64; i++) { |
| 2907 | udelay(50); |
| 2908 | mdic = er32(MDIC); |
| 2909 | if (mdic & E1000_MDIC_READY) |
| 2910 | break; |
| 2911 | } |
| 2912 | if (!(mdic & E1000_MDIC_READY)) { |
| 2913 | e_dbg("MDI Read did not complete\n"); |
| 2914 | return -E1000_ERR_PHY; |
| 2915 | } |
| 2916 | if (mdic & E1000_MDIC_ERROR) { |
| 2917 | e_dbg("MDI Error\n"); |
| 2918 | return -E1000_ERR_PHY; |
| 2919 | } |
| 2920 | *phy_data = (u16) mdic; |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2921 | } |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2922 | } else { |
| 2923 | /* We must first send a preamble through the MDIO pin to signal the |
| 2924 | * beginning of an MII instruction. This is done by sending 32 |
| 2925 | * consecutive "1" bits. |
| 2926 | */ |
| 2927 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2929 | /* Now combine the next few fields that are required for a read |
| 2930 | * operation. We use this method instead of calling the |
| 2931 | * e1000_shift_out_mdi_bits routine five different times. The format of |
| 2932 | * a MII read instruction consists of a shift out of 14 bits and is |
| 2933 | * defined as follows: |
| 2934 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr> |
| 2935 | * followed by a shift in of 18 bits. This first two bits shifted in |
| 2936 | * are TurnAround bits used to avoid contention on the MDIO pin when a |
| 2937 | * READ operation is performed. These two bits are thrown away |
| 2938 | * followed by a shift in of 16 bits which contains the desired data. |
| 2939 | */ |
| 2940 | mdic = ((reg_addr) | (phy_addr << 5) | |
| 2941 | (PHY_OP_READ << 10) | (PHY_SOF << 12)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2943 | e1000_shift_out_mdi_bits(hw, mdic, 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2945 | /* Now that we've shifted out the read command to the MII, we need to |
| 2946 | * "shift in" the 16-bit value (18 total bits) of the requested PHY |
| 2947 | * register address. |
| 2948 | */ |
| 2949 | *phy_data = e1000_shift_in_mdi_bits(hw); |
| 2950 | } |
| 2951 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | } |
| 2953 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2954 | /** |
| 2955 | * e1000_write_phy_reg - write a phy register |
| 2956 | * |
| 2957 | * @hw: Struct containing variables accessed by shared code |
| 2958 | * @reg_addr: address of the PHY register to write |
| 2959 | * @data: data to write to the PHY |
| 2960 | |
| 2961 | * Writes a value to a PHY register |
| 2962 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2963 | 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] | 2964 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2965 | u32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2967 | e_dbg("e1000_write_phy_reg"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2969 | if ((hw->phy_type == e1000_phy_igp) && |
| 2970 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { |
| 2971 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 2972 | (u16) reg_addr); |
| 2973 | if (ret_val) |
| 2974 | return ret_val; |
| 2975 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2976 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2977 | ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, |
| 2978 | phy_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2980 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | } |
| 2982 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2983 | static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, |
| 2984 | u16 phy_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2986 | u32 i; |
| 2987 | u32 mdic = 0; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2988 | const u32 phy_addr = (hw->mac_type == e1000_ce4100) ? hw->phy_addr : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2990 | e_dbg("e1000_write_phy_reg_ex"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2992 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2993 | e_dbg("PHY Address %d is out of range\n", reg_addr); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2994 | return -E1000_ERR_PARAM; |
| 2995 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2997 | if (hw->mac_type > e1000_82543) { |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2998 | /* Set up Op-code, Phy Address, register address, and data |
| 2999 | * intended for the PHY register in the MDI Control register. |
| 3000 | * The MAC will take care of interfacing with the PHY to send |
| 3001 | * the desired data. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3002 | */ |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3003 | if (hw->mac_type == e1000_ce4100) { |
| 3004 | mdic = (((u32) phy_data) | |
| 3005 | (reg_addr << E1000_MDIC_REG_SHIFT) | |
| 3006 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 3007 | (INTEL_CE_GBE_MDIC_OP_WRITE) | |
| 3008 | (INTEL_CE_GBE_MDIC_GO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3010 | writel(mdic, E1000_MDIO_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3012 | /* Poll the ready bit to see if the MDI read |
| 3013 | * completed |
| 3014 | */ |
| 3015 | for (i = 0; i < 640; i++) { |
| 3016 | udelay(5); |
| 3017 | mdic = readl(E1000_MDIO_CMD); |
| 3018 | if (!(mdic & INTEL_CE_GBE_MDIC_GO)) |
| 3019 | break; |
| 3020 | } |
| 3021 | if (mdic & INTEL_CE_GBE_MDIC_GO) { |
| 3022 | e_dbg("MDI Write did not complete\n"); |
| 3023 | return -E1000_ERR_PHY; |
| 3024 | } |
| 3025 | } else { |
| 3026 | mdic = (((u32) phy_data) | |
| 3027 | (reg_addr << E1000_MDIC_REG_SHIFT) | |
| 3028 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 3029 | (E1000_MDIC_OP_WRITE)); |
| 3030 | |
| 3031 | ew32(MDIC, mdic); |
| 3032 | |
| 3033 | /* Poll the ready bit to see if the MDI read |
| 3034 | * completed |
| 3035 | */ |
| 3036 | for (i = 0; i < 641; i++) { |
| 3037 | udelay(5); |
| 3038 | mdic = er32(MDIC); |
| 3039 | if (mdic & E1000_MDIC_READY) |
| 3040 | break; |
| 3041 | } |
| 3042 | if (!(mdic & E1000_MDIC_READY)) { |
| 3043 | e_dbg("MDI Write did not complete\n"); |
| 3044 | return -E1000_ERR_PHY; |
| 3045 | } |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3046 | } |
| 3047 | } else { |
| 3048 | /* We'll need to use the SW defined pins to shift the write command |
| 3049 | * out to the PHY. We first send a preamble to the PHY to signal the |
| 3050 | * beginning of the MII instruction. This is done by sending 32 |
| 3051 | * consecutive "1" bits. |
| 3052 | */ |
| 3053 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3055 | /* Now combine the remaining required fields that will indicate a |
| 3056 | * write operation. We use this method instead of calling the |
| 3057 | * e1000_shift_out_mdi_bits routine for each field in the command. The |
| 3058 | * format of a MII write instruction is as follows: |
| 3059 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>. |
| 3060 | */ |
| 3061 | mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) | |
| 3062 | (PHY_OP_WRITE << 12) | (PHY_SOF << 14)); |
| 3063 | mdic <<= 16; |
| 3064 | mdic |= (u32) phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3066 | e1000_shift_out_mdi_bits(hw, mdic, 32); |
| 3067 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3069 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | } |
| 3071 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3072 | /** |
| 3073 | * e1000_phy_hw_reset - reset the phy, hardware style |
| 3074 | * @hw: Struct containing variables accessed by shared code |
| 3075 | * |
| 3076 | * Returns the PHY to the power-on reset state |
| 3077 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3078 | s32 e1000_phy_hw_reset(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3080 | u32 ctrl, ctrl_ext; |
| 3081 | u32 led_ctrl; |
| 3082 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3084 | e_dbg("e1000_phy_hw_reset"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3086 | e_dbg("Resetting Phy...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3088 | if (hw->mac_type > e1000_82543) { |
| 3089 | /* Read the device control register and assert the E1000_CTRL_PHY_RST |
| 3090 | * bit. Then, take it out of reset. |
| 3091 | * For e1000 hardware, we delay for 10ms between the assert |
| 3092 | * and deassert. |
| 3093 | */ |
| 3094 | ctrl = er32(CTRL); |
| 3095 | ew32(CTRL, ctrl | E1000_CTRL_PHY_RST); |
| 3096 | E1000_WRITE_FLUSH(); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3097 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3098 | msleep(10); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3099 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3100 | ew32(CTRL, ctrl); |
| 3101 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3103 | } else { |
| 3104 | /* Read the Extended Device Control Register, assert the PHY_RESET_DIR |
| 3105 | * bit to put the PHY into reset. Then, take it out of reset. |
| 3106 | */ |
| 3107 | ctrl_ext = er32(CTRL_EXT); |
| 3108 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR; |
| 3109 | ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA; |
| 3110 | ew32(CTRL_EXT, ctrl_ext); |
| 3111 | E1000_WRITE_FLUSH(); |
| 3112 | msleep(10); |
| 3113 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA; |
| 3114 | ew32(CTRL_EXT, ctrl_ext); |
| 3115 | E1000_WRITE_FLUSH(); |
| 3116 | } |
| 3117 | udelay(150); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3118 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3119 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 3120 | /* Configure activity LED after PHY reset */ |
| 3121 | led_ctrl = er32(LEDCTL); |
| 3122 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 3123 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 3124 | ew32(LEDCTL, led_ctrl); |
| 3125 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3126 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3127 | /* Wait for FW to finish PHY configuration. */ |
| 3128 | ret_val = e1000_get_phy_cfg_done(hw); |
| 3129 | if (ret_val != E1000_SUCCESS) |
| 3130 | return ret_val; |
| 3131 | |
| 3132 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | } |
| 3134 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3135 | /** |
| 3136 | * e1000_phy_reset - reset the phy to commit settings |
| 3137 | * @hw: Struct containing variables accessed by shared code |
| 3138 | * |
| 3139 | * Resets the PHY |
| 3140 | * Sets bit 15 of the MII Control register |
| 3141 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3142 | s32 e1000_phy_reset(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3144 | s32 ret_val; |
| 3145 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3147 | e_dbg("e1000_phy_reset"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3149 | switch (hw->phy_type) { |
| 3150 | case e1000_phy_igp: |
| 3151 | ret_val = e1000_phy_hw_reset(hw); |
| 3152 | if (ret_val) |
| 3153 | return ret_val; |
| 3154 | break; |
| 3155 | default: |
| 3156 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
| 3157 | if (ret_val) |
| 3158 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3160 | phy_data |= MII_CR_RESET; |
| 3161 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); |
| 3162 | if (ret_val) |
| 3163 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3165 | udelay(1); |
| 3166 | break; |
| 3167 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3169 | if (hw->phy_type == e1000_phy_igp) |
| 3170 | e1000_phy_init_script(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3172 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | } |
| 3174 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3175 | /** |
| 3176 | * e1000_detect_gig_phy - check the phy type |
| 3177 | * @hw: Struct containing variables accessed by shared code |
| 3178 | * |
| 3179 | * Probes the expected PHY address for known PHY IDs |
| 3180 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3181 | static s32 e1000_detect_gig_phy(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3183 | s32 phy_init_status, ret_val; |
| 3184 | u16 phy_id_high, phy_id_low; |
| 3185 | bool match = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3187 | e_dbg("e1000_detect_gig_phy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3189 | if (hw->phy_id != 0) |
| 3190 | return E1000_SUCCESS; |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3191 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3192 | /* Read the PHY ID Registers to identify which PHY is onboard. */ |
| 3193 | ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high); |
| 3194 | if (ret_val) |
| 3195 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3197 | hw->phy_id = (u32) (phy_id_high << 16); |
| 3198 | udelay(20); |
| 3199 | ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low); |
| 3200 | if (ret_val) |
| 3201 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3203 | hw->phy_id |= (u32) (phy_id_low & PHY_REVISION_MASK); |
| 3204 | hw->phy_revision = (u32) phy_id_low & ~PHY_REVISION_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3206 | switch (hw->mac_type) { |
| 3207 | case e1000_82543: |
| 3208 | if (hw->phy_id == M88E1000_E_PHY_ID) |
| 3209 | match = true; |
| 3210 | break; |
| 3211 | case e1000_82544: |
| 3212 | if (hw->phy_id == M88E1000_I_PHY_ID) |
| 3213 | match = true; |
| 3214 | break; |
| 3215 | case e1000_82540: |
| 3216 | case e1000_82545: |
| 3217 | case e1000_82545_rev_3: |
| 3218 | case e1000_82546: |
| 3219 | case e1000_82546_rev_3: |
| 3220 | if (hw->phy_id == M88E1011_I_PHY_ID) |
| 3221 | match = true; |
| 3222 | break; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3223 | case e1000_ce4100: |
| 3224 | if ((hw->phy_id == RTL8211B_PHY_ID) || |
| 3225 | (hw->phy_id == RTL8201N_PHY_ID)) |
| 3226 | match = true; |
| 3227 | break; |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3228 | case e1000_82541: |
| 3229 | case e1000_82541_rev_2: |
| 3230 | case e1000_82547: |
| 3231 | case e1000_82547_rev_2: |
| 3232 | if (hw->phy_id == IGP01E1000_I_PHY_ID) |
| 3233 | match = true; |
| 3234 | break; |
| 3235 | default: |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3236 | e_dbg("Invalid MAC type %d\n", hw->mac_type); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3237 | return -E1000_ERR_CONFIG; |
| 3238 | } |
| 3239 | phy_init_status = e1000_set_phy_type(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3241 | if ((match) && (phy_init_status == E1000_SUCCESS)) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3242 | e_dbg("PHY ID 0x%X detected\n", hw->phy_id); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3243 | return E1000_SUCCESS; |
| 3244 | } |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3245 | e_dbg("Invalid PHY ID 0x%X\n", hw->phy_id); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3246 | return -E1000_ERR_PHY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | } |
| 3248 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3249 | /** |
| 3250 | * e1000_phy_reset_dsp - reset DSP |
| 3251 | * @hw: Struct containing variables accessed by shared code |
| 3252 | * |
| 3253 | * Resets the PHY's DSP |
| 3254 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3255 | static s32 e1000_phy_reset_dsp(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3257 | s32 ret_val; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3258 | e_dbg("e1000_phy_reset_dsp"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3260 | do { |
| 3261 | ret_val = e1000_write_phy_reg(hw, 29, 0x001d); |
| 3262 | if (ret_val) |
| 3263 | break; |
| 3264 | ret_val = e1000_write_phy_reg(hw, 30, 0x00c1); |
| 3265 | if (ret_val) |
| 3266 | break; |
| 3267 | ret_val = e1000_write_phy_reg(hw, 30, 0x0000); |
| 3268 | if (ret_val) |
| 3269 | break; |
| 3270 | ret_val = E1000_SUCCESS; |
| 3271 | } while (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3273 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | } |
| 3275 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3276 | /** |
| 3277 | * e1000_phy_igp_get_info - get igp specific registers |
| 3278 | * @hw: Struct containing variables accessed by shared code |
| 3279 | * @phy_info: PHY information structure |
| 3280 | * |
| 3281 | * Get PHY information from various PHY registers for igp PHY only. |
| 3282 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3283 | static s32 e1000_phy_igp_get_info(struct e1000_hw *hw, |
| 3284 | struct e1000_phy_info *phy_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3286 | s32 ret_val; |
| 3287 | u16 phy_data, min_length, max_length, average; |
| 3288 | e1000_rev_polarity polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3289 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3290 | e_dbg("e1000_phy_igp_get_info"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3292 | /* The downshift status is checked only once, after link is established, |
| 3293 | * and it stored in the hw->speed_downgraded parameter. */ |
| 3294 | phy_info->downshift = (e1000_downshift) hw->speed_downgraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3296 | /* IGP01E1000 does not need to support it. */ |
| 3297 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3299 | /* IGP01E1000 always correct polarity reversal */ |
| 3300 | phy_info->polarity_correction = e1000_polarity_reversal_enabled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3302 | /* Check polarity status */ |
| 3303 | ret_val = e1000_check_polarity(hw, &polarity); |
| 3304 | if (ret_val) |
| 3305 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3307 | phy_info->cable_polarity = polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3309 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data); |
| 3310 | if (ret_val) |
| 3311 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3313 | phy_info->mdix_mode = |
| 3314 | (e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >> |
| 3315 | IGP01E1000_PSSR_MDIX_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3317 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == |
| 3318 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
| 3319 | /* Local/Remote Receiver Information are only valid at 1000 Mbps */ |
| 3320 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); |
| 3321 | if (ret_val) |
| 3322 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3324 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> |
| 3325 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? |
| 3326 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
| 3327 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> |
| 3328 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? |
| 3329 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3331 | /* Get cable length */ |
| 3332 | ret_val = e1000_get_cable_length(hw, &min_length, &max_length); |
| 3333 | if (ret_val) |
| 3334 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3336 | /* Translate to old method */ |
| 3337 | average = (max_length + min_length) / 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3339 | if (average <= e1000_igp_cable_length_50) |
| 3340 | phy_info->cable_length = e1000_cable_length_50; |
| 3341 | else if (average <= e1000_igp_cable_length_80) |
| 3342 | phy_info->cable_length = e1000_cable_length_50_80; |
| 3343 | else if (average <= e1000_igp_cable_length_110) |
| 3344 | phy_info->cable_length = e1000_cable_length_80_110; |
| 3345 | else if (average <= e1000_igp_cable_length_140) |
| 3346 | phy_info->cable_length = e1000_cable_length_110_140; |
| 3347 | else |
| 3348 | phy_info->cable_length = e1000_cable_length_140; |
| 3349 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3351 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | } |
| 3353 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3354 | /** |
| 3355 | * e1000_phy_m88_get_info - get m88 specific registers |
| 3356 | * @hw: Struct containing variables accessed by shared code |
| 3357 | * @phy_info: PHY information structure |
| 3358 | * |
| 3359 | * Get PHY information from various PHY registers for m88 PHY only. |
| 3360 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3361 | static s32 e1000_phy_m88_get_info(struct e1000_hw *hw, |
| 3362 | struct e1000_phy_info *phy_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3364 | s32 ret_val; |
| 3365 | u16 phy_data; |
| 3366 | e1000_rev_polarity polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3368 | e_dbg("e1000_phy_m88_get_info"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3370 | /* The downshift status is checked only once, after link is established, |
| 3371 | * and it stored in the hw->speed_downgraded parameter. */ |
| 3372 | phy_info->downshift = (e1000_downshift) hw->speed_downgraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3374 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 3375 | if (ret_val) |
| 3376 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3378 | phy_info->extended_10bt_distance = |
| 3379 | ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >> |
| 3380 | M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ? |
| 3381 | e1000_10bt_ext_dist_enable_lower : |
| 3382 | e1000_10bt_ext_dist_enable_normal; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3383 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3384 | phy_info->polarity_correction = |
| 3385 | ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >> |
| 3386 | M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ? |
| 3387 | e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3389 | /* Check polarity status */ |
| 3390 | ret_val = e1000_check_polarity(hw, &polarity); |
| 3391 | if (ret_val) |
| 3392 | return ret_val; |
| 3393 | phy_info->cable_polarity = polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3395 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); |
| 3396 | if (ret_val) |
| 3397 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3399 | phy_info->mdix_mode = |
| 3400 | (e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >> |
| 3401 | M88E1000_PSSR_MDIX_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3403 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) { |
| 3404 | /* Cable Length Estimation and Local/Remote Receiver Information |
| 3405 | * are only valid at 1000 Mbps. |
| 3406 | */ |
| 3407 | phy_info->cable_length = |
| 3408 | (e1000_cable_length) ((phy_data & |
| 3409 | M88E1000_PSSR_CABLE_LENGTH) >> |
| 3410 | M88E1000_PSSR_CABLE_LENGTH_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3412 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); |
| 3413 | if (ret_val) |
| 3414 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3416 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> |
| 3417 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? |
| 3418 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
| 3419 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> |
| 3420 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? |
| 3421 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3423 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3425 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | } |
| 3427 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3428 | /** |
| 3429 | * e1000_phy_get_info - request phy info |
| 3430 | * @hw: Struct containing variables accessed by shared code |
| 3431 | * @phy_info: PHY information structure |
| 3432 | * |
| 3433 | * Get PHY information from various PHY registers |
| 3434 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3435 | 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] | 3436 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3437 | s32 ret_val; |
| 3438 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3439 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3440 | e_dbg("e1000_phy_get_info"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3441 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3442 | phy_info->cable_length = e1000_cable_length_undefined; |
| 3443 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined; |
| 3444 | phy_info->cable_polarity = e1000_rev_polarity_undefined; |
| 3445 | phy_info->downshift = e1000_downshift_undefined; |
| 3446 | phy_info->polarity_correction = e1000_polarity_reversal_undefined; |
| 3447 | phy_info->mdix_mode = e1000_auto_x_mode_undefined; |
| 3448 | phy_info->local_rx = e1000_1000t_rx_status_undefined; |
| 3449 | phy_info->remote_rx = e1000_1000t_rx_status_undefined; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3451 | if (hw->media_type != e1000_media_type_copper) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3452 | e_dbg("PHY info is only valid for copper media\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3453 | return -E1000_ERR_CONFIG; |
| 3454 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3456 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 3457 | if (ret_val) |
| 3458 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3460 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 3461 | if (ret_val) |
| 3462 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3464 | if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3465 | e_dbg("PHY info is only valid if link is up\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3466 | return -E1000_ERR_CONFIG; |
| 3467 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3469 | if (hw->phy_type == e1000_phy_igp) |
| 3470 | return e1000_phy_igp_get_info(hw, phy_info); |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3471 | else if ((hw->phy_type == e1000_phy_8211) || |
| 3472 | (hw->phy_type == e1000_phy_8201)) |
| 3473 | return E1000_SUCCESS; |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3474 | else |
| 3475 | return e1000_phy_m88_get_info(hw, phy_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | } |
| 3477 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3478 | s32 e1000_validate_mdi_setting(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3479 | { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3480 | e_dbg("e1000_validate_mdi_settings"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3481 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3482 | if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3483 | e_dbg("Invalid MDI setting detected\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3484 | hw->mdix = 1; |
| 3485 | return -E1000_ERR_CONFIG; |
| 3486 | } |
| 3487 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | } |
| 3489 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3490 | /** |
| 3491 | * e1000_init_eeprom_params - initialize sw eeprom vars |
| 3492 | * @hw: Struct containing variables accessed by shared code |
| 3493 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | * 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] | 3495 | * is configured. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3496 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3497 | s32 e1000_init_eeprom_params(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3499 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 3500 | u32 eecd = er32(EECD); |
| 3501 | s32 ret_val = E1000_SUCCESS; |
| 3502 | u16 eeprom_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3504 | e_dbg("e1000_init_eeprom_params"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3505 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3506 | switch (hw->mac_type) { |
| 3507 | case e1000_82542_rev2_0: |
| 3508 | case e1000_82542_rev2_1: |
| 3509 | case e1000_82543: |
| 3510 | case e1000_82544: |
| 3511 | eeprom->type = e1000_eeprom_microwire; |
| 3512 | eeprom->word_size = 64; |
| 3513 | eeprom->opcode_bits = 3; |
| 3514 | eeprom->address_bits = 6; |
| 3515 | eeprom->delay_usec = 50; |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3516 | break; |
| 3517 | case e1000_82540: |
| 3518 | case e1000_82545: |
| 3519 | case e1000_82545_rev_3: |
| 3520 | case e1000_82546: |
| 3521 | case e1000_82546_rev_3: |
| 3522 | eeprom->type = e1000_eeprom_microwire; |
| 3523 | eeprom->opcode_bits = 3; |
| 3524 | eeprom->delay_usec = 50; |
| 3525 | if (eecd & E1000_EECD_SIZE) { |
| 3526 | eeprom->word_size = 256; |
| 3527 | eeprom->address_bits = 8; |
| 3528 | } else { |
| 3529 | eeprom->word_size = 64; |
| 3530 | eeprom->address_bits = 6; |
| 3531 | } |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3532 | break; |
| 3533 | case e1000_82541: |
| 3534 | case e1000_82541_rev_2: |
| 3535 | case e1000_82547: |
| 3536 | case e1000_82547_rev_2: |
| 3537 | if (eecd & E1000_EECD_TYPE) { |
| 3538 | eeprom->type = e1000_eeprom_spi; |
| 3539 | eeprom->opcode_bits = 8; |
| 3540 | eeprom->delay_usec = 1; |
| 3541 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 3542 | eeprom->page_size = 32; |
| 3543 | eeprom->address_bits = 16; |
| 3544 | } else { |
| 3545 | eeprom->page_size = 8; |
| 3546 | eeprom->address_bits = 8; |
| 3547 | } |
| 3548 | } else { |
| 3549 | eeprom->type = e1000_eeprom_microwire; |
| 3550 | eeprom->opcode_bits = 3; |
| 3551 | eeprom->delay_usec = 50; |
| 3552 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 3553 | eeprom->word_size = 256; |
| 3554 | eeprom->address_bits = 8; |
| 3555 | } else { |
| 3556 | eeprom->word_size = 64; |
| 3557 | eeprom->address_bits = 6; |
| 3558 | } |
| 3559 | } |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3560 | break; |
| 3561 | default: |
| 3562 | break; |
| 3563 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3565 | if (eeprom->type == e1000_eeprom_spi) { |
| 3566 | /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to |
| 3567 | * 32KB (incremented by powers of 2). |
| 3568 | */ |
| 3569 | /* Set to default value for initial eeprom read. */ |
| 3570 | eeprom->word_size = 64; |
| 3571 | ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size); |
| 3572 | if (ret_val) |
| 3573 | return ret_val; |
| 3574 | eeprom_size = |
| 3575 | (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT; |
| 3576 | /* 256B eeprom size was not supported in earlier hardware, so we |
| 3577 | * bump eeprom_size up one to ensure that "1" (which maps to 256B) |
| 3578 | * is never the result used in the shifting logic below. */ |
| 3579 | if (eeprom_size) |
| 3580 | eeprom_size++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3581 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3582 | eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT); |
| 3583 | } |
| 3584 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3587 | /** |
| 3588 | * e1000_raise_ee_clk - Raises the EEPROM's clock input. |
| 3589 | * @hw: Struct containing variables accessed by shared code |
| 3590 | * @eecd: EECD's current value |
| 3591 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3592 | static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3594 | /* Raise the clock input to the EEPROM (by setting the SK bit), and then |
| 3595 | * wait <delay> microseconds. |
| 3596 | */ |
| 3597 | *eecd = *eecd | E1000_EECD_SK; |
| 3598 | ew32(EECD, *eecd); |
| 3599 | E1000_WRITE_FLUSH(); |
| 3600 | udelay(hw->eeprom.delay_usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | } |
| 3602 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3603 | /** |
| 3604 | * e1000_lower_ee_clk - Lowers the EEPROM's clock input. |
| 3605 | * @hw: Struct containing variables accessed by shared code |
| 3606 | * @eecd: EECD's current value |
| 3607 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3608 | static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3610 | /* Lower the clock input to the EEPROM (by clearing the SK bit), and then |
| 3611 | * wait 50 microseconds. |
| 3612 | */ |
| 3613 | *eecd = *eecd & ~E1000_EECD_SK; |
| 3614 | ew32(EECD, *eecd); |
| 3615 | E1000_WRITE_FLUSH(); |
| 3616 | udelay(hw->eeprom.delay_usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | } |
| 3618 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3619 | /** |
| 3620 | * e1000_shift_out_ee_bits - Shift data bits out to the EEPROM. |
| 3621 | * @hw: Struct containing variables accessed by shared code |
| 3622 | * @data: data to send to the EEPROM |
| 3623 | * @count: number of bits to shift out |
| 3624 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3625 | 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] | 3626 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3627 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 3628 | u32 eecd; |
| 3629 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3631 | /* We need to shift "count" bits out to the EEPROM. So, value in the |
| 3632 | * "data" parameter will be shifted out to the EEPROM one bit at a time. |
| 3633 | * In order to do this, "data" must be broken down into bits. |
| 3634 | */ |
| 3635 | mask = 0x01 << (count - 1); |
| 3636 | eecd = er32(EECD); |
| 3637 | if (eeprom->type == e1000_eeprom_microwire) { |
| 3638 | eecd &= ~E1000_EECD_DO; |
| 3639 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 3640 | eecd |= E1000_EECD_DO; |
| 3641 | } |
| 3642 | do { |
| 3643 | /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1", |
| 3644 | * and then raising and then lowering the clock (the SK bit controls |
| 3645 | * the clock input to the EEPROM). A "0" is shifted out to the EEPROM |
| 3646 | * by setting "DI" to "0" and then raising and then lowering the clock. |
| 3647 | */ |
| 3648 | eecd &= ~E1000_EECD_DI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3649 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3650 | if (data & mask) |
| 3651 | eecd |= E1000_EECD_DI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3653 | ew32(EECD, eecd); |
| 3654 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3656 | udelay(eeprom->delay_usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3658 | e1000_raise_ee_clk(hw, &eecd); |
| 3659 | e1000_lower_ee_clk(hw, &eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3661 | mask = mask >> 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3663 | } while (mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3665 | /* We leave the "DI" bit set to "0" when we leave this routine. */ |
| 3666 | eecd &= ~E1000_EECD_DI; |
| 3667 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | } |
| 3669 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3670 | /** |
| 3671 | * e1000_shift_in_ee_bits - Shift data bits in from the EEPROM |
| 3672 | * @hw: Struct containing variables accessed by shared code |
| 3673 | * @count: number of bits to shift in |
| 3674 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3675 | 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] | 3676 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3677 | u32 eecd; |
| 3678 | u32 i; |
| 3679 | u16 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3681 | /* In order to read a register from the EEPROM, we need to shift 'count' |
| 3682 | * bits in from the EEPROM. Bits are "shifted in" by raising the clock |
| 3683 | * input to the EEPROM (setting the SK bit), and then reading the value of |
| 3684 | * the "DO" bit. During this "shifting in" process the "DI" bit should |
| 3685 | * always be clear. |
| 3686 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3688 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3690 | eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); |
| 3691 | data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3693 | for (i = 0; i < count; i++) { |
| 3694 | data = data << 1; |
| 3695 | e1000_raise_ee_clk(hw, &eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3697 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3699 | eecd &= ~(E1000_EECD_DI); |
| 3700 | if (eecd & E1000_EECD_DO) |
| 3701 | data |= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3703 | e1000_lower_ee_clk(hw, &eecd); |
| 3704 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3705 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3706 | return data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 | } |
| 3708 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3709 | /** |
| 3710 | * e1000_acquire_eeprom - Prepares EEPROM for access |
| 3711 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 | * |
| 3713 | * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This |
| 3714 | * function should be called before issuing a command to the EEPROM. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3715 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3716 | static s32 e1000_acquire_eeprom(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3718 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 3719 | u32 eecd, i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3721 | e_dbg("e1000_acquire_eeprom"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3722 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3723 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3724 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3725 | /* Request EEPROM Access */ |
| 3726 | if (hw->mac_type > e1000_82544) { |
| 3727 | eecd |= E1000_EECD_REQ; |
| 3728 | ew32(EECD, eecd); |
| 3729 | eecd = er32(EECD); |
| 3730 | while ((!(eecd & E1000_EECD_GNT)) && |
| 3731 | (i < E1000_EEPROM_GRANT_ATTEMPTS)) { |
| 3732 | i++; |
| 3733 | udelay(5); |
| 3734 | eecd = er32(EECD); |
| 3735 | } |
| 3736 | if (!(eecd & E1000_EECD_GNT)) { |
| 3737 | eecd &= ~E1000_EECD_REQ; |
| 3738 | ew32(EECD, eecd); |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3739 | e_dbg("Could not acquire EEPROM grant\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3740 | return -E1000_ERR_EEPROM; |
| 3741 | } |
| 3742 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3743 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3744 | /* Setup EEPROM for Read/Write */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3746 | if (eeprom->type == e1000_eeprom_microwire) { |
| 3747 | /* Clear SK and DI */ |
| 3748 | eecd &= ~(E1000_EECD_DI | E1000_EECD_SK); |
| 3749 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3751 | /* Set CS */ |
| 3752 | eecd |= E1000_EECD_CS; |
| 3753 | ew32(EECD, eecd); |
| 3754 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 3755 | /* Clear SK and CS */ |
| 3756 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
| 3757 | ew32(EECD, eecd); |
| 3758 | udelay(1); |
| 3759 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3760 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3761 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3762 | } |
| 3763 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3764 | /** |
| 3765 | * e1000_standby_eeprom - Returns EEPROM to a "standby" state |
| 3766 | * @hw: Struct containing variables accessed by shared code |
| 3767 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3768 | static void e1000_standby_eeprom(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3770 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 3771 | u32 eecd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3773 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3775 | if (eeprom->type == e1000_eeprom_microwire) { |
| 3776 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
| 3777 | ew32(EECD, eecd); |
| 3778 | E1000_WRITE_FLUSH(); |
| 3779 | udelay(eeprom->delay_usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3780 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3781 | /* Clock high */ |
| 3782 | eecd |= E1000_EECD_SK; |
| 3783 | ew32(EECD, eecd); |
| 3784 | E1000_WRITE_FLUSH(); |
| 3785 | udelay(eeprom->delay_usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3786 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3787 | /* Select EEPROM */ |
| 3788 | eecd |= E1000_EECD_CS; |
| 3789 | ew32(EECD, eecd); |
| 3790 | E1000_WRITE_FLUSH(); |
| 3791 | udelay(eeprom->delay_usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3793 | /* Clock low */ |
| 3794 | eecd &= ~E1000_EECD_SK; |
| 3795 | ew32(EECD, eecd); |
| 3796 | E1000_WRITE_FLUSH(); |
| 3797 | udelay(eeprom->delay_usec); |
| 3798 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 3799 | /* Toggle CS to flush commands */ |
| 3800 | eecd |= E1000_EECD_CS; |
| 3801 | ew32(EECD, eecd); |
| 3802 | E1000_WRITE_FLUSH(); |
| 3803 | udelay(eeprom->delay_usec); |
| 3804 | eecd &= ~E1000_EECD_CS; |
| 3805 | ew32(EECD, eecd); |
| 3806 | E1000_WRITE_FLUSH(); |
| 3807 | udelay(eeprom->delay_usec); |
| 3808 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | } |
| 3810 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3811 | /** |
| 3812 | * e1000_release_eeprom - drop chip select |
| 3813 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3815 | * Terminates a command by inverting the EEPROM's chip select pin |
| 3816 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3817 | static void e1000_release_eeprom(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3819 | u32 eecd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3821 | e_dbg("e1000_release_eeprom"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3823 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3825 | if (hw->eeprom.type == e1000_eeprom_spi) { |
| 3826 | eecd |= E1000_EECD_CS; /* Pull CS high */ |
| 3827 | eecd &= ~E1000_EECD_SK; /* Lower SCK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3829 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3831 | udelay(hw->eeprom.delay_usec); |
| 3832 | } else if (hw->eeprom.type == e1000_eeprom_microwire) { |
| 3833 | /* cleanup eeprom */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3835 | /* CS on Microwire is active-high */ |
| 3836 | eecd &= ~(E1000_EECD_CS | E1000_EECD_DI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3838 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3840 | /* Rising edge of clock */ |
| 3841 | eecd |= E1000_EECD_SK; |
| 3842 | ew32(EECD, eecd); |
| 3843 | E1000_WRITE_FLUSH(); |
| 3844 | udelay(hw->eeprom.delay_usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3846 | /* Falling edge of clock */ |
| 3847 | eecd &= ~E1000_EECD_SK; |
| 3848 | ew32(EECD, eecd); |
| 3849 | E1000_WRITE_FLUSH(); |
| 3850 | udelay(hw->eeprom.delay_usec); |
| 3851 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3852 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3853 | /* Stop requesting EEPROM access */ |
| 3854 | if (hw->mac_type > e1000_82544) { |
| 3855 | eecd &= ~E1000_EECD_REQ; |
| 3856 | ew32(EECD, eecd); |
| 3857 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3858 | } |
| 3859 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3860 | /** |
| 3861 | * e1000_spi_eeprom_ready - Reads a 16 bit word from the EEPROM. |
| 3862 | * @hw: Struct containing variables accessed by shared code |
| 3863 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3864 | static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3866 | u16 retry_count = 0; |
| 3867 | u8 spi_stat_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3868 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3869 | e_dbg("e1000_spi_eeprom_ready"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3871 | /* Read "Status Register" repeatedly until the LSB is cleared. The |
| 3872 | * EEPROM will signal that the command has been completed by clearing |
| 3873 | * bit 0 of the internal status register. If it's not cleared within |
| 3874 | * 5 milliseconds, then error out. |
| 3875 | */ |
| 3876 | retry_count = 0; |
| 3877 | do { |
| 3878 | e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI, |
| 3879 | hw->eeprom.opcode_bits); |
| 3880 | spi_stat_reg = (u8) e1000_shift_in_ee_bits(hw, 8); |
| 3881 | if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI)) |
| 3882 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3883 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3884 | udelay(5); |
| 3885 | retry_count += 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3886 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3887 | e1000_standby_eeprom(hw); |
| 3888 | } while (retry_count < EEPROM_MAX_RETRY_SPI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3889 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3890 | /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and |
| 3891 | * only 0-5mSec on 5V devices) |
| 3892 | */ |
| 3893 | if (retry_count >= EEPROM_MAX_RETRY_SPI) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3894 | e_dbg("SPI EEPROM Status error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3895 | return -E1000_ERR_EEPROM; |
| 3896 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3897 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3898 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | } |
| 3900 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3901 | /** |
| 3902 | * e1000_read_eeprom - Reads a 16 bit word from the EEPROM. |
| 3903 | * @hw: Struct containing variables accessed by shared code |
| 3904 | * @offset: offset of word in the EEPROM to read |
| 3905 | * @data: word read from the EEPROM |
| 3906 | * @words: number of words to read |
| 3907 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3908 | 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] | 3909 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3910 | s32 ret; |
| 3911 | spin_lock(&e1000_eeprom_lock); |
| 3912 | ret = e1000_do_read_eeprom(hw, offset, words, data); |
| 3913 | spin_unlock(&e1000_eeprom_lock); |
| 3914 | return ret; |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 3915 | } |
| 3916 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3917 | static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, |
| 3918 | u16 *data) |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 3919 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3920 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 3921 | u32 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3922 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3923 | e_dbg("e1000_read_eeprom"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3924 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3925 | if (hw->mac_type == e1000_ce4100) { |
| 3926 | GBE_CONFIG_FLASH_READ(GBE_CONFIG_BASE_VIRT, offset, words, |
| 3927 | data); |
| 3928 | return E1000_SUCCESS; |
| 3929 | } |
| 3930 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3931 | /* If eeprom is not yet detected, do so now */ |
| 3932 | if (eeprom->word_size == 0) |
| 3933 | e1000_init_eeprom_params(hw); |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3934 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3935 | /* A check for invalid values: offset too large, too many words, and not |
| 3936 | * enough words. |
| 3937 | */ |
| 3938 | if ((offset >= eeprom->word_size) |
| 3939 | || (words > eeprom->word_size - offset) || (words == 0)) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3940 | e_dbg("\"words\" parameter out of bounds. Words = %d," |
| 3941 | "size = %d\n", offset, eeprom->word_size); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3942 | return -E1000_ERR_EEPROM; |
| 3943 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3945 | /* EEPROM's that don't use EERD to read require us to bit-bang the SPI |
| 3946 | * directly. In this case, we need to acquire the EEPROM so that |
| 3947 | * FW or other port software does not interrupt. |
| 3948 | */ |
Jesse Brandeburg | 8f601b2 | 2009-09-25 12:20:11 +0000 | [diff] [blame] | 3949 | /* Prepare the EEPROM for bit-bang reading */ |
| 3950 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) |
| 3951 | return -E1000_ERR_EEPROM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3953 | /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have |
| 3954 | * acquired the EEPROM at this point, so any returns should release it */ |
| 3955 | if (eeprom->type == e1000_eeprom_spi) { |
| 3956 | u16 word_in; |
| 3957 | u8 read_opcode = EEPROM_READ_OPCODE_SPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3959 | if (e1000_spi_eeprom_ready(hw)) { |
| 3960 | e1000_release_eeprom(hw); |
| 3961 | return -E1000_ERR_EEPROM; |
| 3962 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3964 | e1000_standby_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3965 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3966 | /* Some SPI eeproms use the 8th address bit embedded in the opcode */ |
| 3967 | if ((eeprom->address_bits == 8) && (offset >= 128)) |
| 3968 | read_opcode |= EEPROM_A8_OPCODE_SPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3970 | /* Send the READ command (opcode + addr) */ |
| 3971 | e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits); |
| 3972 | e1000_shift_out_ee_bits(hw, (u16) (offset * 2), |
| 3973 | eeprom->address_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3975 | /* Read the data. The address of the eeprom internally increments with |
| 3976 | * each byte (spi) being read, saving on the overhead of eeprom setup |
| 3977 | * and tear-down. The address counter will roll over if reading beyond |
| 3978 | * the size of the eeprom, thus allowing the entire memory to be read |
| 3979 | * starting from any offset. */ |
| 3980 | for (i = 0; i < words; i++) { |
| 3981 | word_in = e1000_shift_in_ee_bits(hw, 16); |
| 3982 | data[i] = (word_in >> 8) | (word_in << 8); |
| 3983 | } |
| 3984 | } else if (eeprom->type == e1000_eeprom_microwire) { |
| 3985 | for (i = 0; i < words; i++) { |
| 3986 | /* Send the READ command (opcode + addr) */ |
| 3987 | e1000_shift_out_ee_bits(hw, |
| 3988 | EEPROM_READ_OPCODE_MICROWIRE, |
| 3989 | eeprom->opcode_bits); |
| 3990 | e1000_shift_out_ee_bits(hw, (u16) (offset + i), |
| 3991 | eeprom->address_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3992 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3993 | /* Read the data. For microwire, each word requires the overhead |
| 3994 | * of eeprom setup and tear-down. */ |
| 3995 | data[i] = e1000_shift_in_ee_bits(hw, 16); |
| 3996 | e1000_standby_eeprom(hw); |
| 3997 | } |
| 3998 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4000 | /* End this read operation */ |
| 4001 | e1000_release_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4002 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4003 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | } |
| 4005 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4006 | /** |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4007 | * e1000_validate_eeprom_checksum - Verifies that the EEPROM has a valid checksum |
| 4008 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4009 | * |
| 4010 | * Reads the first 64 16 bit words of the EEPROM and sums the values read. |
| 4011 | * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is |
| 4012 | * valid. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4013 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4014 | s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4016 | u16 checksum = 0; |
| 4017 | u16 i, eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4019 | e_dbg("e1000_validate_eeprom_checksum"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4020 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4021 | for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) { |
| 4022 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4023 | e_dbg("EEPROM Read Error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4024 | return -E1000_ERR_EEPROM; |
| 4025 | } |
| 4026 | checksum += eeprom_data; |
| 4027 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4028 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4029 | if (checksum == (u16) EEPROM_SUM) |
| 4030 | return E1000_SUCCESS; |
| 4031 | else { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4032 | e_dbg("EEPROM Checksum Invalid\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4033 | return -E1000_ERR_EEPROM; |
| 4034 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | } |
| 4036 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4037 | /** |
| 4038 | * e1000_update_eeprom_checksum - Calculates/writes the EEPROM checksum |
| 4039 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | * |
| 4041 | * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA. |
| 4042 | * Writes the difference to word offset 63 of the EEPROM. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4043 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4044 | s32 e1000_update_eeprom_checksum(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4046 | u16 checksum = 0; |
| 4047 | u16 i, eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4048 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4049 | e_dbg("e1000_update_eeprom_checksum"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4051 | for (i = 0; i < EEPROM_CHECKSUM_REG; i++) { |
| 4052 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4053 | e_dbg("EEPROM Read Error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4054 | return -E1000_ERR_EEPROM; |
| 4055 | } |
| 4056 | checksum += eeprom_data; |
| 4057 | } |
| 4058 | checksum = (u16) EEPROM_SUM - checksum; |
| 4059 | if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4060 | e_dbg("EEPROM Write Error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4061 | return -E1000_ERR_EEPROM; |
| 4062 | } |
| 4063 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | } |
| 4065 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4066 | /** |
| 4067 | * e1000_write_eeprom - write words to the different EEPROM types. |
| 4068 | * @hw: Struct containing variables accessed by shared code |
| 4069 | * @offset: offset within the EEPROM to be written to |
| 4070 | * @words: number of words to write |
| 4071 | * @data: 16 bit word to be written to the EEPROM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | * |
| 4073 | * If e1000_update_eeprom_checksum is not called after this function, the |
| 4074 | * EEPROM will most likely contain an invalid checksum. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4075 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4076 | 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] | 4077 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4078 | s32 ret; |
| 4079 | spin_lock(&e1000_eeprom_lock); |
| 4080 | ret = e1000_do_write_eeprom(hw, offset, words, data); |
| 4081 | spin_unlock(&e1000_eeprom_lock); |
| 4082 | return ret; |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 4083 | } |
| 4084 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4085 | static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, |
| 4086 | u16 *data) |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 4087 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4088 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 4089 | s32 status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4091 | e_dbg("e1000_write_eeprom"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4092 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 4093 | if (hw->mac_type == e1000_ce4100) { |
| 4094 | GBE_CONFIG_FLASH_WRITE(GBE_CONFIG_BASE_VIRT, offset, words, |
| 4095 | data); |
| 4096 | return E1000_SUCCESS; |
| 4097 | } |
| 4098 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4099 | /* If eeprom is not yet detected, do so now */ |
| 4100 | if (eeprom->word_size == 0) |
| 4101 | e1000_init_eeprom_params(hw); |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4102 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4103 | /* A check for invalid values: offset too large, too many words, and not |
| 4104 | * enough words. |
| 4105 | */ |
| 4106 | if ((offset >= eeprom->word_size) |
| 4107 | || (words > eeprom->word_size - offset) || (words == 0)) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4108 | e_dbg("\"words\" parameter out of bounds\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4109 | return -E1000_ERR_EEPROM; |
| 4110 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4111 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4112 | /* Prepare the EEPROM for writing */ |
| 4113 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) |
| 4114 | return -E1000_ERR_EEPROM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4116 | if (eeprom->type == e1000_eeprom_microwire) { |
| 4117 | status = e1000_write_eeprom_microwire(hw, offset, words, data); |
| 4118 | } else { |
| 4119 | status = e1000_write_eeprom_spi(hw, offset, words, data); |
| 4120 | msleep(10); |
| 4121 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4123 | /* Done with writing */ |
| 4124 | e1000_release_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4125 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4126 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4127 | } |
| 4128 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4129 | /** |
| 4130 | * e1000_write_eeprom_spi - Writes a 16 bit word to a given offset in an SPI EEPROM. |
| 4131 | * @hw: Struct containing variables accessed by shared code |
| 4132 | * @offset: offset within the EEPROM to be written to |
| 4133 | * @words: number of words to write |
| 4134 | * @data: pointer to array of 8 bit words to be written to the EEPROM |
| 4135 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4136 | static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words, |
| 4137 | u16 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4139 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 4140 | u16 widx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4142 | e_dbg("e1000_write_eeprom_spi"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4143 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4144 | while (widx < words) { |
| 4145 | u8 write_opcode = EEPROM_WRITE_OPCODE_SPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4147 | if (e1000_spi_eeprom_ready(hw)) |
| 4148 | return -E1000_ERR_EEPROM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4150 | e1000_standby_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4152 | /* Send the WRITE ENABLE command (8 bit opcode ) */ |
| 4153 | e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI, |
| 4154 | eeprom->opcode_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4156 | e1000_standby_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4158 | /* Some SPI eeproms use the 8th address bit embedded in the opcode */ |
| 4159 | if ((eeprom->address_bits == 8) && (offset >= 128)) |
| 4160 | write_opcode |= EEPROM_A8_OPCODE_SPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4162 | /* Send the Write command (8-bit opcode + addr) */ |
| 4163 | e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4165 | e1000_shift_out_ee_bits(hw, (u16) ((offset + widx) * 2), |
| 4166 | eeprom->address_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4167 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4168 | /* Send the data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4170 | /* Loop to allow for up to whole page write (32 bytes) of eeprom */ |
| 4171 | while (widx < words) { |
| 4172 | u16 word_out = data[widx]; |
| 4173 | word_out = (word_out >> 8) | (word_out << 8); |
| 4174 | e1000_shift_out_ee_bits(hw, word_out, 16); |
| 4175 | widx++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4176 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4177 | /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE |
| 4178 | * operation, while the smaller eeproms are capable of an 8-byte |
| 4179 | * PAGE WRITE operation. Break the inner loop to pass new address |
| 4180 | */ |
| 4181 | if ((((offset + widx) * 2) % eeprom->page_size) == 0) { |
| 4182 | e1000_standby_eeprom(hw); |
| 4183 | break; |
| 4184 | } |
| 4185 | } |
| 4186 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4187 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4188 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | } |
| 4190 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4191 | /** |
| 4192 | * e1000_write_eeprom_microwire - Writes a 16 bit word to a given offset in a Microwire EEPROM. |
| 4193 | * @hw: Struct containing variables accessed by shared code |
| 4194 | * @offset: offset within the EEPROM to be written to |
| 4195 | * @words: number of words to write |
| 4196 | * @data: pointer to array of 8 bit words to be written to the EEPROM |
| 4197 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4198 | static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset, |
| 4199 | u16 words, u16 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4201 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 4202 | u32 eecd; |
| 4203 | u16 words_written = 0; |
| 4204 | u16 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4205 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4206 | e_dbg("e1000_write_eeprom_microwire"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4208 | /* Send the write enable command to the EEPROM (3-bit opcode plus |
| 4209 | * 6/8-bit dummy address beginning with 11). It's less work to include |
| 4210 | * the 11 of the dummy address as part of the opcode than it is to shift |
| 4211 | * it over the correct number of bits for the address. This puts the |
| 4212 | * EEPROM into write/erase mode. |
| 4213 | */ |
| 4214 | e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE, |
| 4215 | (u16) (eeprom->opcode_bits + 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4216 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4217 | e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4219 | /* Prepare the EEPROM */ |
| 4220 | e1000_standby_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4222 | while (words_written < words) { |
| 4223 | /* Send the Write command (3-bit opcode + addr) */ |
| 4224 | e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE, |
| 4225 | eeprom->opcode_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4227 | e1000_shift_out_ee_bits(hw, (u16) (offset + words_written), |
| 4228 | eeprom->address_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4230 | /* Send the data */ |
| 4231 | e1000_shift_out_ee_bits(hw, data[words_written], 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4233 | /* Toggle the CS line. This in effect tells the EEPROM to execute |
| 4234 | * the previous command. |
| 4235 | */ |
| 4236 | e1000_standby_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4238 | /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will |
| 4239 | * signal that the command has been completed by raising the DO signal. |
| 4240 | * If DO does not go high in 10 milliseconds, then error out. |
| 4241 | */ |
| 4242 | for (i = 0; i < 200; i++) { |
| 4243 | eecd = er32(EECD); |
| 4244 | if (eecd & E1000_EECD_DO) |
| 4245 | break; |
| 4246 | udelay(50); |
| 4247 | } |
| 4248 | if (i == 200) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4249 | e_dbg("EEPROM Write did not complete\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4250 | return -E1000_ERR_EEPROM; |
| 4251 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4253 | /* Recover from write */ |
| 4254 | e1000_standby_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4255 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4256 | words_written++; |
| 4257 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4259 | /* Send the write disable command to the EEPROM (3-bit opcode plus |
| 4260 | * 6/8-bit dummy address beginning with 10). It's less work to include |
| 4261 | * the 10 of the dummy address as part of the opcode than it is to shift |
| 4262 | * it over the correct number of bits for the address. This takes the |
| 4263 | * EEPROM out of write/erase mode. |
| 4264 | */ |
| 4265 | e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE, |
| 4266 | (u16) (eeprom->opcode_bits + 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4268 | e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4270 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | } |
| 4272 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4273 | /** |
| 4274 | * e1000_read_mac_addr - read the adapters MAC from eeprom |
| 4275 | * @hw: Struct containing variables accessed by shared code |
| 4276 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the |
| 4278 | * second function of dual function devices |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4279 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4280 | s32 e1000_read_mac_addr(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4282 | u16 offset; |
| 4283 | u16 eeprom_data, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4285 | e_dbg("e1000_read_mac_addr"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4287 | for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) { |
| 4288 | offset = i >> 1; |
| 4289 | if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4290 | e_dbg("EEPROM Read Error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4291 | return -E1000_ERR_EEPROM; |
| 4292 | } |
| 4293 | hw->perm_mac_addr[i] = (u8) (eeprom_data & 0x00FF); |
| 4294 | hw->perm_mac_addr[i + 1] = (u8) (eeprom_data >> 8); |
| 4295 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4296 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4297 | switch (hw->mac_type) { |
| 4298 | default: |
| 4299 | break; |
| 4300 | case e1000_82546: |
| 4301 | case e1000_82546_rev_3: |
| 4302 | if (er32(STATUS) & E1000_STATUS_FUNC_1) |
| 4303 | hw->perm_mac_addr[5] ^= 0x01; |
| 4304 | break; |
| 4305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4306 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4307 | for (i = 0; i < NODE_ADDRESS_SIZE; i++) |
| 4308 | hw->mac_addr[i] = hw->perm_mac_addr[i]; |
| 4309 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | } |
| 4311 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4312 | /** |
| 4313 | * e1000_init_rx_addrs - Initializes receive address filters. |
| 4314 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | * |
| 4316 | * Places the MAC address in receive address register 0 and clears the rest |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4317 | * of the receive address registers. Clears the multicast table. Assumes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | * the receiver is in reset when the routine is called. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4319 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4320 | static void e1000_init_rx_addrs(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4322 | u32 i; |
| 4323 | u32 rar_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4325 | e_dbg("e1000_init_rx_addrs"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4327 | /* Setup the receive address. */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4328 | e_dbg("Programming MAC Address into RAR[0]\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4329 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4330 | e1000_rar_set(hw, hw->mac_addr, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4331 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4332 | rar_num = E1000_RAR_ENTRIES; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4333 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4334 | /* Zero out the other 15 receive addresses. */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4335 | e_dbg("Clearing RAR[1-15]\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4336 | for (i = 1; i < rar_num; i++) { |
| 4337 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0); |
| 4338 | E1000_WRITE_FLUSH(); |
| 4339 | E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0); |
| 4340 | E1000_WRITE_FLUSH(); |
| 4341 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | } |
| 4343 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4344 | /** |
| 4345 | * e1000_hash_mc_addr - Hashes an address to determine its location in the multicast table |
| 4346 | * @hw: Struct containing variables accessed by shared code |
| 4347 | * @mc_addr: the multicast address to hash |
| 4348 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4349 | u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4351 | u32 hash_value = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4352 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4353 | /* The portion of the address that is used for the hash table is |
| 4354 | * determined by the mc_filter_type setting. |
| 4355 | */ |
| 4356 | switch (hw->mc_filter_type) { |
| 4357 | /* [0] [1] [2] [3] [4] [5] |
| 4358 | * 01 AA 00 12 34 56 |
| 4359 | * LSB MSB |
| 4360 | */ |
| 4361 | case 0: |
| 4362 | /* [47:36] i.e. 0x563 for above example address */ |
| 4363 | hash_value = ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4)); |
| 4364 | break; |
| 4365 | case 1: |
| 4366 | /* [46:35] i.e. 0xAC6 for above example address */ |
| 4367 | hash_value = ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5)); |
| 4368 | break; |
| 4369 | case 2: |
| 4370 | /* [45:34] i.e. 0x5D8 for above example address */ |
| 4371 | hash_value = ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6)); |
| 4372 | break; |
| 4373 | case 3: |
| 4374 | /* [43:32] i.e. 0x634 for above example address */ |
| 4375 | hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8)); |
| 4376 | break; |
| 4377 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4378 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4379 | hash_value &= 0xFFF; |
| 4380 | return hash_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | } |
| 4382 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4383 | /** |
| 4384 | * e1000_rar_set - Puts an ethernet address into a receive address register. |
| 4385 | * @hw: Struct containing variables accessed by shared code |
| 4386 | * @addr: Address to put into receive address register |
| 4387 | * @index: Receive address register to write |
| 4388 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4389 | void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4391 | u32 rar_low, rar_high; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4392 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4393 | /* HW expects these in little endian so we reverse the byte order |
| 4394 | * from network order (big endian) to little endian |
| 4395 | */ |
| 4396 | rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) | |
| 4397 | ((u32) addr[2] << 16) | ((u32) addr[3] << 24)); |
| 4398 | rar_high = ((u32) addr[4] | ((u32) addr[5] << 8)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4400 | /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx |
| 4401 | * unit hang. |
| 4402 | * |
| 4403 | * Description: |
| 4404 | * If there are any Rx frames queued up or otherwise present in the HW |
| 4405 | * before RSS is enabled, and then we enable RSS, the HW Rx unit will |
| 4406 | * hang. To work around this issue, we have to disable receives and |
| 4407 | * flush out all Rx frames before we enable RSS. To do so, we modify we |
| 4408 | * redirect all Rx traffic to manageability and then reset the HW. |
| 4409 | * This flushes away Rx frames, and (since the redirections to |
| 4410 | * manageability persists across resets) keeps new ones from coming in |
| 4411 | * while we work. Then, we clear the Address Valid AV bit for all MAC |
| 4412 | * addresses and undo the re-direction to manageability. |
| 4413 | * Now, frames are coming in again, but the MAC won't accept them, so |
| 4414 | * far so good. We now proceed to initialize RSS (if necessary) and |
| 4415 | * configure the Rx unit. Last, we re-enable the AV bits and continue |
| 4416 | * on our merry way. |
| 4417 | */ |
| 4418 | switch (hw->mac_type) { |
| 4419 | default: |
| 4420 | /* Indicate to hardware the Address is Valid. */ |
| 4421 | rar_high |= E1000_RAH_AV; |
| 4422 | break; |
| 4423 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4425 | E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low); |
| 4426 | E1000_WRITE_FLUSH(); |
| 4427 | E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high); |
| 4428 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4429 | } |
| 4430 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4431 | /** |
| 4432 | * e1000_write_vfta - Writes a value to the specified offset in the VLAN filter table. |
| 4433 | * @hw: Struct containing variables accessed by shared code |
| 4434 | * @offset: Offset in VLAN filer table to write |
| 4435 | * @value: Value to write into VLAN filter table |
| 4436 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4437 | void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4438 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4439 | u32 temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4440 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4441 | if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) { |
| 4442 | temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1)); |
| 4443 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); |
| 4444 | E1000_WRITE_FLUSH(); |
| 4445 | E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp); |
| 4446 | E1000_WRITE_FLUSH(); |
| 4447 | } else { |
| 4448 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); |
| 4449 | E1000_WRITE_FLUSH(); |
| 4450 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | } |
| 4452 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4453 | /** |
| 4454 | * e1000_clear_vfta - Clears the VLAN filer table |
| 4455 | * @hw: Struct containing variables accessed by shared code |
| 4456 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4457 | static void e1000_clear_vfta(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4458 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4459 | u32 offset; |
| 4460 | u32 vfta_value = 0; |
| 4461 | u32 vfta_offset = 0; |
| 4462 | u32 vfta_bit_in_reg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4464 | for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) { |
| 4465 | /* If the offset we want to clear is the same offset of the |
| 4466 | * manageability VLAN ID, then clear all bits except that of the |
| 4467 | * manageability unit */ |
| 4468 | vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0; |
| 4469 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value); |
| 4470 | E1000_WRITE_FLUSH(); |
| 4471 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4472 | } |
| 4473 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4474 | static s32 e1000_id_led_init(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4476 | u32 ledctl; |
| 4477 | const u32 ledctl_mask = 0x000000FF; |
| 4478 | const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON; |
| 4479 | const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF; |
| 4480 | u16 eeprom_data, i, temp; |
| 4481 | const u16 led_mask = 0x0F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4483 | e_dbg("e1000_id_led_init"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4484 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4485 | if (hw->mac_type < e1000_82540) { |
| 4486 | /* Nothing to do */ |
| 4487 | return E1000_SUCCESS; |
| 4488 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4489 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4490 | ledctl = er32(LEDCTL); |
| 4491 | hw->ledctl_default = ledctl; |
| 4492 | hw->ledctl_mode1 = hw->ledctl_default; |
| 4493 | hw->ledctl_mode2 = hw->ledctl_default; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4495 | if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4496 | e_dbg("EEPROM Read Error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4497 | return -E1000_ERR_EEPROM; |
| 4498 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4499 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4500 | if ((eeprom_data == ID_LED_RESERVED_0000) || |
| 4501 | (eeprom_data == ID_LED_RESERVED_FFFF)) { |
| 4502 | eeprom_data = ID_LED_DEFAULT; |
| 4503 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4504 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4505 | for (i = 0; i < 4; i++) { |
| 4506 | temp = (eeprom_data >> (i << 2)) & led_mask; |
| 4507 | switch (temp) { |
| 4508 | case ID_LED_ON1_DEF2: |
| 4509 | case ID_LED_ON1_ON2: |
| 4510 | case ID_LED_ON1_OFF2: |
| 4511 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); |
| 4512 | hw->ledctl_mode1 |= ledctl_on << (i << 3); |
| 4513 | break; |
| 4514 | case ID_LED_OFF1_DEF2: |
| 4515 | case ID_LED_OFF1_ON2: |
| 4516 | case ID_LED_OFF1_OFF2: |
| 4517 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); |
| 4518 | hw->ledctl_mode1 |= ledctl_off << (i << 3); |
| 4519 | break; |
| 4520 | default: |
| 4521 | /* Do nothing */ |
| 4522 | break; |
| 4523 | } |
| 4524 | switch (temp) { |
| 4525 | case ID_LED_DEF1_ON2: |
| 4526 | case ID_LED_ON1_ON2: |
| 4527 | case ID_LED_OFF1_ON2: |
| 4528 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); |
| 4529 | hw->ledctl_mode2 |= ledctl_on << (i << 3); |
| 4530 | break; |
| 4531 | case ID_LED_DEF1_OFF2: |
| 4532 | case ID_LED_ON1_OFF2: |
| 4533 | case ID_LED_OFF1_OFF2: |
| 4534 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); |
| 4535 | hw->ledctl_mode2 |= ledctl_off << (i << 3); |
| 4536 | break; |
| 4537 | default: |
| 4538 | /* Do nothing */ |
| 4539 | break; |
| 4540 | } |
| 4541 | } |
| 4542 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4543 | } |
| 4544 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4545 | /** |
| 4546 | * e1000_setup_led |
| 4547 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4549 | * Prepares SW controlable LED for use and saves the current state of the LED. |
| 4550 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4551 | s32 e1000_setup_led(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4552 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4553 | u32 ledctl; |
| 4554 | s32 ret_val = E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4555 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4556 | e_dbg("e1000_setup_led"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4558 | switch (hw->mac_type) { |
| 4559 | case e1000_82542_rev2_0: |
| 4560 | case e1000_82542_rev2_1: |
| 4561 | case e1000_82543: |
| 4562 | case e1000_82544: |
| 4563 | /* No setup necessary */ |
| 4564 | break; |
| 4565 | case e1000_82541: |
| 4566 | case e1000_82547: |
| 4567 | case e1000_82541_rev_2: |
| 4568 | case e1000_82547_rev_2: |
| 4569 | /* Turn off PHY Smart Power Down (if enabled) */ |
| 4570 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 4571 | &hw->phy_spd_default); |
| 4572 | if (ret_val) |
| 4573 | return ret_val; |
| 4574 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 4575 | (u16) (hw->phy_spd_default & |
| 4576 | ~IGP01E1000_GMII_SPD)); |
| 4577 | if (ret_val) |
| 4578 | return ret_val; |
| 4579 | /* Fall Through */ |
| 4580 | default: |
| 4581 | if (hw->media_type == e1000_media_type_fiber) { |
| 4582 | ledctl = er32(LEDCTL); |
| 4583 | /* Save current LEDCTL settings */ |
| 4584 | hw->ledctl_default = ledctl; |
| 4585 | /* Turn off LED0 */ |
| 4586 | ledctl &= ~(E1000_LEDCTL_LED0_IVRT | |
| 4587 | E1000_LEDCTL_LED0_BLINK | |
| 4588 | E1000_LEDCTL_LED0_MODE_MASK); |
| 4589 | ledctl |= (E1000_LEDCTL_MODE_LED_OFF << |
| 4590 | E1000_LEDCTL_LED0_MODE_SHIFT); |
| 4591 | ew32(LEDCTL, ledctl); |
| 4592 | } else if (hw->media_type == e1000_media_type_copper) |
| 4593 | ew32(LEDCTL, hw->ledctl_mode1); |
| 4594 | break; |
| 4595 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4597 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4598 | } |
| 4599 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4600 | /** |
| 4601 | * e1000_cleanup_led - Restores the saved state of the SW controlable LED. |
| 4602 | * @hw: Struct containing variables accessed by shared code |
| 4603 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4604 | s32 e1000_cleanup_led(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4606 | s32 ret_val = E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4607 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4608 | e_dbg("e1000_cleanup_led"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4609 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4610 | switch (hw->mac_type) { |
| 4611 | case e1000_82542_rev2_0: |
| 4612 | case e1000_82542_rev2_1: |
| 4613 | case e1000_82543: |
| 4614 | case e1000_82544: |
| 4615 | /* No cleanup necessary */ |
| 4616 | break; |
| 4617 | case e1000_82541: |
| 4618 | case e1000_82547: |
| 4619 | case e1000_82541_rev_2: |
| 4620 | case e1000_82547_rev_2: |
| 4621 | /* Turn on PHY Smart Power Down (if previously enabled) */ |
| 4622 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 4623 | hw->phy_spd_default); |
| 4624 | if (ret_val) |
| 4625 | return ret_val; |
| 4626 | /* Fall Through */ |
| 4627 | default: |
| 4628 | /* Restore LEDCTL settings */ |
| 4629 | ew32(LEDCTL, hw->ledctl_default); |
| 4630 | break; |
| 4631 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4632 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4633 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4634 | } |
| 4635 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4636 | /** |
| 4637 | * e1000_led_on - Turns on the software controllable LED |
| 4638 | * @hw: Struct containing variables accessed by shared code |
| 4639 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4640 | s32 e1000_led_on(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4642 | u32 ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4643 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4644 | e_dbg("e1000_led_on"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4645 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4646 | switch (hw->mac_type) { |
| 4647 | case e1000_82542_rev2_0: |
| 4648 | case e1000_82542_rev2_1: |
| 4649 | case e1000_82543: |
| 4650 | /* Set SW Defineable Pin 0 to turn on the LED */ |
| 4651 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4652 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4653 | break; |
| 4654 | case e1000_82544: |
| 4655 | if (hw->media_type == e1000_media_type_fiber) { |
| 4656 | /* Set SW Defineable Pin 0 to turn on the LED */ |
| 4657 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4658 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4659 | } else { |
| 4660 | /* Clear SW Defineable Pin 0 to turn on the LED */ |
| 4661 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4662 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4663 | } |
| 4664 | break; |
| 4665 | default: |
| 4666 | if (hw->media_type == e1000_media_type_fiber) { |
| 4667 | /* Clear SW Defineable Pin 0 to turn on the LED */ |
| 4668 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4669 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4670 | } else if (hw->media_type == e1000_media_type_copper) { |
| 4671 | ew32(LEDCTL, hw->ledctl_mode2); |
| 4672 | return E1000_SUCCESS; |
| 4673 | } |
| 4674 | break; |
| 4675 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4676 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4677 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4678 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4679 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 | } |
| 4681 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4682 | /** |
| 4683 | * e1000_led_off - Turns off the software controllable LED |
| 4684 | * @hw: Struct containing variables accessed by shared code |
| 4685 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4686 | s32 e1000_led_off(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4687 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4688 | u32 ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4689 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4690 | e_dbg("e1000_led_off"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4691 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4692 | switch (hw->mac_type) { |
| 4693 | case e1000_82542_rev2_0: |
| 4694 | case e1000_82542_rev2_1: |
| 4695 | case e1000_82543: |
| 4696 | /* Clear SW Defineable Pin 0 to turn off the LED */ |
| 4697 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4698 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4699 | break; |
| 4700 | case e1000_82544: |
| 4701 | if (hw->media_type == e1000_media_type_fiber) { |
| 4702 | /* Clear SW Defineable Pin 0 to turn off the LED */ |
| 4703 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4704 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4705 | } else { |
| 4706 | /* Set SW Defineable Pin 0 to turn off the LED */ |
| 4707 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4708 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4709 | } |
| 4710 | break; |
| 4711 | default: |
| 4712 | if (hw->media_type == e1000_media_type_fiber) { |
| 4713 | /* Set SW Defineable Pin 0 to turn off the LED */ |
| 4714 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4715 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4716 | } else if (hw->media_type == e1000_media_type_copper) { |
| 4717 | ew32(LEDCTL, hw->ledctl_mode1); |
| 4718 | return E1000_SUCCESS; |
| 4719 | } |
| 4720 | break; |
| 4721 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4723 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4724 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4725 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4726 | } |
| 4727 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4728 | /** |
| 4729 | * e1000_clear_hw_cntrs - Clears all hardware statistics counters. |
| 4730 | * @hw: Struct containing variables accessed by shared code |
| 4731 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4732 | static void e1000_clear_hw_cntrs(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4733 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4734 | volatile u32 temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4735 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4736 | temp = er32(CRCERRS); |
| 4737 | temp = er32(SYMERRS); |
| 4738 | temp = er32(MPC); |
| 4739 | temp = er32(SCC); |
| 4740 | temp = er32(ECOL); |
| 4741 | temp = er32(MCC); |
| 4742 | temp = er32(LATECOL); |
| 4743 | temp = er32(COLC); |
| 4744 | temp = er32(DC); |
| 4745 | temp = er32(SEC); |
| 4746 | temp = er32(RLEC); |
| 4747 | temp = er32(XONRXC); |
| 4748 | temp = er32(XONTXC); |
| 4749 | temp = er32(XOFFRXC); |
| 4750 | temp = er32(XOFFTXC); |
| 4751 | temp = er32(FCRUC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4752 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4753 | temp = er32(PRC64); |
| 4754 | temp = er32(PRC127); |
| 4755 | temp = er32(PRC255); |
| 4756 | temp = er32(PRC511); |
| 4757 | temp = er32(PRC1023); |
| 4758 | temp = er32(PRC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4759 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4760 | temp = er32(GPRC); |
| 4761 | temp = er32(BPRC); |
| 4762 | temp = er32(MPRC); |
| 4763 | temp = er32(GPTC); |
| 4764 | temp = er32(GORCL); |
| 4765 | temp = er32(GORCH); |
| 4766 | temp = er32(GOTCL); |
| 4767 | temp = er32(GOTCH); |
| 4768 | temp = er32(RNBC); |
| 4769 | temp = er32(RUC); |
| 4770 | temp = er32(RFC); |
| 4771 | temp = er32(ROC); |
| 4772 | temp = er32(RJC); |
| 4773 | temp = er32(TORL); |
| 4774 | temp = er32(TORH); |
| 4775 | temp = er32(TOTL); |
| 4776 | temp = er32(TOTH); |
| 4777 | temp = er32(TPR); |
| 4778 | temp = er32(TPT); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4779 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4780 | temp = er32(PTC64); |
| 4781 | temp = er32(PTC127); |
| 4782 | temp = er32(PTC255); |
| 4783 | temp = er32(PTC511); |
| 4784 | temp = er32(PTC1023); |
| 4785 | temp = er32(PTC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4786 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4787 | temp = er32(MPTC); |
| 4788 | temp = er32(BPTC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4789 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4790 | if (hw->mac_type < e1000_82543) |
| 4791 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4792 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4793 | temp = er32(ALGNERRC); |
| 4794 | temp = er32(RXERRC); |
| 4795 | temp = er32(TNCRS); |
| 4796 | temp = er32(CEXTERR); |
| 4797 | temp = er32(TSCTC); |
| 4798 | temp = er32(TSCTFC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4799 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4800 | if (hw->mac_type <= e1000_82544) |
| 4801 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4802 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4803 | temp = er32(MGTPRC); |
| 4804 | temp = er32(MGTPDC); |
| 4805 | temp = er32(MGTPTC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4806 | } |
| 4807 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4808 | /** |
| 4809 | * e1000_reset_adaptive - Resets Adaptive IFS to its default state. |
| 4810 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | * |
| 4812 | * 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] | 4813 | * hw->ifs_params_forced to true. However, you must initialize hw-> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio |
| 4815 | * before calling this function. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4816 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4817 | void e1000_reset_adaptive(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4818 | { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4819 | e_dbg("e1000_reset_adaptive"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4820 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4821 | if (hw->adaptive_ifs) { |
| 4822 | if (!hw->ifs_params_forced) { |
| 4823 | hw->current_ifs_val = 0; |
| 4824 | hw->ifs_min_val = IFS_MIN; |
| 4825 | hw->ifs_max_val = IFS_MAX; |
| 4826 | hw->ifs_step_size = IFS_STEP; |
| 4827 | hw->ifs_ratio = IFS_RATIO; |
| 4828 | } |
| 4829 | hw->in_ifs_mode = false; |
| 4830 | ew32(AIT, 0); |
| 4831 | } else { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4832 | e_dbg("Not in Adaptive IFS mode!\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4833 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4834 | } |
| 4835 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4836 | /** |
| 4837 | * e1000_update_adaptive - update adaptive IFS |
| 4838 | * @hw: Struct containing variables accessed by shared code |
| 4839 | * @tx_packets: Number of transmits since last callback |
| 4840 | * @total_collisions: Number of collisions since last callback |
| 4841 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | * Called during the callback/watchdog routine to update IFS value based on |
| 4843 | * the ratio of transmits to collisions. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4844 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4845 | void e1000_update_adaptive(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4846 | { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4847 | e_dbg("e1000_update_adaptive"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4848 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4849 | if (hw->adaptive_ifs) { |
| 4850 | if ((hw->collision_delta *hw->ifs_ratio) > hw->tx_packet_delta) { |
| 4851 | if (hw->tx_packet_delta > MIN_NUM_XMITS) { |
| 4852 | hw->in_ifs_mode = true; |
| 4853 | if (hw->current_ifs_val < hw->ifs_max_val) { |
| 4854 | if (hw->current_ifs_val == 0) |
| 4855 | hw->current_ifs_val = |
| 4856 | hw->ifs_min_val; |
| 4857 | else |
| 4858 | hw->current_ifs_val += |
| 4859 | hw->ifs_step_size; |
| 4860 | ew32(AIT, hw->current_ifs_val); |
| 4861 | } |
| 4862 | } |
| 4863 | } else { |
| 4864 | if (hw->in_ifs_mode |
| 4865 | && (hw->tx_packet_delta <= MIN_NUM_XMITS)) { |
| 4866 | hw->current_ifs_val = 0; |
| 4867 | hw->in_ifs_mode = false; |
| 4868 | ew32(AIT, 0); |
| 4869 | } |
| 4870 | } |
| 4871 | } else { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4872 | e_dbg("Not in Adaptive IFS mode!\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4873 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4874 | } |
| 4875 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4876 | /** |
| 4877 | * e1000_tbi_adjust_stats |
| 4878 | * @hw: Struct containing variables accessed by shared code |
| 4879 | * @frame_len: The length of the frame in question |
| 4880 | * @mac_addr: The Ethernet destination address of the frame in question |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4881 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4882 | * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT |
| 4883 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4884 | void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats, |
| 4885 | u32 frame_len, u8 *mac_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4886 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4887 | u64 carry_bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4888 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4889 | /* First adjust the frame length. */ |
| 4890 | frame_len--; |
| 4891 | /* We need to adjust the statistics counters, since the hardware |
| 4892 | * counters overcount this packet as a CRC error and undercount |
| 4893 | * the packet as a good packet |
| 4894 | */ |
| 4895 | /* This packet should not be counted as a CRC error. */ |
| 4896 | stats->crcerrs--; |
| 4897 | /* This packet does count as a Good Packet Received. */ |
| 4898 | stats->gprc++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4899 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4900 | /* Adjust the Good Octets received counters */ |
| 4901 | carry_bit = 0x80000000 & stats->gorcl; |
| 4902 | stats->gorcl += frame_len; |
| 4903 | /* If the high bit of Gorcl (the low 32 bits of the Good Octets |
| 4904 | * Received Count) was one before the addition, |
| 4905 | * AND it is zero after, then we lost the carry out, |
| 4906 | * need to add one to Gorch (Good Octets Received Count High). |
| 4907 | * This could be simplified if all environments supported |
| 4908 | * 64-bit integers. |
| 4909 | */ |
| 4910 | if (carry_bit && ((stats->gorcl & 0x80000000) == 0)) |
| 4911 | stats->gorch++; |
| 4912 | /* Is this a broadcast or multicast? Check broadcast first, |
| 4913 | * since the test for a multicast frame will test positive on |
| 4914 | * a broadcast frame. |
| 4915 | */ |
| 4916 | if ((mac_addr[0] == (u8) 0xff) && (mac_addr[1] == (u8) 0xff)) |
| 4917 | /* Broadcast packet */ |
| 4918 | stats->bprc++; |
| 4919 | else if (*mac_addr & 0x01) |
| 4920 | /* Multicast packet */ |
| 4921 | stats->mprc++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4922 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4923 | if (frame_len == hw->max_frame_size) { |
| 4924 | /* In this case, the hardware has overcounted the number of |
| 4925 | * oversize frames. |
| 4926 | */ |
| 4927 | if (stats->roc > 0) |
| 4928 | stats->roc--; |
| 4929 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4930 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4931 | /* Adjust the bin counters when the extra byte put the frame in the |
| 4932 | * wrong bin. Remember that the frame_len was adjusted above. |
| 4933 | */ |
| 4934 | if (frame_len == 64) { |
| 4935 | stats->prc64++; |
| 4936 | stats->prc127--; |
| 4937 | } else if (frame_len == 127) { |
| 4938 | stats->prc127++; |
| 4939 | stats->prc255--; |
| 4940 | } else if (frame_len == 255) { |
| 4941 | stats->prc255++; |
| 4942 | stats->prc511--; |
| 4943 | } else if (frame_len == 511) { |
| 4944 | stats->prc511++; |
| 4945 | stats->prc1023--; |
| 4946 | } else if (frame_len == 1023) { |
| 4947 | stats->prc1023++; |
| 4948 | stats->prc1522--; |
| 4949 | } else if (frame_len == 1522) { |
| 4950 | stats->prc1522++; |
| 4951 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4952 | } |
| 4953 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4954 | /** |
| 4955 | * e1000_get_bus_info |
| 4956 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4958 | * Gets the current PCI bus type, speed, and width of the hardware |
| 4959 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4960 | void e1000_get_bus_info(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4961 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4962 | u32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4963 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4964 | switch (hw->mac_type) { |
| 4965 | case e1000_82542_rev2_0: |
| 4966 | case e1000_82542_rev2_1: |
| 4967 | hw->bus_type = e1000_bus_type_pci; |
| 4968 | hw->bus_speed = e1000_bus_speed_unknown; |
| 4969 | hw->bus_width = e1000_bus_width_unknown; |
| 4970 | break; |
| 4971 | default: |
| 4972 | status = er32(STATUS); |
| 4973 | hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ? |
| 4974 | e1000_bus_type_pcix : e1000_bus_type_pci; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4975 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4976 | if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) { |
| 4977 | hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ? |
| 4978 | e1000_bus_speed_66 : e1000_bus_speed_120; |
| 4979 | } else if (hw->bus_type == e1000_bus_type_pci) { |
| 4980 | hw->bus_speed = (status & E1000_STATUS_PCI66) ? |
| 4981 | e1000_bus_speed_66 : e1000_bus_speed_33; |
| 4982 | } else { |
| 4983 | switch (status & E1000_STATUS_PCIX_SPEED) { |
| 4984 | case E1000_STATUS_PCIX_SPEED_66: |
| 4985 | hw->bus_speed = e1000_bus_speed_66; |
| 4986 | break; |
| 4987 | case E1000_STATUS_PCIX_SPEED_100: |
| 4988 | hw->bus_speed = e1000_bus_speed_100; |
| 4989 | break; |
| 4990 | case E1000_STATUS_PCIX_SPEED_133: |
| 4991 | hw->bus_speed = e1000_bus_speed_133; |
| 4992 | break; |
| 4993 | default: |
| 4994 | hw->bus_speed = e1000_bus_speed_reserved; |
| 4995 | break; |
| 4996 | } |
| 4997 | } |
| 4998 | hw->bus_width = (status & E1000_STATUS_BUS64) ? |
| 4999 | e1000_bus_width_64 : e1000_bus_width_32; |
| 5000 | break; |
| 5001 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5002 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5003 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5004 | /** |
| 5005 | * e1000_write_reg_io |
| 5006 | * @hw: Struct containing variables accessed by shared code |
| 5007 | * @offset: offset to write to |
| 5008 | * @value: value to write |
| 5009 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5010 | * Writes a value to one of the devices registers using port I/O (as opposed to |
| 5011 | * memory mapped I/O). Only 82544 and newer devices support port I/O. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5012 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5013 | 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] | 5014 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5015 | unsigned long io_addr = hw->io_base; |
| 5016 | unsigned long io_data = hw->io_base + 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5018 | e1000_io_write(hw, io_addr, offset); |
| 5019 | e1000_io_write(hw, io_data, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5020 | } |
| 5021 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5022 | /** |
| 5023 | * e1000_get_cable_length - Estimates the cable length. |
| 5024 | * @hw: Struct containing variables accessed by shared code |
| 5025 | * @min_length: The estimated minimum length |
| 5026 | * @max_length: The estimated maximum length |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5027 | * |
| 5028 | * returns: - E1000_ERR_XXX |
| 5029 | * E1000_SUCCESS |
| 5030 | * |
| 5031 | * This function always returns a ranged length (minimum & maximum). |
| 5032 | * So for M88 phy's, this function interprets the one value returned from the |
| 5033 | * register to the minimum and maximum range. |
| 5034 | * For IGP phy's, the function calculates the range by the AGC registers. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5035 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5036 | static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length, |
| 5037 | u16 *max_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5038 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5039 | s32 ret_val; |
| 5040 | u16 agc_value = 0; |
| 5041 | u16 i, phy_data; |
| 5042 | u16 cable_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5043 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5044 | e_dbg("e1000_get_cable_length"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5046 | *min_length = *max_length = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5047 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5048 | /* Use old method for Phy older than IGP */ |
| 5049 | if (hw->phy_type == e1000_phy_m88) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5050 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5051 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 5052 | &phy_data); |
| 5053 | if (ret_val) |
| 5054 | return ret_val; |
| 5055 | cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >> |
| 5056 | M88E1000_PSSR_CABLE_LENGTH_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5057 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5058 | /* Convert the enum value to ranged values */ |
| 5059 | switch (cable_length) { |
| 5060 | case e1000_cable_length_50: |
| 5061 | *min_length = 0; |
| 5062 | *max_length = e1000_igp_cable_length_50; |
| 5063 | break; |
| 5064 | case e1000_cable_length_50_80: |
| 5065 | *min_length = e1000_igp_cable_length_50; |
| 5066 | *max_length = e1000_igp_cable_length_80; |
| 5067 | break; |
| 5068 | case e1000_cable_length_80_110: |
| 5069 | *min_length = e1000_igp_cable_length_80; |
| 5070 | *max_length = e1000_igp_cable_length_110; |
| 5071 | break; |
| 5072 | case e1000_cable_length_110_140: |
| 5073 | *min_length = e1000_igp_cable_length_110; |
| 5074 | *max_length = e1000_igp_cable_length_140; |
| 5075 | break; |
| 5076 | case e1000_cable_length_140: |
| 5077 | *min_length = e1000_igp_cable_length_140; |
| 5078 | *max_length = e1000_igp_cable_length_170; |
| 5079 | break; |
| 5080 | default: |
| 5081 | return -E1000_ERR_PHY; |
| 5082 | break; |
| 5083 | } |
| 5084 | } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */ |
| 5085 | u16 cur_agc_value; |
| 5086 | u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE; |
Jeff Kirsher | 6674450 | 2010-12-01 19:59:50 +0000 | [diff] [blame] | 5087 | static const u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = { |
| 5088 | IGP01E1000_PHY_AGC_A, |
| 5089 | IGP01E1000_PHY_AGC_B, |
| 5090 | IGP01E1000_PHY_AGC_C, |
| 5091 | IGP01E1000_PHY_AGC_D |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5092 | }; |
| 5093 | /* Read the AGC registers for all channels */ |
| 5094 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5095 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5096 | ret_val = |
| 5097 | e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data); |
| 5098 | if (ret_val) |
| 5099 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5100 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5101 | cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5102 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5103 | /* Value bound check. */ |
| 5104 | if ((cur_agc_value >= |
| 5105 | IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) |
| 5106 | || (cur_agc_value == 0)) |
| 5107 | return -E1000_ERR_PHY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5108 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5109 | agc_value += cur_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5110 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5111 | /* Update minimal AGC value. */ |
| 5112 | if (min_agc_value > cur_agc_value) |
| 5113 | min_agc_value = cur_agc_value; |
| 5114 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5115 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5116 | /* Remove the minimal AGC result for length < 50m */ |
| 5117 | if (agc_value < |
| 5118 | IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) { |
| 5119 | agc_value -= min_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5120 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5121 | /* Get the average length of the remaining 3 channels */ |
| 5122 | agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1); |
| 5123 | } else { |
| 5124 | /* Get the average length of all the 4 channels. */ |
| 5125 | agc_value /= IGP01E1000_PHY_CHANNEL_NUM; |
| 5126 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5127 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5128 | /* Set the range of the calculated length. */ |
| 5129 | *min_length = ((e1000_igp_cable_length_table[agc_value] - |
| 5130 | IGP01E1000_AGC_RANGE) > 0) ? |
| 5131 | (e1000_igp_cable_length_table[agc_value] - |
| 5132 | IGP01E1000_AGC_RANGE) : 0; |
| 5133 | *max_length = e1000_igp_cable_length_table[agc_value] + |
| 5134 | IGP01E1000_AGC_RANGE; |
| 5135 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5136 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5137 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5138 | } |
| 5139 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5140 | /** |
| 5141 | * e1000_check_polarity - Check the cable polarity |
| 5142 | * @hw: Struct containing variables accessed by shared code |
| 5143 | * @polarity: output parameter : 0 - Polarity is not reversed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5144 | * 1 - Polarity is reversed. |
| 5145 | * |
| 5146 | * returns: - E1000_ERR_XXX |
| 5147 | * E1000_SUCCESS |
| 5148 | * |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 5149 | * 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] | 5150 | * Phy Status register. For IGP phy's, this bit is valid only if link speed is |
| 5151 | * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will |
| 5152 | * return 0. If the link speed is 1000 Mbps the polarity status is in the |
| 5153 | * IGP01E1000_PHY_PCS_INIT_REG. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5154 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5155 | static s32 e1000_check_polarity(struct e1000_hw *hw, |
| 5156 | e1000_rev_polarity *polarity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5157 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5158 | s32 ret_val; |
| 5159 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5160 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5161 | e_dbg("e1000_check_polarity"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5163 | if (hw->phy_type == e1000_phy_m88) { |
| 5164 | /* return the Polarity bit in the Status register. */ |
| 5165 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 5166 | &phy_data); |
| 5167 | if (ret_val) |
| 5168 | return ret_val; |
| 5169 | *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >> |
| 5170 | M88E1000_PSSR_REV_POLARITY_SHIFT) ? |
| 5171 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 5172 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5173 | } else if (hw->phy_type == e1000_phy_igp) { |
| 5174 | /* Read the Status register to check the speed */ |
| 5175 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, |
| 5176 | &phy_data); |
| 5177 | if (ret_val) |
| 5178 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5179 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5180 | /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to |
| 5181 | * find the polarity status */ |
| 5182 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == |
| 5183 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5184 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5185 | /* Read the GIG initialization PCS register (0x00B4) */ |
| 5186 | ret_val = |
| 5187 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG, |
| 5188 | &phy_data); |
| 5189 | if (ret_val) |
| 5190 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5191 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5192 | /* Check the polarity bits */ |
| 5193 | *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? |
| 5194 | e1000_rev_polarity_reversed : |
| 5195 | e1000_rev_polarity_normal; |
| 5196 | } else { |
| 5197 | /* For 10 Mbps, read the polarity bit in the status register. (for |
| 5198 | * 100 Mbps this bit is always 0) */ |
| 5199 | *polarity = |
| 5200 | (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ? |
| 5201 | e1000_rev_polarity_reversed : |
| 5202 | e1000_rev_polarity_normal; |
| 5203 | } |
| 5204 | } |
| 5205 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5206 | } |
| 5207 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5208 | /** |
| 5209 | * e1000_check_downshift - Check if Downshift occurred |
| 5210 | * @hw: Struct containing variables accessed by shared code |
| 5211 | * @downshift: output parameter : 0 - No Downshift occurred. |
| 5212 | * 1 - Downshift occurred. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5213 | * |
| 5214 | * returns: - E1000_ERR_XXX |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5215 | * E1000_SUCCESS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5216 | * |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 5217 | * 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] | 5218 | * Specific Status register. For IGP phy's, it reads the Downgrade bit in the |
| 5219 | * Link Health register. In IGP this bit is latched high, so the driver must |
| 5220 | * read it immediately after link is established. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5221 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5222 | static s32 e1000_check_downshift(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5223 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5224 | s32 ret_val; |
| 5225 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5226 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5227 | e_dbg("e1000_check_downshift"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5228 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5229 | if (hw->phy_type == e1000_phy_igp) { |
| 5230 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH, |
| 5231 | &phy_data); |
| 5232 | if (ret_val) |
| 5233 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5234 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5235 | hw->speed_downgraded = |
| 5236 | (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0; |
| 5237 | } else if (hw->phy_type == e1000_phy_m88) { |
| 5238 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 5239 | &phy_data); |
| 5240 | if (ret_val) |
| 5241 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5242 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5243 | hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >> |
| 5244 | M88E1000_PSSR_DOWNSHIFT_SHIFT; |
| 5245 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5246 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5247 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5248 | } |
| 5249 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5250 | /** |
| 5251 | * e1000_config_dsp_after_link_change |
| 5252 | * @hw: Struct containing variables accessed by shared code |
| 5253 | * @link_up: was link up at the time this was called |
| 5254 | * |
| 5255 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 5256 | * E1000_SUCCESS at any other case. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5257 | * |
| 5258 | * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a |
| 5259 | * gigabit link is achieved to improve link quality. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5260 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5261 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5262 | 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] | 5263 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5264 | s32 ret_val; |
| 5265 | u16 phy_data, phy_saved_data, speed, duplex, i; |
Jeff Kirsher | 6674450 | 2010-12-01 19:59:50 +0000 | [diff] [blame] | 5266 | static const u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = { |
| 5267 | IGP01E1000_PHY_AGC_PARAM_A, |
| 5268 | IGP01E1000_PHY_AGC_PARAM_B, |
| 5269 | IGP01E1000_PHY_AGC_PARAM_C, |
| 5270 | IGP01E1000_PHY_AGC_PARAM_D |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5271 | }; |
| 5272 | u16 min_length, max_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5273 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5274 | e_dbg("e1000_config_dsp_after_link_change"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5275 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5276 | if (hw->phy_type != e1000_phy_igp) |
| 5277 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5278 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5279 | if (link_up) { |
| 5280 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); |
| 5281 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5282 | e_dbg("Error getting link speed and duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5283 | return ret_val; |
| 5284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5285 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5286 | if (speed == SPEED_1000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5287 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5288 | ret_val = |
| 5289 | e1000_get_cable_length(hw, &min_length, |
| 5290 | &max_length); |
| 5291 | if (ret_val) |
| 5292 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5293 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5294 | if ((hw->dsp_config_state == e1000_dsp_config_enabled) |
| 5295 | && min_length >= e1000_igp_cable_length_50) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5296 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5297 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
| 5298 | ret_val = |
| 5299 | e1000_read_phy_reg(hw, |
| 5300 | dsp_reg_array[i], |
| 5301 | &phy_data); |
| 5302 | if (ret_val) |
| 5303 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5304 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5305 | phy_data &= |
| 5306 | ~IGP01E1000_PHY_EDAC_MU_INDEX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5307 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5308 | ret_val = |
| 5309 | e1000_write_phy_reg(hw, |
| 5310 | dsp_reg_array |
| 5311 | [i], phy_data); |
| 5312 | if (ret_val) |
| 5313 | return ret_val; |
| 5314 | } |
| 5315 | hw->dsp_config_state = |
| 5316 | e1000_dsp_config_activated; |
| 5317 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5318 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5319 | if ((hw->ffe_config_state == e1000_ffe_config_enabled) |
| 5320 | && (min_length < e1000_igp_cable_length_50)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5322 | u16 ffe_idle_err_timeout = |
| 5323 | FFE_IDLE_ERR_COUNT_TIMEOUT_20; |
| 5324 | u32 idle_errs = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5325 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5326 | /* clear previous idle error counts */ |
| 5327 | ret_val = |
| 5328 | e1000_read_phy_reg(hw, PHY_1000T_STATUS, |
| 5329 | &phy_data); |
| 5330 | if (ret_val) |
| 5331 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5332 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5333 | for (i = 0; i < ffe_idle_err_timeout; i++) { |
| 5334 | udelay(1000); |
| 5335 | ret_val = |
| 5336 | e1000_read_phy_reg(hw, |
| 5337 | PHY_1000T_STATUS, |
| 5338 | &phy_data); |
| 5339 | if (ret_val) |
| 5340 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5341 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5342 | idle_errs += |
| 5343 | (phy_data & |
| 5344 | SR_1000T_IDLE_ERROR_CNT); |
| 5345 | if (idle_errs > |
| 5346 | SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) |
| 5347 | { |
| 5348 | hw->ffe_config_state = |
| 5349 | e1000_ffe_config_active; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5350 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5351 | ret_val = |
| 5352 | e1000_write_phy_reg(hw, |
| 5353 | IGP01E1000_PHY_DSP_FFE, |
| 5354 | IGP01E1000_PHY_DSP_FFE_CM_CP); |
| 5355 | if (ret_val) |
| 5356 | return ret_val; |
| 5357 | break; |
| 5358 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5359 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5360 | if (idle_errs) |
| 5361 | ffe_idle_err_timeout = |
| 5362 | FFE_IDLE_ERR_COUNT_TIMEOUT_100; |
| 5363 | } |
| 5364 | } |
| 5365 | } |
| 5366 | } else { |
| 5367 | if (hw->dsp_config_state == e1000_dsp_config_activated) { |
| 5368 | /* Save off the current value of register 0x2F5B to be restored at |
| 5369 | * the end of the routines. */ |
| 5370 | ret_val = |
| 5371 | e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5372 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5373 | if (ret_val) |
| 5374 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5375 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5376 | /* Disable the PHY transmitter */ |
| 5377 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5378 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5379 | if (ret_val) |
| 5380 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5381 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5382 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5383 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5384 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 5385 | IGP01E1000_IEEE_FORCE_GIGA); |
| 5386 | if (ret_val) |
| 5387 | return ret_val; |
| 5388 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
| 5389 | ret_val = |
| 5390 | e1000_read_phy_reg(hw, dsp_reg_array[i], |
| 5391 | &phy_data); |
| 5392 | if (ret_val) |
| 5393 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5394 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5395 | phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX; |
| 5396 | phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5397 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5398 | ret_val = |
| 5399 | e1000_write_phy_reg(hw, dsp_reg_array[i], |
| 5400 | phy_data); |
| 5401 | if (ret_val) |
| 5402 | return ret_val; |
| 5403 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5404 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5405 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 5406 | IGP01E1000_IEEE_RESTART_AUTONEG); |
| 5407 | if (ret_val) |
| 5408 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5409 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5410 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5411 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5412 | /* Now enable the transmitter */ |
| 5413 | ret_val = |
| 5414 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5415 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5416 | if (ret_val) |
| 5417 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5418 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5419 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 5420 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5421 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5422 | if (hw->ffe_config_state == e1000_ffe_config_active) { |
| 5423 | /* Save off the current value of register 0x2F5B to be restored at |
| 5424 | * the end of the routines. */ |
| 5425 | ret_val = |
| 5426 | e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5427 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5428 | if (ret_val) |
| 5429 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5430 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5431 | /* Disable the PHY transmitter */ |
| 5432 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5433 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5434 | if (ret_val) |
| 5435 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5436 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5437 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5438 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5439 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 5440 | IGP01E1000_IEEE_FORCE_GIGA); |
| 5441 | if (ret_val) |
| 5442 | return ret_val; |
| 5443 | ret_val = |
| 5444 | e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE, |
| 5445 | IGP01E1000_PHY_DSP_FFE_DEFAULT); |
| 5446 | if (ret_val) |
| 5447 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5448 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5449 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 5450 | IGP01E1000_IEEE_RESTART_AUTONEG); |
| 5451 | if (ret_val) |
| 5452 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5453 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5454 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5455 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5456 | /* Now enable the transmitter */ |
| 5457 | ret_val = |
| 5458 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5459 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5460 | if (ret_val) |
| 5461 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5462 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5463 | hw->ffe_config_state = e1000_ffe_config_enabled; |
| 5464 | } |
| 5465 | } |
| 5466 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5467 | } |
| 5468 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5469 | /** |
| 5470 | * e1000_set_phy_mode - Set PHY to class A mode |
| 5471 | * @hw: Struct containing variables accessed by shared code |
| 5472 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5473 | * Assumes the following operations will follow to enable the new class mode. |
| 5474 | * 1. Do a PHY soft reset |
| 5475 | * 2. Restart auto-negotiation or force link. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5476 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5477 | static s32 e1000_set_phy_mode(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5478 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5479 | s32 ret_val; |
| 5480 | u16 eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5481 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5482 | e_dbg("e1000_set_phy_mode"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5483 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5484 | if ((hw->mac_type == e1000_82545_rev_3) && |
| 5485 | (hw->media_type == e1000_media_type_copper)) { |
| 5486 | ret_val = |
| 5487 | e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, |
| 5488 | &eeprom_data); |
| 5489 | if (ret_val) { |
| 5490 | return ret_val; |
| 5491 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5492 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5493 | if ((eeprom_data != EEPROM_RESERVED_WORD) && |
| 5494 | (eeprom_data & EEPROM_PHY_CLASS_A)) { |
| 5495 | ret_val = |
| 5496 | e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, |
| 5497 | 0x000B); |
| 5498 | if (ret_val) |
| 5499 | return ret_val; |
| 5500 | ret_val = |
| 5501 | e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, |
| 5502 | 0x8104); |
| 5503 | if (ret_val) |
| 5504 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5505 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5506 | hw->phy_reset_disable = false; |
| 5507 | } |
| 5508 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5510 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5511 | } |
| 5512 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5513 | /** |
| 5514 | * e1000_set_d3_lplu_state - set d3 link power state |
| 5515 | * @hw: Struct containing variables accessed by shared code |
| 5516 | * @active: true to enable lplu false to disable lplu. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5517 | * |
| 5518 | * This function sets the lplu state according to the active flag. When |
| 5519 | * activating lplu this function also disables smart speed and vise versa. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5520 | * lplu will not be activated unless the device autonegotiation advertisement |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5521 | * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5522 | * |
| 5523 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 5524 | * E1000_SUCCESS at any other case. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5525 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5526 | 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] | 5527 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5528 | s32 ret_val; |
| 5529 | u16 phy_data; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5530 | e_dbg("e1000_set_d3_lplu_state"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5531 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5532 | if (hw->phy_type != e1000_phy_igp) |
| 5533 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5534 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5535 | /* During driver activity LPLU should not be used or it will attain link |
| 5536 | * from the lowest speeds starting from 10Mbps. The capability is used for |
| 5537 | * Dx transitions and states */ |
| 5538 | if (hw->mac_type == e1000_82541_rev_2 |
| 5539 | || hw->mac_type == e1000_82547_rev_2) { |
| 5540 | ret_val = |
| 5541 | e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data); |
| 5542 | if (ret_val) |
| 5543 | return ret_val; |
| 5544 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5545 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5546 | if (!active) { |
| 5547 | if (hw->mac_type == e1000_82541_rev_2 || |
| 5548 | hw->mac_type == e1000_82547_rev_2) { |
| 5549 | phy_data &= ~IGP01E1000_GMII_FLEX_SPD; |
| 5550 | ret_val = |
| 5551 | e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 5552 | phy_data); |
| 5553 | if (ret_val) |
| 5554 | return ret_val; |
| 5555 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5556 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5557 | /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during |
| 5558 | * Dx states where the power conservation is most important. During |
| 5559 | * driver activity we should enable SmartSpeed, so performance is |
| 5560 | * maintained. */ |
| 5561 | if (hw->smart_speed == e1000_smart_speed_on) { |
| 5562 | ret_val = |
| 5563 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5564 | &phy_data); |
| 5565 | if (ret_val) |
| 5566 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5567 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5568 | phy_data |= IGP01E1000_PSCFR_SMART_SPEED; |
| 5569 | ret_val = |
| 5570 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5571 | phy_data); |
| 5572 | if (ret_val) |
| 5573 | return ret_val; |
| 5574 | } else if (hw->smart_speed == e1000_smart_speed_off) { |
| 5575 | ret_val = |
| 5576 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5577 | &phy_data); |
| 5578 | if (ret_val) |
| 5579 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5580 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5581 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 5582 | ret_val = |
| 5583 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5584 | phy_data); |
| 5585 | if (ret_val) |
| 5586 | return ret_val; |
| 5587 | } |
| 5588 | } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) |
| 5589 | || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) |
| 5590 | || (hw->autoneg_advertised == |
| 5591 | AUTONEG_ADVERTISE_10_100_ALL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5592 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5593 | if (hw->mac_type == e1000_82541_rev_2 || |
| 5594 | hw->mac_type == e1000_82547_rev_2) { |
| 5595 | phy_data |= IGP01E1000_GMII_FLEX_SPD; |
| 5596 | ret_val = |
| 5597 | e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 5598 | phy_data); |
| 5599 | if (ret_val) |
| 5600 | return ret_val; |
| 5601 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5602 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5603 | /* When LPLU is enabled we should disable SmartSpeed */ |
| 5604 | ret_val = |
| 5605 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5606 | &phy_data); |
| 5607 | if (ret_val) |
| 5608 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5609 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5610 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 5611 | ret_val = |
| 5612 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5613 | phy_data); |
| 5614 | if (ret_val) |
| 5615 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5616 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5617 | } |
| 5618 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5619 | } |
| 5620 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5621 | /** |
| 5622 | * e1000_set_vco_speed |
| 5623 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5624 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5625 | * Change VCO speed register to improve Bit Error Rate performance of SERDES. |
| 5626 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5627 | static s32 e1000_set_vco_speed(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5628 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5629 | s32 ret_val; |
| 5630 | u16 default_page = 0; |
| 5631 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5632 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5633 | e_dbg("e1000_set_vco_speed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5634 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5635 | switch (hw->mac_type) { |
| 5636 | case e1000_82545_rev_3: |
| 5637 | case e1000_82546_rev_3: |
| 5638 | break; |
| 5639 | default: |
| 5640 | return E1000_SUCCESS; |
| 5641 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5642 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5643 | /* Set PHY register 30, page 5, bit 8 to 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5644 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5645 | ret_val = |
| 5646 | e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page); |
| 5647 | if (ret_val) |
| 5648 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5649 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5650 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005); |
| 5651 | if (ret_val) |
| 5652 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5653 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5654 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data); |
| 5655 | if (ret_val) |
| 5656 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5657 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5658 | phy_data &= ~M88E1000_PHY_VCO_REG_BIT8; |
| 5659 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data); |
| 5660 | if (ret_val) |
| 5661 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5662 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5663 | /* Set PHY register 30, page 4, bit 11 to 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5664 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5665 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004); |
| 5666 | if (ret_val) |
| 5667 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5668 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5669 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data); |
| 5670 | if (ret_val) |
| 5671 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5672 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5673 | phy_data |= M88E1000_PHY_VCO_REG_BIT11; |
| 5674 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data); |
| 5675 | if (ret_val) |
| 5676 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5677 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5678 | ret_val = |
| 5679 | e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page); |
| 5680 | if (ret_val) |
| 5681 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5682 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5683 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5684 | } |
| 5685 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5686 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5687 | /** |
| 5688 | * e1000_enable_mng_pass_thru - check for bmc pass through |
| 5689 | * @hw: Struct containing variables accessed by shared code |
| 5690 | * |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5691 | * Verifies the hardware needs to allow ARPs to be processed by the host |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5692 | * returns: - true/false |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5693 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5694 | u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5695 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5696 | u32 manc; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5697 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5698 | if (hw->asf_firmware_present) { |
| 5699 | manc = er32(MANC); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5700 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5701 | if (!(manc & E1000_MANC_RCV_TCO_EN) || |
| 5702 | !(manc & E1000_MANC_EN_MAC_ADDR_FILTER)) |
| 5703 | return false; |
| 5704 | if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN)) |
| 5705 | return true; |
| 5706 | } |
| 5707 | return false; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5708 | } |
| 5709 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5710 | static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5711 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5712 | s32 ret_val; |
| 5713 | u16 mii_status_reg; |
| 5714 | u16 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5715 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5716 | /* Polarity reversal workaround for forced 10F/10H links. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5717 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5718 | /* Disable the transmitter on the PHY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5719 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5720 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); |
| 5721 | if (ret_val) |
| 5722 | return ret_val; |
| 5723 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF); |
| 5724 | if (ret_val) |
| 5725 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5726 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5727 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); |
| 5728 | if (ret_val) |
| 5729 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5730 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5731 | /* This loop will early-out if the NO link condition has been met. */ |
| 5732 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
| 5733 | /* Read the MII Status Register and wait for Link Status bit |
| 5734 | * to be clear. |
| 5735 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5736 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5737 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 5738 | if (ret_val) |
| 5739 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5740 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5741 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 5742 | if (ret_val) |
| 5743 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5744 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5745 | if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) |
| 5746 | break; |
| 5747 | mdelay(100); |
| 5748 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5749 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5750 | /* Recommended delay time after link has been lost */ |
| 5751 | mdelay(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5752 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5753 | /* Now we will re-enable th transmitter on the PHY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5754 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5755 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); |
| 5756 | if (ret_val) |
| 5757 | return ret_val; |
| 5758 | mdelay(50); |
| 5759 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0); |
| 5760 | if (ret_val) |
| 5761 | return ret_val; |
| 5762 | mdelay(50); |
| 5763 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00); |
| 5764 | if (ret_val) |
| 5765 | return ret_val; |
| 5766 | mdelay(50); |
| 5767 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000); |
| 5768 | if (ret_val) |
| 5769 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5770 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5771 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); |
| 5772 | if (ret_val) |
| 5773 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5774 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5775 | /* This loop will early-out if the link condition has been met. */ |
| 5776 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
| 5777 | /* Read the MII Status Register and wait for Link Status bit |
| 5778 | * to be set. |
| 5779 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5780 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5781 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 5782 | if (ret_val) |
| 5783 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5784 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5785 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 5786 | if (ret_val) |
| 5787 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5788 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5789 | if (mii_status_reg & MII_SR_LINK_STATUS) |
| 5790 | break; |
| 5791 | mdelay(100); |
| 5792 | } |
| 5793 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5794 | } |
| 5795 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5796 | /** |
| 5797 | * e1000_get_auto_rd_done |
| 5798 | * @hw: Struct containing variables accessed by shared code |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5799 | * |
| 5800 | * Check for EEPROM Auto Read bit done. |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5801 | * returns: - E1000_ERR_RESET if fail to reset MAC |
| 5802 | * E1000_SUCCESS at any other case. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5803 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5804 | static s32 e1000_get_auto_rd_done(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5805 | { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5806 | e_dbg("e1000_get_auto_rd_done"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5807 | msleep(5); |
| 5808 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5809 | } |
| 5810 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5811 | /** |
| 5812 | * e1000_get_phy_cfg_done |
| 5813 | * @hw: Struct containing variables accessed by shared code |
| 5814 | * |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5815 | * Checks if the PHY configuration is done |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5816 | * returns: - E1000_ERR_RESET if fail to reset MAC |
| 5817 | * E1000_SUCCESS at any other case. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5818 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5819 | static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5820 | { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5821 | e_dbg("e1000_get_phy_cfg_done"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5822 | mdelay(10); |
| 5823 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5824 | } |