| 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 |  | 
|  | 33 | #include "e1000_hw.h" | 
|  | 34 |  | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 35 | static s32 e1000_check_downshift(struct e1000_hw *hw); | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 36 | static s32 e1000_check_polarity(struct e1000_hw *hw, | 
|  | 37 | e1000_rev_polarity *polarity); | 
| Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 38 | static void e1000_clear_hw_cntrs(struct e1000_hw *hw); | 
|  | 39 | static void e1000_clear_vfta(struct e1000_hw *hw); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 40 | static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 41 | bool link_up); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 42 | static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw); | 
|  | 43 | static s32 e1000_detect_gig_phy(struct e1000_hw *hw); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 44 | static s32 e1000_get_auto_rd_done(struct e1000_hw *hw); | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 45 | static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length, | 
|  | 46 | u16 *max_length); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 47 | static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 48 | static s32 e1000_id_led_init(struct e1000_hw *hw); | 
| Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 49 | static void e1000_init_rx_addrs(struct e1000_hw *hw); | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 50 | static s32 e1000_phy_igp_get_info(struct e1000_hw *hw, | 
|  | 51 | struct e1000_phy_info *phy_info); | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 52 | static s32 e1000_phy_m88_get_info(struct e1000_hw *hw, | 
|  | 53 | struct e1000_phy_info *phy_info); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 54 | static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 55 | static s32 e1000_wait_autoneg(struct e1000_hw *hw); | 
|  | 56 | static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value); | 
|  | 57 | static s32 e1000_set_phy_type(struct e1000_hw *hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | static void e1000_phy_init_script(struct e1000_hw *hw); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 59 | static s32 e1000_setup_copper_link(struct e1000_hw *hw); | 
|  | 60 | static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw); | 
|  | 61 | static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw); | 
|  | 62 | static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw); | 
|  | 63 | static s32 e1000_config_mac_to_phy(struct e1000_hw *hw); | 
|  | 64 | static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl); | 
|  | 65 | static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 66 | static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 67 | static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw); | 
|  | 68 | static s32 e1000_phy_reset_dsp(struct e1000_hw *hw); | 
|  | 69 | static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 70 | u16 words, u16 *data); | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 71 | static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset, | 
|  | 72 | u16 words, u16 *data); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 73 | static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw); | 
|  | 74 | static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd); | 
|  | 75 | static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd); | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 76 | static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 77 | static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 78 | u16 phy_data); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 79 | static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 80 | u16 *phy_data); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 81 | static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count); | 
|  | 82 | static s32 e1000_acquire_eeprom(struct e1000_hw *hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | static void e1000_release_eeprom(struct e1000_hw *hw); | 
|  | 84 | static void e1000_standby_eeprom(struct e1000_hw *hw); | 
| Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 85 | static s32 e1000_set_vco_speed(struct e1000_hw *hw); | 
|  | 86 | static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw); | 
|  | 87 | static s32 e1000_set_phy_mode(struct e1000_hw *hw); | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 88 | static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, | 
|  | 89 | u16 *data); | 
|  | 90 | static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, | 
|  | 91 | u16 *data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 |  | 
|  | 93 | /* IGP cable length table */ | 
|  | 94 | static const | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 95 | u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = { | 
|  | 96 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | 
|  | 97 | 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25, | 
|  | 98 | 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40, | 
|  | 99 | 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, | 
|  | 100 | 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90, | 
|  | 101 | 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, | 
|  | 102 | 100, | 
|  | 103 | 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, | 
|  | 104 | 110, 110, | 
|  | 105 | 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, | 
|  | 106 | 120, 120 | 
|  | 107 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 |  | 
| Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 109 | static DEFINE_SPINLOCK(e1000_eeprom_lock); | 
|  | 110 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 111 | /** | 
|  | 112 | * e1000_set_phy_type - Set the phy type member in the hw struct. | 
|  | 113 | * @hw: Struct containing variables accessed by shared code | 
|  | 114 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 115 | static s32 e1000_set_phy_type(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 117 | DEBUGFUNC("e1000_set_phy_type"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 119 | if (hw->mac_type == e1000_undefined) | 
|  | 120 | return -E1000_ERR_PHY_TYPE; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 121 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 122 | switch (hw->phy_id) { | 
|  | 123 | case M88E1000_E_PHY_ID: | 
|  | 124 | case M88E1000_I_PHY_ID: | 
|  | 125 | case M88E1011_I_PHY_ID: | 
|  | 126 | case M88E1111_I_PHY_ID: | 
|  | 127 | hw->phy_type = e1000_phy_m88; | 
|  | 128 | break; | 
|  | 129 | case IGP01E1000_I_PHY_ID: | 
|  | 130 | if (hw->mac_type == e1000_82541 || | 
|  | 131 | hw->mac_type == e1000_82541_rev_2 || | 
|  | 132 | hw->mac_type == e1000_82547 || | 
|  | 133 | hw->mac_type == e1000_82547_rev_2) { | 
|  | 134 | hw->phy_type = e1000_phy_igp; | 
|  | 135 | break; | 
|  | 136 | } | 
|  | 137 | default: | 
|  | 138 | /* Should never have loaded on this device */ | 
|  | 139 | hw->phy_type = e1000_phy_undefined; | 
|  | 140 | return -E1000_ERR_PHY_TYPE; | 
|  | 141 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 143 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } | 
|  | 145 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 146 | /** | 
|  | 147 | * e1000_phy_init_script - IGP phy init script - initializes the GbE PHY | 
|  | 148 | * @hw: Struct containing variables accessed by shared code | 
|  | 149 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 150 | static void e1000_phy_init_script(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 152 | u32 ret_val; | 
|  | 153 | u16 phy_saved_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 155 | DEBUGFUNC("e1000_phy_init_script"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 157 | if (hw->phy_init_script) { | 
|  | 158 | msleep(20); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 160 | /* Save off the current value of register 0x2F5B to be restored at | 
|  | 161 | * the end of this routine. */ | 
|  | 162 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); | 
| 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 | /* Disabled the PHY transmitter */ | 
|  | 165 | e1000_write_phy_reg(hw, 0x2F5B, 0x0003); | 
|  | 166 | msleep(20); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 168 | e1000_write_phy_reg(hw, 0x0000, 0x0140); | 
|  | 169 | msleep(5); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 171 | switch (hw->mac_type) { | 
|  | 172 | case e1000_82541: | 
|  | 173 | case e1000_82547: | 
|  | 174 | e1000_write_phy_reg(hw, 0x1F95, 0x0001); | 
|  | 175 | e1000_write_phy_reg(hw, 0x1F71, 0xBD21); | 
|  | 176 | e1000_write_phy_reg(hw, 0x1F79, 0x0018); | 
|  | 177 | e1000_write_phy_reg(hw, 0x1F30, 0x1600); | 
|  | 178 | e1000_write_phy_reg(hw, 0x1F31, 0x0014); | 
|  | 179 | e1000_write_phy_reg(hw, 0x1F32, 0x161C); | 
|  | 180 | e1000_write_phy_reg(hw, 0x1F94, 0x0003); | 
|  | 181 | e1000_write_phy_reg(hw, 0x1F96, 0x003F); | 
|  | 182 | e1000_write_phy_reg(hw, 0x2010, 0x0008); | 
|  | 183 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 185 | case e1000_82541_rev_2: | 
|  | 186 | case e1000_82547_rev_2: | 
|  | 187 | e1000_write_phy_reg(hw, 0x1F73, 0x0099); | 
|  | 188 | break; | 
|  | 189 | default: | 
|  | 190 | break; | 
|  | 191 | } | 
| 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 | e1000_write_phy_reg(hw, 0x0000, 0x3300); | 
|  | 194 | msleep(20); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 196 | /* Now enable the transmitter */ | 
|  | 197 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 199 | if (hw->mac_type == e1000_82547) { | 
|  | 200 | u16 fused, fine, coarse; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 202 | /* Move to analog registers page */ | 
|  | 203 | e1000_read_phy_reg(hw, | 
|  | 204 | IGP01E1000_ANALOG_SPARE_FUSE_STATUS, | 
|  | 205 | &fused); | 
| 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 (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) { | 
|  | 208 | e1000_read_phy_reg(hw, | 
|  | 209 | IGP01E1000_ANALOG_FUSE_STATUS, | 
|  | 210 | &fused); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 212 | fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK; | 
|  | 213 | coarse = | 
|  | 214 | fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 216 | if (coarse > | 
|  | 217 | IGP01E1000_ANALOG_FUSE_COARSE_THRESH) { | 
|  | 218 | coarse -= | 
|  | 219 | IGP01E1000_ANALOG_FUSE_COARSE_10; | 
|  | 220 | fine -= IGP01E1000_ANALOG_FUSE_FINE_1; | 
|  | 221 | } else if (coarse == | 
|  | 222 | IGP01E1000_ANALOG_FUSE_COARSE_THRESH) | 
|  | 223 | fine -= IGP01E1000_ANALOG_FUSE_FINE_10; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 225 | fused = | 
|  | 226 | (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) | | 
|  | 227 | (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) | | 
|  | 228 | (coarse & | 
|  | 229 | IGP01E1000_ANALOG_FUSE_COARSE_MASK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 231 | e1000_write_phy_reg(hw, | 
|  | 232 | IGP01E1000_ANALOG_FUSE_CONTROL, | 
|  | 233 | fused); | 
|  | 234 | e1000_write_phy_reg(hw, | 
|  | 235 | IGP01E1000_ANALOG_FUSE_BYPASS, | 
|  | 236 | IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL); | 
|  | 237 | } | 
|  | 238 | } | 
|  | 239 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } | 
|  | 241 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 242 | /** | 
|  | 243 | * e1000_set_mac_type - Set the mac type member in the hw struct. | 
|  | 244 | * @hw: Struct containing variables accessed by shared code | 
|  | 245 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 246 | s32 e1000_set_mac_type(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { | 
| Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 248 | DEBUGFUNC("e1000_set_mac_type"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 |  | 
| Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 250 | switch (hw->device_id) { | 
|  | 251 | case E1000_DEV_ID_82542: | 
|  | 252 | switch (hw->revision_id) { | 
|  | 253 | case E1000_82542_2_0_REV_ID: | 
|  | 254 | hw->mac_type = e1000_82542_rev2_0; | 
|  | 255 | break; | 
|  | 256 | case E1000_82542_2_1_REV_ID: | 
|  | 257 | hw->mac_type = e1000_82542_rev2_1; | 
|  | 258 | break; | 
|  | 259 | default: | 
|  | 260 | /* Invalid 82542 revision ID */ | 
|  | 261 | return -E1000_ERR_MAC_TYPE; | 
|  | 262 | } | 
|  | 263 | break; | 
|  | 264 | case E1000_DEV_ID_82543GC_FIBER: | 
|  | 265 | case E1000_DEV_ID_82543GC_COPPER: | 
|  | 266 | hw->mac_type = e1000_82543; | 
|  | 267 | break; | 
|  | 268 | case E1000_DEV_ID_82544EI_COPPER: | 
|  | 269 | case E1000_DEV_ID_82544EI_FIBER: | 
|  | 270 | case E1000_DEV_ID_82544GC_COPPER: | 
|  | 271 | case E1000_DEV_ID_82544GC_LOM: | 
|  | 272 | hw->mac_type = e1000_82544; | 
|  | 273 | break; | 
|  | 274 | case E1000_DEV_ID_82540EM: | 
|  | 275 | case E1000_DEV_ID_82540EM_LOM: | 
|  | 276 | case E1000_DEV_ID_82540EP: | 
|  | 277 | case E1000_DEV_ID_82540EP_LOM: | 
|  | 278 | case E1000_DEV_ID_82540EP_LP: | 
|  | 279 | hw->mac_type = e1000_82540; | 
|  | 280 | break; | 
|  | 281 | case E1000_DEV_ID_82545EM_COPPER: | 
|  | 282 | case E1000_DEV_ID_82545EM_FIBER: | 
|  | 283 | hw->mac_type = e1000_82545; | 
|  | 284 | break; | 
|  | 285 | case E1000_DEV_ID_82545GM_COPPER: | 
|  | 286 | case E1000_DEV_ID_82545GM_FIBER: | 
|  | 287 | case E1000_DEV_ID_82545GM_SERDES: | 
|  | 288 | hw->mac_type = e1000_82545_rev_3; | 
|  | 289 | break; | 
|  | 290 | case E1000_DEV_ID_82546EB_COPPER: | 
|  | 291 | case E1000_DEV_ID_82546EB_FIBER: | 
|  | 292 | case E1000_DEV_ID_82546EB_QUAD_COPPER: | 
|  | 293 | hw->mac_type = e1000_82546; | 
|  | 294 | break; | 
|  | 295 | case E1000_DEV_ID_82546GB_COPPER: | 
|  | 296 | case E1000_DEV_ID_82546GB_FIBER: | 
|  | 297 | case E1000_DEV_ID_82546GB_SERDES: | 
|  | 298 | case E1000_DEV_ID_82546GB_PCIE: | 
|  | 299 | case E1000_DEV_ID_82546GB_QUAD_COPPER: | 
|  | 300 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: | 
|  | 301 | hw->mac_type = e1000_82546_rev_3; | 
|  | 302 | break; | 
|  | 303 | case E1000_DEV_ID_82541EI: | 
|  | 304 | case E1000_DEV_ID_82541EI_MOBILE: | 
|  | 305 | case E1000_DEV_ID_82541ER_LOM: | 
|  | 306 | hw->mac_type = e1000_82541; | 
|  | 307 | break; | 
|  | 308 | case E1000_DEV_ID_82541ER: | 
|  | 309 | case E1000_DEV_ID_82541GI: | 
|  | 310 | case E1000_DEV_ID_82541GI_LF: | 
|  | 311 | case E1000_DEV_ID_82541GI_MOBILE: | 
|  | 312 | hw->mac_type = e1000_82541_rev_2; | 
|  | 313 | break; | 
|  | 314 | case E1000_DEV_ID_82547EI: | 
|  | 315 | case E1000_DEV_ID_82547EI_MOBILE: | 
|  | 316 | hw->mac_type = e1000_82547; | 
|  | 317 | break; | 
|  | 318 | case E1000_DEV_ID_82547GI: | 
|  | 319 | hw->mac_type = e1000_82547_rev_2; | 
|  | 320 | break; | 
| Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 321 | default: | 
|  | 322 | /* Should never have loaded on this device */ | 
|  | 323 | return -E1000_ERR_MAC_TYPE; | 
|  | 324 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 |  | 
| Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 326 | switch (hw->mac_type) { | 
| Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 327 | case e1000_82541: | 
|  | 328 | case e1000_82547: | 
|  | 329 | case e1000_82541_rev_2: | 
|  | 330 | case e1000_82547_rev_2: | 
| Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 331 | hw->asf_firmware_present = true; | 
| Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 332 | break; | 
|  | 333 | default: | 
|  | 334 | break; | 
|  | 335 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 |  | 
| Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 337 | /* The 82543 chip does not count tx_carrier_errors properly in | 
|  | 338 | * FD mode | 
|  | 339 | */ | 
|  | 340 | if (hw->mac_type == e1000_82543) | 
| Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 341 | hw->bad_tx_carr_stats_fd = true; | 
| Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 342 |  | 
| Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 343 | if (hw->mac_type > e1000_82544) | 
| Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 344 | hw->has_smbus = true; | 
| Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 345 |  | 
| Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 346 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } | 
|  | 348 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 349 | /** | 
|  | 350 | * e1000_set_media_type - Set media type and TBI compatibility. | 
|  | 351 | * @hw: Struct containing variables accessed by shared code | 
|  | 352 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 353 | void e1000_set_media_type(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 355 | u32 status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 357 | DEBUGFUNC("e1000_set_media_type"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 359 | if (hw->mac_type != e1000_82543) { | 
|  | 360 | /* tbi_compatibility is only valid on 82543 */ | 
|  | 361 | hw->tbi_compatibility_en = false; | 
|  | 362 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 364 | switch (hw->device_id) { | 
|  | 365 | case E1000_DEV_ID_82545GM_SERDES: | 
|  | 366 | case E1000_DEV_ID_82546GB_SERDES: | 
|  | 367 | hw->media_type = e1000_media_type_internal_serdes; | 
|  | 368 | break; | 
|  | 369 | default: | 
|  | 370 | switch (hw->mac_type) { | 
|  | 371 | case e1000_82542_rev2_0: | 
|  | 372 | case e1000_82542_rev2_1: | 
|  | 373 | hw->media_type = e1000_media_type_fiber; | 
|  | 374 | break; | 
|  | 375 | default: | 
|  | 376 | status = er32(STATUS); | 
|  | 377 | if (status & E1000_STATUS_TBIMODE) { | 
|  | 378 | hw->media_type = e1000_media_type_fiber; | 
|  | 379 | /* tbi_compatibility not valid on fiber */ | 
|  | 380 | hw->tbi_compatibility_en = false; | 
|  | 381 | } else { | 
|  | 382 | hw->media_type = e1000_media_type_copper; | 
|  | 383 | } | 
|  | 384 | break; | 
|  | 385 | } | 
|  | 386 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } | 
|  | 388 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 389 | /** | 
|  | 390 | * e1000_reset_hw: reset the hardware completely | 
|  | 391 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | * | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 393 | * Reset the transmit and receive units; mask and clear all interrupts. | 
|  | 394 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 395 | s32 e1000_reset_hw(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 397 | u32 ctrl; | 
|  | 398 | u32 ctrl_ext; | 
|  | 399 | u32 icr; | 
|  | 400 | u32 manc; | 
|  | 401 | u32 led_ctrl; | 
|  | 402 | s32 ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 404 | DEBUGFUNC("e1000_reset_hw"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 406 | /* For 82542 (rev 2.0), disable MWI before issuing a device reset */ | 
|  | 407 | if (hw->mac_type == e1000_82542_rev2_0) { | 
|  | 408 | DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); | 
|  | 409 | e1000_pci_clear_mwi(hw); | 
|  | 410 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 412 | /* Clear interrupt mask to stop board from generating interrupts */ | 
|  | 413 | DEBUGOUT("Masking off all interrupts\n"); | 
|  | 414 | ew32(IMC, 0xffffffff); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 416 | /* Disable the Transmit and Receive units.  Then delay to allow | 
|  | 417 | * any pending transactions to complete before we hit the MAC with | 
|  | 418 | * the global reset. | 
|  | 419 | */ | 
|  | 420 | ew32(RCTL, 0); | 
|  | 421 | ew32(TCTL, E1000_TCTL_PSP); | 
|  | 422 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 424 | /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */ | 
|  | 425 | hw->tbi_compatibility_on = false; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 427 | /* Delay to allow any outstanding PCI transactions to complete before | 
|  | 428 | * resetting the device | 
|  | 429 | */ | 
|  | 430 | msleep(10); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 432 | ctrl = er32(CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 434 | /* Must reset the PHY before resetting the MAC */ | 
|  | 435 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { | 
|  | 436 | ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST)); | 
|  | 437 | msleep(5); | 
|  | 438 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 440 | /* Issue a global reset to the MAC.  This will reset the chip's | 
|  | 441 | * transmit, receive, DMA, and link units.  It will not effect | 
|  | 442 | * the current PCI configuration.  The global reset bit is self- | 
|  | 443 | * clearing, and should clear within a microsecond. | 
|  | 444 | */ | 
|  | 445 | DEBUGOUT("Issuing a global reset to MAC\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 447 | switch (hw->mac_type) { | 
|  | 448 | case e1000_82544: | 
|  | 449 | case e1000_82540: | 
|  | 450 | case e1000_82545: | 
|  | 451 | case e1000_82546: | 
|  | 452 | case e1000_82541: | 
|  | 453 | case e1000_82541_rev_2: | 
|  | 454 | /* These controllers can't ack the 64-bit write when issuing the | 
|  | 455 | * reset, so use IO-mapping as a workaround to issue the reset */ | 
|  | 456 | E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST)); | 
|  | 457 | break; | 
|  | 458 | case e1000_82545_rev_3: | 
|  | 459 | case e1000_82546_rev_3: | 
|  | 460 | /* Reset is performed on a shadow of the control register */ | 
|  | 461 | ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST)); | 
|  | 462 | break; | 
|  | 463 | default: | 
|  | 464 | ew32(CTRL, (ctrl | E1000_CTRL_RST)); | 
|  | 465 | break; | 
|  | 466 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 468 | /* After MAC reset, force reload of EEPROM to restore power-on settings to | 
|  | 469 | * device.  Later controllers reload the EEPROM automatically, so just wait | 
|  | 470 | * for reload to complete. | 
|  | 471 | */ | 
|  | 472 | switch (hw->mac_type) { | 
|  | 473 | case e1000_82542_rev2_0: | 
|  | 474 | case e1000_82542_rev2_1: | 
|  | 475 | case e1000_82543: | 
|  | 476 | case e1000_82544: | 
|  | 477 | /* Wait for reset to complete */ | 
|  | 478 | udelay(10); | 
|  | 479 | ctrl_ext = er32(CTRL_EXT); | 
|  | 480 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; | 
|  | 481 | ew32(CTRL_EXT, ctrl_ext); | 
|  | 482 | E1000_WRITE_FLUSH(); | 
|  | 483 | /* Wait for EEPROM reload */ | 
|  | 484 | msleep(2); | 
|  | 485 | break; | 
|  | 486 | case e1000_82541: | 
|  | 487 | case e1000_82541_rev_2: | 
|  | 488 | case e1000_82547: | 
|  | 489 | case e1000_82547_rev_2: | 
|  | 490 | /* Wait for EEPROM reload */ | 
|  | 491 | msleep(20); | 
|  | 492 | break; | 
|  | 493 | default: | 
|  | 494 | /* Auto read done will delay 5ms or poll based on mac type */ | 
|  | 495 | ret_val = e1000_get_auto_rd_done(hw); | 
|  | 496 | if (ret_val) | 
|  | 497 | return ret_val; | 
|  | 498 | break; | 
|  | 499 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 501 | /* Disable HW ARPs on ASF enabled adapters */ | 
|  | 502 | if (hw->mac_type >= e1000_82540) { | 
|  | 503 | manc = er32(MANC); | 
|  | 504 | manc &= ~(E1000_MANC_ARP_EN); | 
|  | 505 | ew32(MANC, manc); | 
|  | 506 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 508 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { | 
|  | 509 | e1000_phy_init_script(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 511 | /* Configure activity LED after PHY reset */ | 
|  | 512 | led_ctrl = er32(LEDCTL); | 
|  | 513 | led_ctrl &= IGP_ACTIVITY_LED_MASK; | 
|  | 514 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); | 
|  | 515 | ew32(LEDCTL, led_ctrl); | 
|  | 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 | /* Clear interrupt mask to stop board from generating interrupts */ | 
|  | 519 | DEBUGOUT("Masking off all interrupts\n"); | 
|  | 520 | ew32(IMC, 0xffffffff); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 522 | /* Clear any pending interrupt events. */ | 
|  | 523 | icr = er32(ICR); | 
| 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 MWI was previously enabled, reenable it. */ | 
|  | 526 | if (hw->mac_type == e1000_82542_rev2_0) { | 
|  | 527 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) | 
|  | 528 | e1000_pci_set_mwi(hw); | 
|  | 529 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 531 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | } | 
|  | 533 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 534 | /** | 
|  | 535 | * e1000_init_hw: Performs basic configuration of the adapter. | 
|  | 536 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | * | 
|  | 538 | * Assumes that the controller has previously been reset and is in a | 
|  | 539 | * post-reset uninitialized state. Initializes the receive address registers, | 
|  | 540 | * multicast table, and VLAN filter table. Calls routines to setup link | 
|  | 541 | * configuration and flow control settings. Clears all on-chip counters. Leaves | 
|  | 542 | * the transmit and receive units disabled and uninitialized. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 543 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 544 | s32 e1000_init_hw(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 546 | u32 ctrl; | 
|  | 547 | u32 i; | 
|  | 548 | s32 ret_val; | 
|  | 549 | u32 mta_size; | 
|  | 550 | u32 ctrl_ext; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 551 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 552 | DEBUGFUNC("e1000_init_hw"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 554 | /* Initialize Identification LED */ | 
|  | 555 | ret_val = e1000_id_led_init(hw); | 
|  | 556 | if (ret_val) { | 
|  | 557 | DEBUGOUT("Error Initializing Identification LED\n"); | 
|  | 558 | return ret_val; | 
|  | 559 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 561 | /* Set the media type and TBI compatibility */ | 
|  | 562 | e1000_set_media_type(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 564 | /* Disabling VLAN filtering. */ | 
|  | 565 | DEBUGOUT("Initializing the IEEE VLAN\n"); | 
|  | 566 | if (hw->mac_type < e1000_82545_rev_3) | 
|  | 567 | ew32(VET, 0); | 
|  | 568 | e1000_clear_vfta(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 570 | /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */ | 
|  | 571 | if (hw->mac_type == e1000_82542_rev2_0) { | 
|  | 572 | DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); | 
|  | 573 | e1000_pci_clear_mwi(hw); | 
|  | 574 | ew32(RCTL, E1000_RCTL_RST); | 
|  | 575 | E1000_WRITE_FLUSH(); | 
|  | 576 | msleep(5); | 
|  | 577 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 579 | /* Setup the receive address. This involves initializing all of the Receive | 
|  | 580 | * Address Registers (RARs 0 - 15). | 
|  | 581 | */ | 
|  | 582 | e1000_init_rx_addrs(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 584 | /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */ | 
|  | 585 | if (hw->mac_type == e1000_82542_rev2_0) { | 
|  | 586 | ew32(RCTL, 0); | 
|  | 587 | E1000_WRITE_FLUSH(); | 
|  | 588 | msleep(1); | 
|  | 589 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) | 
|  | 590 | e1000_pci_set_mwi(hw); | 
|  | 591 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 593 | /* Zero out the Multicast HASH table */ | 
|  | 594 | DEBUGOUT("Zeroing the MTA\n"); | 
|  | 595 | mta_size = E1000_MC_TBL_SIZE; | 
|  | 596 | for (i = 0; i < mta_size; i++) { | 
|  | 597 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); | 
|  | 598 | /* use write flush to prevent Memory Write Block (MWB) from | 
|  | 599 | * occurring when accessing our register space */ | 
|  | 600 | E1000_WRITE_FLUSH(); | 
|  | 601 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 603 | /* Set the PCI priority bit correctly in the CTRL register.  This | 
|  | 604 | * determines if the adapter gives priority to receives, or if it | 
|  | 605 | * gives equal priority to transmits and receives.  Valid only on | 
|  | 606 | * 82542 and 82543 silicon. | 
|  | 607 | */ | 
|  | 608 | if (hw->dma_fairness && hw->mac_type <= e1000_82543) { | 
|  | 609 | ctrl = er32(CTRL); | 
|  | 610 | ew32(CTRL, ctrl | E1000_CTRL_PRIOR); | 
|  | 611 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 613 | switch (hw->mac_type) { | 
|  | 614 | case e1000_82545_rev_3: | 
|  | 615 | case e1000_82546_rev_3: | 
|  | 616 | break; | 
|  | 617 | default: | 
|  | 618 | /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */ | 
|  | 619 | if (hw->bus_type == e1000_bus_type_pcix | 
|  | 620 | && e1000_pcix_get_mmrbc(hw) > 2048) | 
|  | 621 | e1000_pcix_set_mmrbc(hw, 2048); | 
|  | 622 | break; | 
|  | 623 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 625 | /* Call a subroutine to configure the link and setup flow control. */ | 
|  | 626 | ret_val = e1000_setup_link(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 628 | /* Set the transmit descriptor write-back policy */ | 
|  | 629 | if (hw->mac_type > e1000_82544) { | 
|  | 630 | ctrl = er32(TXDCTL); | 
|  | 631 | ctrl = | 
|  | 632 | (ctrl & ~E1000_TXDCTL_WTHRESH) | | 
|  | 633 | E1000_TXDCTL_FULL_TX_DESC_WB; | 
|  | 634 | ew32(TXDCTL, ctrl); | 
|  | 635 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 637 | /* Clear all of the statistics registers (clear on read).  It is | 
|  | 638 | * important that we do this after we have tried to establish link | 
|  | 639 | * because the symbol error count will increment wildly if there | 
|  | 640 | * is no link. | 
|  | 641 | */ | 
|  | 642 | e1000_clear_hw_cntrs(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 644 | if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER || | 
|  | 645 | hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) { | 
|  | 646 | ctrl_ext = er32(CTRL_EXT); | 
|  | 647 | /* Relaxed ordering must be disabled to avoid a parity | 
|  | 648 | * error crash in a PCI slot. */ | 
|  | 649 | ctrl_ext |= E1000_CTRL_EXT_RO_DIS; | 
|  | 650 | ew32(CTRL_EXT, ctrl_ext); | 
|  | 651 | } | 
| Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 652 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 653 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } | 
|  | 655 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 656 | /** | 
|  | 657 | * e1000_adjust_serdes_amplitude - Adjust SERDES output amplitude based on EEPROM setting. | 
|  | 658 | * @hw: Struct containing variables accessed by shared code. | 
|  | 659 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 660 | static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 662 | u16 eeprom_data; | 
|  | 663 | s32 ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 665 | DEBUGFUNC("e1000_adjust_serdes_amplitude"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 667 | if (hw->media_type != e1000_media_type_internal_serdes) | 
|  | 668 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 670 | switch (hw->mac_type) { | 
|  | 671 | case e1000_82545_rev_3: | 
|  | 672 | case e1000_82546_rev_3: | 
|  | 673 | break; | 
|  | 674 | default: | 
|  | 675 | return E1000_SUCCESS; | 
|  | 676 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 678 | ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, | 
|  | 679 | &eeprom_data); | 
|  | 680 | if (ret_val) { | 
|  | 681 | return ret_val; | 
|  | 682 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 684 | if (eeprom_data != EEPROM_RESERVED_WORD) { | 
|  | 685 | /* Adjust SERDES output amplitude only. */ | 
|  | 686 | eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK; | 
|  | 687 | ret_val = | 
|  | 688 | e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data); | 
|  | 689 | if (ret_val) | 
|  | 690 | return ret_val; | 
|  | 691 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 693 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | } | 
|  | 695 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 696 | /** | 
|  | 697 | * e1000_setup_link - Configures flow control and link settings. | 
|  | 698 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | * | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 700 | * Determines which flow control settings to use. Calls the appropriate media- | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | * specific link configuration function. Configures the flow control settings. | 
|  | 702 | * Assuming the adapter has a valid link partner, a valid link should be | 
|  | 703 | * established. Assumes the hardware has previously been reset and the | 
|  | 704 | * transmitter and receiver are not enabled. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 705 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 706 | s32 e1000_setup_link(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 708 | u32 ctrl_ext; | 
|  | 709 | s32 ret_val; | 
|  | 710 | u16 eeprom_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 712 | DEBUGFUNC("e1000_setup_link"); | 
| 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 | /* Read and store word 0x0F of the EEPROM. This word contains bits | 
|  | 715 | * that determine the hardware's default PAUSE (flow control) mode, | 
|  | 716 | * a bit that determines whether the HW defaults to enabling or | 
|  | 717 | * disabling auto-negotiation, and the direction of the | 
|  | 718 | * SW defined pins. If there is no SW over-ride of the flow | 
|  | 719 | * control setting, then the variable hw->fc will | 
|  | 720 | * be initialized based on a value in the EEPROM. | 
|  | 721 | */ | 
|  | 722 | if (hw->fc == E1000_FC_DEFAULT) { | 
|  | 723 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, | 
|  | 724 | 1, &eeprom_data); | 
|  | 725 | if (ret_val) { | 
|  | 726 | DEBUGOUT("EEPROM Read Error\n"); | 
|  | 727 | return -E1000_ERR_EEPROM; | 
|  | 728 | } | 
|  | 729 | if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0) | 
|  | 730 | hw->fc = E1000_FC_NONE; | 
|  | 731 | else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == | 
|  | 732 | EEPROM_WORD0F_ASM_DIR) | 
|  | 733 | hw->fc = E1000_FC_TX_PAUSE; | 
|  | 734 | else | 
|  | 735 | hw->fc = E1000_FC_FULL; | 
|  | 736 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 738 | /* We want to save off the original Flow Control configuration just | 
|  | 739 | * in case we get disconnected and then reconnected into a different | 
|  | 740 | * hub or switch with different Flow Control capabilities. | 
|  | 741 | */ | 
|  | 742 | if (hw->mac_type == e1000_82542_rev2_0) | 
|  | 743 | hw->fc &= (~E1000_FC_TX_PAUSE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 745 | if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1)) | 
|  | 746 | hw->fc &= (~E1000_FC_RX_PAUSE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 748 | hw->original_fc = hw->fc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 750 | DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 752 | /* Take the 4 bits from EEPROM word 0x0F that determine the initial | 
|  | 753 | * polarity value for the SW controlled pins, and setup the | 
|  | 754 | * Extended Device Control reg with that info. | 
|  | 755 | * This is needed because one of the SW controlled pins is used for | 
|  | 756 | * signal detection.  So this should be done before e1000_setup_pcs_link() | 
|  | 757 | * or e1000_phy_setup() is called. | 
|  | 758 | */ | 
|  | 759 | if (hw->mac_type == e1000_82543) { | 
|  | 760 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, | 
|  | 761 | 1, &eeprom_data); | 
|  | 762 | if (ret_val) { | 
|  | 763 | DEBUGOUT("EEPROM Read Error\n"); | 
|  | 764 | return -E1000_ERR_EEPROM; | 
|  | 765 | } | 
|  | 766 | ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) << | 
|  | 767 | SWDPIO__EXT_SHIFT); | 
|  | 768 | ew32(CTRL_EXT, ctrl_ext); | 
|  | 769 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 771 | /* Call the necessary subroutine to configure the link. */ | 
|  | 772 | ret_val = (hw->media_type == e1000_media_type_copper) ? | 
|  | 773 | e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 775 | /* Initialize the flow control address, type, and PAUSE timer | 
|  | 776 | * registers to their default values.  This is done even if flow | 
|  | 777 | * control is disabled, because it does not hurt anything to | 
|  | 778 | * initialize these registers. | 
|  | 779 | */ | 
|  | 780 | DEBUGOUT | 
|  | 781 | ("Initializing the Flow Control address, type and timer regs\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 783 | ew32(FCT, FLOW_CONTROL_TYPE); | 
|  | 784 | ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH); | 
|  | 785 | ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 786 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 787 | ew32(FCTTV, hw->fc_pause_time); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 789 | /* Set the flow control receive threshold registers.  Normally, | 
|  | 790 | * these registers will be set to a default threshold that may be | 
|  | 791 | * adjusted later by the driver's runtime code.  However, if the | 
|  | 792 | * ability to transmit pause frames in not enabled, then these | 
|  | 793 | * registers will be set to 0. | 
|  | 794 | */ | 
|  | 795 | if (!(hw->fc & E1000_FC_TX_PAUSE)) { | 
|  | 796 | ew32(FCRTL, 0); | 
|  | 797 | ew32(FCRTH, 0); | 
|  | 798 | } else { | 
|  | 799 | /* We need to set up the Receive Threshold high and low water marks | 
|  | 800 | * as well as (optionally) enabling the transmission of XON frames. | 
|  | 801 | */ | 
|  | 802 | if (hw->fc_send_xon) { | 
|  | 803 | ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE)); | 
|  | 804 | ew32(FCRTH, hw->fc_high_water); | 
|  | 805 | } else { | 
|  | 806 | ew32(FCRTL, hw->fc_low_water); | 
|  | 807 | ew32(FCRTH, hw->fc_high_water); | 
|  | 808 | } | 
|  | 809 | } | 
|  | 810 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | } | 
|  | 812 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 813 | /** | 
|  | 814 | * e1000_setup_fiber_serdes_link - prepare fiber or serdes link | 
|  | 815 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | * | 
|  | 817 | * Manipulates Physical Coding Sublayer functions in order to configure | 
|  | 818 | * link. Assumes the hardware has been previously reset and the transmitter | 
|  | 819 | * and receiver are not enabled. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 820 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 821 | static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 823 | u32 ctrl; | 
|  | 824 | u32 status; | 
|  | 825 | u32 txcw = 0; | 
|  | 826 | u32 i; | 
|  | 827 | u32 signal = 0; | 
|  | 828 | s32 ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 830 | DEBUGFUNC("e1000_setup_fiber_serdes_link"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 832 | /* On adapters with a MAC newer than 82544, SWDP 1 will be | 
|  | 833 | * set when the optics detect a signal. On older adapters, it will be | 
|  | 834 | * cleared when there is a signal.  This applies to fiber media only. | 
|  | 835 | * If we're on serdes media, adjust the output amplitude to value | 
|  | 836 | * set in the EEPROM. | 
|  | 837 | */ | 
|  | 838 | ctrl = er32(CTRL); | 
|  | 839 | if (hw->media_type == e1000_media_type_fiber) | 
|  | 840 | signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 842 | ret_val = e1000_adjust_serdes_amplitude(hw); | 
|  | 843 | if (ret_val) | 
|  | 844 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 846 | /* Take the link out of reset */ | 
|  | 847 | ctrl &= ~(E1000_CTRL_LRST); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 849 | /* Adjust VCO speed to improve BER performance */ | 
|  | 850 | ret_val = e1000_set_vco_speed(hw); | 
|  | 851 | if (ret_val) | 
|  | 852 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 854 | e1000_config_collision_dist(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 856 | /* Check for a software override of the flow control settings, and setup | 
|  | 857 | * the device accordingly.  If auto-negotiation is enabled, then software | 
|  | 858 | * will have to set the "PAUSE" bits to the correct value in the Tranmsit | 
|  | 859 | * Config Word Register (TXCW) and re-start auto-negotiation.  However, if | 
|  | 860 | * auto-negotiation is disabled, then software will have to manually | 
|  | 861 | * configure the two flow control enable bits in the CTRL register. | 
|  | 862 | * | 
|  | 863 | * The possible values of the "fc" parameter are: | 
|  | 864 | *      0:  Flow control is completely disabled | 
|  | 865 | *      1:  Rx flow control is enabled (we can receive pause frames, but | 
|  | 866 | *          not send pause frames). | 
|  | 867 | *      2:  Tx flow control is enabled (we can send pause frames but we do | 
|  | 868 | *          not support receiving pause frames). | 
|  | 869 | *      3:  Both Rx and TX flow control (symmetric) are enabled. | 
|  | 870 | */ | 
|  | 871 | switch (hw->fc) { | 
|  | 872 | case E1000_FC_NONE: | 
|  | 873 | /* Flow control is completely disabled by a software over-ride. */ | 
|  | 874 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); | 
|  | 875 | break; | 
|  | 876 | case E1000_FC_RX_PAUSE: | 
|  | 877 | /* RX Flow control is enabled and TX Flow control is disabled by a | 
|  | 878 | * software over-ride. Since there really isn't a way to advertise | 
|  | 879 | * that we are capable of RX Pause ONLY, we will advertise that we | 
|  | 880 | * support both symmetric and asymmetric RX PAUSE. Later, we will | 
|  | 881 | *  disable the adapter's ability to send PAUSE frames. | 
|  | 882 | */ | 
|  | 883 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); | 
|  | 884 | break; | 
|  | 885 | case E1000_FC_TX_PAUSE: | 
|  | 886 | /* TX Flow control is enabled, and RX Flow control is disabled, by a | 
|  | 887 | * software over-ride. | 
|  | 888 | */ | 
|  | 889 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); | 
|  | 890 | break; | 
|  | 891 | case E1000_FC_FULL: | 
|  | 892 | /* Flow control (both RX and TX) is enabled by a software over-ride. */ | 
|  | 893 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); | 
|  | 894 | break; | 
|  | 895 | default: | 
|  | 896 | DEBUGOUT("Flow control param set incorrectly\n"); | 
|  | 897 | return -E1000_ERR_CONFIG; | 
|  | 898 | break; | 
|  | 899 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 901 | /* Since auto-negotiation is enabled, take the link out of reset (the link | 
|  | 902 | * will be in reset, because we previously reset the chip). This will | 
|  | 903 | * restart auto-negotiation.  If auto-negotiation is successful then the | 
|  | 904 | * link-up status bit will be set and the flow control enable bits (RFCE | 
|  | 905 | * and TFCE) will be set according to their negotiated value. | 
|  | 906 | */ | 
|  | 907 | DEBUGOUT("Auto-negotiation enabled\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 909 | ew32(TXCW, txcw); | 
|  | 910 | ew32(CTRL, ctrl); | 
|  | 911 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 913 | hw->txcw = txcw; | 
|  | 914 | msleep(1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 916 | /* If we have a signal (the cable is plugged in) then poll for a "Link-Up" | 
|  | 917 | * indication in the Device Status Register.  Time-out if a link isn't | 
|  | 918 | * seen in 500 milliseconds seconds (Auto-negotiation should complete in | 
|  | 919 | * less than 500 milliseconds even if the other end is doing it in SW). | 
|  | 920 | * For internal serdes, we just assume a signal is present, then poll. | 
|  | 921 | */ | 
|  | 922 | if (hw->media_type == e1000_media_type_internal_serdes || | 
|  | 923 | (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) { | 
|  | 924 | DEBUGOUT("Looking for Link\n"); | 
|  | 925 | for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) { | 
|  | 926 | msleep(10); | 
|  | 927 | status = er32(STATUS); | 
|  | 928 | if (status & E1000_STATUS_LU) | 
|  | 929 | break; | 
|  | 930 | } | 
|  | 931 | if (i == (LINK_UP_TIMEOUT / 10)) { | 
|  | 932 | DEBUGOUT("Never got a valid link from auto-neg!!!\n"); | 
|  | 933 | hw->autoneg_failed = 1; | 
|  | 934 | /* AutoNeg failed to achieve a link, so we'll call | 
|  | 935 | * e1000_check_for_link. This routine will force the link up if | 
|  | 936 | * we detect a signal. This will allow us to communicate with | 
|  | 937 | * non-autonegotiating link partners. | 
|  | 938 | */ | 
|  | 939 | ret_val = e1000_check_for_link(hw); | 
|  | 940 | if (ret_val) { | 
|  | 941 | DEBUGOUT("Error while checking for link\n"); | 
|  | 942 | return ret_val; | 
|  | 943 | } | 
|  | 944 | hw->autoneg_failed = 0; | 
|  | 945 | } else { | 
|  | 946 | hw->autoneg_failed = 0; | 
|  | 947 | DEBUGOUT("Valid Link Found\n"); | 
|  | 948 | } | 
|  | 949 | } else { | 
|  | 950 | DEBUGOUT("No Signal Detected\n"); | 
|  | 951 | } | 
|  | 952 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | } | 
|  | 954 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 955 | /** | 
|  | 956 | * e1000_copper_link_preconfig - early configuration for copper | 
|  | 957 | * @hw: Struct containing variables accessed by shared code | 
|  | 958 | * | 
|  | 959 | * Make sure we have a valid PHY and change PHY mode before link setup. | 
|  | 960 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 961 | static s32 e1000_copper_link_preconfig(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 963 | u32 ctrl; | 
|  | 964 | s32 ret_val; | 
|  | 965 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 967 | DEBUGFUNC("e1000_copper_link_preconfig"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 969 | ctrl = er32(CTRL); | 
|  | 970 | /* With 82543, we need to force speed and duplex on the MAC equal to what | 
|  | 971 | * the PHY speed and duplex configuration is. In addition, we need to | 
|  | 972 | * perform a hardware reset on the PHY to take it out of reset. | 
|  | 973 | */ | 
|  | 974 | if (hw->mac_type > e1000_82543) { | 
|  | 975 | ctrl |= E1000_CTRL_SLU; | 
|  | 976 | ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); | 
|  | 977 | ew32(CTRL, ctrl); | 
|  | 978 | } else { | 
|  | 979 | ctrl |= | 
|  | 980 | (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU); | 
|  | 981 | ew32(CTRL, ctrl); | 
|  | 982 | ret_val = e1000_phy_hw_reset(hw); | 
|  | 983 | if (ret_val) | 
|  | 984 | return ret_val; | 
|  | 985 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 987 | /* Make sure we have a valid PHY */ | 
|  | 988 | ret_val = e1000_detect_gig_phy(hw); | 
|  | 989 | if (ret_val) { | 
|  | 990 | DEBUGOUT("Error, did not detect valid phy.\n"); | 
|  | 991 | return ret_val; | 
|  | 992 | } | 
|  | 993 | DEBUGOUT1("Phy ID = %x \n", hw->phy_id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 995 | /* Set PHY to class A mode (if necessary) */ | 
|  | 996 | ret_val = e1000_set_phy_mode(hw); | 
|  | 997 | if (ret_val) | 
|  | 998 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1000 | if ((hw->mac_type == e1000_82545_rev_3) || | 
|  | 1001 | (hw->mac_type == e1000_82546_rev_3)) { | 
|  | 1002 | ret_val = | 
|  | 1003 | e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); | 
|  | 1004 | phy_data |= 0x00000008; | 
|  | 1005 | ret_val = | 
|  | 1006 | e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); | 
|  | 1007 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1009 | if (hw->mac_type <= e1000_82543 || | 
|  | 1010 | hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 || | 
|  | 1011 | hw->mac_type == e1000_82541_rev_2 | 
|  | 1012 | || hw->mac_type == e1000_82547_rev_2) | 
|  | 1013 | hw->phy_reset_disable = false; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1015 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1016 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1018 | /** | 
|  | 1019 | * e1000_copper_link_igp_setup - Copper link setup for e1000_phy_igp series. | 
|  | 1020 | * @hw: Struct containing variables accessed by shared code | 
|  | 1021 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1022 | static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1023 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1024 | u32 led_ctrl; | 
|  | 1025 | s32 ret_val; | 
|  | 1026 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1028 | DEBUGFUNC("e1000_copper_link_igp_setup"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1030 | if (hw->phy_reset_disable) | 
|  | 1031 | return E1000_SUCCESS; | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1032 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1033 | ret_val = e1000_phy_reset(hw); | 
|  | 1034 | if (ret_val) { | 
|  | 1035 | DEBUGOUT("Error Resetting the PHY\n"); | 
|  | 1036 | return ret_val; | 
|  | 1037 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1039 | /* Wait 15ms for MAC to configure PHY from eeprom settings */ | 
|  | 1040 | msleep(15); | 
|  | 1041 | /* Configure activity LED after PHY reset */ | 
|  | 1042 | led_ctrl = er32(LEDCTL); | 
|  | 1043 | led_ctrl &= IGP_ACTIVITY_LED_MASK; | 
|  | 1044 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); | 
|  | 1045 | ew32(LEDCTL, led_ctrl); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1046 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1047 | /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */ | 
|  | 1048 | if (hw->phy_type == e1000_phy_igp) { | 
|  | 1049 | /* disable lplu d3 during driver init */ | 
|  | 1050 | ret_val = e1000_set_d3_lplu_state(hw, false); | 
|  | 1051 | if (ret_val) { | 
|  | 1052 | DEBUGOUT("Error Disabling LPLU D3\n"); | 
|  | 1053 | return ret_val; | 
|  | 1054 | } | 
|  | 1055 | } | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1056 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1057 | /* Configure mdi-mdix settings */ | 
|  | 1058 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); | 
|  | 1059 | if (ret_val) | 
|  | 1060 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1061 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1062 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { | 
|  | 1063 | hw->dsp_config_state = e1000_dsp_config_disabled; | 
|  | 1064 | /* Force MDI for earlier revs of the IGP PHY */ | 
|  | 1065 | phy_data &= | 
|  | 1066 | ~(IGP01E1000_PSCR_AUTO_MDIX | | 
|  | 1067 | IGP01E1000_PSCR_FORCE_MDI_MDIX); | 
|  | 1068 | hw->mdix = 1; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1069 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1070 | } else { | 
|  | 1071 | hw->dsp_config_state = e1000_dsp_config_enabled; | 
|  | 1072 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1073 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1074 | switch (hw->mdix) { | 
|  | 1075 | case 1: | 
|  | 1076 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; | 
|  | 1077 | break; | 
|  | 1078 | case 2: | 
|  | 1079 | phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX; | 
|  | 1080 | break; | 
|  | 1081 | case 0: | 
|  | 1082 | default: | 
|  | 1083 | phy_data |= IGP01E1000_PSCR_AUTO_MDIX; | 
|  | 1084 | break; | 
|  | 1085 | } | 
|  | 1086 | } | 
|  | 1087 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); | 
|  | 1088 | if (ret_val) | 
|  | 1089 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1090 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1091 | /* set auto-master slave resolution settings */ | 
|  | 1092 | if (hw->autoneg) { | 
|  | 1093 | e1000_ms_type phy_ms_setting = hw->master_slave; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1094 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1095 | if (hw->ffe_config_state == e1000_ffe_config_active) | 
|  | 1096 | hw->ffe_config_state = e1000_ffe_config_enabled; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1097 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1098 | if (hw->dsp_config_state == e1000_dsp_config_activated) | 
|  | 1099 | hw->dsp_config_state = e1000_dsp_config_enabled; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1100 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1101 | /* when autonegotiation advertisement is only 1000Mbps then we | 
|  | 1102 | * should disable SmartSpeed and enable Auto MasterSlave | 
|  | 1103 | * resolution as hardware default. */ | 
|  | 1104 | if (hw->autoneg_advertised == ADVERTISE_1000_FULL) { | 
|  | 1105 | /* Disable SmartSpeed */ | 
|  | 1106 | ret_val = | 
|  | 1107 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 1108 | &phy_data); | 
|  | 1109 | if (ret_val) | 
|  | 1110 | return ret_val; | 
|  | 1111 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; | 
|  | 1112 | ret_val = | 
|  | 1113 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 1114 | phy_data); | 
|  | 1115 | if (ret_val) | 
|  | 1116 | return ret_val; | 
|  | 1117 | /* Set auto Master/Slave resolution process */ | 
|  | 1118 | ret_val = | 
|  | 1119 | e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); | 
|  | 1120 | if (ret_val) | 
|  | 1121 | return ret_val; | 
|  | 1122 | phy_data &= ~CR_1000T_MS_ENABLE; | 
|  | 1123 | ret_val = | 
|  | 1124 | e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); | 
|  | 1125 | if (ret_val) | 
|  | 1126 | return ret_val; | 
|  | 1127 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1129 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); | 
|  | 1130 | if (ret_val) | 
|  | 1131 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1133 | /* load defaults for future use */ | 
|  | 1134 | hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ? | 
|  | 1135 | ((phy_data & CR_1000T_MS_VALUE) ? | 
|  | 1136 | e1000_ms_force_master : | 
|  | 1137 | e1000_ms_force_slave) : e1000_ms_auto; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1139 | switch (phy_ms_setting) { | 
|  | 1140 | case e1000_ms_force_master: | 
|  | 1141 | phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE); | 
|  | 1142 | break; | 
|  | 1143 | case e1000_ms_force_slave: | 
|  | 1144 | phy_data |= CR_1000T_MS_ENABLE; | 
|  | 1145 | phy_data &= ~(CR_1000T_MS_VALUE); | 
|  | 1146 | break; | 
|  | 1147 | case e1000_ms_auto: | 
|  | 1148 | phy_data &= ~CR_1000T_MS_ENABLE; | 
|  | 1149 | default: | 
|  | 1150 | break; | 
|  | 1151 | } | 
|  | 1152 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); | 
|  | 1153 | if (ret_val) | 
|  | 1154 | return ret_val; | 
|  | 1155 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1157 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1158 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1160 | /** | 
|  | 1161 | * e1000_copper_link_mgp_setup - Copper link setup for e1000_phy_m88 series. | 
|  | 1162 | * @hw: Struct containing variables accessed by shared code | 
|  | 1163 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1164 | static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1165 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1166 | s32 ret_val; | 
|  | 1167 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1169 | DEBUGFUNC("e1000_copper_link_mgp_setup"); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1170 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1171 | if (hw->phy_reset_disable) | 
|  | 1172 | return E1000_SUCCESS; | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1173 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1174 | /* Enable CRS on TX. This must be set for half-duplex operation. */ | 
|  | 1175 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); | 
|  | 1176 | if (ret_val) | 
|  | 1177 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1178 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1179 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1180 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1181 | /* Options: | 
|  | 1182 | *   MDI/MDI-X = 0 (default) | 
|  | 1183 | *   0 - Auto for all speeds | 
|  | 1184 | *   1 - MDI mode | 
|  | 1185 | *   2 - MDI-X mode | 
|  | 1186 | *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) | 
|  | 1187 | */ | 
|  | 1188 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1189 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1190 | switch (hw->mdix) { | 
|  | 1191 | case 1: | 
|  | 1192 | phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE; | 
|  | 1193 | break; | 
|  | 1194 | case 2: | 
|  | 1195 | phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE; | 
|  | 1196 | break; | 
|  | 1197 | case 3: | 
|  | 1198 | phy_data |= M88E1000_PSCR_AUTO_X_1000T; | 
|  | 1199 | break; | 
|  | 1200 | case 0: | 
|  | 1201 | default: | 
|  | 1202 | phy_data |= M88E1000_PSCR_AUTO_X_MODE; | 
|  | 1203 | break; | 
|  | 1204 | } | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1205 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1206 | /* Options: | 
|  | 1207 | *   disable_polarity_correction = 0 (default) | 
|  | 1208 | *       Automatic Correction for Reversed Cable Polarity | 
|  | 1209 | *   0 - Disabled | 
|  | 1210 | *   1 - Enabled | 
|  | 1211 | */ | 
|  | 1212 | phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL; | 
|  | 1213 | if (hw->disable_polarity_correction == 1) | 
|  | 1214 | phy_data |= M88E1000_PSCR_POLARITY_REVERSAL; | 
|  | 1215 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); | 
|  | 1216 | if (ret_val) | 
|  | 1217 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1218 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1219 | if (hw->phy_revision < M88E1011_I_REV_4) { | 
|  | 1220 | /* Force TX_CLK in the Extended PHY Specific Control Register | 
|  | 1221 | * to 25MHz clock. | 
|  | 1222 | */ | 
|  | 1223 | ret_val = | 
|  | 1224 | e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, | 
|  | 1225 | &phy_data); | 
|  | 1226 | if (ret_val) | 
|  | 1227 | return ret_val; | 
| Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1228 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1229 | phy_data |= M88E1000_EPSCR_TX_CLK_25; | 
| Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1230 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1231 | if ((hw->phy_revision == E1000_REVISION_2) && | 
|  | 1232 | (hw->phy_id == M88E1111_I_PHY_ID)) { | 
|  | 1233 | /* Vidalia Phy, set the downshift counter to 5x */ | 
|  | 1234 | phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK); | 
|  | 1235 | phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X; | 
|  | 1236 | ret_val = e1000_write_phy_reg(hw, | 
|  | 1237 | M88E1000_EXT_PHY_SPEC_CTRL, | 
|  | 1238 | phy_data); | 
|  | 1239 | if (ret_val) | 
|  | 1240 | return ret_val; | 
|  | 1241 | } else { | 
|  | 1242 | /* Configure Master and Slave downshift values */ | 
|  | 1243 | phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK | | 
|  | 1244 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK); | 
|  | 1245 | phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X | | 
|  | 1246 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X); | 
|  | 1247 | ret_val = e1000_write_phy_reg(hw, | 
|  | 1248 | M88E1000_EXT_PHY_SPEC_CTRL, | 
|  | 1249 | phy_data); | 
|  | 1250 | if (ret_val) | 
|  | 1251 | return ret_val; | 
|  | 1252 | } | 
|  | 1253 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1255 | /* SW Reset the PHY so all changes take effect */ | 
|  | 1256 | ret_val = e1000_phy_reset(hw); | 
|  | 1257 | if (ret_val) { | 
|  | 1258 | DEBUGOUT("Error Resetting the PHY\n"); | 
|  | 1259 | return ret_val; | 
|  | 1260 | } | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1261 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1262 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1263 | } | 
|  | 1264 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1265 | /** | 
|  | 1266 | * e1000_copper_link_autoneg - setup auto-neg | 
|  | 1267 | * @hw: Struct containing variables accessed by shared code | 
|  | 1268 | * | 
|  | 1269 | * Setup auto-negotiation and flow control advertisements, | 
|  | 1270 | * and then perform auto-negotiation. | 
|  | 1271 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1272 | static s32 e1000_copper_link_autoneg(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1273 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1274 | s32 ret_val; | 
|  | 1275 | u16 phy_data; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1276 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1277 | DEBUGFUNC("e1000_copper_link_autoneg"); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1278 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1279 | /* Perform some bounds checking on the hw->autoneg_advertised | 
|  | 1280 | * parameter.  If this variable is zero, then set it to the default. | 
|  | 1281 | */ | 
|  | 1282 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1283 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1284 | /* If autoneg_advertised is zero, we assume it was not defaulted | 
|  | 1285 | * by the calling code so we set to advertise full capability. | 
|  | 1286 | */ | 
|  | 1287 | if (hw->autoneg_advertised == 0) | 
|  | 1288 | hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1289 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1290 | DEBUGOUT("Reconfiguring auto-neg advertisement params\n"); | 
|  | 1291 | ret_val = e1000_phy_setup_autoneg(hw); | 
|  | 1292 | if (ret_val) { | 
|  | 1293 | DEBUGOUT("Error Setting up Auto-Negotiation\n"); | 
|  | 1294 | return ret_val; | 
|  | 1295 | } | 
|  | 1296 | DEBUGOUT("Restarting Auto-Neg\n"); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1297 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1298 | /* Restart auto-negotiation by setting the Auto Neg Enable bit and | 
|  | 1299 | * the Auto Neg Restart bit in the PHY control register. | 
|  | 1300 | */ | 
|  | 1301 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); | 
|  | 1302 | if (ret_val) | 
|  | 1303 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1304 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1305 | phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); | 
|  | 1306 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); | 
|  | 1307 | if (ret_val) | 
|  | 1308 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1309 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1310 | /* Does the user want to wait for Auto-Neg to complete here, or | 
|  | 1311 | * check at a later time (for example, callback routine). | 
|  | 1312 | */ | 
|  | 1313 | if (hw->wait_autoneg_complete) { | 
|  | 1314 | ret_val = e1000_wait_autoneg(hw); | 
|  | 1315 | if (ret_val) { | 
|  | 1316 | DEBUGOUT | 
|  | 1317 | ("Error while waiting for autoneg to complete\n"); | 
|  | 1318 | return ret_val; | 
|  | 1319 | } | 
|  | 1320 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1322 | hw->get_link_status = true; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1324 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1325 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1327 | /** | 
|  | 1328 | * e1000_copper_link_postconfig - post link setup | 
|  | 1329 | * @hw: Struct containing variables accessed by shared code | 
|  | 1330 | * | 
|  | 1331 | * Config the MAC and the PHY after link is up. | 
|  | 1332 | *   1) Set up the MAC to the current PHY speed/duplex | 
|  | 1333 | *      if we are on 82543.  If we | 
|  | 1334 | *      are on newer silicon, we only need to configure | 
|  | 1335 | *      collision distance in the Transmit Control Register. | 
|  | 1336 | *   2) Set up flow control on the MAC to that established with | 
|  | 1337 | *      the link partner. | 
|  | 1338 | *   3) Config DSP to improve Gigabit link quality for some PHY revisions. | 
|  | 1339 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1340 | static s32 e1000_copper_link_postconfig(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1341 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1342 | s32 ret_val; | 
|  | 1343 | DEBUGFUNC("e1000_copper_link_postconfig"); | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1344 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1345 | if (hw->mac_type >= e1000_82544) { | 
|  | 1346 | e1000_config_collision_dist(hw); | 
|  | 1347 | } else { | 
|  | 1348 | ret_val = e1000_config_mac_to_phy(hw); | 
|  | 1349 | if (ret_val) { | 
|  | 1350 | DEBUGOUT("Error configuring MAC to PHY settings\n"); | 
|  | 1351 | return ret_val; | 
|  | 1352 | } | 
|  | 1353 | } | 
|  | 1354 | ret_val = e1000_config_fc_after_link_up(hw); | 
|  | 1355 | if (ret_val) { | 
|  | 1356 | DEBUGOUT("Error Configuring Flow Control\n"); | 
|  | 1357 | return ret_val; | 
|  | 1358 | } | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1359 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1360 | /* Config DSP to improve Giga link quality */ | 
|  | 1361 | if (hw->phy_type == e1000_phy_igp) { | 
|  | 1362 | ret_val = e1000_config_dsp_after_link_change(hw, true); | 
|  | 1363 | if (ret_val) { | 
|  | 1364 | DEBUGOUT("Error Configuring DSP after link up\n"); | 
|  | 1365 | return ret_val; | 
|  | 1366 | } | 
|  | 1367 | } | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1368 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1369 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1370 | } | 
|  | 1371 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1372 | /** | 
|  | 1373 | * e1000_setup_copper_link - phy/speed/duplex setting | 
|  | 1374 | * @hw: Struct containing variables accessed by shared code | 
|  | 1375 | * | 
|  | 1376 | * Detects which PHY is present and sets up the speed and duplex | 
|  | 1377 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1378 | static s32 e1000_setup_copper_link(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1379 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1380 | s32 ret_val; | 
|  | 1381 | u16 i; | 
|  | 1382 | u16 phy_data; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1383 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1384 | DEBUGFUNC("e1000_setup_copper_link"); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1385 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1386 | /* Check if it is a valid PHY and set PHY mode if necessary. */ | 
|  | 1387 | ret_val = e1000_copper_link_preconfig(hw); | 
|  | 1388 | if (ret_val) | 
|  | 1389 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1390 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1391 | if (hw->phy_type == e1000_phy_igp) { | 
|  | 1392 | ret_val = e1000_copper_link_igp_setup(hw); | 
|  | 1393 | if (ret_val) | 
|  | 1394 | return ret_val; | 
|  | 1395 | } else if (hw->phy_type == e1000_phy_m88) { | 
|  | 1396 | ret_val = e1000_copper_link_mgp_setup(hw); | 
|  | 1397 | if (ret_val) | 
|  | 1398 | return ret_val; | 
|  | 1399 | } | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1400 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1401 | if (hw->autoneg) { | 
|  | 1402 | /* Setup autoneg and flow control advertisement | 
|  | 1403 | * and perform autonegotiation */ | 
|  | 1404 | ret_val = e1000_copper_link_autoneg(hw); | 
|  | 1405 | if (ret_val) | 
|  | 1406 | return ret_val; | 
|  | 1407 | } else { | 
|  | 1408 | /* PHY will be set to 10H, 10F, 100H,or 100F | 
|  | 1409 | * depending on value from forced_speed_duplex. */ | 
|  | 1410 | DEBUGOUT("Forcing speed and duplex\n"); | 
|  | 1411 | ret_val = e1000_phy_force_speed_duplex(hw); | 
|  | 1412 | if (ret_val) { | 
|  | 1413 | DEBUGOUT("Error Forcing Speed and Duplex\n"); | 
|  | 1414 | return ret_val; | 
|  | 1415 | } | 
|  | 1416 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1418 | /* Check link status. Wait up to 100 microseconds for link to become | 
|  | 1419 | * valid. | 
|  | 1420 | */ | 
|  | 1421 | for (i = 0; i < 10; i++) { | 
|  | 1422 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 1423 | if (ret_val) | 
|  | 1424 | return ret_val; | 
|  | 1425 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 1426 | if (ret_val) | 
|  | 1427 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1429 | if (phy_data & MII_SR_LINK_STATUS) { | 
|  | 1430 | /* Config the MAC and PHY after link is up */ | 
|  | 1431 | ret_val = e1000_copper_link_postconfig(hw); | 
|  | 1432 | if (ret_val) | 
|  | 1433 | return ret_val; | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1434 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1435 | DEBUGOUT("Valid link established!!!\n"); | 
|  | 1436 | return E1000_SUCCESS; | 
|  | 1437 | } | 
|  | 1438 | udelay(10); | 
|  | 1439 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1441 | DEBUGOUT("Unable to establish link!!!\n"); | 
|  | 1442 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | } | 
|  | 1444 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1445 | /** | 
|  | 1446 | * e1000_phy_setup_autoneg - phy settings | 
|  | 1447 | * @hw: Struct containing variables accessed by shared code | 
|  | 1448 | * | 
|  | 1449 | * Configures PHY autoneg and flow control advertisement settings | 
|  | 1450 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1451 | s32 e1000_phy_setup_autoneg(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1453 | s32 ret_val; | 
|  | 1454 | u16 mii_autoneg_adv_reg; | 
|  | 1455 | u16 mii_1000t_ctrl_reg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1457 | DEBUGFUNC("e1000_phy_setup_autoneg"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1459 | /* Read the MII Auto-Neg Advertisement Register (Address 4). */ | 
|  | 1460 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg); | 
|  | 1461 | if (ret_val) | 
|  | 1462 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1464 | /* Read the MII 1000Base-T Control Register (Address 9). */ | 
|  | 1465 | ret_val = | 
|  | 1466 | e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg); | 
|  | 1467 | if (ret_val) | 
|  | 1468 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1470 | /* Need to parse both autoneg_advertised and fc and set up | 
|  | 1471 | * the appropriate PHY registers.  First we will parse for | 
|  | 1472 | * autoneg_advertised software override.  Since we can advertise | 
|  | 1473 | * a plethora of combinations, we need to check each bit | 
|  | 1474 | * individually. | 
|  | 1475 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1477 | /* First we clear all the 10/100 mb speed bits in the Auto-Neg | 
|  | 1478 | * Advertisement Register (Address 4) and the 1000 mb speed bits in | 
|  | 1479 | * the  1000Base-T Control Register (Address 9). | 
|  | 1480 | */ | 
|  | 1481 | mii_autoneg_adv_reg &= ~REG4_SPEED_MASK; | 
|  | 1482 | mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1484 | DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1486 | /* Do we want to advertise 10 Mb Half Duplex? */ | 
|  | 1487 | if (hw->autoneg_advertised & ADVERTISE_10_HALF) { | 
|  | 1488 | DEBUGOUT("Advertise 10mb Half duplex\n"); | 
|  | 1489 | mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS; | 
|  | 1490 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1492 | /* Do we want to advertise 10 Mb Full Duplex? */ | 
|  | 1493 | if (hw->autoneg_advertised & ADVERTISE_10_FULL) { | 
|  | 1494 | DEBUGOUT("Advertise 10mb Full duplex\n"); | 
|  | 1495 | mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS; | 
|  | 1496 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1498 | /* Do we want to advertise 100 Mb Half Duplex? */ | 
|  | 1499 | if (hw->autoneg_advertised & ADVERTISE_100_HALF) { | 
|  | 1500 | DEBUGOUT("Advertise 100mb Half duplex\n"); | 
|  | 1501 | mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS; | 
|  | 1502 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1504 | /* Do we want to advertise 100 Mb Full Duplex? */ | 
|  | 1505 | if (hw->autoneg_advertised & ADVERTISE_100_FULL) { | 
|  | 1506 | DEBUGOUT("Advertise 100mb Full duplex\n"); | 
|  | 1507 | mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS; | 
|  | 1508 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1510 | /* We do not allow the Phy to advertise 1000 Mb Half Duplex */ | 
|  | 1511 | if (hw->autoneg_advertised & ADVERTISE_1000_HALF) { | 
|  | 1512 | DEBUGOUT | 
|  | 1513 | ("Advertise 1000mb Half duplex requested, request denied!\n"); | 
|  | 1514 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1516 | /* Do we want to advertise 1000 Mb Full Duplex? */ | 
|  | 1517 | if (hw->autoneg_advertised & ADVERTISE_1000_FULL) { | 
|  | 1518 | DEBUGOUT("Advertise 1000mb Full duplex\n"); | 
|  | 1519 | mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS; | 
|  | 1520 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1522 | /* Check for a software override of the flow control settings, and | 
|  | 1523 | * setup the PHY advertisement registers accordingly.  If | 
|  | 1524 | * auto-negotiation is enabled, then software will have to set the | 
|  | 1525 | * "PAUSE" bits to the correct value in the Auto-Negotiation | 
|  | 1526 | * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation. | 
|  | 1527 | * | 
|  | 1528 | * The possible values of the "fc" parameter are: | 
|  | 1529 | *      0:  Flow control is completely disabled | 
|  | 1530 | *      1:  Rx flow control is enabled (we can receive pause frames | 
|  | 1531 | *          but not send pause frames). | 
|  | 1532 | *      2:  Tx flow control is enabled (we can send pause frames | 
|  | 1533 | *          but we do not support receiving pause frames). | 
|  | 1534 | *      3:  Both Rx and TX flow control (symmetric) are enabled. | 
|  | 1535 | *  other:  No software override.  The flow control configuration | 
|  | 1536 | *          in the EEPROM is used. | 
|  | 1537 | */ | 
|  | 1538 | switch (hw->fc) { | 
|  | 1539 | case E1000_FC_NONE:	/* 0 */ | 
|  | 1540 | /* Flow control (RX & TX) is completely disabled by a | 
|  | 1541 | * software over-ride. | 
|  | 1542 | */ | 
|  | 1543 | mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); | 
|  | 1544 | break; | 
|  | 1545 | case E1000_FC_RX_PAUSE:	/* 1 */ | 
|  | 1546 | /* RX Flow control is enabled, and TX Flow control is | 
|  | 1547 | * disabled, by a software over-ride. | 
|  | 1548 | */ | 
|  | 1549 | /* Since there really isn't a way to advertise that we are | 
|  | 1550 | * capable of RX Pause ONLY, we will advertise that we | 
|  | 1551 | * support both symmetric and asymmetric RX PAUSE.  Later | 
|  | 1552 | * (in e1000_config_fc_after_link_up) we will disable the | 
|  | 1553 | *hw's ability to send PAUSE frames. | 
|  | 1554 | */ | 
|  | 1555 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); | 
|  | 1556 | break; | 
|  | 1557 | case E1000_FC_TX_PAUSE:	/* 2 */ | 
|  | 1558 | /* TX Flow control is enabled, and RX Flow control is | 
|  | 1559 | * disabled, by a software over-ride. | 
|  | 1560 | */ | 
|  | 1561 | mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR; | 
|  | 1562 | mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE; | 
|  | 1563 | break; | 
|  | 1564 | case E1000_FC_FULL:	/* 3 */ | 
|  | 1565 | /* Flow control (both RX and TX) is enabled by a software | 
|  | 1566 | * over-ride. | 
|  | 1567 | */ | 
|  | 1568 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); | 
|  | 1569 | break; | 
|  | 1570 | default: | 
|  | 1571 | DEBUGOUT("Flow control param set incorrectly\n"); | 
|  | 1572 | return -E1000_ERR_CONFIG; | 
|  | 1573 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1575 | ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg); | 
|  | 1576 | if (ret_val) | 
|  | 1577 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1579 | DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1581 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg); | 
|  | 1582 | if (ret_val) | 
|  | 1583 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1585 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | } | 
|  | 1587 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1588 | /** | 
|  | 1589 | * e1000_phy_force_speed_duplex - force link settings | 
|  | 1590 | * @hw: Struct containing variables accessed by shared code | 
|  | 1591 | * | 
|  | 1592 | * Force PHY speed and duplex settings to hw->forced_speed_duplex | 
|  | 1593 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1594 | static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1596 | u32 ctrl; | 
|  | 1597 | s32 ret_val; | 
|  | 1598 | u16 mii_ctrl_reg; | 
|  | 1599 | u16 mii_status_reg; | 
|  | 1600 | u16 phy_data; | 
|  | 1601 | u16 i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1603 | DEBUGFUNC("e1000_phy_force_speed_duplex"); | 
| 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 | /* Turn off Flow control if we are forcing speed and duplex. */ | 
|  | 1606 | hw->fc = E1000_FC_NONE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1608 | DEBUGOUT1("hw->fc = %d\n", hw->fc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1610 | /* Read the Device Control Register. */ | 
|  | 1611 | ctrl = er32(CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1613 | /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */ | 
|  | 1614 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); | 
|  | 1615 | ctrl &= ~(DEVICE_SPEED_MASK); | 
| 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 | /* Clear the Auto Speed Detect Enable bit. */ | 
|  | 1618 | ctrl &= ~E1000_CTRL_ASDE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1620 | /* Read the MII Control Register. */ | 
|  | 1621 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg); | 
|  | 1622 | if (ret_val) | 
|  | 1623 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1625 | /* We need to disable autoneg in order to force link and duplex. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1627 | mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1629 | /* Are we forcing Full or Half Duplex? */ | 
|  | 1630 | if (hw->forced_speed_duplex == e1000_100_full || | 
|  | 1631 | hw->forced_speed_duplex == e1000_10_full) { | 
|  | 1632 | /* We want to force full duplex so we SET the full duplex bits in the | 
|  | 1633 | * Device and MII Control Registers. | 
|  | 1634 | */ | 
|  | 1635 | ctrl |= E1000_CTRL_FD; | 
|  | 1636 | mii_ctrl_reg |= MII_CR_FULL_DUPLEX; | 
|  | 1637 | DEBUGOUT("Full Duplex\n"); | 
|  | 1638 | } else { | 
|  | 1639 | /* We want to force half duplex so we CLEAR the full duplex bits in | 
|  | 1640 | * the Device and MII Control Registers. | 
|  | 1641 | */ | 
|  | 1642 | ctrl &= ~E1000_CTRL_FD; | 
|  | 1643 | mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX; | 
|  | 1644 | DEBUGOUT("Half Duplex\n"); | 
|  | 1645 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1647 | /* Are we forcing 100Mbps??? */ | 
|  | 1648 | if (hw->forced_speed_duplex == e1000_100_full || | 
|  | 1649 | hw->forced_speed_duplex == e1000_100_half) { | 
|  | 1650 | /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */ | 
|  | 1651 | ctrl |= E1000_CTRL_SPD_100; | 
|  | 1652 | mii_ctrl_reg |= MII_CR_SPEED_100; | 
|  | 1653 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10); | 
|  | 1654 | DEBUGOUT("Forcing 100mb "); | 
|  | 1655 | } else { | 
|  | 1656 | /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */ | 
|  | 1657 | ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100); | 
|  | 1658 | mii_ctrl_reg |= MII_CR_SPEED_10; | 
|  | 1659 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100); | 
|  | 1660 | DEBUGOUT("Forcing 10mb "); | 
|  | 1661 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1663 | e1000_config_collision_dist(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1665 | /* Write the configured values back to the Device Control Reg. */ | 
|  | 1666 | ew32(CTRL, ctrl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1668 | if (hw->phy_type == e1000_phy_m88) { | 
|  | 1669 | ret_val = | 
|  | 1670 | e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); | 
|  | 1671 | if (ret_val) | 
|  | 1672 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1674 | /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI | 
|  | 1675 | * forced whenever speed are duplex are forced. | 
|  | 1676 | */ | 
|  | 1677 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; | 
|  | 1678 | ret_val = | 
|  | 1679 | e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); | 
|  | 1680 | if (ret_val) | 
|  | 1681 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1683 | DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1685 | /* Need to reset the PHY or these changes will be ignored */ | 
|  | 1686 | mii_ctrl_reg |= MII_CR_RESET; | 
| Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 1687 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1688 | /* Disable MDI-X support for 10/100 */ | 
|  | 1689 | } else { | 
|  | 1690 | /* Clear Auto-Crossover to force MDI manually.  IGP requires MDI | 
|  | 1691 | * forced whenever speed or duplex are forced. | 
|  | 1692 | */ | 
|  | 1693 | ret_val = | 
|  | 1694 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); | 
|  | 1695 | if (ret_val) | 
|  | 1696 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1698 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; | 
|  | 1699 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1701 | ret_val = | 
|  | 1702 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); | 
|  | 1703 | if (ret_val) | 
|  | 1704 | return ret_val; | 
|  | 1705 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1707 | /* Write back the modified PHY MII control register. */ | 
|  | 1708 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg); | 
|  | 1709 | if (ret_val) | 
|  | 1710 | return ret_val; | 
| 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 | udelay(1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1714 | /* The wait_autoneg_complete flag may be a little misleading here. | 
|  | 1715 | * Since we are forcing speed and duplex, Auto-Neg is not enabled. | 
|  | 1716 | * But we do want to delay for a period while forcing only so we | 
|  | 1717 | * don't generate false No Link messages.  So we will wait here | 
|  | 1718 | * only if the user has set wait_autoneg_complete to 1, which is | 
|  | 1719 | * the default. | 
|  | 1720 | */ | 
|  | 1721 | if (hw->wait_autoneg_complete) { | 
|  | 1722 | /* We will wait for autoneg to complete. */ | 
|  | 1723 | DEBUGOUT("Waiting for forced speed/duplex link.\n"); | 
|  | 1724 | mii_status_reg = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1726 | /* We will wait for autoneg to complete or 4.5 seconds to expire. */ | 
|  | 1727 | for (i = PHY_FORCE_TIME; i > 0; i--) { | 
|  | 1728 | /* Read the MII Status Register and wait for Auto-Neg Complete bit | 
|  | 1729 | * to be set. | 
|  | 1730 | */ | 
|  | 1731 | ret_val = | 
|  | 1732 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 1733 | if (ret_val) | 
|  | 1734 | return ret_val; | 
| 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 | ret_val = | 
|  | 1737 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 1738 | if (ret_val) | 
|  | 1739 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1741 | if (mii_status_reg & MII_SR_LINK_STATUS) | 
|  | 1742 | break; | 
|  | 1743 | msleep(100); | 
|  | 1744 | } | 
|  | 1745 | if ((i == 0) && (hw->phy_type == e1000_phy_m88)) { | 
|  | 1746 | /* We didn't get link.  Reset the DSP and wait again for link. */ | 
|  | 1747 | ret_val = e1000_phy_reset_dsp(hw); | 
|  | 1748 | if (ret_val) { | 
|  | 1749 | DEBUGOUT("Error Resetting PHY DSP\n"); | 
|  | 1750 | return ret_val; | 
|  | 1751 | } | 
|  | 1752 | } | 
|  | 1753 | /* This loop will early-out if the link condition has been met.  */ | 
|  | 1754 | for (i = PHY_FORCE_TIME; i > 0; i--) { | 
|  | 1755 | if (mii_status_reg & MII_SR_LINK_STATUS) | 
|  | 1756 | break; | 
|  | 1757 | msleep(100); | 
|  | 1758 | /* Read the MII Status Register and wait for Auto-Neg Complete bit | 
|  | 1759 | * to be set. | 
|  | 1760 | */ | 
|  | 1761 | ret_val = | 
|  | 1762 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 1763 | if (ret_val) | 
|  | 1764 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1766 | ret_val = | 
|  | 1767 | e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 1768 | if (ret_val) | 
|  | 1769 | return ret_val; | 
|  | 1770 | } | 
|  | 1771 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1773 | if (hw->phy_type == e1000_phy_m88) { | 
|  | 1774 | /* Because we reset the PHY above, we need to re-force TX_CLK in the | 
|  | 1775 | * Extended PHY Specific Control Register to 25MHz clock.  This value | 
|  | 1776 | * defaults back to a 2.5MHz clock when the PHY is reset. | 
|  | 1777 | */ | 
|  | 1778 | ret_val = | 
|  | 1779 | e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, | 
|  | 1780 | &phy_data); | 
|  | 1781 | if (ret_val) | 
|  | 1782 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1784 | phy_data |= M88E1000_EPSCR_TX_CLK_25; | 
|  | 1785 | ret_val = | 
|  | 1786 | e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, | 
|  | 1787 | phy_data); | 
|  | 1788 | if (ret_val) | 
|  | 1789 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1791 | /* In addition, because of the s/w reset above, we need to enable CRS on | 
|  | 1792 | * TX.  This must be set for both full and half duplex operation. | 
|  | 1793 | */ | 
|  | 1794 | ret_val = | 
|  | 1795 | e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); | 
|  | 1796 | if (ret_val) | 
|  | 1797 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1799 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; | 
|  | 1800 | ret_val = | 
|  | 1801 | e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_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 | if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) | 
|  | 1806 | && (!hw->autoneg) | 
|  | 1807 | && (hw->forced_speed_duplex == e1000_10_full | 
|  | 1808 | || hw->forced_speed_duplex == e1000_10_half)) { | 
|  | 1809 | ret_val = e1000_polarity_reversal_workaround(hw); | 
|  | 1810 | if (ret_val) | 
|  | 1811 | return ret_val; | 
|  | 1812 | } | 
|  | 1813 | } | 
|  | 1814 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | } | 
|  | 1816 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1817 | /** | 
|  | 1818 | * e1000_config_collision_dist - set collision distance register | 
|  | 1819 | * @hw: Struct containing variables accessed by shared code | 
|  | 1820 | * | 
|  | 1821 | * Sets the collision distance in the Transmit Control register. | 
|  | 1822 | * Link should have been established previously. Reads the speed and duplex | 
|  | 1823 | * information from the Device Status register. | 
|  | 1824 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1825 | void e1000_config_collision_dist(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1827 | u32 tctl, coll_dist; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1829 | DEBUGFUNC("e1000_config_collision_dist"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1831 | if (hw->mac_type < e1000_82543) | 
|  | 1832 | coll_dist = E1000_COLLISION_DISTANCE_82542; | 
|  | 1833 | else | 
|  | 1834 | coll_dist = E1000_COLLISION_DISTANCE; | 
| Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1835 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1836 | tctl = er32(TCTL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1838 | tctl &= ~E1000_TCTL_COLD; | 
|  | 1839 | tctl |= coll_dist << E1000_COLD_SHIFT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1841 | ew32(TCTL, tctl); | 
|  | 1842 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | } | 
|  | 1844 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1845 | /** | 
|  | 1846 | * e1000_config_mac_to_phy - sync phy and mac settings | 
|  | 1847 | * @hw: Struct containing variables accessed by shared code | 
|  | 1848 | * @mii_reg: data to write to the MII control register | 
|  | 1849 | * | 
|  | 1850 | * Sets MAC speed and duplex settings to reflect the those in the PHY | 
|  | 1851 | * The contents of the PHY register containing the needed information need to | 
|  | 1852 | * be passed in. | 
|  | 1853 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1854 | static s32 e1000_config_mac_to_phy(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1856 | u32 ctrl; | 
|  | 1857 | s32 ret_val; | 
|  | 1858 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1860 | DEBUGFUNC("e1000_config_mac_to_phy"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1862 | /* 82544 or newer MAC, Auto Speed Detection takes care of | 
|  | 1863 | * MAC speed/duplex configuration.*/ | 
|  | 1864 | if (hw->mac_type >= e1000_82544) | 
|  | 1865 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1866 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1867 | /* Read the Device Control Register and set the bits to Force Speed | 
|  | 1868 | * and Duplex. | 
|  | 1869 | */ | 
|  | 1870 | ctrl = er32(CTRL); | 
|  | 1871 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); | 
|  | 1872 | ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1874 | /* Set up duplex in the Device Control and Transmit Control | 
|  | 1875 | * registers depending on negotiated values. | 
|  | 1876 | */ | 
|  | 1877 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); | 
|  | 1878 | if (ret_val) | 
|  | 1879 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1881 | if (phy_data & M88E1000_PSSR_DPLX) | 
|  | 1882 | ctrl |= E1000_CTRL_FD; | 
|  | 1883 | else | 
|  | 1884 | ctrl &= ~E1000_CTRL_FD; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1886 | e1000_config_collision_dist(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1888 | /* Set up speed in the Device Control register depending on | 
|  | 1889 | * negotiated values. | 
|  | 1890 | */ | 
|  | 1891 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) | 
|  | 1892 | ctrl |= E1000_CTRL_SPD_1000; | 
|  | 1893 | else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS) | 
|  | 1894 | ctrl |= E1000_CTRL_SPD_100; | 
| 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 | /* Write the configured values back to the Device Control Reg. */ | 
|  | 1897 | ew32(CTRL, ctrl); | 
|  | 1898 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | } | 
|  | 1900 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1901 | /** | 
|  | 1902 | * e1000_force_mac_fc - force flow control settings | 
|  | 1903 | * @hw: Struct containing variables accessed by shared code | 
|  | 1904 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | * Forces the MAC's flow control settings. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | * Sets the TFCE and RFCE bits in the device control register to reflect | 
|  | 1907 | * the adapter settings. TFCE and RFCE need to be explicitly set by | 
|  | 1908 | * software when a Copper PHY is used because autonegotiation is managed | 
|  | 1909 | * by the PHY rather than the MAC. Software must also configure these | 
|  | 1910 | * bits when link is forced on a fiber connection. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1911 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1912 | s32 e1000_force_mac_fc(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1914 | u32 ctrl; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1916 | DEBUGFUNC("e1000_force_mac_fc"); | 
| 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 | /* Get the current configuration of the Device Control Register */ | 
|  | 1919 | ctrl = er32(CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1921 | /* Because we didn't get link via the internal auto-negotiation | 
|  | 1922 | * mechanism (we either forced link or we got link via PHY | 
|  | 1923 | * auto-neg), we have to manually enable/disable transmit an | 
|  | 1924 | * receive flow control. | 
|  | 1925 | * | 
|  | 1926 | * The "Case" statement below enables/disable flow control | 
|  | 1927 | * according to the "hw->fc" parameter. | 
|  | 1928 | * | 
|  | 1929 | * The possible values of the "fc" parameter are: | 
|  | 1930 | *      0:  Flow control is completely disabled | 
|  | 1931 | *      1:  Rx flow control is enabled (we can receive pause | 
|  | 1932 | *          frames but not send pause frames). | 
|  | 1933 | *      2:  Tx flow control is enabled (we can send pause frames | 
|  | 1934 | *          frames but we do not receive pause frames). | 
|  | 1935 | *      3:  Both Rx and TX flow control (symmetric) is enabled. | 
|  | 1936 | *  other:  No other values should be possible at this point. | 
|  | 1937 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1939 | switch (hw->fc) { | 
|  | 1940 | case E1000_FC_NONE: | 
|  | 1941 | ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); | 
|  | 1942 | break; | 
|  | 1943 | case E1000_FC_RX_PAUSE: | 
|  | 1944 | ctrl &= (~E1000_CTRL_TFCE); | 
|  | 1945 | ctrl |= E1000_CTRL_RFCE; | 
|  | 1946 | break; | 
|  | 1947 | case E1000_FC_TX_PAUSE: | 
|  | 1948 | ctrl &= (~E1000_CTRL_RFCE); | 
|  | 1949 | ctrl |= E1000_CTRL_TFCE; | 
|  | 1950 | break; | 
|  | 1951 | case E1000_FC_FULL: | 
|  | 1952 | ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); | 
|  | 1953 | break; | 
|  | 1954 | default: | 
|  | 1955 | DEBUGOUT("Flow control param set incorrectly\n"); | 
|  | 1956 | return -E1000_ERR_CONFIG; | 
|  | 1957 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1959 | /* Disable TX Flow Control for 82542 (rev 2.0) */ | 
|  | 1960 | if (hw->mac_type == e1000_82542_rev2_0) | 
|  | 1961 | ctrl &= (~E1000_CTRL_TFCE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1963 | ew32(CTRL, ctrl); | 
|  | 1964 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | } | 
|  | 1966 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1967 | /** | 
|  | 1968 | * e1000_config_fc_after_link_up - configure flow control after autoneg | 
|  | 1969 | * @hw: Struct containing variables accessed by shared code | 
|  | 1970 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | * Configures flow control settings after link is established | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | * Should be called immediately after a valid link has been established. | 
|  | 1973 | * Forces MAC flow control settings if link was forced. When in MII/GMII mode | 
|  | 1974 | * and autonegotiation is enabled, the MAC flow control settings will be set | 
|  | 1975 | * 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] | 1976 | * and RFCE bits will be automatically set to the negotiated flow control mode. | 
|  | 1977 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1978 | static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1980 | s32 ret_val; | 
|  | 1981 | u16 mii_status_reg; | 
|  | 1982 | u16 mii_nway_adv_reg; | 
|  | 1983 | u16 mii_nway_lp_ability_reg; | 
|  | 1984 | u16 speed; | 
|  | 1985 | u16 duplex; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1987 | DEBUGFUNC("e1000_config_fc_after_link_up"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 1989 | /* Check for the case where we have fiber media and auto-neg failed | 
|  | 1990 | * so we had to force link.  In this case, we need to force the | 
|  | 1991 | * configuration of the MAC to match the "fc" parameter. | 
|  | 1992 | */ | 
|  | 1993 | if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) | 
|  | 1994 | || ((hw->media_type == e1000_media_type_internal_serdes) | 
|  | 1995 | && (hw->autoneg_failed)) | 
|  | 1996 | || ((hw->media_type == e1000_media_type_copper) | 
|  | 1997 | && (!hw->autoneg))) { | 
|  | 1998 | ret_val = e1000_force_mac_fc(hw); | 
|  | 1999 | if (ret_val) { | 
|  | 2000 | DEBUGOUT("Error forcing flow control settings\n"); | 
|  | 2001 | return ret_val; | 
|  | 2002 | } | 
|  | 2003 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2005 | /* Check for the case where we have copper media and auto-neg is | 
|  | 2006 | * enabled.  In this case, we need to check and see if Auto-Neg | 
|  | 2007 | * has completed, and if so, how the PHY and link partner has | 
|  | 2008 | * flow control configured. | 
|  | 2009 | */ | 
|  | 2010 | if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) { | 
|  | 2011 | /* Read the MII Status Register and check to see if AutoNeg | 
|  | 2012 | * has completed.  We read this twice because this reg has | 
|  | 2013 | * some "sticky" (latched) bits. | 
|  | 2014 | */ | 
|  | 2015 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 2016 | if (ret_val) | 
|  | 2017 | return ret_val; | 
|  | 2018 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 2019 | if (ret_val) | 
|  | 2020 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2022 | if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) { | 
|  | 2023 | /* The AutoNeg process has completed, so we now need to | 
|  | 2024 | * read both the Auto Negotiation Advertisement Register | 
|  | 2025 | * (Address 4) and the Auto_Negotiation Base Page Ability | 
|  | 2026 | * Register (Address 5) to determine how flow control was | 
|  | 2027 | * negotiated. | 
|  | 2028 | */ | 
|  | 2029 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, | 
|  | 2030 | &mii_nway_adv_reg); | 
|  | 2031 | if (ret_val) | 
|  | 2032 | return ret_val; | 
|  | 2033 | ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, | 
|  | 2034 | &mii_nway_lp_ability_reg); | 
|  | 2035 | if (ret_val) | 
|  | 2036 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2038 | /* Two bits in the Auto Negotiation Advertisement Register | 
|  | 2039 | * (Address 4) and two bits in the Auto Negotiation Base | 
|  | 2040 | * Page Ability Register (Address 5) determine flow control | 
|  | 2041 | * for both the PHY and the link partner.  The following | 
|  | 2042 | * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, | 
|  | 2043 | * 1999, describes these PAUSE resolution bits and how flow | 
|  | 2044 | * control is determined based upon these settings. | 
|  | 2045 | * NOTE:  DC = Don't Care | 
|  | 2046 | * | 
|  | 2047 | *   LOCAL DEVICE  |   LINK PARTNER | 
|  | 2048 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution | 
|  | 2049 | *-------|---------|-------|---------|-------------------- | 
|  | 2050 | *   0   |    0    |  DC   |   DC    | E1000_FC_NONE | 
|  | 2051 | *   0   |    1    |   0   |   DC    | E1000_FC_NONE | 
|  | 2052 | *   0   |    1    |   1   |    0    | E1000_FC_NONE | 
|  | 2053 | *   0   |    1    |   1   |    1    | E1000_FC_TX_PAUSE | 
|  | 2054 | *   1   |    0    |   0   |   DC    | E1000_FC_NONE | 
|  | 2055 | *   1   |   DC    |   1   |   DC    | E1000_FC_FULL | 
|  | 2056 | *   1   |    1    |   0   |    0    | E1000_FC_NONE | 
|  | 2057 | *   1   |    1    |   0   |    1    | E1000_FC_RX_PAUSE | 
|  | 2058 | * | 
|  | 2059 | */ | 
|  | 2060 | /* Are both PAUSE bits set to 1?  If so, this implies | 
|  | 2061 | * Symmetric Flow Control is enabled at both ends.  The | 
|  | 2062 | * ASM_DIR bits are irrelevant per the spec. | 
|  | 2063 | * | 
|  | 2064 | * For Symmetric Flow Control: | 
|  | 2065 | * | 
|  | 2066 | *   LOCAL DEVICE  |   LINK PARTNER | 
|  | 2067 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result | 
|  | 2068 | *-------|---------|-------|---------|-------------------- | 
|  | 2069 | *   1   |   DC    |   1   |   DC    | E1000_FC_FULL | 
|  | 2070 | * | 
|  | 2071 | */ | 
|  | 2072 | if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && | 
|  | 2073 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { | 
|  | 2074 | /* Now we need to check if the user selected RX ONLY | 
|  | 2075 | * of pause frames.  In this case, we had to advertise | 
|  | 2076 | * FULL flow control because we could not advertise RX | 
|  | 2077 | * ONLY. Hence, we must now check to see if we need to | 
|  | 2078 | * turn OFF  the TRANSMISSION of PAUSE frames. | 
|  | 2079 | */ | 
|  | 2080 | if (hw->original_fc == E1000_FC_FULL) { | 
|  | 2081 | hw->fc = E1000_FC_FULL; | 
|  | 2082 | DEBUGOUT("Flow Control = FULL.\n"); | 
|  | 2083 | } else { | 
|  | 2084 | hw->fc = E1000_FC_RX_PAUSE; | 
|  | 2085 | DEBUGOUT | 
|  | 2086 | ("Flow Control = RX PAUSE frames only.\n"); | 
|  | 2087 | } | 
|  | 2088 | } | 
|  | 2089 | /* For receiving PAUSE frames ONLY. | 
|  | 2090 | * | 
|  | 2091 | *   LOCAL DEVICE  |   LINK PARTNER | 
|  | 2092 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result | 
|  | 2093 | *-------|---------|-------|---------|-------------------- | 
|  | 2094 | *   0   |    1    |   1   |    1    | E1000_FC_TX_PAUSE | 
|  | 2095 | * | 
|  | 2096 | */ | 
|  | 2097 | else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && | 
|  | 2098 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && | 
|  | 2099 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && | 
|  | 2100 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) | 
|  | 2101 | { | 
|  | 2102 | hw->fc = E1000_FC_TX_PAUSE; | 
|  | 2103 | DEBUGOUT | 
|  | 2104 | ("Flow Control = TX PAUSE frames only.\n"); | 
|  | 2105 | } | 
|  | 2106 | /* For transmitting PAUSE frames ONLY. | 
|  | 2107 | * | 
|  | 2108 | *   LOCAL DEVICE  |   LINK PARTNER | 
|  | 2109 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result | 
|  | 2110 | *-------|---------|-------|---------|-------------------- | 
|  | 2111 | *   1   |    1    |   0   |    1    | E1000_FC_RX_PAUSE | 
|  | 2112 | * | 
|  | 2113 | */ | 
|  | 2114 | else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && | 
|  | 2115 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && | 
|  | 2116 | !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && | 
|  | 2117 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) | 
|  | 2118 | { | 
|  | 2119 | hw->fc = E1000_FC_RX_PAUSE; | 
|  | 2120 | DEBUGOUT | 
|  | 2121 | ("Flow Control = RX PAUSE frames only.\n"); | 
|  | 2122 | } | 
|  | 2123 | /* Per the IEEE spec, at this point flow control should be | 
|  | 2124 | * disabled.  However, we want to consider that we could | 
|  | 2125 | * be connected to a legacy switch that doesn't advertise | 
|  | 2126 | * desired flow control, but can be forced on the link | 
|  | 2127 | * partner.  So if we advertised no flow control, that is | 
|  | 2128 | * what we will resolve to.  If we advertised some kind of | 
|  | 2129 | * receive capability (Rx Pause Only or Full Flow Control) | 
|  | 2130 | * and the link partner advertised none, we will configure | 
|  | 2131 | * ourselves to enable Rx Flow Control only.  We can do | 
|  | 2132 | * this safely for two reasons:  If the link partner really | 
|  | 2133 | * didn't want flow control enabled, and we enable Rx, no | 
|  | 2134 | * harm done since we won't be receiving any PAUSE frames | 
|  | 2135 | * anyway.  If the intent on the link partner was to have | 
|  | 2136 | * flow control enabled, then by us enabling RX only, we | 
|  | 2137 | * can at least receive pause frames and process them. | 
|  | 2138 | * This is a good idea because in most cases, since we are | 
|  | 2139 | * predominantly a server NIC, more times than not we will | 
|  | 2140 | * be asked to delay transmission of packets than asking | 
|  | 2141 | * our link partner to pause transmission of frames. | 
|  | 2142 | */ | 
|  | 2143 | else if ((hw->original_fc == E1000_FC_NONE || | 
|  | 2144 | hw->original_fc == E1000_FC_TX_PAUSE) || | 
|  | 2145 | hw->fc_strict_ieee) { | 
|  | 2146 | hw->fc = E1000_FC_NONE; | 
|  | 2147 | DEBUGOUT("Flow Control = NONE.\n"); | 
|  | 2148 | } else { | 
|  | 2149 | hw->fc = E1000_FC_RX_PAUSE; | 
|  | 2150 | DEBUGOUT | 
|  | 2151 | ("Flow Control = RX PAUSE frames only.\n"); | 
|  | 2152 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2154 | /* Now we need to do one last check...  If we auto- | 
|  | 2155 | * negotiated to HALF DUPLEX, flow control should not be | 
|  | 2156 | * enabled per IEEE 802.3 spec. | 
|  | 2157 | */ | 
|  | 2158 | ret_val = | 
|  | 2159 | e1000_get_speed_and_duplex(hw, &speed, &duplex); | 
|  | 2160 | if (ret_val) { | 
|  | 2161 | DEBUGOUT | 
|  | 2162 | ("Error getting link speed and duplex\n"); | 
|  | 2163 | return ret_val; | 
|  | 2164 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2166 | if (duplex == HALF_DUPLEX) | 
|  | 2167 | hw->fc = E1000_FC_NONE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2169 | /* Now we call a subroutine to actually force the MAC | 
|  | 2170 | * controller to use the correct flow control settings. | 
|  | 2171 | */ | 
|  | 2172 | ret_val = e1000_force_mac_fc(hw); | 
|  | 2173 | if (ret_val) { | 
|  | 2174 | DEBUGOUT | 
|  | 2175 | ("Error forcing flow control settings\n"); | 
|  | 2176 | return ret_val; | 
|  | 2177 | } | 
|  | 2178 | } else { | 
|  | 2179 | DEBUGOUT | 
|  | 2180 | ("Copper PHY and Auto Neg has not completed.\n"); | 
|  | 2181 | } | 
|  | 2182 | } | 
|  | 2183 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | } | 
|  | 2185 |  | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2186 | /** | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2187 | * e1000_check_for_serdes_link_generic - Check for link (Serdes) | 
|  | 2188 | * @hw: pointer to the HW structure | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2189 | * | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2190 | * Checks for link up on the hardware.  If link is not up and we have | 
|  | 2191 | * a signal, then we need to force link up. | 
|  | 2192 | */ | 
| Jesse Brandeburg | 11b7f7b | 2009-09-25 12:20:33 +0000 | [diff] [blame] | 2193 | static s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw) | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2194 | { | 
|  | 2195 | u32 rxcw; | 
|  | 2196 | u32 ctrl; | 
|  | 2197 | u32 status; | 
|  | 2198 | s32 ret_val = E1000_SUCCESS; | 
|  | 2199 |  | 
|  | 2200 | DEBUGFUNC("e1000_check_for_serdes_link_generic"); | 
|  | 2201 |  | 
|  | 2202 | ctrl = er32(CTRL); | 
|  | 2203 | status = er32(STATUS); | 
|  | 2204 | rxcw = er32(RXCW); | 
|  | 2205 |  | 
|  | 2206 | /* | 
|  | 2207 | * If we don't have link (auto-negotiation failed or link partner | 
|  | 2208 | * cannot auto-negotiate), and our link partner is not trying to | 
|  | 2209 | * auto-negotiate with us (we are receiving idles or data), | 
|  | 2210 | * we need to force link up. We also need to give auto-negotiation | 
|  | 2211 | * time to complete. | 
|  | 2212 | */ | 
|  | 2213 | /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */ | 
|  | 2214 | if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) { | 
|  | 2215 | if (hw->autoneg_failed == 0) { | 
|  | 2216 | hw->autoneg_failed = 1; | 
|  | 2217 | goto out; | 
|  | 2218 | } | 
|  | 2219 | DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n"); | 
|  | 2220 |  | 
|  | 2221 | /* Disable auto-negotiation in the TXCW register */ | 
|  | 2222 | ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE)); | 
|  | 2223 |  | 
|  | 2224 | /* Force link-up and also force full-duplex. */ | 
|  | 2225 | ctrl = er32(CTRL); | 
|  | 2226 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); | 
|  | 2227 | ew32(CTRL, ctrl); | 
|  | 2228 |  | 
|  | 2229 | /* Configure Flow Control after forcing link up. */ | 
|  | 2230 | ret_val = e1000_config_fc_after_link_up(hw); | 
|  | 2231 | if (ret_val) { | 
|  | 2232 | DEBUGOUT("Error configuring flow control\n"); | 
|  | 2233 | goto out; | 
|  | 2234 | } | 
|  | 2235 | } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { | 
|  | 2236 | /* | 
|  | 2237 | * If we are forcing link and we are receiving /C/ ordered | 
|  | 2238 | * sets, re-enable auto-negotiation in the TXCW register | 
|  | 2239 | * and disable forced link in the Device Control register | 
|  | 2240 | * in an attempt to auto-negotiate with our link partner. | 
|  | 2241 | */ | 
|  | 2242 | DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n"); | 
|  | 2243 | ew32(TXCW, hw->txcw); | 
|  | 2244 | ew32(CTRL, (ctrl & ~E1000_CTRL_SLU)); | 
|  | 2245 |  | 
|  | 2246 | hw->serdes_has_link = true; | 
|  | 2247 | } else if (!(E1000_TXCW_ANE & er32(TXCW))) { | 
|  | 2248 | /* | 
|  | 2249 | * If we force link for non-auto-negotiation switch, check | 
|  | 2250 | * link status based on MAC synchronization for internal | 
|  | 2251 | * serdes media type. | 
|  | 2252 | */ | 
|  | 2253 | /* SYNCH bit and IV bit are sticky. */ | 
|  | 2254 | udelay(10); | 
|  | 2255 | rxcw = er32(RXCW); | 
|  | 2256 | if (rxcw & E1000_RXCW_SYNCH) { | 
|  | 2257 | if (!(rxcw & E1000_RXCW_IV)) { | 
|  | 2258 | hw->serdes_has_link = true; | 
|  | 2259 | DEBUGOUT("SERDES: Link up - forced.\n"); | 
|  | 2260 | } | 
|  | 2261 | } else { | 
|  | 2262 | hw->serdes_has_link = false; | 
|  | 2263 | DEBUGOUT("SERDES: Link down - force failed.\n"); | 
|  | 2264 | } | 
|  | 2265 | } | 
|  | 2266 |  | 
|  | 2267 | if (E1000_TXCW_ANE & er32(TXCW)) { | 
|  | 2268 | status = er32(STATUS); | 
|  | 2269 | if (status & E1000_STATUS_LU) { | 
|  | 2270 | /* SYNCH bit and IV bit are sticky, so reread rxcw. */ | 
|  | 2271 | udelay(10); | 
|  | 2272 | rxcw = er32(RXCW); | 
|  | 2273 | if (rxcw & E1000_RXCW_SYNCH) { | 
|  | 2274 | if (!(rxcw & E1000_RXCW_IV)) { | 
|  | 2275 | hw->serdes_has_link = true; | 
|  | 2276 | DEBUGOUT("SERDES: Link up - autoneg " | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2277 | "completed successfully.\n"); | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2278 | } else { | 
|  | 2279 | hw->serdes_has_link = false; | 
|  | 2280 | DEBUGOUT("SERDES: Link down - invalid" | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2281 | "codewords detected in autoneg.\n"); | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2282 | } | 
|  | 2283 | } else { | 
|  | 2284 | hw->serdes_has_link = false; | 
|  | 2285 | DEBUGOUT("SERDES: Link down - no sync.\n"); | 
|  | 2286 | } | 
|  | 2287 | } else { | 
|  | 2288 | hw->serdes_has_link = false; | 
|  | 2289 | DEBUGOUT("SERDES: Link down - autoneg failed\n"); | 
|  | 2290 | } | 
|  | 2291 | } | 
|  | 2292 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2293 | out: | 
| Jesse Brandeburg | be0f071 | 2009-09-25 12:17:44 +0000 | [diff] [blame] | 2294 | return ret_val; | 
|  | 2295 | } | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2296 |  | 
|  | 2297 | /** | 
|  | 2298 | * e1000_check_for_link | 
|  | 2299 | * @hw: Struct containing variables accessed by shared code | 
|  | 2300 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | * Checks to see if the link status of the hardware has changed. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | * 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] | 2303 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2304 | s32 e1000_check_for_link(struct e1000_hw *hw) | 
| 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 | u32 rxcw = 0; | 
|  | 2307 | u32 ctrl; | 
|  | 2308 | u32 status; | 
|  | 2309 | u32 rctl; | 
|  | 2310 | u32 icr; | 
|  | 2311 | u32 signal = 0; | 
|  | 2312 | s32 ret_val; | 
|  | 2313 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2315 | DEBUGFUNC("e1000_check_for_link"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2317 | ctrl = er32(CTRL); | 
|  | 2318 | status = er32(STATUS); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2320 | /* On adapters with a MAC newer than 82544, SW Definable pin 1 will be | 
|  | 2321 | * set when the optics detect a signal. On older adapters, it will be | 
|  | 2322 | * cleared when there is a signal.  This applies to fiber media only. | 
|  | 2323 | */ | 
|  | 2324 | if ((hw->media_type == e1000_media_type_fiber) || | 
|  | 2325 | (hw->media_type == e1000_media_type_internal_serdes)) { | 
|  | 2326 | rxcw = er32(RXCW); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2328 | if (hw->media_type == e1000_media_type_fiber) { | 
|  | 2329 | signal = | 
|  | 2330 | (hw->mac_type > | 
|  | 2331 | e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; | 
|  | 2332 | if (status & E1000_STATUS_LU) | 
|  | 2333 | hw->get_link_status = false; | 
|  | 2334 | } | 
|  | 2335 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2337 | /* If we have a copper PHY then we only want to go out to the PHY | 
|  | 2338 | * registers to see if Auto-Neg has completed and/or if our link | 
|  | 2339 | * status has changed.  The get_link_status flag will be set if we | 
|  | 2340 | * receive a Link Status Change interrupt or we have Rx Sequence | 
|  | 2341 | * Errors. | 
|  | 2342 | */ | 
|  | 2343 | if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) { | 
|  | 2344 | /* First we want to see if the MII Status Register reports | 
|  | 2345 | * link.  If so, then we want to get the current speed/duplex | 
|  | 2346 | * of the PHY. | 
|  | 2347 | * Read the register twice since the link bit is sticky. | 
|  | 2348 | */ | 
|  | 2349 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 2350 | if (ret_val) | 
|  | 2351 | return ret_val; | 
|  | 2352 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 2353 | if (ret_val) | 
|  | 2354 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2356 | if (phy_data & MII_SR_LINK_STATUS) { | 
|  | 2357 | hw->get_link_status = false; | 
|  | 2358 | /* Check if there was DownShift, must be checked immediately after | 
|  | 2359 | * link-up */ | 
|  | 2360 | e1000_check_downshift(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2362 | /* If we are on 82544 or 82543 silicon and speed/duplex | 
|  | 2363 | * are forced to 10H or 10F, then we will implement the polarity | 
|  | 2364 | * reversal workaround.  We disable interrupts first, and upon | 
|  | 2365 | * returning, place the devices interrupt state to its previous | 
|  | 2366 | * value except for the link status change interrupt which will | 
|  | 2367 | * happen due to the execution of this workaround. | 
|  | 2368 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2370 | if ((hw->mac_type == e1000_82544 | 
|  | 2371 | || hw->mac_type == e1000_82543) && (!hw->autoneg) | 
|  | 2372 | && (hw->forced_speed_duplex == e1000_10_full | 
|  | 2373 | || hw->forced_speed_duplex == e1000_10_half)) { | 
|  | 2374 | ew32(IMC, 0xffffffff); | 
|  | 2375 | ret_val = | 
|  | 2376 | e1000_polarity_reversal_workaround(hw); | 
|  | 2377 | icr = er32(ICR); | 
|  | 2378 | ew32(ICS, (icr & ~E1000_ICS_LSC)); | 
|  | 2379 | ew32(IMS, IMS_ENABLE_MASK); | 
|  | 2380 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2382 | } else { | 
|  | 2383 | /* No link detected */ | 
|  | 2384 | e1000_config_dsp_after_link_change(hw, false); | 
|  | 2385 | return 0; | 
|  | 2386 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2388 | /* If we are forcing speed/duplex, then we simply return since | 
|  | 2389 | * we have already determined whether we have link or not. | 
|  | 2390 | */ | 
|  | 2391 | if (!hw->autoneg) | 
|  | 2392 | return -E1000_ERR_CONFIG; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2394 | /* optimize the dsp settings for the igp phy */ | 
|  | 2395 | e1000_config_dsp_after_link_change(hw, true); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2397 | /* We have a M88E1000 PHY and Auto-Neg is enabled.  If we | 
|  | 2398 | * have Si on board that is 82544 or newer, Auto | 
|  | 2399 | * Speed Detection takes care of MAC speed/duplex | 
|  | 2400 | * configuration.  So we only need to configure Collision | 
|  | 2401 | * Distance in the MAC.  Otherwise, we need to force | 
|  | 2402 | * speed/duplex on the MAC to the current PHY speed/duplex | 
|  | 2403 | * settings. | 
|  | 2404 | */ | 
|  | 2405 | if (hw->mac_type >= e1000_82544) | 
|  | 2406 | e1000_config_collision_dist(hw); | 
|  | 2407 | else { | 
|  | 2408 | ret_val = e1000_config_mac_to_phy(hw); | 
|  | 2409 | if (ret_val) { | 
|  | 2410 | DEBUGOUT | 
|  | 2411 | ("Error configuring MAC to PHY settings\n"); | 
|  | 2412 | return ret_val; | 
|  | 2413 | } | 
|  | 2414 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2416 | /* Configure Flow Control now that Auto-Neg has completed. First, we | 
|  | 2417 | * need to restore the desired flow control settings because we may | 
|  | 2418 | * have had to re-autoneg with a different link partner. | 
|  | 2419 | */ | 
|  | 2420 | ret_val = e1000_config_fc_after_link_up(hw); | 
|  | 2421 | if (ret_val) { | 
|  | 2422 | DEBUGOUT("Error configuring flow control\n"); | 
|  | 2423 | return ret_val; | 
|  | 2424 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2426 | /* At this point we know that we are on copper and we have | 
|  | 2427 | * auto-negotiated link.  These are conditions for checking the link | 
|  | 2428 | * partner capability register.  We use the link speed to determine if | 
|  | 2429 | * TBI compatibility needs to be turned on or off.  If the link is not | 
|  | 2430 | * at gigabit speed, then TBI compatibility is not needed.  If we are | 
|  | 2431 | * at gigabit speed, we turn on TBI compatibility. | 
|  | 2432 | */ | 
|  | 2433 | if (hw->tbi_compatibility_en) { | 
|  | 2434 | u16 speed, duplex; | 
|  | 2435 | ret_val = | 
|  | 2436 | e1000_get_speed_and_duplex(hw, &speed, &duplex); | 
|  | 2437 | if (ret_val) { | 
|  | 2438 | DEBUGOUT | 
|  | 2439 | ("Error getting link speed and duplex\n"); | 
|  | 2440 | return ret_val; | 
|  | 2441 | } | 
|  | 2442 | if (speed != SPEED_1000) { | 
|  | 2443 | /* If link speed is not set to gigabit speed, we do not need | 
|  | 2444 | * to enable TBI compatibility. | 
|  | 2445 | */ | 
|  | 2446 | if (hw->tbi_compatibility_on) { | 
|  | 2447 | /* If we previously were in the mode, turn it off. */ | 
|  | 2448 | rctl = er32(RCTL); | 
|  | 2449 | rctl &= ~E1000_RCTL_SBP; | 
|  | 2450 | ew32(RCTL, rctl); | 
|  | 2451 | hw->tbi_compatibility_on = false; | 
|  | 2452 | } | 
|  | 2453 | } else { | 
|  | 2454 | /* If TBI compatibility is was previously off, turn it on. For | 
|  | 2455 | * compatibility with a TBI link partner, we will store bad | 
|  | 2456 | * packets. Some frames have an additional byte on the end and | 
|  | 2457 | * will look like CRC errors to to the hardware. | 
|  | 2458 | */ | 
|  | 2459 | if (!hw->tbi_compatibility_on) { | 
|  | 2460 | hw->tbi_compatibility_on = true; | 
|  | 2461 | rctl = er32(RCTL); | 
|  | 2462 | rctl |= E1000_RCTL_SBP; | 
|  | 2463 | ew32(RCTL, rctl); | 
|  | 2464 | } | 
|  | 2465 | } | 
|  | 2466 | } | 
|  | 2467 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2469 | if ((hw->media_type == e1000_media_type_fiber) || | 
|  | 2470 | (hw->media_type == e1000_media_type_internal_serdes)) | 
|  | 2471 | e1000_check_for_serdes_link_generic(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2473 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | } | 
|  | 2475 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2476 | /** | 
|  | 2477 | * e1000_get_speed_and_duplex | 
|  | 2478 | * @hw: Struct containing variables accessed by shared code | 
|  | 2479 | * @speed: Speed of the connection | 
|  | 2480 | * @duplex: Duplex setting of the connection | 
|  | 2481 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | * Detects the current speed and duplex settings of the hardware. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2483 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2484 | 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] | 2485 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2486 | u32 status; | 
|  | 2487 | s32 ret_val; | 
|  | 2488 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2490 | DEBUGFUNC("e1000_get_speed_and_duplex"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2492 | if (hw->mac_type >= e1000_82543) { | 
|  | 2493 | status = er32(STATUS); | 
|  | 2494 | if (status & E1000_STATUS_SPEED_1000) { | 
|  | 2495 | *speed = SPEED_1000; | 
|  | 2496 | DEBUGOUT("1000 Mbs, "); | 
|  | 2497 | } else if (status & E1000_STATUS_SPEED_100) { | 
|  | 2498 | *speed = SPEED_100; | 
|  | 2499 | DEBUGOUT("100 Mbs, "); | 
|  | 2500 | } else { | 
|  | 2501 | *speed = SPEED_10; | 
|  | 2502 | DEBUGOUT("10 Mbs, "); | 
|  | 2503 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2504 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2505 | if (status & E1000_STATUS_FD) { | 
|  | 2506 | *duplex = FULL_DUPLEX; | 
|  | 2507 | DEBUGOUT("Full Duplex\n"); | 
|  | 2508 | } else { | 
|  | 2509 | *duplex = HALF_DUPLEX; | 
|  | 2510 | DEBUGOUT(" Half Duplex\n"); | 
|  | 2511 | } | 
|  | 2512 | } else { | 
|  | 2513 | DEBUGOUT("1000 Mbs, Full Duplex\n"); | 
|  | 2514 | *speed = SPEED_1000; | 
|  | 2515 | *duplex = FULL_DUPLEX; | 
|  | 2516 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2518 | /* IGP01 PHY may advertise full duplex operation after speed downgrade even | 
|  | 2519 | * if it is operating at half duplex.  Here we set the duplex settings to | 
|  | 2520 | * match the duplex in the link partner's capabilities. | 
|  | 2521 | */ | 
|  | 2522 | if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) { | 
|  | 2523 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data); | 
|  | 2524 | if (ret_val) | 
|  | 2525 | return ret_val; | 
| 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 (!(phy_data & NWAY_ER_LP_NWAY_CAPS)) | 
|  | 2528 | *duplex = HALF_DUPLEX; | 
|  | 2529 | else { | 
|  | 2530 | ret_val = | 
|  | 2531 | e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data); | 
|  | 2532 | if (ret_val) | 
|  | 2533 | return ret_val; | 
|  | 2534 | if ((*speed == SPEED_100 | 
|  | 2535 | && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) | 
|  | 2536 | || (*speed == SPEED_10 | 
|  | 2537 | && !(phy_data & NWAY_LPAR_10T_FD_CAPS))) | 
|  | 2538 | *duplex = HALF_DUPLEX; | 
|  | 2539 | } | 
|  | 2540 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2541 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2542 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | } | 
|  | 2544 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2545 | /** | 
|  | 2546 | * e1000_wait_autoneg | 
|  | 2547 | * @hw: Struct containing variables accessed by shared code | 
|  | 2548 | * | 
|  | 2549 | * Blocks until autoneg completes or times out (~4.5 seconds) | 
|  | 2550 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2551 | static s32 e1000_wait_autoneg(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2553 | s32 ret_val; | 
|  | 2554 | u16 i; | 
|  | 2555 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2557 | DEBUGFUNC("e1000_wait_autoneg"); | 
|  | 2558 | DEBUGOUT("Waiting for Auto-Neg to complete.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2560 | /* We will wait for autoneg to complete or 4.5 seconds to expire. */ | 
|  | 2561 | for (i = PHY_AUTO_NEG_TIME; i > 0; i--) { | 
|  | 2562 | /* Read the MII Status Register and wait for Auto-Neg | 
|  | 2563 | * Complete bit to be set. | 
|  | 2564 | */ | 
|  | 2565 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 2566 | if (ret_val) | 
|  | 2567 | return ret_val; | 
|  | 2568 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 2569 | if (ret_val) | 
|  | 2570 | return ret_val; | 
|  | 2571 | if (phy_data & MII_SR_AUTONEG_COMPLETE) { | 
|  | 2572 | return E1000_SUCCESS; | 
|  | 2573 | } | 
|  | 2574 | msleep(100); | 
|  | 2575 | } | 
|  | 2576 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2577 | } | 
|  | 2578 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2579 | /** | 
|  | 2580 | * e1000_raise_mdi_clk - Raises the Management Data Clock | 
|  | 2581 | * @hw: Struct containing variables accessed by shared code | 
|  | 2582 | * @ctrl: Device control register's current value | 
|  | 2583 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2584 | static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2586 | /* Raise the clock input to the Management Data Clock (by setting the MDC | 
|  | 2587 | * bit), and then delay 10 microseconds. | 
|  | 2588 | */ | 
|  | 2589 | ew32(CTRL, (*ctrl | E1000_CTRL_MDC)); | 
|  | 2590 | E1000_WRITE_FLUSH(); | 
|  | 2591 | udelay(10); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | } | 
|  | 2593 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2594 | /** | 
|  | 2595 | * e1000_lower_mdi_clk - Lowers the Management Data Clock | 
|  | 2596 | * @hw: Struct containing variables accessed by shared code | 
|  | 2597 | * @ctrl: Device control register's current value | 
|  | 2598 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2599 | static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2601 | /* Lower the clock input to the Management Data Clock (by clearing the MDC | 
|  | 2602 | * bit), and then delay 10 microseconds. | 
|  | 2603 | */ | 
|  | 2604 | ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC)); | 
|  | 2605 | E1000_WRITE_FLUSH(); | 
|  | 2606 | udelay(10); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | } | 
|  | 2608 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2609 | /** | 
|  | 2610 | * e1000_shift_out_mdi_bits - Shifts data bits out to the PHY | 
|  | 2611 | * @hw: Struct containing variables accessed by shared code | 
|  | 2612 | * @data: Data to send out to the PHY | 
|  | 2613 | * @count: Number of bits to shift out | 
|  | 2614 | * | 
|  | 2615 | * Bits are shifted out in MSB to LSB order. | 
|  | 2616 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2617 | 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] | 2618 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2619 | u32 ctrl; | 
|  | 2620 | u32 mask; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2621 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2622 | /* We need to shift "count" number of bits out to the PHY. So, the value | 
|  | 2623 | * in the "data" parameter will be shifted out to the PHY one bit at a | 
|  | 2624 | * time. In order to do this, "data" must be broken down into bits. | 
|  | 2625 | */ | 
|  | 2626 | mask = 0x01; | 
|  | 2627 | mask <<= (count - 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2629 | ctrl = er32(CTRL); | 
| 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 | /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */ | 
|  | 2632 | ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2634 | while (mask) { | 
|  | 2635 | /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and | 
|  | 2636 | * then raising and lowering the Management Data Clock. A "0" is | 
|  | 2637 | * shifted out to the PHY by setting the MDIO bit to "0" and then | 
|  | 2638 | * raising and lowering the clock. | 
|  | 2639 | */ | 
|  | 2640 | if (data & mask) | 
|  | 2641 | ctrl |= E1000_CTRL_MDIO; | 
|  | 2642 | else | 
|  | 2643 | ctrl &= ~E1000_CTRL_MDIO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2645 | ew32(CTRL, ctrl); | 
|  | 2646 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2648 | udelay(10); | 
| 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 | e1000_raise_mdi_clk(hw, &ctrl); | 
|  | 2651 | e1000_lower_mdi_clk(hw, &ctrl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2652 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2653 | mask = mask >> 1; | 
|  | 2654 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | } | 
|  | 2656 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2657 | /** | 
|  | 2658 | * e1000_shift_in_mdi_bits - Shifts data bits in from the PHY | 
|  | 2659 | * @hw: Struct containing variables accessed by shared code | 
|  | 2660 | * | 
|  | 2661 | * Bits are shifted in in MSB to LSB order. | 
|  | 2662 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2663 | static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2665 | u32 ctrl; | 
|  | 2666 | u16 data = 0; | 
|  | 2667 | u8 i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2669 | /* In order to read a register from the PHY, we need to shift in a total | 
|  | 2670 | * of 18 bits from the PHY. The first two bit (turnaround) times are used | 
|  | 2671 | * to avoid contention on the MDIO pin when a read operation is performed. | 
|  | 2672 | * These two bits are ignored by us and thrown away. Bits are "shifted in" | 
|  | 2673 | * by raising the input to the Management Data Clock (setting the MDC bit), | 
|  | 2674 | * and then reading the value of the MDIO bit. | 
|  | 2675 | */ | 
|  | 2676 | ctrl = er32(CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2678 | /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */ | 
|  | 2679 | ctrl &= ~E1000_CTRL_MDIO_DIR; | 
|  | 2680 | ctrl &= ~E1000_CTRL_MDIO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2682 | ew32(CTRL, ctrl); | 
|  | 2683 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2685 | /* Raise and Lower the clock before reading in the data. This accounts for | 
|  | 2686 | * the turnaround bits. The first clock occurred when we clocked out the | 
|  | 2687 | * last bit of the Register Address. | 
|  | 2688 | */ | 
|  | 2689 | e1000_raise_mdi_clk(hw, &ctrl); | 
|  | 2690 | e1000_lower_mdi_clk(hw, &ctrl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2692 | for (data = 0, i = 0; i < 16; i++) { | 
|  | 2693 | data = data << 1; | 
|  | 2694 | e1000_raise_mdi_clk(hw, &ctrl); | 
|  | 2695 | ctrl = er32(CTRL); | 
|  | 2696 | /* Check to see if we shifted in a "1". */ | 
|  | 2697 | if (ctrl & E1000_CTRL_MDIO) | 
|  | 2698 | data |= 1; | 
|  | 2699 | e1000_lower_mdi_clk(hw, &ctrl); | 
|  | 2700 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2702 | e1000_raise_mdi_clk(hw, &ctrl); | 
|  | 2703 | e1000_lower_mdi_clk(hw, &ctrl); | 
| 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 | return data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | } | 
|  | 2707 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2708 |  | 
|  | 2709 | /** | 
|  | 2710 | * e1000_read_phy_reg - read a phy register | 
|  | 2711 | * @hw: Struct containing variables accessed by shared code | 
|  | 2712 | * @reg_addr: address of the PHY register to read | 
|  | 2713 | * | 
|  | 2714 | * Reads the value from a PHY register, if the value is on a specific non zero | 
|  | 2715 | * page, sets the page first. | 
|  | 2716 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2717 | 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] | 2718 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2719 | u32 ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2721 | DEBUGFUNC("e1000_read_phy_reg"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2723 | if ((hw->phy_type == e1000_phy_igp) && | 
|  | 2724 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { | 
|  | 2725 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, | 
|  | 2726 | (u16) reg_addr); | 
|  | 2727 | if (ret_val) | 
|  | 2728 | return ret_val; | 
|  | 2729 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2731 | ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, | 
|  | 2732 | phy_data); | 
|  | 2733 |  | 
|  | 2734 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | } | 
|  | 2736 |  | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2737 | static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, | 
|  | 2738 | u16 *phy_data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2740 | u32 i; | 
|  | 2741 | u32 mdic = 0; | 
|  | 2742 | const u32 phy_addr = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2744 | DEBUGFUNC("e1000_read_phy_reg_ex"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2746 | if (reg_addr > MAX_PHY_REG_ADDRESS) { | 
|  | 2747 | DEBUGOUT1("PHY Address %d is out of range\n", reg_addr); | 
|  | 2748 | return -E1000_ERR_PARAM; | 
|  | 2749 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2751 | if (hw->mac_type > e1000_82543) { | 
|  | 2752 | /* Set up Op-code, Phy Address, and register address in the MDI | 
|  | 2753 | * Control register.  The MAC will take care of interfacing with the | 
|  | 2754 | * PHY to retrieve the desired data. | 
|  | 2755 | */ | 
|  | 2756 | mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) | | 
|  | 2757 | (phy_addr << E1000_MDIC_PHY_SHIFT) | | 
|  | 2758 | (E1000_MDIC_OP_READ)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2760 | ew32(MDIC, mdic); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2762 | /* Poll the ready bit to see if the MDI read completed */ | 
|  | 2763 | for (i = 0; i < 64; i++) { | 
|  | 2764 | udelay(50); | 
|  | 2765 | mdic = er32(MDIC); | 
|  | 2766 | if (mdic & E1000_MDIC_READY) | 
|  | 2767 | break; | 
|  | 2768 | } | 
|  | 2769 | if (!(mdic & E1000_MDIC_READY)) { | 
|  | 2770 | DEBUGOUT("MDI Read did not complete\n"); | 
|  | 2771 | return -E1000_ERR_PHY; | 
|  | 2772 | } | 
|  | 2773 | if (mdic & E1000_MDIC_ERROR) { | 
|  | 2774 | DEBUGOUT("MDI Error\n"); | 
|  | 2775 | return -E1000_ERR_PHY; | 
|  | 2776 | } | 
|  | 2777 | *phy_data = (u16) mdic; | 
|  | 2778 | } else { | 
|  | 2779 | /* We must first send a preamble through the MDIO pin to signal the | 
|  | 2780 | * beginning of an MII instruction.  This is done by sending 32 | 
|  | 2781 | * consecutive "1" bits. | 
|  | 2782 | */ | 
|  | 2783 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2785 | /* Now combine the next few fields that are required for a read | 
|  | 2786 | * operation.  We use this method instead of calling the | 
|  | 2787 | * e1000_shift_out_mdi_bits routine five different times. The format of | 
|  | 2788 | * a MII read instruction consists of a shift out of 14 bits and is | 
|  | 2789 | * defined as follows: | 
|  | 2790 | *    <Preamble><SOF><Op Code><Phy Addr><Reg Addr> | 
|  | 2791 | * followed by a shift in of 18 bits.  This first two bits shifted in | 
|  | 2792 | * are TurnAround bits used to avoid contention on the MDIO pin when a | 
|  | 2793 | * READ operation is performed.  These two bits are thrown away | 
|  | 2794 | * followed by a shift in of 16 bits which contains the desired data. | 
|  | 2795 | */ | 
|  | 2796 | mdic = ((reg_addr) | (phy_addr << 5) | | 
|  | 2797 | (PHY_OP_READ << 10) | (PHY_SOF << 12)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2799 | e1000_shift_out_mdi_bits(hw, mdic, 14); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2801 | /* Now that we've shifted out the read command to the MII, we need to | 
|  | 2802 | * "shift in" the 16-bit value (18 total bits) of the requested PHY | 
|  | 2803 | * register address. | 
|  | 2804 | */ | 
|  | 2805 | *phy_data = e1000_shift_in_mdi_bits(hw); | 
|  | 2806 | } | 
|  | 2807 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | } | 
|  | 2809 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2810 | /** | 
|  | 2811 | * e1000_write_phy_reg - write a phy register | 
|  | 2812 | * | 
|  | 2813 | * @hw: Struct containing variables accessed by shared code | 
|  | 2814 | * @reg_addr: address of the PHY register to write | 
|  | 2815 | * @data: data to write to the PHY | 
|  | 2816 |  | 
|  | 2817 | * Writes a value to a PHY register | 
|  | 2818 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2819 | 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] | 2820 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2821 | u32 ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2823 | DEBUGFUNC("e1000_write_phy_reg"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2825 | if ((hw->phy_type == e1000_phy_igp) && | 
|  | 2826 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { | 
|  | 2827 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, | 
|  | 2828 | (u16) reg_addr); | 
|  | 2829 | if (ret_val) | 
|  | 2830 | return ret_val; | 
|  | 2831 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2833 | ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, | 
|  | 2834 | phy_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2836 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | } | 
|  | 2838 |  | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2839 | static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, | 
|  | 2840 | u16 phy_data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2842 | u32 i; | 
|  | 2843 | u32 mdic = 0; | 
|  | 2844 | const u32 phy_addr = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2846 | DEBUGFUNC("e1000_write_phy_reg_ex"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2848 | if (reg_addr > MAX_PHY_REG_ADDRESS) { | 
|  | 2849 | DEBUGOUT1("PHY Address %d is out of range\n", reg_addr); | 
|  | 2850 | return -E1000_ERR_PARAM; | 
|  | 2851 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2853 | if (hw->mac_type > e1000_82543) { | 
|  | 2854 | /* Set up Op-code, Phy Address, register address, and data intended | 
|  | 2855 | * for the PHY register in the MDI Control register.  The MAC will take | 
|  | 2856 | * care of interfacing with the PHY to send the desired data. | 
|  | 2857 | */ | 
|  | 2858 | mdic = (((u32) phy_data) | | 
|  | 2859 | (reg_addr << E1000_MDIC_REG_SHIFT) | | 
|  | 2860 | (phy_addr << E1000_MDIC_PHY_SHIFT) | | 
|  | 2861 | (E1000_MDIC_OP_WRITE)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2863 | ew32(MDIC, mdic); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2865 | /* Poll the ready bit to see if the MDI read completed */ | 
|  | 2866 | for (i = 0; i < 641; i++) { | 
|  | 2867 | udelay(5); | 
|  | 2868 | mdic = er32(MDIC); | 
|  | 2869 | if (mdic & E1000_MDIC_READY) | 
|  | 2870 | break; | 
|  | 2871 | } | 
|  | 2872 | if (!(mdic & E1000_MDIC_READY)) { | 
|  | 2873 | DEBUGOUT("MDI Write did not complete\n"); | 
|  | 2874 | return -E1000_ERR_PHY; | 
|  | 2875 | } | 
|  | 2876 | } else { | 
|  | 2877 | /* We'll need to use the SW defined pins to shift the write command | 
|  | 2878 | * out to the PHY. We first send a preamble to the PHY to signal the | 
|  | 2879 | * beginning of the MII instruction.  This is done by sending 32 | 
|  | 2880 | * consecutive "1" bits. | 
|  | 2881 | */ | 
|  | 2882 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2884 | /* Now combine the remaining required fields that will indicate a | 
|  | 2885 | * write operation. We use this method instead of calling the | 
|  | 2886 | * e1000_shift_out_mdi_bits routine for each field in the command. The | 
|  | 2887 | * format of a MII write instruction is as follows: | 
|  | 2888 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>. | 
|  | 2889 | */ | 
|  | 2890 | mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) | | 
|  | 2891 | (PHY_OP_WRITE << 12) | (PHY_SOF << 14)); | 
|  | 2892 | mdic <<= 16; | 
|  | 2893 | mdic |= (u32) phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2895 | e1000_shift_out_mdi_bits(hw, mdic, 32); | 
|  | 2896 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2898 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | } | 
|  | 2900 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2901 | /** | 
|  | 2902 | * e1000_phy_hw_reset - reset the phy, hardware style | 
|  | 2903 | * @hw: Struct containing variables accessed by shared code | 
|  | 2904 | * | 
|  | 2905 | * Returns the PHY to the power-on reset state | 
|  | 2906 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2907 | s32 e1000_phy_hw_reset(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2909 | u32 ctrl, ctrl_ext; | 
|  | 2910 | u32 led_ctrl; | 
|  | 2911 | s32 ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2913 | DEBUGFUNC("e1000_phy_hw_reset"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2915 | DEBUGOUT("Resetting Phy...\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2917 | if (hw->mac_type > e1000_82543) { | 
|  | 2918 | /* Read the device control register and assert the E1000_CTRL_PHY_RST | 
|  | 2919 | * bit. Then, take it out of reset. | 
|  | 2920 | * For e1000 hardware, we delay for 10ms between the assert | 
|  | 2921 | * and deassert. | 
|  | 2922 | */ | 
|  | 2923 | ctrl = er32(CTRL); | 
|  | 2924 | ew32(CTRL, ctrl | E1000_CTRL_PHY_RST); | 
|  | 2925 | E1000_WRITE_FLUSH(); | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2926 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2927 | msleep(10); | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2928 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2929 | ew32(CTRL, ctrl); | 
|  | 2930 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2932 | } else { | 
|  | 2933 | /* Read the Extended Device Control Register, assert the PHY_RESET_DIR | 
|  | 2934 | * bit to put the PHY into reset. Then, take it out of reset. | 
|  | 2935 | */ | 
|  | 2936 | ctrl_ext = er32(CTRL_EXT); | 
|  | 2937 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR; | 
|  | 2938 | ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA; | 
|  | 2939 | ew32(CTRL_EXT, ctrl_ext); | 
|  | 2940 | E1000_WRITE_FLUSH(); | 
|  | 2941 | msleep(10); | 
|  | 2942 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA; | 
|  | 2943 | ew32(CTRL_EXT, ctrl_ext); | 
|  | 2944 | E1000_WRITE_FLUSH(); | 
|  | 2945 | } | 
|  | 2946 | udelay(150); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2947 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2948 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { | 
|  | 2949 | /* Configure activity LED after PHY reset */ | 
|  | 2950 | led_ctrl = er32(LEDCTL); | 
|  | 2951 | led_ctrl &= IGP_ACTIVITY_LED_MASK; | 
|  | 2952 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); | 
|  | 2953 | ew32(LEDCTL, led_ctrl); | 
|  | 2954 | } | 
| Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2955 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2956 | /* Wait for FW to finish PHY configuration. */ | 
|  | 2957 | ret_val = e1000_get_phy_cfg_done(hw); | 
|  | 2958 | if (ret_val != E1000_SUCCESS) | 
|  | 2959 | return ret_val; | 
|  | 2960 |  | 
|  | 2961 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | } | 
|  | 2963 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2964 | /** | 
|  | 2965 | * e1000_phy_reset - reset the phy to commit settings | 
|  | 2966 | * @hw: Struct containing variables accessed by shared code | 
|  | 2967 | * | 
|  | 2968 | * Resets the PHY | 
|  | 2969 | * Sets bit 15 of the MII Control register | 
|  | 2970 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2971 | s32 e1000_phy_reset(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2973 | s32 ret_val; | 
|  | 2974 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2976 | DEBUGFUNC("e1000_phy_reset"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2978 | switch (hw->phy_type) { | 
|  | 2979 | case e1000_phy_igp: | 
|  | 2980 | ret_val = e1000_phy_hw_reset(hw); | 
|  | 2981 | if (ret_val) | 
|  | 2982 | return ret_val; | 
|  | 2983 | break; | 
|  | 2984 | default: | 
|  | 2985 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); | 
|  | 2986 | if (ret_val) | 
|  | 2987 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2989 | phy_data |= MII_CR_RESET; | 
|  | 2990 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); | 
|  | 2991 | if (ret_val) | 
|  | 2992 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2994 | udelay(1); | 
|  | 2995 | break; | 
|  | 2996 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 2998 | if (hw->phy_type == e1000_phy_igp) | 
|  | 2999 | e1000_phy_init_script(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3001 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | } | 
|  | 3003 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3004 | /** | 
|  | 3005 | * e1000_detect_gig_phy - check the phy type | 
|  | 3006 | * @hw: Struct containing variables accessed by shared code | 
|  | 3007 | * | 
|  | 3008 | * Probes the expected PHY address for known PHY IDs | 
|  | 3009 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3010 | static s32 e1000_detect_gig_phy(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3012 | s32 phy_init_status, ret_val; | 
|  | 3013 | u16 phy_id_high, phy_id_low; | 
|  | 3014 | bool match = false; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3016 | DEBUGFUNC("e1000_detect_gig_phy"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3018 | if (hw->phy_id != 0) | 
|  | 3019 | return E1000_SUCCESS; | 
| Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3020 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3021 | /* Read the PHY ID Registers to identify which PHY is onboard. */ | 
|  | 3022 | ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high); | 
|  | 3023 | if (ret_val) | 
|  | 3024 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3026 | hw->phy_id = (u32) (phy_id_high << 16); | 
|  | 3027 | udelay(20); | 
|  | 3028 | ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low); | 
|  | 3029 | if (ret_val) | 
|  | 3030 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3031 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3032 | hw->phy_id |= (u32) (phy_id_low & PHY_REVISION_MASK); | 
|  | 3033 | hw->phy_revision = (u32) phy_id_low & ~PHY_REVISION_MASK; | 
| 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 | switch (hw->mac_type) { | 
|  | 3036 | case e1000_82543: | 
|  | 3037 | if (hw->phy_id == M88E1000_E_PHY_ID) | 
|  | 3038 | match = true; | 
|  | 3039 | break; | 
|  | 3040 | case e1000_82544: | 
|  | 3041 | if (hw->phy_id == M88E1000_I_PHY_ID) | 
|  | 3042 | match = true; | 
|  | 3043 | break; | 
|  | 3044 | case e1000_82540: | 
|  | 3045 | case e1000_82545: | 
|  | 3046 | case e1000_82545_rev_3: | 
|  | 3047 | case e1000_82546: | 
|  | 3048 | case e1000_82546_rev_3: | 
|  | 3049 | if (hw->phy_id == M88E1011_I_PHY_ID) | 
|  | 3050 | match = true; | 
|  | 3051 | break; | 
|  | 3052 | case e1000_82541: | 
|  | 3053 | case e1000_82541_rev_2: | 
|  | 3054 | case e1000_82547: | 
|  | 3055 | case e1000_82547_rev_2: | 
|  | 3056 | if (hw->phy_id == IGP01E1000_I_PHY_ID) | 
|  | 3057 | match = true; | 
|  | 3058 | break; | 
|  | 3059 | default: | 
|  | 3060 | DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type); | 
|  | 3061 | return -E1000_ERR_CONFIG; | 
|  | 3062 | } | 
|  | 3063 | phy_init_status = e1000_set_phy_type(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3065 | if ((match) && (phy_init_status == E1000_SUCCESS)) { | 
|  | 3066 | DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id); | 
|  | 3067 | return E1000_SUCCESS; | 
|  | 3068 | } | 
|  | 3069 | DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id); | 
|  | 3070 | return -E1000_ERR_PHY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | } | 
|  | 3072 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3073 | /** | 
|  | 3074 | * e1000_phy_reset_dsp - reset DSP | 
|  | 3075 | * @hw: Struct containing variables accessed by shared code | 
|  | 3076 | * | 
|  | 3077 | * Resets the PHY's DSP | 
|  | 3078 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3079 | static s32 e1000_phy_reset_dsp(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3081 | s32 ret_val; | 
|  | 3082 | DEBUGFUNC("e1000_phy_reset_dsp"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3084 | do { | 
|  | 3085 | ret_val = e1000_write_phy_reg(hw, 29, 0x001d); | 
|  | 3086 | if (ret_val) | 
|  | 3087 | break; | 
|  | 3088 | ret_val = e1000_write_phy_reg(hw, 30, 0x00c1); | 
|  | 3089 | if (ret_val) | 
|  | 3090 | break; | 
|  | 3091 | ret_val = e1000_write_phy_reg(hw, 30, 0x0000); | 
|  | 3092 | if (ret_val) | 
|  | 3093 | break; | 
|  | 3094 | ret_val = E1000_SUCCESS; | 
|  | 3095 | } while (0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3097 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | } | 
|  | 3099 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3100 | /** | 
|  | 3101 | * e1000_phy_igp_get_info - get igp specific registers | 
|  | 3102 | * @hw: Struct containing variables accessed by shared code | 
|  | 3103 | * @phy_info: PHY information structure | 
|  | 3104 | * | 
|  | 3105 | * Get PHY information from various PHY registers for igp PHY only. | 
|  | 3106 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3107 | static s32 e1000_phy_igp_get_info(struct e1000_hw *hw, | 
|  | 3108 | struct e1000_phy_info *phy_info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3110 | s32 ret_val; | 
|  | 3111 | u16 phy_data, min_length, max_length, average; | 
|  | 3112 | e1000_rev_polarity polarity; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3114 | DEBUGFUNC("e1000_phy_igp_get_info"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3116 | /* The downshift status is checked only once, after link is established, | 
|  | 3117 | * and it stored in the hw->speed_downgraded parameter. */ | 
|  | 3118 | phy_info->downshift = (e1000_downshift) hw->speed_downgraded; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3120 | /* IGP01E1000 does not need to support it. */ | 
|  | 3121 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3123 | /* IGP01E1000 always correct polarity reversal */ | 
|  | 3124 | phy_info->polarity_correction = e1000_polarity_reversal_enabled; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3126 | /* Check polarity status */ | 
|  | 3127 | ret_val = e1000_check_polarity(hw, &polarity); | 
|  | 3128 | if (ret_val) | 
|  | 3129 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3131 | phy_info->cable_polarity = polarity; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3133 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data); | 
|  | 3134 | if (ret_val) | 
|  | 3135 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3137 | phy_info->mdix_mode = | 
|  | 3138 | (e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >> | 
|  | 3139 | IGP01E1000_PSSR_MDIX_SHIFT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3141 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == | 
|  | 3142 | IGP01E1000_PSSR_SPEED_1000MBPS) { | 
|  | 3143 | /* Local/Remote Receiver Information are only valid at 1000 Mbps */ | 
|  | 3144 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); | 
|  | 3145 | if (ret_val) | 
|  | 3146 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3148 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> | 
|  | 3149 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? | 
|  | 3150 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; | 
|  | 3151 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> | 
|  | 3152 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? | 
|  | 3153 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3155 | /* Get cable length */ | 
|  | 3156 | ret_val = e1000_get_cable_length(hw, &min_length, &max_length); | 
|  | 3157 | if (ret_val) | 
|  | 3158 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3160 | /* Translate to old method */ | 
|  | 3161 | average = (max_length + min_length) / 2; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3163 | if (average <= e1000_igp_cable_length_50) | 
|  | 3164 | phy_info->cable_length = e1000_cable_length_50; | 
|  | 3165 | else if (average <= e1000_igp_cable_length_80) | 
|  | 3166 | phy_info->cable_length = e1000_cable_length_50_80; | 
|  | 3167 | else if (average <= e1000_igp_cable_length_110) | 
|  | 3168 | phy_info->cable_length = e1000_cable_length_80_110; | 
|  | 3169 | else if (average <= e1000_igp_cable_length_140) | 
|  | 3170 | phy_info->cable_length = e1000_cable_length_110_140; | 
|  | 3171 | else | 
|  | 3172 | phy_info->cable_length = e1000_cable_length_140; | 
|  | 3173 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3175 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | } | 
|  | 3177 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3178 | /** | 
|  | 3179 | * e1000_phy_m88_get_info - get m88 specific registers | 
|  | 3180 | * @hw: Struct containing variables accessed by shared code | 
|  | 3181 | * @phy_info: PHY information structure | 
|  | 3182 | * | 
|  | 3183 | * Get PHY information from various PHY registers for m88 PHY only. | 
|  | 3184 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3185 | static s32 e1000_phy_m88_get_info(struct e1000_hw *hw, | 
|  | 3186 | struct e1000_phy_info *phy_info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3188 | s32 ret_val; | 
|  | 3189 | u16 phy_data; | 
|  | 3190 | e1000_rev_polarity polarity; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3192 | DEBUGFUNC("e1000_phy_m88_get_info"); | 
| 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 | /* The downshift status is checked only once, after link is established, | 
|  | 3195 | * and it stored in the hw->speed_downgraded parameter. */ | 
|  | 3196 | phy_info->downshift = (e1000_downshift) hw->speed_downgraded; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3198 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); | 
|  | 3199 | if (ret_val) | 
|  | 3200 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3202 | phy_info->extended_10bt_distance = | 
|  | 3203 | ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >> | 
|  | 3204 | M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ? | 
|  | 3205 | e1000_10bt_ext_dist_enable_lower : | 
|  | 3206 | e1000_10bt_ext_dist_enable_normal; | 
| Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 3207 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3208 | phy_info->polarity_correction = | 
|  | 3209 | ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >> | 
|  | 3210 | M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ? | 
|  | 3211 | e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3213 | /* Check polarity status */ | 
|  | 3214 | ret_val = e1000_check_polarity(hw, &polarity); | 
|  | 3215 | if (ret_val) | 
|  | 3216 | return ret_val; | 
|  | 3217 | phy_info->cable_polarity = polarity; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3219 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); | 
|  | 3220 | if (ret_val) | 
|  | 3221 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3223 | phy_info->mdix_mode = | 
|  | 3224 | (e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >> | 
|  | 3225 | M88E1000_PSSR_MDIX_SHIFT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3227 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) { | 
|  | 3228 | /* Cable Length Estimation and Local/Remote Receiver Information | 
|  | 3229 | * are only valid at 1000 Mbps. | 
|  | 3230 | */ | 
|  | 3231 | phy_info->cable_length = | 
|  | 3232 | (e1000_cable_length) ((phy_data & | 
|  | 3233 | M88E1000_PSSR_CABLE_LENGTH) >> | 
|  | 3234 | M88E1000_PSSR_CABLE_LENGTH_SHIFT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3236 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); | 
|  | 3237 | if (ret_val) | 
|  | 3238 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3240 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> | 
|  | 3241 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? | 
|  | 3242 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; | 
|  | 3243 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> | 
|  | 3244 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? | 
|  | 3245 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3247 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3249 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | } | 
|  | 3251 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3252 | /** | 
|  | 3253 | * e1000_phy_get_info - request phy info | 
|  | 3254 | * @hw: Struct containing variables accessed by shared code | 
|  | 3255 | * @phy_info: PHY information structure | 
|  | 3256 | * | 
|  | 3257 | * Get PHY information from various PHY registers | 
|  | 3258 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3259 | 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] | 3260 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3261 | s32 ret_val; | 
|  | 3262 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3264 | DEBUGFUNC("e1000_phy_get_info"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3266 | phy_info->cable_length = e1000_cable_length_undefined; | 
|  | 3267 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined; | 
|  | 3268 | phy_info->cable_polarity = e1000_rev_polarity_undefined; | 
|  | 3269 | phy_info->downshift = e1000_downshift_undefined; | 
|  | 3270 | phy_info->polarity_correction = e1000_polarity_reversal_undefined; | 
|  | 3271 | phy_info->mdix_mode = e1000_auto_x_mode_undefined; | 
|  | 3272 | phy_info->local_rx = e1000_1000t_rx_status_undefined; | 
|  | 3273 | phy_info->remote_rx = e1000_1000t_rx_status_undefined; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3275 | if (hw->media_type != e1000_media_type_copper) { | 
|  | 3276 | DEBUGOUT("PHY info is only valid for copper media\n"); | 
|  | 3277 | return -E1000_ERR_CONFIG; | 
|  | 3278 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3280 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 3281 | if (ret_val) | 
|  | 3282 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3284 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); | 
|  | 3285 | if (ret_val) | 
|  | 3286 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3288 | if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) { | 
|  | 3289 | DEBUGOUT("PHY info is only valid if link is up\n"); | 
|  | 3290 | return -E1000_ERR_CONFIG; | 
|  | 3291 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3293 | if (hw->phy_type == e1000_phy_igp) | 
|  | 3294 | return e1000_phy_igp_get_info(hw, phy_info); | 
|  | 3295 | else | 
|  | 3296 | return e1000_phy_m88_get_info(hw, phy_info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | } | 
|  | 3298 |  | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3299 | s32 e1000_validate_mdi_setting(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3301 | DEBUGFUNC("e1000_validate_mdi_settings"); | 
| 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 | if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) { | 
|  | 3304 | DEBUGOUT("Invalid MDI setting detected\n"); | 
|  | 3305 | hw->mdix = 1; | 
|  | 3306 | return -E1000_ERR_CONFIG; | 
|  | 3307 | } | 
|  | 3308 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | } | 
|  | 3310 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3311 | /** | 
|  | 3312 | * e1000_init_eeprom_params - initialize sw eeprom vars | 
|  | 3313 | * @hw: Struct containing variables accessed by shared code | 
|  | 3314 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | * 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] | 3316 | * is configured. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3317 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3318 | s32 e1000_init_eeprom_params(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3319 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3320 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 3321 | u32 eecd = er32(EECD); | 
|  | 3322 | s32 ret_val = E1000_SUCCESS; | 
|  | 3323 | u16 eeprom_size; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3324 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3325 | DEBUGFUNC("e1000_init_eeprom_params"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3327 | switch (hw->mac_type) { | 
|  | 3328 | case e1000_82542_rev2_0: | 
|  | 3329 | case e1000_82542_rev2_1: | 
|  | 3330 | case e1000_82543: | 
|  | 3331 | case e1000_82544: | 
|  | 3332 | eeprom->type = e1000_eeprom_microwire; | 
|  | 3333 | eeprom->word_size = 64; | 
|  | 3334 | eeprom->opcode_bits = 3; | 
|  | 3335 | eeprom->address_bits = 6; | 
|  | 3336 | eeprom->delay_usec = 50; | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3337 | break; | 
|  | 3338 | case e1000_82540: | 
|  | 3339 | case e1000_82545: | 
|  | 3340 | case e1000_82545_rev_3: | 
|  | 3341 | case e1000_82546: | 
|  | 3342 | case e1000_82546_rev_3: | 
|  | 3343 | eeprom->type = e1000_eeprom_microwire; | 
|  | 3344 | eeprom->opcode_bits = 3; | 
|  | 3345 | eeprom->delay_usec = 50; | 
|  | 3346 | if (eecd & E1000_EECD_SIZE) { | 
|  | 3347 | eeprom->word_size = 256; | 
|  | 3348 | eeprom->address_bits = 8; | 
|  | 3349 | } else { | 
|  | 3350 | eeprom->word_size = 64; | 
|  | 3351 | eeprom->address_bits = 6; | 
|  | 3352 | } | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3353 | break; | 
|  | 3354 | case e1000_82541: | 
|  | 3355 | case e1000_82541_rev_2: | 
|  | 3356 | case e1000_82547: | 
|  | 3357 | case e1000_82547_rev_2: | 
|  | 3358 | if (eecd & E1000_EECD_TYPE) { | 
|  | 3359 | eeprom->type = e1000_eeprom_spi; | 
|  | 3360 | eeprom->opcode_bits = 8; | 
|  | 3361 | eeprom->delay_usec = 1; | 
|  | 3362 | if (eecd & E1000_EECD_ADDR_BITS) { | 
|  | 3363 | eeprom->page_size = 32; | 
|  | 3364 | eeprom->address_bits = 16; | 
|  | 3365 | } else { | 
|  | 3366 | eeprom->page_size = 8; | 
|  | 3367 | eeprom->address_bits = 8; | 
|  | 3368 | } | 
|  | 3369 | } else { | 
|  | 3370 | eeprom->type = e1000_eeprom_microwire; | 
|  | 3371 | eeprom->opcode_bits = 3; | 
|  | 3372 | eeprom->delay_usec = 50; | 
|  | 3373 | if (eecd & E1000_EECD_ADDR_BITS) { | 
|  | 3374 | eeprom->word_size = 256; | 
|  | 3375 | eeprom->address_bits = 8; | 
|  | 3376 | } else { | 
|  | 3377 | eeprom->word_size = 64; | 
|  | 3378 | eeprom->address_bits = 6; | 
|  | 3379 | } | 
|  | 3380 | } | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3381 | break; | 
|  | 3382 | default: | 
|  | 3383 | break; | 
|  | 3384 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3386 | if (eeprom->type == e1000_eeprom_spi) { | 
|  | 3387 | /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to | 
|  | 3388 | * 32KB (incremented by powers of 2). | 
|  | 3389 | */ | 
|  | 3390 | /* Set to default value for initial eeprom read. */ | 
|  | 3391 | eeprom->word_size = 64; | 
|  | 3392 | ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size); | 
|  | 3393 | if (ret_val) | 
|  | 3394 | return ret_val; | 
|  | 3395 | eeprom_size = | 
|  | 3396 | (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT; | 
|  | 3397 | /* 256B eeprom size was not supported in earlier hardware, so we | 
|  | 3398 | * bump eeprom_size up one to ensure that "1" (which maps to 256B) | 
|  | 3399 | * is never the result used in the shifting logic below. */ | 
|  | 3400 | if (eeprom_size) | 
|  | 3401 | eeprom_size++; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3402 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3403 | eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT); | 
|  | 3404 | } | 
|  | 3405 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | } | 
|  | 3407 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3408 | /** | 
|  | 3409 | * e1000_raise_ee_clk - Raises the EEPROM's clock input. | 
|  | 3410 | * @hw: Struct containing variables accessed by shared code | 
|  | 3411 | * @eecd: EECD's current value | 
|  | 3412 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3413 | static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3415 | /* Raise the clock input to the EEPROM (by setting the SK bit), and then | 
|  | 3416 | * wait <delay> microseconds. | 
|  | 3417 | */ | 
|  | 3418 | *eecd = *eecd | E1000_EECD_SK; | 
|  | 3419 | ew32(EECD, *eecd); | 
|  | 3420 | E1000_WRITE_FLUSH(); | 
|  | 3421 | udelay(hw->eeprom.delay_usec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | } | 
|  | 3423 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3424 | /** | 
|  | 3425 | * e1000_lower_ee_clk - Lowers the EEPROM's clock input. | 
|  | 3426 | * @hw: Struct containing variables accessed by shared code | 
|  | 3427 | * @eecd: EECD's current value | 
|  | 3428 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3429 | static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3431 | /* Lower the clock input to the EEPROM (by clearing the SK bit), and then | 
|  | 3432 | * wait 50 microseconds. | 
|  | 3433 | */ | 
|  | 3434 | *eecd = *eecd & ~E1000_EECD_SK; | 
|  | 3435 | ew32(EECD, *eecd); | 
|  | 3436 | E1000_WRITE_FLUSH(); | 
|  | 3437 | udelay(hw->eeprom.delay_usec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | } | 
|  | 3439 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3440 | /** | 
|  | 3441 | * e1000_shift_out_ee_bits - Shift data bits out to the EEPROM. | 
|  | 3442 | * @hw: Struct containing variables accessed by shared code | 
|  | 3443 | * @data: data to send to the EEPROM | 
|  | 3444 | * @count: number of bits to shift out | 
|  | 3445 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3446 | 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] | 3447 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3448 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 3449 | u32 eecd; | 
|  | 3450 | u32 mask; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3452 | /* We need to shift "count" bits out to the EEPROM. So, value in the | 
|  | 3453 | * "data" parameter will be shifted out to the EEPROM one bit at a time. | 
|  | 3454 | * In order to do this, "data" must be broken down into bits. | 
|  | 3455 | */ | 
|  | 3456 | mask = 0x01 << (count - 1); | 
|  | 3457 | eecd = er32(EECD); | 
|  | 3458 | if (eeprom->type == e1000_eeprom_microwire) { | 
|  | 3459 | eecd &= ~E1000_EECD_DO; | 
|  | 3460 | } else if (eeprom->type == e1000_eeprom_spi) { | 
|  | 3461 | eecd |= E1000_EECD_DO; | 
|  | 3462 | } | 
|  | 3463 | do { | 
|  | 3464 | /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1", | 
|  | 3465 | * and then raising and then lowering the clock (the SK bit controls | 
|  | 3466 | * the clock input to the EEPROM).  A "0" is shifted out to the EEPROM | 
|  | 3467 | * by setting "DI" to "0" and then raising and then lowering the clock. | 
|  | 3468 | */ | 
|  | 3469 | eecd &= ~E1000_EECD_DI; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3471 | if (data & mask) | 
|  | 3472 | eecd |= E1000_EECD_DI; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3474 | ew32(EECD, eecd); | 
|  | 3475 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3477 | udelay(eeprom->delay_usec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3479 | e1000_raise_ee_clk(hw, &eecd); | 
|  | 3480 | e1000_lower_ee_clk(hw, &eecd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3481 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3482 | mask = mask >> 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3484 | } while (mask); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3486 | /* We leave the "DI" bit set to "0" when we leave this routine. */ | 
|  | 3487 | eecd &= ~E1000_EECD_DI; | 
|  | 3488 | ew32(EECD, eecd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | } | 
|  | 3490 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3491 | /** | 
|  | 3492 | * e1000_shift_in_ee_bits - Shift data bits in from the EEPROM | 
|  | 3493 | * @hw: Struct containing variables accessed by shared code | 
|  | 3494 | * @count: number of bits to shift in | 
|  | 3495 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3496 | 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] | 3497 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3498 | u32 eecd; | 
|  | 3499 | u32 i; | 
|  | 3500 | u16 data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3502 | /* In order to read a register from the EEPROM, we need to shift 'count' | 
|  | 3503 | * bits in from the EEPROM. Bits are "shifted in" by raising the clock | 
|  | 3504 | * input to the EEPROM (setting the SK bit), and then reading the value of | 
|  | 3505 | * the "DO" bit.  During this "shifting in" process the "DI" bit should | 
|  | 3506 | * always be clear. | 
|  | 3507 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3509 | eecd = er32(EECD); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3510 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3511 | eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); | 
|  | 3512 | data = 0; | 
| 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 | for (i = 0; i < count; i++) { | 
|  | 3515 | data = data << 1; | 
|  | 3516 | e1000_raise_ee_clk(hw, &eecd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3518 | eecd = er32(EECD); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3520 | eecd &= ~(E1000_EECD_DI); | 
|  | 3521 | if (eecd & E1000_EECD_DO) | 
|  | 3522 | data |= 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3524 | e1000_lower_ee_clk(hw, &eecd); | 
|  | 3525 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3527 | return data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | } | 
|  | 3529 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3530 | /** | 
|  | 3531 | * e1000_acquire_eeprom - Prepares EEPROM for access | 
|  | 3532 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | * | 
|  | 3534 | * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This | 
|  | 3535 | * function should be called before issuing a command to the EEPROM. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3536 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3537 | static s32 e1000_acquire_eeprom(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3538 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3539 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 3540 | u32 eecd, i = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3542 | DEBUGFUNC("e1000_acquire_eeprom"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3544 | eecd = er32(EECD); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3545 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3546 | /* Request EEPROM Access */ | 
|  | 3547 | if (hw->mac_type > e1000_82544) { | 
|  | 3548 | eecd |= E1000_EECD_REQ; | 
|  | 3549 | ew32(EECD, eecd); | 
|  | 3550 | eecd = er32(EECD); | 
|  | 3551 | while ((!(eecd & E1000_EECD_GNT)) && | 
|  | 3552 | (i < E1000_EEPROM_GRANT_ATTEMPTS)) { | 
|  | 3553 | i++; | 
|  | 3554 | udelay(5); | 
|  | 3555 | eecd = er32(EECD); | 
|  | 3556 | } | 
|  | 3557 | if (!(eecd & E1000_EECD_GNT)) { | 
|  | 3558 | eecd &= ~E1000_EECD_REQ; | 
|  | 3559 | ew32(EECD, eecd); | 
|  | 3560 | DEBUGOUT("Could not acquire EEPROM grant\n"); | 
|  | 3561 | return -E1000_ERR_EEPROM; | 
|  | 3562 | } | 
|  | 3563 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3565 | /* Setup EEPROM for Read/Write */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3567 | if (eeprom->type == e1000_eeprom_microwire) { | 
|  | 3568 | /* Clear SK and DI */ | 
|  | 3569 | eecd &= ~(E1000_EECD_DI | E1000_EECD_SK); | 
|  | 3570 | ew32(EECD, eecd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3572 | /* Set CS */ | 
|  | 3573 | eecd |= E1000_EECD_CS; | 
|  | 3574 | ew32(EECD, eecd); | 
|  | 3575 | } else if (eeprom->type == e1000_eeprom_spi) { | 
|  | 3576 | /* Clear SK and CS */ | 
|  | 3577 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); | 
|  | 3578 | ew32(EECD, eecd); | 
|  | 3579 | udelay(1); | 
|  | 3580 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3581 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3582 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | } | 
|  | 3584 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3585 | /** | 
|  | 3586 | * e1000_standby_eeprom - Returns EEPROM to a "standby" state | 
|  | 3587 | * @hw: Struct containing variables accessed by shared code | 
|  | 3588 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3589 | static void e1000_standby_eeprom(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3591 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 3592 | u32 eecd; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3594 | eecd = er32(EECD); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3596 | if (eeprom->type == e1000_eeprom_microwire) { | 
|  | 3597 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); | 
|  | 3598 | ew32(EECD, eecd); | 
|  | 3599 | E1000_WRITE_FLUSH(); | 
|  | 3600 | udelay(eeprom->delay_usec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3602 | /* Clock high */ | 
|  | 3603 | eecd |= E1000_EECD_SK; | 
|  | 3604 | ew32(EECD, eecd); | 
|  | 3605 | E1000_WRITE_FLUSH(); | 
|  | 3606 | udelay(eeprom->delay_usec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3608 | /* Select EEPROM */ | 
|  | 3609 | eecd |= E1000_EECD_CS; | 
|  | 3610 | ew32(EECD, eecd); | 
|  | 3611 | E1000_WRITE_FLUSH(); | 
|  | 3612 | udelay(eeprom->delay_usec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3614 | /* Clock low */ | 
|  | 3615 | eecd &= ~E1000_EECD_SK; | 
|  | 3616 | ew32(EECD, eecd); | 
|  | 3617 | E1000_WRITE_FLUSH(); | 
|  | 3618 | udelay(eeprom->delay_usec); | 
|  | 3619 | } else if (eeprom->type == e1000_eeprom_spi) { | 
|  | 3620 | /* Toggle CS to flush commands */ | 
|  | 3621 | eecd |= E1000_EECD_CS; | 
|  | 3622 | ew32(EECD, eecd); | 
|  | 3623 | E1000_WRITE_FLUSH(); | 
|  | 3624 | udelay(eeprom->delay_usec); | 
|  | 3625 | eecd &= ~E1000_EECD_CS; | 
|  | 3626 | ew32(EECD, eecd); | 
|  | 3627 | E1000_WRITE_FLUSH(); | 
|  | 3628 | udelay(eeprom->delay_usec); | 
|  | 3629 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | } | 
|  | 3631 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3632 | /** | 
|  | 3633 | * e1000_release_eeprom - drop chip select | 
|  | 3634 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | * | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3636 | * Terminates a command by inverting the EEPROM's chip select pin | 
|  | 3637 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3638 | static void e1000_release_eeprom(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3640 | u32 eecd; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3641 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3642 | DEBUGFUNC("e1000_release_eeprom"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3644 | eecd = er32(EECD); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3646 | if (hw->eeprom.type == e1000_eeprom_spi) { | 
|  | 3647 | eecd |= E1000_EECD_CS;	/* Pull CS high */ | 
|  | 3648 | eecd &= ~E1000_EECD_SK;	/* Lower SCK */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3649 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3650 | ew32(EECD, eecd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3652 | udelay(hw->eeprom.delay_usec); | 
|  | 3653 | } else if (hw->eeprom.type == e1000_eeprom_microwire) { | 
|  | 3654 | /* cleanup eeprom */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3656 | /* CS on Microwire is active-high */ | 
|  | 3657 | eecd &= ~(E1000_EECD_CS | E1000_EECD_DI); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3659 | ew32(EECD, eecd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3661 | /* Rising edge of clock */ | 
|  | 3662 | eecd |= E1000_EECD_SK; | 
|  | 3663 | ew32(EECD, eecd); | 
|  | 3664 | E1000_WRITE_FLUSH(); | 
|  | 3665 | udelay(hw->eeprom.delay_usec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3666 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3667 | /* Falling edge of clock */ | 
|  | 3668 | eecd &= ~E1000_EECD_SK; | 
|  | 3669 | ew32(EECD, eecd); | 
|  | 3670 | E1000_WRITE_FLUSH(); | 
|  | 3671 | udelay(hw->eeprom.delay_usec); | 
|  | 3672 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3674 | /* Stop requesting EEPROM access */ | 
|  | 3675 | if (hw->mac_type > e1000_82544) { | 
|  | 3676 | eecd &= ~E1000_EECD_REQ; | 
|  | 3677 | ew32(EECD, eecd); | 
|  | 3678 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3679 | } | 
|  | 3680 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3681 | /** | 
|  | 3682 | * e1000_spi_eeprom_ready - Reads a 16 bit word from the EEPROM. | 
|  | 3683 | * @hw: Struct containing variables accessed by shared code | 
|  | 3684 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3685 | static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3687 | u16 retry_count = 0; | 
|  | 3688 | u8 spi_stat_reg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3690 | DEBUGFUNC("e1000_spi_eeprom_ready"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3692 | /* Read "Status Register" repeatedly until the LSB is cleared.  The | 
|  | 3693 | * EEPROM will signal that the command has been completed by clearing | 
|  | 3694 | * bit 0 of the internal status register.  If it's not cleared within | 
|  | 3695 | * 5 milliseconds, then error out. | 
|  | 3696 | */ | 
|  | 3697 | retry_count = 0; | 
|  | 3698 | do { | 
|  | 3699 | e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI, | 
|  | 3700 | hw->eeprom.opcode_bits); | 
|  | 3701 | spi_stat_reg = (u8) e1000_shift_in_ee_bits(hw, 8); | 
|  | 3702 | if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI)) | 
|  | 3703 | break; | 
| 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 | udelay(5); | 
|  | 3706 | retry_count += 5; | 
| 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 | e1000_standby_eeprom(hw); | 
|  | 3709 | } while (retry_count < EEPROM_MAX_RETRY_SPI); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3711 | /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and | 
|  | 3712 | * only 0-5mSec on 5V devices) | 
|  | 3713 | */ | 
|  | 3714 | if (retry_count >= EEPROM_MAX_RETRY_SPI) { | 
|  | 3715 | DEBUGOUT("SPI EEPROM Status error\n"); | 
|  | 3716 | return -E1000_ERR_EEPROM; | 
|  | 3717 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3719 | return E1000_SUCCESS; | 
| 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_read_eeprom - Reads a 16 bit word from the EEPROM. | 
|  | 3724 | * @hw: Struct containing variables accessed by shared code | 
|  | 3725 | * @offset: offset of  word in the EEPROM to read | 
|  | 3726 | * @data: word read from the EEPROM | 
|  | 3727 | * @words: number of words to read | 
|  | 3728 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3729 | 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] | 3730 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3731 | s32 ret; | 
|  | 3732 | spin_lock(&e1000_eeprom_lock); | 
|  | 3733 | ret = e1000_do_read_eeprom(hw, offset, words, data); | 
|  | 3734 | spin_unlock(&e1000_eeprom_lock); | 
|  | 3735 | return ret; | 
| Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 3736 | } | 
|  | 3737 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3738 | static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, | 
|  | 3739 | u16 *data) | 
| Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 3740 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3741 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 3742 | u32 i = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3743 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3744 | DEBUGFUNC("e1000_read_eeprom"); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3745 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3746 | /* If eeprom is not yet detected, do so now */ | 
|  | 3747 | if (eeprom->word_size == 0) | 
|  | 3748 | e1000_init_eeprom_params(hw); | 
| Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3749 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3750 | /* A check for invalid values:  offset too large, too many words, and not | 
|  | 3751 | * enough words. | 
|  | 3752 | */ | 
|  | 3753 | if ((offset >= eeprom->word_size) | 
|  | 3754 | || (words > eeprom->word_size - offset) || (words == 0)) { | 
|  | 3755 | DEBUGOUT2 | 
|  | 3756 | ("\"words\" parameter out of bounds. Words = %d, size = %d\n", | 
|  | 3757 | offset, eeprom->word_size); | 
|  | 3758 | return -E1000_ERR_EEPROM; | 
|  | 3759 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3760 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3761 | /* EEPROM's that don't use EERD to read require us to bit-bang the SPI | 
|  | 3762 | * directly. In this case, we need to acquire the EEPROM so that | 
|  | 3763 | * FW or other port software does not interrupt. | 
|  | 3764 | */ | 
| Jesse Brandeburg | 8f601b2 | 2009-09-25 12:20:11 +0000 | [diff] [blame] | 3765 | /* Prepare the EEPROM for bit-bang reading */ | 
|  | 3766 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) | 
|  | 3767 | return -E1000_ERR_EEPROM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3769 | /* Set up the SPI or Microwire EEPROM for bit-bang reading.  We have | 
|  | 3770 | * acquired the EEPROM at this point, so any returns should release it */ | 
|  | 3771 | if (eeprom->type == e1000_eeprom_spi) { | 
|  | 3772 | u16 word_in; | 
|  | 3773 | u8 read_opcode = EEPROM_READ_OPCODE_SPI; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3775 | if (e1000_spi_eeprom_ready(hw)) { | 
|  | 3776 | e1000_release_eeprom(hw); | 
|  | 3777 | return -E1000_ERR_EEPROM; | 
|  | 3778 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3780 | e1000_standby_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3782 | /* Some SPI eeproms use the 8th address bit embedded in the opcode */ | 
|  | 3783 | if ((eeprom->address_bits == 8) && (offset >= 128)) | 
|  | 3784 | read_opcode |= EEPROM_A8_OPCODE_SPI; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3786 | /* Send the READ command (opcode + addr)  */ | 
|  | 3787 | e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits); | 
|  | 3788 | e1000_shift_out_ee_bits(hw, (u16) (offset * 2), | 
|  | 3789 | eeprom->address_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3791 | /* Read the data.  The address of the eeprom internally increments with | 
|  | 3792 | * each byte (spi) being read, saving on the overhead of eeprom setup | 
|  | 3793 | * and tear-down.  The address counter will roll over if reading beyond | 
|  | 3794 | * the size of the eeprom, thus allowing the entire memory to be read | 
|  | 3795 | * starting from any offset. */ | 
|  | 3796 | for (i = 0; i < words; i++) { | 
|  | 3797 | word_in = e1000_shift_in_ee_bits(hw, 16); | 
|  | 3798 | data[i] = (word_in >> 8) | (word_in << 8); | 
|  | 3799 | } | 
|  | 3800 | } else if (eeprom->type == e1000_eeprom_microwire) { | 
|  | 3801 | for (i = 0; i < words; i++) { | 
|  | 3802 | /* Send the READ command (opcode + addr)  */ | 
|  | 3803 | e1000_shift_out_ee_bits(hw, | 
|  | 3804 | EEPROM_READ_OPCODE_MICROWIRE, | 
|  | 3805 | eeprom->opcode_bits); | 
|  | 3806 | e1000_shift_out_ee_bits(hw, (u16) (offset + i), | 
|  | 3807 | eeprom->address_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3809 | /* Read the data.  For microwire, each word requires the overhead | 
|  | 3810 | * of eeprom setup and tear-down. */ | 
|  | 3811 | data[i] = e1000_shift_in_ee_bits(hw, 16); | 
|  | 3812 | e1000_standby_eeprom(hw); | 
|  | 3813 | } | 
|  | 3814 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3816 | /* End this read operation */ | 
|  | 3817 | e1000_release_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3819 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | } | 
|  | 3821 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3822 | /** | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3823 | * e1000_validate_eeprom_checksum - Verifies that the EEPROM has a valid checksum | 
|  | 3824 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | * | 
|  | 3826 | * Reads the first 64 16 bit words of the EEPROM and sums the values read. | 
|  | 3827 | * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is | 
|  | 3828 | * valid. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3829 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3830 | s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3831 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3832 | u16 checksum = 0; | 
|  | 3833 | u16 i, eeprom_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3835 | DEBUGFUNC("e1000_validate_eeprom_checksum"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3837 | for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) { | 
|  | 3838 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { | 
|  | 3839 | DEBUGOUT("EEPROM Read Error\n"); | 
|  | 3840 | return -E1000_ERR_EEPROM; | 
|  | 3841 | } | 
|  | 3842 | checksum += eeprom_data; | 
|  | 3843 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3844 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3845 | if (checksum == (u16) EEPROM_SUM) | 
|  | 3846 | return E1000_SUCCESS; | 
|  | 3847 | else { | 
|  | 3848 | DEBUGOUT("EEPROM Checksum Invalid\n"); | 
|  | 3849 | return -E1000_ERR_EEPROM; | 
|  | 3850 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3851 | } | 
|  | 3852 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3853 | /** | 
|  | 3854 | * e1000_update_eeprom_checksum - Calculates/writes the EEPROM checksum | 
|  | 3855 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | * | 
|  | 3857 | * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA. | 
|  | 3858 | * Writes the difference to word offset 63 of the EEPROM. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3859 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3860 | s32 e1000_update_eeprom_checksum(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3861 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3862 | u16 checksum = 0; | 
|  | 3863 | u16 i, eeprom_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3864 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3865 | DEBUGFUNC("e1000_update_eeprom_checksum"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3867 | for (i = 0; i < EEPROM_CHECKSUM_REG; i++) { | 
|  | 3868 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { | 
|  | 3869 | DEBUGOUT("EEPROM Read Error\n"); | 
|  | 3870 | return -E1000_ERR_EEPROM; | 
|  | 3871 | } | 
|  | 3872 | checksum += eeprom_data; | 
|  | 3873 | } | 
|  | 3874 | checksum = (u16) EEPROM_SUM - checksum; | 
|  | 3875 | if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) { | 
|  | 3876 | DEBUGOUT("EEPROM Write Error\n"); | 
|  | 3877 | return -E1000_ERR_EEPROM; | 
|  | 3878 | } | 
|  | 3879 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3880 | } | 
|  | 3881 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3882 | /** | 
|  | 3883 | * e1000_write_eeprom - write words to the different EEPROM types. | 
|  | 3884 | * @hw: Struct containing variables accessed by shared code | 
|  | 3885 | * @offset: offset within the EEPROM to be written to | 
|  | 3886 | * @words: number of words to write | 
|  | 3887 | * @data: 16 bit word to be written to the EEPROM | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | * | 
|  | 3889 | * If e1000_update_eeprom_checksum is not called after this function, the | 
|  | 3890 | * EEPROM will most likely contain an invalid checksum. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3891 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3892 | 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] | 3893 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3894 | s32 ret; | 
|  | 3895 | spin_lock(&e1000_eeprom_lock); | 
|  | 3896 | ret = e1000_do_write_eeprom(hw, offset, words, data); | 
|  | 3897 | spin_unlock(&e1000_eeprom_lock); | 
|  | 3898 | return ret; | 
| Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 3899 | } | 
|  | 3900 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3901 | static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, | 
|  | 3902 | u16 *data) | 
| Christopher Li | 78566fe | 2008-09-05 14:04:05 -0700 | [diff] [blame] | 3903 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3904 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 3905 | s32 status = 0; | 
| 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 | DEBUGFUNC("e1000_write_eeprom"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3908 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3909 | /* If eeprom is not yet detected, do so now */ | 
|  | 3910 | if (eeprom->word_size == 0) | 
|  | 3911 | e1000_init_eeprom_params(hw); | 
| Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3912 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3913 | /* A check for invalid values:  offset too large, too many words, and not | 
|  | 3914 | * enough words. | 
|  | 3915 | */ | 
|  | 3916 | if ((offset >= eeprom->word_size) | 
|  | 3917 | || (words > eeprom->word_size - offset) || (words == 0)) { | 
|  | 3918 | DEBUGOUT("\"words\" parameter out of bounds\n"); | 
|  | 3919 | return -E1000_ERR_EEPROM; | 
|  | 3920 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3921 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3922 | /* Prepare the EEPROM for writing  */ | 
|  | 3923 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) | 
|  | 3924 | return -E1000_ERR_EEPROM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3926 | if (eeprom->type == e1000_eeprom_microwire) { | 
|  | 3927 | status = e1000_write_eeprom_microwire(hw, offset, words, data); | 
|  | 3928 | } else { | 
|  | 3929 | status = e1000_write_eeprom_spi(hw, offset, words, data); | 
|  | 3930 | msleep(10); | 
|  | 3931 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3933 | /* Done with writing */ | 
|  | 3934 | e1000_release_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3935 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3936 | return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | } | 
|  | 3938 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3939 | /** | 
|  | 3940 | * e1000_write_eeprom_spi - Writes a 16 bit word to a given offset in an SPI EEPROM. | 
|  | 3941 | * @hw: Struct containing variables accessed by shared code | 
|  | 3942 | * @offset: offset within the EEPROM to be written to | 
|  | 3943 | * @words: number of words to write | 
|  | 3944 | * @data: pointer to array of 8 bit words to be written to the EEPROM | 
|  | 3945 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3946 | static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words, | 
|  | 3947 | u16 *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3949 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 3950 | u16 widx = 0; | 
| 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 | DEBUGFUNC("e1000_write_eeprom_spi"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3953 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3954 | while (widx < words) { | 
|  | 3955 | u8 write_opcode = EEPROM_WRITE_OPCODE_SPI; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3957 | if (e1000_spi_eeprom_ready(hw)) | 
|  | 3958 | return -E1000_ERR_EEPROM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3959 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3960 | e1000_standby_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3962 | /*  Send the WRITE ENABLE command (8 bit opcode )  */ | 
|  | 3963 | e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI, | 
|  | 3964 | eeprom->opcode_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3965 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3966 | e1000_standby_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3968 | /* Some SPI eeproms use the 8th address bit embedded in the opcode */ | 
|  | 3969 | if ((eeprom->address_bits == 8) && (offset >= 128)) | 
|  | 3970 | write_opcode |= EEPROM_A8_OPCODE_SPI; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3971 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3972 | /* Send the Write command (8-bit opcode + addr) */ | 
|  | 3973 | e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3975 | e1000_shift_out_ee_bits(hw, (u16) ((offset + widx) * 2), | 
|  | 3976 | eeprom->address_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3977 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3978 | /* Send the data */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3979 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3980 | /* Loop to allow for up to whole page write (32 bytes) of eeprom */ | 
|  | 3981 | while (widx < words) { | 
|  | 3982 | u16 word_out = data[widx]; | 
|  | 3983 | word_out = (word_out >> 8) | (word_out << 8); | 
|  | 3984 | e1000_shift_out_ee_bits(hw, word_out, 16); | 
|  | 3985 | widx++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3987 | /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE | 
|  | 3988 | * operation, while the smaller eeproms are capable of an 8-byte | 
|  | 3989 | * PAGE WRITE operation.  Break the inner loop to pass new address | 
|  | 3990 | */ | 
|  | 3991 | if ((((offset + widx) * 2) % eeprom->page_size) == 0) { | 
|  | 3992 | e1000_standby_eeprom(hw); | 
|  | 3993 | break; | 
|  | 3994 | } | 
|  | 3995 | } | 
|  | 3996 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 3998 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | } | 
|  | 4000 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4001 | /** | 
|  | 4002 | * e1000_write_eeprom_microwire - Writes a 16 bit word to a given offset in a Microwire EEPROM. | 
|  | 4003 | * @hw: Struct containing variables accessed by shared code | 
|  | 4004 | * @offset: offset within the EEPROM to be written to | 
|  | 4005 | * @words: number of words to write | 
|  | 4006 | * @data: pointer to array of 8 bit words to be written to the EEPROM | 
|  | 4007 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4008 | static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset, | 
|  | 4009 | u16 words, u16 *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4011 | struct e1000_eeprom_info *eeprom = &hw->eeprom; | 
|  | 4012 | u32 eecd; | 
|  | 4013 | u16 words_written = 0; | 
|  | 4014 | u16 i = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4016 | DEBUGFUNC("e1000_write_eeprom_microwire"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4018 | /* Send the write enable command to the EEPROM (3-bit opcode plus | 
|  | 4019 | * 6/8-bit dummy address beginning with 11).  It's less work to include | 
|  | 4020 | * the 11 of the dummy address as part of the opcode than it is to shift | 
|  | 4021 | * it over the correct number of bits for the address.  This puts the | 
|  | 4022 | * EEPROM into write/erase mode. | 
|  | 4023 | */ | 
|  | 4024 | e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE, | 
|  | 4025 | (u16) (eeprom->opcode_bits + 2)); | 
| 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 | e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4028 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4029 | /* Prepare the EEPROM */ | 
|  | 4030 | e1000_standby_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4032 | while (words_written < words) { | 
|  | 4033 | /* Send the Write command (3-bit opcode + addr) */ | 
|  | 4034 | e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE, | 
|  | 4035 | eeprom->opcode_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4037 | e1000_shift_out_ee_bits(hw, (u16) (offset + words_written), | 
|  | 4038 | eeprom->address_bits); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4040 | /* Send the data */ | 
|  | 4041 | e1000_shift_out_ee_bits(hw, data[words_written], 16); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4043 | /* Toggle the CS line.  This in effect tells the EEPROM to execute | 
|  | 4044 | * the previous command. | 
|  | 4045 | */ | 
|  | 4046 | e1000_standby_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4048 | /* Read DO repeatedly until it is high (equal to '1').  The EEPROM will | 
|  | 4049 | * signal that the command has been completed by raising the DO signal. | 
|  | 4050 | * If DO does not go high in 10 milliseconds, then error out. | 
|  | 4051 | */ | 
|  | 4052 | for (i = 0; i < 200; i++) { | 
|  | 4053 | eecd = er32(EECD); | 
|  | 4054 | if (eecd & E1000_EECD_DO) | 
|  | 4055 | break; | 
|  | 4056 | udelay(50); | 
|  | 4057 | } | 
|  | 4058 | if (i == 200) { | 
|  | 4059 | DEBUGOUT("EEPROM Write did not complete\n"); | 
|  | 4060 | return -E1000_ERR_EEPROM; | 
|  | 4061 | } | 
| 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 | /* Recover from write */ | 
|  | 4064 | e1000_standby_eeprom(hw); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4066 | words_written++; | 
|  | 4067 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4069 | /* Send the write disable command to the EEPROM (3-bit opcode plus | 
|  | 4070 | * 6/8-bit dummy address beginning with 10).  It's less work to include | 
|  | 4071 | * the 10 of the dummy address as part of the opcode than it is to shift | 
|  | 4072 | * it over the correct number of bits for the address.  This takes the | 
|  | 4073 | * EEPROM out of write/erase mode. | 
|  | 4074 | */ | 
|  | 4075 | e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE, | 
|  | 4076 | (u16) (eeprom->opcode_bits + 2)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4078 | e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4080 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | } | 
|  | 4082 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4083 | /** | 
|  | 4084 | * e1000_read_mac_addr - read the adapters MAC from eeprom | 
|  | 4085 | * @hw: Struct containing variables accessed by shared code | 
|  | 4086 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the | 
|  | 4088 | * second function of dual function devices | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4089 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4090 | s32 e1000_read_mac_addr(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4092 | u16 offset; | 
|  | 4093 | u16 eeprom_data, i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4095 | DEBUGFUNC("e1000_read_mac_addr"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4097 | for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) { | 
|  | 4098 | offset = i >> 1; | 
|  | 4099 | if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) { | 
|  | 4100 | DEBUGOUT("EEPROM Read Error\n"); | 
|  | 4101 | return -E1000_ERR_EEPROM; | 
|  | 4102 | } | 
|  | 4103 | hw->perm_mac_addr[i] = (u8) (eeprom_data & 0x00FF); | 
|  | 4104 | hw->perm_mac_addr[i + 1] = (u8) (eeprom_data >> 8); | 
|  | 4105 | } | 
| Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4106 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4107 | switch (hw->mac_type) { | 
|  | 4108 | default: | 
|  | 4109 | break; | 
|  | 4110 | case e1000_82546: | 
|  | 4111 | case e1000_82546_rev_3: | 
|  | 4112 | if (er32(STATUS) & E1000_STATUS_FUNC_1) | 
|  | 4113 | hw->perm_mac_addr[5] ^= 0x01; | 
|  | 4114 | break; | 
|  | 4115 | } | 
| 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 < NODE_ADDRESS_SIZE; i++) | 
|  | 4118 | hw->mac_addr[i] = hw->perm_mac_addr[i]; | 
|  | 4119 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | } | 
|  | 4121 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4122 | /** | 
|  | 4123 | * e1000_init_rx_addrs - Initializes receive address filters. | 
|  | 4124 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4125 | * | 
|  | 4126 | * 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] | 4127 | * of the receive address registers. Clears the multicast table. Assumes | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | * the receiver is in reset when the routine is called. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4129 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4130 | static void e1000_init_rx_addrs(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4132 | u32 i; | 
|  | 4133 | u32 rar_num; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4134 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4135 | DEBUGFUNC("e1000_init_rx_addrs"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4137 | /* Setup the receive address. */ | 
|  | 4138 | DEBUGOUT("Programming MAC Address into RAR[0]\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4140 | e1000_rar_set(hw, hw->mac_addr, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4142 | rar_num = E1000_RAR_ENTRIES; | 
| Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4143 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4144 | /* Zero out the other 15 receive addresses. */ | 
|  | 4145 | DEBUGOUT("Clearing RAR[1-15]\n"); | 
|  | 4146 | for (i = 1; i < rar_num; i++) { | 
|  | 4147 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0); | 
|  | 4148 | E1000_WRITE_FLUSH(); | 
|  | 4149 | E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0); | 
|  | 4150 | E1000_WRITE_FLUSH(); | 
|  | 4151 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4152 | } | 
|  | 4153 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4154 | /** | 
|  | 4155 | * e1000_hash_mc_addr - Hashes an address to determine its location in the multicast table | 
|  | 4156 | * @hw: Struct containing variables accessed by shared code | 
|  | 4157 | * @mc_addr: the multicast address to hash | 
|  | 4158 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4159 | u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4161 | u32 hash_value = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4162 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4163 | /* The portion of the address that is used for the hash table is | 
|  | 4164 | * determined by the mc_filter_type setting. | 
|  | 4165 | */ | 
|  | 4166 | switch (hw->mc_filter_type) { | 
|  | 4167 | /* [0] [1] [2] [3] [4] [5] | 
|  | 4168 | * 01  AA  00  12  34  56 | 
|  | 4169 | * LSB                 MSB | 
|  | 4170 | */ | 
|  | 4171 | case 0: | 
|  | 4172 | /* [47:36] i.e. 0x563 for above example address */ | 
|  | 4173 | hash_value = ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4)); | 
|  | 4174 | break; | 
|  | 4175 | case 1: | 
|  | 4176 | /* [46:35] i.e. 0xAC6 for above example address */ | 
|  | 4177 | hash_value = ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5)); | 
|  | 4178 | break; | 
|  | 4179 | case 2: | 
|  | 4180 | /* [45:34] i.e. 0x5D8 for above example address */ | 
|  | 4181 | hash_value = ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6)); | 
|  | 4182 | break; | 
|  | 4183 | case 3: | 
|  | 4184 | /* [43:32] i.e. 0x634 for above example address */ | 
|  | 4185 | hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8)); | 
|  | 4186 | break; | 
|  | 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 | hash_value &= 0xFFF; | 
|  | 4190 | return hash_value; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | } | 
|  | 4192 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4193 | /** | 
|  | 4194 | * e1000_rar_set - Puts an ethernet address into a receive address register. | 
|  | 4195 | * @hw: Struct containing variables accessed by shared code | 
|  | 4196 | * @addr: Address to put into receive address register | 
|  | 4197 | * @index: Receive address register to write | 
|  | 4198 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4199 | void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4201 | u32 rar_low, rar_high; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4203 | /* HW expects these in little endian so we reverse the byte order | 
|  | 4204 | * from network order (big endian) to little endian | 
|  | 4205 | */ | 
|  | 4206 | rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) | | 
|  | 4207 | ((u32) addr[2] << 16) | ((u32) addr[3] << 24)); | 
|  | 4208 | rar_high = ((u32) addr[4] | ((u32) addr[5] << 8)); | 
| 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 | /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx | 
|  | 4211 | * unit hang. | 
|  | 4212 | * | 
|  | 4213 | * Description: | 
|  | 4214 | * If there are any Rx frames queued up or otherwise present in the HW | 
|  | 4215 | * before RSS is enabled, and then we enable RSS, the HW Rx unit will | 
|  | 4216 | * hang.  To work around this issue, we have to disable receives and | 
|  | 4217 | * flush out all Rx frames before we enable RSS. To do so, we modify we | 
|  | 4218 | * redirect all Rx traffic to manageability and then reset the HW. | 
|  | 4219 | * This flushes away Rx frames, and (since the redirections to | 
|  | 4220 | * manageability persists across resets) keeps new ones from coming in | 
|  | 4221 | * while we work.  Then, we clear the Address Valid AV bit for all MAC | 
|  | 4222 | * addresses and undo the re-direction to manageability. | 
|  | 4223 | * Now, frames are coming in again, but the MAC won't accept them, so | 
|  | 4224 | * far so good.  We now proceed to initialize RSS (if necessary) and | 
|  | 4225 | * configure the Rx unit.  Last, we re-enable the AV bits and continue | 
|  | 4226 | * on our merry way. | 
|  | 4227 | */ | 
|  | 4228 | switch (hw->mac_type) { | 
|  | 4229 | default: | 
|  | 4230 | /* Indicate to hardware the Address is Valid. */ | 
|  | 4231 | rar_high |= E1000_RAH_AV; | 
|  | 4232 | break; | 
|  | 4233 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4234 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4235 | E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low); | 
|  | 4236 | E1000_WRITE_FLUSH(); | 
|  | 4237 | E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high); | 
|  | 4238 | E1000_WRITE_FLUSH(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4239 | } | 
|  | 4240 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4241 | /** | 
|  | 4242 | * e1000_write_vfta - Writes a value to the specified offset in the VLAN filter table. | 
|  | 4243 | * @hw: Struct containing variables accessed by shared code | 
|  | 4244 | * @offset: Offset in VLAN filer table to write | 
|  | 4245 | * @value: Value to write into VLAN filter table | 
|  | 4246 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4247 | void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4249 | u32 temp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4251 | if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) { | 
|  | 4252 | temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1)); | 
|  | 4253 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); | 
|  | 4254 | E1000_WRITE_FLUSH(); | 
|  | 4255 | E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp); | 
|  | 4256 | E1000_WRITE_FLUSH(); | 
|  | 4257 | } else { | 
|  | 4258 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); | 
|  | 4259 | E1000_WRITE_FLUSH(); | 
|  | 4260 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4261 | } | 
|  | 4262 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4263 | /** | 
|  | 4264 | * e1000_clear_vfta - Clears the VLAN filer table | 
|  | 4265 | * @hw: Struct containing variables accessed by shared code | 
|  | 4266 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4267 | static void e1000_clear_vfta(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4269 | u32 offset; | 
|  | 4270 | u32 vfta_value = 0; | 
|  | 4271 | u32 vfta_offset = 0; | 
|  | 4272 | u32 vfta_bit_in_reg = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4273 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4274 | for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) { | 
|  | 4275 | /* If the offset we want to clear is the same offset of the | 
|  | 4276 | * manageability VLAN ID, then clear all bits except that of the | 
|  | 4277 | * manageability unit */ | 
|  | 4278 | vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0; | 
|  | 4279 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value); | 
|  | 4280 | E1000_WRITE_FLUSH(); | 
|  | 4281 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | } | 
|  | 4283 |  | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4284 | static s32 e1000_id_led_init(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4286 | u32 ledctl; | 
|  | 4287 | const u32 ledctl_mask = 0x000000FF; | 
|  | 4288 | const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON; | 
|  | 4289 | const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF; | 
|  | 4290 | u16 eeprom_data, i, temp; | 
|  | 4291 | const u16 led_mask = 0x0F; | 
| 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 | DEBUGFUNC("e1000_id_led_init"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4294 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4295 | if (hw->mac_type < e1000_82540) { | 
|  | 4296 | /* Nothing to do */ | 
|  | 4297 | return E1000_SUCCESS; | 
|  | 4298 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4300 | ledctl = er32(LEDCTL); | 
|  | 4301 | hw->ledctl_default = ledctl; | 
|  | 4302 | hw->ledctl_mode1 = hw->ledctl_default; | 
|  | 4303 | hw->ledctl_mode2 = hw->ledctl_default; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4305 | if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) { | 
|  | 4306 | DEBUGOUT("EEPROM Read Error\n"); | 
|  | 4307 | return -E1000_ERR_EEPROM; | 
|  | 4308 | } | 
| Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4309 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4310 | if ((eeprom_data == ID_LED_RESERVED_0000) || | 
|  | 4311 | (eeprom_data == ID_LED_RESERVED_FFFF)) { | 
|  | 4312 | eeprom_data = ID_LED_DEFAULT; | 
|  | 4313 | } | 
| Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4314 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4315 | for (i = 0; i < 4; i++) { | 
|  | 4316 | temp = (eeprom_data >> (i << 2)) & led_mask; | 
|  | 4317 | switch (temp) { | 
|  | 4318 | case ID_LED_ON1_DEF2: | 
|  | 4319 | case ID_LED_ON1_ON2: | 
|  | 4320 | case ID_LED_ON1_OFF2: | 
|  | 4321 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); | 
|  | 4322 | hw->ledctl_mode1 |= ledctl_on << (i << 3); | 
|  | 4323 | break; | 
|  | 4324 | case ID_LED_OFF1_DEF2: | 
|  | 4325 | case ID_LED_OFF1_ON2: | 
|  | 4326 | case ID_LED_OFF1_OFF2: | 
|  | 4327 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); | 
|  | 4328 | hw->ledctl_mode1 |= ledctl_off << (i << 3); | 
|  | 4329 | break; | 
|  | 4330 | default: | 
|  | 4331 | /* Do nothing */ | 
|  | 4332 | break; | 
|  | 4333 | } | 
|  | 4334 | switch (temp) { | 
|  | 4335 | case ID_LED_DEF1_ON2: | 
|  | 4336 | case ID_LED_ON1_ON2: | 
|  | 4337 | case ID_LED_OFF1_ON2: | 
|  | 4338 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); | 
|  | 4339 | hw->ledctl_mode2 |= ledctl_on << (i << 3); | 
|  | 4340 | break; | 
|  | 4341 | case ID_LED_DEF1_OFF2: | 
|  | 4342 | case ID_LED_ON1_OFF2: | 
|  | 4343 | case ID_LED_OFF1_OFF2: | 
|  | 4344 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); | 
|  | 4345 | hw->ledctl_mode2 |= ledctl_off << (i << 3); | 
|  | 4346 | break; | 
|  | 4347 | default: | 
|  | 4348 | /* Do nothing */ | 
|  | 4349 | break; | 
|  | 4350 | } | 
|  | 4351 | } | 
|  | 4352 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4353 | } | 
|  | 4354 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4355 | /** | 
|  | 4356 | * e1000_setup_led | 
|  | 4357 | * @hw: Struct containing variables accessed by shared code | 
| 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 | * Prepares SW controlable LED for use and saves the current state of the LED. | 
|  | 4360 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4361 | s32 e1000_setup_led(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4362 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4363 | u32 ledctl; | 
|  | 4364 | s32 ret_val = E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4365 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4366 | DEBUGFUNC("e1000_setup_led"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4368 | switch (hw->mac_type) { | 
|  | 4369 | case e1000_82542_rev2_0: | 
|  | 4370 | case e1000_82542_rev2_1: | 
|  | 4371 | case e1000_82543: | 
|  | 4372 | case e1000_82544: | 
|  | 4373 | /* No setup necessary */ | 
|  | 4374 | break; | 
|  | 4375 | case e1000_82541: | 
|  | 4376 | case e1000_82547: | 
|  | 4377 | case e1000_82541_rev_2: | 
|  | 4378 | case e1000_82547_rev_2: | 
|  | 4379 | /* Turn off PHY Smart Power Down (if enabled) */ | 
|  | 4380 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, | 
|  | 4381 | &hw->phy_spd_default); | 
|  | 4382 | if (ret_val) | 
|  | 4383 | return ret_val; | 
|  | 4384 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, | 
|  | 4385 | (u16) (hw->phy_spd_default & | 
|  | 4386 | ~IGP01E1000_GMII_SPD)); | 
|  | 4387 | if (ret_val) | 
|  | 4388 | return ret_val; | 
|  | 4389 | /* Fall Through */ | 
|  | 4390 | default: | 
|  | 4391 | if (hw->media_type == e1000_media_type_fiber) { | 
|  | 4392 | ledctl = er32(LEDCTL); | 
|  | 4393 | /* Save current LEDCTL settings */ | 
|  | 4394 | hw->ledctl_default = ledctl; | 
|  | 4395 | /* Turn off LED0 */ | 
|  | 4396 | ledctl &= ~(E1000_LEDCTL_LED0_IVRT | | 
|  | 4397 | E1000_LEDCTL_LED0_BLINK | | 
|  | 4398 | E1000_LEDCTL_LED0_MODE_MASK); | 
|  | 4399 | ledctl |= (E1000_LEDCTL_MODE_LED_OFF << | 
|  | 4400 | E1000_LEDCTL_LED0_MODE_SHIFT); | 
|  | 4401 | ew32(LEDCTL, ledctl); | 
|  | 4402 | } else if (hw->media_type == e1000_media_type_copper) | 
|  | 4403 | ew32(LEDCTL, hw->ledctl_mode1); | 
|  | 4404 | break; | 
|  | 4405 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4407 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | } | 
|  | 4409 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4410 | /** | 
|  | 4411 | * e1000_cleanup_led - Restores the saved state of the SW controlable LED. | 
|  | 4412 | * @hw: Struct containing variables accessed by shared code | 
|  | 4413 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4414 | s32 e1000_cleanup_led(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4416 | s32 ret_val = E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4418 | DEBUGFUNC("e1000_cleanup_led"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4420 | switch (hw->mac_type) { | 
|  | 4421 | case e1000_82542_rev2_0: | 
|  | 4422 | case e1000_82542_rev2_1: | 
|  | 4423 | case e1000_82543: | 
|  | 4424 | case e1000_82544: | 
|  | 4425 | /* No cleanup necessary */ | 
|  | 4426 | break; | 
|  | 4427 | case e1000_82541: | 
|  | 4428 | case e1000_82547: | 
|  | 4429 | case e1000_82541_rev_2: | 
|  | 4430 | case e1000_82547_rev_2: | 
|  | 4431 | /* Turn on PHY Smart Power Down (if previously enabled) */ | 
|  | 4432 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, | 
|  | 4433 | hw->phy_spd_default); | 
|  | 4434 | if (ret_val) | 
|  | 4435 | return ret_val; | 
|  | 4436 | /* Fall Through */ | 
|  | 4437 | default: | 
|  | 4438 | /* Restore LEDCTL settings */ | 
|  | 4439 | ew32(LEDCTL, hw->ledctl_default); | 
|  | 4440 | break; | 
|  | 4441 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4442 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4443 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | } | 
|  | 4445 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4446 | /** | 
|  | 4447 | * e1000_led_on - Turns on the software controllable LED | 
|  | 4448 | * @hw: Struct containing variables accessed by shared code | 
|  | 4449 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4450 | s32 e1000_led_on(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4452 | u32 ctrl = er32(CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4454 | DEBUGFUNC("e1000_led_on"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4455 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4456 | switch (hw->mac_type) { | 
|  | 4457 | case e1000_82542_rev2_0: | 
|  | 4458 | case e1000_82542_rev2_1: | 
|  | 4459 | case e1000_82543: | 
|  | 4460 | /* Set SW Defineable Pin 0 to turn on the LED */ | 
|  | 4461 | ctrl |= E1000_CTRL_SWDPIN0; | 
|  | 4462 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4463 | break; | 
|  | 4464 | case e1000_82544: | 
|  | 4465 | if (hw->media_type == e1000_media_type_fiber) { | 
|  | 4466 | /* Set SW Defineable Pin 0 to turn on the LED */ | 
|  | 4467 | ctrl |= E1000_CTRL_SWDPIN0; | 
|  | 4468 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4469 | } else { | 
|  | 4470 | /* Clear SW Defineable Pin 0 to turn on the LED */ | 
|  | 4471 | ctrl &= ~E1000_CTRL_SWDPIN0; | 
|  | 4472 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4473 | } | 
|  | 4474 | break; | 
|  | 4475 | default: | 
|  | 4476 | if (hw->media_type == e1000_media_type_fiber) { | 
|  | 4477 | /* Clear SW Defineable Pin 0 to turn on the LED */ | 
|  | 4478 | ctrl &= ~E1000_CTRL_SWDPIN0; | 
|  | 4479 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4480 | } else if (hw->media_type == e1000_media_type_copper) { | 
|  | 4481 | ew32(LEDCTL, hw->ledctl_mode2); | 
|  | 4482 | return E1000_SUCCESS; | 
|  | 4483 | } | 
|  | 4484 | break; | 
|  | 4485 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4486 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4487 | ew32(CTRL, ctrl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4489 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | } | 
|  | 4491 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4492 | /** | 
|  | 4493 | * e1000_led_off - Turns off the software controllable LED | 
|  | 4494 | * @hw: Struct containing variables accessed by shared code | 
|  | 4495 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4496 | s32 e1000_led_off(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4498 | u32 ctrl = er32(CTRL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4500 | DEBUGFUNC("e1000_led_off"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4501 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4502 | switch (hw->mac_type) { | 
|  | 4503 | case e1000_82542_rev2_0: | 
|  | 4504 | case e1000_82542_rev2_1: | 
|  | 4505 | case e1000_82543: | 
|  | 4506 | /* Clear SW Defineable Pin 0 to turn off the LED */ | 
|  | 4507 | ctrl &= ~E1000_CTRL_SWDPIN0; | 
|  | 4508 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4509 | break; | 
|  | 4510 | case e1000_82544: | 
|  | 4511 | if (hw->media_type == e1000_media_type_fiber) { | 
|  | 4512 | /* Clear SW Defineable Pin 0 to turn off the LED */ | 
|  | 4513 | ctrl &= ~E1000_CTRL_SWDPIN0; | 
|  | 4514 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4515 | } else { | 
|  | 4516 | /* Set SW Defineable Pin 0 to turn off the LED */ | 
|  | 4517 | ctrl |= E1000_CTRL_SWDPIN0; | 
|  | 4518 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4519 | } | 
|  | 4520 | break; | 
|  | 4521 | default: | 
|  | 4522 | if (hw->media_type == e1000_media_type_fiber) { | 
|  | 4523 | /* Set SW Defineable Pin 0 to turn off the LED */ | 
|  | 4524 | ctrl |= E1000_CTRL_SWDPIN0; | 
|  | 4525 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 4526 | } else if (hw->media_type == e1000_media_type_copper) { | 
|  | 4527 | ew32(LEDCTL, hw->ledctl_mode1); | 
|  | 4528 | return E1000_SUCCESS; | 
|  | 4529 | } | 
|  | 4530 | break; | 
|  | 4531 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4533 | ew32(CTRL, ctrl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4535 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | } | 
|  | 4537 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4538 | /** | 
|  | 4539 | * e1000_clear_hw_cntrs - Clears all hardware statistics counters. | 
|  | 4540 | * @hw: Struct containing variables accessed by shared code | 
|  | 4541 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4542 | static void e1000_clear_hw_cntrs(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4543 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4544 | volatile u32 temp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4546 | temp = er32(CRCERRS); | 
|  | 4547 | temp = er32(SYMERRS); | 
|  | 4548 | temp = er32(MPC); | 
|  | 4549 | temp = er32(SCC); | 
|  | 4550 | temp = er32(ECOL); | 
|  | 4551 | temp = er32(MCC); | 
|  | 4552 | temp = er32(LATECOL); | 
|  | 4553 | temp = er32(COLC); | 
|  | 4554 | temp = er32(DC); | 
|  | 4555 | temp = er32(SEC); | 
|  | 4556 | temp = er32(RLEC); | 
|  | 4557 | temp = er32(XONRXC); | 
|  | 4558 | temp = er32(XONTXC); | 
|  | 4559 | temp = er32(XOFFRXC); | 
|  | 4560 | temp = er32(XOFFTXC); | 
|  | 4561 | temp = er32(FCRUC); | 
| Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4562 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4563 | temp = er32(PRC64); | 
|  | 4564 | temp = er32(PRC127); | 
|  | 4565 | temp = er32(PRC255); | 
|  | 4566 | temp = er32(PRC511); | 
|  | 4567 | temp = er32(PRC1023); | 
|  | 4568 | temp = er32(PRC1522); | 
| Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4569 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4570 | temp = er32(GPRC); | 
|  | 4571 | temp = er32(BPRC); | 
|  | 4572 | temp = er32(MPRC); | 
|  | 4573 | temp = er32(GPTC); | 
|  | 4574 | temp = er32(GORCL); | 
|  | 4575 | temp = er32(GORCH); | 
|  | 4576 | temp = er32(GOTCL); | 
|  | 4577 | temp = er32(GOTCH); | 
|  | 4578 | temp = er32(RNBC); | 
|  | 4579 | temp = er32(RUC); | 
|  | 4580 | temp = er32(RFC); | 
|  | 4581 | temp = er32(ROC); | 
|  | 4582 | temp = er32(RJC); | 
|  | 4583 | temp = er32(TORL); | 
|  | 4584 | temp = er32(TORH); | 
|  | 4585 | temp = er32(TOTL); | 
|  | 4586 | temp = er32(TOTH); | 
|  | 4587 | temp = er32(TPR); | 
|  | 4588 | temp = er32(TPT); | 
| Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4589 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4590 | temp = er32(PTC64); | 
|  | 4591 | temp = er32(PTC127); | 
|  | 4592 | temp = er32(PTC255); | 
|  | 4593 | temp = er32(PTC511); | 
|  | 4594 | temp = er32(PTC1023); | 
|  | 4595 | temp = er32(PTC1522); | 
| Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4596 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4597 | temp = er32(MPTC); | 
|  | 4598 | temp = er32(BPTC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4599 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4600 | if (hw->mac_type < e1000_82543) | 
|  | 4601 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4602 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4603 | temp = er32(ALGNERRC); | 
|  | 4604 | temp = er32(RXERRC); | 
|  | 4605 | temp = er32(TNCRS); | 
|  | 4606 | temp = er32(CEXTERR); | 
|  | 4607 | temp = er32(TSCTC); | 
|  | 4608 | temp = er32(TSCTFC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4609 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4610 | if (hw->mac_type <= e1000_82544) | 
|  | 4611 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4613 | temp = er32(MGTPRC); | 
|  | 4614 | temp = er32(MGTPDC); | 
|  | 4615 | temp = er32(MGTPTC); | 
| 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_reset_adaptive - Resets Adaptive IFS to its default state. | 
|  | 4620 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | * | 
|  | 4622 | * 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] | 4623 | * hw->ifs_params_forced to true. However, you must initialize hw-> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio | 
|  | 4625 | * before calling this function. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4626 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4627 | void e1000_reset_adaptive(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4629 | DEBUGFUNC("e1000_reset_adaptive"); | 
| 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 | if (hw->adaptive_ifs) { | 
|  | 4632 | if (!hw->ifs_params_forced) { | 
|  | 4633 | hw->current_ifs_val = 0; | 
|  | 4634 | hw->ifs_min_val = IFS_MIN; | 
|  | 4635 | hw->ifs_max_val = IFS_MAX; | 
|  | 4636 | hw->ifs_step_size = IFS_STEP; | 
|  | 4637 | hw->ifs_ratio = IFS_RATIO; | 
|  | 4638 | } | 
|  | 4639 | hw->in_ifs_mode = false; | 
|  | 4640 | ew32(AIT, 0); | 
|  | 4641 | } else { | 
|  | 4642 | DEBUGOUT("Not in Adaptive IFS mode!\n"); | 
|  | 4643 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | } | 
|  | 4645 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4646 | /** | 
|  | 4647 | * e1000_update_adaptive - update adaptive IFS | 
|  | 4648 | * @hw: Struct containing variables accessed by shared code | 
|  | 4649 | * @tx_packets: Number of transmits since last callback | 
|  | 4650 | * @total_collisions: Number of collisions since last callback | 
|  | 4651 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4652 | * Called during the callback/watchdog routine to update IFS value based on | 
|  | 4653 | * the ratio of transmits to collisions. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4654 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4655 | void e1000_update_adaptive(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4656 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4657 | DEBUGFUNC("e1000_update_adaptive"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4659 | if (hw->adaptive_ifs) { | 
|  | 4660 | if ((hw->collision_delta *hw->ifs_ratio) > hw->tx_packet_delta) { | 
|  | 4661 | if (hw->tx_packet_delta > MIN_NUM_XMITS) { | 
|  | 4662 | hw->in_ifs_mode = true; | 
|  | 4663 | if (hw->current_ifs_val < hw->ifs_max_val) { | 
|  | 4664 | if (hw->current_ifs_val == 0) | 
|  | 4665 | hw->current_ifs_val = | 
|  | 4666 | hw->ifs_min_val; | 
|  | 4667 | else | 
|  | 4668 | hw->current_ifs_val += | 
|  | 4669 | hw->ifs_step_size; | 
|  | 4670 | ew32(AIT, hw->current_ifs_val); | 
|  | 4671 | } | 
|  | 4672 | } | 
|  | 4673 | } else { | 
|  | 4674 | if (hw->in_ifs_mode | 
|  | 4675 | && (hw->tx_packet_delta <= MIN_NUM_XMITS)) { | 
|  | 4676 | hw->current_ifs_val = 0; | 
|  | 4677 | hw->in_ifs_mode = false; | 
|  | 4678 | ew32(AIT, 0); | 
|  | 4679 | } | 
|  | 4680 | } | 
|  | 4681 | } else { | 
|  | 4682 | DEBUGOUT("Not in Adaptive IFS mode!\n"); | 
|  | 4683 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4684 | } | 
|  | 4685 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4686 | /** | 
|  | 4687 | * e1000_tbi_adjust_stats | 
|  | 4688 | * @hw: Struct containing variables accessed by shared code | 
|  | 4689 | * @frame_len: The length of the frame in question | 
|  | 4690 | * @mac_addr: The Ethernet destination address of the frame in question | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4691 | * | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4692 | * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT | 
|  | 4693 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4694 | void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats, | 
|  | 4695 | u32 frame_len, u8 *mac_addr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4696 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4697 | u64 carry_bit; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4698 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4699 | /* First adjust the frame length. */ | 
|  | 4700 | frame_len--; | 
|  | 4701 | /* We need to adjust the statistics counters, since the hardware | 
|  | 4702 | * counters overcount this packet as a CRC error and undercount | 
|  | 4703 | * the packet as a good packet | 
|  | 4704 | */ | 
|  | 4705 | /* This packet should not be counted as a CRC error.    */ | 
|  | 4706 | stats->crcerrs--; | 
|  | 4707 | /* This packet does count as a Good Packet Received.    */ | 
|  | 4708 | stats->gprc++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4709 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4710 | /* Adjust the Good Octets received counters             */ | 
|  | 4711 | carry_bit = 0x80000000 & stats->gorcl; | 
|  | 4712 | stats->gorcl += frame_len; | 
|  | 4713 | /* If the high bit of Gorcl (the low 32 bits of the Good Octets | 
|  | 4714 | * Received Count) was one before the addition, | 
|  | 4715 | * AND it is zero after, then we lost the carry out, | 
|  | 4716 | * need to add one to Gorch (Good Octets Received Count High). | 
|  | 4717 | * This could be simplified if all environments supported | 
|  | 4718 | * 64-bit integers. | 
|  | 4719 | */ | 
|  | 4720 | if (carry_bit && ((stats->gorcl & 0x80000000) == 0)) | 
|  | 4721 | stats->gorch++; | 
|  | 4722 | /* Is this a broadcast or multicast?  Check broadcast first, | 
|  | 4723 | * since the test for a multicast frame will test positive on | 
|  | 4724 | * a broadcast frame. | 
|  | 4725 | */ | 
|  | 4726 | if ((mac_addr[0] == (u8) 0xff) && (mac_addr[1] == (u8) 0xff)) | 
|  | 4727 | /* Broadcast packet */ | 
|  | 4728 | stats->bprc++; | 
|  | 4729 | else if (*mac_addr & 0x01) | 
|  | 4730 | /* Multicast packet */ | 
|  | 4731 | stats->mprc++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4732 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4733 | if (frame_len == hw->max_frame_size) { | 
|  | 4734 | /* In this case, the hardware has overcounted the number of | 
|  | 4735 | * oversize frames. | 
|  | 4736 | */ | 
|  | 4737 | if (stats->roc > 0) | 
|  | 4738 | stats->roc--; | 
|  | 4739 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4740 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4741 | /* Adjust the bin counters when the extra byte put the frame in the | 
|  | 4742 | * wrong bin. Remember that the frame_len was adjusted above. | 
|  | 4743 | */ | 
|  | 4744 | if (frame_len == 64) { | 
|  | 4745 | stats->prc64++; | 
|  | 4746 | stats->prc127--; | 
|  | 4747 | } else if (frame_len == 127) { | 
|  | 4748 | stats->prc127++; | 
|  | 4749 | stats->prc255--; | 
|  | 4750 | } else if (frame_len == 255) { | 
|  | 4751 | stats->prc255++; | 
|  | 4752 | stats->prc511--; | 
|  | 4753 | } else if (frame_len == 511) { | 
|  | 4754 | stats->prc511++; | 
|  | 4755 | stats->prc1023--; | 
|  | 4756 | } else if (frame_len == 1023) { | 
|  | 4757 | stats->prc1023++; | 
|  | 4758 | stats->prc1522--; | 
|  | 4759 | } else if (frame_len == 1522) { | 
|  | 4760 | stats->prc1522++; | 
|  | 4761 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | } | 
|  | 4763 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4764 | /** | 
|  | 4765 | * e1000_get_bus_info | 
|  | 4766 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4767 | * | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4768 | * Gets the current PCI bus type, speed, and width of the hardware | 
|  | 4769 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4770 | void e1000_get_bus_info(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4772 | u32 status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4774 | switch (hw->mac_type) { | 
|  | 4775 | case e1000_82542_rev2_0: | 
|  | 4776 | case e1000_82542_rev2_1: | 
|  | 4777 | hw->bus_type = e1000_bus_type_pci; | 
|  | 4778 | hw->bus_speed = e1000_bus_speed_unknown; | 
|  | 4779 | hw->bus_width = e1000_bus_width_unknown; | 
|  | 4780 | break; | 
|  | 4781 | default: | 
|  | 4782 | status = er32(STATUS); | 
|  | 4783 | hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ? | 
|  | 4784 | e1000_bus_type_pcix : e1000_bus_type_pci; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4785 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4786 | if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) { | 
|  | 4787 | hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ? | 
|  | 4788 | e1000_bus_speed_66 : e1000_bus_speed_120; | 
|  | 4789 | } else if (hw->bus_type == e1000_bus_type_pci) { | 
|  | 4790 | hw->bus_speed = (status & E1000_STATUS_PCI66) ? | 
|  | 4791 | e1000_bus_speed_66 : e1000_bus_speed_33; | 
|  | 4792 | } else { | 
|  | 4793 | switch (status & E1000_STATUS_PCIX_SPEED) { | 
|  | 4794 | case E1000_STATUS_PCIX_SPEED_66: | 
|  | 4795 | hw->bus_speed = e1000_bus_speed_66; | 
|  | 4796 | break; | 
|  | 4797 | case E1000_STATUS_PCIX_SPEED_100: | 
|  | 4798 | hw->bus_speed = e1000_bus_speed_100; | 
|  | 4799 | break; | 
|  | 4800 | case E1000_STATUS_PCIX_SPEED_133: | 
|  | 4801 | hw->bus_speed = e1000_bus_speed_133; | 
|  | 4802 | break; | 
|  | 4803 | default: | 
|  | 4804 | hw->bus_speed = e1000_bus_speed_reserved; | 
|  | 4805 | break; | 
|  | 4806 | } | 
|  | 4807 | } | 
|  | 4808 | hw->bus_width = (status & E1000_STATUS_BUS64) ? | 
|  | 4809 | e1000_bus_width_64 : e1000_bus_width_32; | 
|  | 4810 | break; | 
|  | 4811 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4812 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4813 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4814 | /** | 
|  | 4815 | * e1000_write_reg_io | 
|  | 4816 | * @hw: Struct containing variables accessed by shared code | 
|  | 4817 | * @offset: offset to write to | 
|  | 4818 | * @value: value to write | 
|  | 4819 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4820 | * Writes a value to one of the devices registers using port I/O (as opposed to | 
|  | 4821 | * 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] | 4822 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4823 | 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] | 4824 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4825 | unsigned long io_addr = hw->io_base; | 
|  | 4826 | unsigned long io_data = hw->io_base + 4; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4827 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4828 | e1000_io_write(hw, io_addr, offset); | 
|  | 4829 | e1000_io_write(hw, io_data, value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4830 | } | 
|  | 4831 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4832 | /** | 
|  | 4833 | * e1000_get_cable_length - Estimates the cable length. | 
|  | 4834 | * @hw: Struct containing variables accessed by shared code | 
|  | 4835 | * @min_length: The estimated minimum length | 
|  | 4836 | * @max_length: The estimated maximum length | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4837 | * | 
|  | 4838 | * returns: - E1000_ERR_XXX | 
|  | 4839 | *            E1000_SUCCESS | 
|  | 4840 | * | 
|  | 4841 | * This function always returns a ranged length (minimum & maximum). | 
|  | 4842 | * So for M88 phy's, this function interprets the one value returned from the | 
|  | 4843 | * register to the minimum and maximum range. | 
|  | 4844 | * 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] | 4845 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4846 | static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length, | 
|  | 4847 | u16 *max_length) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4848 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4849 | s32 ret_val; | 
|  | 4850 | u16 agc_value = 0; | 
|  | 4851 | u16 i, phy_data; | 
|  | 4852 | u16 cable_length; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4853 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4854 | DEBUGFUNC("e1000_get_cable_length"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4855 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4856 | *min_length = *max_length = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4857 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4858 | /* Use old method for Phy older than IGP */ | 
|  | 4859 | if (hw->phy_type == e1000_phy_m88) { | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4860 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4861 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, | 
|  | 4862 | &phy_data); | 
|  | 4863 | if (ret_val) | 
|  | 4864 | return ret_val; | 
|  | 4865 | cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >> | 
|  | 4866 | M88E1000_PSSR_CABLE_LENGTH_SHIFT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4867 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4868 | /* Convert the enum value to ranged values */ | 
|  | 4869 | switch (cable_length) { | 
|  | 4870 | case e1000_cable_length_50: | 
|  | 4871 | *min_length = 0; | 
|  | 4872 | *max_length = e1000_igp_cable_length_50; | 
|  | 4873 | break; | 
|  | 4874 | case e1000_cable_length_50_80: | 
|  | 4875 | *min_length = e1000_igp_cable_length_50; | 
|  | 4876 | *max_length = e1000_igp_cable_length_80; | 
|  | 4877 | break; | 
|  | 4878 | case e1000_cable_length_80_110: | 
|  | 4879 | *min_length = e1000_igp_cable_length_80; | 
|  | 4880 | *max_length = e1000_igp_cable_length_110; | 
|  | 4881 | break; | 
|  | 4882 | case e1000_cable_length_110_140: | 
|  | 4883 | *min_length = e1000_igp_cable_length_110; | 
|  | 4884 | *max_length = e1000_igp_cable_length_140; | 
|  | 4885 | break; | 
|  | 4886 | case e1000_cable_length_140: | 
|  | 4887 | *min_length = e1000_igp_cable_length_140; | 
|  | 4888 | *max_length = e1000_igp_cable_length_170; | 
|  | 4889 | break; | 
|  | 4890 | default: | 
|  | 4891 | return -E1000_ERR_PHY; | 
|  | 4892 | break; | 
|  | 4893 | } | 
|  | 4894 | } else if (hw->phy_type == e1000_phy_igp) {	/* For IGP PHY */ | 
|  | 4895 | u16 cur_agc_value; | 
|  | 4896 | u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE; | 
|  | 4897 | u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = | 
|  | 4898 | { IGP01E1000_PHY_AGC_A, | 
|  | 4899 | IGP01E1000_PHY_AGC_B, | 
|  | 4900 | IGP01E1000_PHY_AGC_C, | 
|  | 4901 | IGP01E1000_PHY_AGC_D | 
|  | 4902 | }; | 
|  | 4903 | /* Read the AGC registers for all channels */ | 
|  | 4904 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4906 | ret_val = | 
|  | 4907 | e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data); | 
|  | 4908 | if (ret_val) | 
|  | 4909 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4910 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4911 | cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4912 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4913 | /* Value bound check. */ | 
|  | 4914 | if ((cur_agc_value >= | 
|  | 4915 | IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) | 
|  | 4916 | || (cur_agc_value == 0)) | 
|  | 4917 | return -E1000_ERR_PHY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4918 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4919 | agc_value += cur_agc_value; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4921 | /* Update minimal AGC value. */ | 
|  | 4922 | if (min_agc_value > cur_agc_value) | 
|  | 4923 | min_agc_value = cur_agc_value; | 
|  | 4924 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4925 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4926 | /* Remove the minimal AGC result for length < 50m */ | 
|  | 4927 | if (agc_value < | 
|  | 4928 | IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) { | 
|  | 4929 | agc_value -= min_agc_value; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4930 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4931 | /* Get the average length of the remaining 3 channels */ | 
|  | 4932 | agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1); | 
|  | 4933 | } else { | 
|  | 4934 | /* Get the average length of all the 4 channels. */ | 
|  | 4935 | agc_value /= IGP01E1000_PHY_CHANNEL_NUM; | 
|  | 4936 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4938 | /* Set the range of the calculated length. */ | 
|  | 4939 | *min_length = ((e1000_igp_cable_length_table[agc_value] - | 
|  | 4940 | IGP01E1000_AGC_RANGE) > 0) ? | 
|  | 4941 | (e1000_igp_cable_length_table[agc_value] - | 
|  | 4942 | IGP01E1000_AGC_RANGE) : 0; | 
|  | 4943 | *max_length = e1000_igp_cable_length_table[agc_value] + | 
|  | 4944 | IGP01E1000_AGC_RANGE; | 
|  | 4945 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4946 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4947 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4948 | } | 
|  | 4949 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4950 | /** | 
|  | 4951 | * e1000_check_polarity - Check the cable polarity | 
|  | 4952 | * @hw: Struct containing variables accessed by shared code | 
|  | 4953 | * @polarity: output parameter : 0 - Polarity is not reversed | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | *                               1 - Polarity is reversed. | 
|  | 4955 | * | 
|  | 4956 | * returns: - E1000_ERR_XXX | 
|  | 4957 | *            E1000_SUCCESS | 
|  | 4958 | * | 
| Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4959 | * 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] | 4960 | * Phy Status register.  For IGP phy's, this bit is valid only if link speed is | 
|  | 4961 | * 10 Mbps.  If the link speed is 100 Mbps there is no polarity so this bit will | 
|  | 4962 | * return 0.  If the link speed is 1000 Mbps the polarity status is in the | 
|  | 4963 | * IGP01E1000_PHY_PCS_INIT_REG. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4964 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4965 | static s32 e1000_check_polarity(struct e1000_hw *hw, | 
|  | 4966 | e1000_rev_polarity *polarity) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4967 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4968 | s32 ret_val; | 
|  | 4969 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4970 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4971 | DEBUGFUNC("e1000_check_polarity"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4973 | if (hw->phy_type == e1000_phy_m88) { | 
|  | 4974 | /* return the Polarity bit in the Status register. */ | 
|  | 4975 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, | 
|  | 4976 | &phy_data); | 
|  | 4977 | if (ret_val) | 
|  | 4978 | return ret_val; | 
|  | 4979 | *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >> | 
|  | 4980 | M88E1000_PSSR_REV_POLARITY_SHIFT) ? | 
|  | 4981 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; | 
| Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4982 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4983 | } else if (hw->phy_type == e1000_phy_igp) { | 
|  | 4984 | /* Read the Status register to check the speed */ | 
|  | 4985 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, | 
|  | 4986 | &phy_data); | 
|  | 4987 | if (ret_val) | 
|  | 4988 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4989 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4990 | /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to | 
|  | 4991 | * find the polarity status */ | 
|  | 4992 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == | 
|  | 4993 | IGP01E1000_PSSR_SPEED_1000MBPS) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4994 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 4995 | /* Read the GIG initialization PCS register (0x00B4) */ | 
|  | 4996 | ret_val = | 
|  | 4997 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG, | 
|  | 4998 | &phy_data); | 
|  | 4999 | if (ret_val) | 
|  | 5000 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5001 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5002 | /* Check the polarity bits */ | 
|  | 5003 | *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? | 
|  | 5004 | e1000_rev_polarity_reversed : | 
|  | 5005 | e1000_rev_polarity_normal; | 
|  | 5006 | } else { | 
|  | 5007 | /* For 10 Mbps, read the polarity bit in the status register. (for | 
|  | 5008 | * 100 Mbps this bit is always 0) */ | 
|  | 5009 | *polarity = | 
|  | 5010 | (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ? | 
|  | 5011 | e1000_rev_polarity_reversed : | 
|  | 5012 | e1000_rev_polarity_normal; | 
|  | 5013 | } | 
|  | 5014 | } | 
|  | 5015 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5016 | } | 
|  | 5017 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5018 | /** | 
|  | 5019 | * e1000_check_downshift - Check if Downshift occurred | 
|  | 5020 | * @hw: Struct containing variables accessed by shared code | 
|  | 5021 | * @downshift: output parameter : 0 - No Downshift occurred. | 
|  | 5022 | *                                1 - Downshift occurred. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | * | 
|  | 5024 | * returns: - E1000_ERR_XXX | 
| Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5025 | *            E1000_SUCCESS | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5026 | * | 
| Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 5027 | * 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] | 5028 | * Specific Status register.  For IGP phy's, it reads the Downgrade bit in the | 
|  | 5029 | * Link Health register.  In IGP this bit is latched high, so the driver must | 
|  | 5030 | * read it immediately after link is established. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5031 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5032 | static s32 e1000_check_downshift(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5033 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5034 | s32 ret_val; | 
|  | 5035 | u16 phy_data; | 
| 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 | DEBUGFUNC("e1000_check_downshift"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5038 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5039 | if (hw->phy_type == e1000_phy_igp) { | 
|  | 5040 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH, | 
|  | 5041 | &phy_data); | 
|  | 5042 | if (ret_val) | 
|  | 5043 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5044 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5045 | hw->speed_downgraded = | 
|  | 5046 | (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0; | 
|  | 5047 | } else if (hw->phy_type == e1000_phy_m88) { | 
|  | 5048 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, | 
|  | 5049 | &phy_data); | 
|  | 5050 | if (ret_val) | 
|  | 5051 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5053 | hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >> | 
|  | 5054 | M88E1000_PSSR_DOWNSHIFT_SHIFT; | 
|  | 5055 | } | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5056 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5057 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5058 | } | 
|  | 5059 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5060 | /** | 
|  | 5061 | * e1000_config_dsp_after_link_change | 
|  | 5062 | * @hw: Struct containing variables accessed by shared code | 
|  | 5063 | * @link_up: was link up at the time this was called | 
|  | 5064 | * | 
|  | 5065 | * returns: - E1000_ERR_PHY if fail to read/write the PHY | 
|  | 5066 | *            E1000_SUCCESS at any other case. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5067 | * | 
|  | 5068 | * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a | 
|  | 5069 | * gigabit link is achieved to improve link quality. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5070 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5071 |  | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5072 | 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] | 5073 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5074 | s32 ret_val; | 
|  | 5075 | u16 phy_data, phy_saved_data, speed, duplex, i; | 
|  | 5076 | u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = | 
|  | 5077 | { IGP01E1000_PHY_AGC_PARAM_A, | 
|  | 5078 | IGP01E1000_PHY_AGC_PARAM_B, | 
|  | 5079 | IGP01E1000_PHY_AGC_PARAM_C, | 
|  | 5080 | IGP01E1000_PHY_AGC_PARAM_D | 
|  | 5081 | }; | 
|  | 5082 | u16 min_length, max_length; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5083 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5084 | DEBUGFUNC("e1000_config_dsp_after_link_change"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5085 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5086 | if (hw->phy_type != e1000_phy_igp) | 
|  | 5087 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5088 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5089 | if (link_up) { | 
|  | 5090 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); | 
|  | 5091 | if (ret_val) { | 
|  | 5092 | DEBUGOUT("Error getting link speed and duplex\n"); | 
|  | 5093 | return ret_val; | 
|  | 5094 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5095 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5096 | if (speed == SPEED_1000) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5097 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5098 | ret_val = | 
|  | 5099 | e1000_get_cable_length(hw, &min_length, | 
|  | 5100 | &max_length); | 
|  | 5101 | if (ret_val) | 
|  | 5102 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5103 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5104 | if ((hw->dsp_config_state == e1000_dsp_config_enabled) | 
|  | 5105 | && min_length >= e1000_igp_cable_length_50) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5106 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5107 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { | 
|  | 5108 | ret_val = | 
|  | 5109 | e1000_read_phy_reg(hw, | 
|  | 5110 | dsp_reg_array[i], | 
|  | 5111 | &phy_data); | 
|  | 5112 | if (ret_val) | 
|  | 5113 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5114 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5115 | phy_data &= | 
|  | 5116 | ~IGP01E1000_PHY_EDAC_MU_INDEX; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5117 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5118 | ret_val = | 
|  | 5119 | e1000_write_phy_reg(hw, | 
|  | 5120 | dsp_reg_array | 
|  | 5121 | [i], phy_data); | 
|  | 5122 | if (ret_val) | 
|  | 5123 | return ret_val; | 
|  | 5124 | } | 
|  | 5125 | hw->dsp_config_state = | 
|  | 5126 | e1000_dsp_config_activated; | 
|  | 5127 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5128 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5129 | if ((hw->ffe_config_state == e1000_ffe_config_enabled) | 
|  | 5130 | && (min_length < e1000_igp_cable_length_50)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5131 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5132 | u16 ffe_idle_err_timeout = | 
|  | 5133 | FFE_IDLE_ERR_COUNT_TIMEOUT_20; | 
|  | 5134 | u32 idle_errs = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5135 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5136 | /* clear previous idle error counts */ | 
|  | 5137 | ret_val = | 
|  | 5138 | e1000_read_phy_reg(hw, PHY_1000T_STATUS, | 
|  | 5139 | &phy_data); | 
|  | 5140 | if (ret_val) | 
|  | 5141 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5142 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5143 | for (i = 0; i < ffe_idle_err_timeout; i++) { | 
|  | 5144 | udelay(1000); | 
|  | 5145 | ret_val = | 
|  | 5146 | e1000_read_phy_reg(hw, | 
|  | 5147 | PHY_1000T_STATUS, | 
|  | 5148 | &phy_data); | 
|  | 5149 | if (ret_val) | 
|  | 5150 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5151 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5152 | idle_errs += | 
|  | 5153 | (phy_data & | 
|  | 5154 | SR_1000T_IDLE_ERROR_CNT); | 
|  | 5155 | if (idle_errs > | 
|  | 5156 | SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) | 
|  | 5157 | { | 
|  | 5158 | hw->ffe_config_state = | 
|  | 5159 | e1000_ffe_config_active; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5160 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5161 | ret_val = | 
|  | 5162 | e1000_write_phy_reg(hw, | 
|  | 5163 | IGP01E1000_PHY_DSP_FFE, | 
|  | 5164 | IGP01E1000_PHY_DSP_FFE_CM_CP); | 
|  | 5165 | if (ret_val) | 
|  | 5166 | return ret_val; | 
|  | 5167 | break; | 
|  | 5168 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5169 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5170 | if (idle_errs) | 
|  | 5171 | ffe_idle_err_timeout = | 
|  | 5172 | FFE_IDLE_ERR_COUNT_TIMEOUT_100; | 
|  | 5173 | } | 
|  | 5174 | } | 
|  | 5175 | } | 
|  | 5176 | } else { | 
|  | 5177 | if (hw->dsp_config_state == e1000_dsp_config_activated) { | 
|  | 5178 | /* Save off the current value of register 0x2F5B to be restored at | 
|  | 5179 | * the end of the routines. */ | 
|  | 5180 | ret_val = | 
|  | 5181 | e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5182 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5183 | if (ret_val) | 
|  | 5184 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5185 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5186 | /* Disable the PHY transmitter */ | 
|  | 5187 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); | 
| 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 | if (ret_val) | 
|  | 5190 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5191 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5192 | mdelay(20); | 
| 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 | ret_val = e1000_write_phy_reg(hw, 0x0000, | 
|  | 5195 | IGP01E1000_IEEE_FORCE_GIGA); | 
|  | 5196 | if (ret_val) | 
|  | 5197 | return ret_val; | 
|  | 5198 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { | 
|  | 5199 | ret_val = | 
|  | 5200 | e1000_read_phy_reg(hw, dsp_reg_array[i], | 
|  | 5201 | &phy_data); | 
|  | 5202 | if (ret_val) | 
|  | 5203 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5204 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5205 | phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX; | 
|  | 5206 | phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5207 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5208 | ret_val = | 
|  | 5209 | e1000_write_phy_reg(hw, dsp_reg_array[i], | 
|  | 5210 | phy_data); | 
|  | 5211 | if (ret_val) | 
|  | 5212 | return ret_val; | 
|  | 5213 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5214 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5215 | ret_val = e1000_write_phy_reg(hw, 0x0000, | 
|  | 5216 | IGP01E1000_IEEE_RESTART_AUTONEG); | 
|  | 5217 | if (ret_val) | 
|  | 5218 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5219 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5220 | mdelay(20); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5221 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5222 | /* Now enable the transmitter */ | 
|  | 5223 | ret_val = | 
|  | 5224 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5225 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5226 | if (ret_val) | 
|  | 5227 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5228 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5229 | hw->dsp_config_state = e1000_dsp_config_enabled; | 
|  | 5230 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5231 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5232 | if (hw->ffe_config_state == e1000_ffe_config_active) { | 
|  | 5233 | /* Save off the current value of register 0x2F5B to be restored at | 
|  | 5234 | * the end of the routines. */ | 
|  | 5235 | ret_val = | 
|  | 5236 | e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5237 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5238 | if (ret_val) | 
|  | 5239 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5240 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5241 | /* Disable the PHY transmitter */ | 
|  | 5242 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5243 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5244 | if (ret_val) | 
|  | 5245 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5246 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5247 | mdelay(20); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5248 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5249 | ret_val = e1000_write_phy_reg(hw, 0x0000, | 
|  | 5250 | IGP01E1000_IEEE_FORCE_GIGA); | 
|  | 5251 | if (ret_val) | 
|  | 5252 | return ret_val; | 
|  | 5253 | ret_val = | 
|  | 5254 | e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE, | 
|  | 5255 | IGP01E1000_PHY_DSP_FFE_DEFAULT); | 
|  | 5256 | if (ret_val) | 
|  | 5257 | return ret_val; | 
| 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 | ret_val = e1000_write_phy_reg(hw, 0x0000, | 
|  | 5260 | IGP01E1000_IEEE_RESTART_AUTONEG); | 
|  | 5261 | if (ret_val) | 
|  | 5262 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5263 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5264 | mdelay(20); | 
| 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 | /* Now enable the transmitter */ | 
|  | 5267 | ret_val = | 
|  | 5268 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5269 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5270 | if (ret_val) | 
|  | 5271 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5272 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5273 | hw->ffe_config_state = e1000_ffe_config_enabled; | 
|  | 5274 | } | 
|  | 5275 | } | 
|  | 5276 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5277 | } | 
|  | 5278 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5279 | /** | 
|  | 5280 | * e1000_set_phy_mode - Set PHY to class A mode | 
|  | 5281 | * @hw: Struct containing variables accessed by shared code | 
|  | 5282 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5283 | * Assumes the following operations will follow to enable the new class mode. | 
|  | 5284 | *  1. Do a PHY soft reset | 
|  | 5285 | *  2. Restart auto-negotiation or force link. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5286 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5287 | static s32 e1000_set_phy_mode(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5288 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5289 | s32 ret_val; | 
|  | 5290 | u16 eeprom_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5291 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5292 | DEBUGFUNC("e1000_set_phy_mode"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5293 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5294 | if ((hw->mac_type == e1000_82545_rev_3) && | 
|  | 5295 | (hw->media_type == e1000_media_type_copper)) { | 
|  | 5296 | ret_val = | 
|  | 5297 | e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, | 
|  | 5298 | &eeprom_data); | 
|  | 5299 | if (ret_val) { | 
|  | 5300 | return ret_val; | 
|  | 5301 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5302 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5303 | if ((eeprom_data != EEPROM_RESERVED_WORD) && | 
|  | 5304 | (eeprom_data & EEPROM_PHY_CLASS_A)) { | 
|  | 5305 | ret_val = | 
|  | 5306 | e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, | 
|  | 5307 | 0x000B); | 
|  | 5308 | if (ret_val) | 
|  | 5309 | return ret_val; | 
|  | 5310 | ret_val = | 
|  | 5311 | e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, | 
|  | 5312 | 0x8104); | 
|  | 5313 | if (ret_val) | 
|  | 5314 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5315 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5316 | hw->phy_reset_disable = false; | 
|  | 5317 | } | 
|  | 5318 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5319 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5320 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | } | 
|  | 5322 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5323 | /** | 
|  | 5324 | * e1000_set_d3_lplu_state - set d3 link power state | 
|  | 5325 | * @hw: Struct containing variables accessed by shared code | 
|  | 5326 | * @active: true to enable lplu false to disable lplu. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5327 | * | 
|  | 5328 | * This function sets the lplu state according to the active flag.  When | 
|  | 5329 | * activating lplu this function also disables smart speed and vise versa. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5330 | * lplu will not be activated unless the device autonegotiation advertisement | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5331 | * 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] | 5332 | * | 
|  | 5333 | * returns: - E1000_ERR_PHY if fail to read/write the PHY | 
|  | 5334 | *            E1000_SUCCESS at any other case. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5335 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5336 | 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] | 5337 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5338 | s32 ret_val; | 
|  | 5339 | u16 phy_data; | 
|  | 5340 | DEBUGFUNC("e1000_set_d3_lplu_state"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5341 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5342 | if (hw->phy_type != e1000_phy_igp) | 
|  | 5343 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5344 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5345 | /* During driver activity LPLU should not be used or it will attain link | 
|  | 5346 | * from the lowest speeds starting from 10Mbps. The capability is used for | 
|  | 5347 | * Dx transitions and states */ | 
|  | 5348 | if (hw->mac_type == e1000_82541_rev_2 | 
|  | 5349 | || hw->mac_type == e1000_82547_rev_2) { | 
|  | 5350 | ret_val = | 
|  | 5351 | e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data); | 
|  | 5352 | if (ret_val) | 
|  | 5353 | return ret_val; | 
|  | 5354 | } | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5355 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5356 | if (!active) { | 
|  | 5357 | if (hw->mac_type == e1000_82541_rev_2 || | 
|  | 5358 | hw->mac_type == e1000_82547_rev_2) { | 
|  | 5359 | phy_data &= ~IGP01E1000_GMII_FLEX_SPD; | 
|  | 5360 | ret_val = | 
|  | 5361 | e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, | 
|  | 5362 | phy_data); | 
|  | 5363 | if (ret_val) | 
|  | 5364 | return ret_val; | 
|  | 5365 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5366 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5367 | /* LPLU and SmartSpeed are mutually exclusive.  LPLU is used during | 
|  | 5368 | * Dx states where the power conservation is most important.  During | 
|  | 5369 | * driver activity we should enable SmartSpeed, so performance is | 
|  | 5370 | * maintained. */ | 
|  | 5371 | if (hw->smart_speed == e1000_smart_speed_on) { | 
|  | 5372 | ret_val = | 
|  | 5373 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 5374 | &phy_data); | 
|  | 5375 | if (ret_val) | 
|  | 5376 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5377 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5378 | phy_data |= IGP01E1000_PSCFR_SMART_SPEED; | 
|  | 5379 | ret_val = | 
|  | 5380 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 5381 | phy_data); | 
|  | 5382 | if (ret_val) | 
|  | 5383 | return ret_val; | 
|  | 5384 | } else if (hw->smart_speed == e1000_smart_speed_off) { | 
|  | 5385 | ret_val = | 
|  | 5386 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 5387 | &phy_data); | 
|  | 5388 | if (ret_val) | 
|  | 5389 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5390 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5391 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; | 
|  | 5392 | ret_val = | 
|  | 5393 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 5394 | phy_data); | 
|  | 5395 | if (ret_val) | 
|  | 5396 | return ret_val; | 
|  | 5397 | } | 
|  | 5398 | } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) | 
|  | 5399 | || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) | 
|  | 5400 | || (hw->autoneg_advertised == | 
|  | 5401 | AUTONEG_ADVERTISE_10_100_ALL)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5402 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5403 | if (hw->mac_type == e1000_82541_rev_2 || | 
|  | 5404 | hw->mac_type == e1000_82547_rev_2) { | 
|  | 5405 | phy_data |= IGP01E1000_GMII_FLEX_SPD; | 
|  | 5406 | ret_val = | 
|  | 5407 | e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, | 
|  | 5408 | phy_data); | 
|  | 5409 | if (ret_val) | 
|  | 5410 | return ret_val; | 
|  | 5411 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5412 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5413 | /* When LPLU is enabled we should disable SmartSpeed */ | 
|  | 5414 | ret_val = | 
|  | 5415 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 5416 | &phy_data); | 
|  | 5417 | if (ret_val) | 
|  | 5418 | return ret_val; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5419 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5420 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; | 
|  | 5421 | ret_val = | 
|  | 5422 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, | 
|  | 5423 | phy_data); | 
|  | 5424 | if (ret_val) | 
|  | 5425 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5426 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5427 | } | 
|  | 5428 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5429 | } | 
|  | 5430 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5431 | /** | 
|  | 5432 | * e1000_set_vco_speed | 
|  | 5433 | * @hw: Struct containing variables accessed by shared code | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5434 | * | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5435 | * Change VCO speed register to improve Bit Error Rate performance of SERDES. | 
|  | 5436 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5437 | static s32 e1000_set_vco_speed(struct e1000_hw *hw) | 
| 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 | s32 ret_val; | 
|  | 5440 | u16 default_page = 0; | 
|  | 5441 | u16 phy_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5442 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5443 | DEBUGFUNC("e1000_set_vco_speed"); | 
| 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 | switch (hw->mac_type) { | 
|  | 5446 | case e1000_82545_rev_3: | 
|  | 5447 | case e1000_82546_rev_3: | 
|  | 5448 | break; | 
|  | 5449 | default: | 
|  | 5450 | return E1000_SUCCESS; | 
|  | 5451 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5452 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5453 | /* Set PHY register 30, page 5, bit 8 to 0 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5454 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5455 | ret_val = | 
|  | 5456 | e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page); | 
|  | 5457 | if (ret_val) | 
|  | 5458 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5459 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5460 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005); | 
|  | 5461 | if (ret_val) | 
|  | 5462 | return ret_val; | 
| 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 = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data); | 
|  | 5465 | if (ret_val) | 
|  | 5466 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5467 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5468 | phy_data &= ~M88E1000_PHY_VCO_REG_BIT8; | 
|  | 5469 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data); | 
|  | 5470 | if (ret_val) | 
|  | 5471 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5472 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5473 | /* Set PHY register 30, page 4, bit 11 to 1 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5474 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5475 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004); | 
|  | 5476 | if (ret_val) | 
|  | 5477 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5478 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5479 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data); | 
|  | 5480 | if (ret_val) | 
|  | 5481 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5482 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5483 | phy_data |= M88E1000_PHY_VCO_REG_BIT11; | 
|  | 5484 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data); | 
|  | 5485 | if (ret_val) | 
|  | 5486 | return ret_val; | 
| 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 | ret_val = | 
|  | 5489 | e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page); | 
|  | 5490 | if (ret_val) | 
|  | 5491 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5492 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5493 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5494 | } | 
|  | 5495 |  | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5496 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5497 | /** | 
|  | 5498 | * e1000_enable_mng_pass_thru - check for bmc pass through | 
|  | 5499 | * @hw: Struct containing variables accessed by shared code | 
|  | 5500 | * | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5501 | * 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] | 5502 | * returns: - true/false | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5503 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5504 | u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5505 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5506 | u32 manc; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5507 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5508 | if (hw->asf_firmware_present) { | 
|  | 5509 | manc = er32(MANC); | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5510 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5511 | if (!(manc & E1000_MANC_RCV_TCO_EN) || | 
|  | 5512 | !(manc & E1000_MANC_EN_MAC_ADDR_FILTER)) | 
|  | 5513 | return false; | 
|  | 5514 | if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN)) | 
|  | 5515 | return true; | 
|  | 5516 | } | 
|  | 5517 | return false; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5518 | } | 
|  | 5519 |  | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5520 | static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5521 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5522 | s32 ret_val; | 
|  | 5523 | u16 mii_status_reg; | 
|  | 5524 | u16 i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5526 | /* Polarity reversal workaround for forced 10F/10H links. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5527 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5528 | /* Disable the transmitter on the PHY */ | 
| 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 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); | 
|  | 5531 | if (ret_val) | 
|  | 5532 | return ret_val; | 
|  | 5533 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF); | 
|  | 5534 | if (ret_val) | 
|  | 5535 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5536 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5537 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); | 
|  | 5538 | if (ret_val) | 
|  | 5539 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5540 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5541 | /* This loop will early-out if the NO link condition has been met. */ | 
|  | 5542 | for (i = PHY_FORCE_TIME; i > 0; i--) { | 
|  | 5543 | /* Read the MII Status Register and wait for Link Status bit | 
|  | 5544 | * to be clear. | 
|  | 5545 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5546 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5547 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 5548 | if (ret_val) | 
|  | 5549 | return ret_val; | 
| 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 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 5552 | if (ret_val) | 
|  | 5553 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5554 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5555 | if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) | 
|  | 5556 | break; | 
|  | 5557 | mdelay(100); | 
|  | 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 | /* Recommended delay time after link has been lost */ | 
|  | 5561 | mdelay(1000); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5562 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5563 | /* Now we will re-enable th transmitter on the PHY */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5564 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5565 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); | 
|  | 5566 | if (ret_val) | 
|  | 5567 | return ret_val; | 
|  | 5568 | mdelay(50); | 
|  | 5569 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0); | 
|  | 5570 | if (ret_val) | 
|  | 5571 | return ret_val; | 
|  | 5572 | mdelay(50); | 
|  | 5573 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00); | 
|  | 5574 | if (ret_val) | 
|  | 5575 | return ret_val; | 
|  | 5576 | mdelay(50); | 
|  | 5577 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000); | 
|  | 5578 | if (ret_val) | 
|  | 5579 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5580 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5581 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); | 
|  | 5582 | if (ret_val) | 
|  | 5583 | return ret_val; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5584 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5585 | /* This loop will early-out if the link condition has been met. */ | 
|  | 5586 | for (i = PHY_FORCE_TIME; i > 0; i--) { | 
|  | 5587 | /* Read the MII Status Register and wait for Link Status bit | 
|  | 5588 | * to be set. | 
|  | 5589 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5590 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5591 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 5592 | if (ret_val) | 
|  | 5593 | return ret_val; | 
| 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 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); | 
|  | 5596 | if (ret_val) | 
|  | 5597 | return ret_val; | 
| 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 (mii_status_reg & MII_SR_LINK_STATUS) | 
|  | 5600 | break; | 
|  | 5601 | mdelay(100); | 
|  | 5602 | } | 
|  | 5603 | return E1000_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5604 | } | 
|  | 5605 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5606 | /** | 
|  | 5607 | * e1000_get_auto_rd_done | 
|  | 5608 | * @hw: Struct containing variables accessed by shared code | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5609 | * | 
|  | 5610 | * Check for EEPROM Auto Read bit done. | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5611 | * returns: - E1000_ERR_RESET if fail to reset MAC | 
|  | 5612 | *            E1000_SUCCESS at any other case. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5613 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5614 | static s32 e1000_get_auto_rd_done(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5615 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5616 | DEBUGFUNC("e1000_get_auto_rd_done"); | 
|  | 5617 | msleep(5); | 
|  | 5618 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5619 | } | 
|  | 5620 |  | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5621 | /** | 
|  | 5622 | * e1000_get_phy_cfg_done | 
|  | 5623 | * @hw: Struct containing variables accessed by shared code | 
|  | 5624 | * | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5625 | * Checks if the PHY configuration is done | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5626 | * returns: - E1000_ERR_RESET if fail to reset MAC | 
|  | 5627 | *            E1000_SUCCESS at any other case. | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5628 | */ | 
| Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5629 | static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw) | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5630 | { | 
| Jesse Brandeburg | 120a5d0 | 2009-09-25 15:19:46 -0700 | [diff] [blame] | 5631 | DEBUGFUNC("e1000_get_phy_cfg_done"); | 
|  | 5632 | mdelay(10); | 
|  | 5633 | return E1000_SUCCESS; | 
| Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5634 | } |