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); |
Maxime Bizon | ac56558 | 2012-10-20 14:53:40 +0000 | [diff] [blame] | 110 | static DEFINE_SPINLOCK(e1000_phy_lock); |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 111 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 112 | /** |
| 113 | * e1000_set_phy_type - Set the phy type member in the hw struct. |
| 114 | * @hw: Struct containing variables accessed by shared code |
| 115 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 116 | static s32 e1000_set_phy_type(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 118 | e_dbg("e1000_set_phy_type"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 120 | if (hw->mac_type == e1000_undefined) |
| 121 | return -E1000_ERR_PHY_TYPE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 122 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 123 | switch (hw->phy_id) { |
| 124 | case M88E1000_E_PHY_ID: |
| 125 | case M88E1000_I_PHY_ID: |
| 126 | case M88E1011_I_PHY_ID: |
| 127 | case M88E1111_I_PHY_ID: |
Florian Fainelli | cf8e09b | 2011-01-24 14:48:03 +0000 | [diff] [blame] | 128 | case M88E1118_E_PHY_ID: |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 129 | hw->phy_type = e1000_phy_m88; |
| 130 | break; |
| 131 | case IGP01E1000_I_PHY_ID: |
| 132 | if (hw->mac_type == e1000_82541 || |
| 133 | hw->mac_type == e1000_82541_rev_2 || |
| 134 | hw->mac_type == e1000_82547 || |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 135 | hw->mac_type == e1000_82547_rev_2) |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 136 | hw->phy_type = e1000_phy_igp; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 137 | break; |
| 138 | case RTL8211B_PHY_ID: |
| 139 | hw->phy_type = e1000_phy_8211; |
| 140 | break; |
| 141 | case RTL8201N_PHY_ID: |
| 142 | hw->phy_type = e1000_phy_8201; |
| 143 | break; |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 144 | default: |
| 145 | /* Should never have loaded on this device */ |
| 146 | hw->phy_type = e1000_phy_undefined; |
| 147 | return -E1000_ERR_PHY_TYPE; |
| 148 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 150 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 153 | /** |
| 154 | * e1000_phy_init_script - IGP phy init script - initializes the GbE PHY |
| 155 | * @hw: Struct containing variables accessed by shared code |
| 156 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 157 | static void e1000_phy_init_script(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 159 | u32 ret_val; |
| 160 | u16 phy_saved_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 162 | e_dbg("e1000_phy_init_script"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 164 | if (hw->phy_init_script) { |
| 165 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 167 | /* Save off the current value of register 0x2F5B to be restored |
| 168 | * at the end of this routine. |
| 169 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 170 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 172 | /* Disabled the PHY transmitter */ |
| 173 | e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 174 | msleep(20); |
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 | e1000_write_phy_reg(hw, 0x0000, 0x0140); |
| 177 | msleep(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 179 | switch (hw->mac_type) { |
| 180 | case e1000_82541: |
| 181 | case e1000_82547: |
| 182 | e1000_write_phy_reg(hw, 0x1F95, 0x0001); |
| 183 | e1000_write_phy_reg(hw, 0x1F71, 0xBD21); |
| 184 | e1000_write_phy_reg(hw, 0x1F79, 0x0018); |
| 185 | e1000_write_phy_reg(hw, 0x1F30, 0x1600); |
| 186 | e1000_write_phy_reg(hw, 0x1F31, 0x0014); |
| 187 | e1000_write_phy_reg(hw, 0x1F32, 0x161C); |
| 188 | e1000_write_phy_reg(hw, 0x1F94, 0x0003); |
| 189 | e1000_write_phy_reg(hw, 0x1F96, 0x003F); |
| 190 | e1000_write_phy_reg(hw, 0x2010, 0x0008); |
| 191 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 193 | case e1000_82541_rev_2: |
| 194 | case e1000_82547_rev_2: |
| 195 | e1000_write_phy_reg(hw, 0x1F73, 0x0099); |
| 196 | break; |
| 197 | default: |
| 198 | break; |
| 199 | } |
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 | e1000_write_phy_reg(hw, 0x0000, 0x3300); |
| 202 | msleep(20); |
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 | /* Now enable the transmitter */ |
| 205 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
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 | if (hw->mac_type == e1000_82547) { |
| 208 | u16 fused, fine, coarse; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 210 | /* Move to analog registers page */ |
| 211 | e1000_read_phy_reg(hw, |
| 212 | IGP01E1000_ANALOG_SPARE_FUSE_STATUS, |
| 213 | &fused); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 215 | if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) { |
| 216 | e1000_read_phy_reg(hw, |
| 217 | IGP01E1000_ANALOG_FUSE_STATUS, |
| 218 | &fused); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 220 | fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK; |
| 221 | coarse = |
| 222 | fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 224 | if (coarse > |
| 225 | IGP01E1000_ANALOG_FUSE_COARSE_THRESH) { |
| 226 | coarse -= |
| 227 | IGP01E1000_ANALOG_FUSE_COARSE_10; |
| 228 | fine -= IGP01E1000_ANALOG_FUSE_FINE_1; |
| 229 | } else if (coarse == |
| 230 | IGP01E1000_ANALOG_FUSE_COARSE_THRESH) |
| 231 | fine -= IGP01E1000_ANALOG_FUSE_FINE_10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 233 | fused = |
| 234 | (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) | |
| 235 | (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) | |
| 236 | (coarse & |
| 237 | IGP01E1000_ANALOG_FUSE_COARSE_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 239 | e1000_write_phy_reg(hw, |
| 240 | IGP01E1000_ANALOG_FUSE_CONTROL, |
| 241 | fused); |
| 242 | e1000_write_phy_reg(hw, |
| 243 | IGP01E1000_ANALOG_FUSE_BYPASS, |
| 244 | IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL); |
| 245 | } |
| 246 | } |
| 247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 250 | /** |
| 251 | * e1000_set_mac_type - Set the mac type member in the hw struct. |
| 252 | * @hw: Struct containing variables accessed by shared code |
| 253 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 254 | s32 e1000_set_mac_type(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 256 | e_dbg("e1000_set_mac_type"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 258 | switch (hw->device_id) { |
| 259 | case E1000_DEV_ID_82542: |
| 260 | switch (hw->revision_id) { |
| 261 | case E1000_82542_2_0_REV_ID: |
| 262 | hw->mac_type = e1000_82542_rev2_0; |
| 263 | break; |
| 264 | case E1000_82542_2_1_REV_ID: |
| 265 | hw->mac_type = e1000_82542_rev2_1; |
| 266 | break; |
| 267 | default: |
| 268 | /* Invalid 82542 revision ID */ |
| 269 | return -E1000_ERR_MAC_TYPE; |
| 270 | } |
| 271 | break; |
| 272 | case E1000_DEV_ID_82543GC_FIBER: |
| 273 | case E1000_DEV_ID_82543GC_COPPER: |
| 274 | hw->mac_type = e1000_82543; |
| 275 | break; |
| 276 | case E1000_DEV_ID_82544EI_COPPER: |
| 277 | case E1000_DEV_ID_82544EI_FIBER: |
| 278 | case E1000_DEV_ID_82544GC_COPPER: |
| 279 | case E1000_DEV_ID_82544GC_LOM: |
| 280 | hw->mac_type = e1000_82544; |
| 281 | break; |
| 282 | case E1000_DEV_ID_82540EM: |
| 283 | case E1000_DEV_ID_82540EM_LOM: |
| 284 | case E1000_DEV_ID_82540EP: |
| 285 | case E1000_DEV_ID_82540EP_LOM: |
| 286 | case E1000_DEV_ID_82540EP_LP: |
| 287 | hw->mac_type = e1000_82540; |
| 288 | break; |
| 289 | case E1000_DEV_ID_82545EM_COPPER: |
| 290 | case E1000_DEV_ID_82545EM_FIBER: |
| 291 | hw->mac_type = e1000_82545; |
| 292 | break; |
| 293 | case E1000_DEV_ID_82545GM_COPPER: |
| 294 | case E1000_DEV_ID_82545GM_FIBER: |
| 295 | case E1000_DEV_ID_82545GM_SERDES: |
| 296 | hw->mac_type = e1000_82545_rev_3; |
| 297 | break; |
| 298 | case E1000_DEV_ID_82546EB_COPPER: |
| 299 | case E1000_DEV_ID_82546EB_FIBER: |
| 300 | case E1000_DEV_ID_82546EB_QUAD_COPPER: |
| 301 | hw->mac_type = e1000_82546; |
| 302 | break; |
| 303 | case E1000_DEV_ID_82546GB_COPPER: |
| 304 | case E1000_DEV_ID_82546GB_FIBER: |
| 305 | case E1000_DEV_ID_82546GB_SERDES: |
| 306 | case E1000_DEV_ID_82546GB_PCIE: |
| 307 | case E1000_DEV_ID_82546GB_QUAD_COPPER: |
| 308 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
| 309 | hw->mac_type = e1000_82546_rev_3; |
| 310 | break; |
| 311 | case E1000_DEV_ID_82541EI: |
| 312 | case E1000_DEV_ID_82541EI_MOBILE: |
| 313 | case E1000_DEV_ID_82541ER_LOM: |
| 314 | hw->mac_type = e1000_82541; |
| 315 | break; |
| 316 | case E1000_DEV_ID_82541ER: |
| 317 | case E1000_DEV_ID_82541GI: |
| 318 | case E1000_DEV_ID_82541GI_LF: |
| 319 | case E1000_DEV_ID_82541GI_MOBILE: |
| 320 | hw->mac_type = e1000_82541_rev_2; |
| 321 | break; |
| 322 | case E1000_DEV_ID_82547EI: |
| 323 | case E1000_DEV_ID_82547EI_MOBILE: |
| 324 | hw->mac_type = e1000_82547; |
| 325 | break; |
| 326 | case E1000_DEV_ID_82547GI: |
| 327 | hw->mac_type = e1000_82547_rev_2; |
| 328 | break; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 329 | case E1000_DEV_ID_INTEL_CE4100_GBE: |
| 330 | hw->mac_type = e1000_ce4100; |
| 331 | break; |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 332 | default: |
| 333 | /* Should never have loaded on this device */ |
| 334 | return -E1000_ERR_MAC_TYPE; |
| 335 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 337 | switch (hw->mac_type) { |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 338 | case e1000_82541: |
| 339 | case e1000_82547: |
| 340 | case e1000_82541_rev_2: |
| 341 | case e1000_82547_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 342 | hw->asf_firmware_present = true; |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 343 | break; |
| 344 | default: |
| 345 | break; |
| 346 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 348 | /* The 82543 chip does not count tx_carrier_errors properly in |
| 349 | * FD mode |
| 350 | */ |
| 351 | if (hw->mac_type == e1000_82543) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 352 | hw->bad_tx_carr_stats_fd = true; |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 353 | |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 354 | if (hw->mac_type > e1000_82544) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 355 | hw->has_smbus = true; |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 356 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 357 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 360 | /** |
| 361 | * e1000_set_media_type - Set media type and TBI compatibility. |
| 362 | * @hw: Struct containing variables accessed by shared code |
| 363 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 364 | void e1000_set_media_type(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 366 | u32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 368 | e_dbg("e1000_set_media_type"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 370 | if (hw->mac_type != e1000_82543) { |
| 371 | /* tbi_compatibility is only valid on 82543 */ |
| 372 | hw->tbi_compatibility_en = false; |
| 373 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 375 | switch (hw->device_id) { |
| 376 | case E1000_DEV_ID_82545GM_SERDES: |
| 377 | case E1000_DEV_ID_82546GB_SERDES: |
| 378 | hw->media_type = e1000_media_type_internal_serdes; |
| 379 | break; |
| 380 | default: |
| 381 | switch (hw->mac_type) { |
| 382 | case e1000_82542_rev2_0: |
| 383 | case e1000_82542_rev2_1: |
| 384 | hw->media_type = e1000_media_type_fiber; |
| 385 | break; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 386 | case e1000_ce4100: |
| 387 | hw->media_type = e1000_media_type_copper; |
| 388 | break; |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 389 | default: |
| 390 | status = er32(STATUS); |
| 391 | if (status & E1000_STATUS_TBIMODE) { |
| 392 | hw->media_type = e1000_media_type_fiber; |
| 393 | /* tbi_compatibility not valid on fiber */ |
| 394 | hw->tbi_compatibility_en = false; |
| 395 | } else { |
| 396 | hw->media_type = e1000_media_type_copper; |
| 397 | } |
| 398 | break; |
| 399 | } |
| 400 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 403 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 404 | * e1000_reset_hw - reset the hardware completely |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 405 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 407 | * Reset the transmit and receive units; mask and clear all interrupts. |
| 408 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 409 | s32 e1000_reset_hw(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 411 | u32 ctrl; |
| 412 | u32 ctrl_ext; |
| 413 | u32 icr; |
| 414 | u32 manc; |
| 415 | u32 led_ctrl; |
| 416 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 418 | e_dbg("e1000_reset_hw"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 420 | /* For 82542 (rev 2.0), disable MWI before issuing a device reset */ |
| 421 | if (hw->mac_type == e1000_82542_rev2_0) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 422 | e_dbg("Disabling MWI on 82542 rev 2.0\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 423 | e1000_pci_clear_mwi(hw); |
| 424 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 426 | /* Clear interrupt mask to stop board from generating interrupts */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 427 | e_dbg("Masking off all interrupts\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 428 | ew32(IMC, 0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 430 | /* Disable the Transmit and Receive units. Then delay to allow |
| 431 | * any pending transactions to complete before we hit the MAC with |
| 432 | * the global reset. |
| 433 | */ |
| 434 | ew32(RCTL, 0); |
| 435 | ew32(TCTL, E1000_TCTL_PSP); |
| 436 | E1000_WRITE_FLUSH(); |
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 | /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */ |
| 439 | hw->tbi_compatibility_on = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 441 | /* Delay to allow any outstanding PCI transactions to complete before |
| 442 | * resetting the device |
| 443 | */ |
| 444 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 446 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 448 | /* Must reset the PHY before resetting the MAC */ |
| 449 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 450 | ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST)); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 451 | E1000_WRITE_FLUSH(); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 452 | msleep(5); |
| 453 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 455 | /* Issue a global reset to the MAC. This will reset the chip's |
| 456 | * transmit, receive, DMA, and link units. It will not effect |
| 457 | * the current PCI configuration. The global reset bit is self- |
| 458 | * clearing, and should clear within a microsecond. |
| 459 | */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 460 | e_dbg("Issuing a global reset to MAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 462 | switch (hw->mac_type) { |
| 463 | case e1000_82544: |
| 464 | case e1000_82540: |
| 465 | case e1000_82545: |
| 466 | case e1000_82546: |
| 467 | case e1000_82541: |
| 468 | case e1000_82541_rev_2: |
| 469 | /* These controllers can't ack the 64-bit write when issuing the |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 470 | * reset, so use IO-mapping as a workaround to issue the reset |
| 471 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 472 | E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST)); |
| 473 | break; |
| 474 | case e1000_82545_rev_3: |
| 475 | case e1000_82546_rev_3: |
| 476 | /* Reset is performed on a shadow of the control register */ |
| 477 | ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST)); |
| 478 | break; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 479 | case e1000_ce4100: |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 480 | default: |
| 481 | ew32(CTRL, (ctrl | E1000_CTRL_RST)); |
| 482 | break; |
| 483 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 485 | /* After MAC reset, force reload of EEPROM to restore power-on settings |
| 486 | * to device. Later controllers reload the EEPROM automatically, so |
| 487 | * just wait for reload to complete. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 488 | */ |
| 489 | switch (hw->mac_type) { |
| 490 | case e1000_82542_rev2_0: |
| 491 | case e1000_82542_rev2_1: |
| 492 | case e1000_82543: |
| 493 | case e1000_82544: |
| 494 | /* Wait for reset to complete */ |
| 495 | udelay(10); |
| 496 | ctrl_ext = er32(CTRL_EXT); |
| 497 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; |
| 498 | ew32(CTRL_EXT, ctrl_ext); |
| 499 | E1000_WRITE_FLUSH(); |
| 500 | /* Wait for EEPROM reload */ |
| 501 | msleep(2); |
| 502 | break; |
| 503 | case e1000_82541: |
| 504 | case e1000_82541_rev_2: |
| 505 | case e1000_82547: |
| 506 | case e1000_82547_rev_2: |
| 507 | /* Wait for EEPROM reload */ |
| 508 | msleep(20); |
| 509 | break; |
| 510 | default: |
| 511 | /* Auto read done will delay 5ms or poll based on mac type */ |
| 512 | ret_val = e1000_get_auto_rd_done(hw); |
| 513 | if (ret_val) |
| 514 | return ret_val; |
| 515 | break; |
| 516 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 518 | /* Disable HW ARPs on ASF enabled adapters */ |
| 519 | if (hw->mac_type >= e1000_82540) { |
| 520 | manc = er32(MANC); |
| 521 | manc &= ~(E1000_MANC_ARP_EN); |
| 522 | ew32(MANC, manc); |
| 523 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 525 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 526 | e1000_phy_init_script(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 528 | /* Configure activity LED after PHY reset */ |
| 529 | led_ctrl = er32(LEDCTL); |
| 530 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 531 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 532 | ew32(LEDCTL, led_ctrl); |
| 533 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 535 | /* Clear interrupt mask to stop board from generating interrupts */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 536 | e_dbg("Masking off all interrupts\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 537 | ew32(IMC, 0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 539 | /* Clear any pending interrupt events. */ |
| 540 | icr = er32(ICR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 542 | /* If MWI was previously enabled, reenable it. */ |
| 543 | if (hw->mac_type == e1000_82542_rev2_0) { |
| 544 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
| 545 | e1000_pci_set_mwi(hw); |
| 546 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 548 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 551 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 552 | * e1000_init_hw - Performs basic configuration of the adapter. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 553 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | * |
| 555 | * Assumes that the controller has previously been reset and is in a |
| 556 | * post-reset uninitialized state. Initializes the receive address registers, |
| 557 | * multicast table, and VLAN filter table. Calls routines to setup link |
| 558 | * configuration and flow control settings. Clears all on-chip counters. Leaves |
| 559 | * the transmit and receive units disabled and uninitialized. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 560 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 561 | s32 e1000_init_hw(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 563 | u32 ctrl; |
| 564 | u32 i; |
| 565 | s32 ret_val; |
| 566 | u32 mta_size; |
| 567 | u32 ctrl_ext; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 568 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 569 | e_dbg("e1000_init_hw"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 571 | /* Initialize Identification LED */ |
| 572 | ret_val = e1000_id_led_init(hw); |
| 573 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 574 | e_dbg("Error Initializing Identification LED\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 575 | return ret_val; |
| 576 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 578 | /* Set the media type and TBI compatibility */ |
| 579 | e1000_set_media_type(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 581 | /* Disabling VLAN filtering. */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 582 | e_dbg("Initializing the IEEE VLAN\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 583 | if (hw->mac_type < e1000_82545_rev_3) |
| 584 | ew32(VET, 0); |
| 585 | e1000_clear_vfta(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 587 | /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */ |
| 588 | if (hw->mac_type == e1000_82542_rev2_0) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 589 | e_dbg("Disabling MWI on 82542 rev 2.0\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 590 | e1000_pci_clear_mwi(hw); |
| 591 | ew32(RCTL, E1000_RCTL_RST); |
| 592 | E1000_WRITE_FLUSH(); |
| 593 | msleep(5); |
| 594 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 596 | /* Setup the receive address. This involves initializing all of the |
| 597 | * Receive Address Registers (RARs 0 - 15). |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 598 | */ |
| 599 | e1000_init_rx_addrs(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 601 | /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */ |
| 602 | if (hw->mac_type == e1000_82542_rev2_0) { |
| 603 | ew32(RCTL, 0); |
| 604 | E1000_WRITE_FLUSH(); |
| 605 | msleep(1); |
| 606 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
| 607 | e1000_pci_set_mwi(hw); |
| 608 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 610 | /* Zero out the Multicast HASH table */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 611 | e_dbg("Zeroing the MTA\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 612 | mta_size = E1000_MC_TBL_SIZE; |
| 613 | for (i = 0; i < mta_size; i++) { |
| 614 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
| 615 | /* use write flush to prevent Memory Write Block (MWB) from |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 616 | * occurring when accessing our register space |
| 617 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 618 | E1000_WRITE_FLUSH(); |
| 619 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 621 | /* Set the PCI priority bit correctly in the CTRL register. This |
| 622 | * determines if the adapter gives priority to receives, or if it |
| 623 | * gives equal priority to transmits and receives. Valid only on |
| 624 | * 82542 and 82543 silicon. |
| 625 | */ |
| 626 | if (hw->dma_fairness && hw->mac_type <= e1000_82543) { |
| 627 | ctrl = er32(CTRL); |
| 628 | ew32(CTRL, ctrl | E1000_CTRL_PRIOR); |
| 629 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 631 | switch (hw->mac_type) { |
| 632 | case e1000_82545_rev_3: |
| 633 | case e1000_82546_rev_3: |
| 634 | break; |
| 635 | default: |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 636 | /* Workaround for PCI-X problem when BIOS sets MMRBC |
| 637 | * incorrectly. |
| 638 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 639 | if (hw->bus_type == e1000_bus_type_pcix |
| 640 | && e1000_pcix_get_mmrbc(hw) > 2048) |
| 641 | e1000_pcix_set_mmrbc(hw, 2048); |
| 642 | break; |
| 643 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 645 | /* Call a subroutine to configure the link and setup flow control. */ |
| 646 | ret_val = e1000_setup_link(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 648 | /* Set the transmit descriptor write-back policy */ |
| 649 | if (hw->mac_type > e1000_82544) { |
| 650 | ctrl = er32(TXDCTL); |
| 651 | ctrl = |
| 652 | (ctrl & ~E1000_TXDCTL_WTHRESH) | |
| 653 | E1000_TXDCTL_FULL_TX_DESC_WB; |
| 654 | ew32(TXDCTL, ctrl); |
| 655 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 657 | /* Clear all of the statistics registers (clear on read). It is |
| 658 | * important that we do this after we have tried to establish link |
| 659 | * because the symbol error count will increment wildly if there |
| 660 | * is no link. |
| 661 | */ |
| 662 | e1000_clear_hw_cntrs(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 664 | if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER || |
| 665 | hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) { |
| 666 | ctrl_ext = er32(CTRL_EXT); |
| 667 | /* Relaxed ordering must be disabled to avoid a parity |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 668 | * error crash in a PCI slot. |
| 669 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 670 | ctrl_ext |= E1000_CTRL_EXT_RO_DIS; |
| 671 | ew32(CTRL_EXT, ctrl_ext); |
| 672 | } |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 673 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 674 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 677 | /** |
| 678 | * e1000_adjust_serdes_amplitude - Adjust SERDES output amplitude based on EEPROM setting. |
| 679 | * @hw: Struct containing variables accessed by shared code. |
| 680 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 681 | static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 683 | u16 eeprom_data; |
| 684 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 686 | e_dbg("e1000_adjust_serdes_amplitude"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 688 | if (hw->media_type != e1000_media_type_internal_serdes) |
| 689 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 691 | switch (hw->mac_type) { |
| 692 | case e1000_82545_rev_3: |
| 693 | case e1000_82546_rev_3: |
| 694 | break; |
| 695 | default: |
| 696 | return E1000_SUCCESS; |
| 697 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 699 | ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, |
| 700 | &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 | if (eeprom_data != EEPROM_RESERVED_WORD) { |
| 706 | /* Adjust SERDES output amplitude only. */ |
| 707 | eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK; |
| 708 | ret_val = |
| 709 | e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data); |
| 710 | if (ret_val) |
| 711 | return ret_val; |
| 712 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 714 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 717 | /** |
| 718 | * e1000_setup_link - Configures flow control and link settings. |
| 719 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 721 | * Determines which flow control settings to use. Calls the appropriate media- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | * specific link configuration function. Configures the flow control settings. |
| 723 | * Assuming the adapter has a valid link partner, a valid link should be |
| 724 | * established. Assumes the hardware has previously been reset and the |
| 725 | * transmitter and receiver are not enabled. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 726 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 727 | s32 e1000_setup_link(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 729 | u32 ctrl_ext; |
| 730 | s32 ret_val; |
| 731 | u16 eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 733 | e_dbg("e1000_setup_link"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 735 | /* Read and store word 0x0F of the EEPROM. This word contains bits |
| 736 | * that determine the hardware's default PAUSE (flow control) mode, |
| 737 | * a bit that determines whether the HW defaults to enabling or |
| 738 | * disabling auto-negotiation, and the direction of the |
| 739 | * SW defined pins. If there is no SW over-ride of the flow |
| 740 | * control setting, then the variable hw->fc will |
| 741 | * be initialized based on a value in the EEPROM. |
| 742 | */ |
| 743 | if (hw->fc == E1000_FC_DEFAULT) { |
| 744 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, |
| 745 | 1, &eeprom_data); |
| 746 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 747 | e_dbg("EEPROM Read Error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 748 | return -E1000_ERR_EEPROM; |
| 749 | } |
| 750 | if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0) |
| 751 | hw->fc = E1000_FC_NONE; |
| 752 | else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == |
| 753 | EEPROM_WORD0F_ASM_DIR) |
| 754 | hw->fc = E1000_FC_TX_PAUSE; |
| 755 | else |
| 756 | hw->fc = E1000_FC_FULL; |
| 757 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 759 | /* We want to save off the original Flow Control configuration just |
| 760 | * in case we get disconnected and then reconnected into a different |
| 761 | * hub or switch with different Flow Control capabilities. |
| 762 | */ |
| 763 | if (hw->mac_type == e1000_82542_rev2_0) |
| 764 | hw->fc &= (~E1000_FC_TX_PAUSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 766 | if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1)) |
| 767 | hw->fc &= (~E1000_FC_RX_PAUSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 769 | hw->original_fc = hw->fc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 771 | e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 773 | /* Take the 4 bits from EEPROM word 0x0F that determine the initial |
| 774 | * polarity value for the SW controlled pins, and setup the |
| 775 | * Extended Device Control reg with that info. |
| 776 | * This is needed because one of the SW controlled pins is used for |
| 777 | * signal detection. So this should be done before e1000_setup_pcs_link() |
| 778 | * or e1000_phy_setup() is called. |
| 779 | */ |
| 780 | if (hw->mac_type == e1000_82543) { |
| 781 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, |
| 782 | 1, &eeprom_data); |
| 783 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 784 | e_dbg("EEPROM Read Error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 785 | return -E1000_ERR_EEPROM; |
| 786 | } |
| 787 | ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) << |
| 788 | SWDPIO__EXT_SHIFT); |
| 789 | ew32(CTRL_EXT, ctrl_ext); |
| 790 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 792 | /* Call the necessary subroutine to configure the link. */ |
| 793 | ret_val = (hw->media_type == e1000_media_type_copper) ? |
| 794 | e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 796 | /* Initialize the flow control address, type, and PAUSE timer |
| 797 | * registers to their default values. This is done even if flow |
| 798 | * control is disabled, because it does not hurt anything to |
| 799 | * initialize these registers. |
| 800 | */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 801 | e_dbg("Initializing the Flow Control address, type and timer regs\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 803 | ew32(FCT, FLOW_CONTROL_TYPE); |
| 804 | ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH); |
| 805 | ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 806 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 807 | ew32(FCTTV, hw->fc_pause_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 809 | /* Set the flow control receive threshold registers. Normally, |
| 810 | * these registers will be set to a default threshold that may be |
| 811 | * adjusted later by the driver's runtime code. However, if the |
| 812 | * ability to transmit pause frames in not enabled, then these |
| 813 | * registers will be set to 0. |
| 814 | */ |
| 815 | if (!(hw->fc & E1000_FC_TX_PAUSE)) { |
| 816 | ew32(FCRTL, 0); |
| 817 | ew32(FCRTH, 0); |
| 818 | } else { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 819 | /* We need to set up the Receive Threshold high and low water |
| 820 | * marks as well as (optionally) enabling the transmission of |
| 821 | * XON frames. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 822 | */ |
| 823 | if (hw->fc_send_xon) { |
| 824 | ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE)); |
| 825 | ew32(FCRTH, hw->fc_high_water); |
| 826 | } else { |
| 827 | ew32(FCRTL, hw->fc_low_water); |
| 828 | ew32(FCRTH, hw->fc_high_water); |
| 829 | } |
| 830 | } |
| 831 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | } |
| 833 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 834 | /** |
| 835 | * e1000_setup_fiber_serdes_link - prepare fiber or serdes link |
| 836 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | * |
| 838 | * Manipulates Physical Coding Sublayer functions in order to configure |
| 839 | * link. Assumes the hardware has been previously reset and the transmitter |
| 840 | * and receiver are not enabled. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 841 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 842 | static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 844 | u32 ctrl; |
| 845 | u32 status; |
| 846 | u32 txcw = 0; |
| 847 | u32 i; |
| 848 | u32 signal = 0; |
| 849 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 851 | e_dbg("e1000_setup_fiber_serdes_link"); |
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 | /* On adapters with a MAC newer than 82544, SWDP 1 will be |
| 854 | * set when the optics detect a signal. On older adapters, it will be |
| 855 | * cleared when there is a signal. This applies to fiber media only. |
| 856 | * If we're on serdes media, adjust the output amplitude to value |
| 857 | * set in the EEPROM. |
| 858 | */ |
| 859 | ctrl = er32(CTRL); |
| 860 | if (hw->media_type == e1000_media_type_fiber) |
| 861 | signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 863 | ret_val = e1000_adjust_serdes_amplitude(hw); |
| 864 | if (ret_val) |
| 865 | return ret_val; |
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 | /* Take the link out of reset */ |
| 868 | ctrl &= ~(E1000_CTRL_LRST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 870 | /* Adjust VCO speed to improve BER performance */ |
| 871 | ret_val = e1000_set_vco_speed(hw); |
| 872 | if (ret_val) |
| 873 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 875 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 877 | /* Check for a software override of the flow control settings, and setup |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 878 | * the device accordingly. If auto-negotiation is enabled, then |
| 879 | * software will have to set the "PAUSE" bits to the correct value in |
| 880 | * the Tranmsit Config Word Register (TXCW) and re-start |
| 881 | * auto-negotiation. However, if auto-negotiation is disabled, then |
| 882 | * software will have to manually configure the two flow control enable |
| 883 | * bits in the CTRL register. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 884 | * |
| 885 | * The possible values of the "fc" parameter are: |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 886 | * 0: Flow control is completely disabled |
| 887 | * 1: Rx flow control is enabled (we can receive pause frames, but |
| 888 | * not send pause frames). |
| 889 | * 2: Tx flow control is enabled (we can send pause frames but we do |
| 890 | * not support receiving pause frames). |
| 891 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 892 | */ |
| 893 | switch (hw->fc) { |
| 894 | case E1000_FC_NONE: |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 895 | /* Flow ctrl is completely disabled by a software over-ride */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 896 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); |
| 897 | break; |
| 898 | case E1000_FC_RX_PAUSE: |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 899 | /* Rx Flow control is enabled and Tx Flow control is disabled by |
| 900 | * a software over-ride. Since there really isn't a way to |
| 901 | * advertise that we are capable of Rx Pause ONLY, we will |
| 902 | * advertise that we support both symmetric and asymmetric Rx |
| 903 | * PAUSE. Later, we will disable the adapter's ability to send |
| 904 | * PAUSE frames. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 905 | */ |
| 906 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 907 | break; |
| 908 | case E1000_FC_TX_PAUSE: |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 909 | /* Tx Flow control is enabled, and Rx Flow control is disabled, |
| 910 | * by a software over-ride. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 911 | */ |
| 912 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); |
| 913 | break; |
| 914 | case E1000_FC_FULL: |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 915 | /* Flow control (both Rx and Tx) is enabled by a software |
| 916 | * over-ride. |
| 917 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 918 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 919 | break; |
| 920 | default: |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 921 | e_dbg("Flow control param set incorrectly\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 922 | return -E1000_ERR_CONFIG; |
| 923 | break; |
| 924 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 926 | /* Since auto-negotiation is enabled, take the link out of reset (the |
| 927 | * link will be in reset, because we previously reset the chip). This |
| 928 | * will restart auto-negotiation. If auto-negotiation is successful |
| 929 | * then the link-up status bit will be set and the flow control enable |
| 930 | * bits (RFCE and TFCE) will be set according to their negotiated value. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 931 | */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 932 | e_dbg("Auto-negotiation enabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 934 | ew32(TXCW, txcw); |
| 935 | ew32(CTRL, ctrl); |
| 936 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 938 | hw->txcw = txcw; |
| 939 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 941 | /* If we have a signal (the cable is plugged in) then poll for a |
| 942 | * "Link-Up" indication in the Device Status Register. Time-out if a |
| 943 | * link isn't seen in 500 milliseconds seconds (Auto-negotiation should |
| 944 | * complete in less than 500 milliseconds even if the other end is doing |
| 945 | * it in SW). For internal serdes, we just assume a signal is present, |
| 946 | * then poll. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 947 | */ |
| 948 | if (hw->media_type == e1000_media_type_internal_serdes || |
| 949 | (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 950 | e_dbg("Looking for Link\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 951 | for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) { |
| 952 | msleep(10); |
| 953 | status = er32(STATUS); |
| 954 | if (status & E1000_STATUS_LU) |
| 955 | break; |
| 956 | } |
| 957 | if (i == (LINK_UP_TIMEOUT / 10)) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 958 | e_dbg("Never got a valid link from auto-neg!!!\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 959 | hw->autoneg_failed = 1; |
| 960 | /* AutoNeg failed to achieve a link, so we'll call |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 961 | * e1000_check_for_link. This routine will force the |
| 962 | * link up if we detect a signal. This will allow us to |
| 963 | * communicate with non-autonegotiating link partners. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 964 | */ |
| 965 | ret_val = e1000_check_for_link(hw); |
| 966 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 967 | e_dbg("Error while checking for link\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 968 | return ret_val; |
| 969 | } |
| 970 | hw->autoneg_failed = 0; |
| 971 | } else { |
| 972 | hw->autoneg_failed = 0; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 973 | e_dbg("Valid Link Found\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 974 | } |
| 975 | } else { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 976 | e_dbg("No Signal Detected\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 977 | } |
| 978 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 981 | /** |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 982 | * e1000_copper_link_rtl_setup - Copper link setup for e1000_phy_rtl series. |
| 983 | * @hw: Struct containing variables accessed by shared code |
| 984 | * |
| 985 | * Commits changes to PHY configuration by calling e1000_phy_reset(). |
| 986 | */ |
| 987 | static s32 e1000_copper_link_rtl_setup(struct e1000_hw *hw) |
| 988 | { |
| 989 | s32 ret_val; |
| 990 | |
| 991 | /* SW reset the PHY so all changes take effect */ |
| 992 | ret_val = e1000_phy_reset(hw); |
| 993 | if (ret_val) { |
| 994 | e_dbg("Error Resetting the PHY\n"); |
| 995 | return ret_val; |
| 996 | } |
| 997 | |
| 998 | return E1000_SUCCESS; |
| 999 | } |
| 1000 | |
| 1001 | static s32 gbe_dhg_phy_setup(struct e1000_hw *hw) |
| 1002 | { |
| 1003 | s32 ret_val; |
| 1004 | u32 ctrl_aux; |
| 1005 | |
| 1006 | switch (hw->phy_type) { |
| 1007 | case e1000_phy_8211: |
| 1008 | ret_val = e1000_copper_link_rtl_setup(hw); |
| 1009 | if (ret_val) { |
| 1010 | e_dbg("e1000_copper_link_rtl_setup failed!\n"); |
| 1011 | return ret_val; |
| 1012 | } |
| 1013 | break; |
| 1014 | case e1000_phy_8201: |
| 1015 | /* Set RMII mode */ |
| 1016 | ctrl_aux = er32(CTL_AUX); |
| 1017 | ctrl_aux |= E1000_CTL_AUX_RMII; |
| 1018 | ew32(CTL_AUX, ctrl_aux); |
| 1019 | E1000_WRITE_FLUSH(); |
| 1020 | |
| 1021 | /* Disable the J/K bits required for receive */ |
| 1022 | ctrl_aux = er32(CTL_AUX); |
| 1023 | ctrl_aux |= 0x4; |
| 1024 | ctrl_aux &= ~0x2; |
| 1025 | ew32(CTL_AUX, ctrl_aux); |
| 1026 | E1000_WRITE_FLUSH(); |
| 1027 | ret_val = e1000_copper_link_rtl_setup(hw); |
| 1028 | |
| 1029 | if (ret_val) { |
| 1030 | e_dbg("e1000_copper_link_rtl_setup failed!\n"); |
| 1031 | return ret_val; |
| 1032 | } |
| 1033 | break; |
| 1034 | default: |
| 1035 | e_dbg("Error Resetting the PHY\n"); |
| 1036 | return E1000_ERR_PHY_TYPE; |
| 1037 | } |
| 1038 | |
| 1039 | return E1000_SUCCESS; |
| 1040 | } |
| 1041 | |
| 1042 | /** |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1043 | * e1000_copper_link_preconfig - early configuration for copper |
| 1044 | * @hw: Struct containing variables accessed by shared code |
| 1045 | * |
| 1046 | * Make sure we have a valid PHY and change PHY mode before link setup. |
| 1047 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1048 | static s32 e1000_copper_link_preconfig(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1050 | u32 ctrl; |
| 1051 | s32 ret_val; |
| 1052 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1054 | e_dbg("e1000_copper_link_preconfig"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1056 | ctrl = er32(CTRL); |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1057 | /* With 82543, we need to force speed and duplex on the MAC equal to |
| 1058 | * what the PHY speed and duplex configuration is. In addition, we need |
| 1059 | * to perform a hardware reset on the PHY to take it out of reset. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1060 | */ |
| 1061 | if (hw->mac_type > e1000_82543) { |
| 1062 | ctrl |= E1000_CTRL_SLU; |
| 1063 | ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 1064 | ew32(CTRL, ctrl); |
| 1065 | } else { |
| 1066 | ctrl |= |
| 1067 | (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU); |
| 1068 | ew32(CTRL, ctrl); |
| 1069 | ret_val = e1000_phy_hw_reset(hw); |
| 1070 | if (ret_val) |
| 1071 | return ret_val; |
| 1072 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1074 | /* Make sure we have a valid PHY */ |
| 1075 | ret_val = e1000_detect_gig_phy(hw); |
| 1076 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1077 | e_dbg("Error, did not detect valid phy.\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1078 | return ret_val; |
| 1079 | } |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1080 | e_dbg("Phy ID = %x\n", hw->phy_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1082 | /* Set PHY to class A mode (if necessary) */ |
| 1083 | ret_val = e1000_set_phy_mode(hw); |
| 1084 | if (ret_val) |
| 1085 | return ret_val; |
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 | if ((hw->mac_type == e1000_82545_rev_3) || |
| 1088 | (hw->mac_type == e1000_82546_rev_3)) { |
| 1089 | ret_val = |
| 1090 | e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 1091 | phy_data |= 0x00000008; |
| 1092 | ret_val = |
| 1093 | e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 1094 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1096 | if (hw->mac_type <= e1000_82543 || |
| 1097 | hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 || |
| 1098 | hw->mac_type == e1000_82541_rev_2 |
| 1099 | || hw->mac_type == e1000_82547_rev_2) |
| 1100 | hw->phy_reset_disable = false; |
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 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1103 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1105 | /** |
| 1106 | * e1000_copper_link_igp_setup - Copper link setup for e1000_phy_igp series. |
| 1107 | * @hw: Struct containing variables accessed by shared code |
| 1108 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1109 | static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1110 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1111 | u32 led_ctrl; |
| 1112 | s32 ret_val; |
| 1113 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1115 | e_dbg("e1000_copper_link_igp_setup"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1117 | if (hw->phy_reset_disable) |
| 1118 | return E1000_SUCCESS; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1119 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1120 | ret_val = e1000_phy_reset(hw); |
| 1121 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1122 | e_dbg("Error Resetting the PHY\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1123 | return ret_val; |
| 1124 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1126 | /* Wait 15ms for MAC to configure PHY from eeprom settings */ |
| 1127 | msleep(15); |
| 1128 | /* Configure activity LED after PHY reset */ |
| 1129 | led_ctrl = er32(LEDCTL); |
| 1130 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 1131 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 1132 | ew32(LEDCTL, led_ctrl); |
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 | /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */ |
| 1135 | if (hw->phy_type == e1000_phy_igp) { |
| 1136 | /* disable lplu d3 during driver init */ |
| 1137 | ret_val = e1000_set_d3_lplu_state(hw, false); |
| 1138 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1139 | e_dbg("Error Disabling LPLU D3\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1140 | return ret_val; |
| 1141 | } |
| 1142 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1143 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1144 | /* Configure mdi-mdix settings */ |
| 1145 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); |
| 1146 | if (ret_val) |
| 1147 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1148 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1149 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 1150 | hw->dsp_config_state = e1000_dsp_config_disabled; |
| 1151 | /* Force MDI for earlier revs of the IGP PHY */ |
| 1152 | phy_data &= |
| 1153 | ~(IGP01E1000_PSCR_AUTO_MDIX | |
| 1154 | IGP01E1000_PSCR_FORCE_MDI_MDIX); |
| 1155 | hw->mdix = 1; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1156 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1157 | } else { |
| 1158 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 1159 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1160 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1161 | switch (hw->mdix) { |
| 1162 | case 1: |
| 1163 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 1164 | break; |
| 1165 | case 2: |
| 1166 | phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 1167 | break; |
| 1168 | case 0: |
| 1169 | default: |
| 1170 | phy_data |= IGP01E1000_PSCR_AUTO_MDIX; |
| 1171 | break; |
| 1172 | } |
| 1173 | } |
| 1174 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); |
| 1175 | if (ret_val) |
| 1176 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1177 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1178 | /* set auto-master slave resolution settings */ |
| 1179 | if (hw->autoneg) { |
| 1180 | e1000_ms_type phy_ms_setting = hw->master_slave; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1181 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1182 | if (hw->ffe_config_state == e1000_ffe_config_active) |
| 1183 | hw->ffe_config_state = e1000_ffe_config_enabled; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1184 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1185 | if (hw->dsp_config_state == e1000_dsp_config_activated) |
| 1186 | hw->dsp_config_state = e1000_dsp_config_enabled; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1187 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1188 | /* when autonegotiation advertisement is only 1000Mbps then we |
| 1189 | * should disable SmartSpeed and enable Auto MasterSlave |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1190 | * resolution as hardware default. |
| 1191 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1192 | if (hw->autoneg_advertised == ADVERTISE_1000_FULL) { |
| 1193 | /* Disable SmartSpeed */ |
| 1194 | ret_val = |
| 1195 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 1196 | &phy_data); |
| 1197 | if (ret_val) |
| 1198 | return ret_val; |
| 1199 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 1200 | ret_val = |
| 1201 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 1202 | phy_data); |
| 1203 | if (ret_val) |
| 1204 | return ret_val; |
| 1205 | /* Set auto Master/Slave resolution process */ |
| 1206 | ret_val = |
| 1207 | e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); |
| 1208 | if (ret_val) |
| 1209 | return ret_val; |
| 1210 | phy_data &= ~CR_1000T_MS_ENABLE; |
| 1211 | ret_val = |
| 1212 | e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); |
| 1213 | if (ret_val) |
| 1214 | return ret_val; |
| 1215 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1217 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); |
| 1218 | if (ret_val) |
| 1219 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1221 | /* load defaults for future use */ |
| 1222 | hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ? |
| 1223 | ((phy_data & CR_1000T_MS_VALUE) ? |
| 1224 | e1000_ms_force_master : |
| 1225 | e1000_ms_force_slave) : e1000_ms_auto; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1227 | switch (phy_ms_setting) { |
| 1228 | case e1000_ms_force_master: |
| 1229 | phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE); |
| 1230 | break; |
| 1231 | case e1000_ms_force_slave: |
| 1232 | phy_data |= CR_1000T_MS_ENABLE; |
| 1233 | phy_data &= ~(CR_1000T_MS_VALUE); |
| 1234 | break; |
| 1235 | case e1000_ms_auto: |
| 1236 | phy_data &= ~CR_1000T_MS_ENABLE; |
| 1237 | default: |
| 1238 | break; |
| 1239 | } |
| 1240 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); |
| 1241 | if (ret_val) |
| 1242 | return ret_val; |
| 1243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1245 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1246 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1248 | /** |
| 1249 | * e1000_copper_link_mgp_setup - Copper link setup for e1000_phy_m88 series. |
| 1250 | * @hw: Struct containing variables accessed by shared code |
| 1251 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1252 | static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1253 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1254 | s32 ret_val; |
| 1255 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1257 | e_dbg("e1000_copper_link_mgp_setup"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1258 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1259 | if (hw->phy_reset_disable) |
| 1260 | return E1000_SUCCESS; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1261 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1262 | /* Enable CRS on TX. This must be set for half-duplex operation. */ |
| 1263 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 1264 | if (ret_val) |
| 1265 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1266 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1267 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1268 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1269 | /* Options: |
| 1270 | * MDI/MDI-X = 0 (default) |
| 1271 | * 0 - Auto for all speeds |
| 1272 | * 1 - MDI mode |
| 1273 | * 2 - MDI-X mode |
| 1274 | * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) |
| 1275 | */ |
| 1276 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
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 | switch (hw->mdix) { |
| 1279 | case 1: |
| 1280 | phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE; |
| 1281 | break; |
| 1282 | case 2: |
| 1283 | phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE; |
| 1284 | break; |
| 1285 | case 3: |
| 1286 | phy_data |= M88E1000_PSCR_AUTO_X_1000T; |
| 1287 | break; |
| 1288 | case 0: |
| 1289 | default: |
| 1290 | phy_data |= M88E1000_PSCR_AUTO_X_MODE; |
| 1291 | break; |
| 1292 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1293 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1294 | /* Options: |
| 1295 | * disable_polarity_correction = 0 (default) |
| 1296 | * Automatic Correction for Reversed Cable Polarity |
| 1297 | * 0 - Disabled |
| 1298 | * 1 - Enabled |
| 1299 | */ |
| 1300 | phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL; |
| 1301 | if (hw->disable_polarity_correction == 1) |
| 1302 | phy_data |= M88E1000_PSCR_POLARITY_REVERSAL; |
| 1303 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 1304 | if (ret_val) |
| 1305 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1306 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1307 | if (hw->phy_revision < M88E1011_I_REV_4) { |
| 1308 | /* Force TX_CLK in the Extended PHY Specific Control Register |
| 1309 | * to 25MHz clock. |
| 1310 | */ |
| 1311 | ret_val = |
| 1312 | e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, |
| 1313 | &phy_data); |
| 1314 | if (ret_val) |
| 1315 | return ret_val; |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1316 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1317 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1318 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1319 | if ((hw->phy_revision == E1000_REVISION_2) && |
| 1320 | (hw->phy_id == M88E1111_I_PHY_ID)) { |
| 1321 | /* Vidalia Phy, set the downshift counter to 5x */ |
| 1322 | phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK); |
| 1323 | phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X; |
| 1324 | ret_val = e1000_write_phy_reg(hw, |
| 1325 | M88E1000_EXT_PHY_SPEC_CTRL, |
| 1326 | phy_data); |
| 1327 | if (ret_val) |
| 1328 | return ret_val; |
| 1329 | } else { |
| 1330 | /* Configure Master and Slave downshift values */ |
| 1331 | phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK | |
| 1332 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK); |
| 1333 | phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X | |
| 1334 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X); |
| 1335 | ret_val = e1000_write_phy_reg(hw, |
| 1336 | M88E1000_EXT_PHY_SPEC_CTRL, |
| 1337 | phy_data); |
| 1338 | if (ret_val) |
| 1339 | return ret_val; |
| 1340 | } |
| 1341 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1343 | /* SW Reset the PHY so all changes take effect */ |
| 1344 | ret_val = e1000_phy_reset(hw); |
| 1345 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1346 | e_dbg("Error Resetting the PHY\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1347 | return ret_val; |
| 1348 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1349 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1350 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1351 | } |
| 1352 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1353 | /** |
| 1354 | * e1000_copper_link_autoneg - setup auto-neg |
| 1355 | * @hw: Struct containing variables accessed by shared code |
| 1356 | * |
| 1357 | * Setup auto-negotiation and flow control advertisements, |
| 1358 | * and then perform auto-negotiation. |
| 1359 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1360 | static s32 e1000_copper_link_autoneg(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1361 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1362 | s32 ret_val; |
| 1363 | u16 phy_data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1364 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1365 | e_dbg("e1000_copper_link_autoneg"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1366 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1367 | /* Perform some bounds checking on the hw->autoneg_advertised |
| 1368 | * parameter. If this variable is zero, then set it to the default. |
| 1369 | */ |
| 1370 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1371 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1372 | /* If autoneg_advertised is zero, we assume it was not defaulted |
| 1373 | * by the calling code so we set to advertise full capability. |
| 1374 | */ |
| 1375 | if (hw->autoneg_advertised == 0) |
| 1376 | hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1377 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1378 | /* IFE/RTL8201N PHY only supports 10/100 */ |
| 1379 | if (hw->phy_type == e1000_phy_8201) |
| 1380 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL; |
| 1381 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1382 | e_dbg("Reconfiguring auto-neg advertisement params\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1383 | ret_val = e1000_phy_setup_autoneg(hw); |
| 1384 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1385 | e_dbg("Error Setting up Auto-Negotiation\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1386 | return ret_val; |
| 1387 | } |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1388 | e_dbg("Restarting Auto-Neg\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1389 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1390 | /* Restart auto-negotiation by setting the Auto Neg Enable bit and |
| 1391 | * the Auto Neg Restart bit in the PHY control register. |
| 1392 | */ |
| 1393 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
| 1394 | if (ret_val) |
| 1395 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1396 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1397 | phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); |
| 1398 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); |
| 1399 | if (ret_val) |
| 1400 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1401 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1402 | /* Does the user want to wait for Auto-Neg to complete here, or |
| 1403 | * check at a later time (for example, callback routine). |
| 1404 | */ |
| 1405 | if (hw->wait_autoneg_complete) { |
| 1406 | ret_val = e1000_wait_autoneg(hw); |
| 1407 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1408 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1409 | ("Error while waiting for autoneg to complete\n"); |
| 1410 | return ret_val; |
| 1411 | } |
| 1412 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1414 | hw->get_link_status = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1416 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1417 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1419 | /** |
| 1420 | * e1000_copper_link_postconfig - post link setup |
| 1421 | * @hw: Struct containing variables accessed by shared code |
| 1422 | * |
| 1423 | * Config the MAC and the PHY after link is up. |
| 1424 | * 1) Set up the MAC to the current PHY speed/duplex |
| 1425 | * if we are on 82543. If we |
| 1426 | * are on newer silicon, we only need to configure |
| 1427 | * collision distance in the Transmit Control Register. |
| 1428 | * 2) Set up flow control on the MAC to that established with |
| 1429 | * the link partner. |
| 1430 | * 3) Config DSP to improve Gigabit link quality for some PHY revisions. |
| 1431 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1432 | static s32 e1000_copper_link_postconfig(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1433 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1434 | s32 ret_val; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1435 | e_dbg("e1000_copper_link_postconfig"); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1436 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1437 | if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100)) { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1438 | e1000_config_collision_dist(hw); |
| 1439 | } else { |
| 1440 | ret_val = e1000_config_mac_to_phy(hw); |
| 1441 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1442 | e_dbg("Error configuring MAC to PHY settings\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1443 | return ret_val; |
| 1444 | } |
| 1445 | } |
| 1446 | ret_val = e1000_config_fc_after_link_up(hw); |
| 1447 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1448 | e_dbg("Error Configuring Flow Control\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1449 | return ret_val; |
| 1450 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1451 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1452 | /* Config DSP to improve Giga link quality */ |
| 1453 | if (hw->phy_type == e1000_phy_igp) { |
| 1454 | ret_val = e1000_config_dsp_after_link_change(hw, true); |
| 1455 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1456 | e_dbg("Error Configuring DSP after link up\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1457 | return ret_val; |
| 1458 | } |
| 1459 | } |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1460 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1461 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1464 | /** |
| 1465 | * e1000_setup_copper_link - phy/speed/duplex setting |
| 1466 | * @hw: Struct containing variables accessed by shared code |
| 1467 | * |
| 1468 | * Detects which PHY is present and sets up the speed and duplex |
| 1469 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1470 | static s32 e1000_setup_copper_link(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1471 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1472 | s32 ret_val; |
| 1473 | u16 i; |
| 1474 | u16 phy_data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1475 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1476 | e_dbg("e1000_setup_copper_link"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1477 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1478 | /* Check if it is a valid PHY and set PHY mode if necessary. */ |
| 1479 | ret_val = e1000_copper_link_preconfig(hw); |
| 1480 | if (ret_val) |
| 1481 | return ret_val; |
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->phy_type == e1000_phy_igp) { |
| 1484 | ret_val = e1000_copper_link_igp_setup(hw); |
| 1485 | if (ret_val) |
| 1486 | return ret_val; |
| 1487 | } else if (hw->phy_type == e1000_phy_m88) { |
| 1488 | ret_val = e1000_copper_link_mgp_setup(hw); |
| 1489 | if (ret_val) |
| 1490 | return ret_val; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1491 | } else { |
| 1492 | ret_val = gbe_dhg_phy_setup(hw); |
| 1493 | if (ret_val) { |
| 1494 | e_dbg("gbe_dhg_phy_setup failed!\n"); |
| 1495 | return ret_val; |
| 1496 | } |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1497 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1498 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1499 | if (hw->autoneg) { |
| 1500 | /* Setup autoneg and flow control advertisement |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1501 | * and perform autonegotiation |
| 1502 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1503 | ret_val = e1000_copper_link_autoneg(hw); |
| 1504 | if (ret_val) |
| 1505 | return ret_val; |
| 1506 | } else { |
| 1507 | /* PHY will be set to 10H, 10F, 100H,or 100F |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1508 | * depending on value from forced_speed_duplex. |
| 1509 | */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1510 | e_dbg("Forcing speed and duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1511 | ret_val = e1000_phy_force_speed_duplex(hw); |
| 1512 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1513 | e_dbg("Error Forcing Speed and Duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1514 | return ret_val; |
| 1515 | } |
| 1516 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1518 | /* Check link status. Wait up to 100 microseconds for link to become |
| 1519 | * valid. |
| 1520 | */ |
| 1521 | for (i = 0; i < 10; i++) { |
| 1522 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 1523 | if (ret_val) |
| 1524 | return ret_val; |
| 1525 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 1526 | if (ret_val) |
| 1527 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1529 | if (phy_data & MII_SR_LINK_STATUS) { |
| 1530 | /* Config the MAC and PHY after link is up */ |
| 1531 | ret_val = e1000_copper_link_postconfig(hw); |
| 1532 | if (ret_val) |
| 1533 | return ret_val; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1534 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1535 | e_dbg("Valid link established!!!\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1536 | return E1000_SUCCESS; |
| 1537 | } |
| 1538 | udelay(10); |
| 1539 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1541 | e_dbg("Unable to establish link!!!\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1542 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | } |
| 1544 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1545 | /** |
| 1546 | * e1000_phy_setup_autoneg - phy settings |
| 1547 | * @hw: Struct containing variables accessed by shared code |
| 1548 | * |
| 1549 | * Configures PHY autoneg and flow control advertisement settings |
| 1550 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1551 | s32 e1000_phy_setup_autoneg(struct e1000_hw *hw) |
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 | s32 ret_val; |
| 1554 | u16 mii_autoneg_adv_reg; |
| 1555 | u16 mii_1000t_ctrl_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1557 | e_dbg("e1000_phy_setup_autoneg"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1559 | /* Read the MII Auto-Neg Advertisement Register (Address 4). */ |
| 1560 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg); |
| 1561 | if (ret_val) |
| 1562 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1564 | /* Read the MII 1000Base-T Control Register (Address 9). */ |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1565 | 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] | 1566 | if (ret_val) |
| 1567 | return ret_val; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1568 | else if (hw->phy_type == e1000_phy_8201) |
| 1569 | mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1571 | /* Need to parse both autoneg_advertised and fc and set up |
| 1572 | * the appropriate PHY registers. First we will parse for |
| 1573 | * autoneg_advertised software override. Since we can advertise |
| 1574 | * a plethora of combinations, we need to check each bit |
| 1575 | * individually. |
| 1576 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1578 | /* First we clear all the 10/100 mb speed bits in the Auto-Neg |
| 1579 | * Advertisement Register (Address 4) and the 1000 mb speed bits in |
| 1580 | * the 1000Base-T Control Register (Address 9). |
| 1581 | */ |
| 1582 | mii_autoneg_adv_reg &= ~REG4_SPEED_MASK; |
| 1583 | mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1585 | e_dbg("autoneg_advertised %x\n", hw->autoneg_advertised); |
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 10 Mb Half Duplex? */ |
| 1588 | if (hw->autoneg_advertised & ADVERTISE_10_HALF) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1589 | e_dbg("Advertise 10mb Half duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1590 | mii_autoneg_adv_reg |= NWAY_AR_10T_HD_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 | /* Do we want to advertise 10 Mb Full Duplex? */ |
| 1594 | if (hw->autoneg_advertised & ADVERTISE_10_FULL) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1595 | e_dbg("Advertise 10mb Full duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1596 | mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS; |
| 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 100 Mb Half Duplex? */ |
| 1600 | if (hw->autoneg_advertised & ADVERTISE_100_HALF) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1601 | e_dbg("Advertise 100mb Half duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1602 | mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_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 | /* Do we want to advertise 100 Mb Full Duplex? */ |
| 1606 | if (hw->autoneg_advertised & ADVERTISE_100_FULL) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1607 | e_dbg("Advertise 100mb Full duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1608 | mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS; |
| 1609 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1611 | /* We do not allow the Phy to advertise 1000 Mb Half Duplex */ |
| 1612 | if (hw->autoneg_advertised & ADVERTISE_1000_HALF) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1613 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1614 | ("Advertise 1000mb Half duplex requested, request denied!\n"); |
| 1615 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1617 | /* Do we want to advertise 1000 Mb Full Duplex? */ |
| 1618 | if (hw->autoneg_advertised & ADVERTISE_1000_FULL) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1619 | e_dbg("Advertise 1000mb Full duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1620 | mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS; |
| 1621 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1623 | /* Check for a software override of the flow control settings, and |
| 1624 | * setup the PHY advertisement registers accordingly. If |
| 1625 | * auto-negotiation is enabled, then software will have to set the |
| 1626 | * "PAUSE" bits to the correct value in the Auto-Negotiation |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1627 | * Advertisement Register (PHY_AUTONEG_ADV) and re-start |
| 1628 | * auto-negotiation. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1629 | * |
| 1630 | * The possible values of the "fc" parameter are: |
| 1631 | * 0: Flow control is completely disabled |
| 1632 | * 1: Rx flow control is enabled (we can receive pause frames |
| 1633 | * but not send pause frames). |
| 1634 | * 2: Tx flow control is enabled (we can send pause frames |
| 1635 | * but we do not support receiving pause frames). |
| 1636 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
| 1637 | * other: No software override. The flow control configuration |
| 1638 | * in the EEPROM is used. |
| 1639 | */ |
| 1640 | switch (hw->fc) { |
| 1641 | case E1000_FC_NONE: /* 0 */ |
| 1642 | /* Flow control (RX & TX) is completely disabled by a |
| 1643 | * software over-ride. |
| 1644 | */ |
| 1645 | mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 1646 | break; |
| 1647 | case E1000_FC_RX_PAUSE: /* 1 */ |
| 1648 | /* RX Flow control is enabled, and TX Flow control is |
| 1649 | * disabled, by a software over-ride. |
| 1650 | */ |
| 1651 | /* Since there really isn't a way to advertise that we are |
| 1652 | * capable of RX Pause ONLY, we will advertise that we |
| 1653 | * support both symmetric and asymmetric RX PAUSE. Later |
| 1654 | * (in e1000_config_fc_after_link_up) we will disable the |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1655 | * hw's ability to send PAUSE frames. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1656 | */ |
| 1657 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 1658 | break; |
| 1659 | case E1000_FC_TX_PAUSE: /* 2 */ |
| 1660 | /* TX Flow control is enabled, and RX Flow control is |
| 1661 | * disabled, by a software over-ride. |
| 1662 | */ |
| 1663 | mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR; |
| 1664 | mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE; |
| 1665 | break; |
| 1666 | case E1000_FC_FULL: /* 3 */ |
| 1667 | /* Flow control (both RX and TX) is enabled by a software |
| 1668 | * over-ride. |
| 1669 | */ |
| 1670 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 1671 | break; |
| 1672 | default: |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1673 | e_dbg("Flow control param set incorrectly\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1674 | return -E1000_ERR_CONFIG; |
| 1675 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1677 | ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg); |
| 1678 | if (ret_val) |
| 1679 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1681 | e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1683 | if (hw->phy_type == e1000_phy_8201) { |
| 1684 | mii_1000t_ctrl_reg = 0; |
| 1685 | } else { |
| 1686 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, |
| 1687 | mii_1000t_ctrl_reg); |
| 1688 | if (ret_val) |
| 1689 | return ret_val; |
| 1690 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1692 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1695 | /** |
| 1696 | * e1000_phy_force_speed_duplex - force link settings |
| 1697 | * @hw: Struct containing variables accessed by shared code |
| 1698 | * |
| 1699 | * Force PHY speed and duplex settings to hw->forced_speed_duplex |
| 1700 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1701 | static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1703 | u32 ctrl; |
| 1704 | s32 ret_val; |
| 1705 | u16 mii_ctrl_reg; |
| 1706 | u16 mii_status_reg; |
| 1707 | u16 phy_data; |
| 1708 | u16 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1710 | e_dbg("e1000_phy_force_speed_duplex"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1712 | /* Turn off Flow control if we are forcing speed and duplex. */ |
| 1713 | hw->fc = E1000_FC_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1715 | e_dbg("hw->fc = %d\n", hw->fc); |
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 | /* Read the Device Control Register. */ |
| 1718 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1720 | /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */ |
| 1721 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 1722 | ctrl &= ~(DEVICE_SPEED_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1724 | /* Clear the Auto Speed Detect Enable bit. */ |
| 1725 | ctrl &= ~E1000_CTRL_ASDE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1727 | /* Read the MII Control Register. */ |
| 1728 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg); |
| 1729 | if (ret_val) |
| 1730 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1732 | /* We need to disable autoneg in order to force link and duplex. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1734 | mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1736 | /* Are we forcing Full or Half Duplex? */ |
| 1737 | if (hw->forced_speed_duplex == e1000_100_full || |
| 1738 | hw->forced_speed_duplex == e1000_10_full) { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1739 | /* We want to force full duplex so we SET the full duplex bits |
| 1740 | * in the Device and MII Control Registers. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1741 | */ |
| 1742 | ctrl |= E1000_CTRL_FD; |
| 1743 | mii_ctrl_reg |= MII_CR_FULL_DUPLEX; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1744 | e_dbg("Full Duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1745 | } else { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1746 | /* We want to force half duplex so we CLEAR the full duplex bits |
| 1747 | * in the Device and MII Control Registers. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1748 | */ |
| 1749 | ctrl &= ~E1000_CTRL_FD; |
| 1750 | mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1751 | e_dbg("Half Duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1752 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1754 | /* Are we forcing 100Mbps??? */ |
| 1755 | if (hw->forced_speed_duplex == e1000_100_full || |
| 1756 | hw->forced_speed_duplex == e1000_100_half) { |
| 1757 | /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */ |
| 1758 | ctrl |= E1000_CTRL_SPD_100; |
| 1759 | mii_ctrl_reg |= MII_CR_SPEED_100; |
| 1760 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10); |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1761 | e_dbg("Forcing 100mb "); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1762 | } else { |
| 1763 | /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */ |
| 1764 | ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100); |
| 1765 | mii_ctrl_reg |= MII_CR_SPEED_10; |
| 1766 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100); |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1767 | e_dbg("Forcing 10mb "); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1768 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1770 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1772 | /* Write the configured values back to the Device Control Reg. */ |
| 1773 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1775 | if (hw->phy_type == e1000_phy_m88) { |
| 1776 | ret_val = |
| 1777 | e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 1778 | if (ret_val) |
| 1779 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1781 | /* Clear Auto-Crossover to force MDI manually. M88E1000 requires |
| 1782 | * MDI forced whenever speed are duplex are forced. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1783 | */ |
| 1784 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 1785 | ret_val = |
| 1786 | e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 1787 | if (ret_val) |
| 1788 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1790 | e_dbg("M88E1000 PSCR: %x\n", phy_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1792 | /* Need to reset the PHY or these changes will be ignored */ |
| 1793 | mii_ctrl_reg |= MII_CR_RESET; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 1794 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1795 | /* Disable MDI-X support for 10/100 */ |
| 1796 | } else { |
| 1797 | /* Clear Auto-Crossover to force MDI manually. IGP requires MDI |
| 1798 | * forced whenever speed or duplex are forced. |
| 1799 | */ |
| 1800 | ret_val = |
| 1801 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); |
| 1802 | if (ret_val) |
| 1803 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1805 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 1806 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1808 | ret_val = |
| 1809 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); |
| 1810 | if (ret_val) |
| 1811 | return ret_val; |
| 1812 | } |
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 | /* Write back the modified PHY MII control register. */ |
| 1815 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg); |
| 1816 | if (ret_val) |
| 1817 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1819 | udelay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1821 | /* The wait_autoneg_complete flag may be a little misleading here. |
| 1822 | * Since we are forcing speed and duplex, Auto-Neg is not enabled. |
| 1823 | * But we do want to delay for a period while forcing only so we |
| 1824 | * don't generate false No Link messages. So we will wait here |
| 1825 | * only if the user has set wait_autoneg_complete to 1, which is |
| 1826 | * the default. |
| 1827 | */ |
| 1828 | if (hw->wait_autoneg_complete) { |
| 1829 | /* We will wait for autoneg to complete. */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1830 | e_dbg("Waiting for forced speed/duplex link.\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1831 | mii_status_reg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1833 | /* Wait for autoneg to complete or 4.5 seconds to expire */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1834 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1835 | /* Read the MII Status Register and wait for Auto-Neg |
| 1836 | * Complete bit to be set. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1837 | */ |
| 1838 | ret_val = |
| 1839 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 1840 | if (ret_val) |
| 1841 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1843 | ret_val = |
| 1844 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 1845 | if (ret_val) |
| 1846 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1848 | if (mii_status_reg & MII_SR_LINK_STATUS) |
| 1849 | break; |
| 1850 | msleep(100); |
| 1851 | } |
| 1852 | if ((i == 0) && (hw->phy_type == e1000_phy_m88)) { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1853 | /* We didn't get link. Reset the DSP and wait again |
| 1854 | * for link. |
| 1855 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1856 | ret_val = e1000_phy_reset_dsp(hw); |
| 1857 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1858 | e_dbg("Error Resetting PHY DSP\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1859 | return ret_val; |
| 1860 | } |
| 1861 | } |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1862 | /* This loop will early-out if the link condition has been |
| 1863 | * met |
| 1864 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1865 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
| 1866 | if (mii_status_reg & MII_SR_LINK_STATUS) |
| 1867 | break; |
| 1868 | msleep(100); |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1869 | /* Read the MII Status Register and wait for Auto-Neg |
| 1870 | * Complete bit to be set. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1871 | */ |
| 1872 | ret_val = |
| 1873 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 1874 | if (ret_val) |
| 1875 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1877 | ret_val = |
| 1878 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 1879 | if (ret_val) |
| 1880 | return ret_val; |
| 1881 | } |
| 1882 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1884 | if (hw->phy_type == e1000_phy_m88) { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1885 | /* Because we reset the PHY above, we need to re-force TX_CLK in |
| 1886 | * the Extended PHY Specific Control Register to 25MHz clock. |
| 1887 | * This value defaults back to a 2.5MHz clock when the PHY is |
| 1888 | * reset. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1889 | */ |
| 1890 | ret_val = |
| 1891 | e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, |
| 1892 | &phy_data); |
| 1893 | if (ret_val) |
| 1894 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1896 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
| 1897 | ret_val = |
| 1898 | e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, |
| 1899 | phy_data); |
| 1900 | if (ret_val) |
| 1901 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1903 | /* In addition, because of the s/w reset above, we need to |
| 1904 | * enable CRS on Tx. This must be set for both full and half |
| 1905 | * duplex operation. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1906 | */ |
| 1907 | ret_val = |
| 1908 | e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 1909 | if (ret_val) |
| 1910 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1912 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 1913 | ret_val = |
| 1914 | e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 1915 | if (ret_val) |
| 1916 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1918 | if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) |
| 1919 | && (!hw->autoneg) |
| 1920 | && (hw->forced_speed_duplex == e1000_10_full |
| 1921 | || hw->forced_speed_duplex == e1000_10_half)) { |
| 1922 | ret_val = e1000_polarity_reversal_workaround(hw); |
| 1923 | if (ret_val) |
| 1924 | return ret_val; |
| 1925 | } |
| 1926 | } |
| 1927 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | } |
| 1929 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1930 | /** |
| 1931 | * e1000_config_collision_dist - set collision distance register |
| 1932 | * @hw: Struct containing variables accessed by shared code |
| 1933 | * |
| 1934 | * Sets the collision distance in the Transmit Control register. |
| 1935 | * Link should have been established previously. Reads the speed and duplex |
| 1936 | * information from the Device Status register. |
| 1937 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1938 | void e1000_config_collision_dist(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1940 | u32 tctl, coll_dist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1942 | e_dbg("e1000_config_collision_dist"); |
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 | if (hw->mac_type < e1000_82543) |
| 1945 | coll_dist = E1000_COLLISION_DISTANCE_82542; |
| 1946 | else |
| 1947 | coll_dist = E1000_COLLISION_DISTANCE; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1948 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1949 | tctl = er32(TCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1951 | tctl &= ~E1000_TCTL_COLD; |
| 1952 | tctl |= coll_dist << E1000_COLD_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1954 | ew32(TCTL, tctl); |
| 1955 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1958 | /** |
| 1959 | * e1000_config_mac_to_phy - sync phy and mac settings |
| 1960 | * @hw: Struct containing variables accessed by shared code |
| 1961 | * @mii_reg: data to write to the MII control register |
| 1962 | * |
| 1963 | * Sets MAC speed and duplex settings to reflect the those in the PHY |
| 1964 | * The contents of the PHY register containing the needed information need to |
| 1965 | * be passed in. |
| 1966 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1967 | static s32 e1000_config_mac_to_phy(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1969 | u32 ctrl; |
| 1970 | s32 ret_val; |
| 1971 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 1973 | e_dbg("e1000_config_mac_to_phy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1975 | /* 82544 or newer MAC, Auto Speed Detection takes care of |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 1976 | * MAC speed/duplex configuration. |
| 1977 | */ |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1978 | if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100)) |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1979 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1980 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1981 | /* Read the Device Control Register and set the bits to Force Speed |
| 1982 | * and Duplex. |
| 1983 | */ |
| 1984 | ctrl = er32(CTRL); |
| 1985 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 1986 | ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1988 | switch (hw->phy_type) { |
| 1989 | case e1000_phy_8201: |
| 1990 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
| 1991 | if (ret_val) |
| 1992 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1994 | if (phy_data & RTL_PHY_CTRL_FD) |
| 1995 | ctrl |= E1000_CTRL_FD; |
| 1996 | else |
| 1997 | ctrl &= ~E1000_CTRL_FD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 1999 | if (phy_data & RTL_PHY_CTRL_SPD_100) |
| 2000 | ctrl |= E1000_CTRL_SPD_100; |
| 2001 | else |
| 2002 | ctrl |= E1000_CTRL_SPD_10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2004 | e1000_config_collision_dist(hw); |
| 2005 | break; |
| 2006 | default: |
| 2007 | /* Set up duplex in the Device Control and Transmit Control |
| 2008 | * registers depending on negotiated values. |
| 2009 | */ |
| 2010 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2011 | &phy_data); |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2012 | if (ret_val) |
| 2013 | return ret_val; |
| 2014 | |
| 2015 | if (phy_data & M88E1000_PSSR_DPLX) |
| 2016 | ctrl |= E1000_CTRL_FD; |
| 2017 | else |
| 2018 | ctrl &= ~E1000_CTRL_FD; |
| 2019 | |
| 2020 | e1000_config_collision_dist(hw); |
| 2021 | |
| 2022 | /* Set up speed in the Device Control register depending on |
| 2023 | * negotiated values. |
| 2024 | */ |
| 2025 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) |
| 2026 | ctrl |= E1000_CTRL_SPD_1000; |
| 2027 | else if ((phy_data & M88E1000_PSSR_SPEED) == |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2028 | M88E1000_PSSR_100MBS) |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2029 | ctrl |= E1000_CTRL_SPD_100; |
| 2030 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2032 | /* Write the configured values back to the Device Control Reg. */ |
| 2033 | ew32(CTRL, ctrl); |
| 2034 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2037 | /** |
| 2038 | * e1000_force_mac_fc - force flow control settings |
| 2039 | * @hw: Struct containing variables accessed by shared code |
| 2040 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | * Forces the MAC's flow control settings. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | * Sets the TFCE and RFCE bits in the device control register to reflect |
| 2043 | * the adapter settings. TFCE and RFCE need to be explicitly set by |
| 2044 | * software when a Copper PHY is used because autonegotiation is managed |
| 2045 | * by the PHY rather than the MAC. Software must also configure these |
| 2046 | * bits when link is forced on a fiber connection. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2047 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2048 | s32 e1000_force_mac_fc(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2050 | u32 ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2052 | e_dbg("e1000_force_mac_fc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2054 | /* Get the current configuration of the Device Control Register */ |
| 2055 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2057 | /* Because we didn't get link via the internal auto-negotiation |
| 2058 | * mechanism (we either forced link or we got link via PHY |
| 2059 | * auto-neg), we have to manually enable/disable transmit an |
| 2060 | * receive flow control. |
| 2061 | * |
| 2062 | * The "Case" statement below enables/disable flow control |
| 2063 | * according to the "hw->fc" parameter. |
| 2064 | * |
| 2065 | * The possible values of the "fc" parameter are: |
| 2066 | * 0: Flow control is completely disabled |
| 2067 | * 1: Rx flow control is enabled (we can receive pause |
| 2068 | * frames but not send pause frames). |
| 2069 | * 2: Tx flow control is enabled (we can send pause frames |
| 2070 | * frames but we do not receive pause frames). |
| 2071 | * 3: Both Rx and TX flow control (symmetric) is enabled. |
| 2072 | * other: No other values should be possible at this point. |
| 2073 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2075 | switch (hw->fc) { |
| 2076 | case E1000_FC_NONE: |
| 2077 | ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); |
| 2078 | break; |
| 2079 | case E1000_FC_RX_PAUSE: |
| 2080 | ctrl &= (~E1000_CTRL_TFCE); |
| 2081 | ctrl |= E1000_CTRL_RFCE; |
| 2082 | break; |
| 2083 | case E1000_FC_TX_PAUSE: |
| 2084 | ctrl &= (~E1000_CTRL_RFCE); |
| 2085 | ctrl |= E1000_CTRL_TFCE; |
| 2086 | break; |
| 2087 | case E1000_FC_FULL: |
| 2088 | ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); |
| 2089 | break; |
| 2090 | default: |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2091 | e_dbg("Flow control param set incorrectly\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2092 | return -E1000_ERR_CONFIG; |
| 2093 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2095 | /* Disable TX Flow Control for 82542 (rev 2.0) */ |
| 2096 | if (hw->mac_type == e1000_82542_rev2_0) |
| 2097 | ctrl &= (~E1000_CTRL_TFCE); |
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 | ew32(CTRL, ctrl); |
| 2100 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | } |
| 2102 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2103 | /** |
| 2104 | * e1000_config_fc_after_link_up - configure flow control after autoneg |
| 2105 | * @hw: Struct containing variables accessed by shared code |
| 2106 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | * Configures flow control settings after link is established |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | * Should be called immediately after a valid link has been established. |
| 2109 | * Forces MAC flow control settings if link was forced. When in MII/GMII mode |
| 2110 | * and autonegotiation is enabled, the MAC flow control settings will be set |
| 2111 | * 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] | 2112 | * and RFCE bits will be automatically set to the negotiated flow control mode. |
| 2113 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2114 | static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2116 | s32 ret_val; |
| 2117 | u16 mii_status_reg; |
| 2118 | u16 mii_nway_adv_reg; |
| 2119 | u16 mii_nway_lp_ability_reg; |
| 2120 | u16 speed; |
| 2121 | u16 duplex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2123 | e_dbg("e1000_config_fc_after_link_up"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2125 | /* Check for the case where we have fiber media and auto-neg failed |
| 2126 | * so we had to force link. In this case, we need to force the |
| 2127 | * configuration of the MAC to match the "fc" parameter. |
| 2128 | */ |
| 2129 | if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) |
| 2130 | || ((hw->media_type == e1000_media_type_internal_serdes) |
| 2131 | && (hw->autoneg_failed)) |
| 2132 | || ((hw->media_type == e1000_media_type_copper) |
| 2133 | && (!hw->autoneg))) { |
| 2134 | ret_val = e1000_force_mac_fc(hw); |
| 2135 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2136 | e_dbg("Error forcing flow control settings\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2137 | return ret_val; |
| 2138 | } |
| 2139 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2141 | /* Check for the case where we have copper media and auto-neg is |
| 2142 | * enabled. In this case, we need to check and see if Auto-Neg |
| 2143 | * has completed, and if so, how the PHY and link partner has |
| 2144 | * flow control configured. |
| 2145 | */ |
| 2146 | if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) { |
| 2147 | /* Read the MII Status Register and check to see if AutoNeg |
| 2148 | * has completed. We read this twice because this reg has |
| 2149 | * some "sticky" (latched) bits. |
| 2150 | */ |
| 2151 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 2152 | if (ret_val) |
| 2153 | return ret_val; |
| 2154 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 2155 | if (ret_val) |
| 2156 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2158 | if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) { |
| 2159 | /* The AutoNeg process has completed, so we now need to |
| 2160 | * read both the Auto Negotiation Advertisement Register |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2161 | * (Address 4) and the Auto_Negotiation Base Page |
| 2162 | * Ability Register (Address 5) to determine how flow |
| 2163 | * control was negotiated. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2164 | */ |
| 2165 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, |
| 2166 | &mii_nway_adv_reg); |
| 2167 | if (ret_val) |
| 2168 | return ret_val; |
| 2169 | ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, |
| 2170 | &mii_nway_lp_ability_reg); |
| 2171 | if (ret_val) |
| 2172 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2174 | /* Two bits in the Auto Negotiation Advertisement |
| 2175 | * Register (Address 4) and two bits in the Auto |
| 2176 | * Negotiation Base Page Ability Register (Address 5) |
| 2177 | * determine flow control for both the PHY and the link |
| 2178 | * partner. The following table, taken out of the IEEE |
| 2179 | * 802.3ab/D6.0 dated March 25, 1999, describes these |
| 2180 | * PAUSE resolution bits and how flow control is |
| 2181 | * determined based upon these settings. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2182 | * NOTE: DC = Don't Care |
| 2183 | * |
| 2184 | * LOCAL DEVICE | LINK PARTNER |
| 2185 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2186 | *-------|---------|-------|---------|------------------ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2187 | * 0 | 0 | DC | DC | E1000_FC_NONE |
| 2188 | * 0 | 1 | 0 | DC | E1000_FC_NONE |
| 2189 | * 0 | 1 | 1 | 0 | E1000_FC_NONE |
| 2190 | * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE |
| 2191 | * 1 | 0 | 0 | DC | E1000_FC_NONE |
| 2192 | * 1 | DC | 1 | DC | E1000_FC_FULL |
| 2193 | * 1 | 1 | 0 | 0 | E1000_FC_NONE |
| 2194 | * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE |
| 2195 | * |
| 2196 | */ |
| 2197 | /* Are both PAUSE bits set to 1? If so, this implies |
| 2198 | * Symmetric Flow Control is enabled at both ends. The |
| 2199 | * ASM_DIR bits are irrelevant per the spec. |
| 2200 | * |
| 2201 | * For Symmetric Flow Control: |
| 2202 | * |
| 2203 | * LOCAL DEVICE | LINK PARTNER |
| 2204 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2205 | *-------|---------|-------|---------|------------------ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2206 | * 1 | DC | 1 | DC | E1000_FC_FULL |
| 2207 | * |
| 2208 | */ |
| 2209 | if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2210 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2211 | /* Now we need to check if the user selected Rx |
| 2212 | * ONLY of pause frames. In this case, we had |
| 2213 | * to advertise FULL flow control because we |
| 2214 | * could not advertise Rx ONLY. Hence, we must |
| 2215 | * now check to see if we need to turn OFF the |
| 2216 | * TRANSMISSION of PAUSE frames. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2217 | */ |
| 2218 | if (hw->original_fc == E1000_FC_FULL) { |
| 2219 | hw->fc = E1000_FC_FULL; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2220 | e_dbg("Flow Control = FULL.\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2221 | } else { |
| 2222 | hw->fc = E1000_FC_RX_PAUSE; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2223 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2224 | ("Flow Control = RX PAUSE frames only.\n"); |
| 2225 | } |
| 2226 | } |
| 2227 | /* For receiving PAUSE frames ONLY. |
| 2228 | * |
| 2229 | * LOCAL DEVICE | LINK PARTNER |
| 2230 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2231 | *-------|---------|-------|---------|------------------ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2232 | * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE |
| 2233 | * |
| 2234 | */ |
| 2235 | else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2236 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 2237 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 2238 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) |
| 2239 | { |
| 2240 | hw->fc = E1000_FC_TX_PAUSE; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2241 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2242 | ("Flow Control = TX PAUSE frames only.\n"); |
| 2243 | } |
| 2244 | /* For transmitting PAUSE frames ONLY. |
| 2245 | * |
| 2246 | * LOCAL DEVICE | LINK PARTNER |
| 2247 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2248 | *-------|---------|-------|---------|------------------ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2249 | * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE |
| 2250 | * |
| 2251 | */ |
| 2252 | else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2253 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 2254 | !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 2255 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) |
| 2256 | { |
| 2257 | hw->fc = E1000_FC_RX_PAUSE; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2258 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2259 | ("Flow Control = RX PAUSE frames only.\n"); |
| 2260 | } |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2261 | /* Per the IEEE spec, at this point flow control should |
| 2262 | * be disabled. However, we want to consider that we |
| 2263 | * could be connected to a legacy switch that doesn't |
| 2264 | * advertise desired flow control, but can be forced on |
| 2265 | * the link partner. So if we advertised no flow |
| 2266 | * control, that is what we will resolve to. If we |
| 2267 | * advertised some kind of receive capability (Rx Pause |
| 2268 | * Only or Full Flow Control) and the link partner |
| 2269 | * advertised none, we will configure ourselves to |
| 2270 | * enable Rx Flow Control only. We can do this safely |
| 2271 | * for two reasons: If the link partner really |
| 2272 | * didn't want flow control enabled, and we enable Rx, |
| 2273 | * no harm done since we won't be receiving any PAUSE |
| 2274 | * frames anyway. If the intent on the link partner was |
| 2275 | * to have flow control enabled, then by us enabling Rx |
| 2276 | * only, we can at least receive pause frames and |
| 2277 | * process them. This is a good idea because in most |
| 2278 | * cases, since we are predominantly a server NIC, more |
| 2279 | * times than not we will be asked to delay transmission |
| 2280 | * of packets than asking our link partner to pause |
| 2281 | * transmission of frames. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2282 | */ |
| 2283 | else if ((hw->original_fc == E1000_FC_NONE || |
| 2284 | hw->original_fc == E1000_FC_TX_PAUSE) || |
| 2285 | hw->fc_strict_ieee) { |
| 2286 | hw->fc = E1000_FC_NONE; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2287 | e_dbg("Flow Control = NONE.\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2288 | } else { |
| 2289 | hw->fc = E1000_FC_RX_PAUSE; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2290 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2291 | ("Flow Control = RX PAUSE frames only.\n"); |
| 2292 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2294 | /* Now we need to do one last check... If we auto- |
| 2295 | * negotiated to HALF DUPLEX, flow control should not be |
| 2296 | * enabled per IEEE 802.3 spec. |
| 2297 | */ |
| 2298 | ret_val = |
| 2299 | e1000_get_speed_and_duplex(hw, &speed, &duplex); |
| 2300 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2301 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2302 | ("Error getting link speed and duplex\n"); |
| 2303 | return ret_val; |
| 2304 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2306 | if (duplex == HALF_DUPLEX) |
| 2307 | hw->fc = E1000_FC_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2309 | /* Now we call a subroutine to actually force the MAC |
| 2310 | * controller to use the correct flow control settings. |
| 2311 | */ |
| 2312 | ret_val = e1000_force_mac_fc(hw); |
| 2313 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2314 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2315 | ("Error forcing flow control settings\n"); |
| 2316 | return ret_val; |
| 2317 | } |
| 2318 | } else { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2319 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2320 | ("Copper PHY and Auto Neg has not completed.\n"); |
| 2321 | } |
| 2322 | } |
| 2323 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | } |
| 2325 | |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2326 | /** |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2327 | * e1000_check_for_serdes_link_generic - Check for link (Serdes) |
| 2328 | * @hw: pointer to the HW structure |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2329 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2330 | * Checks for link up on the hardware. If link is not up and we have |
| 2331 | * a signal, then we need to force link up. |
| 2332 | */ |
Jesse Brandeburg | 11b7f7b | 2009-09-25 12:20:33 +0000 | [diff] [blame] | 2333 | static s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw) |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2334 | { |
| 2335 | u32 rxcw; |
| 2336 | u32 ctrl; |
| 2337 | u32 status; |
| 2338 | s32 ret_val = E1000_SUCCESS; |
| 2339 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2340 | e_dbg("e1000_check_for_serdes_link_generic"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2341 | |
| 2342 | ctrl = er32(CTRL); |
| 2343 | status = er32(STATUS); |
| 2344 | rxcw = er32(RXCW); |
| 2345 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2346 | /* If we don't have link (auto-negotiation failed or link partner |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2347 | * cannot auto-negotiate), and our link partner is not trying to |
| 2348 | * auto-negotiate with us (we are receiving idles or data), |
| 2349 | * we need to force link up. We also need to give auto-negotiation |
| 2350 | * time to complete. |
| 2351 | */ |
| 2352 | /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */ |
| 2353 | if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) { |
| 2354 | if (hw->autoneg_failed == 0) { |
| 2355 | hw->autoneg_failed = 1; |
| 2356 | goto out; |
| 2357 | } |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2358 | e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2359 | |
| 2360 | /* Disable auto-negotiation in the TXCW register */ |
| 2361 | ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE)); |
| 2362 | |
| 2363 | /* Force link-up and also force full-duplex. */ |
| 2364 | ctrl = er32(CTRL); |
| 2365 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); |
| 2366 | ew32(CTRL, ctrl); |
| 2367 | |
| 2368 | /* Configure Flow Control after forcing link up. */ |
| 2369 | ret_val = e1000_config_fc_after_link_up(hw); |
| 2370 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2371 | e_dbg("Error configuring flow control\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2372 | goto out; |
| 2373 | } |
| 2374 | } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2375 | /* If we are forcing link and we are receiving /C/ ordered |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2376 | * sets, re-enable auto-negotiation in the TXCW register |
| 2377 | * and disable forced link in the Device Control register |
| 2378 | * in an attempt to auto-negotiate with our link partner. |
| 2379 | */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2380 | e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2381 | ew32(TXCW, hw->txcw); |
| 2382 | ew32(CTRL, (ctrl & ~E1000_CTRL_SLU)); |
| 2383 | |
| 2384 | hw->serdes_has_link = true; |
| 2385 | } else if (!(E1000_TXCW_ANE & er32(TXCW))) { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2386 | /* If we force link for non-auto-negotiation switch, check |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2387 | * link status based on MAC synchronization for internal |
| 2388 | * serdes media type. |
| 2389 | */ |
| 2390 | /* SYNCH bit and IV bit are sticky. */ |
| 2391 | udelay(10); |
| 2392 | rxcw = er32(RXCW); |
| 2393 | if (rxcw & E1000_RXCW_SYNCH) { |
| 2394 | if (!(rxcw & E1000_RXCW_IV)) { |
| 2395 | hw->serdes_has_link = true; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2396 | e_dbg("SERDES: Link up - forced.\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2397 | } |
| 2398 | } else { |
| 2399 | hw->serdes_has_link = false; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2400 | e_dbg("SERDES: Link down - force failed.\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2401 | } |
| 2402 | } |
| 2403 | |
| 2404 | if (E1000_TXCW_ANE & er32(TXCW)) { |
| 2405 | status = er32(STATUS); |
| 2406 | if (status & E1000_STATUS_LU) { |
| 2407 | /* SYNCH bit and IV bit are sticky, so reread rxcw. */ |
| 2408 | udelay(10); |
| 2409 | rxcw = er32(RXCW); |
| 2410 | if (rxcw & E1000_RXCW_SYNCH) { |
| 2411 | if (!(rxcw & E1000_RXCW_IV)) { |
| 2412 | hw->serdes_has_link = true; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2413 | e_dbg("SERDES: Link up - autoneg " |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2414 | "completed successfully.\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2415 | } else { |
| 2416 | hw->serdes_has_link = false; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2417 | e_dbg("SERDES: Link down - invalid" |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2418 | "codewords detected in autoneg.\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2419 | } |
| 2420 | } else { |
| 2421 | hw->serdes_has_link = false; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2422 | e_dbg("SERDES: Link down - no sync.\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2423 | } |
| 2424 | } else { |
| 2425 | hw->serdes_has_link = false; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2426 | e_dbg("SERDES: Link down - autoneg failed\n"); |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2427 | } |
| 2428 | } |
| 2429 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2430 | out: |
Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2431 | return ret_val; |
| 2432 | } |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2433 | |
| 2434 | /** |
| 2435 | * e1000_check_for_link |
| 2436 | * @hw: Struct containing variables accessed by shared code |
| 2437 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | * Checks to see if the link status of the hardware has changed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | * 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] | 2440 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2441 | s32 e1000_check_for_link(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2443 | u32 rxcw = 0; |
| 2444 | u32 ctrl; |
| 2445 | u32 status; |
| 2446 | u32 rctl; |
| 2447 | u32 icr; |
| 2448 | u32 signal = 0; |
| 2449 | s32 ret_val; |
| 2450 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2452 | e_dbg("e1000_check_for_link"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2453 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2454 | ctrl = er32(CTRL); |
| 2455 | status = er32(STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2457 | /* On adapters with a MAC newer than 82544, SW Definable pin 1 will be |
| 2458 | * set when the optics detect a signal. On older adapters, it will be |
| 2459 | * cleared when there is a signal. This applies to fiber media only. |
| 2460 | */ |
| 2461 | if ((hw->media_type == e1000_media_type_fiber) || |
| 2462 | (hw->media_type == e1000_media_type_internal_serdes)) { |
| 2463 | rxcw = er32(RXCW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2465 | if (hw->media_type == e1000_media_type_fiber) { |
| 2466 | signal = |
| 2467 | (hw->mac_type > |
| 2468 | e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; |
| 2469 | if (status & E1000_STATUS_LU) |
| 2470 | hw->get_link_status = false; |
| 2471 | } |
| 2472 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2474 | /* If we have a copper PHY then we only want to go out to the PHY |
| 2475 | * registers to see if Auto-Neg has completed and/or if our link |
| 2476 | * status has changed. The get_link_status flag will be set if we |
| 2477 | * receive a Link Status Change interrupt or we have Rx Sequence |
| 2478 | * Errors. |
| 2479 | */ |
| 2480 | if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) { |
| 2481 | /* First we want to see if the MII Status Register reports |
| 2482 | * link. If so, then we want to get the current speed/duplex |
| 2483 | * of the PHY. |
| 2484 | * Read the register twice since the link bit is sticky. |
| 2485 | */ |
| 2486 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 2487 | if (ret_val) |
| 2488 | return ret_val; |
| 2489 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 2490 | if (ret_val) |
| 2491 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2493 | if (phy_data & MII_SR_LINK_STATUS) { |
| 2494 | hw->get_link_status = false; |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2495 | /* Check if there was DownShift, must be checked |
| 2496 | * immediately after link-up |
| 2497 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2498 | e1000_check_downshift(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2500 | /* If we are on 82544 or 82543 silicon and speed/duplex |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2501 | * are forced to 10H or 10F, then we will implement the |
| 2502 | * polarity reversal workaround. We disable interrupts |
| 2503 | * first, and upon returning, place the devices |
| 2504 | * interrupt state to its previous value except for the |
| 2505 | * link status change interrupt which will |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2506 | * happen due to the execution of this workaround. |
| 2507 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2509 | if ((hw->mac_type == e1000_82544 |
| 2510 | || hw->mac_type == e1000_82543) && (!hw->autoneg) |
| 2511 | && (hw->forced_speed_duplex == e1000_10_full |
| 2512 | || hw->forced_speed_duplex == e1000_10_half)) { |
| 2513 | ew32(IMC, 0xffffffff); |
| 2514 | ret_val = |
| 2515 | e1000_polarity_reversal_workaround(hw); |
| 2516 | icr = er32(ICR); |
| 2517 | ew32(ICS, (icr & ~E1000_ICS_LSC)); |
| 2518 | ew32(IMS, IMS_ENABLE_MASK); |
| 2519 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2521 | } else { |
| 2522 | /* No link detected */ |
| 2523 | e1000_config_dsp_after_link_change(hw, false); |
| 2524 | return 0; |
| 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 | /* If we are forcing speed/duplex, then we simply return since |
| 2528 | * we have already determined whether we have link or not. |
| 2529 | */ |
| 2530 | if (!hw->autoneg) |
| 2531 | return -E1000_ERR_CONFIG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2533 | /* optimize the dsp settings for the igp phy */ |
| 2534 | e1000_config_dsp_after_link_change(hw, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2536 | /* We have a M88E1000 PHY and Auto-Neg is enabled. If we |
| 2537 | * have Si on board that is 82544 or newer, Auto |
| 2538 | * Speed Detection takes care of MAC speed/duplex |
| 2539 | * configuration. So we only need to configure Collision |
| 2540 | * Distance in the MAC. Otherwise, we need to force |
| 2541 | * speed/duplex on the MAC to the current PHY speed/duplex |
| 2542 | * settings. |
| 2543 | */ |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2544 | if ((hw->mac_type >= e1000_82544) && |
| 2545 | (hw->mac_type != e1000_ce4100)) |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2546 | e1000_config_collision_dist(hw); |
| 2547 | else { |
| 2548 | ret_val = e1000_config_mac_to_phy(hw); |
| 2549 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2550 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2551 | ("Error configuring MAC to PHY settings\n"); |
| 2552 | return ret_val; |
| 2553 | } |
| 2554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2555 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2556 | /* Configure Flow Control now that Auto-Neg has completed. |
| 2557 | * First, we need to restore the desired flow control settings |
| 2558 | * because we may have had to re-autoneg with a different link |
| 2559 | * partner. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2560 | */ |
| 2561 | ret_val = e1000_config_fc_after_link_up(hw); |
| 2562 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2563 | e_dbg("Error configuring flow control\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2564 | return ret_val; |
| 2565 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2566 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2567 | /* At this point we know that we are on copper and we have |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2568 | * auto-negotiated link. These are conditions for checking the |
| 2569 | * link partner capability register. We use the link speed to |
| 2570 | * determine if TBI compatibility needs to be turned on or off. |
| 2571 | * If the link is not at gigabit speed, then TBI compatibility |
| 2572 | * is not needed. If we are at gigabit speed, we turn on TBI |
| 2573 | * compatibility. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2574 | */ |
| 2575 | if (hw->tbi_compatibility_en) { |
| 2576 | u16 speed, duplex; |
| 2577 | ret_val = |
| 2578 | e1000_get_speed_and_duplex(hw, &speed, &duplex); |
| 2579 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2580 | e_dbg |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2581 | ("Error getting link speed and duplex\n"); |
| 2582 | return ret_val; |
| 2583 | } |
| 2584 | if (speed != SPEED_1000) { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2585 | /* If link speed is not set to gigabit speed, we |
| 2586 | * do not need to enable TBI compatibility. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2587 | */ |
| 2588 | if (hw->tbi_compatibility_on) { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2589 | /* If we previously were in the mode, |
| 2590 | * turn it off. |
| 2591 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2592 | rctl = er32(RCTL); |
| 2593 | rctl &= ~E1000_RCTL_SBP; |
| 2594 | ew32(RCTL, rctl); |
| 2595 | hw->tbi_compatibility_on = false; |
| 2596 | } |
| 2597 | } else { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2598 | /* If TBI compatibility is was previously off, |
| 2599 | * turn it on. For compatibility with a TBI link |
| 2600 | * partner, we will store bad packets. Some |
| 2601 | * frames have an additional byte on the end and |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2602 | * will look like CRC errors to to the hardware. |
| 2603 | */ |
| 2604 | if (!hw->tbi_compatibility_on) { |
| 2605 | hw->tbi_compatibility_on = true; |
| 2606 | rctl = er32(RCTL); |
| 2607 | rctl |= E1000_RCTL_SBP; |
| 2608 | ew32(RCTL, rctl); |
| 2609 | } |
| 2610 | } |
| 2611 | } |
| 2612 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2614 | if ((hw->media_type == e1000_media_type_fiber) || |
| 2615 | (hw->media_type == e1000_media_type_internal_serdes)) |
| 2616 | e1000_check_for_serdes_link_generic(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2618 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | } |
| 2620 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2621 | /** |
| 2622 | * e1000_get_speed_and_duplex |
| 2623 | * @hw: Struct containing variables accessed by shared code |
| 2624 | * @speed: Speed of the connection |
| 2625 | * @duplex: Duplex setting of the connection |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 2626 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | * Detects the current speed and duplex settings of the hardware. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2628 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2629 | 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] | 2630 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2631 | u32 status; |
| 2632 | s32 ret_val; |
| 2633 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2635 | e_dbg("e1000_get_speed_and_duplex"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2637 | if (hw->mac_type >= e1000_82543) { |
| 2638 | status = er32(STATUS); |
| 2639 | if (status & E1000_STATUS_SPEED_1000) { |
| 2640 | *speed = SPEED_1000; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2641 | e_dbg("1000 Mbs, "); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2642 | } else if (status & E1000_STATUS_SPEED_100) { |
| 2643 | *speed = SPEED_100; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2644 | e_dbg("100 Mbs, "); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2645 | } else { |
| 2646 | *speed = SPEED_10; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2647 | e_dbg("10 Mbs, "); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2648 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2650 | if (status & E1000_STATUS_FD) { |
| 2651 | *duplex = FULL_DUPLEX; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2652 | e_dbg("Full Duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2653 | } else { |
| 2654 | *duplex = HALF_DUPLEX; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2655 | e_dbg(" Half Duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2656 | } |
| 2657 | } else { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2658 | e_dbg("1000 Mbs, Full Duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2659 | *speed = SPEED_1000; |
| 2660 | *duplex = FULL_DUPLEX; |
| 2661 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2663 | /* IGP01 PHY may advertise full duplex operation after speed downgrade |
| 2664 | * even if it is operating at half duplex. Here we set the duplex |
| 2665 | * settings to match the duplex in the link partner's capabilities. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2666 | */ |
| 2667 | if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) { |
| 2668 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data); |
| 2669 | if (ret_val) |
| 2670 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2672 | if (!(phy_data & NWAY_ER_LP_NWAY_CAPS)) |
| 2673 | *duplex = HALF_DUPLEX; |
| 2674 | else { |
| 2675 | ret_val = |
| 2676 | e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data); |
| 2677 | if (ret_val) |
| 2678 | return ret_val; |
| 2679 | if ((*speed == SPEED_100 |
| 2680 | && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) |
| 2681 | || (*speed == SPEED_10 |
| 2682 | && !(phy_data & NWAY_LPAR_10T_FD_CAPS))) |
| 2683 | *duplex = HALF_DUPLEX; |
| 2684 | } |
| 2685 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 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_wait_autoneg |
| 2692 | * @hw: Struct containing variables accessed by shared code |
| 2693 | * |
| 2694 | * Blocks until autoneg completes or times out (~4.5 seconds) |
| 2695 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2696 | static s32 e1000_wait_autoneg(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2698 | s32 ret_val; |
| 2699 | u16 i; |
| 2700 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2702 | e_dbg("e1000_wait_autoneg"); |
| 2703 | e_dbg("Waiting for Auto-Neg to complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2705 | /* We will wait for autoneg to complete or 4.5 seconds to expire. */ |
| 2706 | for (i = PHY_AUTO_NEG_TIME; i > 0; i--) { |
| 2707 | /* Read the MII Status Register and wait for Auto-Neg |
| 2708 | * Complete bit to be set. |
| 2709 | */ |
| 2710 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 2711 | if (ret_val) |
| 2712 | return ret_val; |
| 2713 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 2714 | if (ret_val) |
| 2715 | return ret_val; |
| 2716 | if (phy_data & MII_SR_AUTONEG_COMPLETE) { |
| 2717 | return E1000_SUCCESS; |
| 2718 | } |
| 2719 | msleep(100); |
| 2720 | } |
| 2721 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2724 | /** |
| 2725 | * e1000_raise_mdi_clk - Raises the Management Data Clock |
| 2726 | * @hw: Struct containing variables accessed by shared code |
| 2727 | * @ctrl: Device control register's current value |
| 2728 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2729 | static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2731 | /* Raise the clock input to the Management Data Clock (by setting the |
| 2732 | * MDC bit), and then delay 10 microseconds. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2733 | */ |
| 2734 | ew32(CTRL, (*ctrl | E1000_CTRL_MDC)); |
| 2735 | E1000_WRITE_FLUSH(); |
| 2736 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2739 | /** |
| 2740 | * e1000_lower_mdi_clk - Lowers the Management Data Clock |
| 2741 | * @hw: Struct containing variables accessed by shared code |
| 2742 | * @ctrl: Device control register's current value |
| 2743 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2744 | static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2746 | /* Lower the clock input to the Management Data Clock (by clearing the |
| 2747 | * MDC bit), and then delay 10 microseconds. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2748 | */ |
| 2749 | ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC)); |
| 2750 | E1000_WRITE_FLUSH(); |
| 2751 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | } |
| 2753 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2754 | /** |
| 2755 | * e1000_shift_out_mdi_bits - Shifts data bits out to the PHY |
| 2756 | * @hw: Struct containing variables accessed by shared code |
| 2757 | * @data: Data to send out to the PHY |
| 2758 | * @count: Number of bits to shift out |
| 2759 | * |
| 2760 | * Bits are shifted out in MSB to LSB order. |
| 2761 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2762 | 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] | 2763 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2764 | u32 ctrl; |
| 2765 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2767 | /* We need to shift "count" number of bits out to the PHY. So, the value |
| 2768 | * in the "data" parameter will be shifted out to the PHY one bit at a |
| 2769 | * time. In order to do this, "data" must be broken down into bits. |
| 2770 | */ |
| 2771 | mask = 0x01; |
| 2772 | mask <<= (count - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2774 | ctrl = er32(CTRL); |
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 | /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */ |
| 2777 | ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2779 | while (mask) { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2780 | /* A "1" is shifted out to the PHY by setting the MDIO bit to |
| 2781 | * "1" and then raising and lowering the Management Data Clock. |
| 2782 | * A "0" is shifted out to the PHY by setting the MDIO bit to |
| 2783 | * "0" and then raising and lowering the clock. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2784 | */ |
| 2785 | if (data & mask) |
| 2786 | ctrl |= E1000_CTRL_MDIO; |
| 2787 | else |
| 2788 | ctrl &= ~E1000_CTRL_MDIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2790 | ew32(CTRL, ctrl); |
| 2791 | E1000_WRITE_FLUSH(); |
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 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2795 | e1000_raise_mdi_clk(hw, &ctrl); |
| 2796 | e1000_lower_mdi_clk(hw, &ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2798 | mask = mask >> 1; |
| 2799 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | } |
| 2801 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2802 | /** |
| 2803 | * e1000_shift_in_mdi_bits - Shifts data bits in from the PHY |
| 2804 | * @hw: Struct containing variables accessed by shared code |
| 2805 | * |
| 2806 | * Bits are shifted in in MSB to LSB order. |
| 2807 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2808 | static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2810 | u32 ctrl; |
| 2811 | u16 data = 0; |
| 2812 | u8 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2814 | /* In order to read a register from the PHY, we need to shift in a total |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2815 | * of 18 bits from the PHY. The first two bit (turnaround) times are |
| 2816 | * used to avoid contention on the MDIO pin when a read operation is |
| 2817 | * performed. These two bits are ignored by us and thrown away. Bits are |
| 2818 | * "shifted in" by raising the input to the Management Data Clock |
| 2819 | * (setting the MDC bit), and then reading the value of the MDIO bit. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2820 | */ |
| 2821 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2823 | /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as |
| 2824 | * input. |
| 2825 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2826 | ctrl &= ~E1000_CTRL_MDIO_DIR; |
| 2827 | ctrl &= ~E1000_CTRL_MDIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2829 | ew32(CTRL, ctrl); |
| 2830 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2832 | /* Raise and Lower the clock before reading in the data. This accounts |
| 2833 | * for the turnaround bits. The first clock occurred when we clocked out |
| 2834 | * the last bit of the Register Address. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2835 | */ |
| 2836 | e1000_raise_mdi_clk(hw, &ctrl); |
| 2837 | e1000_lower_mdi_clk(hw, &ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2839 | for (data = 0, i = 0; i < 16; i++) { |
| 2840 | data = data << 1; |
| 2841 | e1000_raise_mdi_clk(hw, &ctrl); |
| 2842 | ctrl = er32(CTRL); |
| 2843 | /* Check to see if we shifted in a "1". */ |
| 2844 | if (ctrl & E1000_CTRL_MDIO) |
| 2845 | data |= 1; |
| 2846 | e1000_lower_mdi_clk(hw, &ctrl); |
| 2847 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2849 | e1000_raise_mdi_clk(hw, &ctrl); |
| 2850 | e1000_lower_mdi_clk(hw, &ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2852 | return data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | } |
| 2854 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2855 | |
| 2856 | /** |
| 2857 | * e1000_read_phy_reg - read a phy register |
| 2858 | * @hw: Struct containing variables accessed by shared code |
| 2859 | * @reg_addr: address of the PHY register to read |
| 2860 | * |
| 2861 | * Reads the value from a PHY register, if the value is on a specific non zero |
| 2862 | * page, sets the page first. |
| 2863 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2864 | 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] | 2865 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2866 | u32 ret_val; |
Maxime Bizon | ac56558 | 2012-10-20 14:53:40 +0000 | [diff] [blame] | 2867 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2869 | e_dbg("e1000_read_phy_reg"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2870 | |
Maxime Bizon | ac56558 | 2012-10-20 14:53:40 +0000 | [diff] [blame] | 2871 | spin_lock_irqsave(&e1000_phy_lock, flags); |
| 2872 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2873 | if ((hw->phy_type == e1000_phy_igp) && |
| 2874 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { |
| 2875 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 2876 | (u16) reg_addr); |
Maxime Bizon | ac56558 | 2012-10-20 14:53:40 +0000 | [diff] [blame] | 2877 | if (ret_val) { |
| 2878 | spin_unlock_irqrestore(&e1000_phy_lock, flags); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2879 | return ret_val; |
Maxime Bizon | ac56558 | 2012-10-20 14:53:40 +0000 | [diff] [blame] | 2880 | } |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2881 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2883 | ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, |
| 2884 | phy_data); |
Maxime Bizon | ac56558 | 2012-10-20 14:53:40 +0000 | [diff] [blame] | 2885 | spin_unlock_irqrestore(&e1000_phy_lock, flags); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2886 | |
| 2887 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2888 | } |
| 2889 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2890 | static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, |
| 2891 | u16 *phy_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2893 | u32 i; |
| 2894 | u32 mdic = 0; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2895 | 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] | 2896 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2897 | e_dbg("e1000_read_phy_reg_ex"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2899 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 2900 | e_dbg("PHY Address %d is out of range\n", reg_addr); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2901 | return -E1000_ERR_PARAM; |
| 2902 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2904 | if (hw->mac_type > e1000_82543) { |
| 2905 | /* Set up Op-code, Phy Address, and register address in the MDI |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2906 | * Control register. The MAC will take care of interfacing with |
| 2907 | * the PHY to retrieve the desired data. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2908 | */ |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2909 | if (hw->mac_type == e1000_ce4100) { |
| 2910 | mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) | |
| 2911 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 2912 | (INTEL_CE_GBE_MDIC_OP_READ) | |
| 2913 | (INTEL_CE_GBE_MDIC_GO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2915 | writel(mdic, E1000_MDIO_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 2917 | /* Poll the ready bit to see if the MDI read |
| 2918 | * completed |
| 2919 | */ |
| 2920 | for (i = 0; i < 64; i++) { |
| 2921 | udelay(50); |
| 2922 | mdic = readl(E1000_MDIO_CMD); |
| 2923 | if (!(mdic & INTEL_CE_GBE_MDIC_GO)) |
| 2924 | break; |
| 2925 | } |
| 2926 | |
| 2927 | if (mdic & INTEL_CE_GBE_MDIC_GO) { |
| 2928 | e_dbg("MDI Read did not complete\n"); |
| 2929 | return -E1000_ERR_PHY; |
| 2930 | } |
| 2931 | |
| 2932 | mdic = readl(E1000_MDIO_STS); |
| 2933 | if (mdic & INTEL_CE_GBE_MDIC_READ_ERROR) { |
| 2934 | e_dbg("MDI Read Error\n"); |
| 2935 | return -E1000_ERR_PHY; |
| 2936 | } |
| 2937 | *phy_data = (u16) mdic; |
| 2938 | } else { |
| 2939 | mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) | |
| 2940 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 2941 | (E1000_MDIC_OP_READ)); |
| 2942 | |
| 2943 | ew32(MDIC, mdic); |
| 2944 | |
| 2945 | /* Poll the ready bit to see if the MDI read |
| 2946 | * completed |
| 2947 | */ |
| 2948 | for (i = 0; i < 64; i++) { |
| 2949 | udelay(50); |
| 2950 | mdic = er32(MDIC); |
| 2951 | if (mdic & E1000_MDIC_READY) |
| 2952 | break; |
| 2953 | } |
| 2954 | if (!(mdic & E1000_MDIC_READY)) { |
| 2955 | e_dbg("MDI Read did not complete\n"); |
| 2956 | return -E1000_ERR_PHY; |
| 2957 | } |
| 2958 | if (mdic & E1000_MDIC_ERROR) { |
| 2959 | e_dbg("MDI Error\n"); |
| 2960 | return -E1000_ERR_PHY; |
| 2961 | } |
| 2962 | *phy_data = (u16) mdic; |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2963 | } |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2964 | } else { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2965 | /* We must first send a preamble through the MDIO pin to signal |
| 2966 | * the beginning of an MII instruction. This is done by sending |
| 2967 | * 32 consecutive "1" bits. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2968 | */ |
| 2969 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2971 | /* Now combine the next few fields that are required for a read |
| 2972 | * operation. We use this method instead of calling the |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2973 | * e1000_shift_out_mdi_bits routine five different times. The |
| 2974 | * format of a MII read instruction consists of a shift out of |
| 2975 | * 14 bits and is defined as follows: |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2976 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr> |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2977 | * followed by a shift in of 18 bits. This first two bits |
| 2978 | * shifted in are TurnAround bits used to avoid contention on |
| 2979 | * the MDIO pin when a READ operation is performed. These two |
| 2980 | * bits are thrown away followed by a shift in of 16 bits which |
| 2981 | * contains the desired data. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2982 | */ |
| 2983 | mdic = ((reg_addr) | (phy_addr << 5) | |
| 2984 | (PHY_OP_READ << 10) | (PHY_SOF << 12)); |
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 | e1000_shift_out_mdi_bits(hw, mdic, 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 2988 | /* Now that we've shifted out the read command to the MII, we |
| 2989 | * need to "shift in" the 16-bit value (18 total bits) of the |
| 2990 | * requested PHY register address. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2991 | */ |
| 2992 | *phy_data = e1000_shift_in_mdi_bits(hw); |
| 2993 | } |
| 2994 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | } |
| 2996 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2997 | /** |
| 2998 | * e1000_write_phy_reg - write a phy register |
| 2999 | * |
| 3000 | * @hw: Struct containing variables accessed by shared code |
| 3001 | * @reg_addr: address of the PHY register to write |
| 3002 | * @data: data to write to the PHY |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 3003 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3004 | * Writes a value to a PHY register |
| 3005 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3006 | 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] | 3007 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3008 | u32 ret_val; |
Maxime Bizon | ac56558 | 2012-10-20 14:53:40 +0000 | [diff] [blame] | 3009 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3011 | e_dbg("e1000_write_phy_reg"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | |
Maxime Bizon | ac56558 | 2012-10-20 14:53:40 +0000 | [diff] [blame] | 3013 | spin_lock_irqsave(&e1000_phy_lock, flags); |
| 3014 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3015 | if ((hw->phy_type == e1000_phy_igp) && |
| 3016 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { |
| 3017 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 3018 | (u16) reg_addr); |
Maxime Bizon | ac56558 | 2012-10-20 14:53:40 +0000 | [diff] [blame] | 3019 | if (ret_val) { |
| 3020 | spin_unlock_irqrestore(&e1000_phy_lock, flags); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3021 | return ret_val; |
Maxime Bizon | ac56558 | 2012-10-20 14:53:40 +0000 | [diff] [blame] | 3022 | } |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3023 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3025 | ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, |
| 3026 | phy_data); |
Maxime Bizon | ac56558 | 2012-10-20 14:53:40 +0000 | [diff] [blame] | 3027 | spin_unlock_irqrestore(&e1000_phy_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3029 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | } |
| 3031 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3032 | static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, |
| 3033 | u16 phy_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3035 | u32 i; |
| 3036 | u32 mdic = 0; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3037 | 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] | 3038 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3039 | e_dbg("e1000_write_phy_reg_ex"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3041 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3042 | e_dbg("PHY Address %d is out of range\n", reg_addr); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3043 | return -E1000_ERR_PARAM; |
| 3044 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3046 | if (hw->mac_type > e1000_82543) { |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3047 | /* Set up Op-code, Phy Address, register address, and data |
| 3048 | * intended for the PHY register in the MDI Control register. |
| 3049 | * The MAC will take care of interfacing with the PHY to send |
| 3050 | * the desired data. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3051 | */ |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3052 | if (hw->mac_type == e1000_ce4100) { |
| 3053 | mdic = (((u32) phy_data) | |
| 3054 | (reg_addr << E1000_MDIC_REG_SHIFT) | |
| 3055 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 3056 | (INTEL_CE_GBE_MDIC_OP_WRITE) | |
| 3057 | (INTEL_CE_GBE_MDIC_GO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3059 | writel(mdic, E1000_MDIO_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3061 | /* Poll the ready bit to see if the MDI read |
| 3062 | * completed |
| 3063 | */ |
| 3064 | for (i = 0; i < 640; i++) { |
| 3065 | udelay(5); |
| 3066 | mdic = readl(E1000_MDIO_CMD); |
| 3067 | if (!(mdic & INTEL_CE_GBE_MDIC_GO)) |
| 3068 | break; |
| 3069 | } |
| 3070 | if (mdic & INTEL_CE_GBE_MDIC_GO) { |
| 3071 | e_dbg("MDI Write did not complete\n"); |
| 3072 | return -E1000_ERR_PHY; |
| 3073 | } |
| 3074 | } else { |
| 3075 | mdic = (((u32) phy_data) | |
| 3076 | (reg_addr << E1000_MDIC_REG_SHIFT) | |
| 3077 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 3078 | (E1000_MDIC_OP_WRITE)); |
| 3079 | |
| 3080 | ew32(MDIC, mdic); |
| 3081 | |
| 3082 | /* Poll the ready bit to see if the MDI read |
| 3083 | * completed |
| 3084 | */ |
| 3085 | for (i = 0; i < 641; i++) { |
| 3086 | udelay(5); |
| 3087 | mdic = er32(MDIC); |
| 3088 | if (mdic & E1000_MDIC_READY) |
| 3089 | break; |
| 3090 | } |
| 3091 | if (!(mdic & E1000_MDIC_READY)) { |
| 3092 | e_dbg("MDI Write did not complete\n"); |
| 3093 | return -E1000_ERR_PHY; |
| 3094 | } |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3095 | } |
| 3096 | } else { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 3097 | /* We'll need to use the SW defined pins to shift the write |
| 3098 | * command out to the PHY. We first send a preamble to the PHY |
| 3099 | * to signal the beginning of the MII instruction. This is done |
| 3100 | * by sending 32 consecutive "1" bits. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3101 | */ |
| 3102 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 3104 | /* Now combine the remaining required fields that will indicate |
| 3105 | * a write operation. We use this method instead of calling the |
| 3106 | * e1000_shift_out_mdi_bits routine for each field in the |
| 3107 | * command. The format of a MII write instruction is as follows: |
| 3108 | * <Preamble><SOF><OpCode><PhyAddr><RegAddr><Turnaround><Data>. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3109 | */ |
| 3110 | mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) | |
| 3111 | (PHY_OP_WRITE << 12) | (PHY_SOF << 14)); |
| 3112 | mdic <<= 16; |
| 3113 | mdic |= (u32) phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3115 | e1000_shift_out_mdi_bits(hw, mdic, 32); |
| 3116 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3118 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | } |
| 3120 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3121 | /** |
| 3122 | * e1000_phy_hw_reset - reset the phy, hardware style |
| 3123 | * @hw: Struct containing variables accessed by shared code |
| 3124 | * |
| 3125 | * Returns the PHY to the power-on reset state |
| 3126 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3127 | s32 e1000_phy_hw_reset(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3129 | u32 ctrl, ctrl_ext; |
| 3130 | u32 led_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3132 | e_dbg("e1000_phy_hw_reset"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3134 | e_dbg("Resetting Phy...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3135 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3136 | if (hw->mac_type > e1000_82543) { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 3137 | /* Read the device control register and assert the |
| 3138 | * E1000_CTRL_PHY_RST bit. Then, take it out of reset. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3139 | * For e1000 hardware, we delay for 10ms between the assert |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 3140 | * and de-assert. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3141 | */ |
| 3142 | ctrl = er32(CTRL); |
| 3143 | ew32(CTRL, ctrl | E1000_CTRL_PHY_RST); |
| 3144 | E1000_WRITE_FLUSH(); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3145 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3146 | msleep(10); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3147 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3148 | ew32(CTRL, ctrl); |
| 3149 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3151 | } else { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 3152 | /* Read the Extended Device Control Register, assert the |
| 3153 | * PHY_RESET_DIR bit to put the PHY into reset. Then, take it |
| 3154 | * out of reset. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3155 | */ |
| 3156 | ctrl_ext = er32(CTRL_EXT); |
| 3157 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR; |
| 3158 | ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA; |
| 3159 | ew32(CTRL_EXT, ctrl_ext); |
| 3160 | E1000_WRITE_FLUSH(); |
| 3161 | msleep(10); |
| 3162 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA; |
| 3163 | ew32(CTRL_EXT, ctrl_ext); |
| 3164 | E1000_WRITE_FLUSH(); |
| 3165 | } |
| 3166 | udelay(150); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3167 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3168 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 3169 | /* Configure activity LED after PHY reset */ |
| 3170 | led_ctrl = er32(LEDCTL); |
| 3171 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 3172 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 3173 | ew32(LEDCTL, led_ctrl); |
| 3174 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3175 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3176 | /* Wait for FW to finish PHY configuration. */ |
Greg Dietsche | c4dc4d1 | 2011-06-16 07:09:30 +0000 | [diff] [blame] | 3177 | return e1000_get_phy_cfg_done(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | } |
| 3179 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3180 | /** |
| 3181 | * e1000_phy_reset - reset the phy to commit settings |
| 3182 | * @hw: Struct containing variables accessed by shared code |
| 3183 | * |
| 3184 | * Resets the PHY |
| 3185 | * Sets bit 15 of the MII Control register |
| 3186 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3187 | s32 e1000_phy_reset(struct e1000_hw *hw) |
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 | s32 ret_val; |
| 3190 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3192 | e_dbg("e1000_phy_reset"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3194 | switch (hw->phy_type) { |
| 3195 | case e1000_phy_igp: |
| 3196 | ret_val = e1000_phy_hw_reset(hw); |
| 3197 | if (ret_val) |
| 3198 | return ret_val; |
| 3199 | break; |
| 3200 | default: |
| 3201 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
| 3202 | if (ret_val) |
| 3203 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3205 | phy_data |= MII_CR_RESET; |
| 3206 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); |
| 3207 | if (ret_val) |
| 3208 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3210 | udelay(1); |
| 3211 | break; |
| 3212 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3214 | if (hw->phy_type == e1000_phy_igp) |
| 3215 | e1000_phy_init_script(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3217 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | } |
| 3219 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3220 | /** |
| 3221 | * e1000_detect_gig_phy - check the phy type |
| 3222 | * @hw: Struct containing variables accessed by shared code |
| 3223 | * |
| 3224 | * Probes the expected PHY address for known PHY IDs |
| 3225 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3226 | static s32 e1000_detect_gig_phy(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3228 | s32 phy_init_status, ret_val; |
| 3229 | u16 phy_id_high, phy_id_low; |
| 3230 | bool match = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3232 | e_dbg("e1000_detect_gig_phy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3234 | if (hw->phy_id != 0) |
| 3235 | return E1000_SUCCESS; |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3236 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3237 | /* Read the PHY ID Registers to identify which PHY is onboard. */ |
| 3238 | ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high); |
| 3239 | if (ret_val) |
| 3240 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3242 | hw->phy_id = (u32) (phy_id_high << 16); |
| 3243 | udelay(20); |
| 3244 | ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low); |
| 3245 | if (ret_val) |
| 3246 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3248 | hw->phy_id |= (u32) (phy_id_low & PHY_REVISION_MASK); |
| 3249 | hw->phy_revision = (u32) phy_id_low & ~PHY_REVISION_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3251 | switch (hw->mac_type) { |
| 3252 | case e1000_82543: |
| 3253 | if (hw->phy_id == M88E1000_E_PHY_ID) |
| 3254 | match = true; |
| 3255 | break; |
| 3256 | case e1000_82544: |
| 3257 | if (hw->phy_id == M88E1000_I_PHY_ID) |
| 3258 | match = true; |
| 3259 | break; |
| 3260 | case e1000_82540: |
| 3261 | case e1000_82545: |
| 3262 | case e1000_82545_rev_3: |
| 3263 | case e1000_82546: |
| 3264 | case e1000_82546_rev_3: |
| 3265 | if (hw->phy_id == M88E1011_I_PHY_ID) |
| 3266 | match = true; |
| 3267 | break; |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3268 | case e1000_ce4100: |
| 3269 | if ((hw->phy_id == RTL8211B_PHY_ID) || |
Florian Fainelli | cf8e09b | 2011-01-24 14:48:03 +0000 | [diff] [blame] | 3270 | (hw->phy_id == RTL8201N_PHY_ID) || |
| 3271 | (hw->phy_id == M88E1118_E_PHY_ID)) |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3272 | match = true; |
| 3273 | break; |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3274 | case e1000_82541: |
| 3275 | case e1000_82541_rev_2: |
| 3276 | case e1000_82547: |
| 3277 | case e1000_82547_rev_2: |
| 3278 | if (hw->phy_id == IGP01E1000_I_PHY_ID) |
| 3279 | match = true; |
| 3280 | break; |
| 3281 | default: |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3282 | e_dbg("Invalid MAC type %d\n", hw->mac_type); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3283 | return -E1000_ERR_CONFIG; |
| 3284 | } |
| 3285 | phy_init_status = e1000_set_phy_type(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3286 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3287 | if ((match) && (phy_init_status == E1000_SUCCESS)) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3288 | e_dbg("PHY ID 0x%X detected\n", hw->phy_id); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3289 | return E1000_SUCCESS; |
| 3290 | } |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3291 | e_dbg("Invalid PHY ID 0x%X\n", hw->phy_id); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3292 | return -E1000_ERR_PHY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | } |
| 3294 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3295 | /** |
| 3296 | * e1000_phy_reset_dsp - reset DSP |
| 3297 | * @hw: Struct containing variables accessed by shared code |
| 3298 | * |
| 3299 | * Resets the PHY's DSP |
| 3300 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3301 | static s32 e1000_phy_reset_dsp(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3303 | s32 ret_val; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3304 | e_dbg("e1000_phy_reset_dsp"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3306 | do { |
| 3307 | ret_val = e1000_write_phy_reg(hw, 29, 0x001d); |
| 3308 | if (ret_val) |
| 3309 | break; |
| 3310 | ret_val = e1000_write_phy_reg(hw, 30, 0x00c1); |
| 3311 | if (ret_val) |
| 3312 | break; |
| 3313 | ret_val = e1000_write_phy_reg(hw, 30, 0x0000); |
| 3314 | if (ret_val) |
| 3315 | break; |
| 3316 | ret_val = E1000_SUCCESS; |
| 3317 | } while (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3319 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | } |
| 3321 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3322 | /** |
| 3323 | * e1000_phy_igp_get_info - get igp specific registers |
| 3324 | * @hw: Struct containing variables accessed by shared code |
| 3325 | * @phy_info: PHY information structure |
| 3326 | * |
| 3327 | * Get PHY information from various PHY registers for igp PHY only. |
| 3328 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3329 | static s32 e1000_phy_igp_get_info(struct e1000_hw *hw, |
| 3330 | struct e1000_phy_info *phy_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3332 | s32 ret_val; |
| 3333 | u16 phy_data, min_length, max_length, average; |
| 3334 | e1000_rev_polarity polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3336 | e_dbg("e1000_phy_igp_get_info"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3338 | /* The downshift status is checked only once, after link is established, |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 3339 | * and it stored in the hw->speed_downgraded parameter. |
| 3340 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3341 | phy_info->downshift = (e1000_downshift) hw->speed_downgraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3343 | /* IGP01E1000 does not need to support it. */ |
| 3344 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3346 | /* IGP01E1000 always correct polarity reversal */ |
| 3347 | phy_info->polarity_correction = e1000_polarity_reversal_enabled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3349 | /* Check polarity status */ |
| 3350 | ret_val = e1000_check_polarity(hw, &polarity); |
| 3351 | if (ret_val) |
| 3352 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3354 | phy_info->cable_polarity = polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3356 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data); |
| 3357 | if (ret_val) |
| 3358 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3360 | phy_info->mdix_mode = |
| 3361 | (e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >> |
| 3362 | IGP01E1000_PSSR_MDIX_SHIFT); |
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 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == |
| 3365 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 3366 | /* Local/Remote Receiver Information are only valid @ 1000 |
| 3367 | * Mbps |
| 3368 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3369 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); |
| 3370 | if (ret_val) |
| 3371 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3373 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> |
| 3374 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? |
| 3375 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
| 3376 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> |
| 3377 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? |
| 3378 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3380 | /* Get cable length */ |
| 3381 | ret_val = e1000_get_cable_length(hw, &min_length, &max_length); |
| 3382 | if (ret_val) |
| 3383 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3384 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3385 | /* Translate to old method */ |
| 3386 | average = (max_length + min_length) / 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3388 | if (average <= e1000_igp_cable_length_50) |
| 3389 | phy_info->cable_length = e1000_cable_length_50; |
| 3390 | else if (average <= e1000_igp_cable_length_80) |
| 3391 | phy_info->cable_length = e1000_cable_length_50_80; |
| 3392 | else if (average <= e1000_igp_cable_length_110) |
| 3393 | phy_info->cable_length = e1000_cable_length_80_110; |
| 3394 | else if (average <= e1000_igp_cable_length_140) |
| 3395 | phy_info->cable_length = e1000_cable_length_110_140; |
| 3396 | else |
| 3397 | phy_info->cable_length = e1000_cable_length_140; |
| 3398 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3400 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | } |
| 3402 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3403 | /** |
| 3404 | * e1000_phy_m88_get_info - get m88 specific registers |
| 3405 | * @hw: Struct containing variables accessed by shared code |
| 3406 | * @phy_info: PHY information structure |
| 3407 | * |
| 3408 | * Get PHY information from various PHY registers for m88 PHY only. |
| 3409 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3410 | static s32 e1000_phy_m88_get_info(struct e1000_hw *hw, |
| 3411 | struct e1000_phy_info *phy_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3413 | s32 ret_val; |
| 3414 | u16 phy_data; |
| 3415 | e1000_rev_polarity polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3417 | e_dbg("e1000_phy_m88_get_info"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3419 | /* The downshift status is checked only once, after link is established, |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 3420 | * and it stored in the hw->speed_downgraded parameter. |
| 3421 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3422 | phy_info->downshift = (e1000_downshift) hw->speed_downgraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3424 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 3425 | if (ret_val) |
| 3426 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3428 | phy_info->extended_10bt_distance = |
| 3429 | ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >> |
| 3430 | M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ? |
| 3431 | e1000_10bt_ext_dist_enable_lower : |
| 3432 | e1000_10bt_ext_dist_enable_normal; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3433 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3434 | phy_info->polarity_correction = |
| 3435 | ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >> |
| 3436 | M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ? |
| 3437 | e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3439 | /* Check polarity status */ |
| 3440 | ret_val = e1000_check_polarity(hw, &polarity); |
| 3441 | if (ret_val) |
| 3442 | return ret_val; |
| 3443 | phy_info->cable_polarity = polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3444 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3445 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); |
| 3446 | if (ret_val) |
| 3447 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3449 | phy_info->mdix_mode = |
| 3450 | (e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >> |
| 3451 | M88E1000_PSSR_MDIX_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3453 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) { |
| 3454 | /* Cable Length Estimation and Local/Remote Receiver Information |
| 3455 | * are only valid at 1000 Mbps. |
| 3456 | */ |
| 3457 | phy_info->cable_length = |
| 3458 | (e1000_cable_length) ((phy_data & |
| 3459 | M88E1000_PSSR_CABLE_LENGTH) >> |
| 3460 | M88E1000_PSSR_CABLE_LENGTH_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3462 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); |
| 3463 | if (ret_val) |
| 3464 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3466 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> |
| 3467 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? |
| 3468 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
| 3469 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> |
| 3470 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? |
| 3471 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3473 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3475 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | } |
| 3477 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3478 | /** |
| 3479 | * e1000_phy_get_info - request phy info |
| 3480 | * @hw: Struct containing variables accessed by shared code |
| 3481 | * @phy_info: PHY information structure |
| 3482 | * |
| 3483 | * Get PHY information from various PHY registers |
| 3484 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3485 | 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] | 3486 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3487 | s32 ret_val; |
| 3488 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3490 | e_dbg("e1000_phy_get_info"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3491 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3492 | phy_info->cable_length = e1000_cable_length_undefined; |
| 3493 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined; |
| 3494 | phy_info->cable_polarity = e1000_rev_polarity_undefined; |
| 3495 | phy_info->downshift = e1000_downshift_undefined; |
| 3496 | phy_info->polarity_correction = e1000_polarity_reversal_undefined; |
| 3497 | phy_info->mdix_mode = e1000_auto_x_mode_undefined; |
| 3498 | phy_info->local_rx = e1000_1000t_rx_status_undefined; |
| 3499 | phy_info->remote_rx = e1000_1000t_rx_status_undefined; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3501 | if (hw->media_type != e1000_media_type_copper) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3502 | e_dbg("PHY info is only valid for copper media\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3503 | return -E1000_ERR_CONFIG; |
| 3504 | } |
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 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 3507 | if (ret_val) |
| 3508 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3509 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3510 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 3511 | if (ret_val) |
| 3512 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3513 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3514 | if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3515 | e_dbg("PHY info is only valid if link is up\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3516 | return -E1000_ERR_CONFIG; |
| 3517 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3519 | if (hw->phy_type == e1000_phy_igp) |
| 3520 | return e1000_phy_igp_get_info(hw, phy_info); |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3521 | else if ((hw->phy_type == e1000_phy_8211) || |
| 3522 | (hw->phy_type == e1000_phy_8201)) |
| 3523 | return E1000_SUCCESS; |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3524 | else |
| 3525 | return e1000_phy_m88_get_info(hw, phy_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | } |
| 3527 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3528 | s32 e1000_validate_mdi_setting(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3530 | e_dbg("e1000_validate_mdi_settings"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3532 | if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3533 | e_dbg("Invalid MDI setting detected\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3534 | hw->mdix = 1; |
| 3535 | return -E1000_ERR_CONFIG; |
| 3536 | } |
| 3537 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | } |
| 3539 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3540 | /** |
| 3541 | * e1000_init_eeprom_params - initialize sw eeprom vars |
| 3542 | * @hw: Struct containing variables accessed by shared code |
| 3543 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | * 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] | 3545 | * is configured. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3546 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3547 | s32 e1000_init_eeprom_params(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3549 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 3550 | u32 eecd = er32(EECD); |
| 3551 | s32 ret_val = E1000_SUCCESS; |
| 3552 | u16 eeprom_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3553 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3554 | e_dbg("e1000_init_eeprom_params"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3556 | switch (hw->mac_type) { |
| 3557 | case e1000_82542_rev2_0: |
| 3558 | case e1000_82542_rev2_1: |
| 3559 | case e1000_82543: |
| 3560 | case e1000_82544: |
| 3561 | eeprom->type = e1000_eeprom_microwire; |
| 3562 | eeprom->word_size = 64; |
| 3563 | eeprom->opcode_bits = 3; |
| 3564 | eeprom->address_bits = 6; |
| 3565 | eeprom->delay_usec = 50; |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3566 | break; |
| 3567 | case e1000_82540: |
| 3568 | case e1000_82545: |
| 3569 | case e1000_82545_rev_3: |
| 3570 | case e1000_82546: |
| 3571 | case e1000_82546_rev_3: |
| 3572 | eeprom->type = e1000_eeprom_microwire; |
| 3573 | eeprom->opcode_bits = 3; |
| 3574 | eeprom->delay_usec = 50; |
| 3575 | if (eecd & E1000_EECD_SIZE) { |
| 3576 | eeprom->word_size = 256; |
| 3577 | eeprom->address_bits = 8; |
| 3578 | } else { |
| 3579 | eeprom->word_size = 64; |
| 3580 | eeprom->address_bits = 6; |
| 3581 | } |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3582 | break; |
| 3583 | case e1000_82541: |
| 3584 | case e1000_82541_rev_2: |
| 3585 | case e1000_82547: |
| 3586 | case e1000_82547_rev_2: |
| 3587 | if (eecd & E1000_EECD_TYPE) { |
| 3588 | eeprom->type = e1000_eeprom_spi; |
| 3589 | eeprom->opcode_bits = 8; |
| 3590 | eeprom->delay_usec = 1; |
| 3591 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 3592 | eeprom->page_size = 32; |
| 3593 | eeprom->address_bits = 16; |
| 3594 | } else { |
| 3595 | eeprom->page_size = 8; |
| 3596 | eeprom->address_bits = 8; |
| 3597 | } |
| 3598 | } else { |
| 3599 | eeprom->type = e1000_eeprom_microwire; |
| 3600 | eeprom->opcode_bits = 3; |
| 3601 | eeprom->delay_usec = 50; |
| 3602 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 3603 | eeprom->word_size = 256; |
| 3604 | eeprom->address_bits = 8; |
| 3605 | } else { |
| 3606 | eeprom->word_size = 64; |
| 3607 | eeprom->address_bits = 6; |
| 3608 | } |
| 3609 | } |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3610 | break; |
| 3611 | default: |
| 3612 | break; |
| 3613 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3615 | if (eeprom->type == e1000_eeprom_spi) { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 3616 | /* eeprom_size will be an enum [0..8] that maps to eeprom sizes |
| 3617 | * 128B to 32KB (incremented by powers of 2). |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3618 | */ |
| 3619 | /* Set to default value for initial eeprom read. */ |
| 3620 | eeprom->word_size = 64; |
| 3621 | ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size); |
| 3622 | if (ret_val) |
| 3623 | return ret_val; |
| 3624 | eeprom_size = |
| 3625 | (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT; |
| 3626 | /* 256B eeprom size was not supported in earlier hardware, so we |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 3627 | * bump eeprom_size up one to ensure that "1" (which maps to |
| 3628 | * 256B) is never the result used in the shifting logic below. |
| 3629 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3630 | if (eeprom_size) |
| 3631 | eeprom_size++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3632 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3633 | eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT); |
| 3634 | } |
| 3635 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | } |
| 3637 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3638 | /** |
| 3639 | * e1000_raise_ee_clk - Raises the EEPROM's clock input. |
| 3640 | * @hw: Struct containing variables accessed by shared code |
| 3641 | * @eecd: EECD's current value |
| 3642 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3643 | static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3645 | /* Raise the clock input to the EEPROM (by setting the SK bit), and then |
| 3646 | * wait <delay> microseconds. |
| 3647 | */ |
| 3648 | *eecd = *eecd | E1000_EECD_SK; |
| 3649 | ew32(EECD, *eecd); |
| 3650 | E1000_WRITE_FLUSH(); |
| 3651 | udelay(hw->eeprom.delay_usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | } |
| 3653 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3654 | /** |
| 3655 | * e1000_lower_ee_clk - Lowers the EEPROM's clock input. |
| 3656 | * @hw: Struct containing variables accessed by shared code |
| 3657 | * @eecd: EECD's current value |
| 3658 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3659 | static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 3661 | /* Lower the clock input to the EEPROM (by clearing the SK bit), and |
| 3662 | * then wait 50 microseconds. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3663 | */ |
| 3664 | *eecd = *eecd & ~E1000_EECD_SK; |
| 3665 | ew32(EECD, *eecd); |
| 3666 | E1000_WRITE_FLUSH(); |
| 3667 | udelay(hw->eeprom.delay_usec); |
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_out_ee_bits - Shift data bits out to the EEPROM. |
| 3672 | * @hw: Struct containing variables accessed by shared code |
| 3673 | * @data: data to send to the EEPROM |
| 3674 | * @count: number of bits to shift out |
| 3675 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3676 | 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] | 3677 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3678 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 3679 | u32 eecd; |
| 3680 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3681 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3682 | /* We need to shift "count" bits out to the EEPROM. So, value in the |
| 3683 | * "data" parameter will be shifted out to the EEPROM one bit at a time. |
| 3684 | * In order to do this, "data" must be broken down into bits. |
| 3685 | */ |
| 3686 | mask = 0x01 << (count - 1); |
| 3687 | eecd = er32(EECD); |
| 3688 | if (eeprom->type == e1000_eeprom_microwire) { |
| 3689 | eecd &= ~E1000_EECD_DO; |
| 3690 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 3691 | eecd |= E1000_EECD_DO; |
| 3692 | } |
| 3693 | do { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 3694 | /* A "1" is shifted out to the EEPROM by setting bit "DI" to a |
| 3695 | * "1", and then raising and then lowering the clock (the SK bit |
| 3696 | * controls the clock input to the EEPROM). A "0" is shifted |
| 3697 | * out to the EEPROM by setting "DI" to "0" and then raising and |
| 3698 | * then lowering the clock. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3699 | */ |
| 3700 | eecd &= ~E1000_EECD_DI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3702 | if (data & mask) |
| 3703 | eecd |= E1000_EECD_DI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3704 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3705 | ew32(EECD, eecd); |
| 3706 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3708 | udelay(eeprom->delay_usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3710 | e1000_raise_ee_clk(hw, &eecd); |
| 3711 | e1000_lower_ee_clk(hw, &eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3713 | mask = mask >> 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3715 | } while (mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3717 | /* We leave the "DI" bit set to "0" when we leave this routine. */ |
| 3718 | eecd &= ~E1000_EECD_DI; |
| 3719 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | } |
| 3721 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3722 | /** |
| 3723 | * e1000_shift_in_ee_bits - Shift data bits in from the EEPROM |
| 3724 | * @hw: Struct containing variables accessed by shared code |
| 3725 | * @count: number of bits to shift in |
| 3726 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3727 | 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] | 3728 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3729 | u32 eecd; |
| 3730 | u32 i; |
| 3731 | u16 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3733 | /* In order to read a register from the EEPROM, we need to shift 'count' |
| 3734 | * bits in from the EEPROM. Bits are "shifted in" by raising the clock |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 3735 | * input to the EEPROM (setting the SK bit), and then reading the value |
| 3736 | * of the "DO" bit. During this "shifting in" process the "DI" bit |
| 3737 | * should always be clear. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3738 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3739 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3740 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3741 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3742 | eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); |
| 3743 | data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3744 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3745 | for (i = 0; i < count; i++) { |
| 3746 | data = data << 1; |
| 3747 | e1000_raise_ee_clk(hw, &eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3749 | eecd = er32(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 | eecd &= ~(E1000_EECD_DI); |
| 3752 | if (eecd & E1000_EECD_DO) |
| 3753 | data |= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3754 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3755 | e1000_lower_ee_clk(hw, &eecd); |
| 3756 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3757 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3758 | return data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | } |
| 3760 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3761 | /** |
| 3762 | * e1000_acquire_eeprom - Prepares EEPROM for access |
| 3763 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | * |
| 3765 | * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This |
| 3766 | * function should be called before issuing a command to the EEPROM. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3767 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3768 | static s32 e1000_acquire_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, i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3773 | e_dbg("e1000_acquire_eeprom"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3775 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3777 | /* Request EEPROM Access */ |
| 3778 | if (hw->mac_type > e1000_82544) { |
| 3779 | eecd |= E1000_EECD_REQ; |
| 3780 | ew32(EECD, eecd); |
| 3781 | eecd = er32(EECD); |
| 3782 | while ((!(eecd & E1000_EECD_GNT)) && |
| 3783 | (i < E1000_EEPROM_GRANT_ATTEMPTS)) { |
| 3784 | i++; |
| 3785 | udelay(5); |
| 3786 | eecd = er32(EECD); |
| 3787 | } |
| 3788 | if (!(eecd & E1000_EECD_GNT)) { |
| 3789 | eecd &= ~E1000_EECD_REQ; |
| 3790 | ew32(EECD, eecd); |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3791 | e_dbg("Could not acquire EEPROM grant\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3792 | return -E1000_ERR_EEPROM; |
| 3793 | } |
| 3794 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3796 | /* Setup EEPROM for Read/Write */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3798 | if (eeprom->type == e1000_eeprom_microwire) { |
| 3799 | /* Clear SK and DI */ |
| 3800 | eecd &= ~(E1000_EECD_DI | E1000_EECD_SK); |
| 3801 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3803 | /* Set CS */ |
| 3804 | eecd |= E1000_EECD_CS; |
| 3805 | ew32(EECD, eecd); |
| 3806 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 3807 | /* Clear SK and CS */ |
| 3808 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
| 3809 | ew32(EECD, eecd); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 3810 | E1000_WRITE_FLUSH(); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3811 | udelay(1); |
| 3812 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3814 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | } |
| 3816 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3817 | /** |
| 3818 | * e1000_standby_eeprom - Returns EEPROM to a "standby" state |
| 3819 | * @hw: Struct containing variables accessed by shared code |
| 3820 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3821 | static void e1000_standby_eeprom(struct e1000_hw *hw) |
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 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 3824 | u32 eecd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3826 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3828 | if (eeprom->type == e1000_eeprom_microwire) { |
| 3829 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
| 3830 | ew32(EECD, eecd); |
| 3831 | E1000_WRITE_FLUSH(); |
| 3832 | udelay(eeprom->delay_usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3833 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3834 | /* Clock high */ |
| 3835 | eecd |= E1000_EECD_SK; |
| 3836 | ew32(EECD, eecd); |
| 3837 | E1000_WRITE_FLUSH(); |
| 3838 | udelay(eeprom->delay_usec); |
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 | /* Select EEPROM */ |
| 3841 | eecd |= E1000_EECD_CS; |
| 3842 | ew32(EECD, eecd); |
| 3843 | E1000_WRITE_FLUSH(); |
| 3844 | udelay(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 | /* Clock low */ |
| 3847 | eecd &= ~E1000_EECD_SK; |
| 3848 | ew32(EECD, eecd); |
| 3849 | E1000_WRITE_FLUSH(); |
| 3850 | udelay(eeprom->delay_usec); |
| 3851 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 3852 | /* Toggle CS to flush commands */ |
| 3853 | eecd |= E1000_EECD_CS; |
| 3854 | ew32(EECD, eecd); |
| 3855 | E1000_WRITE_FLUSH(); |
| 3856 | udelay(eeprom->delay_usec); |
| 3857 | eecd &= ~E1000_EECD_CS; |
| 3858 | ew32(EECD, eecd); |
| 3859 | E1000_WRITE_FLUSH(); |
| 3860 | udelay(eeprom->delay_usec); |
| 3861 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3862 | } |
| 3863 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3864 | /** |
| 3865 | * e1000_release_eeprom - drop chip select |
| 3866 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3867 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3868 | * Terminates a command by inverting the EEPROM's chip select pin |
| 3869 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3870 | static void e1000_release_eeprom(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3872 | u32 eecd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3874 | e_dbg("e1000_release_eeprom"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3876 | eecd = er32(EECD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3877 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3878 | if (hw->eeprom.type == e1000_eeprom_spi) { |
| 3879 | eecd |= E1000_EECD_CS; /* Pull CS high */ |
| 3880 | eecd &= ~E1000_EECD_SK; /* Lower SCK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3881 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3882 | ew32(EECD, eecd); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 3883 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3885 | udelay(hw->eeprom.delay_usec); |
| 3886 | } else if (hw->eeprom.type == e1000_eeprom_microwire) { |
| 3887 | /* cleanup eeprom */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3889 | /* CS on Microwire is active-high */ |
| 3890 | eecd &= ~(E1000_EECD_CS | E1000_EECD_DI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3892 | ew32(EECD, eecd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3893 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3894 | /* Rising edge of clock */ |
| 3895 | eecd |= E1000_EECD_SK; |
| 3896 | ew32(EECD, eecd); |
| 3897 | E1000_WRITE_FLUSH(); |
| 3898 | udelay(hw->eeprom.delay_usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3900 | /* Falling edge of clock */ |
| 3901 | eecd &= ~E1000_EECD_SK; |
| 3902 | ew32(EECD, eecd); |
| 3903 | E1000_WRITE_FLUSH(); |
| 3904 | udelay(hw->eeprom.delay_usec); |
| 3905 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3906 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3907 | /* Stop requesting EEPROM access */ |
| 3908 | if (hw->mac_type > e1000_82544) { |
| 3909 | eecd &= ~E1000_EECD_REQ; |
| 3910 | ew32(EECD, eecd); |
| 3911 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | } |
| 3913 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3914 | /** |
| 3915 | * e1000_spi_eeprom_ready - Reads a 16 bit word from the EEPROM. |
| 3916 | * @hw: Struct containing variables accessed by shared code |
| 3917 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3918 | static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3919 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3920 | u16 retry_count = 0; |
| 3921 | u8 spi_stat_reg; |
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_spi_eeprom_ready"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3925 | /* Read "Status Register" repeatedly until the LSB is cleared. The |
| 3926 | * EEPROM will signal that the command has been completed by clearing |
| 3927 | * bit 0 of the internal status register. If it's not cleared within |
| 3928 | * 5 milliseconds, then error out. |
| 3929 | */ |
| 3930 | retry_count = 0; |
| 3931 | do { |
| 3932 | e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI, |
| 3933 | hw->eeprom.opcode_bits); |
| 3934 | spi_stat_reg = (u8) e1000_shift_in_ee_bits(hw, 8); |
| 3935 | if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI)) |
| 3936 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3938 | udelay(5); |
| 3939 | retry_count += 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3941 | e1000_standby_eeprom(hw); |
| 3942 | } while (retry_count < EEPROM_MAX_RETRY_SPI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3944 | /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and |
| 3945 | * only 0-5mSec on 5V devices) |
| 3946 | */ |
| 3947 | if (retry_count >= EEPROM_MAX_RETRY_SPI) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3948 | e_dbg("SPI EEPROM Status error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3949 | return -E1000_ERR_EEPROM; |
| 3950 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3952 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3953 | } |
| 3954 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3955 | /** |
| 3956 | * e1000_read_eeprom - Reads a 16 bit word from the EEPROM. |
| 3957 | * @hw: Struct containing variables accessed by shared code |
| 3958 | * @offset: offset of word in the EEPROM to read |
| 3959 | * @data: word read from the EEPROM |
| 3960 | * @words: number of words to read |
| 3961 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3962 | 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] | 3963 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3964 | s32 ret; |
| 3965 | spin_lock(&e1000_eeprom_lock); |
| 3966 | ret = e1000_do_read_eeprom(hw, offset, words, data); |
| 3967 | spin_unlock(&e1000_eeprom_lock); |
| 3968 | return ret; |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 3969 | } |
| 3970 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3971 | static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, |
| 3972 | u16 *data) |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 3973 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3974 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 3975 | u32 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3976 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3977 | e_dbg("e1000_read_eeprom"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3978 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 3979 | if (hw->mac_type == e1000_ce4100) { |
| 3980 | GBE_CONFIG_FLASH_READ(GBE_CONFIG_BASE_VIRT, offset, words, |
| 3981 | data); |
| 3982 | return E1000_SUCCESS; |
| 3983 | } |
| 3984 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3985 | /* If eeprom is not yet detected, do so now */ |
| 3986 | if (eeprom->word_size == 0) |
| 3987 | e1000_init_eeprom_params(hw); |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3988 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 3989 | /* A check for invalid values: offset too large, too many words, and |
| 3990 | * not enough words. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3991 | */ |
| 3992 | if ((offset >= eeprom->word_size) |
| 3993 | || (words > eeprom->word_size - offset) || (words == 0)) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 3994 | e_dbg("\"words\" parameter out of bounds. Words = %d," |
| 3995 | "size = %d\n", offset, eeprom->word_size); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3996 | return -E1000_ERR_EEPROM; |
| 3997 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3999 | /* EEPROM's that don't use EERD to read require us to bit-bang the SPI |
| 4000 | * directly. In this case, we need to acquire the EEPROM so that |
| 4001 | * FW or other port software does not interrupt. |
| 4002 | */ |
Jesse Brandeburg | 8f601b2 | 2009-09-25 12:20:11 +0000 | [diff] [blame] | 4003 | /* Prepare the EEPROM for bit-bang reading */ |
| 4004 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) |
| 4005 | return -E1000_ERR_EEPROM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4007 | /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 4008 | * acquired the EEPROM at this point, so any returns should release it |
| 4009 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4010 | if (eeprom->type == e1000_eeprom_spi) { |
| 4011 | u16 word_in; |
| 4012 | u8 read_opcode = EEPROM_READ_OPCODE_SPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4014 | if (e1000_spi_eeprom_ready(hw)) { |
| 4015 | e1000_release_eeprom(hw); |
| 4016 | return -E1000_ERR_EEPROM; |
| 4017 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4019 | e1000_standby_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4020 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 4021 | /* Some SPI eeproms use the 8th address bit embedded in the |
| 4022 | * opcode |
| 4023 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4024 | if ((eeprom->address_bits == 8) && (offset >= 128)) |
| 4025 | read_opcode |= EEPROM_A8_OPCODE_SPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4027 | /* Send the READ command (opcode + addr) */ |
| 4028 | e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits); |
| 4029 | e1000_shift_out_ee_bits(hw, (u16) (offset * 2), |
| 4030 | eeprom->address_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 4032 | /* Read the data. The address of the eeprom internally |
| 4033 | * increments with each byte (spi) being read, saving on the |
| 4034 | * overhead of eeprom setup and tear-down. The address counter |
| 4035 | * will roll over if reading beyond the size of the eeprom, thus |
| 4036 | * allowing the entire memory to be read starting from any |
| 4037 | * offset. |
| 4038 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4039 | for (i = 0; i < words; i++) { |
| 4040 | word_in = e1000_shift_in_ee_bits(hw, 16); |
| 4041 | data[i] = (word_in >> 8) | (word_in << 8); |
| 4042 | } |
| 4043 | } else if (eeprom->type == e1000_eeprom_microwire) { |
| 4044 | for (i = 0; i < words; i++) { |
| 4045 | /* Send the READ command (opcode + addr) */ |
| 4046 | e1000_shift_out_ee_bits(hw, |
| 4047 | EEPROM_READ_OPCODE_MICROWIRE, |
| 4048 | eeprom->opcode_bits); |
| 4049 | e1000_shift_out_ee_bits(hw, (u16) (offset + i), |
| 4050 | eeprom->address_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 4052 | /* Read the data. For microwire, each word requires the |
| 4053 | * overhead of eeprom setup and tear-down. |
| 4054 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4055 | data[i] = e1000_shift_in_ee_bits(hw, 16); |
| 4056 | e1000_standby_eeprom(hw); |
| 4057 | } |
| 4058 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4060 | /* End this read operation */ |
| 4061 | e1000_release_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 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 | /** |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4067 | * e1000_validate_eeprom_checksum - Verifies that the EEPROM has a valid checksum |
| 4068 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | * |
| 4070 | * Reads the first 64 16 bit words of the EEPROM and sums the values read. |
| 4071 | * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is |
| 4072 | * valid. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4073 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4074 | s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4076 | u16 checksum = 0; |
| 4077 | u16 i, eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4078 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4079 | e_dbg("e1000_validate_eeprom_checksum"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4081 | for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) { |
| 4082 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4083 | e_dbg("EEPROM Read Error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4084 | return -E1000_ERR_EEPROM; |
| 4085 | } |
| 4086 | checksum += eeprom_data; |
| 4087 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4088 | |
Jeff Kirsher | e2faeec | 2011-08-30 20:58:56 -0400 | [diff] [blame] | 4089 | #ifdef CONFIG_PARISC |
| 4090 | /* This is a signature and not a checksum on HP c8000 */ |
| 4091 | if ((hw->subsystem_vendor_id == 0x103C) && (eeprom_data == 0x16d6)) |
| 4092 | return E1000_SUCCESS; |
| 4093 | |
| 4094 | #endif |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4095 | if (checksum == (u16) EEPROM_SUM) |
| 4096 | return E1000_SUCCESS; |
| 4097 | else { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4098 | e_dbg("EEPROM Checksum Invalid\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4099 | return -E1000_ERR_EEPROM; |
| 4100 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | } |
| 4102 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4103 | /** |
| 4104 | * e1000_update_eeprom_checksum - Calculates/writes the EEPROM checksum |
| 4105 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | * |
| 4107 | * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA. |
| 4108 | * Writes the difference to word offset 63 of the EEPROM. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4109 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4110 | s32 e1000_update_eeprom_checksum(struct e1000_hw *hw) |
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 | u16 checksum = 0; |
| 4113 | u16 i, eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4114 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4115 | e_dbg("e1000_update_eeprom_checksum"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4117 | for (i = 0; i < EEPROM_CHECKSUM_REG; i++) { |
| 4118 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4119 | e_dbg("EEPROM Read Error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4120 | return -E1000_ERR_EEPROM; |
| 4121 | } |
| 4122 | checksum += eeprom_data; |
| 4123 | } |
| 4124 | checksum = (u16) EEPROM_SUM - checksum; |
| 4125 | if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4126 | e_dbg("EEPROM Write Error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4127 | return -E1000_ERR_EEPROM; |
| 4128 | } |
| 4129 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | } |
| 4131 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4132 | /** |
| 4133 | * e1000_write_eeprom - write words to the different EEPROM types. |
| 4134 | * @hw: Struct containing variables accessed by shared code |
| 4135 | * @offset: offset within the EEPROM to be written to |
| 4136 | * @words: number of words to write |
| 4137 | * @data: 16 bit word to be written to the EEPROM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | * |
| 4139 | * If e1000_update_eeprom_checksum is not called after this function, the |
| 4140 | * EEPROM will most likely contain an invalid checksum. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4141 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4142 | 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] | 4143 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4144 | s32 ret; |
| 4145 | spin_lock(&e1000_eeprom_lock); |
| 4146 | ret = e1000_do_write_eeprom(hw, offset, words, data); |
| 4147 | spin_unlock(&e1000_eeprom_lock); |
| 4148 | return ret; |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 4149 | } |
| 4150 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4151 | static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, |
| 4152 | u16 *data) |
Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 4153 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4154 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 4155 | s32 status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4157 | e_dbg("e1000_write_eeprom"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4158 | |
Dirk Brandewie | 5377a41 | 2011-01-06 14:29:54 +0000 | [diff] [blame] | 4159 | if (hw->mac_type == e1000_ce4100) { |
| 4160 | GBE_CONFIG_FLASH_WRITE(GBE_CONFIG_BASE_VIRT, offset, words, |
| 4161 | data); |
| 4162 | return E1000_SUCCESS; |
| 4163 | } |
| 4164 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4165 | /* If eeprom is not yet detected, do so now */ |
| 4166 | if (eeprom->word_size == 0) |
| 4167 | e1000_init_eeprom_params(hw); |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4168 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 4169 | /* A check for invalid values: offset too large, too many words, and |
| 4170 | * not enough words. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4171 | */ |
| 4172 | if ((offset >= eeprom->word_size) |
| 4173 | || (words > eeprom->word_size - offset) || (words == 0)) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4174 | e_dbg("\"words\" parameter out of bounds\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4175 | return -E1000_ERR_EEPROM; |
| 4176 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4178 | /* Prepare the EEPROM for writing */ |
| 4179 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) |
| 4180 | return -E1000_ERR_EEPROM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4182 | if (eeprom->type == e1000_eeprom_microwire) { |
| 4183 | status = e1000_write_eeprom_microwire(hw, offset, words, data); |
| 4184 | } else { |
| 4185 | status = e1000_write_eeprom_spi(hw, offset, words, data); |
| 4186 | msleep(10); |
| 4187 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4189 | /* Done with writing */ |
| 4190 | e1000_release_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4192 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4193 | } |
| 4194 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4195 | /** |
| 4196 | * e1000_write_eeprom_spi - Writes a 16 bit word to a given offset in an SPI EEPROM. |
| 4197 | * @hw: Struct containing variables accessed by shared code |
| 4198 | * @offset: offset within the EEPROM to be written to |
| 4199 | * @words: number of words to write |
| 4200 | * @data: pointer to array of 8 bit words to be written to the EEPROM |
| 4201 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4202 | static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words, |
| 4203 | u16 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4205 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 4206 | u16 widx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4208 | e_dbg("e1000_write_eeprom_spi"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4209 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4210 | while (widx < words) { |
| 4211 | u8 write_opcode = EEPROM_WRITE_OPCODE_SPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4212 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4213 | if (e1000_spi_eeprom_ready(hw)) |
| 4214 | return -E1000_ERR_EEPROM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4215 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4216 | e1000_standby_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4218 | /* Send the WRITE ENABLE command (8 bit opcode ) */ |
| 4219 | e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI, |
| 4220 | eeprom->opcode_bits); |
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 | e1000_standby_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 4224 | /* Some SPI eeproms use the 8th address bit embedded in the |
| 4225 | * opcode |
| 4226 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4227 | if ((eeprom->address_bits == 8) && (offset >= 128)) |
| 4228 | write_opcode |= EEPROM_A8_OPCODE_SPI; |
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 Write command (8-bit opcode + addr) */ |
| 4231 | e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits); |
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 | e1000_shift_out_ee_bits(hw, (u16) ((offset + widx) * 2), |
| 4234 | eeprom->address_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4235 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4236 | /* Send the data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 4238 | /* Loop to allow for up to whole page write (32 bytes) of |
| 4239 | * eeprom |
| 4240 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4241 | while (widx < words) { |
| 4242 | u16 word_out = data[widx]; |
| 4243 | word_out = (word_out >> 8) | (word_out << 8); |
| 4244 | e1000_shift_out_ee_bits(hw, word_out, 16); |
| 4245 | widx++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4246 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 4247 | /* Some larger eeprom sizes are capable of a 32-byte |
| 4248 | * PAGE WRITE operation, while the smaller eeproms are |
| 4249 | * capable of an 8-byte PAGE WRITE operation. Break the |
| 4250 | * inner loop to pass new address |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4251 | */ |
| 4252 | if ((((offset + widx) * 2) % eeprom->page_size) == 0) { |
| 4253 | e1000_standby_eeprom(hw); |
| 4254 | break; |
| 4255 | } |
| 4256 | } |
| 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 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | } |
| 4261 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4262 | /** |
| 4263 | * e1000_write_eeprom_microwire - Writes a 16 bit word to a given offset in a Microwire EEPROM. |
| 4264 | * @hw: Struct containing variables accessed by shared code |
| 4265 | * @offset: offset within the EEPROM to be written to |
| 4266 | * @words: number of words to write |
| 4267 | * @data: pointer to array of 8 bit words to be written to the EEPROM |
| 4268 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4269 | static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset, |
| 4270 | u16 words, u16 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4272 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 4273 | u32 eecd; |
| 4274 | u16 words_written = 0; |
| 4275 | u16 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4277 | e_dbg("e1000_write_eeprom_microwire"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4278 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4279 | /* Send the write enable command to the EEPROM (3-bit opcode plus |
| 4280 | * 6/8-bit dummy address beginning with 11). It's less work to include |
| 4281 | * the 11 of the dummy address as part of the opcode than it is to shift |
| 4282 | * it over the correct number of bits for the address. This puts the |
| 4283 | * EEPROM into write/erase mode. |
| 4284 | */ |
| 4285 | e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE, |
| 4286 | (u16) (eeprom->opcode_bits + 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4288 | e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4290 | /* Prepare the EEPROM */ |
| 4291 | e1000_standby_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4292 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4293 | while (words_written < words) { |
| 4294 | /* Send the Write command (3-bit opcode + addr) */ |
| 4295 | e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE, |
| 4296 | eeprom->opcode_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4298 | e1000_shift_out_ee_bits(hw, (u16) (offset + words_written), |
| 4299 | eeprom->address_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4301 | /* Send the data */ |
| 4302 | e1000_shift_out_ee_bits(hw, data[words_written], 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 4304 | /* Toggle the CS line. This in effect tells the EEPROM to |
| 4305 | * execute the previous command. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4306 | */ |
| 4307 | e1000_standby_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 4309 | /* Read DO repeatedly until it is high (equal to '1'). The |
| 4310 | * EEPROM will signal that the command has been completed by |
| 4311 | * raising the DO signal. If DO does not go high in 10 |
| 4312 | * milliseconds, then error out. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4313 | */ |
| 4314 | for (i = 0; i < 200; i++) { |
| 4315 | eecd = er32(EECD); |
| 4316 | if (eecd & E1000_EECD_DO) |
| 4317 | break; |
| 4318 | udelay(50); |
| 4319 | } |
| 4320 | if (i == 200) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4321 | e_dbg("EEPROM Write did not complete\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4322 | return -E1000_ERR_EEPROM; |
| 4323 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4325 | /* Recover from write */ |
| 4326 | e1000_standby_eeprom(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4328 | words_written++; |
| 4329 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4331 | /* Send the write disable command to the EEPROM (3-bit opcode plus |
| 4332 | * 6/8-bit dummy address beginning with 10). It's less work to include |
| 4333 | * the 10 of the dummy address as part of the opcode than it is to shift |
| 4334 | * it over the correct number of bits for the address. This takes the |
| 4335 | * EEPROM out of write/erase mode. |
| 4336 | */ |
| 4337 | e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE, |
| 4338 | (u16) (eeprom->opcode_bits + 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4340 | e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4342 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4343 | } |
| 4344 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4345 | /** |
| 4346 | * e1000_read_mac_addr - read the adapters MAC from eeprom |
| 4347 | * @hw: Struct containing variables accessed by shared code |
| 4348 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the |
| 4350 | * second function of dual function devices |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4351 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4352 | s32 e1000_read_mac_addr(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4353 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4354 | u16 offset; |
| 4355 | u16 eeprom_data, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4356 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4357 | e_dbg("e1000_read_mac_addr"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4358 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4359 | for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) { |
| 4360 | offset = i >> 1; |
| 4361 | if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4362 | e_dbg("EEPROM Read Error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4363 | return -E1000_ERR_EEPROM; |
| 4364 | } |
| 4365 | hw->perm_mac_addr[i] = (u8) (eeprom_data & 0x00FF); |
| 4366 | hw->perm_mac_addr[i + 1] = (u8) (eeprom_data >> 8); |
| 4367 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4368 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4369 | switch (hw->mac_type) { |
| 4370 | default: |
| 4371 | break; |
| 4372 | case e1000_82546: |
| 4373 | case e1000_82546_rev_3: |
| 4374 | if (er32(STATUS) & E1000_STATUS_FUNC_1) |
| 4375 | hw->perm_mac_addr[5] ^= 0x01; |
| 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 | for (i = 0; i < NODE_ADDRESS_SIZE; i++) |
| 4380 | hw->mac_addr[i] = hw->perm_mac_addr[i]; |
| 4381 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4382 | } |
| 4383 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4384 | /** |
| 4385 | * e1000_init_rx_addrs - Initializes receive address filters. |
| 4386 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | * |
| 4388 | * 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] | 4389 | * of the receive address registers. Clears the multicast table. Assumes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | * the receiver is in reset when the routine is called. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4391 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4392 | static void e1000_init_rx_addrs(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4394 | u32 i; |
| 4395 | u32 rar_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4397 | e_dbg("e1000_init_rx_addrs"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4398 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4399 | /* Setup the receive address. */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4400 | e_dbg("Programming MAC Address into RAR[0]\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4402 | e1000_rar_set(hw, hw->mac_addr, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4404 | rar_num = E1000_RAR_ENTRIES; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4405 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4406 | /* Zero out the other 15 receive addresses. */ |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4407 | e_dbg("Clearing RAR[1-15]\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4408 | for (i = 1; i < rar_num; i++) { |
| 4409 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0); |
| 4410 | E1000_WRITE_FLUSH(); |
| 4411 | E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0); |
| 4412 | E1000_WRITE_FLUSH(); |
| 4413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4414 | } |
| 4415 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4416 | /** |
| 4417 | * e1000_hash_mc_addr - Hashes an address to determine its location in the multicast table |
| 4418 | * @hw: Struct containing variables accessed by shared code |
| 4419 | * @mc_addr: the multicast address to hash |
| 4420 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4421 | u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4422 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4423 | u32 hash_value = 0; |
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 | /* The portion of the address that is used for the hash table is |
| 4426 | * determined by the mc_filter_type setting. |
| 4427 | */ |
| 4428 | switch (hw->mc_filter_type) { |
| 4429 | /* [0] [1] [2] [3] [4] [5] |
| 4430 | * 01 AA 00 12 34 56 |
| 4431 | * LSB MSB |
| 4432 | */ |
| 4433 | case 0: |
| 4434 | /* [47:36] i.e. 0x563 for above example address */ |
| 4435 | hash_value = ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4)); |
| 4436 | break; |
| 4437 | case 1: |
| 4438 | /* [46:35] i.e. 0xAC6 for above example address */ |
| 4439 | hash_value = ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5)); |
| 4440 | break; |
| 4441 | case 2: |
| 4442 | /* [45:34] i.e. 0x5D8 for above example address */ |
| 4443 | hash_value = ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6)); |
| 4444 | break; |
| 4445 | case 3: |
| 4446 | /* [43:32] i.e. 0x634 for above example address */ |
| 4447 | hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8)); |
| 4448 | break; |
| 4449 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4450 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4451 | hash_value &= 0xFFF; |
| 4452 | return hash_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | } |
| 4454 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4455 | /** |
| 4456 | * e1000_rar_set - Puts an ethernet address into a receive address register. |
| 4457 | * @hw: Struct containing variables accessed by shared code |
| 4458 | * @addr: Address to put into receive address register |
| 4459 | * @index: Receive address register to write |
| 4460 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4461 | void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4463 | u32 rar_low, rar_high; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4465 | /* HW expects these in little endian so we reverse the byte order |
| 4466 | * from network order (big endian) to little endian |
| 4467 | */ |
| 4468 | rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) | |
| 4469 | ((u32) addr[2] << 16) | ((u32) addr[3] << 24)); |
| 4470 | rar_high = ((u32) addr[4] | ((u32) addr[5] << 8)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4472 | /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx |
| 4473 | * unit hang. |
| 4474 | * |
| 4475 | * Description: |
| 4476 | * If there are any Rx frames queued up or otherwise present in the HW |
| 4477 | * before RSS is enabled, and then we enable RSS, the HW Rx unit will |
| 4478 | * hang. To work around this issue, we have to disable receives and |
| 4479 | * flush out all Rx frames before we enable RSS. To do so, we modify we |
| 4480 | * redirect all Rx traffic to manageability and then reset the HW. |
| 4481 | * This flushes away Rx frames, and (since the redirections to |
| 4482 | * manageability persists across resets) keeps new ones from coming in |
| 4483 | * while we work. Then, we clear the Address Valid AV bit for all MAC |
| 4484 | * addresses and undo the re-direction to manageability. |
| 4485 | * Now, frames are coming in again, but the MAC won't accept them, so |
| 4486 | * far so good. We now proceed to initialize RSS (if necessary) and |
| 4487 | * configure the Rx unit. Last, we re-enable the AV bits and continue |
| 4488 | * on our merry way. |
| 4489 | */ |
| 4490 | switch (hw->mac_type) { |
| 4491 | default: |
| 4492 | /* Indicate to hardware the Address is Valid. */ |
| 4493 | rar_high |= E1000_RAH_AV; |
| 4494 | break; |
| 4495 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4497 | E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low); |
| 4498 | E1000_WRITE_FLUSH(); |
| 4499 | E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high); |
| 4500 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4501 | } |
| 4502 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4503 | /** |
| 4504 | * e1000_write_vfta - Writes a value to the specified offset in the VLAN filter table. |
| 4505 | * @hw: Struct containing variables accessed by shared code |
| 4506 | * @offset: Offset in VLAN filer table to write |
| 4507 | * @value: Value to write into VLAN filter table |
| 4508 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4509 | void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4511 | u32 temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4513 | if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) { |
| 4514 | temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1)); |
| 4515 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); |
| 4516 | E1000_WRITE_FLUSH(); |
| 4517 | E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp); |
| 4518 | E1000_WRITE_FLUSH(); |
| 4519 | } else { |
| 4520 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); |
| 4521 | E1000_WRITE_FLUSH(); |
| 4522 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4523 | } |
| 4524 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4525 | /** |
| 4526 | * e1000_clear_vfta - Clears the VLAN filer table |
| 4527 | * @hw: Struct containing variables accessed by shared code |
| 4528 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4529 | static void e1000_clear_vfta(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4531 | u32 offset; |
| 4532 | u32 vfta_value = 0; |
| 4533 | u32 vfta_offset = 0; |
| 4534 | u32 vfta_bit_in_reg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4536 | for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) { |
| 4537 | /* If the offset we want to clear is the same offset of the |
| 4538 | * manageability VLAN ID, then clear all bits except that of the |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 4539 | * manageability unit |
| 4540 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4541 | vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0; |
| 4542 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value); |
| 4543 | E1000_WRITE_FLUSH(); |
| 4544 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | } |
| 4546 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4547 | static s32 e1000_id_led_init(struct e1000_hw *hw) |
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 | u32 ledctl; |
| 4550 | const u32 ledctl_mask = 0x000000FF; |
| 4551 | const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON; |
| 4552 | const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF; |
| 4553 | u16 eeprom_data, i, temp; |
| 4554 | const u16 led_mask = 0x0F; |
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_id_led_init"); |
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 | if (hw->mac_type < e1000_82540) { |
| 4559 | /* Nothing to do */ |
| 4560 | return E1000_SUCCESS; |
| 4561 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4563 | ledctl = er32(LEDCTL); |
| 4564 | hw->ledctl_default = ledctl; |
| 4565 | hw->ledctl_mode1 = hw->ledctl_default; |
| 4566 | hw->ledctl_mode2 = hw->ledctl_default; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4568 | 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] | 4569 | e_dbg("EEPROM Read Error\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4570 | return -E1000_ERR_EEPROM; |
| 4571 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4572 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4573 | if ((eeprom_data == ID_LED_RESERVED_0000) || |
| 4574 | (eeprom_data == ID_LED_RESERVED_FFFF)) { |
| 4575 | eeprom_data = ID_LED_DEFAULT; |
| 4576 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4577 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4578 | for (i = 0; i < 4; i++) { |
| 4579 | temp = (eeprom_data >> (i << 2)) & led_mask; |
| 4580 | switch (temp) { |
| 4581 | case ID_LED_ON1_DEF2: |
| 4582 | case ID_LED_ON1_ON2: |
| 4583 | case ID_LED_ON1_OFF2: |
| 4584 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); |
| 4585 | hw->ledctl_mode1 |= ledctl_on << (i << 3); |
| 4586 | break; |
| 4587 | case ID_LED_OFF1_DEF2: |
| 4588 | case ID_LED_OFF1_ON2: |
| 4589 | case ID_LED_OFF1_OFF2: |
| 4590 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); |
| 4591 | hw->ledctl_mode1 |= ledctl_off << (i << 3); |
| 4592 | break; |
| 4593 | default: |
| 4594 | /* Do nothing */ |
| 4595 | break; |
| 4596 | } |
| 4597 | switch (temp) { |
| 4598 | case ID_LED_DEF1_ON2: |
| 4599 | case ID_LED_ON1_ON2: |
| 4600 | case ID_LED_OFF1_ON2: |
| 4601 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); |
| 4602 | hw->ledctl_mode2 |= ledctl_on << (i << 3); |
| 4603 | break; |
| 4604 | case ID_LED_DEF1_OFF2: |
| 4605 | case ID_LED_ON1_OFF2: |
| 4606 | case ID_LED_OFF1_OFF2: |
| 4607 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); |
| 4608 | hw->ledctl_mode2 |= ledctl_off << (i << 3); |
| 4609 | break; |
| 4610 | default: |
| 4611 | /* Do nothing */ |
| 4612 | break; |
| 4613 | } |
| 4614 | } |
| 4615 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4616 | } |
| 4617 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4618 | /** |
| 4619 | * e1000_setup_led |
| 4620 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4622 | * Prepares SW controlable LED for use and saves the current state of the LED. |
| 4623 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4624 | s32 e1000_setup_led(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4625 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4626 | u32 ledctl; |
| 4627 | s32 ret_val = E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4629 | e_dbg("e1000_setup_led"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4630 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4631 | switch (hw->mac_type) { |
| 4632 | case e1000_82542_rev2_0: |
| 4633 | case e1000_82542_rev2_1: |
| 4634 | case e1000_82543: |
| 4635 | case e1000_82544: |
| 4636 | /* No setup necessary */ |
| 4637 | break; |
| 4638 | case e1000_82541: |
| 4639 | case e1000_82547: |
| 4640 | case e1000_82541_rev_2: |
| 4641 | case e1000_82547_rev_2: |
| 4642 | /* Turn off PHY Smart Power Down (if enabled) */ |
| 4643 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 4644 | &hw->phy_spd_default); |
| 4645 | if (ret_val) |
| 4646 | return ret_val; |
| 4647 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 4648 | (u16) (hw->phy_spd_default & |
| 4649 | ~IGP01E1000_GMII_SPD)); |
| 4650 | if (ret_val) |
| 4651 | return ret_val; |
| 4652 | /* Fall Through */ |
| 4653 | default: |
| 4654 | if (hw->media_type == e1000_media_type_fiber) { |
| 4655 | ledctl = er32(LEDCTL); |
| 4656 | /* Save current LEDCTL settings */ |
| 4657 | hw->ledctl_default = ledctl; |
| 4658 | /* Turn off LED0 */ |
| 4659 | ledctl &= ~(E1000_LEDCTL_LED0_IVRT | |
| 4660 | E1000_LEDCTL_LED0_BLINK | |
| 4661 | E1000_LEDCTL_LED0_MODE_MASK); |
| 4662 | ledctl |= (E1000_LEDCTL_MODE_LED_OFF << |
| 4663 | E1000_LEDCTL_LED0_MODE_SHIFT); |
| 4664 | ew32(LEDCTL, ledctl); |
| 4665 | } else if (hw->media_type == e1000_media_type_copper) |
| 4666 | ew32(LEDCTL, hw->ledctl_mode1); |
| 4667 | break; |
| 4668 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4670 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4671 | } |
| 4672 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4673 | /** |
| 4674 | * e1000_cleanup_led - Restores the saved state of the SW controlable LED. |
| 4675 | * @hw: Struct containing variables accessed by shared code |
| 4676 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4677 | s32 e1000_cleanup_led(struct e1000_hw *hw) |
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 | s32 ret_val = E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4681 | e_dbg("e1000_cleanup_led"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4682 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4683 | switch (hw->mac_type) { |
| 4684 | case e1000_82542_rev2_0: |
| 4685 | case e1000_82542_rev2_1: |
| 4686 | case e1000_82543: |
| 4687 | case e1000_82544: |
| 4688 | /* No cleanup necessary */ |
| 4689 | break; |
| 4690 | case e1000_82541: |
| 4691 | case e1000_82547: |
| 4692 | case e1000_82541_rev_2: |
| 4693 | case e1000_82547_rev_2: |
| 4694 | /* Turn on PHY Smart Power Down (if previously enabled) */ |
| 4695 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 4696 | hw->phy_spd_default); |
| 4697 | if (ret_val) |
| 4698 | return ret_val; |
| 4699 | /* Fall Through */ |
| 4700 | default: |
| 4701 | /* Restore LEDCTL settings */ |
| 4702 | ew32(LEDCTL, hw->ledctl_default); |
| 4703 | break; |
| 4704 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4705 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4706 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4707 | } |
| 4708 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4709 | /** |
| 4710 | * e1000_led_on - Turns on the software controllable LED |
| 4711 | * @hw: Struct containing variables accessed by shared code |
| 4712 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4713 | s32 e1000_led_on(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4715 | u32 ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4716 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4717 | e_dbg("e1000_led_on"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4718 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4719 | switch (hw->mac_type) { |
| 4720 | case e1000_82542_rev2_0: |
| 4721 | case e1000_82542_rev2_1: |
| 4722 | case e1000_82543: |
| 4723 | /* Set SW Defineable Pin 0 to turn on the LED */ |
| 4724 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4725 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4726 | break; |
| 4727 | case e1000_82544: |
| 4728 | if (hw->media_type == e1000_media_type_fiber) { |
| 4729 | /* Set SW Defineable Pin 0 to turn on the LED */ |
| 4730 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4731 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4732 | } else { |
| 4733 | /* Clear SW Defineable Pin 0 to turn on the LED */ |
| 4734 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4735 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4736 | } |
| 4737 | break; |
| 4738 | default: |
| 4739 | if (hw->media_type == e1000_media_type_fiber) { |
| 4740 | /* Clear SW Defineable Pin 0 to turn on the LED */ |
| 4741 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4742 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4743 | } else if (hw->media_type == e1000_media_type_copper) { |
| 4744 | ew32(LEDCTL, hw->ledctl_mode2); |
| 4745 | return E1000_SUCCESS; |
| 4746 | } |
| 4747 | break; |
| 4748 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4749 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4750 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4752 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4753 | } |
| 4754 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4755 | /** |
| 4756 | * e1000_led_off - Turns off the software controllable LED |
| 4757 | * @hw: Struct containing variables accessed by shared code |
| 4758 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4759 | s32 e1000_led_off(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4760 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4761 | u32 ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4763 | e_dbg("e1000_led_off"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4765 | switch (hw->mac_type) { |
| 4766 | case e1000_82542_rev2_0: |
| 4767 | case e1000_82542_rev2_1: |
| 4768 | case e1000_82543: |
| 4769 | /* Clear SW Defineable Pin 0 to turn off the LED */ |
| 4770 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4771 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4772 | break; |
| 4773 | case e1000_82544: |
| 4774 | if (hw->media_type == e1000_media_type_fiber) { |
| 4775 | /* Clear SW Defineable Pin 0 to turn off the LED */ |
| 4776 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 4777 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4778 | } else { |
| 4779 | /* Set SW Defineable Pin 0 to turn off the LED */ |
| 4780 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4781 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4782 | } |
| 4783 | break; |
| 4784 | default: |
| 4785 | if (hw->media_type == e1000_media_type_fiber) { |
| 4786 | /* Set SW Defineable Pin 0 to turn off the LED */ |
| 4787 | ctrl |= E1000_CTRL_SWDPIN0; |
| 4788 | ctrl |= E1000_CTRL_SWDPIO0; |
| 4789 | } else if (hw->media_type == e1000_media_type_copper) { |
| 4790 | ew32(LEDCTL, hw->ledctl_mode1); |
| 4791 | return E1000_SUCCESS; |
| 4792 | } |
| 4793 | break; |
| 4794 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4795 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4796 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4797 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4798 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4799 | } |
| 4800 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4801 | /** |
| 4802 | * e1000_clear_hw_cntrs - Clears all hardware statistics counters. |
| 4803 | * @hw: Struct containing variables accessed by shared code |
| 4804 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4805 | static void e1000_clear_hw_cntrs(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4806 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4807 | volatile u32 temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4809 | temp = er32(CRCERRS); |
| 4810 | temp = er32(SYMERRS); |
| 4811 | temp = er32(MPC); |
| 4812 | temp = er32(SCC); |
| 4813 | temp = er32(ECOL); |
| 4814 | temp = er32(MCC); |
| 4815 | temp = er32(LATECOL); |
| 4816 | temp = er32(COLC); |
| 4817 | temp = er32(DC); |
| 4818 | temp = er32(SEC); |
| 4819 | temp = er32(RLEC); |
| 4820 | temp = er32(XONRXC); |
| 4821 | temp = er32(XONTXC); |
| 4822 | temp = er32(XOFFRXC); |
| 4823 | temp = er32(XOFFTXC); |
| 4824 | temp = er32(FCRUC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4825 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4826 | temp = er32(PRC64); |
| 4827 | temp = er32(PRC127); |
| 4828 | temp = er32(PRC255); |
| 4829 | temp = er32(PRC511); |
| 4830 | temp = er32(PRC1023); |
| 4831 | temp = er32(PRC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4832 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4833 | temp = er32(GPRC); |
| 4834 | temp = er32(BPRC); |
| 4835 | temp = er32(MPRC); |
| 4836 | temp = er32(GPTC); |
| 4837 | temp = er32(GORCL); |
| 4838 | temp = er32(GORCH); |
| 4839 | temp = er32(GOTCL); |
| 4840 | temp = er32(GOTCH); |
| 4841 | temp = er32(RNBC); |
| 4842 | temp = er32(RUC); |
| 4843 | temp = er32(RFC); |
| 4844 | temp = er32(ROC); |
| 4845 | temp = er32(RJC); |
| 4846 | temp = er32(TORL); |
| 4847 | temp = er32(TORH); |
| 4848 | temp = er32(TOTL); |
| 4849 | temp = er32(TOTH); |
| 4850 | temp = er32(TPR); |
| 4851 | temp = er32(TPT); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4852 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4853 | temp = er32(PTC64); |
| 4854 | temp = er32(PTC127); |
| 4855 | temp = er32(PTC255); |
| 4856 | temp = er32(PTC511); |
| 4857 | temp = er32(PTC1023); |
| 4858 | temp = er32(PTC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4859 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4860 | temp = er32(MPTC); |
| 4861 | temp = er32(BPTC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4863 | if (hw->mac_type < e1000_82543) |
| 4864 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4865 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4866 | temp = er32(ALGNERRC); |
| 4867 | temp = er32(RXERRC); |
| 4868 | temp = er32(TNCRS); |
| 4869 | temp = er32(CEXTERR); |
| 4870 | temp = er32(TSCTC); |
| 4871 | temp = er32(TSCTFC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4872 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4873 | if (hw->mac_type <= e1000_82544) |
| 4874 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4876 | temp = er32(MGTPRC); |
| 4877 | temp = er32(MGTPDC); |
| 4878 | temp = er32(MGTPTC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4879 | } |
| 4880 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4881 | /** |
| 4882 | * e1000_reset_adaptive - Resets Adaptive IFS to its default state. |
| 4883 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | * |
| 4885 | * 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] | 4886 | * hw->ifs_params_forced to true. However, you must initialize hw-> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio |
| 4888 | * before calling this function. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4889 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4890 | void e1000_reset_adaptive(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4891 | { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4892 | e_dbg("e1000_reset_adaptive"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4893 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4894 | if (hw->adaptive_ifs) { |
| 4895 | if (!hw->ifs_params_forced) { |
| 4896 | hw->current_ifs_val = 0; |
| 4897 | hw->ifs_min_val = IFS_MIN; |
| 4898 | hw->ifs_max_val = IFS_MAX; |
| 4899 | hw->ifs_step_size = IFS_STEP; |
| 4900 | hw->ifs_ratio = IFS_RATIO; |
| 4901 | } |
| 4902 | hw->in_ifs_mode = false; |
| 4903 | ew32(AIT, 0); |
| 4904 | } else { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4905 | e_dbg("Not in Adaptive IFS mode!\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4906 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | } |
| 4908 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4909 | /** |
| 4910 | * e1000_update_adaptive - update adaptive IFS |
| 4911 | * @hw: Struct containing variables accessed by shared code |
| 4912 | * @tx_packets: Number of transmits since last callback |
| 4913 | * @total_collisions: Number of collisions since last callback |
| 4914 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | * Called during the callback/watchdog routine to update IFS value based on |
| 4916 | * the ratio of transmits to collisions. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4917 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4918 | void e1000_update_adaptive(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4919 | { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4920 | e_dbg("e1000_update_adaptive"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4921 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4922 | if (hw->adaptive_ifs) { |
| 4923 | if ((hw->collision_delta *hw->ifs_ratio) > hw->tx_packet_delta) { |
| 4924 | if (hw->tx_packet_delta > MIN_NUM_XMITS) { |
| 4925 | hw->in_ifs_mode = true; |
| 4926 | if (hw->current_ifs_val < hw->ifs_max_val) { |
| 4927 | if (hw->current_ifs_val == 0) |
| 4928 | hw->current_ifs_val = |
| 4929 | hw->ifs_min_val; |
| 4930 | else |
| 4931 | hw->current_ifs_val += |
| 4932 | hw->ifs_step_size; |
| 4933 | ew32(AIT, hw->current_ifs_val); |
| 4934 | } |
| 4935 | } |
| 4936 | } else { |
| 4937 | if (hw->in_ifs_mode |
| 4938 | && (hw->tx_packet_delta <= MIN_NUM_XMITS)) { |
| 4939 | hw->current_ifs_val = 0; |
| 4940 | hw->in_ifs_mode = false; |
| 4941 | ew32(AIT, 0); |
| 4942 | } |
| 4943 | } |
| 4944 | } else { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 4945 | e_dbg("Not in Adaptive IFS mode!\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4946 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4947 | } |
| 4948 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4949 | /** |
| 4950 | * e1000_tbi_adjust_stats |
| 4951 | * @hw: Struct containing variables accessed by shared code |
| 4952 | * @frame_len: The length of the frame in question |
| 4953 | * @mac_addr: The Ethernet destination address of the frame in question |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4955 | * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT |
| 4956 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4957 | void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats, |
| 4958 | u32 frame_len, u8 *mac_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4959 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4960 | u64 carry_bit; |
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 | /* First adjust the frame length. */ |
| 4963 | frame_len--; |
| 4964 | /* We need to adjust the statistics counters, since the hardware |
| 4965 | * counters overcount this packet as a CRC error and undercount |
| 4966 | * the packet as a good packet |
| 4967 | */ |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 4968 | /* This packet should not be counted as a CRC error. */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4969 | stats->crcerrs--; |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 4970 | /* This packet does count as a Good Packet Received. */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4971 | stats->gprc++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 4973 | /* Adjust the Good Octets received counters */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4974 | carry_bit = 0x80000000 & stats->gorcl; |
| 4975 | stats->gorcl += frame_len; |
| 4976 | /* If the high bit of Gorcl (the low 32 bits of the Good Octets |
| 4977 | * Received Count) was one before the addition, |
| 4978 | * AND it is zero after, then we lost the carry out, |
| 4979 | * need to add one to Gorch (Good Octets Received Count High). |
| 4980 | * This could be simplified if all environments supported |
| 4981 | * 64-bit integers. |
| 4982 | */ |
| 4983 | if (carry_bit && ((stats->gorcl & 0x80000000) == 0)) |
| 4984 | stats->gorch++; |
| 4985 | /* Is this a broadcast or multicast? Check broadcast first, |
| 4986 | * since the test for a multicast frame will test positive on |
| 4987 | * a broadcast frame. |
| 4988 | */ |
| 4989 | if ((mac_addr[0] == (u8) 0xff) && (mac_addr[1] == (u8) 0xff)) |
| 4990 | /* Broadcast packet */ |
| 4991 | stats->bprc++; |
| 4992 | else if (*mac_addr & 0x01) |
| 4993 | /* Multicast packet */ |
| 4994 | stats->mprc++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4995 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4996 | if (frame_len == hw->max_frame_size) { |
| 4997 | /* In this case, the hardware has overcounted the number of |
| 4998 | * oversize frames. |
| 4999 | */ |
| 5000 | if (stats->roc > 0) |
| 5001 | stats->roc--; |
| 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 | /* Adjust the bin counters when the extra byte put the frame in the |
| 5005 | * wrong bin. Remember that the frame_len was adjusted above. |
| 5006 | */ |
| 5007 | if (frame_len == 64) { |
| 5008 | stats->prc64++; |
| 5009 | stats->prc127--; |
| 5010 | } else if (frame_len == 127) { |
| 5011 | stats->prc127++; |
| 5012 | stats->prc255--; |
| 5013 | } else if (frame_len == 255) { |
| 5014 | stats->prc255++; |
| 5015 | stats->prc511--; |
| 5016 | } else if (frame_len == 511) { |
| 5017 | stats->prc511++; |
| 5018 | stats->prc1023--; |
| 5019 | } else if (frame_len == 1023) { |
| 5020 | stats->prc1023++; |
| 5021 | stats->prc1522--; |
| 5022 | } else if (frame_len == 1522) { |
| 5023 | stats->prc1522++; |
| 5024 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5025 | } |
| 5026 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5027 | /** |
| 5028 | * e1000_get_bus_info |
| 5029 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5030 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5031 | * Gets the current PCI bus type, speed, and width of the hardware |
| 5032 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5033 | void e1000_get_bus_info(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5034 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5035 | u32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5036 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5037 | switch (hw->mac_type) { |
| 5038 | case e1000_82542_rev2_0: |
| 5039 | case e1000_82542_rev2_1: |
| 5040 | hw->bus_type = e1000_bus_type_pci; |
| 5041 | hw->bus_speed = e1000_bus_speed_unknown; |
| 5042 | hw->bus_width = e1000_bus_width_unknown; |
| 5043 | break; |
| 5044 | default: |
| 5045 | status = er32(STATUS); |
| 5046 | hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ? |
| 5047 | e1000_bus_type_pcix : e1000_bus_type_pci; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5048 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5049 | if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) { |
| 5050 | hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ? |
| 5051 | e1000_bus_speed_66 : e1000_bus_speed_120; |
| 5052 | } else if (hw->bus_type == e1000_bus_type_pci) { |
| 5053 | hw->bus_speed = (status & E1000_STATUS_PCI66) ? |
| 5054 | e1000_bus_speed_66 : e1000_bus_speed_33; |
| 5055 | } else { |
| 5056 | switch (status & E1000_STATUS_PCIX_SPEED) { |
| 5057 | case E1000_STATUS_PCIX_SPEED_66: |
| 5058 | hw->bus_speed = e1000_bus_speed_66; |
| 5059 | break; |
| 5060 | case E1000_STATUS_PCIX_SPEED_100: |
| 5061 | hw->bus_speed = e1000_bus_speed_100; |
| 5062 | break; |
| 5063 | case E1000_STATUS_PCIX_SPEED_133: |
| 5064 | hw->bus_speed = e1000_bus_speed_133; |
| 5065 | break; |
| 5066 | default: |
| 5067 | hw->bus_speed = e1000_bus_speed_reserved; |
| 5068 | break; |
| 5069 | } |
| 5070 | } |
| 5071 | hw->bus_width = (status & E1000_STATUS_BUS64) ? |
| 5072 | e1000_bus_width_64 : e1000_bus_width_32; |
| 5073 | break; |
| 5074 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5075 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5076 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5077 | /** |
| 5078 | * e1000_write_reg_io |
| 5079 | * @hw: Struct containing variables accessed by shared code |
| 5080 | * @offset: offset to write to |
| 5081 | * @value: value to write |
| 5082 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5083 | * Writes a value to one of the devices registers using port I/O (as opposed to |
| 5084 | * 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] | 5085 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5086 | 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] | 5087 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5088 | unsigned long io_addr = hw->io_base; |
| 5089 | unsigned long io_data = hw->io_base + 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5090 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5091 | e1000_io_write(hw, io_addr, offset); |
| 5092 | e1000_io_write(hw, io_data, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5093 | } |
| 5094 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5095 | /** |
| 5096 | * e1000_get_cable_length - Estimates the cable length. |
| 5097 | * @hw: Struct containing variables accessed by shared code |
| 5098 | * @min_length: The estimated minimum length |
| 5099 | * @max_length: The estimated maximum length |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5100 | * |
| 5101 | * returns: - E1000_ERR_XXX |
| 5102 | * E1000_SUCCESS |
| 5103 | * |
| 5104 | * This function always returns a ranged length (minimum & maximum). |
| 5105 | * So for M88 phy's, this function interprets the one value returned from the |
| 5106 | * register to the minimum and maximum range. |
| 5107 | * 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] | 5108 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5109 | static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length, |
| 5110 | u16 *max_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5111 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5112 | s32 ret_val; |
| 5113 | u16 agc_value = 0; |
| 5114 | u16 i, phy_data; |
| 5115 | u16 cable_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5116 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5117 | e_dbg("e1000_get_cable_length"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5118 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5119 | *min_length = *max_length = 0; |
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 | /* Use old method for Phy older than IGP */ |
| 5122 | if (hw->phy_type == e1000_phy_m88) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5123 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5124 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 5125 | &phy_data); |
| 5126 | if (ret_val) |
| 5127 | return ret_val; |
| 5128 | cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >> |
| 5129 | M88E1000_PSSR_CABLE_LENGTH_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5130 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5131 | /* Convert the enum value to ranged values */ |
| 5132 | switch (cable_length) { |
| 5133 | case e1000_cable_length_50: |
| 5134 | *min_length = 0; |
| 5135 | *max_length = e1000_igp_cable_length_50; |
| 5136 | break; |
| 5137 | case e1000_cable_length_50_80: |
| 5138 | *min_length = e1000_igp_cable_length_50; |
| 5139 | *max_length = e1000_igp_cable_length_80; |
| 5140 | break; |
| 5141 | case e1000_cable_length_80_110: |
| 5142 | *min_length = e1000_igp_cable_length_80; |
| 5143 | *max_length = e1000_igp_cable_length_110; |
| 5144 | break; |
| 5145 | case e1000_cable_length_110_140: |
| 5146 | *min_length = e1000_igp_cable_length_110; |
| 5147 | *max_length = e1000_igp_cable_length_140; |
| 5148 | break; |
| 5149 | case e1000_cable_length_140: |
| 5150 | *min_length = e1000_igp_cable_length_140; |
| 5151 | *max_length = e1000_igp_cable_length_170; |
| 5152 | break; |
| 5153 | default: |
| 5154 | return -E1000_ERR_PHY; |
| 5155 | break; |
| 5156 | } |
| 5157 | } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */ |
| 5158 | u16 cur_agc_value; |
| 5159 | u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE; |
Jeff Kirsher | 6674450 | 2010-12-01 19:59:50 +0000 | [diff] [blame] | 5160 | static const u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = { |
| 5161 | IGP01E1000_PHY_AGC_A, |
| 5162 | IGP01E1000_PHY_AGC_B, |
| 5163 | IGP01E1000_PHY_AGC_C, |
| 5164 | IGP01E1000_PHY_AGC_D |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5165 | }; |
| 5166 | /* Read the AGC registers for all channels */ |
| 5167 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5168 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5169 | ret_val = |
| 5170 | e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data); |
| 5171 | if (ret_val) |
| 5172 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5173 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5174 | cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5175 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5176 | /* Value bound check. */ |
| 5177 | if ((cur_agc_value >= |
| 5178 | IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) |
| 5179 | || (cur_agc_value == 0)) |
| 5180 | return -E1000_ERR_PHY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5181 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5182 | agc_value += cur_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5183 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5184 | /* Update minimal AGC value. */ |
| 5185 | if (min_agc_value > cur_agc_value) |
| 5186 | min_agc_value = cur_agc_value; |
| 5187 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5188 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5189 | /* Remove the minimal AGC result for length < 50m */ |
| 5190 | if (agc_value < |
| 5191 | IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) { |
| 5192 | agc_value -= min_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5193 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5194 | /* Get the average length of the remaining 3 channels */ |
| 5195 | agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1); |
| 5196 | } else { |
| 5197 | /* Get the average length of all the 4 channels. */ |
| 5198 | agc_value /= IGP01E1000_PHY_CHANNEL_NUM; |
| 5199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5200 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5201 | /* Set the range of the calculated length. */ |
| 5202 | *min_length = ((e1000_igp_cable_length_table[agc_value] - |
| 5203 | IGP01E1000_AGC_RANGE) > 0) ? |
| 5204 | (e1000_igp_cable_length_table[agc_value] - |
| 5205 | IGP01E1000_AGC_RANGE) : 0; |
| 5206 | *max_length = e1000_igp_cable_length_table[agc_value] + |
| 5207 | IGP01E1000_AGC_RANGE; |
| 5208 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5209 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5210 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5211 | } |
| 5212 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5213 | /** |
| 5214 | * e1000_check_polarity - Check the cable polarity |
| 5215 | * @hw: Struct containing variables accessed by shared code |
| 5216 | * @polarity: output parameter : 0 - Polarity is not reversed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5217 | * 1 - Polarity is reversed. |
| 5218 | * |
| 5219 | * returns: - E1000_ERR_XXX |
| 5220 | * E1000_SUCCESS |
| 5221 | * |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 5222 | * 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] | 5223 | * Phy Status register. For IGP phy's, this bit is valid only if link speed is |
| 5224 | * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will |
| 5225 | * return 0. If the link speed is 1000 Mbps the polarity status is in the |
| 5226 | * IGP01E1000_PHY_PCS_INIT_REG. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5227 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5228 | static s32 e1000_check_polarity(struct e1000_hw *hw, |
| 5229 | e1000_rev_polarity *polarity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5230 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5231 | s32 ret_val; |
| 5232 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5233 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5234 | e_dbg("e1000_check_polarity"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5235 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5236 | if (hw->phy_type == e1000_phy_m88) { |
| 5237 | /* return the Polarity bit in the Status register. */ |
| 5238 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 5239 | &phy_data); |
| 5240 | if (ret_val) |
| 5241 | return ret_val; |
| 5242 | *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >> |
| 5243 | M88E1000_PSSR_REV_POLARITY_SHIFT) ? |
| 5244 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 5245 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5246 | } else if (hw->phy_type == e1000_phy_igp) { |
| 5247 | /* Read the Status register to check the speed */ |
| 5248 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, |
| 5249 | &phy_data); |
| 5250 | if (ret_val) |
| 5251 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5252 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 5253 | /* If speed is 1000 Mbps, must read the |
| 5254 | * IGP01E1000_PHY_PCS_INIT_REG to find the polarity status |
| 5255 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5256 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == |
| 5257 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5258 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5259 | /* Read the GIG initialization PCS register (0x00B4) */ |
| 5260 | ret_val = |
| 5261 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG, |
| 5262 | &phy_data); |
| 5263 | if (ret_val) |
| 5264 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5265 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5266 | /* Check the polarity bits */ |
| 5267 | *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? |
| 5268 | e1000_rev_polarity_reversed : |
| 5269 | e1000_rev_polarity_normal; |
| 5270 | } else { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 5271 | /* For 10 Mbps, read the polarity bit in the status |
| 5272 | * register. (for 100 Mbps this bit is always 0) |
| 5273 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5274 | *polarity = |
| 5275 | (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ? |
| 5276 | e1000_rev_polarity_reversed : |
| 5277 | e1000_rev_polarity_normal; |
| 5278 | } |
| 5279 | } |
| 5280 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5281 | } |
| 5282 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5283 | /** |
| 5284 | * e1000_check_downshift - Check if Downshift occurred |
| 5285 | * @hw: Struct containing variables accessed by shared code |
| 5286 | * @downshift: output parameter : 0 - No Downshift occurred. |
| 5287 | * 1 - Downshift occurred. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5288 | * |
| 5289 | * returns: - E1000_ERR_XXX |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5290 | * E1000_SUCCESS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5291 | * |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 5292 | * 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] | 5293 | * Specific Status register. For IGP phy's, it reads the Downgrade bit in the |
| 5294 | * Link Health register. In IGP this bit is latched high, so the driver must |
| 5295 | * read it immediately after link is established. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5296 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5297 | static s32 e1000_check_downshift(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5298 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5299 | s32 ret_val; |
| 5300 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5301 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5302 | e_dbg("e1000_check_downshift"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5303 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5304 | if (hw->phy_type == e1000_phy_igp) { |
| 5305 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH, |
| 5306 | &phy_data); |
| 5307 | if (ret_val) |
| 5308 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5309 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5310 | hw->speed_downgraded = |
| 5311 | (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0; |
| 5312 | } else if (hw->phy_type == e1000_phy_m88) { |
| 5313 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 5314 | &phy_data); |
| 5315 | if (ret_val) |
| 5316 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5317 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5318 | hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >> |
| 5319 | M88E1000_PSSR_DOWNSHIFT_SHIFT; |
| 5320 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5321 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5322 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5323 | } |
| 5324 | |
Joe Perches | 542c3f4 | 2012-02-10 12:07:36 +0000 | [diff] [blame] | 5325 | static const u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = { |
| 5326 | IGP01E1000_PHY_AGC_PARAM_A, |
| 5327 | IGP01E1000_PHY_AGC_PARAM_B, |
| 5328 | IGP01E1000_PHY_AGC_PARAM_C, |
| 5329 | IGP01E1000_PHY_AGC_PARAM_D |
| 5330 | }; |
| 5331 | |
| 5332 | static s32 e1000_1000Mb_check_cable_length(struct e1000_hw *hw) |
| 5333 | { |
| 5334 | u16 min_length, max_length; |
| 5335 | u16 phy_data, i; |
| 5336 | s32 ret_val; |
| 5337 | |
| 5338 | ret_val = e1000_get_cable_length(hw, &min_length, &max_length); |
| 5339 | if (ret_val) |
| 5340 | return ret_val; |
| 5341 | |
| 5342 | if (hw->dsp_config_state != e1000_dsp_config_enabled) |
| 5343 | return 0; |
| 5344 | |
| 5345 | if (min_length >= e1000_igp_cable_length_50) { |
| 5346 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
| 5347 | ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], |
| 5348 | &phy_data); |
| 5349 | if (ret_val) |
| 5350 | return ret_val; |
| 5351 | |
| 5352 | phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX; |
| 5353 | |
| 5354 | ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i], |
| 5355 | phy_data); |
| 5356 | if (ret_val) |
| 5357 | return ret_val; |
| 5358 | } |
| 5359 | hw->dsp_config_state = e1000_dsp_config_activated; |
| 5360 | } else { |
| 5361 | u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20; |
| 5362 | u32 idle_errs = 0; |
| 5363 | |
| 5364 | /* clear previous idle error counts */ |
| 5365 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); |
| 5366 | if (ret_val) |
| 5367 | return ret_val; |
| 5368 | |
| 5369 | for (i = 0; i < ffe_idle_err_timeout; i++) { |
| 5370 | udelay(1000); |
| 5371 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, |
| 5372 | &phy_data); |
| 5373 | if (ret_val) |
| 5374 | return ret_val; |
| 5375 | |
| 5376 | idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT); |
| 5377 | if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) { |
| 5378 | hw->ffe_config_state = e1000_ffe_config_active; |
| 5379 | |
| 5380 | ret_val = e1000_write_phy_reg(hw, |
| 5381 | IGP01E1000_PHY_DSP_FFE, |
| 5382 | IGP01E1000_PHY_DSP_FFE_CM_CP); |
| 5383 | if (ret_val) |
| 5384 | return ret_val; |
| 5385 | break; |
| 5386 | } |
| 5387 | |
| 5388 | if (idle_errs) |
| 5389 | ffe_idle_err_timeout = |
| 5390 | FFE_IDLE_ERR_COUNT_TIMEOUT_100; |
| 5391 | } |
| 5392 | } |
| 5393 | |
| 5394 | return 0; |
| 5395 | } |
| 5396 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5397 | /** |
| 5398 | * e1000_config_dsp_after_link_change |
| 5399 | * @hw: Struct containing variables accessed by shared code |
| 5400 | * @link_up: was link up at the time this was called |
| 5401 | * |
| 5402 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 5403 | * E1000_SUCCESS at any other case. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5404 | * |
| 5405 | * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a |
| 5406 | * gigabit link is achieved to improve link quality. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5407 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5408 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5409 | 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] | 5410 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5411 | s32 ret_val; |
| 5412 | u16 phy_data, phy_saved_data, speed, duplex, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5413 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5414 | e_dbg("e1000_config_dsp_after_link_change"); |
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 (hw->phy_type != e1000_phy_igp) |
| 5417 | return E1000_SUCCESS; |
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 | if (link_up) { |
| 5420 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); |
| 5421 | if (ret_val) { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5422 | e_dbg("Error getting link speed and duplex\n"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5423 | return ret_val; |
| 5424 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5425 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5426 | if (speed == SPEED_1000) { |
Joe Perches | 542c3f4 | 2012-02-10 12:07:36 +0000 | [diff] [blame] | 5427 | ret_val = e1000_1000Mb_check_cable_length(hw); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5428 | if (ret_val) |
| 5429 | return ret_val; |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5430 | } |
| 5431 | } else { |
| 5432 | if (hw->dsp_config_state == e1000_dsp_config_activated) { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 5433 | /* Save off the current value of register 0x2F5B to be |
| 5434 | * restored at the end of the routines. |
| 5435 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5436 | ret_val = |
| 5437 | e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
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 | if (ret_val) |
| 5440 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5441 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5442 | /* Disable the PHY transmitter */ |
| 5443 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5444 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5445 | if (ret_val) |
| 5446 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5447 | |
Jesse Brandeburg | 4e0d8f7d | 2011-10-05 07:24:46 +0000 | [diff] [blame] | 5448 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5449 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5450 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 5451 | IGP01E1000_IEEE_FORCE_GIGA); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5452 | if (ret_val) |
| 5453 | return ret_val; |
| 5454 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
| 5455 | ret_val = |
| 5456 | e1000_read_phy_reg(hw, dsp_reg_array[i], |
| 5457 | &phy_data); |
| 5458 | if (ret_val) |
| 5459 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5460 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5461 | phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX; |
| 5462 | phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5463 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5464 | ret_val = |
| 5465 | e1000_write_phy_reg(hw, dsp_reg_array[i], |
| 5466 | phy_data); |
| 5467 | if (ret_val) |
| 5468 | return ret_val; |
| 5469 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5470 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5471 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 5472 | IGP01E1000_IEEE_RESTART_AUTONEG); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5473 | if (ret_val) |
| 5474 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5475 | |
Jesse Brandeburg | 4e0d8f7d | 2011-10-05 07:24:46 +0000 | [diff] [blame] | 5476 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5477 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5478 | /* Now enable the transmitter */ |
| 5479 | ret_val = |
| 5480 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5481 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5482 | if (ret_val) |
| 5483 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5484 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5485 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 5486 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5488 | if (hw->ffe_config_state == e1000_ffe_config_active) { |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 5489 | /* Save off the current value of register 0x2F5B to be |
| 5490 | * restored at the end of the routines. |
| 5491 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5492 | ret_val = |
| 5493 | e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5494 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5495 | if (ret_val) |
| 5496 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5497 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5498 | /* Disable the PHY transmitter */ |
| 5499 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5500 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5501 | if (ret_val) |
| 5502 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5503 | |
Jesse Brandeburg | 4e0d8f7d | 2011-10-05 07:24:46 +0000 | [diff] [blame] | 5504 | msleep(20); |
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 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 5507 | IGP01E1000_IEEE_FORCE_GIGA); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5508 | if (ret_val) |
| 5509 | return ret_val; |
| 5510 | ret_val = |
| 5511 | e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE, |
| 5512 | IGP01E1000_PHY_DSP_FFE_DEFAULT); |
| 5513 | if (ret_val) |
| 5514 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5515 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5516 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 5517 | IGP01E1000_IEEE_RESTART_AUTONEG); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5518 | if (ret_val) |
| 5519 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5520 | |
Jesse Brandeburg | 4e0d8f7d | 2011-10-05 07:24:46 +0000 | [diff] [blame] | 5521 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5522 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5523 | /* Now enable the transmitter */ |
| 5524 | ret_val = |
| 5525 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5526 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5527 | if (ret_val) |
| 5528 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5529 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5530 | hw->ffe_config_state = e1000_ffe_config_enabled; |
| 5531 | } |
| 5532 | } |
| 5533 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5534 | } |
| 5535 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5536 | /** |
| 5537 | * e1000_set_phy_mode - Set PHY to class A mode |
| 5538 | * @hw: Struct containing variables accessed by shared code |
| 5539 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5540 | * Assumes the following operations will follow to enable the new class mode. |
| 5541 | * 1. Do a PHY soft reset |
| 5542 | * 2. Restart auto-negotiation or force link. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5543 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5544 | static s32 e1000_set_phy_mode(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5545 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5546 | s32 ret_val; |
| 5547 | u16 eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5548 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5549 | e_dbg("e1000_set_phy_mode"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5550 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5551 | if ((hw->mac_type == e1000_82545_rev_3) && |
| 5552 | (hw->media_type == e1000_media_type_copper)) { |
| 5553 | ret_val = |
| 5554 | e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, |
| 5555 | &eeprom_data); |
| 5556 | if (ret_val) { |
| 5557 | return ret_val; |
| 5558 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5559 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5560 | if ((eeprom_data != EEPROM_RESERVED_WORD) && |
| 5561 | (eeprom_data & EEPROM_PHY_CLASS_A)) { |
| 5562 | ret_val = |
| 5563 | e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, |
| 5564 | 0x000B); |
| 5565 | if (ret_val) |
| 5566 | return ret_val; |
| 5567 | ret_val = |
| 5568 | e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, |
| 5569 | 0x8104); |
| 5570 | if (ret_val) |
| 5571 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5572 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5573 | hw->phy_reset_disable = false; |
| 5574 | } |
| 5575 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5576 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5577 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5578 | } |
| 5579 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5580 | /** |
| 5581 | * e1000_set_d3_lplu_state - set d3 link power state |
| 5582 | * @hw: Struct containing variables accessed by shared code |
| 5583 | * @active: true to enable lplu false to disable lplu. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5584 | * |
| 5585 | * This function sets the lplu state according to the active flag. When |
| 5586 | * activating lplu this function also disables smart speed and vise versa. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5587 | * lplu will not be activated unless the device autonegotiation advertisement |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5588 | * 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] | 5589 | * |
| 5590 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 5591 | * E1000_SUCCESS at any other case. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5592 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5593 | 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] | 5594 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5595 | s32 ret_val; |
| 5596 | u16 phy_data; |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5597 | e_dbg("e1000_set_d3_lplu_state"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5598 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5599 | if (hw->phy_type != e1000_phy_igp) |
| 5600 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5601 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5602 | /* During driver activity LPLU should not be used or it will attain link |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 5603 | * from the lowest speeds starting from 10Mbps. The capability is used |
| 5604 | * for Dx transitions and states |
| 5605 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5606 | if (hw->mac_type == e1000_82541_rev_2 |
| 5607 | || hw->mac_type == e1000_82547_rev_2) { |
| 5608 | ret_val = |
| 5609 | e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data); |
| 5610 | if (ret_val) |
| 5611 | return ret_val; |
| 5612 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5613 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5614 | if (!active) { |
| 5615 | if (hw->mac_type == e1000_82541_rev_2 || |
| 5616 | hw->mac_type == e1000_82547_rev_2) { |
| 5617 | phy_data &= ~IGP01E1000_GMII_FLEX_SPD; |
| 5618 | ret_val = |
| 5619 | e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 5620 | phy_data); |
| 5621 | if (ret_val) |
| 5622 | return ret_val; |
| 5623 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5624 | |
Jeff Kirsher | 6cfbd97 | 2013-02-09 12:49:21 +0000 | [diff] [blame^] | 5625 | /* LPLU and SmartSpeed are mutually exclusive. LPLU is used |
| 5626 | * during Dx states where the power conservation is most |
| 5627 | * important. During driver activity we should enable |
| 5628 | * SmartSpeed, so performance is maintained. |
| 5629 | */ |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5630 | if (hw->smart_speed == e1000_smart_speed_on) { |
| 5631 | ret_val = |
| 5632 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5633 | &phy_data); |
| 5634 | if (ret_val) |
| 5635 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5636 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5637 | phy_data |= IGP01E1000_PSCFR_SMART_SPEED; |
| 5638 | ret_val = |
| 5639 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5640 | phy_data); |
| 5641 | if (ret_val) |
| 5642 | return ret_val; |
| 5643 | } else if (hw->smart_speed == e1000_smart_speed_off) { |
| 5644 | ret_val = |
| 5645 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5646 | &phy_data); |
| 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 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 5651 | ret_val = |
| 5652 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5653 | phy_data); |
| 5654 | if (ret_val) |
| 5655 | return ret_val; |
| 5656 | } |
| 5657 | } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) |
| 5658 | || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) |
| 5659 | || (hw->autoneg_advertised == |
| 5660 | AUTONEG_ADVERTISE_10_100_ALL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5661 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5662 | if (hw->mac_type == e1000_82541_rev_2 || |
| 5663 | hw->mac_type == e1000_82547_rev_2) { |
| 5664 | phy_data |= IGP01E1000_GMII_FLEX_SPD; |
| 5665 | ret_val = |
| 5666 | e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 5667 | phy_data); |
| 5668 | if (ret_val) |
| 5669 | return ret_val; |
| 5670 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5671 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5672 | /* When LPLU is enabled we should disable SmartSpeed */ |
| 5673 | ret_val = |
| 5674 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5675 | &phy_data); |
| 5676 | if (ret_val) |
| 5677 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5678 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5679 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 5680 | ret_val = |
| 5681 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 5682 | phy_data); |
| 5683 | if (ret_val) |
| 5684 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5685 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5686 | } |
| 5687 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5688 | } |
| 5689 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5690 | /** |
| 5691 | * e1000_set_vco_speed |
| 5692 | * @hw: Struct containing variables accessed by shared code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5693 | * |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5694 | * Change VCO speed register to improve Bit Error Rate performance of SERDES. |
| 5695 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5696 | static s32 e1000_set_vco_speed(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5697 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5698 | s32 ret_val; |
| 5699 | u16 default_page = 0; |
| 5700 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5701 | |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5702 | e_dbg("e1000_set_vco_speed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5703 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5704 | switch (hw->mac_type) { |
| 5705 | case e1000_82545_rev_3: |
| 5706 | case e1000_82546_rev_3: |
| 5707 | break; |
| 5708 | default: |
| 5709 | return E1000_SUCCESS; |
| 5710 | } |
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 | /* Set PHY register 30, page 5, bit 8 to 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5713 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5714 | ret_val = |
| 5715 | e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page); |
| 5716 | if (ret_val) |
| 5717 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5718 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5719 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005); |
| 5720 | if (ret_val) |
| 5721 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5722 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5723 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data); |
| 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 | phy_data &= ~M88E1000_PHY_VCO_REG_BIT8; |
| 5728 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data); |
| 5729 | if (ret_val) |
| 5730 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5731 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5732 | /* Set PHY register 30, page 4, bit 11 to 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5733 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5734 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004); |
| 5735 | if (ret_val) |
| 5736 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5737 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5738 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data); |
| 5739 | if (ret_val) |
| 5740 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5741 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5742 | phy_data |= M88E1000_PHY_VCO_REG_BIT11; |
| 5743 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data); |
| 5744 | if (ret_val) |
| 5745 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5746 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5747 | ret_val = |
| 5748 | e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page); |
| 5749 | if (ret_val) |
| 5750 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5751 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5752 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5753 | } |
| 5754 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5755 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5756 | /** |
| 5757 | * e1000_enable_mng_pass_thru - check for bmc pass through |
| 5758 | * @hw: Struct containing variables accessed by shared code |
| 5759 | * |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5760 | * 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] | 5761 | * returns: - true/false |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5762 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5763 | u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5764 | { |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5765 | u32 manc; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5766 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5767 | if (hw->asf_firmware_present) { |
| 5768 | manc = er32(MANC); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5769 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5770 | if (!(manc & E1000_MANC_RCV_TCO_EN) || |
| 5771 | !(manc & E1000_MANC_EN_MAC_ADDR_FILTER)) |
| 5772 | return false; |
| 5773 | if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN)) |
| 5774 | return true; |
| 5775 | } |
| 5776 | return false; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5777 | } |
| 5778 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5779 | static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw) |
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 | s32 ret_val; |
| 5782 | u16 mii_status_reg; |
| 5783 | u16 i; |
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 | /* Polarity reversal workaround for forced 10F/10H links. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5786 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5787 | /* Disable the transmitter on the PHY */ |
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 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); |
| 5790 | if (ret_val) |
| 5791 | return ret_val; |
| 5792 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF); |
| 5793 | if (ret_val) |
| 5794 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5795 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5796 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); |
| 5797 | if (ret_val) |
| 5798 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5799 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5800 | /* This loop will early-out if the NO link condition has been met. */ |
| 5801 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
| 5802 | /* Read the MII Status Register and wait for Link Status bit |
| 5803 | * to be clear. |
| 5804 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5805 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5806 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 5807 | if (ret_val) |
| 5808 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5809 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5810 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 5811 | if (ret_val) |
| 5812 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5813 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5814 | if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) |
| 5815 | break; |
Jesse Brandeburg | 4e0d8f7d | 2011-10-05 07:24:46 +0000 | [diff] [blame] | 5816 | msleep(100); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5817 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5818 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5819 | /* Recommended delay time after link has been lost */ |
Jesse Brandeburg | 4e0d8f7d | 2011-10-05 07:24:46 +0000 | [diff] [blame] | 5820 | msleep(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5821 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5822 | /* Now we will re-enable th transmitter on the PHY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5823 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5824 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); |
| 5825 | if (ret_val) |
| 5826 | return ret_val; |
Jesse Brandeburg | 4e0d8f7d | 2011-10-05 07:24:46 +0000 | [diff] [blame] | 5827 | msleep(50); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5828 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0); |
| 5829 | if (ret_val) |
| 5830 | return ret_val; |
Jesse Brandeburg | 4e0d8f7d | 2011-10-05 07:24:46 +0000 | [diff] [blame] | 5831 | msleep(50); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5832 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00); |
| 5833 | if (ret_val) |
| 5834 | return ret_val; |
Jesse Brandeburg | 4e0d8f7d | 2011-10-05 07:24:46 +0000 | [diff] [blame] | 5835 | msleep(50); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5836 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000); |
| 5837 | if (ret_val) |
| 5838 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5839 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5840 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); |
| 5841 | if (ret_val) |
| 5842 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5843 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5844 | /* This loop will early-out if the link condition has been met. */ |
| 5845 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
| 5846 | /* Read the MII Status Register and wait for Link Status bit |
| 5847 | * to be set. |
| 5848 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5849 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5850 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 5851 | if (ret_val) |
| 5852 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5853 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5854 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
| 5855 | if (ret_val) |
| 5856 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5857 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5858 | if (mii_status_reg & MII_SR_LINK_STATUS) |
| 5859 | break; |
Jesse Brandeburg | 4e0d8f7d | 2011-10-05 07:24:46 +0000 | [diff] [blame] | 5860 | msleep(100); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5861 | } |
| 5862 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5863 | } |
| 5864 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5865 | /** |
| 5866 | * e1000_get_auto_rd_done |
| 5867 | * @hw: Struct containing variables accessed by shared code |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5868 | * |
| 5869 | * Check for EEPROM Auto Read bit done. |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5870 | * returns: - E1000_ERR_RESET if fail to reset MAC |
| 5871 | * E1000_SUCCESS at any other case. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5872 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5873 | static s32 e1000_get_auto_rd_done(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5874 | { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5875 | e_dbg("e1000_get_auto_rd_done"); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5876 | msleep(5); |
| 5877 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5878 | } |
| 5879 | |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5880 | /** |
| 5881 | * e1000_get_phy_cfg_done |
| 5882 | * @hw: Struct containing variables accessed by shared code |
| 5883 | * |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5884 | * Checks if the PHY configuration is done |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5885 | * returns: - E1000_ERR_RESET if fail to reset MAC |
| 5886 | * E1000_SUCCESS at any other case. |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5887 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5888 | static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5889 | { |
Emil Tantilov | 675ad47 | 2010-04-27 14:02:58 +0000 | [diff] [blame] | 5890 | e_dbg("e1000_get_phy_cfg_done"); |
Jesse Brandeburg | 4e0d8f7d | 2011-10-05 07:24:46 +0000 | [diff] [blame] | 5891 | msleep(10); |
Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5892 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5893 | } |