Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 3 | Intel PRO/1000 Linux driver |
| 4 | Copyright(c) 1999 - 2006 Intel Corporation. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | more details. |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | You should have received a copy of the GNU General Public License along with |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | Contact Information: |
| 23 | Linux NICS <linux.nics@intel.com> |
Auke Kok | 3d41e30 | 2006-04-14 19:05:31 -0700 | [diff] [blame] | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | /* e1000_hw.c |
| 30 | * Shared functions for accessing and configuring the MAC |
| 31 | */ |
| 32 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include "e1000_hw.h" |
| 35 | |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 36 | static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask); |
| 37 | static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask); |
| 38 | static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data); |
| 39 | static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data); |
| 40 | static int32_t e1000_get_software_semaphore(struct e1000_hw *hw); |
| 41 | static void e1000_release_software_semaphore(struct e1000_hw *hw); |
| 42 | |
| 43 | static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw); |
| 44 | static int32_t e1000_check_downshift(struct e1000_hw *hw); |
| 45 | static int32_t e1000_check_polarity(struct e1000_hw *hw, e1000_rev_polarity *polarity); |
| 46 | static void e1000_clear_hw_cntrs(struct e1000_hw *hw); |
| 47 | static void e1000_clear_vfta(struct e1000_hw *hw); |
| 48 | static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw); |
| 49 | static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw, boolean_t link_up); |
| 50 | static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw); |
| 51 | static int32_t e1000_detect_gig_phy(struct e1000_hw *hw); |
| 52 | static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank); |
| 53 | static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw); |
| 54 | static int32_t e1000_get_cable_length(struct e1000_hw *hw, uint16_t *min_length, uint16_t *max_length); |
| 55 | static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw); |
| 56 | static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw); |
| 57 | static int32_t e1000_get_software_flag(struct e1000_hw *hw); |
| 58 | static int32_t e1000_ich8_cycle_init(struct e1000_hw *hw); |
| 59 | static int32_t e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout); |
| 60 | static int32_t e1000_id_led_init(struct e1000_hw *hw); |
| 61 | static int32_t e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw, uint32_t cnf_base_addr, uint32_t cnf_size); |
| 62 | static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw); |
| 63 | static void e1000_init_rx_addrs(struct e1000_hw *hw); |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 64 | static void e1000_initialize_hardware_bits(struct e1000_hw *hw); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 65 | static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw); |
| 66 | static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw); |
| 67 | static int32_t e1000_mng_enable_host_if(struct e1000_hw *hw); |
| 68 | static int32_t e1000_mng_host_if_write(struct e1000_hw *hw, uint8_t *buffer, uint16_t length, uint16_t offset, uint8_t *sum); |
| 69 | static int32_t e1000_mng_write_cmd_header(struct e1000_hw* hw, struct e1000_host_mng_command_header* hdr); |
| 70 | static int32_t e1000_mng_write_commit(struct e1000_hw *hw); |
| 71 | static int32_t e1000_phy_ife_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info); |
| 72 | static int32_t e1000_phy_igp_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info); |
| 73 | static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data); |
| 74 | static int32_t e1000_write_eeprom_eewr(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data); |
| 75 | static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd); |
| 76 | static int32_t e1000_phy_m88_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info); |
| 77 | static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw); |
| 78 | static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t *data); |
| 79 | static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte); |
| 80 | static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte); |
| 81 | static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data); |
| 82 | static int32_t e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t *data); |
| 83 | static int32_t e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t data); |
| 84 | static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data); |
| 85 | static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data); |
| 86 | static void e1000_release_software_flag(struct e1000_hw *hw); |
| 87 | static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active); |
| 88 | static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active); |
| 89 | static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop); |
| 90 | static void e1000_set_pci_express_master_disable(struct e1000_hw *hw); |
| 91 | static int32_t e1000_wait_autoneg(struct e1000_hw *hw); |
| 92 | static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset, uint32_t value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | static int32_t e1000_set_phy_type(struct e1000_hw *hw); |
| 94 | static void e1000_phy_init_script(struct e1000_hw *hw); |
| 95 | static int32_t e1000_setup_copper_link(struct e1000_hw *hw); |
| 96 | static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw); |
| 97 | static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw); |
| 98 | static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw); |
| 99 | static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw); |
| 100 | static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl); |
| 101 | static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl); |
| 102 | static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, |
| 103 | uint16_t count); |
| 104 | static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw); |
| 105 | static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw); |
| 106 | static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset, |
| 107 | uint16_t words, uint16_t *data); |
| 108 | static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw, |
| 109 | uint16_t offset, uint16_t words, |
| 110 | uint16_t *data); |
| 111 | static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw); |
| 112 | static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd); |
| 113 | static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd); |
| 114 | static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, |
| 115 | uint16_t count); |
| 116 | static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr, |
| 117 | uint16_t phy_data); |
| 118 | static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr, |
| 119 | uint16_t *phy_data); |
| 120 | static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count); |
| 121 | static int32_t e1000_acquire_eeprom(struct e1000_hw *hw); |
| 122 | static void e1000_release_eeprom(struct e1000_hw *hw); |
| 123 | static void e1000_standby_eeprom(struct e1000_hw *hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | static int32_t e1000_set_vco_speed(struct e1000_hw *hw); |
| 125 | static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw); |
| 126 | static int32_t e1000_set_phy_mode(struct e1000_hw *hw); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 127 | static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer); |
| 128 | static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 129 | static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, |
| 130 | uint16_t duplex); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 131 | static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | /* IGP cable length table */ |
| 134 | static const |
| 135 | uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = |
| 136 | { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
| 137 | 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25, |
| 138 | 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40, |
| 139 | 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, |
| 140 | 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90, |
| 141 | 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, |
| 142 | 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, |
| 143 | 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120}; |
| 144 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 145 | static const |
| 146 | uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] = |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 147 | { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, |
| 148 | 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, |
| 149 | 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, |
| 150 | 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, |
| 151 | 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, |
| 152 | 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, |
| 153 | 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124, |
| 154 | 104, 109, 114, 118, 121, 124}; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /****************************************************************************** |
| 157 | * Set the phy type member in the hw struct. |
| 158 | * |
| 159 | * hw - Struct containing variables accessed by shared code |
| 160 | *****************************************************************************/ |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 161 | static int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | e1000_set_phy_type(struct e1000_hw *hw) |
| 163 | { |
| 164 | DEBUGFUNC("e1000_set_phy_type"); |
| 165 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 166 | if (hw->mac_type == e1000_undefined) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 167 | return -E1000_ERR_PHY_TYPE; |
| 168 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 169 | switch (hw->phy_id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | case M88E1000_E_PHY_ID: |
| 171 | case M88E1000_I_PHY_ID: |
| 172 | case M88E1011_I_PHY_ID: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 173 | case M88E1111_I_PHY_ID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | hw->phy_type = e1000_phy_m88; |
| 175 | break; |
| 176 | case IGP01E1000_I_PHY_ID: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 177 | if (hw->mac_type == e1000_82541 || |
| 178 | hw->mac_type == e1000_82541_rev_2 || |
| 179 | hw->mac_type == e1000_82547 || |
| 180 | hw->mac_type == e1000_82547_rev_2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | hw->phy_type = e1000_phy_igp; |
| 182 | break; |
| 183 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 184 | case IGP03E1000_E_PHY_ID: |
| 185 | hw->phy_type = e1000_phy_igp_3; |
| 186 | break; |
| 187 | case IFE_E_PHY_ID: |
| 188 | case IFE_PLUS_E_PHY_ID: |
| 189 | case IFE_C_E_PHY_ID: |
| 190 | hw->phy_type = e1000_phy_ife; |
| 191 | break; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 192 | case GG82563_E_PHY_ID: |
| 193 | if (hw->mac_type == e1000_80003es2lan) { |
| 194 | hw->phy_type = e1000_phy_gg82563; |
| 195 | break; |
| 196 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | /* Fall Through */ |
| 198 | default: |
| 199 | /* Should never have loaded on this device */ |
| 200 | hw->phy_type = e1000_phy_undefined; |
| 201 | return -E1000_ERR_PHY_TYPE; |
| 202 | } |
| 203 | |
| 204 | return E1000_SUCCESS; |
| 205 | } |
| 206 | |
| 207 | /****************************************************************************** |
| 208 | * IGP phy init script - initializes the GbE PHY |
| 209 | * |
| 210 | * hw - Struct containing variables accessed by shared code |
| 211 | *****************************************************************************/ |
| 212 | static void |
| 213 | e1000_phy_init_script(struct e1000_hw *hw) |
| 214 | { |
| 215 | uint32_t ret_val; |
| 216 | uint16_t phy_saved_data; |
| 217 | |
| 218 | DEBUGFUNC("e1000_phy_init_script"); |
| 219 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 220 | if (hw->phy_init_script) { |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 221 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
| 223 | /* Save off the current value of register 0x2F5B to be restored at |
| 224 | * the end of this routine. */ |
| 225 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
| 226 | |
| 227 | /* Disabled the PHY transmitter */ |
| 228 | e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 229 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 230 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
| 232 | e1000_write_phy_reg(hw,0x0000,0x0140); |
| 233 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 234 | msleep(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 236 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | case e1000_82541: |
| 238 | case e1000_82547: |
| 239 | e1000_write_phy_reg(hw, 0x1F95, 0x0001); |
| 240 | |
| 241 | e1000_write_phy_reg(hw, 0x1F71, 0xBD21); |
| 242 | |
| 243 | e1000_write_phy_reg(hw, 0x1F79, 0x0018); |
| 244 | |
| 245 | e1000_write_phy_reg(hw, 0x1F30, 0x1600); |
| 246 | |
| 247 | e1000_write_phy_reg(hw, 0x1F31, 0x0014); |
| 248 | |
| 249 | e1000_write_phy_reg(hw, 0x1F32, 0x161C); |
| 250 | |
| 251 | e1000_write_phy_reg(hw, 0x1F94, 0x0003); |
| 252 | |
| 253 | e1000_write_phy_reg(hw, 0x1F96, 0x003F); |
| 254 | |
| 255 | e1000_write_phy_reg(hw, 0x2010, 0x0008); |
| 256 | break; |
| 257 | |
| 258 | case e1000_82541_rev_2: |
| 259 | case e1000_82547_rev_2: |
| 260 | e1000_write_phy_reg(hw, 0x1F73, 0x0099); |
| 261 | break; |
| 262 | default: |
| 263 | break; |
| 264 | } |
| 265 | |
| 266 | e1000_write_phy_reg(hw, 0x0000, 0x3300); |
| 267 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 268 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
| 270 | /* Now enable the transmitter */ |
| 271 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
| 272 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 273 | if (hw->mac_type == e1000_82547) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | uint16_t fused, fine, coarse; |
| 275 | |
| 276 | /* Move to analog registers page */ |
| 277 | e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused); |
| 278 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 279 | if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused); |
| 281 | |
| 282 | fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK; |
| 283 | coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK; |
| 284 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 285 | if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10; |
| 287 | fine -= IGP01E1000_ANALOG_FUSE_FINE_1; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 288 | } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | fine -= IGP01E1000_ANALOG_FUSE_FINE_10; |
| 290 | |
| 291 | fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) | |
| 292 | (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) | |
| 293 | (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK); |
| 294 | |
| 295 | e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused); |
| 296 | e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS, |
| 297 | IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL); |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | /****************************************************************************** |
| 304 | * Set the mac type member in the hw struct. |
| 305 | * |
| 306 | * hw - Struct containing variables accessed by shared code |
| 307 | *****************************************************************************/ |
| 308 | int32_t |
| 309 | e1000_set_mac_type(struct e1000_hw *hw) |
| 310 | { |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 311 | DEBUGFUNC("e1000_set_mac_type"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 313 | switch (hw->device_id) { |
| 314 | case E1000_DEV_ID_82542: |
| 315 | switch (hw->revision_id) { |
| 316 | case E1000_82542_2_0_REV_ID: |
| 317 | hw->mac_type = e1000_82542_rev2_0; |
| 318 | break; |
| 319 | case E1000_82542_2_1_REV_ID: |
| 320 | hw->mac_type = e1000_82542_rev2_1; |
| 321 | break; |
| 322 | default: |
| 323 | /* Invalid 82542 revision ID */ |
| 324 | return -E1000_ERR_MAC_TYPE; |
| 325 | } |
| 326 | break; |
| 327 | case E1000_DEV_ID_82543GC_FIBER: |
| 328 | case E1000_DEV_ID_82543GC_COPPER: |
| 329 | hw->mac_type = e1000_82543; |
| 330 | break; |
| 331 | case E1000_DEV_ID_82544EI_COPPER: |
| 332 | case E1000_DEV_ID_82544EI_FIBER: |
| 333 | case E1000_DEV_ID_82544GC_COPPER: |
| 334 | case E1000_DEV_ID_82544GC_LOM: |
| 335 | hw->mac_type = e1000_82544; |
| 336 | break; |
| 337 | case E1000_DEV_ID_82540EM: |
| 338 | case E1000_DEV_ID_82540EM_LOM: |
| 339 | case E1000_DEV_ID_82540EP: |
| 340 | case E1000_DEV_ID_82540EP_LOM: |
| 341 | case E1000_DEV_ID_82540EP_LP: |
| 342 | hw->mac_type = e1000_82540; |
| 343 | break; |
| 344 | case E1000_DEV_ID_82545EM_COPPER: |
| 345 | case E1000_DEV_ID_82545EM_FIBER: |
| 346 | hw->mac_type = e1000_82545; |
| 347 | break; |
| 348 | case E1000_DEV_ID_82545GM_COPPER: |
| 349 | case E1000_DEV_ID_82545GM_FIBER: |
| 350 | case E1000_DEV_ID_82545GM_SERDES: |
| 351 | hw->mac_type = e1000_82545_rev_3; |
| 352 | break; |
| 353 | case E1000_DEV_ID_82546EB_COPPER: |
| 354 | case E1000_DEV_ID_82546EB_FIBER: |
| 355 | case E1000_DEV_ID_82546EB_QUAD_COPPER: |
| 356 | hw->mac_type = e1000_82546; |
| 357 | break; |
| 358 | case E1000_DEV_ID_82546GB_COPPER: |
| 359 | case E1000_DEV_ID_82546GB_FIBER: |
| 360 | case E1000_DEV_ID_82546GB_SERDES: |
| 361 | case E1000_DEV_ID_82546GB_PCIE: |
| 362 | case E1000_DEV_ID_82546GB_QUAD_COPPER: |
| 363 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
| 364 | hw->mac_type = e1000_82546_rev_3; |
| 365 | break; |
| 366 | case E1000_DEV_ID_82541EI: |
| 367 | case E1000_DEV_ID_82541EI_MOBILE: |
| 368 | case E1000_DEV_ID_82541ER_LOM: |
| 369 | hw->mac_type = e1000_82541; |
| 370 | break; |
| 371 | case E1000_DEV_ID_82541ER: |
| 372 | case E1000_DEV_ID_82541GI: |
| 373 | case E1000_DEV_ID_82541GI_LF: |
| 374 | case E1000_DEV_ID_82541GI_MOBILE: |
| 375 | hw->mac_type = e1000_82541_rev_2; |
| 376 | break; |
| 377 | case E1000_DEV_ID_82547EI: |
| 378 | case E1000_DEV_ID_82547EI_MOBILE: |
| 379 | hw->mac_type = e1000_82547; |
| 380 | break; |
| 381 | case E1000_DEV_ID_82547GI: |
| 382 | hw->mac_type = e1000_82547_rev_2; |
| 383 | break; |
| 384 | case E1000_DEV_ID_82571EB_COPPER: |
| 385 | case E1000_DEV_ID_82571EB_FIBER: |
| 386 | case E1000_DEV_ID_82571EB_SERDES: |
| 387 | case E1000_DEV_ID_82571EB_QUAD_COPPER: |
| 388 | case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE: |
| 389 | hw->mac_type = e1000_82571; |
| 390 | break; |
| 391 | case E1000_DEV_ID_82572EI_COPPER: |
| 392 | case E1000_DEV_ID_82572EI_FIBER: |
| 393 | case E1000_DEV_ID_82572EI_SERDES: |
| 394 | case E1000_DEV_ID_82572EI: |
| 395 | hw->mac_type = e1000_82572; |
| 396 | break; |
| 397 | case E1000_DEV_ID_82573E: |
| 398 | case E1000_DEV_ID_82573E_IAMT: |
| 399 | case E1000_DEV_ID_82573L: |
| 400 | hw->mac_type = e1000_82573; |
| 401 | break; |
| 402 | case E1000_DEV_ID_80003ES2LAN_COPPER_SPT: |
| 403 | case E1000_DEV_ID_80003ES2LAN_SERDES_SPT: |
| 404 | case E1000_DEV_ID_80003ES2LAN_COPPER_DPT: |
| 405 | case E1000_DEV_ID_80003ES2LAN_SERDES_DPT: |
| 406 | hw->mac_type = e1000_80003es2lan; |
| 407 | break; |
| 408 | case E1000_DEV_ID_ICH8_IGP_M_AMT: |
| 409 | case E1000_DEV_ID_ICH8_IGP_AMT: |
| 410 | case E1000_DEV_ID_ICH8_IGP_C: |
| 411 | case E1000_DEV_ID_ICH8_IFE: |
| 412 | case E1000_DEV_ID_ICH8_IFE_GT: |
| 413 | case E1000_DEV_ID_ICH8_IFE_G: |
| 414 | case E1000_DEV_ID_ICH8_IGP_M: |
| 415 | hw->mac_type = e1000_ich8lan; |
| 416 | break; |
| 417 | default: |
| 418 | /* Should never have loaded on this device */ |
| 419 | return -E1000_ERR_MAC_TYPE; |
| 420 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 422 | switch (hw->mac_type) { |
| 423 | case e1000_ich8lan: |
| 424 | hw->swfwhw_semaphore_present = TRUE; |
| 425 | hw->asf_firmware_present = TRUE; |
| 426 | break; |
| 427 | case e1000_80003es2lan: |
| 428 | hw->swfw_sync_present = TRUE; |
| 429 | /* fall through */ |
| 430 | case e1000_82571: |
| 431 | case e1000_82572: |
| 432 | case e1000_82573: |
| 433 | hw->eeprom_semaphore_present = TRUE; |
| 434 | /* fall through */ |
| 435 | case e1000_82541: |
| 436 | case e1000_82547: |
| 437 | case e1000_82541_rev_2: |
| 438 | case e1000_82547_rev_2: |
| 439 | hw->asf_firmware_present = TRUE; |
| 440 | break; |
| 441 | default: |
| 442 | break; |
| 443 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 445 | /* The 82543 chip does not count tx_carrier_errors properly in |
| 446 | * FD mode |
| 447 | */ |
| 448 | if (hw->mac_type == e1000_82543) |
| 449 | hw->bad_tx_carr_stats_fd = TRUE; |
| 450 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 451 | /* capable of receiving management packets to the host */ |
| 452 | if (hw->mac_type >= e1000_82571) |
| 453 | hw->has_manc2h = TRUE; |
| 454 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 455 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | /***************************************************************************** |
| 459 | * Set media type and TBI compatibility. |
| 460 | * |
| 461 | * hw - Struct containing variables accessed by shared code |
| 462 | * **************************************************************************/ |
| 463 | void |
| 464 | e1000_set_media_type(struct e1000_hw *hw) |
| 465 | { |
| 466 | uint32_t status; |
| 467 | |
| 468 | DEBUGFUNC("e1000_set_media_type"); |
| 469 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 470 | if (hw->mac_type != e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | /* tbi_compatibility is only valid on 82543 */ |
| 472 | hw->tbi_compatibility_en = FALSE; |
| 473 | } |
| 474 | |
| 475 | switch (hw->device_id) { |
| 476 | case E1000_DEV_ID_82545GM_SERDES: |
| 477 | case E1000_DEV_ID_82546GB_SERDES: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 478 | case E1000_DEV_ID_82571EB_SERDES: |
| 479 | case E1000_DEV_ID_82572EI_SERDES: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 480 | case E1000_DEV_ID_80003ES2LAN_SERDES_DPT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | hw->media_type = e1000_media_type_internal_serdes; |
| 482 | break; |
| 483 | default: |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 484 | switch (hw->mac_type) { |
| 485 | case e1000_82542_rev2_0: |
| 486 | case e1000_82542_rev2_1: |
| 487 | hw->media_type = e1000_media_type_fiber; |
| 488 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 489 | case e1000_ich8lan: |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 490 | case e1000_82573: |
| 491 | /* The STATUS_TBIMODE bit is reserved or reused for the this |
| 492 | * device. |
| 493 | */ |
| 494 | hw->media_type = e1000_media_type_copper; |
| 495 | break; |
| 496 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | status = E1000_READ_REG(hw, STATUS); |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 498 | if (status & E1000_STATUS_TBIMODE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | hw->media_type = e1000_media_type_fiber; |
| 500 | /* tbi_compatibility not valid on fiber */ |
| 501 | hw->tbi_compatibility_en = FALSE; |
| 502 | } else { |
| 503 | hw->media_type = e1000_media_type_copper; |
| 504 | } |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 505 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | /****************************************************************************** |
| 511 | * Reset the transmit and receive units; mask and clear all interrupts. |
| 512 | * |
| 513 | * hw - Struct containing variables accessed by shared code |
| 514 | *****************************************************************************/ |
| 515 | int32_t |
| 516 | e1000_reset_hw(struct e1000_hw *hw) |
| 517 | { |
| 518 | uint32_t ctrl; |
| 519 | uint32_t ctrl_ext; |
| 520 | uint32_t icr; |
| 521 | uint32_t manc; |
| 522 | uint32_t led_ctrl; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 523 | uint32_t timeout; |
| 524 | uint32_t extcnf_ctrl; |
| 525 | int32_t ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
| 527 | DEBUGFUNC("e1000_reset_hw"); |
| 528 | |
| 529 | /* For 82542 (rev 2.0), disable MWI before issuing a device reset */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 530 | if (hw->mac_type == e1000_82542_rev2_0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); |
| 532 | e1000_pci_clear_mwi(hw); |
| 533 | } |
| 534 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 535 | if (hw->bus_type == e1000_bus_type_pci_express) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 536 | /* Prevent the PCI-E bus from sticking if there is no TLP connection |
| 537 | * on the last TLP read/write transaction when MAC is reset. |
| 538 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 539 | if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 540 | DEBUGOUT("PCI-E Master disable polling has failed.\n"); |
| 541 | } |
| 542 | } |
| 543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | /* Clear interrupt mask to stop board from generating interrupts */ |
| 545 | DEBUGOUT("Masking off all interrupts\n"); |
| 546 | E1000_WRITE_REG(hw, IMC, 0xffffffff); |
| 547 | |
| 548 | /* Disable the Transmit and Receive units. Then delay to allow |
| 549 | * any pending transactions to complete before we hit the MAC with |
| 550 | * the global reset. |
| 551 | */ |
| 552 | E1000_WRITE_REG(hw, RCTL, 0); |
| 553 | E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP); |
| 554 | E1000_WRITE_FLUSH(hw); |
| 555 | |
| 556 | /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */ |
| 557 | hw->tbi_compatibility_on = FALSE; |
| 558 | |
| 559 | /* Delay to allow any outstanding PCI transactions to complete before |
| 560 | * resetting the device |
| 561 | */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 562 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
| 564 | ctrl = E1000_READ_REG(hw, CTRL); |
| 565 | |
| 566 | /* Must reset the PHY before resetting the MAC */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 567 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 568 | E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST)); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 569 | msleep(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 572 | /* Must acquire the MDIO ownership before MAC reset. |
| 573 | * Ownership defaults to firmware after a reset. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 574 | if (hw->mac_type == e1000_82573) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 575 | timeout = 10; |
| 576 | |
| 577 | extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL); |
| 578 | extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP; |
| 579 | |
| 580 | do { |
| 581 | E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl); |
| 582 | extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL); |
| 583 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 584 | if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 585 | break; |
| 586 | else |
| 587 | extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP; |
| 588 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 589 | msleep(2); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 590 | timeout--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 591 | } while (timeout); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 594 | /* Workaround for ICH8 bit corruption issue in FIFO memory */ |
| 595 | if (hw->mac_type == e1000_ich8lan) { |
| 596 | /* Set Tx and Rx buffer allocation to 8k apiece. */ |
| 597 | E1000_WRITE_REG(hw, PBA, E1000_PBA_8K); |
| 598 | /* Set Packet Buffer Size to 16k. */ |
| 599 | E1000_WRITE_REG(hw, PBS, E1000_PBS_16K); |
| 600 | } |
| 601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | /* Issue a global reset to the MAC. This will reset the chip's |
| 603 | * transmit, receive, DMA, and link units. It will not effect |
| 604 | * the current PCI configuration. The global reset bit is self- |
| 605 | * clearing, and should clear within a microsecond. |
| 606 | */ |
| 607 | DEBUGOUT("Issuing a global reset to MAC\n"); |
| 608 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 609 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | case e1000_82544: |
| 611 | case e1000_82540: |
| 612 | case e1000_82545: |
| 613 | case e1000_82546: |
| 614 | case e1000_82541: |
| 615 | case e1000_82541_rev_2: |
| 616 | /* These controllers can't ack the 64-bit write when issuing the |
| 617 | * reset, so use IO-mapping as a workaround to issue the reset */ |
| 618 | E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST)); |
| 619 | break; |
| 620 | case e1000_82545_rev_3: |
| 621 | case e1000_82546_rev_3: |
| 622 | /* Reset is performed on a shadow of the control register */ |
| 623 | E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST)); |
| 624 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 625 | case e1000_ich8lan: |
| 626 | if (!hw->phy_reset_disable && |
| 627 | e1000_check_phy_reset_block(hw) == E1000_SUCCESS) { |
| 628 | /* e1000_ich8lan PHY HW reset requires MAC CORE reset |
| 629 | * at the same time to make sure the interface between |
| 630 | * MAC and the external PHY is reset. |
| 631 | */ |
| 632 | ctrl |= E1000_CTRL_PHY_RST; |
| 633 | } |
| 634 | |
| 635 | e1000_get_software_flag(hw); |
| 636 | E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST)); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 637 | msleep(5); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 638 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | default: |
| 640 | E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST)); |
| 641 | break; |
| 642 | } |
| 643 | |
| 644 | /* After MAC reset, force reload of EEPROM to restore power-on settings to |
| 645 | * device. Later controllers reload the EEPROM automatically, so just wait |
| 646 | * for reload to complete. |
| 647 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 648 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | case e1000_82542_rev2_0: |
| 650 | case e1000_82542_rev2_1: |
| 651 | case e1000_82543: |
| 652 | case e1000_82544: |
| 653 | /* Wait for reset to complete */ |
| 654 | udelay(10); |
| 655 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 656 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; |
| 657 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 658 | E1000_WRITE_FLUSH(hw); |
| 659 | /* Wait for EEPROM reload */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 660 | msleep(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | break; |
| 662 | case e1000_82541: |
| 663 | case e1000_82541_rev_2: |
| 664 | case e1000_82547: |
| 665 | case e1000_82547_rev_2: |
| 666 | /* Wait for EEPROM reload */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 667 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 669 | case e1000_82573: |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 670 | if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) { |
| 671 | udelay(10); |
| 672 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 673 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; |
| 674 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 675 | E1000_WRITE_FLUSH(hw); |
| 676 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 677 | /* fall through */ |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 678 | default: |
| 679 | /* Auto read done will delay 5ms or poll based on mac type */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 680 | ret_val = e1000_get_auto_rd_done(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 681 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 682 | return ret_val; |
| 683 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | /* Disable HW ARPs on ASF enabled adapters */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 687 | if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | manc = E1000_READ_REG(hw, MANC); |
| 689 | manc &= ~(E1000_MANC_ARP_EN); |
| 690 | E1000_WRITE_REG(hw, MANC, manc); |
| 691 | } |
| 692 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 693 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | e1000_phy_init_script(hw); |
| 695 | |
| 696 | /* Configure activity LED after PHY reset */ |
| 697 | led_ctrl = E1000_READ_REG(hw, LEDCTL); |
| 698 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 699 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 700 | E1000_WRITE_REG(hw, LEDCTL, led_ctrl); |
| 701 | } |
| 702 | |
| 703 | /* Clear interrupt mask to stop board from generating interrupts */ |
| 704 | DEBUGOUT("Masking off all interrupts\n"); |
| 705 | E1000_WRITE_REG(hw, IMC, 0xffffffff); |
| 706 | |
| 707 | /* Clear any pending interrupt events. */ |
| 708 | icr = E1000_READ_REG(hw, ICR); |
| 709 | |
| 710 | /* If MWI was previously enabled, reenable it. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 711 | if (hw->mac_type == e1000_82542_rev2_0) { |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 712 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | e1000_pci_set_mwi(hw); |
| 714 | } |
| 715 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 716 | if (hw->mac_type == e1000_ich8lan) { |
| 717 | uint32_t kab = E1000_READ_REG(hw, KABGTXD); |
| 718 | kab |= E1000_KABGTXD_BGSQLBIAS; |
| 719 | E1000_WRITE_REG(hw, KABGTXD, kab); |
| 720 | } |
| 721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | return E1000_SUCCESS; |
| 723 | } |
| 724 | |
| 725 | /****************************************************************************** |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 726 | * |
| 727 | * Initialize a number of hardware-dependent bits |
| 728 | * |
| 729 | * hw: Struct containing variables accessed by shared code |
| 730 | * |
| 731 | * This function contains hardware limitation workarounds for PCI-E adapters |
| 732 | * |
| 733 | *****************************************************************************/ |
| 734 | static void |
| 735 | e1000_initialize_hardware_bits(struct e1000_hw *hw) |
| 736 | { |
| 737 | if ((hw->mac_type >= e1000_82571) && (!hw->initialize_hw_bits_disable)) { |
| 738 | /* Settings common to all PCI-express silicon */ |
| 739 | uint32_t reg_ctrl, reg_ctrl_ext; |
| 740 | uint32_t reg_tarc0, reg_tarc1; |
| 741 | uint32_t reg_tctl; |
| 742 | uint32_t reg_txdctl, reg_txdctl1; |
| 743 | |
| 744 | /* link autonegotiation/sync workarounds */ |
| 745 | reg_tarc0 = E1000_READ_REG(hw, TARC0); |
| 746 | reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)); |
| 747 | |
| 748 | /* Enable not-done TX descriptor counting */ |
| 749 | reg_txdctl = E1000_READ_REG(hw, TXDCTL); |
| 750 | reg_txdctl |= E1000_TXDCTL_COUNT_DESC; |
| 751 | E1000_WRITE_REG(hw, TXDCTL, reg_txdctl); |
| 752 | reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1); |
| 753 | reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC; |
| 754 | E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1); |
| 755 | |
| 756 | switch (hw->mac_type) { |
| 757 | case e1000_82571: |
| 758 | case e1000_82572: |
| 759 | /* Clear PHY TX compatible mode bits */ |
| 760 | reg_tarc1 = E1000_READ_REG(hw, TARC1); |
| 761 | reg_tarc1 &= ~((1 << 30)|(1 << 29)); |
| 762 | |
| 763 | /* link autonegotiation/sync workarounds */ |
| 764 | reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23)); |
| 765 | |
| 766 | /* TX ring control fixes */ |
| 767 | reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24)); |
| 768 | |
| 769 | /* Multiple read bit is reversed polarity */ |
| 770 | reg_tctl = E1000_READ_REG(hw, TCTL); |
| 771 | if (reg_tctl & E1000_TCTL_MULR) |
| 772 | reg_tarc1 &= ~(1 << 28); |
| 773 | else |
| 774 | reg_tarc1 |= (1 << 28); |
| 775 | |
| 776 | E1000_WRITE_REG(hw, TARC1, reg_tarc1); |
| 777 | break; |
| 778 | case e1000_82573: |
| 779 | reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 780 | reg_ctrl_ext &= ~(1 << 23); |
| 781 | reg_ctrl_ext |= (1 << 22); |
| 782 | |
| 783 | /* TX byte count fix */ |
| 784 | reg_ctrl = E1000_READ_REG(hw, CTRL); |
| 785 | reg_ctrl &= ~(1 << 29); |
| 786 | |
| 787 | E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext); |
| 788 | E1000_WRITE_REG(hw, CTRL, reg_ctrl); |
| 789 | break; |
| 790 | case e1000_80003es2lan: |
| 791 | /* improve small packet performace for fiber/serdes */ |
| 792 | if ((hw->media_type == e1000_media_type_fiber) || |
| 793 | (hw->media_type == e1000_media_type_internal_serdes)) { |
| 794 | reg_tarc0 &= ~(1 << 20); |
| 795 | } |
| 796 | |
| 797 | /* Multiple read bit is reversed polarity */ |
| 798 | reg_tctl = E1000_READ_REG(hw, TCTL); |
| 799 | reg_tarc1 = E1000_READ_REG(hw, TARC1); |
| 800 | if (reg_tctl & E1000_TCTL_MULR) |
| 801 | reg_tarc1 &= ~(1 << 28); |
| 802 | else |
| 803 | reg_tarc1 |= (1 << 28); |
| 804 | |
| 805 | E1000_WRITE_REG(hw, TARC1, reg_tarc1); |
| 806 | break; |
| 807 | case e1000_ich8lan: |
| 808 | /* Reduce concurrent DMA requests to 3 from 4 */ |
| 809 | if ((hw->revision_id < 3) || |
| 810 | ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) && |
| 811 | (hw->device_id != E1000_DEV_ID_ICH8_IGP_M))) |
| 812 | reg_tarc0 |= ((1 << 29)|(1 << 28)); |
| 813 | |
| 814 | reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 815 | reg_ctrl_ext |= (1 << 22); |
| 816 | E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext); |
| 817 | |
| 818 | /* workaround TX hang with TSO=on */ |
| 819 | reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23)); |
| 820 | |
| 821 | /* Multiple read bit is reversed polarity */ |
| 822 | reg_tctl = E1000_READ_REG(hw, TCTL); |
| 823 | reg_tarc1 = E1000_READ_REG(hw, TARC1); |
| 824 | if (reg_tctl & E1000_TCTL_MULR) |
| 825 | reg_tarc1 &= ~(1 << 28); |
| 826 | else |
| 827 | reg_tarc1 |= (1 << 28); |
| 828 | |
| 829 | /* workaround TX hang with TSO=on */ |
| 830 | reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24)); |
| 831 | |
| 832 | E1000_WRITE_REG(hw, TARC1, reg_tarc1); |
| 833 | break; |
| 834 | default: |
| 835 | break; |
| 836 | } |
| 837 | |
| 838 | E1000_WRITE_REG(hw, TARC0, reg_tarc0); |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | * Performs basic configuration of the adapter. |
| 844 | * |
| 845 | * hw - Struct containing variables accessed by shared code |
| 846 | * |
| 847 | * Assumes that the controller has previously been reset and is in a |
| 848 | * post-reset uninitialized state. Initializes the receive address registers, |
| 849 | * multicast table, and VLAN filter table. Calls routines to setup link |
| 850 | * configuration and flow control settings. Clears all on-chip counters. Leaves |
| 851 | * the transmit and receive units disabled and uninitialized. |
| 852 | *****************************************************************************/ |
| 853 | int32_t |
| 854 | e1000_init_hw(struct e1000_hw *hw) |
| 855 | { |
| 856 | uint32_t ctrl; |
| 857 | uint32_t i; |
| 858 | int32_t ret_val; |
| 859 | uint16_t pcix_cmd_word; |
| 860 | uint16_t pcix_stat_hi_word; |
| 861 | uint16_t cmd_mmrbc; |
| 862 | uint16_t stat_mmrbc; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 863 | uint32_t mta_size; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 864 | uint32_t reg_data; |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 865 | uint32_t ctrl_ext; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 866 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | DEBUGFUNC("e1000_init_hw"); |
| 868 | |
Jeff Kirsher | 7820d42 | 2006-08-16 13:39:00 -0700 | [diff] [blame] | 869 | /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */ |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 870 | if ((hw->mac_type == e1000_ich8lan) && |
| 871 | ((hw->revision_id < 3) || |
| 872 | ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) && |
| 873 | (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) { |
| 874 | reg_data = E1000_READ_REG(hw, STATUS); |
| 875 | reg_data &= ~0x80000000; |
| 876 | E1000_WRITE_REG(hw, STATUS, reg_data); |
Jeff Kirsher | 7820d42 | 2006-08-16 13:39:00 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | /* Initialize Identification LED */ |
| 880 | ret_val = e1000_id_led_init(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 881 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | DEBUGOUT("Error Initializing Identification LED\n"); |
| 883 | return ret_val; |
| 884 | } |
| 885 | |
| 886 | /* Set the media type and TBI compatibility */ |
| 887 | e1000_set_media_type(hw); |
| 888 | |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 889 | /* Must be called after e1000_set_media_type because media_type is used */ |
| 890 | e1000_initialize_hardware_bits(hw); |
| 891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | /* Disabling VLAN filtering. */ |
| 893 | DEBUGOUT("Initializing the IEEE VLAN\n"); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 894 | /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */ |
| 895 | if (hw->mac_type != e1000_ich8lan) { |
| 896 | if (hw->mac_type < e1000_82545_rev_3) |
| 897 | E1000_WRITE_REG(hw, VET, 0); |
| 898 | e1000_clear_vfta(hw); |
| 899 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
| 901 | /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 902 | if (hw->mac_type == e1000_82542_rev2_0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); |
| 904 | e1000_pci_clear_mwi(hw); |
| 905 | E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST); |
| 906 | E1000_WRITE_FLUSH(hw); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 907 | msleep(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | /* Setup the receive address. This involves initializing all of the Receive |
| 911 | * Address Registers (RARs 0 - 15). |
| 912 | */ |
| 913 | e1000_init_rx_addrs(hw); |
| 914 | |
| 915 | /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 916 | if (hw->mac_type == e1000_82542_rev2_0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | E1000_WRITE_REG(hw, RCTL, 0); |
| 918 | E1000_WRITE_FLUSH(hw); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 919 | msleep(1); |
| 920 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | e1000_pci_set_mwi(hw); |
| 922 | } |
| 923 | |
| 924 | /* Zero out the Multicast HASH table */ |
| 925 | DEBUGOUT("Zeroing the MTA\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 926 | mta_size = E1000_MC_TBL_SIZE; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 927 | if (hw->mac_type == e1000_ich8lan) |
| 928 | mta_size = E1000_MC_TBL_SIZE_ICH8LAN; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 929 | for (i = 0; i < mta_size; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 931 | /* use write flush to prevent Memory Write Block (MWB) from |
| 932 | * occuring when accessing our register space */ |
| 933 | E1000_WRITE_FLUSH(hw); |
| 934 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
| 936 | /* Set the PCI priority bit correctly in the CTRL register. This |
| 937 | * determines if the adapter gives priority to receives, or if it |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 938 | * gives equal priority to transmits and receives. Valid only on |
| 939 | * 82542 and 82543 silicon. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 941 | if (hw->dma_fairness && hw->mac_type <= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | ctrl = E1000_READ_REG(hw, CTRL); |
| 943 | E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR); |
| 944 | } |
| 945 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 946 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | case e1000_82545_rev_3: |
| 948 | case e1000_82546_rev_3: |
| 949 | break; |
| 950 | default: |
| 951 | /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 952 | if (hw->bus_type == e1000_bus_type_pcix) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word); |
| 954 | e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI, |
| 955 | &pcix_stat_hi_word); |
| 956 | cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >> |
| 957 | PCIX_COMMAND_MMRBC_SHIFT; |
| 958 | stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >> |
| 959 | PCIX_STATUS_HI_MMRBC_SHIFT; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 960 | if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 962 | if (cmd_mmrbc > stat_mmrbc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK; |
| 964 | pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT; |
| 965 | e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER, |
| 966 | &pcix_cmd_word); |
| 967 | } |
| 968 | } |
| 969 | break; |
| 970 | } |
| 971 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 972 | /* More time needed for PHY to initialize */ |
| 973 | if (hw->mac_type == e1000_ich8lan) |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 974 | msleep(15); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 975 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | /* Call a subroutine to configure the link and setup flow control. */ |
| 977 | ret_val = e1000_setup_link(hw); |
| 978 | |
| 979 | /* Set the transmit descriptor write-back policy */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 980 | if (hw->mac_type > e1000_82544) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | ctrl = E1000_READ_REG(hw, TXDCTL); |
| 982 | ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB; |
| 983 | E1000_WRITE_REG(hw, TXDCTL, ctrl); |
| 984 | } |
| 985 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 986 | if (hw->mac_type == e1000_82573) { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 987 | e1000_enable_tx_pkt_filtering(hw); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 988 | } |
| 989 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 990 | switch (hw->mac_type) { |
| 991 | default: |
| 992 | break; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 993 | case e1000_80003es2lan: |
| 994 | /* Enable retransmit on late collisions */ |
| 995 | reg_data = E1000_READ_REG(hw, TCTL); |
| 996 | reg_data |= E1000_TCTL_RTLC; |
| 997 | E1000_WRITE_REG(hw, TCTL, reg_data); |
| 998 | |
| 999 | /* Configure Gigabit Carry Extend Padding */ |
| 1000 | reg_data = E1000_READ_REG(hw, TCTL_EXT); |
| 1001 | reg_data &= ~E1000_TCTL_EXT_GCEX_MASK; |
| 1002 | reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX; |
| 1003 | E1000_WRITE_REG(hw, TCTL_EXT, reg_data); |
| 1004 | |
| 1005 | /* Configure Transmit Inter-Packet Gap */ |
| 1006 | reg_data = E1000_READ_REG(hw, TIPG); |
| 1007 | reg_data &= ~E1000_TIPG_IPGT_MASK; |
| 1008 | reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000; |
| 1009 | E1000_WRITE_REG(hw, TIPG, reg_data); |
| 1010 | |
| 1011 | reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001); |
| 1012 | reg_data &= ~0x00100000; |
| 1013 | E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data); |
| 1014 | /* Fall through */ |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 1015 | case e1000_82571: |
Mallikarjuna R Chilakala | a7990ba | 2005-10-04 07:08:19 -0400 | [diff] [blame] | 1016 | case e1000_82572: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1017 | case e1000_ich8lan: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 1018 | ctrl = E1000_READ_REG(hw, TXDCTL1); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1019 | ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 1020 | E1000_WRITE_REG(hw, TXDCTL1, ctrl); |
| 1021 | break; |
| 1022 | } |
| 1023 | |
| 1024 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 1025 | if (hw->mac_type == e1000_82573) { |
| 1026 | uint32_t gcr = E1000_READ_REG(hw, GCR); |
| 1027 | gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX; |
| 1028 | E1000_WRITE_REG(hw, GCR, gcr); |
| 1029 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1030 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | /* Clear all of the statistics registers (clear on read). It is |
| 1032 | * important that we do this after we have tried to establish link |
| 1033 | * because the symbol error count will increment wildly if there |
| 1034 | * is no link. |
| 1035 | */ |
| 1036 | e1000_clear_hw_cntrs(hw); |
| 1037 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1038 | /* ICH8 No-snoop bits are opposite polarity. |
| 1039 | * Set to snoop by default after reset. */ |
| 1040 | if (hw->mac_type == e1000_ich8lan) |
| 1041 | e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL); |
| 1042 | |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 1043 | if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER || |
| 1044 | hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) { |
| 1045 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 1046 | /* Relaxed ordering must be disabled to avoid a parity |
| 1047 | * error crash in a PCI slot. */ |
| 1048 | ctrl_ext |= E1000_CTRL_EXT_RO_DIS; |
| 1049 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 1050 | } |
| 1051 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | return ret_val; |
| 1053 | } |
| 1054 | |
| 1055 | /****************************************************************************** |
| 1056 | * Adjust SERDES output amplitude based on EEPROM setting. |
| 1057 | * |
| 1058 | * hw - Struct containing variables accessed by shared code. |
| 1059 | *****************************************************************************/ |
| 1060 | static int32_t |
| 1061 | e1000_adjust_serdes_amplitude(struct e1000_hw *hw) |
| 1062 | { |
| 1063 | uint16_t eeprom_data; |
| 1064 | int32_t ret_val; |
| 1065 | |
| 1066 | DEBUGFUNC("e1000_adjust_serdes_amplitude"); |
| 1067 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1068 | if (hw->media_type != e1000_media_type_internal_serdes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | return E1000_SUCCESS; |
| 1070 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1071 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | case e1000_82545_rev_3: |
| 1073 | case e1000_82546_rev_3: |
| 1074 | break; |
| 1075 | default: |
| 1076 | return E1000_SUCCESS; |
| 1077 | } |
| 1078 | |
| 1079 | ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data); |
| 1080 | if (ret_val) { |
| 1081 | return ret_val; |
| 1082 | } |
| 1083 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1084 | if (eeprom_data != EEPROM_RESERVED_WORD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | /* Adjust SERDES output amplitude only. */ |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1086 | eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1088 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | return ret_val; |
| 1090 | } |
| 1091 | |
| 1092 | return E1000_SUCCESS; |
| 1093 | } |
| 1094 | |
| 1095 | /****************************************************************************** |
| 1096 | * Configures flow control and link settings. |
| 1097 | * |
| 1098 | * hw - Struct containing variables accessed by shared code |
| 1099 | * |
| 1100 | * Determines which flow control settings to use. Calls the apropriate media- |
| 1101 | * specific link configuration function. Configures the flow control settings. |
| 1102 | * Assuming the adapter has a valid link partner, a valid link should be |
| 1103 | * established. Assumes the hardware has previously been reset and the |
| 1104 | * transmitter and receiver are not enabled. |
| 1105 | *****************************************************************************/ |
| 1106 | int32_t |
| 1107 | e1000_setup_link(struct e1000_hw *hw) |
| 1108 | { |
| 1109 | uint32_t ctrl_ext; |
| 1110 | int32_t ret_val; |
| 1111 | uint16_t eeprom_data; |
| 1112 | |
| 1113 | DEBUGFUNC("e1000_setup_link"); |
| 1114 | |
Jeff Kirsher | 526f995 | 2006-01-12 16:50:46 -0800 | [diff] [blame] | 1115 | /* In the case of the phy reset being blocked, we already have a link. |
| 1116 | * We do not have to set it up again. */ |
| 1117 | if (e1000_check_phy_reset_block(hw)) |
| 1118 | return E1000_SUCCESS; |
| 1119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | /* Read and store word 0x0F of the EEPROM. This word contains bits |
| 1121 | * that determine the hardware's default PAUSE (flow control) mode, |
| 1122 | * a bit that determines whether the HW defaults to enabling or |
| 1123 | * disabling auto-negotiation, and the direction of the |
| 1124 | * SW defined pins. If there is no SW over-ride of the flow |
| 1125 | * control setting, then the variable hw->fc will |
| 1126 | * be initialized based on a value in the EEPROM. |
| 1127 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1128 | if (hw->fc == E1000_FC_DEFAULT) { |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1129 | switch (hw->mac_type) { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1130 | case e1000_ich8lan: |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1131 | case e1000_82573: |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1132 | hw->fc = E1000_FC_FULL; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1133 | break; |
| 1134 | default: |
| 1135 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, |
| 1136 | 1, &eeprom_data); |
| 1137 | if (ret_val) { |
| 1138 | DEBUGOUT("EEPROM Read Error\n"); |
| 1139 | return -E1000_ERR_EEPROM; |
| 1140 | } |
| 1141 | if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1142 | hw->fc = E1000_FC_NONE; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1143 | else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == |
| 1144 | EEPROM_WORD0F_ASM_DIR) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1145 | hw->fc = E1000_FC_TX_PAUSE; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1146 | else |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1147 | hw->fc = E1000_FC_FULL; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1148 | break; |
| 1149 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | /* We want to save off the original Flow Control configuration just |
| 1153 | * in case we get disconnected and then reconnected into a different |
| 1154 | * hub or switch with different Flow Control capabilities. |
| 1155 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1156 | if (hw->mac_type == e1000_82542_rev2_0) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1157 | hw->fc &= (~E1000_FC_TX_PAUSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1159 | if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1)) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1160 | hw->fc &= (~E1000_FC_RX_PAUSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | |
| 1162 | hw->original_fc = hw->fc; |
| 1163 | |
| 1164 | DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc); |
| 1165 | |
| 1166 | /* Take the 4 bits from EEPROM word 0x0F that determine the initial |
| 1167 | * polarity value for the SW controlled pins, and setup the |
| 1168 | * Extended Device Control reg with that info. |
| 1169 | * This is needed because one of the SW controlled pins is used for |
| 1170 | * signal detection. So this should be done before e1000_setup_pcs_link() |
| 1171 | * or e1000_phy_setup() is called. |
| 1172 | */ |
Jeff Kirsher | 497fce5 | 2006-03-02 18:18:20 -0800 | [diff] [blame] | 1173 | if (hw->mac_type == e1000_82543) { |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1174 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, |
| 1175 | 1, &eeprom_data); |
| 1176 | if (ret_val) { |
| 1177 | DEBUGOUT("EEPROM Read Error\n"); |
| 1178 | return -E1000_ERR_EEPROM; |
| 1179 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) << |
| 1181 | SWDPIO__EXT_SHIFT); |
| 1182 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 1183 | } |
| 1184 | |
| 1185 | /* Call the necessary subroutine to configure the link. */ |
| 1186 | ret_val = (hw->media_type == e1000_media_type_copper) ? |
| 1187 | e1000_setup_copper_link(hw) : |
| 1188 | e1000_setup_fiber_serdes_link(hw); |
| 1189 | |
| 1190 | /* Initialize the flow control address, type, and PAUSE timer |
| 1191 | * registers to their default values. This is done even if flow |
| 1192 | * control is disabled, because it does not hurt anything to |
| 1193 | * initialize these registers. |
| 1194 | */ |
| 1195 | DEBUGOUT("Initializing the Flow Control address, type and timer regs\n"); |
| 1196 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1197 | /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */ |
| 1198 | if (hw->mac_type != e1000_ich8lan) { |
| 1199 | E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE); |
| 1200 | E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH); |
| 1201 | E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW); |
| 1202 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time); |
| 1205 | |
| 1206 | /* Set the flow control receive threshold registers. Normally, |
| 1207 | * these registers will be set to a default threshold that may be |
| 1208 | * adjusted later by the driver's runtime code. However, if the |
| 1209 | * ability to transmit pause frames in not enabled, then these |
| 1210 | * registers will be set to 0. |
| 1211 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1212 | if (!(hw->fc & E1000_FC_TX_PAUSE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | E1000_WRITE_REG(hw, FCRTL, 0); |
| 1214 | E1000_WRITE_REG(hw, FCRTH, 0); |
| 1215 | } else { |
| 1216 | /* We need to set up the Receive Threshold high and low water marks |
| 1217 | * as well as (optionally) enabling the transmission of XON frames. |
| 1218 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1219 | if (hw->fc_send_xon) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE)); |
| 1221 | E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water); |
| 1222 | } else { |
| 1223 | E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water); |
| 1224 | E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water); |
| 1225 | } |
| 1226 | } |
| 1227 | return ret_val; |
| 1228 | } |
| 1229 | |
| 1230 | /****************************************************************************** |
| 1231 | * Sets up link for a fiber based or serdes based adapter |
| 1232 | * |
| 1233 | * hw - Struct containing variables accessed by shared code |
| 1234 | * |
| 1235 | * Manipulates Physical Coding Sublayer functions in order to configure |
| 1236 | * link. Assumes the hardware has been previously reset and the transmitter |
| 1237 | * and receiver are not enabled. |
| 1238 | *****************************************************************************/ |
| 1239 | static int32_t |
| 1240 | e1000_setup_fiber_serdes_link(struct e1000_hw *hw) |
| 1241 | { |
| 1242 | uint32_t ctrl; |
| 1243 | uint32_t status; |
| 1244 | uint32_t txcw = 0; |
| 1245 | uint32_t i; |
| 1246 | uint32_t signal = 0; |
| 1247 | int32_t ret_val; |
| 1248 | |
| 1249 | DEBUGFUNC("e1000_setup_fiber_serdes_link"); |
| 1250 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 1251 | /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists |
| 1252 | * until explicitly turned off or a power cycle is performed. A read to |
| 1253 | * the register does not indicate its status. Therefore, we ensure |
| 1254 | * loopback mode is disabled during initialization. |
| 1255 | */ |
| 1256 | if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) |
| 1257 | E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK); |
| 1258 | |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 1259 | /* On adapters with a MAC newer than 82544, SWDP 1 will be |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | * set when the optics detect a signal. On older adapters, it will be |
| 1261 | * cleared when there is a signal. This applies to fiber media only. |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 1262 | * If we're on serdes media, adjust the output amplitude to value |
| 1263 | * set in the EEPROM. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | */ |
| 1265 | ctrl = E1000_READ_REG(hw, CTRL); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1266 | if (hw->media_type == e1000_media_type_fiber) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; |
| 1268 | |
| 1269 | ret_val = e1000_adjust_serdes_amplitude(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1270 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | return ret_val; |
| 1272 | |
| 1273 | /* Take the link out of reset */ |
| 1274 | ctrl &= ~(E1000_CTRL_LRST); |
| 1275 | |
| 1276 | /* Adjust VCO speed to improve BER performance */ |
| 1277 | ret_val = e1000_set_vco_speed(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1278 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | return ret_val; |
| 1280 | |
| 1281 | e1000_config_collision_dist(hw); |
| 1282 | |
| 1283 | /* Check for a software override of the flow control settings, and setup |
| 1284 | * the device accordingly. If auto-negotiation is enabled, then software |
| 1285 | * will have to set the "PAUSE" bits to the correct value in the Tranmsit |
| 1286 | * Config Word Register (TXCW) and re-start auto-negotiation. However, if |
| 1287 | * auto-negotiation is disabled, then software will have to manually |
| 1288 | * configure the two flow control enable bits in the CTRL register. |
| 1289 | * |
| 1290 | * The possible values of the "fc" parameter are: |
| 1291 | * 0: Flow control is completely disabled |
| 1292 | * 1: Rx flow control is enabled (we can receive pause frames, but |
| 1293 | * not send pause frames). |
| 1294 | * 2: Tx flow control is enabled (we can send pause frames but we do |
| 1295 | * not support receiving pause frames). |
| 1296 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
| 1297 | */ |
| 1298 | switch (hw->fc) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1299 | case E1000_FC_NONE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | /* Flow control is completely disabled by a software over-ride. */ |
| 1301 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); |
| 1302 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1303 | case E1000_FC_RX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | /* RX Flow control is enabled and TX Flow control is disabled by a |
| 1305 | * software over-ride. Since there really isn't a way to advertise |
| 1306 | * that we are capable of RX Pause ONLY, we will advertise that we |
| 1307 | * support both symmetric and asymmetric RX PAUSE. Later, we will |
| 1308 | * disable the adapter's ability to send PAUSE frames. |
| 1309 | */ |
| 1310 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 1311 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1312 | case E1000_FC_TX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | /* TX Flow control is enabled, and RX Flow control is disabled, by a |
| 1314 | * software over-ride. |
| 1315 | */ |
| 1316 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); |
| 1317 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1318 | case E1000_FC_FULL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | /* Flow control (both RX and TX) is enabled by a software over-ride. */ |
| 1320 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 1321 | break; |
| 1322 | default: |
| 1323 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 1324 | return -E1000_ERR_CONFIG; |
| 1325 | break; |
| 1326 | } |
| 1327 | |
| 1328 | /* Since auto-negotiation is enabled, take the link out of reset (the link |
| 1329 | * will be in reset, because we previously reset the chip). This will |
| 1330 | * restart auto-negotiation. If auto-neogtiation is successful then the |
| 1331 | * link-up status bit will be set and the flow control enable bits (RFCE |
| 1332 | * and TFCE) will be set according to their negotiated value. |
| 1333 | */ |
| 1334 | DEBUGOUT("Auto-negotiation enabled\n"); |
| 1335 | |
| 1336 | E1000_WRITE_REG(hw, TXCW, txcw); |
| 1337 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 1338 | E1000_WRITE_FLUSH(hw); |
| 1339 | |
| 1340 | hw->txcw = txcw; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1341 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | |
| 1343 | /* If we have a signal (the cable is plugged in) then poll for a "Link-Up" |
| 1344 | * indication in the Device Status Register. Time-out if a link isn't |
| 1345 | * seen in 500 milliseconds seconds (Auto-negotiation should complete in |
| 1346 | * less than 500 milliseconds even if the other end is doing it in SW). |
| 1347 | * For internal serdes, we just assume a signal is present, then poll. |
| 1348 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1349 | if (hw->media_type == e1000_media_type_internal_serdes || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) { |
| 1351 | DEBUGOUT("Looking for Link\n"); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1352 | for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) { |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1353 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | status = E1000_READ_REG(hw, STATUS); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1355 | if (status & E1000_STATUS_LU) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1357 | if (i == (LINK_UP_TIMEOUT / 10)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | DEBUGOUT("Never got a valid link from auto-neg!!!\n"); |
| 1359 | hw->autoneg_failed = 1; |
| 1360 | /* AutoNeg failed to achieve a link, so we'll call |
| 1361 | * e1000_check_for_link. This routine will force the link up if |
| 1362 | * we detect a signal. This will allow us to communicate with |
| 1363 | * non-autonegotiating link partners. |
| 1364 | */ |
| 1365 | ret_val = e1000_check_for_link(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1366 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | DEBUGOUT("Error while checking for link\n"); |
| 1368 | return ret_val; |
| 1369 | } |
| 1370 | hw->autoneg_failed = 0; |
| 1371 | } else { |
| 1372 | hw->autoneg_failed = 0; |
| 1373 | DEBUGOUT("Valid Link Found\n"); |
| 1374 | } |
| 1375 | } else { |
| 1376 | DEBUGOUT("No Signal Detected\n"); |
| 1377 | } |
| 1378 | return E1000_SUCCESS; |
| 1379 | } |
| 1380 | |
| 1381 | /****************************************************************************** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1382 | * Make sure we have a valid PHY and change PHY mode before link setup. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | * |
| 1384 | * hw - Struct containing variables accessed by shared code |
| 1385 | ******************************************************************************/ |
| 1386 | static int32_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1387 | e1000_copper_link_preconfig(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | { |
| 1389 | uint32_t ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | int32_t ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | uint16_t phy_data; |
| 1392 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1393 | DEBUGFUNC("e1000_copper_link_preconfig"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | |
| 1395 | ctrl = E1000_READ_REG(hw, CTRL); |
| 1396 | /* With 82543, we need to force speed and duplex on the MAC equal to what |
| 1397 | * the PHY speed and duplex configuration is. In addition, we need to |
| 1398 | * perform a hardware reset on the PHY to take it out of reset. |
| 1399 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1400 | if (hw->mac_type > e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | ctrl |= E1000_CTRL_SLU; |
| 1402 | ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 1403 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 1404 | } else { |
| 1405 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU); |
| 1406 | E1000_WRITE_REG(hw, CTRL, ctrl); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1407 | ret_val = e1000_phy_hw_reset(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1408 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1409 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | /* Make sure we have a valid PHY */ |
| 1413 | ret_val = e1000_detect_gig_phy(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1414 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | DEBUGOUT("Error, did not detect valid phy.\n"); |
| 1416 | return ret_val; |
| 1417 | } |
| 1418 | DEBUGOUT1("Phy ID = %x \n", hw->phy_id); |
| 1419 | |
| 1420 | /* Set PHY to class A mode (if necessary) */ |
| 1421 | ret_val = e1000_set_phy_mode(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1422 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | return ret_val; |
| 1424 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1425 | if ((hw->mac_type == e1000_82545_rev_3) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | (hw->mac_type == e1000_82546_rev_3)) { |
| 1427 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 1428 | phy_data |= 0x00000008; |
| 1429 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 1430 | } |
| 1431 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1432 | if (hw->mac_type <= e1000_82543 || |
| 1433 | hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 || |
| 1434 | hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | hw->phy_reset_disable = FALSE; |
| 1436 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1437 | return E1000_SUCCESS; |
| 1438 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1441 | /******************************************************************** |
| 1442 | * Copper link setup for e1000_phy_igp series. |
| 1443 | * |
| 1444 | * hw - Struct containing variables accessed by shared code |
| 1445 | *********************************************************************/ |
| 1446 | static int32_t |
| 1447 | e1000_copper_link_igp_setup(struct e1000_hw *hw) |
| 1448 | { |
| 1449 | uint32_t led_ctrl; |
| 1450 | int32_t ret_val; |
| 1451 | uint16_t phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1453 | DEBUGFUNC("e1000_copper_link_igp_setup"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1455 | if (hw->phy_reset_disable) |
| 1456 | return E1000_SUCCESS; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1457 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1458 | ret_val = e1000_phy_reset(hw); |
| 1459 | if (ret_val) { |
| 1460 | DEBUGOUT("Error Resetting the PHY\n"); |
| 1461 | return ret_val; |
| 1462 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1464 | /* Wait 15ms for MAC to configure PHY from eeprom settings */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1465 | msleep(15); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1466 | if (hw->mac_type != e1000_ich8lan) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1467 | /* Configure activity LED after PHY reset */ |
| 1468 | led_ctrl = E1000_READ_REG(hw, LEDCTL); |
| 1469 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 1470 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 1471 | E1000_WRITE_REG(hw, LEDCTL, led_ctrl); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1472 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1473 | |
Jeff Kirsher | c9c1b83 | 2006-08-16 13:38:54 -0700 | [diff] [blame] | 1474 | /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */ |
| 1475 | if (hw->phy_type == e1000_phy_igp) { |
| 1476 | /* disable lplu d3 during driver init */ |
| 1477 | ret_val = e1000_set_d3_lplu_state(hw, FALSE); |
| 1478 | if (ret_val) { |
| 1479 | DEBUGOUT("Error Disabling LPLU D3\n"); |
| 1480 | return ret_val; |
| 1481 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | /* disable lplu d0 during driver init */ |
| 1485 | ret_val = e1000_set_d0_lplu_state(hw, FALSE); |
| 1486 | if (ret_val) { |
| 1487 | DEBUGOUT("Error Disabling LPLU D0\n"); |
| 1488 | return ret_val; |
| 1489 | } |
| 1490 | /* Configure mdi-mdix settings */ |
| 1491 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); |
| 1492 | if (ret_val) |
| 1493 | return ret_val; |
| 1494 | |
| 1495 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 1496 | hw->dsp_config_state = e1000_dsp_config_disabled; |
| 1497 | /* Force MDI for earlier revs of the IGP PHY */ |
| 1498 | phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX); |
| 1499 | hw->mdix = 1; |
| 1500 | |
| 1501 | } else { |
| 1502 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 1503 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 1504 | |
| 1505 | switch (hw->mdix) { |
| 1506 | case 1: |
| 1507 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 1508 | break; |
| 1509 | case 2: |
| 1510 | phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 1511 | break; |
| 1512 | case 0: |
| 1513 | default: |
| 1514 | phy_data |= IGP01E1000_PSCR_AUTO_MDIX; |
| 1515 | break; |
| 1516 | } |
| 1517 | } |
| 1518 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1519 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1520 | return ret_val; |
| 1521 | |
| 1522 | /* set auto-master slave resolution settings */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1523 | if (hw->autoneg) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1524 | e1000_ms_type phy_ms_setting = hw->master_slave; |
| 1525 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1526 | if (hw->ffe_config_state == e1000_ffe_config_active) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1527 | hw->ffe_config_state = e1000_ffe_config_enabled; |
| 1528 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1529 | if (hw->dsp_config_state == e1000_dsp_config_activated) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1530 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 1531 | |
| 1532 | /* when autonegotiation advertisment is only 1000Mbps then we |
| 1533 | * should disable SmartSpeed and enable Auto MasterSlave |
| 1534 | * resolution as hardware default. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1535 | if (hw->autoneg_advertised == ADVERTISE_1000_FULL) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1536 | /* Disable SmartSpeed */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1537 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 1538 | &phy_data); |
| 1539 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1541 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1542 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 1543 | phy_data); |
| 1544 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1546 | /* Set auto Master/Slave resolution process */ |
| 1547 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1548 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1549 | return ret_val; |
| 1550 | phy_data &= ~CR_1000T_MS_ENABLE; |
| 1551 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1552 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1553 | return ret_val; |
| 1554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1556 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1557 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1558 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1560 | /* load defaults for future use */ |
| 1561 | hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ? |
| 1562 | ((phy_data & CR_1000T_MS_VALUE) ? |
| 1563 | e1000_ms_force_master : |
| 1564 | e1000_ms_force_slave) : |
| 1565 | e1000_ms_auto; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1567 | switch (phy_ms_setting) { |
| 1568 | case e1000_ms_force_master: |
| 1569 | phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE); |
| 1570 | break; |
| 1571 | case e1000_ms_force_slave: |
| 1572 | phy_data |= CR_1000T_MS_ENABLE; |
| 1573 | phy_data &= ~(CR_1000T_MS_VALUE); |
| 1574 | break; |
| 1575 | case e1000_ms_auto: |
| 1576 | phy_data &= ~CR_1000T_MS_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | default: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1578 | break; |
| 1579 | } |
| 1580 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1581 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1582 | return ret_val; |
Malli Chilakala | 2b02893 | 2005-06-17 17:46:06 -0700 | [diff] [blame] | 1583 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | |
Malli Chilakala | 2b02893 | 2005-06-17 17:46:06 -0700 | [diff] [blame] | 1585 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1586 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1588 | /******************************************************************** |
| 1589 | * Copper link setup for e1000_phy_gg82563 series. |
| 1590 | * |
| 1591 | * hw - Struct containing variables accessed by shared code |
| 1592 | *********************************************************************/ |
| 1593 | static int32_t |
| 1594 | e1000_copper_link_ggp_setup(struct e1000_hw *hw) |
| 1595 | { |
| 1596 | int32_t ret_val; |
| 1597 | uint16_t phy_data; |
| 1598 | uint32_t reg_data; |
| 1599 | |
| 1600 | DEBUGFUNC("e1000_copper_link_ggp_setup"); |
| 1601 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1602 | if (!hw->phy_reset_disable) { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1603 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1604 | /* Enable CRS on TX for half-duplex operation. */ |
| 1605 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, |
| 1606 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1607 | if (ret_val) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1608 | return ret_val; |
| 1609 | |
| 1610 | phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX; |
| 1611 | /* Use 25MHz for both link down and 1000BASE-T for Tx clock */ |
| 1612 | phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ; |
| 1613 | |
| 1614 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, |
| 1615 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1616 | if (ret_val) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1617 | return ret_val; |
| 1618 | |
| 1619 | /* Options: |
| 1620 | * MDI/MDI-X = 0 (default) |
| 1621 | * 0 - Auto for all speeds |
| 1622 | * 1 - MDI mode |
| 1623 | * 2 - MDI-X mode |
| 1624 | * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) |
| 1625 | */ |
| 1626 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1627 | if (ret_val) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1628 | return ret_val; |
| 1629 | |
| 1630 | phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK; |
| 1631 | |
| 1632 | switch (hw->mdix) { |
| 1633 | case 1: |
| 1634 | phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI; |
| 1635 | break; |
| 1636 | case 2: |
| 1637 | phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX; |
| 1638 | break; |
| 1639 | case 0: |
| 1640 | default: |
| 1641 | phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO; |
| 1642 | break; |
| 1643 | } |
| 1644 | |
| 1645 | /* Options: |
| 1646 | * disable_polarity_correction = 0 (default) |
| 1647 | * Automatic Correction for Reversed Cable Polarity |
| 1648 | * 0 - Disabled |
| 1649 | * 1 - Enabled |
| 1650 | */ |
| 1651 | phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1652 | if (hw->disable_polarity_correction == 1) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1653 | phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE; |
| 1654 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data); |
| 1655 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1656 | if (ret_val) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1657 | return ret_val; |
| 1658 | |
| 1659 | /* SW Reset the PHY so all changes take effect */ |
| 1660 | ret_val = e1000_phy_reset(hw); |
| 1661 | if (ret_val) { |
| 1662 | DEBUGOUT("Error Resetting the PHY\n"); |
| 1663 | return ret_val; |
| 1664 | } |
| 1665 | } /* phy_reset_disable */ |
| 1666 | |
| 1667 | if (hw->mac_type == e1000_80003es2lan) { |
| 1668 | /* Bypass RX and TX FIFO's */ |
| 1669 | ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL, |
| 1670 | E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS | |
| 1671 | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS); |
| 1672 | if (ret_val) |
| 1673 | return ret_val; |
| 1674 | |
| 1675 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data); |
| 1676 | if (ret_val) |
| 1677 | return ret_val; |
| 1678 | |
| 1679 | phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG; |
| 1680 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data); |
| 1681 | |
| 1682 | if (ret_val) |
| 1683 | return ret_val; |
| 1684 | |
| 1685 | reg_data = E1000_READ_REG(hw, CTRL_EXT); |
| 1686 | reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK); |
| 1687 | E1000_WRITE_REG(hw, CTRL_EXT, reg_data); |
| 1688 | |
| 1689 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL, |
| 1690 | &phy_data); |
| 1691 | if (ret_val) |
| 1692 | return ret_val; |
| 1693 | |
| 1694 | /* Do not init these registers when the HW is in IAMT mode, since the |
| 1695 | * firmware will have already initialized them. We only initialize |
| 1696 | * them if the HW is not in IAMT mode. |
| 1697 | */ |
| 1698 | if (e1000_check_mng_mode(hw) == FALSE) { |
| 1699 | /* Enable Electrical Idle on the PHY */ |
| 1700 | phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE; |
| 1701 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL, |
| 1702 | phy_data); |
| 1703 | if (ret_val) |
| 1704 | return ret_val; |
| 1705 | |
| 1706 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, |
| 1707 | &phy_data); |
| 1708 | if (ret_val) |
| 1709 | return ret_val; |
| 1710 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1711 | phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1712 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, |
| 1713 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1714 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1715 | if (ret_val) |
| 1716 | return ret_val; |
| 1717 | } |
| 1718 | |
| 1719 | /* Workaround: Disable padding in Kumeran interface in the MAC |
| 1720 | * and in the PHY to avoid CRC errors. |
| 1721 | */ |
| 1722 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL, |
| 1723 | &phy_data); |
| 1724 | if (ret_val) |
| 1725 | return ret_val; |
| 1726 | phy_data |= GG82563_ICR_DIS_PADDING; |
| 1727 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL, |
| 1728 | phy_data); |
| 1729 | if (ret_val) |
| 1730 | return ret_val; |
| 1731 | } |
| 1732 | |
| 1733 | return E1000_SUCCESS; |
| 1734 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1736 | /******************************************************************** |
| 1737 | * Copper link setup for e1000_phy_m88 series. |
| 1738 | * |
| 1739 | * hw - Struct containing variables accessed by shared code |
| 1740 | *********************************************************************/ |
| 1741 | static int32_t |
| 1742 | e1000_copper_link_mgp_setup(struct e1000_hw *hw) |
| 1743 | { |
| 1744 | int32_t ret_val; |
| 1745 | uint16_t phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1747 | DEBUGFUNC("e1000_copper_link_mgp_setup"); |
| 1748 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1749 | if (hw->phy_reset_disable) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1750 | return E1000_SUCCESS; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1751 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1752 | /* Enable CRS on TX. This must be set for half-duplex operation. */ |
| 1753 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1754 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1755 | return ret_val; |
| 1756 | |
| 1757 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 1758 | |
| 1759 | /* Options: |
| 1760 | * MDI/MDI-X = 0 (default) |
| 1761 | * 0 - Auto for all speeds |
| 1762 | * 1 - MDI mode |
| 1763 | * 2 - MDI-X mode |
| 1764 | * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) |
| 1765 | */ |
| 1766 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 1767 | |
| 1768 | switch (hw->mdix) { |
| 1769 | case 1: |
| 1770 | phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE; |
| 1771 | break; |
| 1772 | case 2: |
| 1773 | phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE; |
| 1774 | break; |
| 1775 | case 3: |
| 1776 | phy_data |= M88E1000_PSCR_AUTO_X_1000T; |
| 1777 | break; |
| 1778 | case 0: |
| 1779 | default: |
| 1780 | phy_data |= M88E1000_PSCR_AUTO_X_MODE; |
| 1781 | break; |
| 1782 | } |
| 1783 | |
| 1784 | /* Options: |
| 1785 | * disable_polarity_correction = 0 (default) |
| 1786 | * Automatic Correction for Reversed Cable Polarity |
| 1787 | * 0 - Disabled |
| 1788 | * 1 - Enabled |
| 1789 | */ |
| 1790 | phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1791 | if (hw->disable_polarity_correction == 1) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1792 | phy_data |= M88E1000_PSCR_POLARITY_REVERSAL; |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1793 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 1794 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1795 | return ret_val; |
| 1796 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1797 | if (hw->phy_revision < M88E1011_I_REV_4) { |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1798 | /* Force TX_CLK in the Extended PHY Specific Control Register |
| 1799 | * to 25MHz clock. |
| 1800 | */ |
| 1801 | ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data); |
| 1802 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1803 | return ret_val; |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1804 | |
| 1805 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
| 1806 | |
| 1807 | if ((hw->phy_revision == E1000_REVISION_2) && |
| 1808 | (hw->phy_id == M88E1111_I_PHY_ID)) { |
| 1809 | /* Vidalia Phy, set the downshift counter to 5x */ |
| 1810 | phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK); |
| 1811 | phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X; |
| 1812 | ret_val = e1000_write_phy_reg(hw, |
| 1813 | M88E1000_EXT_PHY_SPEC_CTRL, phy_data); |
| 1814 | if (ret_val) |
| 1815 | return ret_val; |
| 1816 | } else { |
| 1817 | /* Configure Master and Slave downshift values */ |
| 1818 | phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK | |
| 1819 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK); |
| 1820 | phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X | |
| 1821 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X); |
| 1822 | ret_val = e1000_write_phy_reg(hw, |
| 1823 | M88E1000_EXT_PHY_SPEC_CTRL, phy_data); |
| 1824 | if (ret_val) |
| 1825 | return ret_val; |
| 1826 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1827 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1829 | /* SW Reset the PHY so all changes take effect */ |
| 1830 | ret_val = e1000_phy_reset(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1831 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1832 | DEBUGOUT("Error Resetting the PHY\n"); |
| 1833 | return ret_val; |
| 1834 | } |
| 1835 | |
| 1836 | return E1000_SUCCESS; |
| 1837 | } |
| 1838 | |
| 1839 | /******************************************************************** |
| 1840 | * Setup auto-negotiation and flow control advertisements, |
| 1841 | * and then perform auto-negotiation. |
| 1842 | * |
| 1843 | * hw - Struct containing variables accessed by shared code |
| 1844 | *********************************************************************/ |
| 1845 | static int32_t |
| 1846 | e1000_copper_link_autoneg(struct e1000_hw *hw) |
| 1847 | { |
| 1848 | int32_t ret_val; |
| 1849 | uint16_t phy_data; |
| 1850 | |
| 1851 | DEBUGFUNC("e1000_copper_link_autoneg"); |
| 1852 | |
| 1853 | /* Perform some bounds checking on the hw->autoneg_advertised |
| 1854 | * parameter. If this variable is zero, then set it to the default. |
| 1855 | */ |
| 1856 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT; |
| 1857 | |
| 1858 | /* If autoneg_advertised is zero, we assume it was not defaulted |
| 1859 | * by the calling code so we set to advertise full capability. |
| 1860 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1861 | if (hw->autoneg_advertised == 0) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1862 | hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT; |
| 1863 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1864 | /* IFE phy only supports 10/100 */ |
| 1865 | if (hw->phy_type == e1000_phy_ife) |
| 1866 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL; |
| 1867 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1868 | DEBUGOUT("Reconfiguring auto-neg advertisement params\n"); |
| 1869 | ret_val = e1000_phy_setup_autoneg(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1870 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1871 | DEBUGOUT("Error Setting up Auto-Negotiation\n"); |
| 1872 | return ret_val; |
| 1873 | } |
| 1874 | DEBUGOUT("Restarting Auto-Neg\n"); |
| 1875 | |
| 1876 | /* Restart auto-negotiation by setting the Auto Neg Enable bit and |
| 1877 | * the Auto Neg Restart bit in the PHY control register. |
| 1878 | */ |
| 1879 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1880 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1881 | return ret_val; |
| 1882 | |
| 1883 | phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); |
| 1884 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1885 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1886 | return ret_val; |
| 1887 | |
| 1888 | /* Does the user want to wait for Auto-Neg to complete here, or |
| 1889 | * check at a later time (for example, callback routine). |
| 1890 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1891 | if (hw->wait_autoneg_complete) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1892 | ret_val = e1000_wait_autoneg(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1893 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1894 | DEBUGOUT("Error while waiting for autoneg to complete\n"); |
| 1895 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1897 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1899 | hw->get_link_status = TRUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1901 | return E1000_SUCCESS; |
| 1902 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1904 | /****************************************************************************** |
| 1905 | * Config the MAC and the PHY after link is up. |
| 1906 | * 1) Set up the MAC to the current PHY speed/duplex |
| 1907 | * if we are on 82543. If we |
| 1908 | * are on newer silicon, we only need to configure |
| 1909 | * collision distance in the Transmit Control Register. |
| 1910 | * 2) Set up flow control on the MAC to that established with |
| 1911 | * the link partner. |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1912 | * 3) Config DSP to improve Gigabit link quality for some PHY revisions. |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1913 | * |
| 1914 | * hw - Struct containing variables accessed by shared code |
| 1915 | ******************************************************************************/ |
| 1916 | static int32_t |
| 1917 | e1000_copper_link_postconfig(struct e1000_hw *hw) |
| 1918 | { |
| 1919 | int32_t ret_val; |
| 1920 | DEBUGFUNC("e1000_copper_link_postconfig"); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1921 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1922 | if (hw->mac_type >= e1000_82544) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1923 | e1000_config_collision_dist(hw); |
| 1924 | } else { |
| 1925 | ret_val = e1000_config_mac_to_phy(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1926 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1927 | DEBUGOUT("Error configuring MAC to PHY settings\n"); |
| 1928 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1930 | } |
| 1931 | ret_val = e1000_config_fc_after_link_up(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1932 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1933 | DEBUGOUT("Error Configuring Flow Control\n"); |
| 1934 | return ret_val; |
| 1935 | } |
| 1936 | |
| 1937 | /* Config DSP to improve Giga link quality */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1938 | if (hw->phy_type == e1000_phy_igp) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1939 | ret_val = e1000_config_dsp_after_link_change(hw, TRUE); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1940 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1941 | DEBUGOUT("Error Configuring DSP after link up\n"); |
| 1942 | return ret_val; |
| 1943 | } |
| 1944 | } |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1945 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1946 | return E1000_SUCCESS; |
| 1947 | } |
| 1948 | |
| 1949 | /****************************************************************************** |
| 1950 | * Detects which PHY is present and setup the speed and duplex |
| 1951 | * |
| 1952 | * hw - Struct containing variables accessed by shared code |
| 1953 | ******************************************************************************/ |
| 1954 | static int32_t |
| 1955 | e1000_setup_copper_link(struct e1000_hw *hw) |
| 1956 | { |
| 1957 | int32_t ret_val; |
| 1958 | uint16_t i; |
| 1959 | uint16_t phy_data; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1960 | uint16_t reg_data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1961 | |
| 1962 | DEBUGFUNC("e1000_setup_copper_link"); |
| 1963 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1964 | switch (hw->mac_type) { |
| 1965 | case e1000_80003es2lan: |
| 1966 | case e1000_ich8lan: |
| 1967 | /* Set the mac to wait the maximum time between each |
| 1968 | * iteration and increase the max iterations when |
| 1969 | * polling the phy; this fixes erroneous timeouts at 10Mbps. */ |
| 1970 | ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF); |
| 1971 | if (ret_val) |
| 1972 | return ret_val; |
| 1973 | ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), ®_data); |
| 1974 | if (ret_val) |
| 1975 | return ret_val; |
| 1976 | reg_data |= 0x3F; |
| 1977 | ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data); |
| 1978 | if (ret_val) |
| 1979 | return ret_val; |
| 1980 | default: |
| 1981 | break; |
| 1982 | } |
| 1983 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1984 | /* Check if it is a valid PHY and set PHY mode if necessary. */ |
| 1985 | ret_val = e1000_copper_link_preconfig(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1986 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1987 | return ret_val; |
| 1988 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1989 | switch (hw->mac_type) { |
| 1990 | case e1000_80003es2lan: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1991 | /* Kumeran registers are written-only */ |
| 1992 | reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1993 | reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING; |
| 1994 | ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL, |
| 1995 | reg_data); |
| 1996 | if (ret_val) |
| 1997 | return ret_val; |
| 1998 | break; |
| 1999 | default: |
| 2000 | break; |
| 2001 | } |
| 2002 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2003 | if (hw->phy_type == e1000_phy_igp || |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2004 | hw->phy_type == e1000_phy_igp_3 || |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2005 | hw->phy_type == e1000_phy_igp_2) { |
| 2006 | ret_val = e1000_copper_link_igp_setup(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2007 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2008 | return ret_val; |
| 2009 | } else if (hw->phy_type == e1000_phy_m88) { |
| 2010 | ret_val = e1000_copper_link_mgp_setup(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2011 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2012 | return ret_val; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2013 | } else if (hw->phy_type == e1000_phy_gg82563) { |
| 2014 | ret_val = e1000_copper_link_ggp_setup(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2015 | if (ret_val) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2016 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2019 | if (hw->autoneg) { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2020 | /* Setup autoneg and flow control advertisement |
| 2021 | * and perform autonegotiation */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2022 | ret_val = e1000_copper_link_autoneg(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2023 | if (ret_val) |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2024 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2025 | } else { |
| 2026 | /* PHY will be set to 10H, 10F, 100H,or 100F |
| 2027 | * depending on value from forced_speed_duplex. */ |
| 2028 | DEBUGOUT("Forcing speed and duplex\n"); |
| 2029 | ret_val = e1000_phy_force_speed_duplex(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2030 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2031 | DEBUGOUT("Error Forcing Speed and Duplex\n"); |
| 2032 | return ret_val; |
| 2033 | } |
| 2034 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | |
| 2036 | /* Check link status. Wait up to 100 microseconds for link to become |
| 2037 | * valid. |
| 2038 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2039 | for (i = 0; i < 10; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2041 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | return ret_val; |
| 2043 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2044 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | return ret_val; |
| 2046 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2047 | if (phy_data & MII_SR_LINK_STATUS) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2048 | /* Config the MAC and PHY after link is up */ |
| 2049 | ret_val = e1000_copper_link_postconfig(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2050 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | return ret_val; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | DEBUGOUT("Valid link established!!!\n"); |
| 2054 | return E1000_SUCCESS; |
| 2055 | } |
| 2056 | udelay(10); |
| 2057 | } |
| 2058 | |
| 2059 | DEBUGOUT("Unable to establish link!!!\n"); |
| 2060 | return E1000_SUCCESS; |
| 2061 | } |
| 2062 | |
| 2063 | /****************************************************************************** |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2064 | * Configure the MAC-to-PHY interface for 10/100Mbps |
| 2065 | * |
| 2066 | * hw - Struct containing variables accessed by shared code |
| 2067 | ******************************************************************************/ |
| 2068 | static int32_t |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2069 | e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2070 | { |
| 2071 | int32_t ret_val = E1000_SUCCESS; |
| 2072 | uint32_t tipg; |
| 2073 | uint16_t reg_data; |
| 2074 | |
| 2075 | DEBUGFUNC("e1000_configure_kmrn_for_10_100"); |
| 2076 | |
| 2077 | reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT; |
| 2078 | ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL, |
| 2079 | reg_data); |
| 2080 | if (ret_val) |
| 2081 | return ret_val; |
| 2082 | |
| 2083 | /* Configure Transmit Inter-Packet Gap */ |
| 2084 | tipg = E1000_READ_REG(hw, TIPG); |
| 2085 | tipg &= ~E1000_TIPG_IPGT_MASK; |
| 2086 | tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100; |
| 2087 | E1000_WRITE_REG(hw, TIPG, tipg); |
| 2088 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2089 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data); |
| 2090 | |
| 2091 | if (ret_val) |
| 2092 | return ret_val; |
| 2093 | |
| 2094 | if (duplex == HALF_DUPLEX) |
| 2095 | reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER; |
| 2096 | else |
| 2097 | reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER; |
| 2098 | |
| 2099 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data); |
| 2100 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2101 | return ret_val; |
| 2102 | } |
| 2103 | |
| 2104 | static int32_t |
| 2105 | e1000_configure_kmrn_for_1000(struct e1000_hw *hw) |
| 2106 | { |
| 2107 | int32_t ret_val = E1000_SUCCESS; |
| 2108 | uint16_t reg_data; |
| 2109 | uint32_t tipg; |
| 2110 | |
| 2111 | DEBUGFUNC("e1000_configure_kmrn_for_1000"); |
| 2112 | |
| 2113 | reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT; |
| 2114 | ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL, |
| 2115 | reg_data); |
| 2116 | if (ret_val) |
| 2117 | return ret_val; |
| 2118 | |
| 2119 | /* Configure Transmit Inter-Packet Gap */ |
| 2120 | tipg = E1000_READ_REG(hw, TIPG); |
| 2121 | tipg &= ~E1000_TIPG_IPGT_MASK; |
| 2122 | tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000; |
| 2123 | E1000_WRITE_REG(hw, TIPG, tipg); |
| 2124 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2125 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data); |
| 2126 | |
| 2127 | if (ret_val) |
| 2128 | return ret_val; |
| 2129 | |
| 2130 | reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER; |
| 2131 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data); |
| 2132 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2133 | return ret_val; |
| 2134 | } |
| 2135 | |
| 2136 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | * Configures PHY autoneg and flow control advertisement settings |
| 2138 | * |
| 2139 | * hw - Struct containing variables accessed by shared code |
| 2140 | ******************************************************************************/ |
| 2141 | int32_t |
| 2142 | e1000_phy_setup_autoneg(struct e1000_hw *hw) |
| 2143 | { |
| 2144 | int32_t ret_val; |
| 2145 | uint16_t mii_autoneg_adv_reg; |
| 2146 | uint16_t mii_1000t_ctrl_reg; |
| 2147 | |
| 2148 | DEBUGFUNC("e1000_phy_setup_autoneg"); |
| 2149 | |
| 2150 | /* Read the MII Auto-Neg Advertisement Register (Address 4). */ |
| 2151 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2152 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | return ret_val; |
| 2154 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2155 | if (hw->phy_type != e1000_phy_ife) { |
| 2156 | /* Read the MII 1000Base-T Control Register (Address 9). */ |
| 2157 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg); |
| 2158 | if (ret_val) |
| 2159 | return ret_val; |
| 2160 | } else |
| 2161 | mii_1000t_ctrl_reg=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | |
| 2163 | /* Need to parse both autoneg_advertised and fc and set up |
| 2164 | * the appropriate PHY registers. First we will parse for |
| 2165 | * autoneg_advertised software override. Since we can advertise |
| 2166 | * a plethora of combinations, we need to check each bit |
| 2167 | * individually. |
| 2168 | */ |
| 2169 | |
| 2170 | /* First we clear all the 10/100 mb speed bits in the Auto-Neg |
| 2171 | * Advertisement Register (Address 4) and the 1000 mb speed bits in |
| 2172 | * the 1000Base-T Control Register (Address 9). |
| 2173 | */ |
| 2174 | mii_autoneg_adv_reg &= ~REG4_SPEED_MASK; |
| 2175 | mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK; |
| 2176 | |
| 2177 | DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised); |
| 2178 | |
| 2179 | /* Do we want to advertise 10 Mb Half Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2180 | if (hw->autoneg_advertised & ADVERTISE_10_HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | DEBUGOUT("Advertise 10mb Half duplex\n"); |
| 2182 | mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS; |
| 2183 | } |
| 2184 | |
| 2185 | /* Do we want to advertise 10 Mb Full Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2186 | if (hw->autoneg_advertised & ADVERTISE_10_FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | DEBUGOUT("Advertise 10mb Full duplex\n"); |
| 2188 | mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS; |
| 2189 | } |
| 2190 | |
| 2191 | /* Do we want to advertise 100 Mb Half Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2192 | if (hw->autoneg_advertised & ADVERTISE_100_HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | DEBUGOUT("Advertise 100mb Half duplex\n"); |
| 2194 | mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS; |
| 2195 | } |
| 2196 | |
| 2197 | /* Do we want to advertise 100 Mb Full Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2198 | if (hw->autoneg_advertised & ADVERTISE_100_FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | DEBUGOUT("Advertise 100mb Full duplex\n"); |
| 2200 | mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS; |
| 2201 | } |
| 2202 | |
| 2203 | /* We do not allow the Phy to advertise 1000 Mb Half Duplex */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2204 | if (hw->autoneg_advertised & ADVERTISE_1000_HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n"); |
| 2206 | } |
| 2207 | |
| 2208 | /* Do we want to advertise 1000 Mb Full Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2209 | if (hw->autoneg_advertised & ADVERTISE_1000_FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | DEBUGOUT("Advertise 1000mb Full duplex\n"); |
| 2211 | mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2212 | if (hw->phy_type == e1000_phy_ife) { |
| 2213 | DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n"); |
| 2214 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | /* Check for a software override of the flow control settings, and |
| 2218 | * setup the PHY advertisement registers accordingly. If |
| 2219 | * auto-negotiation is enabled, then software will have to set the |
| 2220 | * "PAUSE" bits to the correct value in the Auto-Negotiation |
| 2221 | * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation. |
| 2222 | * |
| 2223 | * The possible values of the "fc" parameter are: |
| 2224 | * 0: Flow control is completely disabled |
| 2225 | * 1: Rx flow control is enabled (we can receive pause frames |
| 2226 | * but not send pause frames). |
| 2227 | * 2: Tx flow control is enabled (we can send pause frames |
| 2228 | * but we do not support receiving pause frames). |
| 2229 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
| 2230 | * other: No software override. The flow control configuration |
| 2231 | * in the EEPROM is used. |
| 2232 | */ |
| 2233 | switch (hw->fc) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2234 | case E1000_FC_NONE: /* 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | /* Flow control (RX & TX) is completely disabled by a |
| 2236 | * software over-ride. |
| 2237 | */ |
| 2238 | mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 2239 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2240 | case E1000_FC_RX_PAUSE: /* 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | /* RX Flow control is enabled, and TX Flow control is |
| 2242 | * disabled, by a software over-ride. |
| 2243 | */ |
| 2244 | /* Since there really isn't a way to advertise that we are |
| 2245 | * capable of RX Pause ONLY, we will advertise that we |
| 2246 | * support both symmetric and asymmetric RX PAUSE. Later |
| 2247 | * (in e1000_config_fc_after_link_up) we will disable the |
| 2248 | *hw's ability to send PAUSE frames. |
| 2249 | */ |
| 2250 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 2251 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2252 | case E1000_FC_TX_PAUSE: /* 2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | /* TX Flow control is enabled, and RX Flow control is |
| 2254 | * disabled, by a software over-ride. |
| 2255 | */ |
| 2256 | mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR; |
| 2257 | mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE; |
| 2258 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2259 | case E1000_FC_FULL: /* 3 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | /* Flow control (both RX and TX) is enabled by a software |
| 2261 | * over-ride. |
| 2262 | */ |
| 2263 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 2264 | break; |
| 2265 | default: |
| 2266 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 2267 | return -E1000_ERR_CONFIG; |
| 2268 | } |
| 2269 | |
| 2270 | ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2271 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | return ret_val; |
| 2273 | |
| 2274 | DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg); |
| 2275 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2276 | if (hw->phy_type != e1000_phy_ife) { |
| 2277 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg); |
| 2278 | if (ret_val) |
| 2279 | return ret_val; |
| 2280 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | |
| 2282 | return E1000_SUCCESS; |
| 2283 | } |
| 2284 | |
| 2285 | /****************************************************************************** |
| 2286 | * Force PHY speed and duplex settings to hw->forced_speed_duplex |
| 2287 | * |
| 2288 | * hw - Struct containing variables accessed by shared code |
| 2289 | ******************************************************************************/ |
| 2290 | static int32_t |
| 2291 | e1000_phy_force_speed_duplex(struct e1000_hw *hw) |
| 2292 | { |
| 2293 | uint32_t ctrl; |
| 2294 | int32_t ret_val; |
| 2295 | uint16_t mii_ctrl_reg; |
| 2296 | uint16_t mii_status_reg; |
| 2297 | uint16_t phy_data; |
| 2298 | uint16_t i; |
| 2299 | |
| 2300 | DEBUGFUNC("e1000_phy_force_speed_duplex"); |
| 2301 | |
| 2302 | /* Turn off Flow control if we are forcing speed and duplex. */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2303 | hw->fc = E1000_FC_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | |
| 2305 | DEBUGOUT1("hw->fc = %d\n", hw->fc); |
| 2306 | |
| 2307 | /* Read the Device Control Register. */ |
| 2308 | ctrl = E1000_READ_REG(hw, CTRL); |
| 2309 | |
| 2310 | /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */ |
| 2311 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 2312 | ctrl &= ~(DEVICE_SPEED_MASK); |
| 2313 | |
| 2314 | /* Clear the Auto Speed Detect Enable bit. */ |
| 2315 | ctrl &= ~E1000_CTRL_ASDE; |
| 2316 | |
| 2317 | /* Read the MII Control Register. */ |
| 2318 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2319 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | return ret_val; |
| 2321 | |
| 2322 | /* We need to disable autoneg in order to force link and duplex. */ |
| 2323 | |
| 2324 | mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN; |
| 2325 | |
| 2326 | /* Are we forcing Full or Half Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2327 | if (hw->forced_speed_duplex == e1000_100_full || |
| 2328 | hw->forced_speed_duplex == e1000_10_full) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | /* We want to force full duplex so we SET the full duplex bits in the |
| 2330 | * Device and MII Control Registers. |
| 2331 | */ |
| 2332 | ctrl |= E1000_CTRL_FD; |
| 2333 | mii_ctrl_reg |= MII_CR_FULL_DUPLEX; |
| 2334 | DEBUGOUT("Full Duplex\n"); |
| 2335 | } else { |
| 2336 | /* We want to force half duplex so we CLEAR the full duplex bits in |
| 2337 | * the Device and MII Control Registers. |
| 2338 | */ |
| 2339 | ctrl &= ~E1000_CTRL_FD; |
| 2340 | mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX; |
| 2341 | DEBUGOUT("Half Duplex\n"); |
| 2342 | } |
| 2343 | |
| 2344 | /* Are we forcing 100Mbps??? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2345 | if (hw->forced_speed_duplex == e1000_100_full || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | hw->forced_speed_duplex == e1000_100_half) { |
| 2347 | /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */ |
| 2348 | ctrl |= E1000_CTRL_SPD_100; |
| 2349 | mii_ctrl_reg |= MII_CR_SPEED_100; |
| 2350 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10); |
| 2351 | DEBUGOUT("Forcing 100mb "); |
| 2352 | } else { |
| 2353 | /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */ |
| 2354 | ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100); |
| 2355 | mii_ctrl_reg |= MII_CR_SPEED_10; |
| 2356 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100); |
| 2357 | DEBUGOUT("Forcing 10mb "); |
| 2358 | } |
| 2359 | |
| 2360 | e1000_config_collision_dist(hw); |
| 2361 | |
| 2362 | /* Write the configured values back to the Device Control Reg. */ |
| 2363 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 2364 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2365 | if ((hw->phy_type == e1000_phy_m88) || |
| 2366 | (hw->phy_type == e1000_phy_gg82563)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2368 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | return ret_val; |
| 2370 | |
| 2371 | /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI |
| 2372 | * forced whenever speed are duplex are forced. |
| 2373 | */ |
| 2374 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 2375 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2376 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | return ret_val; |
| 2378 | |
| 2379 | DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data); |
| 2380 | |
| 2381 | /* Need to reset the PHY or these changes will be ignored */ |
| 2382 | mii_ctrl_reg |= MII_CR_RESET; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2383 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2384 | /* Disable MDI-X support for 10/100 */ |
| 2385 | } else if (hw->phy_type == e1000_phy_ife) { |
| 2386 | ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data); |
| 2387 | if (ret_val) |
| 2388 | return ret_val; |
| 2389 | |
| 2390 | phy_data &= ~IFE_PMC_AUTO_MDIX; |
| 2391 | phy_data &= ~IFE_PMC_FORCE_MDIX; |
| 2392 | |
| 2393 | ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data); |
| 2394 | if (ret_val) |
| 2395 | return ret_val; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | } else { |
| 2398 | /* Clear Auto-Crossover to force MDI manually. IGP requires MDI |
| 2399 | * forced whenever speed or duplex are forced. |
| 2400 | */ |
| 2401 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2402 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | return ret_val; |
| 2404 | |
| 2405 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 2406 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 2407 | |
| 2408 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2409 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | return ret_val; |
| 2411 | } |
| 2412 | |
| 2413 | /* Write back the modified PHY MII control register. */ |
| 2414 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2415 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | return ret_val; |
| 2417 | |
| 2418 | udelay(1); |
| 2419 | |
| 2420 | /* The wait_autoneg_complete flag may be a little misleading here. |
| 2421 | * Since we are forcing speed and duplex, Auto-Neg is not enabled. |
| 2422 | * But we do want to delay for a period while forcing only so we |
| 2423 | * don't generate false No Link messages. So we will wait here |
| 2424 | * only if the user has set wait_autoneg_complete to 1, which is |
| 2425 | * the default. |
| 2426 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2427 | if (hw->wait_autoneg_complete) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | /* We will wait for autoneg to complete. */ |
| 2429 | DEBUGOUT("Waiting for forced speed/duplex link.\n"); |
| 2430 | mii_status_reg = 0; |
| 2431 | |
| 2432 | /* We will wait for autoneg to complete or 4.5 seconds to expire. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2433 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | /* Read the MII Status Register and wait for Auto-Neg Complete bit |
| 2435 | * to be set. |
| 2436 | */ |
| 2437 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2438 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | return ret_val; |
| 2440 | |
| 2441 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2442 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | return ret_val; |
| 2444 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2445 | if (mii_status_reg & MII_SR_LINK_STATUS) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 2446 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2448 | if ((i == 0) && |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2449 | ((hw->phy_type == e1000_phy_m88) || |
| 2450 | (hw->phy_type == e1000_phy_gg82563))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | /* We didn't get link. Reset the DSP and wait again for link. */ |
| 2452 | ret_val = e1000_phy_reset_dsp(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2453 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | DEBUGOUT("Error Resetting PHY DSP\n"); |
| 2455 | return ret_val; |
| 2456 | } |
| 2457 | } |
| 2458 | /* This loop will early-out if the link condition has been met. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2459 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
| 2460 | if (mii_status_reg & MII_SR_LINK_STATUS) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 2461 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | /* Read the MII Status Register and wait for Auto-Neg Complete bit |
| 2463 | * to be set. |
| 2464 | */ |
| 2465 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2466 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | return ret_val; |
| 2468 | |
| 2469 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2470 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | return ret_val; |
| 2472 | } |
| 2473 | } |
| 2474 | |
| 2475 | if (hw->phy_type == e1000_phy_m88) { |
| 2476 | /* Because we reset the PHY above, we need to re-force TX_CLK in the |
| 2477 | * Extended PHY Specific Control Register to 25MHz clock. This value |
| 2478 | * defaults back to a 2.5MHz clock when the PHY is reset. |
| 2479 | */ |
| 2480 | ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2481 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | return ret_val; |
| 2483 | |
| 2484 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
| 2485 | ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2486 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | return ret_val; |
| 2488 | |
| 2489 | /* In addition, because of the s/w reset above, we need to enable CRS on |
| 2490 | * TX. This must be set for both full and half duplex operation. |
| 2491 | */ |
| 2492 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2493 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | return ret_val; |
| 2495 | |
| 2496 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 2497 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2498 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | return ret_val; |
| 2500 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2501 | if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) && |
| 2502 | (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full || |
| 2503 | hw->forced_speed_duplex == e1000_10_half)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2504 | ret_val = e1000_polarity_reversal_workaround(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2505 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | return ret_val; |
| 2507 | } |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2508 | } else if (hw->phy_type == e1000_phy_gg82563) { |
| 2509 | /* The TX_CLK of the Extended PHY Specific Control Register defaults |
| 2510 | * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if |
| 2511 | * we're not in a forced 10/duplex configuration. */ |
| 2512 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data); |
| 2513 | if (ret_val) |
| 2514 | return ret_val; |
| 2515 | |
| 2516 | phy_data &= ~GG82563_MSCR_TX_CLK_MASK; |
| 2517 | if ((hw->forced_speed_duplex == e1000_10_full) || |
| 2518 | (hw->forced_speed_duplex == e1000_10_half)) |
| 2519 | phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ; |
| 2520 | else |
| 2521 | phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ; |
| 2522 | |
| 2523 | /* Also due to the reset, we need to enable CRS on Tx. */ |
| 2524 | phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX; |
| 2525 | |
| 2526 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data); |
| 2527 | if (ret_val) |
| 2528 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | } |
| 2530 | return E1000_SUCCESS; |
| 2531 | } |
| 2532 | |
| 2533 | /****************************************************************************** |
| 2534 | * Sets the collision distance in the Transmit Control register |
| 2535 | * |
| 2536 | * hw - Struct containing variables accessed by shared code |
| 2537 | * |
| 2538 | * Link should have been established previously. Reads the speed and duplex |
| 2539 | * information from the Device Status register. |
| 2540 | ******************************************************************************/ |
| 2541 | void |
| 2542 | e1000_config_collision_dist(struct e1000_hw *hw) |
| 2543 | { |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 2544 | uint32_t tctl, coll_dist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | |
| 2546 | DEBUGFUNC("e1000_config_collision_dist"); |
| 2547 | |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 2548 | if (hw->mac_type < e1000_82543) |
| 2549 | coll_dist = E1000_COLLISION_DISTANCE_82542; |
| 2550 | else |
| 2551 | coll_dist = E1000_COLLISION_DISTANCE; |
| 2552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | tctl = E1000_READ_REG(hw, TCTL); |
| 2554 | |
| 2555 | tctl &= ~E1000_TCTL_COLD; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 2556 | tctl |= coll_dist << E1000_COLD_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | |
| 2558 | E1000_WRITE_REG(hw, TCTL, tctl); |
| 2559 | E1000_WRITE_FLUSH(hw); |
| 2560 | } |
| 2561 | |
| 2562 | /****************************************************************************** |
| 2563 | * Sets MAC speed and duplex settings to reflect the those in the PHY |
| 2564 | * |
| 2565 | * hw - Struct containing variables accessed by shared code |
| 2566 | * mii_reg - data to write to the MII control register |
| 2567 | * |
| 2568 | * The contents of the PHY register containing the needed information need to |
| 2569 | * be passed in. |
| 2570 | ******************************************************************************/ |
| 2571 | static int32_t |
| 2572 | e1000_config_mac_to_phy(struct e1000_hw *hw) |
| 2573 | { |
| 2574 | uint32_t ctrl; |
| 2575 | int32_t ret_val; |
| 2576 | uint16_t phy_data; |
| 2577 | |
| 2578 | DEBUGFUNC("e1000_config_mac_to_phy"); |
| 2579 | |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2580 | /* 82544 or newer MAC, Auto Speed Detection takes care of |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2581 | * MAC speed/duplex configuration.*/ |
| 2582 | if (hw->mac_type >= e1000_82544) |
| 2583 | return E1000_SUCCESS; |
| 2584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | /* Read the Device Control Register and set the bits to Force Speed |
| 2586 | * and Duplex. |
| 2587 | */ |
| 2588 | ctrl = E1000_READ_REG(hw, CTRL); |
| 2589 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 2590 | ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS); |
| 2591 | |
| 2592 | /* Set up duplex in the Device Control and Transmit Control |
| 2593 | * registers depending on negotiated values. |
| 2594 | */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2595 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2596 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2597 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2599 | if (phy_data & M88E1000_PSSR_DPLX) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2600 | ctrl |= E1000_CTRL_FD; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2601 | else |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2602 | ctrl &= ~E1000_CTRL_FD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2604 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2605 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2606 | /* Set up speed in the Device Control register depending on |
| 2607 | * negotiated values. |
| 2608 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2609 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2610 | ctrl |= E1000_CTRL_SPD_1000; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2611 | else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2612 | ctrl |= E1000_CTRL_SPD_100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2614 | /* Write the configured values back to the Device Control Reg. */ |
| 2615 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 2616 | return E1000_SUCCESS; |
| 2617 | } |
| 2618 | |
| 2619 | /****************************************************************************** |
| 2620 | * Forces the MAC's flow control settings. |
| 2621 | * |
| 2622 | * hw - Struct containing variables accessed by shared code |
| 2623 | * |
| 2624 | * Sets the TFCE and RFCE bits in the device control register to reflect |
| 2625 | * the adapter settings. TFCE and RFCE need to be explicitly set by |
| 2626 | * software when a Copper PHY is used because autonegotiation is managed |
| 2627 | * by the PHY rather than the MAC. Software must also configure these |
| 2628 | * bits when link is forced on a fiber connection. |
| 2629 | *****************************************************************************/ |
| 2630 | int32_t |
| 2631 | e1000_force_mac_fc(struct e1000_hw *hw) |
| 2632 | { |
| 2633 | uint32_t ctrl; |
| 2634 | |
| 2635 | DEBUGFUNC("e1000_force_mac_fc"); |
| 2636 | |
| 2637 | /* Get the current configuration of the Device Control Register */ |
| 2638 | ctrl = E1000_READ_REG(hw, CTRL); |
| 2639 | |
| 2640 | /* Because we didn't get link via the internal auto-negotiation |
| 2641 | * mechanism (we either forced link or we got link via PHY |
| 2642 | * auto-neg), we have to manually enable/disable transmit an |
| 2643 | * receive flow control. |
| 2644 | * |
| 2645 | * The "Case" statement below enables/disable flow control |
| 2646 | * according to the "hw->fc" parameter. |
| 2647 | * |
| 2648 | * The possible values of the "fc" parameter are: |
| 2649 | * 0: Flow control is completely disabled |
| 2650 | * 1: Rx flow control is enabled (we can receive pause |
| 2651 | * frames but not send pause frames). |
| 2652 | * 2: Tx flow control is enabled (we can send pause frames |
| 2653 | * frames but we do not receive pause frames). |
| 2654 | * 3: Both Rx and TX flow control (symmetric) is enabled. |
| 2655 | * other: No other values should be possible at this point. |
| 2656 | */ |
| 2657 | |
| 2658 | switch (hw->fc) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2659 | case E1000_FC_NONE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); |
| 2661 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2662 | case E1000_FC_RX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | ctrl &= (~E1000_CTRL_TFCE); |
| 2664 | ctrl |= E1000_CTRL_RFCE; |
| 2665 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2666 | case E1000_FC_TX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | ctrl &= (~E1000_CTRL_RFCE); |
| 2668 | ctrl |= E1000_CTRL_TFCE; |
| 2669 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2670 | case E1000_FC_FULL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); |
| 2672 | break; |
| 2673 | default: |
| 2674 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 2675 | return -E1000_ERR_CONFIG; |
| 2676 | } |
| 2677 | |
| 2678 | /* Disable TX Flow Control for 82542 (rev 2.0) */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2679 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | ctrl &= (~E1000_CTRL_TFCE); |
| 2681 | |
| 2682 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 2683 | return E1000_SUCCESS; |
| 2684 | } |
| 2685 | |
| 2686 | /****************************************************************************** |
| 2687 | * Configures flow control settings after link is established |
| 2688 | * |
| 2689 | * hw - Struct containing variables accessed by shared code |
| 2690 | * |
| 2691 | * Should be called immediately after a valid link has been established. |
| 2692 | * Forces MAC flow control settings if link was forced. When in MII/GMII mode |
| 2693 | * and autonegotiation is enabled, the MAC flow control settings will be set |
| 2694 | * based on the flow control negotiated by the PHY. In TBI mode, the TFCE |
| 2695 | * and RFCE bits will be automaticaly set to the negotiated flow control mode. |
| 2696 | *****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 2697 | static int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | e1000_config_fc_after_link_up(struct e1000_hw *hw) |
| 2699 | { |
| 2700 | int32_t ret_val; |
| 2701 | uint16_t mii_status_reg; |
| 2702 | uint16_t mii_nway_adv_reg; |
| 2703 | uint16_t mii_nway_lp_ability_reg; |
| 2704 | uint16_t speed; |
| 2705 | uint16_t duplex; |
| 2706 | |
| 2707 | DEBUGFUNC("e1000_config_fc_after_link_up"); |
| 2708 | |
| 2709 | /* Check for the case where we have fiber media and auto-neg failed |
| 2710 | * so we had to force link. In this case, we need to force the |
| 2711 | * configuration of the MAC to match the "fc" parameter. |
| 2712 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2713 | if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) || |
| 2714 | ((hw->media_type == e1000_media_type_internal_serdes) && |
| 2715 | (hw->autoneg_failed)) || |
| 2716 | ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | ret_val = e1000_force_mac_fc(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2718 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | DEBUGOUT("Error forcing flow control settings\n"); |
| 2720 | return ret_val; |
| 2721 | } |
| 2722 | } |
| 2723 | |
| 2724 | /* Check for the case where we have copper media and auto-neg is |
| 2725 | * enabled. In this case, we need to check and see if Auto-Neg |
| 2726 | * has completed, and if so, how the PHY and link partner has |
| 2727 | * flow control configured. |
| 2728 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2729 | if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | /* Read the MII Status Register and check to see if AutoNeg |
| 2731 | * has completed. We read this twice because this reg has |
| 2732 | * some "sticky" (latched) bits. |
| 2733 | */ |
| 2734 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2735 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | return ret_val; |
| 2737 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2738 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | return ret_val; |
| 2740 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2741 | if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | /* The AutoNeg process has completed, so we now need to |
| 2743 | * read both the Auto Negotiation Advertisement Register |
| 2744 | * (Address 4) and the Auto_Negotiation Base Page Ability |
| 2745 | * Register (Address 5) to determine how flow control was |
| 2746 | * negotiated. |
| 2747 | */ |
| 2748 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, |
| 2749 | &mii_nway_adv_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2750 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | return ret_val; |
| 2752 | ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, |
| 2753 | &mii_nway_lp_ability_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2754 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | return ret_val; |
| 2756 | |
| 2757 | /* Two bits in the Auto Negotiation Advertisement Register |
| 2758 | * (Address 4) and two bits in the Auto Negotiation Base |
| 2759 | * Page Ability Register (Address 5) determine flow control |
| 2760 | * for both the PHY and the link partner. The following |
| 2761 | * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, |
| 2762 | * 1999, describes these PAUSE resolution bits and how flow |
| 2763 | * control is determined based upon these settings. |
| 2764 | * NOTE: DC = Don't Care |
| 2765 | * |
| 2766 | * LOCAL DEVICE | LINK PARTNER |
| 2767 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution |
| 2768 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2769 | * 0 | 0 | DC | DC | E1000_FC_NONE |
| 2770 | * 0 | 1 | 0 | DC | E1000_FC_NONE |
| 2771 | * 0 | 1 | 1 | 0 | E1000_FC_NONE |
| 2772 | * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE |
| 2773 | * 1 | 0 | 0 | DC | E1000_FC_NONE |
| 2774 | * 1 | DC | 1 | DC | E1000_FC_FULL |
| 2775 | * 1 | 1 | 0 | 0 | E1000_FC_NONE |
| 2776 | * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | * |
| 2778 | */ |
| 2779 | /* Are both PAUSE bits set to 1? If so, this implies |
| 2780 | * Symmetric Flow Control is enabled at both ends. The |
| 2781 | * ASM_DIR bits are irrelevant per the spec. |
| 2782 | * |
| 2783 | * For Symmetric Flow Control: |
| 2784 | * |
| 2785 | * LOCAL DEVICE | LINK PARTNER |
| 2786 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 2787 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2788 | * 1 | DC | 1 | DC | E1000_FC_FULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | * |
| 2790 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2791 | if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2792 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | /* Now we need to check if the user selected RX ONLY |
| 2794 | * of pause frames. In this case, we had to advertise |
| 2795 | * FULL flow control because we could not advertise RX |
| 2796 | * ONLY. Hence, we must now check to see if we need to |
| 2797 | * turn OFF the TRANSMISSION of PAUSE frames. |
| 2798 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2799 | if (hw->original_fc == E1000_FC_FULL) { |
| 2800 | hw->fc = E1000_FC_FULL; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2801 | DEBUGOUT("Flow Control = FULL.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | } else { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2803 | hw->fc = E1000_FC_RX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2804 | DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | } |
| 2806 | } |
| 2807 | /* For receiving PAUSE frames ONLY. |
| 2808 | * |
| 2809 | * LOCAL DEVICE | LINK PARTNER |
| 2810 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 2811 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2812 | * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | * |
| 2814 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2815 | else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2816 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 2817 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 2818 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2819 | hw->fc = E1000_FC_TX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2820 | DEBUGOUT("Flow Control = TX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | } |
| 2822 | /* For transmitting PAUSE frames ONLY. |
| 2823 | * |
| 2824 | * LOCAL DEVICE | LINK PARTNER |
| 2825 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 2826 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2827 | * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | * |
| 2829 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2830 | else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2831 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 2832 | !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 2833 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2834 | hw->fc = E1000_FC_RX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2835 | DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | } |
| 2837 | /* Per the IEEE spec, at this point flow control should be |
| 2838 | * disabled. However, we want to consider that we could |
| 2839 | * be connected to a legacy switch that doesn't advertise |
| 2840 | * desired flow control, but can be forced on the link |
| 2841 | * partner. So if we advertised no flow control, that is |
| 2842 | * what we will resolve to. If we advertised some kind of |
| 2843 | * receive capability (Rx Pause Only or Full Flow Control) |
| 2844 | * and the link partner advertised none, we will configure |
| 2845 | * ourselves to enable Rx Flow Control only. We can do |
| 2846 | * this safely for two reasons: If the link partner really |
| 2847 | * didn't want flow control enabled, and we enable Rx, no |
| 2848 | * harm done since we won't be receiving any PAUSE frames |
| 2849 | * anyway. If the intent on the link partner was to have |
| 2850 | * flow control enabled, then by us enabling RX only, we |
| 2851 | * can at least receive pause frames and process them. |
| 2852 | * This is a good idea because in most cases, since we are |
| 2853 | * predominantly a server NIC, more times than not we will |
| 2854 | * be asked to delay transmission of packets than asking |
| 2855 | * our link partner to pause transmission of frames. |
| 2856 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2857 | else if ((hw->original_fc == E1000_FC_NONE || |
| 2858 | hw->original_fc == E1000_FC_TX_PAUSE) || |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2859 | hw->fc_strict_ieee) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2860 | hw->fc = E1000_FC_NONE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2861 | DEBUGOUT("Flow Control = NONE.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | } else { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2863 | hw->fc = E1000_FC_RX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2864 | DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | } |
| 2866 | |
| 2867 | /* Now we need to do one last check... If we auto- |
| 2868 | * negotiated to HALF DUPLEX, flow control should not be |
| 2869 | * enabled per IEEE 802.3 spec. |
| 2870 | */ |
| 2871 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2872 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2873 | DEBUGOUT("Error getting link speed and duplex\n"); |
| 2874 | return ret_val; |
| 2875 | } |
| 2876 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2877 | if (duplex == HALF_DUPLEX) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2878 | hw->fc = E1000_FC_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | |
| 2880 | /* Now we call a subroutine to actually force the MAC |
| 2881 | * controller to use the correct flow control settings. |
| 2882 | */ |
| 2883 | ret_val = e1000_force_mac_fc(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2884 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | DEBUGOUT("Error forcing flow control settings\n"); |
| 2886 | return ret_val; |
| 2887 | } |
| 2888 | } else { |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2889 | DEBUGOUT("Copper PHY and Auto Neg has not completed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | } |
| 2891 | } |
| 2892 | return E1000_SUCCESS; |
| 2893 | } |
| 2894 | |
| 2895 | /****************************************************************************** |
| 2896 | * Checks to see if the link status of the hardware has changed. |
| 2897 | * |
| 2898 | * hw - Struct containing variables accessed by shared code |
| 2899 | * |
| 2900 | * Called by any function that needs to check the link status of the adapter. |
| 2901 | *****************************************************************************/ |
| 2902 | int32_t |
| 2903 | e1000_check_for_link(struct e1000_hw *hw) |
| 2904 | { |
| 2905 | uint32_t rxcw = 0; |
| 2906 | uint32_t ctrl; |
| 2907 | uint32_t status; |
| 2908 | uint32_t rctl; |
| 2909 | uint32_t icr; |
| 2910 | uint32_t signal = 0; |
| 2911 | int32_t ret_val; |
| 2912 | uint16_t phy_data; |
| 2913 | |
| 2914 | DEBUGFUNC("e1000_check_for_link"); |
| 2915 | |
| 2916 | ctrl = E1000_READ_REG(hw, CTRL); |
| 2917 | status = E1000_READ_REG(hw, STATUS); |
| 2918 | |
| 2919 | /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be |
| 2920 | * set when the optics detect a signal. On older adapters, it will be |
| 2921 | * cleared when there is a signal. This applies to fiber media only. |
| 2922 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2923 | if ((hw->media_type == e1000_media_type_fiber) || |
| 2924 | (hw->media_type == e1000_media_type_internal_serdes)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | rxcw = E1000_READ_REG(hw, RXCW); |
| 2926 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2927 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2929 | if (status & E1000_STATUS_LU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | hw->get_link_status = FALSE; |
| 2931 | } |
| 2932 | } |
| 2933 | |
| 2934 | /* If we have a copper PHY then we only want to go out to the PHY |
| 2935 | * registers to see if Auto-Neg has completed and/or if our link |
| 2936 | * status has changed. The get_link_status flag will be set if we |
| 2937 | * receive a Link Status Change interrupt or we have Rx Sequence |
| 2938 | * Errors. |
| 2939 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2940 | if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | /* First we want to see if the MII Status Register reports |
| 2942 | * link. If so, then we want to get the current speed/duplex |
| 2943 | * of the PHY. |
| 2944 | * Read the register twice since the link bit is sticky. |
| 2945 | */ |
| 2946 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2947 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | return ret_val; |
| 2949 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2950 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | return ret_val; |
| 2952 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2953 | if (phy_data & MII_SR_LINK_STATUS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2954 | hw->get_link_status = FALSE; |
| 2955 | /* Check if there was DownShift, must be checked immediately after |
| 2956 | * link-up */ |
| 2957 | e1000_check_downshift(hw); |
| 2958 | |
| 2959 | /* If we are on 82544 or 82543 silicon and speed/duplex |
| 2960 | * are forced to 10H or 10F, then we will implement the polarity |
| 2961 | * reversal workaround. We disable interrupts first, and upon |
| 2962 | * returning, place the devices interrupt state to its previous |
| 2963 | * value except for the link status change interrupt which will |
| 2964 | * happen due to the execution of this workaround. |
| 2965 | */ |
| 2966 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2967 | if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) && |
| 2968 | (!hw->autoneg) && |
| 2969 | (hw->forced_speed_duplex == e1000_10_full || |
| 2970 | hw->forced_speed_duplex == e1000_10_half)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | E1000_WRITE_REG(hw, IMC, 0xffffffff); |
| 2972 | ret_val = e1000_polarity_reversal_workaround(hw); |
| 2973 | icr = E1000_READ_REG(hw, ICR); |
| 2974 | E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC)); |
| 2975 | E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK); |
| 2976 | } |
| 2977 | |
| 2978 | } else { |
| 2979 | /* No link detected */ |
| 2980 | e1000_config_dsp_after_link_change(hw, FALSE); |
| 2981 | return 0; |
| 2982 | } |
| 2983 | |
| 2984 | /* If we are forcing speed/duplex, then we simply return since |
| 2985 | * we have already determined whether we have link or not. |
| 2986 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2987 | if (!hw->autoneg) return -E1000_ERR_CONFIG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | |
| 2989 | /* optimize the dsp settings for the igp phy */ |
| 2990 | e1000_config_dsp_after_link_change(hw, TRUE); |
| 2991 | |
| 2992 | /* We have a M88E1000 PHY and Auto-Neg is enabled. If we |
| 2993 | * have Si on board that is 82544 or newer, Auto |
| 2994 | * Speed Detection takes care of MAC speed/duplex |
| 2995 | * configuration. So we only need to configure Collision |
| 2996 | * Distance in the MAC. Otherwise, we need to force |
| 2997 | * speed/duplex on the MAC to the current PHY speed/duplex |
| 2998 | * settings. |
| 2999 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3000 | if (hw->mac_type >= e1000_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | e1000_config_collision_dist(hw); |
| 3002 | else { |
| 3003 | ret_val = e1000_config_mac_to_phy(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3004 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | DEBUGOUT("Error configuring MAC to PHY settings\n"); |
| 3006 | return ret_val; |
| 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | /* Configure Flow Control now that Auto-Neg has completed. First, we |
| 3011 | * need to restore the desired flow control settings because we may |
| 3012 | * have had to re-autoneg with a different link partner. |
| 3013 | */ |
| 3014 | ret_val = e1000_config_fc_after_link_up(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3015 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | DEBUGOUT("Error configuring flow control\n"); |
| 3017 | return ret_val; |
| 3018 | } |
| 3019 | |
| 3020 | /* At this point we know that we are on copper and we have |
| 3021 | * auto-negotiated link. These are conditions for checking the link |
| 3022 | * partner capability register. We use the link speed to determine if |
| 3023 | * TBI compatibility needs to be turned on or off. If the link is not |
| 3024 | * at gigabit speed, then TBI compatibility is not needed. If we are |
| 3025 | * at gigabit speed, we turn on TBI compatibility. |
| 3026 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3027 | if (hw->tbi_compatibility_en) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | uint16_t speed, duplex; |
Auke Kok | 592600a | 2006-06-27 09:08:09 -0700 | [diff] [blame] | 3029 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); |
| 3030 | if (ret_val) { |
| 3031 | DEBUGOUT("Error getting link speed and duplex\n"); |
| 3032 | return ret_val; |
| 3033 | } |
| 3034 | if (speed != SPEED_1000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | /* If link speed is not set to gigabit speed, we do not need |
| 3036 | * to enable TBI compatibility. |
| 3037 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3038 | if (hw->tbi_compatibility_on) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | /* If we previously were in the mode, turn it off. */ |
| 3040 | rctl = E1000_READ_REG(hw, RCTL); |
| 3041 | rctl &= ~E1000_RCTL_SBP; |
| 3042 | E1000_WRITE_REG(hw, RCTL, rctl); |
| 3043 | hw->tbi_compatibility_on = FALSE; |
| 3044 | } |
| 3045 | } else { |
| 3046 | /* If TBI compatibility is was previously off, turn it on. For |
| 3047 | * compatibility with a TBI link partner, we will store bad |
| 3048 | * packets. Some frames have an additional byte on the end and |
| 3049 | * will look like CRC errors to to the hardware. |
| 3050 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3051 | if (!hw->tbi_compatibility_on) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | hw->tbi_compatibility_on = TRUE; |
| 3053 | rctl = E1000_READ_REG(hw, RCTL); |
| 3054 | rctl |= E1000_RCTL_SBP; |
| 3055 | E1000_WRITE_REG(hw, RCTL, rctl); |
| 3056 | } |
| 3057 | } |
| 3058 | } |
| 3059 | } |
| 3060 | /* If we don't have link (auto-negotiation failed or link partner cannot |
| 3061 | * auto-negotiate), the cable is plugged in (we have signal), and our |
| 3062 | * link partner is not trying to auto-negotiate with us (we are receiving |
| 3063 | * idles or data), we need to force link up. We also need to give |
| 3064 | * auto-negotiation time to complete, in case the cable was just plugged |
| 3065 | * in. The autoneg_failed flag does this. |
| 3066 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3067 | else if ((((hw->media_type == e1000_media_type_fiber) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | ((ctrl & E1000_CTRL_SWDPIN1) == signal)) || |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3069 | (hw->media_type == e1000_media_type_internal_serdes)) && |
| 3070 | (!(status & E1000_STATUS_LU)) && |
| 3071 | (!(rxcw & E1000_RXCW_C))) { |
| 3072 | if (hw->autoneg_failed == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | hw->autoneg_failed = 1; |
| 3074 | return 0; |
| 3075 | } |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 3076 | DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | |
| 3078 | /* Disable auto-negotiation in the TXCW register */ |
| 3079 | E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE)); |
| 3080 | |
| 3081 | /* Force link-up and also force full-duplex. */ |
| 3082 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3083 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); |
| 3084 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 3085 | |
| 3086 | /* Configure Flow Control after forcing link up. */ |
| 3087 | ret_val = e1000_config_fc_after_link_up(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3088 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | DEBUGOUT("Error configuring flow control\n"); |
| 3090 | return ret_val; |
| 3091 | } |
| 3092 | } |
| 3093 | /* If we are forcing link and we are receiving /C/ ordered sets, re-enable |
| 3094 | * auto-negotiation in the TXCW register and disable forced link in the |
| 3095 | * Device Control register in an attempt to auto-negotiate with our link |
| 3096 | * partner. |
| 3097 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3098 | else if (((hw->media_type == e1000_media_type_fiber) || |
| 3099 | (hw->media_type == e1000_media_type_internal_serdes)) && |
| 3100 | (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 3101 | DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | E1000_WRITE_REG(hw, TXCW, hw->txcw); |
| 3103 | E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU)); |
| 3104 | |
| 3105 | hw->serdes_link_down = FALSE; |
| 3106 | } |
| 3107 | /* If we force link for non-auto-negotiation switch, check link status |
| 3108 | * based on MAC synchronization for internal serdes media type. |
| 3109 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3110 | else if ((hw->media_type == e1000_media_type_internal_serdes) && |
| 3111 | !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | /* SYNCH bit and IV bit are sticky. */ |
| 3113 | udelay(10); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3114 | if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) { |
| 3115 | if (!(rxcw & E1000_RXCW_IV)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | hw->serdes_link_down = FALSE; |
| 3117 | DEBUGOUT("SERDES: Link is up.\n"); |
| 3118 | } |
| 3119 | } else { |
| 3120 | hw->serdes_link_down = TRUE; |
| 3121 | DEBUGOUT("SERDES: Link is down.\n"); |
| 3122 | } |
| 3123 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3124 | if ((hw->media_type == e1000_media_type_internal_serdes) && |
| 3125 | (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS)); |
| 3127 | } |
| 3128 | return E1000_SUCCESS; |
| 3129 | } |
| 3130 | |
| 3131 | /****************************************************************************** |
| 3132 | * Detects the current speed and duplex settings of the hardware. |
| 3133 | * |
| 3134 | * hw - Struct containing variables accessed by shared code |
| 3135 | * speed - Speed of the connection |
| 3136 | * duplex - Duplex setting of the connection |
| 3137 | *****************************************************************************/ |
| 3138 | int32_t |
| 3139 | e1000_get_speed_and_duplex(struct e1000_hw *hw, |
| 3140 | uint16_t *speed, |
| 3141 | uint16_t *duplex) |
| 3142 | { |
| 3143 | uint32_t status; |
| 3144 | int32_t ret_val; |
| 3145 | uint16_t phy_data; |
| 3146 | |
| 3147 | DEBUGFUNC("e1000_get_speed_and_duplex"); |
| 3148 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3149 | if (hw->mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | status = E1000_READ_REG(hw, STATUS); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3151 | if (status & E1000_STATUS_SPEED_1000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | *speed = SPEED_1000; |
| 3153 | DEBUGOUT("1000 Mbs, "); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3154 | } else if (status & E1000_STATUS_SPEED_100) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | *speed = SPEED_100; |
| 3156 | DEBUGOUT("100 Mbs, "); |
| 3157 | } else { |
| 3158 | *speed = SPEED_10; |
| 3159 | DEBUGOUT("10 Mbs, "); |
| 3160 | } |
| 3161 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3162 | if (status & E1000_STATUS_FD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | *duplex = FULL_DUPLEX; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 3164 | DEBUGOUT("Full Duplex\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3165 | } else { |
| 3166 | *duplex = HALF_DUPLEX; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 3167 | DEBUGOUT(" Half Duplex\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | } |
| 3169 | } else { |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 3170 | DEBUGOUT("1000 Mbs, Full Duplex\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | *speed = SPEED_1000; |
| 3172 | *duplex = FULL_DUPLEX; |
| 3173 | } |
| 3174 | |
| 3175 | /* IGP01 PHY may advertise full duplex operation after speed downgrade even |
| 3176 | * if it is operating at half duplex. Here we set the duplex settings to |
| 3177 | * match the duplex in the link partner's capabilities. |
| 3178 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3179 | if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3181 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | return ret_val; |
| 3183 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3184 | if (!(phy_data & NWAY_ER_LP_NWAY_CAPS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | *duplex = HALF_DUPLEX; |
| 3186 | else { |
| 3187 | ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3188 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | return ret_val; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3190 | if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS))) |
| 3192 | *duplex = HALF_DUPLEX; |
| 3193 | } |
| 3194 | } |
| 3195 | |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3196 | if ((hw->mac_type == e1000_80003es2lan) && |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3197 | (hw->media_type == e1000_media_type_copper)) { |
| 3198 | if (*speed == SPEED_1000) |
| 3199 | ret_val = e1000_configure_kmrn_for_1000(hw); |
| 3200 | else |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3201 | ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex); |
| 3202 | if (ret_val) |
| 3203 | return ret_val; |
| 3204 | } |
| 3205 | |
| 3206 | if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) { |
| 3207 | ret_val = e1000_kumeran_lock_loss_workaround(hw); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3208 | if (ret_val) |
| 3209 | return ret_val; |
| 3210 | } |
| 3211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | return E1000_SUCCESS; |
| 3213 | } |
| 3214 | |
| 3215 | /****************************************************************************** |
| 3216 | * Blocks until autoneg completes or times out (~4.5 seconds) |
| 3217 | * |
| 3218 | * hw - Struct containing variables accessed by shared code |
| 3219 | ******************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 3220 | static int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | e1000_wait_autoneg(struct e1000_hw *hw) |
| 3222 | { |
| 3223 | int32_t ret_val; |
| 3224 | uint16_t i; |
| 3225 | uint16_t phy_data; |
| 3226 | |
| 3227 | DEBUGFUNC("e1000_wait_autoneg"); |
| 3228 | DEBUGOUT("Waiting for Auto-Neg to complete.\n"); |
| 3229 | |
| 3230 | /* We will wait for autoneg to complete or 4.5 seconds to expire. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3231 | for (i = PHY_AUTO_NEG_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | /* Read the MII Status Register and wait for Auto-Neg |
| 3233 | * Complete bit to be set. |
| 3234 | */ |
| 3235 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3236 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | return ret_val; |
| 3238 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3239 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | return ret_val; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3241 | if (phy_data & MII_SR_AUTONEG_COMPLETE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | return E1000_SUCCESS; |
| 3243 | } |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 3244 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | } |
| 3246 | return E1000_SUCCESS; |
| 3247 | } |
| 3248 | |
| 3249 | /****************************************************************************** |
| 3250 | * Raises the Management Data Clock |
| 3251 | * |
| 3252 | * hw - Struct containing variables accessed by shared code |
| 3253 | * ctrl - Device control register's current value |
| 3254 | ******************************************************************************/ |
| 3255 | static void |
| 3256 | e1000_raise_mdi_clk(struct e1000_hw *hw, |
| 3257 | uint32_t *ctrl) |
| 3258 | { |
| 3259 | /* Raise the clock input to the Management Data Clock (by setting the MDC |
| 3260 | * bit), and then delay 10 microseconds. |
| 3261 | */ |
| 3262 | E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC)); |
| 3263 | E1000_WRITE_FLUSH(hw); |
| 3264 | udelay(10); |
| 3265 | } |
| 3266 | |
| 3267 | /****************************************************************************** |
| 3268 | * Lowers the Management Data Clock |
| 3269 | * |
| 3270 | * hw - Struct containing variables accessed by shared code |
| 3271 | * ctrl - Device control register's current value |
| 3272 | ******************************************************************************/ |
| 3273 | static void |
| 3274 | e1000_lower_mdi_clk(struct e1000_hw *hw, |
| 3275 | uint32_t *ctrl) |
| 3276 | { |
| 3277 | /* Lower the clock input to the Management Data Clock (by clearing the MDC |
| 3278 | * bit), and then delay 10 microseconds. |
| 3279 | */ |
| 3280 | E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC)); |
| 3281 | E1000_WRITE_FLUSH(hw); |
| 3282 | udelay(10); |
| 3283 | } |
| 3284 | |
| 3285 | /****************************************************************************** |
| 3286 | * Shifts data bits out to the PHY |
| 3287 | * |
| 3288 | * hw - Struct containing variables accessed by shared code |
| 3289 | * data - Data to send out to the PHY |
| 3290 | * count - Number of bits to shift out |
| 3291 | * |
| 3292 | * Bits are shifted out in MSB to LSB order. |
| 3293 | ******************************************************************************/ |
| 3294 | static void |
| 3295 | e1000_shift_out_mdi_bits(struct e1000_hw *hw, |
| 3296 | uint32_t data, |
| 3297 | uint16_t count) |
| 3298 | { |
| 3299 | uint32_t ctrl; |
| 3300 | uint32_t mask; |
| 3301 | |
| 3302 | /* We need to shift "count" number of bits out to the PHY. So, the value |
| 3303 | * in the "data" parameter will be shifted out to the PHY one bit at a |
| 3304 | * time. In order to do this, "data" must be broken down into bits. |
| 3305 | */ |
| 3306 | mask = 0x01; |
| 3307 | mask <<= (count - 1); |
| 3308 | |
| 3309 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3310 | |
| 3311 | /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */ |
| 3312 | ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR); |
| 3313 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3314 | while (mask) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and |
| 3316 | * then raising and lowering the Management Data Clock. A "0" is |
| 3317 | * shifted out to the PHY by setting the MDIO bit to "0" and then |
| 3318 | * raising and lowering the clock. |
| 3319 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3320 | if (data & mask) |
| 3321 | ctrl |= E1000_CTRL_MDIO; |
| 3322 | else |
| 3323 | ctrl &= ~E1000_CTRL_MDIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3324 | |
| 3325 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 3326 | E1000_WRITE_FLUSH(hw); |
| 3327 | |
| 3328 | udelay(10); |
| 3329 | |
| 3330 | e1000_raise_mdi_clk(hw, &ctrl); |
| 3331 | e1000_lower_mdi_clk(hw, &ctrl); |
| 3332 | |
| 3333 | mask = mask >> 1; |
| 3334 | } |
| 3335 | } |
| 3336 | |
| 3337 | /****************************************************************************** |
| 3338 | * Shifts data bits in from the PHY |
| 3339 | * |
| 3340 | * hw - Struct containing variables accessed by shared code |
| 3341 | * |
| 3342 | * Bits are shifted in in MSB to LSB order. |
| 3343 | ******************************************************************************/ |
| 3344 | static uint16_t |
| 3345 | e1000_shift_in_mdi_bits(struct e1000_hw *hw) |
| 3346 | { |
| 3347 | uint32_t ctrl; |
| 3348 | uint16_t data = 0; |
| 3349 | uint8_t i; |
| 3350 | |
| 3351 | /* In order to read a register from the PHY, we need to shift in a total |
| 3352 | * of 18 bits from the PHY. The first two bit (turnaround) times are used |
| 3353 | * to avoid contention on the MDIO pin when a read operation is performed. |
| 3354 | * These two bits are ignored by us and thrown away. Bits are "shifted in" |
| 3355 | * by raising the input to the Management Data Clock (setting the MDC bit), |
| 3356 | * and then reading the value of the MDIO bit. |
| 3357 | */ |
| 3358 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3359 | |
| 3360 | /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */ |
| 3361 | ctrl &= ~E1000_CTRL_MDIO_DIR; |
| 3362 | ctrl &= ~E1000_CTRL_MDIO; |
| 3363 | |
| 3364 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 3365 | E1000_WRITE_FLUSH(hw); |
| 3366 | |
| 3367 | /* Raise and Lower the clock before reading in the data. This accounts for |
| 3368 | * the turnaround bits. The first clock occurred when we clocked out the |
| 3369 | * last bit of the Register Address. |
| 3370 | */ |
| 3371 | e1000_raise_mdi_clk(hw, &ctrl); |
| 3372 | e1000_lower_mdi_clk(hw, &ctrl); |
| 3373 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3374 | for (data = 0, i = 0; i < 16; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | data = data << 1; |
| 3376 | e1000_raise_mdi_clk(hw, &ctrl); |
| 3377 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3378 | /* Check to see if we shifted in a "1". */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3379 | if (ctrl & E1000_CTRL_MDIO) |
| 3380 | data |= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | e1000_lower_mdi_clk(hw, &ctrl); |
| 3382 | } |
| 3383 | |
| 3384 | e1000_raise_mdi_clk(hw, &ctrl); |
| 3385 | e1000_lower_mdi_clk(hw, &ctrl); |
| 3386 | |
| 3387 | return data; |
| 3388 | } |
| 3389 | |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 3390 | static int32_t |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3391 | e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask) |
| 3392 | { |
| 3393 | uint32_t swfw_sync = 0; |
| 3394 | uint32_t swmask = mask; |
| 3395 | uint32_t fwmask = mask << 16; |
| 3396 | int32_t timeout = 200; |
| 3397 | |
| 3398 | DEBUGFUNC("e1000_swfw_sync_acquire"); |
| 3399 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3400 | if (hw->swfwhw_semaphore_present) |
| 3401 | return e1000_get_software_flag(hw); |
| 3402 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3403 | if (!hw->swfw_sync_present) |
| 3404 | return e1000_get_hw_eeprom_semaphore(hw); |
| 3405 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3406 | while (timeout) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3407 | if (e1000_get_hw_eeprom_semaphore(hw)) |
| 3408 | return -E1000_ERR_SWFW_SYNC; |
| 3409 | |
| 3410 | swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC); |
| 3411 | if (!(swfw_sync & (fwmask | swmask))) { |
| 3412 | break; |
| 3413 | } |
| 3414 | |
| 3415 | /* firmware currently using resource (fwmask) */ |
| 3416 | /* or other software thread currently using resource (swmask) */ |
| 3417 | e1000_put_hw_eeprom_semaphore(hw); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 3418 | mdelay(5); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3419 | timeout--; |
| 3420 | } |
| 3421 | |
| 3422 | if (!timeout) { |
| 3423 | DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n"); |
| 3424 | return -E1000_ERR_SWFW_SYNC; |
| 3425 | } |
| 3426 | |
| 3427 | swfw_sync |= swmask; |
| 3428 | E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync); |
| 3429 | |
| 3430 | e1000_put_hw_eeprom_semaphore(hw); |
| 3431 | return E1000_SUCCESS; |
| 3432 | } |
| 3433 | |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 3434 | static void |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3435 | e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask) |
| 3436 | { |
| 3437 | uint32_t swfw_sync; |
| 3438 | uint32_t swmask = mask; |
| 3439 | |
| 3440 | DEBUGFUNC("e1000_swfw_sync_release"); |
| 3441 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3442 | if (hw->swfwhw_semaphore_present) { |
| 3443 | e1000_release_software_flag(hw); |
| 3444 | return; |
| 3445 | } |
| 3446 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3447 | if (!hw->swfw_sync_present) { |
| 3448 | e1000_put_hw_eeprom_semaphore(hw); |
| 3449 | return; |
| 3450 | } |
| 3451 | |
| 3452 | /* if (e1000_get_hw_eeprom_semaphore(hw)) |
| 3453 | * return -E1000_ERR_SWFW_SYNC; */ |
| 3454 | while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS); |
| 3455 | /* empty */ |
| 3456 | |
| 3457 | swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC); |
| 3458 | swfw_sync &= ~swmask; |
| 3459 | E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync); |
| 3460 | |
| 3461 | e1000_put_hw_eeprom_semaphore(hw); |
| 3462 | } |
| 3463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | /***************************************************************************** |
| 3465 | * Reads the value from a PHY register, if the value is on a specific non zero |
| 3466 | * page, sets the page first. |
| 3467 | * hw - Struct containing variables accessed by shared code |
| 3468 | * reg_addr - address of the PHY register to read |
| 3469 | ******************************************************************************/ |
| 3470 | int32_t |
| 3471 | e1000_read_phy_reg(struct e1000_hw *hw, |
| 3472 | uint32_t reg_addr, |
| 3473 | uint16_t *phy_data) |
| 3474 | { |
| 3475 | uint32_t ret_val; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3476 | uint16_t swfw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | |
| 3478 | DEBUGFUNC("e1000_read_phy_reg"); |
| 3479 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3480 | if ((hw->mac_type == e1000_80003es2lan) && |
| 3481 | (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) { |
| 3482 | swfw = E1000_SWFW_PHY1_SM; |
| 3483 | } else { |
| 3484 | swfw = E1000_SWFW_PHY0_SM; |
| 3485 | } |
| 3486 | if (e1000_swfw_sync_acquire(hw, swfw)) |
| 3487 | return -E1000_ERR_SWFW_SYNC; |
| 3488 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3489 | if ((hw->phy_type == e1000_phy_igp || |
| 3490 | hw->phy_type == e1000_phy_igp_3 || |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3491 | hw->phy_type == e1000_phy_igp_2) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3492 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { |
| 3493 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 3494 | (uint16_t)reg_addr); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3495 | if (ret_val) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3496 | e1000_swfw_sync_release(hw, swfw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | return ret_val; |
| 3498 | } |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3499 | } else if (hw->phy_type == e1000_phy_gg82563) { |
| 3500 | if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) || |
| 3501 | (hw->mac_type == e1000_80003es2lan)) { |
| 3502 | /* Select Configuration Page */ |
| 3503 | if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) { |
| 3504 | ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT, |
| 3505 | (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT)); |
| 3506 | } else { |
| 3507 | /* Use Alternative Page Select register to access |
| 3508 | * registers 30 and 31 |
| 3509 | */ |
| 3510 | ret_val = e1000_write_phy_reg_ex(hw, |
| 3511 | GG82563_PHY_PAGE_SELECT_ALT, |
| 3512 | (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT)); |
| 3513 | } |
| 3514 | |
| 3515 | if (ret_val) { |
| 3516 | e1000_swfw_sync_release(hw, swfw); |
| 3517 | return ret_val; |
| 3518 | } |
| 3519 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, |
| 3523 | phy_data); |
| 3524 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3525 | e1000_swfw_sync_release(hw, swfw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | return ret_val; |
| 3527 | } |
| 3528 | |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 3529 | static int32_t |
| 3530 | e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | uint16_t *phy_data) |
| 3532 | { |
| 3533 | uint32_t i; |
| 3534 | uint32_t mdic = 0; |
| 3535 | const uint32_t phy_addr = 1; |
| 3536 | |
| 3537 | DEBUGFUNC("e1000_read_phy_reg_ex"); |
| 3538 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3539 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | DEBUGOUT1("PHY Address %d is out of range\n", reg_addr); |
| 3541 | return -E1000_ERR_PARAM; |
| 3542 | } |
| 3543 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3544 | if (hw->mac_type > e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3545 | /* Set up Op-code, Phy Address, and register address in the MDI |
| 3546 | * Control register. The MAC will take care of interfacing with the |
| 3547 | * PHY to retrieve the desired data. |
| 3548 | */ |
| 3549 | mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) | |
| 3550 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 3551 | (E1000_MDIC_OP_READ)); |
| 3552 | |
| 3553 | E1000_WRITE_REG(hw, MDIC, mdic); |
| 3554 | |
| 3555 | /* Poll the ready bit to see if the MDI read completed */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3556 | for (i = 0; i < 64; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | udelay(50); |
| 3558 | mdic = E1000_READ_REG(hw, MDIC); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3559 | if (mdic & E1000_MDIC_READY) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3560 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3561 | if (!(mdic & E1000_MDIC_READY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | DEBUGOUT("MDI Read did not complete\n"); |
| 3563 | return -E1000_ERR_PHY; |
| 3564 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3565 | if (mdic & E1000_MDIC_ERROR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | DEBUGOUT("MDI Error\n"); |
| 3567 | return -E1000_ERR_PHY; |
| 3568 | } |
| 3569 | *phy_data = (uint16_t) mdic; |
| 3570 | } else { |
| 3571 | /* We must first send a preamble through the MDIO pin to signal the |
| 3572 | * beginning of an MII instruction. This is done by sending 32 |
| 3573 | * consecutive "1" bits. |
| 3574 | */ |
| 3575 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
| 3576 | |
| 3577 | /* Now combine the next few fields that are required for a read |
| 3578 | * operation. We use this method instead of calling the |
| 3579 | * e1000_shift_out_mdi_bits routine five different times. The format of |
| 3580 | * a MII read instruction consists of a shift out of 14 bits and is |
| 3581 | * defined as follows: |
| 3582 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr> |
| 3583 | * followed by a shift in of 18 bits. This first two bits shifted in |
| 3584 | * are TurnAround bits used to avoid contention on the MDIO pin when a |
| 3585 | * READ operation is performed. These two bits are thrown away |
| 3586 | * followed by a shift in of 16 bits which contains the desired data. |
| 3587 | */ |
| 3588 | mdic = ((reg_addr) | (phy_addr << 5) | |
| 3589 | (PHY_OP_READ << 10) | (PHY_SOF << 12)); |
| 3590 | |
| 3591 | e1000_shift_out_mdi_bits(hw, mdic, 14); |
| 3592 | |
| 3593 | /* Now that we've shifted out the read command to the MII, we need to |
| 3594 | * "shift in" the 16-bit value (18 total bits) of the requested PHY |
| 3595 | * register address. |
| 3596 | */ |
| 3597 | *phy_data = e1000_shift_in_mdi_bits(hw); |
| 3598 | } |
| 3599 | return E1000_SUCCESS; |
| 3600 | } |
| 3601 | |
| 3602 | /****************************************************************************** |
| 3603 | * Writes a value to a PHY register |
| 3604 | * |
| 3605 | * hw - Struct containing variables accessed by shared code |
| 3606 | * reg_addr - address of the PHY register to write |
| 3607 | * data - data to write to the PHY |
| 3608 | ******************************************************************************/ |
| 3609 | int32_t |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 3610 | e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | uint16_t phy_data) |
| 3612 | { |
| 3613 | uint32_t ret_val; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3614 | uint16_t swfw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3615 | |
| 3616 | DEBUGFUNC("e1000_write_phy_reg"); |
| 3617 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3618 | if ((hw->mac_type == e1000_80003es2lan) && |
| 3619 | (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) { |
| 3620 | swfw = E1000_SWFW_PHY1_SM; |
| 3621 | } else { |
| 3622 | swfw = E1000_SWFW_PHY0_SM; |
| 3623 | } |
| 3624 | if (e1000_swfw_sync_acquire(hw, swfw)) |
| 3625 | return -E1000_ERR_SWFW_SYNC; |
| 3626 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3627 | if ((hw->phy_type == e1000_phy_igp || |
| 3628 | hw->phy_type == e1000_phy_igp_3 || |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3629 | hw->phy_type == e1000_phy_igp_2) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { |
| 3631 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 3632 | (uint16_t)reg_addr); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3633 | if (ret_val) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3634 | e1000_swfw_sync_release(hw, swfw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | return ret_val; |
| 3636 | } |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3637 | } else if (hw->phy_type == e1000_phy_gg82563) { |
| 3638 | if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) || |
| 3639 | (hw->mac_type == e1000_80003es2lan)) { |
| 3640 | /* Select Configuration Page */ |
| 3641 | if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) { |
| 3642 | ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT, |
| 3643 | (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT)); |
| 3644 | } else { |
| 3645 | /* Use Alternative Page Select register to access |
| 3646 | * registers 30 and 31 |
| 3647 | */ |
| 3648 | ret_val = e1000_write_phy_reg_ex(hw, |
| 3649 | GG82563_PHY_PAGE_SELECT_ALT, |
| 3650 | (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT)); |
| 3651 | } |
| 3652 | |
| 3653 | if (ret_val) { |
| 3654 | e1000_swfw_sync_release(hw, swfw); |
| 3655 | return ret_val; |
| 3656 | } |
| 3657 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, |
| 3661 | phy_data); |
| 3662 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3663 | e1000_swfw_sync_release(hw, swfw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | return ret_val; |
| 3665 | } |
| 3666 | |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 3667 | static int32_t |
| 3668 | e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr, |
| 3669 | uint16_t phy_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3670 | { |
| 3671 | uint32_t i; |
| 3672 | uint32_t mdic = 0; |
| 3673 | const uint32_t phy_addr = 1; |
| 3674 | |
| 3675 | DEBUGFUNC("e1000_write_phy_reg_ex"); |
| 3676 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3677 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | DEBUGOUT1("PHY Address %d is out of range\n", reg_addr); |
| 3679 | return -E1000_ERR_PARAM; |
| 3680 | } |
| 3681 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3682 | if (hw->mac_type > e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | /* Set up Op-code, Phy Address, register address, and data intended |
| 3684 | * for the PHY register in the MDI Control register. The MAC will take |
| 3685 | * care of interfacing with the PHY to send the desired data. |
| 3686 | */ |
| 3687 | mdic = (((uint32_t) phy_data) | |
| 3688 | (reg_addr << E1000_MDIC_REG_SHIFT) | |
| 3689 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 3690 | (E1000_MDIC_OP_WRITE)); |
| 3691 | |
| 3692 | E1000_WRITE_REG(hw, MDIC, mdic); |
| 3693 | |
| 3694 | /* Poll the ready bit to see if the MDI read completed */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3695 | for (i = 0; i < 641; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | udelay(5); |
| 3697 | mdic = E1000_READ_REG(hw, MDIC); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3698 | if (mdic & E1000_MDIC_READY) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3699 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3700 | if (!(mdic & E1000_MDIC_READY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | DEBUGOUT("MDI Write did not complete\n"); |
| 3702 | return -E1000_ERR_PHY; |
| 3703 | } |
| 3704 | } else { |
| 3705 | /* We'll need to use the SW defined pins to shift the write command |
| 3706 | * out to the PHY. We first send a preamble to the PHY to signal the |
| 3707 | * beginning of the MII instruction. This is done by sending 32 |
| 3708 | * consecutive "1" bits. |
| 3709 | */ |
| 3710 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
| 3711 | |
| 3712 | /* Now combine the remaining required fields that will indicate a |
| 3713 | * write operation. We use this method instead of calling the |
| 3714 | * e1000_shift_out_mdi_bits routine for each field in the command. The |
| 3715 | * format of a MII write instruction is as follows: |
| 3716 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>. |
| 3717 | */ |
| 3718 | mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) | |
| 3719 | (PHY_OP_WRITE << 12) | (PHY_SOF << 14)); |
| 3720 | mdic <<= 16; |
| 3721 | mdic |= (uint32_t) phy_data; |
| 3722 | |
| 3723 | e1000_shift_out_mdi_bits(hw, mdic, 32); |
| 3724 | } |
| 3725 | |
| 3726 | return E1000_SUCCESS; |
| 3727 | } |
| 3728 | |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 3729 | static int32_t |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3730 | e1000_read_kmrn_reg(struct e1000_hw *hw, |
| 3731 | uint32_t reg_addr, |
| 3732 | uint16_t *data) |
| 3733 | { |
| 3734 | uint32_t reg_val; |
| 3735 | uint16_t swfw; |
| 3736 | DEBUGFUNC("e1000_read_kmrn_reg"); |
| 3737 | |
| 3738 | if ((hw->mac_type == e1000_80003es2lan) && |
| 3739 | (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) { |
| 3740 | swfw = E1000_SWFW_PHY1_SM; |
| 3741 | } else { |
| 3742 | swfw = E1000_SWFW_PHY0_SM; |
| 3743 | } |
| 3744 | if (e1000_swfw_sync_acquire(hw, swfw)) |
| 3745 | return -E1000_ERR_SWFW_SYNC; |
| 3746 | |
| 3747 | /* Write register address */ |
| 3748 | reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) & |
| 3749 | E1000_KUMCTRLSTA_OFFSET) | |
| 3750 | E1000_KUMCTRLSTA_REN; |
| 3751 | E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val); |
| 3752 | udelay(2); |
| 3753 | |
| 3754 | /* Read the data returned */ |
| 3755 | reg_val = E1000_READ_REG(hw, KUMCTRLSTA); |
| 3756 | *data = (uint16_t)reg_val; |
| 3757 | |
| 3758 | e1000_swfw_sync_release(hw, swfw); |
| 3759 | return E1000_SUCCESS; |
| 3760 | } |
| 3761 | |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 3762 | static int32_t |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3763 | e1000_write_kmrn_reg(struct e1000_hw *hw, |
| 3764 | uint32_t reg_addr, |
| 3765 | uint16_t data) |
| 3766 | { |
| 3767 | uint32_t reg_val; |
| 3768 | uint16_t swfw; |
| 3769 | DEBUGFUNC("e1000_write_kmrn_reg"); |
| 3770 | |
| 3771 | if ((hw->mac_type == e1000_80003es2lan) && |
| 3772 | (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) { |
| 3773 | swfw = E1000_SWFW_PHY1_SM; |
| 3774 | } else { |
| 3775 | swfw = E1000_SWFW_PHY0_SM; |
| 3776 | } |
| 3777 | if (e1000_swfw_sync_acquire(hw, swfw)) |
| 3778 | return -E1000_ERR_SWFW_SYNC; |
| 3779 | |
| 3780 | reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) & |
| 3781 | E1000_KUMCTRLSTA_OFFSET) | data; |
| 3782 | E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val); |
| 3783 | udelay(2); |
| 3784 | |
| 3785 | e1000_swfw_sync_release(hw, swfw); |
| 3786 | return E1000_SUCCESS; |
| 3787 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | /****************************************************************************** |
| 3790 | * Returns the PHY to the power-on reset state |
| 3791 | * |
| 3792 | * hw - Struct containing variables accessed by shared code |
| 3793 | ******************************************************************************/ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3794 | int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | e1000_phy_hw_reset(struct e1000_hw *hw) |
| 3796 | { |
| 3797 | uint32_t ctrl, ctrl_ext; |
| 3798 | uint32_t led_ctrl; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3799 | int32_t ret_val; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3800 | uint16_t swfw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3801 | |
| 3802 | DEBUGFUNC("e1000_phy_hw_reset"); |
| 3803 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3804 | /* In the case of the phy reset being blocked, it's not an error, we |
| 3805 | * simply return success without performing the reset. */ |
| 3806 | ret_val = e1000_check_phy_reset_block(hw); |
| 3807 | if (ret_val) |
| 3808 | return E1000_SUCCESS; |
| 3809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | DEBUGOUT("Resetting Phy...\n"); |
| 3811 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3812 | if (hw->mac_type > e1000_82543) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3813 | if ((hw->mac_type == e1000_80003es2lan) && |
| 3814 | (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) { |
| 3815 | swfw = E1000_SWFW_PHY1_SM; |
| 3816 | } else { |
| 3817 | swfw = E1000_SWFW_PHY0_SM; |
| 3818 | } |
| 3819 | if (e1000_swfw_sync_acquire(hw, swfw)) { |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3820 | DEBUGOUT("Unable to acquire swfw sync\n"); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3821 | return -E1000_ERR_SWFW_SYNC; |
| 3822 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | /* Read the device control register and assert the E1000_CTRL_PHY_RST |
| 3824 | * bit. Then, take it out of reset. |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3825 | * For pre-e1000_82571 hardware, we delay for 10ms between the assert |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3826 | * and deassert. For e1000_82571 hardware and later, we instead delay |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 3827 | * for 50us between and 10ms after the deassertion. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | */ |
| 3829 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3830 | E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST); |
| 3831 | E1000_WRITE_FLUSH(hw); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3832 | |
| 3833 | if (hw->mac_type < e1000_82571) |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 3834 | msleep(10); |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 3835 | else |
| 3836 | udelay(100); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 3839 | E1000_WRITE_FLUSH(hw); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3840 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3841 | if (hw->mac_type >= e1000_82571) |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 3842 | mdelay(10); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 3843 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3844 | e1000_swfw_sync_release(hw, swfw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | } else { |
| 3846 | /* Read the Extended Device Control Register, assert the PHY_RESET_DIR |
| 3847 | * bit to put the PHY into reset. Then, take it out of reset. |
| 3848 | */ |
| 3849 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 3850 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR; |
| 3851 | ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA; |
| 3852 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 3853 | E1000_WRITE_FLUSH(hw); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 3854 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA; |
| 3856 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 3857 | E1000_WRITE_FLUSH(hw); |
| 3858 | } |
| 3859 | udelay(150); |
| 3860 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3861 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3862 | /* Configure activity LED after PHY reset */ |
| 3863 | led_ctrl = E1000_READ_REG(hw, LEDCTL); |
| 3864 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 3865 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 3866 | E1000_WRITE_REG(hw, LEDCTL, led_ctrl); |
| 3867 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3868 | |
| 3869 | /* Wait for FW to finish PHY configuration. */ |
| 3870 | ret_val = e1000_get_phy_cfg_done(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3871 | if (ret_val != E1000_SUCCESS) |
| 3872 | return ret_val; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3873 | e1000_release_software_semaphore(hw); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3874 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3875 | if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3)) |
| 3876 | ret_val = e1000_init_lcd_from_nvm(hw); |
| 3877 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3878 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3879 | } |
| 3880 | |
| 3881 | /****************************************************************************** |
| 3882 | * Resets the PHY |
| 3883 | * |
| 3884 | * hw - Struct containing variables accessed by shared code |
| 3885 | * |
Matt LaPlante | 0779bf2 | 2006-11-30 05:24:39 +0100 | [diff] [blame] | 3886 | * Sets bit 15 of the MII Control register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3887 | ******************************************************************************/ |
| 3888 | int32_t |
| 3889 | e1000_phy_reset(struct e1000_hw *hw) |
| 3890 | { |
| 3891 | int32_t ret_val; |
| 3892 | uint16_t phy_data; |
| 3893 | |
| 3894 | DEBUGFUNC("e1000_phy_reset"); |
| 3895 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3896 | /* In the case of the phy reset being blocked, it's not an error, we |
| 3897 | * simply return success without performing the reset. */ |
| 3898 | ret_val = e1000_check_phy_reset_block(hw); |
| 3899 | if (ret_val) |
| 3900 | return E1000_SUCCESS; |
| 3901 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3902 | switch (hw->phy_type) { |
| 3903 | case e1000_phy_igp: |
| 3904 | case e1000_phy_igp_2: |
| 3905 | case e1000_phy_igp_3: |
| 3906 | case e1000_phy_ife: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3907 | ret_val = e1000_phy_hw_reset(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3908 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3909 | return ret_val; |
| 3910 | break; |
| 3911 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3913 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3914 | return ret_val; |
| 3915 | |
| 3916 | phy_data |= MII_CR_RESET; |
| 3917 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3918 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3919 | return ret_val; |
| 3920 | |
| 3921 | udelay(1); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3922 | break; |
| 3923 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3925 | if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | e1000_phy_init_script(hw); |
| 3927 | |
| 3928 | return E1000_SUCCESS; |
| 3929 | } |
| 3930 | |
| 3931 | /****************************************************************************** |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3932 | * Work-around for 82566 power-down: on D3 entry- |
| 3933 | * 1) disable gigabit link |
| 3934 | * 2) write VR power-down enable |
| 3935 | * 3) read it back |
| 3936 | * if successful continue, else issue LCD reset and repeat |
| 3937 | * |
| 3938 | * hw - struct containing variables accessed by shared code |
| 3939 | ******************************************************************************/ |
| 3940 | void |
| 3941 | e1000_phy_powerdown_workaround(struct e1000_hw *hw) |
| 3942 | { |
| 3943 | int32_t reg; |
| 3944 | uint16_t phy_data; |
| 3945 | int32_t retry = 0; |
| 3946 | |
| 3947 | DEBUGFUNC("e1000_phy_powerdown_workaround"); |
| 3948 | |
| 3949 | if (hw->phy_type != e1000_phy_igp_3) |
| 3950 | return; |
| 3951 | |
| 3952 | do { |
| 3953 | /* Disable link */ |
| 3954 | reg = E1000_READ_REG(hw, PHY_CTRL); |
| 3955 | E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE | |
| 3956 | E1000_PHY_CTRL_NOND0A_GBE_DISABLE); |
| 3957 | |
Jeff Kirsher | 070f6ff | 2006-11-01 08:47:44 -0800 | [diff] [blame] | 3958 | /* Write VR power-down enable - bits 9:8 should be 10b */ |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3959 | e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data); |
Jeff Kirsher | 070f6ff | 2006-11-01 08:47:44 -0800 | [diff] [blame] | 3960 | phy_data |= (1 << 9); |
| 3961 | phy_data &= ~(1 << 8); |
| 3962 | e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3963 | |
| 3964 | /* Read it back and test */ |
| 3965 | e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data); |
Jeff Kirsher | 070f6ff | 2006-11-01 08:47:44 -0800 | [diff] [blame] | 3966 | if (((phy_data & IGP3_VR_CTRL_MODE_MASK) == IGP3_VR_CTRL_MODE_SHUT) || retry) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3967 | break; |
| 3968 | |
| 3969 | /* Issue PHY reset and repeat at most one more time */ |
| 3970 | reg = E1000_READ_REG(hw, CTRL); |
| 3971 | E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST); |
| 3972 | retry++; |
| 3973 | } while (retry); |
| 3974 | |
| 3975 | return; |
| 3976 | |
| 3977 | } |
| 3978 | |
| 3979 | /****************************************************************************** |
| 3980 | * Work-around for 82566 Kumeran PCS lock loss: |
| 3981 | * On link status change (i.e. PCI reset, speed change) and link is up and |
| 3982 | * speed is gigabit- |
| 3983 | * 0) if workaround is optionally disabled do nothing |
| 3984 | * 1) wait 1ms for Kumeran link to come up |
| 3985 | * 2) check Kumeran Diagnostic register PCS lock loss bit |
| 3986 | * 3) if not set the link is locked (all is good), otherwise... |
| 3987 | * 4) reset the PHY |
| 3988 | * 5) repeat up to 10 times |
| 3989 | * Note: this is only called for IGP3 copper when speed is 1gb. |
| 3990 | * |
| 3991 | * hw - struct containing variables accessed by shared code |
| 3992 | ******************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 3993 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3994 | e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw) |
| 3995 | { |
| 3996 | int32_t ret_val; |
| 3997 | int32_t reg; |
| 3998 | int32_t cnt; |
| 3999 | uint16_t phy_data; |
| 4000 | |
| 4001 | if (hw->kmrn_lock_loss_workaround_disabled) |
| 4002 | return E1000_SUCCESS; |
| 4003 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4004 | /* Make sure link is up before proceeding. If not just return. |
| 4005 | * Attempting this while link is negotiating fouled up link |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 4006 | * stability */ |
| 4007 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 4008 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 4009 | |
| 4010 | if (phy_data & MII_SR_LINK_STATUS) { |
| 4011 | for (cnt = 0; cnt < 10; cnt++) { |
| 4012 | /* read once to clear */ |
| 4013 | ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data); |
| 4014 | if (ret_val) |
| 4015 | return ret_val; |
| 4016 | /* and again to get new status */ |
| 4017 | ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data); |
| 4018 | if (ret_val) |
| 4019 | return ret_val; |
| 4020 | |
| 4021 | /* check for PCS lock */ |
| 4022 | if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS)) |
| 4023 | return E1000_SUCCESS; |
| 4024 | |
| 4025 | /* Issue PHY reset */ |
| 4026 | e1000_phy_hw_reset(hw); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 4027 | mdelay(5); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 4028 | } |
| 4029 | /* Disable GigE link negotiation */ |
| 4030 | reg = E1000_READ_REG(hw, PHY_CTRL); |
| 4031 | E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE | |
| 4032 | E1000_PHY_CTRL_NOND0A_GBE_DISABLE); |
| 4033 | |
| 4034 | /* unable to acquire PCS lock */ |
| 4035 | return E1000_ERR_PHY; |
| 4036 | } |
| 4037 | |
| 4038 | return E1000_SUCCESS; |
| 4039 | } |
| 4040 | |
| 4041 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | * Probes the expected PHY address for known PHY IDs |
| 4043 | * |
| 4044 | * hw - Struct containing variables accessed by shared code |
| 4045 | ******************************************************************************/ |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 4046 | static int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | e1000_detect_gig_phy(struct e1000_hw *hw) |
| 4048 | { |
| 4049 | int32_t phy_init_status, ret_val; |
| 4050 | uint16_t phy_id_high, phy_id_low; |
| 4051 | boolean_t match = FALSE; |
| 4052 | |
| 4053 | DEBUGFUNC("e1000_detect_gig_phy"); |
| 4054 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4055 | if (hw->phy_id != 0) |
| 4056 | return E1000_SUCCESS; |
| 4057 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4058 | /* The 82571 firmware may still be configuring the PHY. In this |
| 4059 | * case, we cannot access the PHY until the configuration is done. So |
| 4060 | * we explicitly set the PHY values. */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4061 | if (hw->mac_type == e1000_82571 || |
| 4062 | hw->mac_type == e1000_82572) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4063 | hw->phy_id = IGP01E1000_I_PHY_ID; |
| 4064 | hw->phy_type = e1000_phy_igp_2; |
| 4065 | return E1000_SUCCESS; |
| 4066 | } |
| 4067 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4068 | /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work- |
| 4069 | * around that forces PHY page 0 to be set or the reads fail. The rest of |
| 4070 | * the code in this routine uses e1000_read_phy_reg to read the PHY ID. |
| 4071 | * So for ESB-2 we need to have this set so our reads won't fail. If the |
| 4072 | * attached PHY is not a e1000_phy_gg82563, the routines below will figure |
| 4073 | * this out as well. */ |
| 4074 | if (hw->mac_type == e1000_80003es2lan) |
| 4075 | hw->phy_type = e1000_phy_gg82563; |
| 4076 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | /* Read the PHY ID Registers to identify which PHY is onboard. */ |
| 4078 | ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4079 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | return ret_val; |
| 4081 | |
| 4082 | hw->phy_id = (uint32_t) (phy_id_high << 16); |
| 4083 | udelay(20); |
| 4084 | ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4085 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4086 | return ret_val; |
| 4087 | |
| 4088 | hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK); |
| 4089 | hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK; |
| 4090 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4091 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4092 | case e1000_82543: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4093 | if (hw->phy_id == M88E1000_E_PHY_ID) match = TRUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | break; |
| 4095 | case e1000_82544: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4096 | if (hw->phy_id == M88E1000_I_PHY_ID) match = TRUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | break; |
| 4098 | case e1000_82540: |
| 4099 | case e1000_82545: |
| 4100 | case e1000_82545_rev_3: |
| 4101 | case e1000_82546: |
| 4102 | case e1000_82546_rev_3: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4103 | if (hw->phy_id == M88E1011_I_PHY_ID) match = TRUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | break; |
| 4105 | case e1000_82541: |
| 4106 | case e1000_82541_rev_2: |
| 4107 | case e1000_82547: |
| 4108 | case e1000_82547_rev_2: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4109 | if (hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4110 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4111 | case e1000_82573: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4112 | if (hw->phy_id == M88E1111_I_PHY_ID) match = TRUE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4113 | break; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4114 | case e1000_80003es2lan: |
| 4115 | if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE; |
| 4116 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4117 | case e1000_ich8lan: |
| 4118 | if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE; |
| 4119 | if (hw->phy_id == IFE_E_PHY_ID) match = TRUE; |
| 4120 | if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE; |
| 4121 | if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE; |
| 4122 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | default: |
| 4124 | DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type); |
| 4125 | return -E1000_ERR_CONFIG; |
| 4126 | } |
| 4127 | phy_init_status = e1000_set_phy_type(hw); |
| 4128 | |
| 4129 | if ((match) && (phy_init_status == E1000_SUCCESS)) { |
| 4130 | DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id); |
| 4131 | return E1000_SUCCESS; |
| 4132 | } |
| 4133 | DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id); |
| 4134 | return -E1000_ERR_PHY; |
| 4135 | } |
| 4136 | |
| 4137 | /****************************************************************************** |
| 4138 | * Resets the PHY's DSP |
| 4139 | * |
| 4140 | * hw - Struct containing variables accessed by shared code |
| 4141 | ******************************************************************************/ |
| 4142 | static int32_t |
| 4143 | e1000_phy_reset_dsp(struct e1000_hw *hw) |
| 4144 | { |
| 4145 | int32_t ret_val; |
| 4146 | DEBUGFUNC("e1000_phy_reset_dsp"); |
| 4147 | |
| 4148 | do { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4149 | if (hw->phy_type != e1000_phy_gg82563) { |
| 4150 | ret_val = e1000_write_phy_reg(hw, 29, 0x001d); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4151 | if (ret_val) break; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4152 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | ret_val = e1000_write_phy_reg(hw, 30, 0x00c1); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4154 | if (ret_val) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | ret_val = e1000_write_phy_reg(hw, 30, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4156 | if (ret_val) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | ret_val = E1000_SUCCESS; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4158 | } while (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | |
| 4160 | return ret_val; |
| 4161 | } |
| 4162 | |
| 4163 | /****************************************************************************** |
| 4164 | * Get PHY information from various PHY registers for igp PHY only. |
| 4165 | * |
| 4166 | * hw - Struct containing variables accessed by shared code |
| 4167 | * phy_info - PHY information structure |
| 4168 | ******************************************************************************/ |
Adrian Bunk | cff93eb | 2006-09-04 13:41:14 +0200 | [diff] [blame] | 4169 | static int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | e1000_phy_igp_get_info(struct e1000_hw *hw, |
| 4171 | struct e1000_phy_info *phy_info) |
| 4172 | { |
| 4173 | int32_t ret_val; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4174 | uint16_t phy_data, min_length, max_length, average; |
| 4175 | e1000_rev_polarity polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4176 | |
| 4177 | DEBUGFUNC("e1000_phy_igp_get_info"); |
| 4178 | |
| 4179 | /* The downshift status is checked only once, after link is established, |
| 4180 | * and it stored in the hw->speed_downgraded parameter. */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4181 | phy_info->downshift = (e1000_downshift)hw->speed_downgraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4182 | |
| 4183 | /* IGP01E1000 does not need to support it. */ |
| 4184 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal; |
| 4185 | |
| 4186 | /* IGP01E1000 always correct polarity reversal */ |
| 4187 | phy_info->polarity_correction = e1000_polarity_reversal_enabled; |
| 4188 | |
| 4189 | /* Check polarity status */ |
| 4190 | ret_val = e1000_check_polarity(hw, &polarity); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4191 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | return ret_val; |
| 4193 | |
| 4194 | phy_info->cable_polarity = polarity; |
| 4195 | |
| 4196 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4197 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4198 | return ret_val; |
| 4199 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4200 | phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >> |
| 4201 | IGP01E1000_PSSR_MDIX_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4203 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
| 4205 | /* Local/Remote Receiver Information are only valid at 1000 Mbps */ |
| 4206 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4207 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | return ret_val; |
| 4209 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4210 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> |
| 4211 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? |
| 4212 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
| 4213 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> |
| 4214 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? |
| 4215 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4216 | |
| 4217 | /* Get cable length */ |
| 4218 | ret_val = e1000_get_cable_length(hw, &min_length, &max_length); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4219 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | return ret_val; |
| 4221 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4222 | /* Translate to old method */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 | average = (max_length + min_length) / 2; |
| 4224 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4225 | if (average <= e1000_igp_cable_length_50) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | phy_info->cable_length = e1000_cable_length_50; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4227 | else if (average <= e1000_igp_cable_length_80) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | phy_info->cable_length = e1000_cable_length_50_80; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4229 | else if (average <= e1000_igp_cable_length_110) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4230 | phy_info->cable_length = e1000_cable_length_80_110; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4231 | else if (average <= e1000_igp_cable_length_140) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | phy_info->cable_length = e1000_cable_length_110_140; |
| 4233 | else |
| 4234 | phy_info->cable_length = e1000_cable_length_140; |
| 4235 | } |
| 4236 | |
| 4237 | return E1000_SUCCESS; |
| 4238 | } |
| 4239 | |
| 4240 | /****************************************************************************** |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 4241 | * Get PHY information from various PHY registers for ife PHY only. |
| 4242 | * |
| 4243 | * hw - Struct containing variables accessed by shared code |
| 4244 | * phy_info - PHY information structure |
| 4245 | ******************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 4246 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 4247 | e1000_phy_ife_get_info(struct e1000_hw *hw, |
| 4248 | struct e1000_phy_info *phy_info) |
| 4249 | { |
| 4250 | int32_t ret_val; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4251 | uint16_t phy_data; |
| 4252 | e1000_rev_polarity polarity; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 4253 | |
| 4254 | DEBUGFUNC("e1000_phy_ife_get_info"); |
| 4255 | |
| 4256 | phy_info->downshift = (e1000_downshift)hw->speed_downgraded; |
| 4257 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal; |
| 4258 | |
| 4259 | ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data); |
| 4260 | if (ret_val) |
| 4261 | return ret_val; |
| 4262 | phy_info->polarity_correction = |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4263 | ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >> |
| 4264 | IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ? |
| 4265 | e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 4266 | |
| 4267 | if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) { |
| 4268 | ret_val = e1000_check_polarity(hw, &polarity); |
| 4269 | if (ret_val) |
| 4270 | return ret_val; |
| 4271 | } else { |
| 4272 | /* Polarity is forced. */ |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4273 | polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >> |
| 4274 | IFE_PSC_FORCE_POLARITY_SHIFT) ? |
| 4275 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 4276 | } |
| 4277 | phy_info->cable_polarity = polarity; |
| 4278 | |
| 4279 | ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data); |
| 4280 | if (ret_val) |
| 4281 | return ret_val; |
| 4282 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4283 | phy_info->mdix_mode = (e1000_auto_x_mode) |
| 4284 | ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >> |
| 4285 | IFE_PMC_MDIX_MODE_SHIFT); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 4286 | |
| 4287 | return E1000_SUCCESS; |
| 4288 | } |
| 4289 | |
| 4290 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | * Get PHY information from various PHY registers fot m88 PHY only. |
| 4292 | * |
| 4293 | * hw - Struct containing variables accessed by shared code |
| 4294 | * phy_info - PHY information structure |
| 4295 | ******************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 4296 | static int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | e1000_phy_m88_get_info(struct e1000_hw *hw, |
| 4298 | struct e1000_phy_info *phy_info) |
| 4299 | { |
| 4300 | int32_t ret_val; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4301 | uint16_t phy_data; |
| 4302 | e1000_rev_polarity polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | |
| 4304 | DEBUGFUNC("e1000_phy_m88_get_info"); |
| 4305 | |
| 4306 | /* The downshift status is checked only once, after link is established, |
| 4307 | * and it stored in the hw->speed_downgraded parameter. */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4308 | phy_info->downshift = (e1000_downshift)hw->speed_downgraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | |
| 4310 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4311 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | return ret_val; |
| 4313 | |
| 4314 | phy_info->extended_10bt_distance = |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4315 | ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >> |
| 4316 | M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ? |
| 4317 | e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal; |
| 4318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4319 | phy_info->polarity_correction = |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4320 | ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >> |
| 4321 | M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ? |
| 4322 | e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | |
| 4324 | /* Check polarity status */ |
| 4325 | ret_val = e1000_check_polarity(hw, &polarity); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4326 | if (ret_val) |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 4327 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | phy_info->cable_polarity = polarity; |
| 4329 | |
| 4330 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4331 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4332 | return ret_val; |
| 4333 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4334 | phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >> |
| 4335 | M88E1000_PSSR_MDIX_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | |
| 4337 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) { |
| 4338 | /* Cable Length Estimation and Local/Remote Receiver Information |
| 4339 | * are only valid at 1000 Mbps. |
| 4340 | */ |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4341 | if (hw->phy_type != e1000_phy_gg82563) { |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4342 | phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >> |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4343 | M88E1000_PSSR_CABLE_LENGTH_SHIFT); |
| 4344 | } else { |
| 4345 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE, |
| 4346 | &phy_data); |
| 4347 | if (ret_val) |
| 4348 | return ret_val; |
| 4349 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4350 | phy_info->cable_length = (e1000_cable_length)(phy_data & GG82563_DSPD_CABLE_LENGTH); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4351 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4352 | |
| 4353 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4354 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | return ret_val; |
| 4356 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4357 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> |
| 4358 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? |
| 4359 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
| 4360 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> |
| 4361 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? |
| 4362 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | } |
| 4365 | |
| 4366 | return E1000_SUCCESS; |
| 4367 | } |
| 4368 | |
| 4369 | /****************************************************************************** |
| 4370 | * Get PHY information from various PHY registers |
| 4371 | * |
| 4372 | * hw - Struct containing variables accessed by shared code |
| 4373 | * phy_info - PHY information structure |
| 4374 | ******************************************************************************/ |
| 4375 | int32_t |
| 4376 | e1000_phy_get_info(struct e1000_hw *hw, |
| 4377 | struct e1000_phy_info *phy_info) |
| 4378 | { |
| 4379 | int32_t ret_val; |
| 4380 | uint16_t phy_data; |
| 4381 | |
| 4382 | DEBUGFUNC("e1000_phy_get_info"); |
| 4383 | |
| 4384 | phy_info->cable_length = e1000_cable_length_undefined; |
| 4385 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined; |
| 4386 | phy_info->cable_polarity = e1000_rev_polarity_undefined; |
| 4387 | phy_info->downshift = e1000_downshift_undefined; |
| 4388 | phy_info->polarity_correction = e1000_polarity_reversal_undefined; |
| 4389 | phy_info->mdix_mode = e1000_auto_x_mode_undefined; |
| 4390 | phy_info->local_rx = e1000_1000t_rx_status_undefined; |
| 4391 | phy_info->remote_rx = e1000_1000t_rx_status_undefined; |
| 4392 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4393 | if (hw->media_type != e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4394 | DEBUGOUT("PHY info is only valid for copper media\n"); |
| 4395 | return -E1000_ERR_CONFIG; |
| 4396 | } |
| 4397 | |
| 4398 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4399 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | return ret_val; |
| 4401 | |
| 4402 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4403 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4404 | return ret_val; |
| 4405 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4406 | if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4407 | DEBUGOUT("PHY info is only valid if link is up\n"); |
| 4408 | return -E1000_ERR_CONFIG; |
| 4409 | } |
| 4410 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4411 | if (hw->phy_type == e1000_phy_igp || |
| 4412 | hw->phy_type == e1000_phy_igp_3 || |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4413 | hw->phy_type == e1000_phy_igp_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4414 | return e1000_phy_igp_get_info(hw, phy_info); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4415 | else if (hw->phy_type == e1000_phy_ife) |
| 4416 | return e1000_phy_ife_get_info(hw, phy_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 | else |
| 4418 | return e1000_phy_m88_get_info(hw, phy_info); |
| 4419 | } |
| 4420 | |
| 4421 | int32_t |
| 4422 | e1000_validate_mdi_setting(struct e1000_hw *hw) |
| 4423 | { |
| 4424 | DEBUGFUNC("e1000_validate_mdi_settings"); |
| 4425 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4426 | if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | DEBUGOUT("Invalid MDI setting detected\n"); |
| 4428 | hw->mdix = 1; |
| 4429 | return -E1000_ERR_CONFIG; |
| 4430 | } |
| 4431 | return E1000_SUCCESS; |
| 4432 | } |
| 4433 | |
| 4434 | |
| 4435 | /****************************************************************************** |
| 4436 | * Sets up eeprom variables in the hw struct. Must be called after mac_type |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 4437 | * is configured. Additionally, if this is ICH8, the flash controller GbE |
| 4438 | * registers must be mapped, or this will crash. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | * |
| 4440 | * hw - Struct containing variables accessed by shared code |
| 4441 | *****************************************************************************/ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4442 | int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4443 | e1000_init_eeprom_params(struct e1000_hw *hw) |
| 4444 | { |
| 4445 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 4446 | uint32_t eecd = E1000_READ_REG(hw, EECD); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4447 | int32_t ret_val = E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | uint16_t eeprom_size; |
| 4449 | |
| 4450 | DEBUGFUNC("e1000_init_eeprom_params"); |
| 4451 | |
| 4452 | switch (hw->mac_type) { |
| 4453 | case e1000_82542_rev2_0: |
| 4454 | case e1000_82542_rev2_1: |
| 4455 | case e1000_82543: |
| 4456 | case e1000_82544: |
| 4457 | eeprom->type = e1000_eeprom_microwire; |
| 4458 | eeprom->word_size = 64; |
| 4459 | eeprom->opcode_bits = 3; |
| 4460 | eeprom->address_bits = 6; |
| 4461 | eeprom->delay_usec = 50; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4462 | eeprom->use_eerd = FALSE; |
| 4463 | eeprom->use_eewr = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | break; |
| 4465 | case e1000_82540: |
| 4466 | case e1000_82545: |
| 4467 | case e1000_82545_rev_3: |
| 4468 | case e1000_82546: |
| 4469 | case e1000_82546_rev_3: |
| 4470 | eeprom->type = e1000_eeprom_microwire; |
| 4471 | eeprom->opcode_bits = 3; |
| 4472 | eeprom->delay_usec = 50; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4473 | if (eecd & E1000_EECD_SIZE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | eeprom->word_size = 256; |
| 4475 | eeprom->address_bits = 8; |
| 4476 | } else { |
| 4477 | eeprom->word_size = 64; |
| 4478 | eeprom->address_bits = 6; |
| 4479 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4480 | eeprom->use_eerd = FALSE; |
| 4481 | eeprom->use_eewr = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | break; |
| 4483 | case e1000_82541: |
| 4484 | case e1000_82541_rev_2: |
| 4485 | case e1000_82547: |
| 4486 | case e1000_82547_rev_2: |
| 4487 | if (eecd & E1000_EECD_TYPE) { |
| 4488 | eeprom->type = e1000_eeprom_spi; |
| 4489 | eeprom->opcode_bits = 8; |
| 4490 | eeprom->delay_usec = 1; |
| 4491 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 4492 | eeprom->page_size = 32; |
| 4493 | eeprom->address_bits = 16; |
| 4494 | } else { |
| 4495 | eeprom->page_size = 8; |
| 4496 | eeprom->address_bits = 8; |
| 4497 | } |
| 4498 | } else { |
| 4499 | eeprom->type = e1000_eeprom_microwire; |
| 4500 | eeprom->opcode_bits = 3; |
| 4501 | eeprom->delay_usec = 50; |
| 4502 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 4503 | eeprom->word_size = 256; |
| 4504 | eeprom->address_bits = 8; |
| 4505 | } else { |
| 4506 | eeprom->word_size = 64; |
| 4507 | eeprom->address_bits = 6; |
| 4508 | } |
| 4509 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4510 | eeprom->use_eerd = FALSE; |
| 4511 | eeprom->use_eewr = FALSE; |
| 4512 | break; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4513 | case e1000_82571: |
| 4514 | case e1000_82572: |
| 4515 | eeprom->type = e1000_eeprom_spi; |
| 4516 | eeprom->opcode_bits = 8; |
| 4517 | eeprom->delay_usec = 1; |
| 4518 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 4519 | eeprom->page_size = 32; |
| 4520 | eeprom->address_bits = 16; |
| 4521 | } else { |
| 4522 | eeprom->page_size = 8; |
| 4523 | eeprom->address_bits = 8; |
| 4524 | } |
| 4525 | eeprom->use_eerd = FALSE; |
| 4526 | eeprom->use_eewr = FALSE; |
| 4527 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4528 | case e1000_82573: |
| 4529 | eeprom->type = e1000_eeprom_spi; |
| 4530 | eeprom->opcode_bits = 8; |
| 4531 | eeprom->delay_usec = 1; |
| 4532 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 4533 | eeprom->page_size = 32; |
| 4534 | eeprom->address_bits = 16; |
| 4535 | } else { |
| 4536 | eeprom->page_size = 8; |
| 4537 | eeprom->address_bits = 8; |
| 4538 | } |
| 4539 | eeprom->use_eerd = TRUE; |
| 4540 | eeprom->use_eewr = TRUE; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4541 | if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4542 | eeprom->type = e1000_eeprom_flash; |
| 4543 | eeprom->word_size = 2048; |
| 4544 | |
| 4545 | /* Ensure that the Autonomous FLASH update bit is cleared due to |
| 4546 | * Flash update issue on parts which use a FLASH for NVM. */ |
| 4547 | eecd &= ~E1000_EECD_AUPDEN; |
| 4548 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4550 | break; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4551 | case e1000_80003es2lan: |
| 4552 | eeprom->type = e1000_eeprom_spi; |
| 4553 | eeprom->opcode_bits = 8; |
| 4554 | eeprom->delay_usec = 1; |
| 4555 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 4556 | eeprom->page_size = 32; |
| 4557 | eeprom->address_bits = 16; |
| 4558 | } else { |
| 4559 | eeprom->page_size = 8; |
| 4560 | eeprom->address_bits = 8; |
| 4561 | } |
| 4562 | eeprom->use_eerd = TRUE; |
| 4563 | eeprom->use_eewr = FALSE; |
| 4564 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4565 | case e1000_ich8lan: |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 4566 | { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4567 | int32_t i = 0; |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 4568 | uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_GFPREG); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4569 | |
| 4570 | eeprom->type = e1000_eeprom_ich8; |
| 4571 | eeprom->use_eerd = FALSE; |
| 4572 | eeprom->use_eewr = FALSE; |
| 4573 | eeprom->word_size = E1000_SHADOW_RAM_WORDS; |
| 4574 | |
| 4575 | /* Zero the shadow RAM structure. But don't load it from NVM |
| 4576 | * so as to save time for driver init */ |
| 4577 | if (hw->eeprom_shadow_ram != NULL) { |
| 4578 | for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) { |
| 4579 | hw->eeprom_shadow_ram[i].modified = FALSE; |
| 4580 | hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF; |
| 4581 | } |
| 4582 | } |
| 4583 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 4584 | hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) * |
| 4585 | ICH_FLASH_SECTOR_SIZE; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4586 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 4587 | hw->flash_bank_size = ((flash_size >> 16) & ICH_GFPREG_BASE_MASK) + 1; |
| 4588 | hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK); |
| 4589 | |
| 4590 | hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE; |
| 4591 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4592 | hw->flash_bank_size /= 2 * sizeof(uint16_t); |
| 4593 | |
| 4594 | break; |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 4595 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | default: |
| 4597 | break; |
| 4598 | } |
| 4599 | |
| 4600 | if (eeprom->type == e1000_eeprom_spi) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4601 | /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to |
| 4602 | * 32KB (incremented by powers of 2). |
| 4603 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4604 | if (hw->mac_type <= e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4605 | /* Set to default value for initial eeprom read. */ |
| 4606 | eeprom->word_size = 64; |
| 4607 | ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4608 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4609 | return ret_val; |
| 4610 | eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT; |
| 4611 | /* 256B eeprom size was not supported in earlier hardware, so we |
| 4612 | * bump eeprom_size up one to ensure that "1" (which maps to 256B) |
| 4613 | * is never the result used in the shifting logic below. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4614 | if (eeprom_size) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4615 | eeprom_size++; |
| 4616 | } else { |
| 4617 | eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >> |
| 4618 | E1000_EECD_SIZE_EX_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4619 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4620 | |
| 4621 | eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4622 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4623 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | /****************************************************************************** |
| 4627 | * Raises the EEPROM's clock input. |
| 4628 | * |
| 4629 | * hw - Struct containing variables accessed by shared code |
| 4630 | * eecd - EECD's current value |
| 4631 | *****************************************************************************/ |
| 4632 | static void |
| 4633 | e1000_raise_ee_clk(struct e1000_hw *hw, |
| 4634 | uint32_t *eecd) |
| 4635 | { |
| 4636 | /* Raise the clock input to the EEPROM (by setting the SK bit), and then |
| 4637 | * wait <delay> microseconds. |
| 4638 | */ |
| 4639 | *eecd = *eecd | E1000_EECD_SK; |
| 4640 | E1000_WRITE_REG(hw, EECD, *eecd); |
| 4641 | E1000_WRITE_FLUSH(hw); |
| 4642 | udelay(hw->eeprom.delay_usec); |
| 4643 | } |
| 4644 | |
| 4645 | /****************************************************************************** |
| 4646 | * Lowers the EEPROM's clock input. |
| 4647 | * |
| 4648 | * hw - Struct containing variables accessed by shared code |
| 4649 | * eecd - EECD's current value |
| 4650 | *****************************************************************************/ |
| 4651 | static void |
| 4652 | e1000_lower_ee_clk(struct e1000_hw *hw, |
| 4653 | uint32_t *eecd) |
| 4654 | { |
| 4655 | /* Lower the clock input to the EEPROM (by clearing the SK bit), and then |
| 4656 | * wait 50 microseconds. |
| 4657 | */ |
| 4658 | *eecd = *eecd & ~E1000_EECD_SK; |
| 4659 | E1000_WRITE_REG(hw, EECD, *eecd); |
| 4660 | E1000_WRITE_FLUSH(hw); |
| 4661 | udelay(hw->eeprom.delay_usec); |
| 4662 | } |
| 4663 | |
| 4664 | /****************************************************************************** |
| 4665 | * Shift data bits out to the EEPROM. |
| 4666 | * |
| 4667 | * hw - Struct containing variables accessed by shared code |
| 4668 | * data - data to send to the EEPROM |
| 4669 | * count - number of bits to shift out |
| 4670 | *****************************************************************************/ |
| 4671 | static void |
| 4672 | e1000_shift_out_ee_bits(struct e1000_hw *hw, |
| 4673 | uint16_t data, |
| 4674 | uint16_t count) |
| 4675 | { |
| 4676 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 4677 | uint32_t eecd; |
| 4678 | uint32_t mask; |
| 4679 | |
| 4680 | /* We need to shift "count" bits out to the EEPROM. So, value in the |
| 4681 | * "data" parameter will be shifted out to the EEPROM one bit at a time. |
| 4682 | * In order to do this, "data" must be broken down into bits. |
| 4683 | */ |
| 4684 | mask = 0x01 << (count - 1); |
| 4685 | eecd = E1000_READ_REG(hw, EECD); |
| 4686 | if (eeprom->type == e1000_eeprom_microwire) { |
| 4687 | eecd &= ~E1000_EECD_DO; |
| 4688 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 4689 | eecd |= E1000_EECD_DO; |
| 4690 | } |
| 4691 | do { |
| 4692 | /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1", |
| 4693 | * and then raising and then lowering the clock (the SK bit controls |
| 4694 | * the clock input to the EEPROM). A "0" is shifted out to the EEPROM |
| 4695 | * by setting "DI" to "0" and then raising and then lowering the clock. |
| 4696 | */ |
| 4697 | eecd &= ~E1000_EECD_DI; |
| 4698 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4699 | if (data & mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | eecd |= E1000_EECD_DI; |
| 4701 | |
| 4702 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4703 | E1000_WRITE_FLUSH(hw); |
| 4704 | |
| 4705 | udelay(eeprom->delay_usec); |
| 4706 | |
| 4707 | e1000_raise_ee_clk(hw, &eecd); |
| 4708 | e1000_lower_ee_clk(hw, &eecd); |
| 4709 | |
| 4710 | mask = mask >> 1; |
| 4711 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4712 | } while (mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4713 | |
| 4714 | /* We leave the "DI" bit set to "0" when we leave this routine. */ |
| 4715 | eecd &= ~E1000_EECD_DI; |
| 4716 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4717 | } |
| 4718 | |
| 4719 | /****************************************************************************** |
| 4720 | * Shift data bits in from the EEPROM |
| 4721 | * |
| 4722 | * hw - Struct containing variables accessed by shared code |
| 4723 | *****************************************************************************/ |
| 4724 | static uint16_t |
| 4725 | e1000_shift_in_ee_bits(struct e1000_hw *hw, |
| 4726 | uint16_t count) |
| 4727 | { |
| 4728 | uint32_t eecd; |
| 4729 | uint32_t i; |
| 4730 | uint16_t data; |
| 4731 | |
| 4732 | /* In order to read a register from the EEPROM, we need to shift 'count' |
| 4733 | * bits in from the EEPROM. Bits are "shifted in" by raising the clock |
| 4734 | * input to the EEPROM (setting the SK bit), and then reading the value of |
| 4735 | * the "DO" bit. During this "shifting in" process the "DI" bit should |
| 4736 | * always be clear. |
| 4737 | */ |
| 4738 | |
| 4739 | eecd = E1000_READ_REG(hw, EECD); |
| 4740 | |
| 4741 | eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); |
| 4742 | data = 0; |
| 4743 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4744 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4745 | data = data << 1; |
| 4746 | e1000_raise_ee_clk(hw, &eecd); |
| 4747 | |
| 4748 | eecd = E1000_READ_REG(hw, EECD); |
| 4749 | |
| 4750 | eecd &= ~(E1000_EECD_DI); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4751 | if (eecd & E1000_EECD_DO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4752 | data |= 1; |
| 4753 | |
| 4754 | e1000_lower_ee_clk(hw, &eecd); |
| 4755 | } |
| 4756 | |
| 4757 | return data; |
| 4758 | } |
| 4759 | |
| 4760 | /****************************************************************************** |
| 4761 | * Prepares EEPROM for access |
| 4762 | * |
| 4763 | * hw - Struct containing variables accessed by shared code |
| 4764 | * |
| 4765 | * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This |
| 4766 | * function should be called before issuing a command to the EEPROM. |
| 4767 | *****************************************************************************/ |
| 4768 | static int32_t |
| 4769 | e1000_acquire_eeprom(struct e1000_hw *hw) |
| 4770 | { |
| 4771 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 4772 | uint32_t eecd, i=0; |
| 4773 | |
| 4774 | DEBUGFUNC("e1000_acquire_eeprom"); |
| 4775 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4776 | if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM)) |
| 4777 | return -E1000_ERR_SWFW_SYNC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4778 | eecd = E1000_READ_REG(hw, EECD); |
| 4779 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4780 | if (hw->mac_type != e1000_82573) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4781 | /* Request EEPROM Access */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4782 | if (hw->mac_type > e1000_82544) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4783 | eecd |= E1000_EECD_REQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4784 | E1000_WRITE_REG(hw, EECD, eecd); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4785 | eecd = E1000_READ_REG(hw, EECD); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4786 | while ((!(eecd & E1000_EECD_GNT)) && |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4787 | (i < E1000_EEPROM_GRANT_ATTEMPTS)) { |
| 4788 | i++; |
| 4789 | udelay(5); |
| 4790 | eecd = E1000_READ_REG(hw, EECD); |
| 4791 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4792 | if (!(eecd & E1000_EECD_GNT)) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4793 | eecd &= ~E1000_EECD_REQ; |
| 4794 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4795 | DEBUGOUT("Could not acquire EEPROM grant\n"); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4796 | e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4797 | return -E1000_ERR_EEPROM; |
| 4798 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4799 | } |
| 4800 | } |
| 4801 | |
| 4802 | /* Setup EEPROM for Read/Write */ |
| 4803 | |
| 4804 | if (eeprom->type == e1000_eeprom_microwire) { |
| 4805 | /* Clear SK and DI */ |
| 4806 | eecd &= ~(E1000_EECD_DI | E1000_EECD_SK); |
| 4807 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4808 | |
| 4809 | /* Set CS */ |
| 4810 | eecd |= E1000_EECD_CS; |
| 4811 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4812 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 4813 | /* Clear SK and CS */ |
| 4814 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
| 4815 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4816 | udelay(1); |
| 4817 | } |
| 4818 | |
| 4819 | return E1000_SUCCESS; |
| 4820 | } |
| 4821 | |
| 4822 | /****************************************************************************** |
| 4823 | * Returns EEPROM to a "standby" state |
| 4824 | * |
| 4825 | * hw - Struct containing variables accessed by shared code |
| 4826 | *****************************************************************************/ |
| 4827 | static void |
| 4828 | e1000_standby_eeprom(struct e1000_hw *hw) |
| 4829 | { |
| 4830 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 4831 | uint32_t eecd; |
| 4832 | |
| 4833 | eecd = E1000_READ_REG(hw, EECD); |
| 4834 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4835 | if (eeprom->type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
| 4837 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4838 | E1000_WRITE_FLUSH(hw); |
| 4839 | udelay(eeprom->delay_usec); |
| 4840 | |
| 4841 | /* Clock high */ |
| 4842 | eecd |= E1000_EECD_SK; |
| 4843 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4844 | E1000_WRITE_FLUSH(hw); |
| 4845 | udelay(eeprom->delay_usec); |
| 4846 | |
| 4847 | /* Select EEPROM */ |
| 4848 | eecd |= E1000_EECD_CS; |
| 4849 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4850 | E1000_WRITE_FLUSH(hw); |
| 4851 | udelay(eeprom->delay_usec); |
| 4852 | |
| 4853 | /* Clock low */ |
| 4854 | eecd &= ~E1000_EECD_SK; |
| 4855 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4856 | E1000_WRITE_FLUSH(hw); |
| 4857 | udelay(eeprom->delay_usec); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4858 | } else if (eeprom->type == e1000_eeprom_spi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | /* Toggle CS to flush commands */ |
| 4860 | eecd |= E1000_EECD_CS; |
| 4861 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4862 | E1000_WRITE_FLUSH(hw); |
| 4863 | udelay(eeprom->delay_usec); |
| 4864 | eecd &= ~E1000_EECD_CS; |
| 4865 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4866 | E1000_WRITE_FLUSH(hw); |
| 4867 | udelay(eeprom->delay_usec); |
| 4868 | } |
| 4869 | } |
| 4870 | |
| 4871 | /****************************************************************************** |
| 4872 | * Terminates a command by inverting the EEPROM's chip select pin |
| 4873 | * |
| 4874 | * hw - Struct containing variables accessed by shared code |
| 4875 | *****************************************************************************/ |
| 4876 | static void |
| 4877 | e1000_release_eeprom(struct e1000_hw *hw) |
| 4878 | { |
| 4879 | uint32_t eecd; |
| 4880 | |
| 4881 | DEBUGFUNC("e1000_release_eeprom"); |
| 4882 | |
| 4883 | eecd = E1000_READ_REG(hw, EECD); |
| 4884 | |
| 4885 | if (hw->eeprom.type == e1000_eeprom_spi) { |
| 4886 | eecd |= E1000_EECD_CS; /* Pull CS high */ |
| 4887 | eecd &= ~E1000_EECD_SK; /* Lower SCK */ |
| 4888 | |
| 4889 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4890 | |
| 4891 | udelay(hw->eeprom.delay_usec); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4892 | } else if (hw->eeprom.type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4893 | /* cleanup eeprom */ |
| 4894 | |
| 4895 | /* CS on Microwire is active-high */ |
| 4896 | eecd &= ~(E1000_EECD_CS | E1000_EECD_DI); |
| 4897 | |
| 4898 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4899 | |
| 4900 | /* Rising edge of clock */ |
| 4901 | eecd |= E1000_EECD_SK; |
| 4902 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4903 | E1000_WRITE_FLUSH(hw); |
| 4904 | udelay(hw->eeprom.delay_usec); |
| 4905 | |
| 4906 | /* Falling edge of clock */ |
| 4907 | eecd &= ~E1000_EECD_SK; |
| 4908 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4909 | E1000_WRITE_FLUSH(hw); |
| 4910 | udelay(hw->eeprom.delay_usec); |
| 4911 | } |
| 4912 | |
| 4913 | /* Stop requesting EEPROM access */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4914 | if (hw->mac_type > e1000_82544) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | eecd &= ~E1000_EECD_REQ; |
| 4916 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4917 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4918 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4919 | e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | } |
| 4921 | |
| 4922 | /****************************************************************************** |
| 4923 | * Reads a 16 bit word from the EEPROM. |
| 4924 | * |
| 4925 | * hw - Struct containing variables accessed by shared code |
| 4926 | *****************************************************************************/ |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 4927 | static int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4928 | e1000_spi_eeprom_ready(struct e1000_hw *hw) |
| 4929 | { |
| 4930 | uint16_t retry_count = 0; |
| 4931 | uint8_t spi_stat_reg; |
| 4932 | |
| 4933 | DEBUGFUNC("e1000_spi_eeprom_ready"); |
| 4934 | |
| 4935 | /* Read "Status Register" repeatedly until the LSB is cleared. The |
| 4936 | * EEPROM will signal that the command has been completed by clearing |
| 4937 | * bit 0 of the internal status register. If it's not cleared within |
| 4938 | * 5 milliseconds, then error out. |
| 4939 | */ |
| 4940 | retry_count = 0; |
| 4941 | do { |
| 4942 | e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI, |
| 4943 | hw->eeprom.opcode_bits); |
| 4944 | spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8); |
| 4945 | if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI)) |
| 4946 | break; |
| 4947 | |
| 4948 | udelay(5); |
| 4949 | retry_count += 5; |
| 4950 | |
| 4951 | e1000_standby_eeprom(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4952 | } while (retry_count < EEPROM_MAX_RETRY_SPI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4953 | |
| 4954 | /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and |
| 4955 | * only 0-5mSec on 5V devices) |
| 4956 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4957 | if (retry_count >= EEPROM_MAX_RETRY_SPI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4958 | DEBUGOUT("SPI EEPROM Status error\n"); |
| 4959 | return -E1000_ERR_EEPROM; |
| 4960 | } |
| 4961 | |
| 4962 | return E1000_SUCCESS; |
| 4963 | } |
| 4964 | |
| 4965 | /****************************************************************************** |
| 4966 | * Reads a 16 bit word from the EEPROM. |
| 4967 | * |
| 4968 | * hw - Struct containing variables accessed by shared code |
| 4969 | * offset - offset of word in the EEPROM to read |
| 4970 | * data - word read from the EEPROM |
| 4971 | * words - number of words to read |
| 4972 | *****************************************************************************/ |
| 4973 | int32_t |
| 4974 | e1000_read_eeprom(struct e1000_hw *hw, |
| 4975 | uint16_t offset, |
| 4976 | uint16_t words, |
| 4977 | uint16_t *data) |
| 4978 | { |
| 4979 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 4980 | uint32_t i = 0; |
| 4981 | |
| 4982 | DEBUGFUNC("e1000_read_eeprom"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4983 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4984 | /* If eeprom is not yet detected, do so now */ |
| 4985 | if (eeprom->word_size == 0) |
| 4986 | e1000_init_eeprom_params(hw); |
| 4987 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4988 | /* A check for invalid values: offset too large, too many words, and not |
| 4989 | * enough words. |
| 4990 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4991 | if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | (words == 0)) { |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4993 | DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4994 | return -E1000_ERR_EEPROM; |
| 4995 | } |
| 4996 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4997 | /* EEPROM's that don't use EERD to read require us to bit-bang the SPI |
| 4998 | * directly. In this case, we need to acquire the EEPROM so that |
| 4999 | * FW or other port software does not interrupt. |
| 5000 | */ |
Jeff Kirsher | 4d351858 | 2006-01-12 16:50:48 -0800 | [diff] [blame] | 5001 | if (e1000_is_onboard_nvm_eeprom(hw) == TRUE && |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5002 | hw->eeprom.use_eerd == FALSE) { |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5003 | /* Prepare the EEPROM for bit-bang reading */ |
| 5004 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) |
| 5005 | return -E1000_ERR_EEPROM; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5006 | } |
| 5007 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5008 | /* Eerd register EEPROM access requires no eeprom aquire/release */ |
| 5009 | if (eeprom->use_eerd == TRUE) |
| 5010 | return e1000_read_eeprom_eerd(hw, offset, words, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5011 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5012 | /* ICH EEPROM access is done via the ICH flash controller */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5013 | if (eeprom->type == e1000_eeprom_ich8) |
| 5014 | return e1000_read_eeprom_ich8(hw, offset, words, data); |
| 5015 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5016 | /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have |
| 5017 | * acquired the EEPROM at this point, so any returns should relase it */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5018 | if (eeprom->type == e1000_eeprom_spi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5019 | uint16_t word_in; |
| 5020 | uint8_t read_opcode = EEPROM_READ_OPCODE_SPI; |
| 5021 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5022 | if (e1000_spi_eeprom_ready(hw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | e1000_release_eeprom(hw); |
| 5024 | return -E1000_ERR_EEPROM; |
| 5025 | } |
| 5026 | |
| 5027 | e1000_standby_eeprom(hw); |
| 5028 | |
| 5029 | /* Some SPI eeproms use the 8th address bit embedded in the opcode */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5030 | if ((eeprom->address_bits == 8) && (offset >= 128)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | read_opcode |= EEPROM_A8_OPCODE_SPI; |
| 5032 | |
| 5033 | /* Send the READ command (opcode + addr) */ |
| 5034 | e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits); |
| 5035 | e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits); |
| 5036 | |
| 5037 | /* Read the data. The address of the eeprom internally increments with |
| 5038 | * each byte (spi) being read, saving on the overhead of eeprom setup |
| 5039 | * and tear-down. The address counter will roll over if reading beyond |
| 5040 | * the size of the eeprom, thus allowing the entire memory to be read |
| 5041 | * starting from any offset. */ |
| 5042 | for (i = 0; i < words; i++) { |
| 5043 | word_in = e1000_shift_in_ee_bits(hw, 16); |
| 5044 | data[i] = (word_in >> 8) | (word_in << 8); |
| 5045 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5046 | } else if (eeprom->type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5047 | for (i = 0; i < words; i++) { |
| 5048 | /* Send the READ command (opcode + addr) */ |
| 5049 | e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE, |
| 5050 | eeprom->opcode_bits); |
| 5051 | e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i), |
| 5052 | eeprom->address_bits); |
| 5053 | |
| 5054 | /* Read the data. For microwire, each word requires the overhead |
| 5055 | * of eeprom setup and tear-down. */ |
| 5056 | data[i] = e1000_shift_in_ee_bits(hw, 16); |
| 5057 | e1000_standby_eeprom(hw); |
| 5058 | } |
| 5059 | } |
| 5060 | |
| 5061 | /* End this read operation */ |
| 5062 | e1000_release_eeprom(hw); |
| 5063 | |
| 5064 | return E1000_SUCCESS; |
| 5065 | } |
| 5066 | |
| 5067 | /****************************************************************************** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5068 | * Reads a 16 bit word from the EEPROM using the EERD register. |
| 5069 | * |
| 5070 | * hw - Struct containing variables accessed by shared code |
| 5071 | * offset - offset of word in the EEPROM to read |
| 5072 | * data - word read from the EEPROM |
| 5073 | * words - number of words to read |
| 5074 | *****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 5075 | static int32_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5076 | e1000_read_eeprom_eerd(struct e1000_hw *hw, |
| 5077 | uint16_t offset, |
| 5078 | uint16_t words, |
| 5079 | uint16_t *data) |
| 5080 | { |
| 5081 | uint32_t i, eerd = 0; |
| 5082 | int32_t error = 0; |
| 5083 | |
| 5084 | for (i = 0; i < words; i++) { |
| 5085 | eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) + |
| 5086 | E1000_EEPROM_RW_REG_START; |
| 5087 | |
| 5088 | E1000_WRITE_REG(hw, EERD, eerd); |
| 5089 | error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5090 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5091 | if (error) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5092 | break; |
| 5093 | } |
| 5094 | data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5095 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5096 | } |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5097 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5098 | return error; |
| 5099 | } |
| 5100 | |
| 5101 | /****************************************************************************** |
| 5102 | * Writes a 16 bit word from the EEPROM using the EEWR register. |
| 5103 | * |
| 5104 | * hw - Struct containing variables accessed by shared code |
| 5105 | * offset - offset of word in the EEPROM to read |
| 5106 | * data - word read from the EEPROM |
| 5107 | * words - number of words to read |
| 5108 | *****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 5109 | static int32_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5110 | e1000_write_eeprom_eewr(struct e1000_hw *hw, |
| 5111 | uint16_t offset, |
| 5112 | uint16_t words, |
| 5113 | uint16_t *data) |
| 5114 | { |
| 5115 | uint32_t register_value = 0; |
| 5116 | uint32_t i = 0; |
| 5117 | int32_t error = 0; |
| 5118 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 5119 | if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM)) |
| 5120 | return -E1000_ERR_SWFW_SYNC; |
| 5121 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5122 | for (i = 0; i < words; i++) { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5123 | register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) | |
| 5124 | ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5125 | E1000_EEPROM_RW_REG_START; |
| 5126 | |
| 5127 | error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5128 | if (error) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5129 | break; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5130 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5131 | |
| 5132 | E1000_WRITE_REG(hw, EEWR, register_value); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5133 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5134 | error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5135 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5136 | if (error) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5137 | break; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5138 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5139 | } |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5140 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 5141 | e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5142 | return error; |
| 5143 | } |
| 5144 | |
| 5145 | /****************************************************************************** |
| 5146 | * Polls the status bit (bit 1) of the EERD to determine when the read is done. |
| 5147 | * |
| 5148 | * hw - Struct containing variables accessed by shared code |
| 5149 | *****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 5150 | static int32_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5151 | e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd) |
| 5152 | { |
| 5153 | uint32_t attempts = 100000; |
| 5154 | uint32_t i, reg = 0; |
| 5155 | int32_t done = E1000_ERR_EEPROM; |
| 5156 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5157 | for (i = 0; i < attempts; i++) { |
| 5158 | if (eerd == E1000_EEPROM_POLL_READ) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5159 | reg = E1000_READ_REG(hw, EERD); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5160 | else |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5161 | reg = E1000_READ_REG(hw, EEWR); |
| 5162 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5163 | if (reg & E1000_EEPROM_RW_REG_DONE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5164 | done = E1000_SUCCESS; |
| 5165 | break; |
| 5166 | } |
| 5167 | udelay(5); |
| 5168 | } |
| 5169 | |
| 5170 | return done; |
| 5171 | } |
| 5172 | |
| 5173 | /*************************************************************************** |
| 5174 | * Description: Determines if the onboard NVM is FLASH or EEPROM. |
| 5175 | * |
| 5176 | * hw - Struct containing variables accessed by shared code |
| 5177 | ****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 5178 | static boolean_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5179 | e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw) |
| 5180 | { |
| 5181 | uint32_t eecd = 0; |
| 5182 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 5183 | DEBUGFUNC("e1000_is_onboard_nvm_eeprom"); |
| 5184 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5185 | if (hw->mac_type == e1000_ich8lan) |
| 5186 | return FALSE; |
| 5187 | |
| 5188 | if (hw->mac_type == e1000_82573) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5189 | eecd = E1000_READ_REG(hw, EECD); |
| 5190 | |
| 5191 | /* Isolate bits 15 & 16 */ |
| 5192 | eecd = ((eecd >> 15) & 0x03); |
| 5193 | |
| 5194 | /* If both bits are set, device is Flash type */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5195 | if (eecd == 0x03) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5196 | return FALSE; |
| 5197 | } |
| 5198 | } |
| 5199 | return TRUE; |
| 5200 | } |
| 5201 | |
| 5202 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5203 | * Verifies that the EEPROM has a valid checksum |
| 5204 | * |
| 5205 | * hw - Struct containing variables accessed by shared code |
| 5206 | * |
| 5207 | * Reads the first 64 16 bit words of the EEPROM and sums the values read. |
| 5208 | * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is |
| 5209 | * valid. |
| 5210 | *****************************************************************************/ |
| 5211 | int32_t |
| 5212 | e1000_validate_eeprom_checksum(struct e1000_hw *hw) |
| 5213 | { |
| 5214 | uint16_t checksum = 0; |
| 5215 | uint16_t i, eeprom_data; |
| 5216 | |
| 5217 | DEBUGFUNC("e1000_validate_eeprom_checksum"); |
| 5218 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5219 | if ((hw->mac_type == e1000_82573) && |
| 5220 | (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) { |
| 5221 | /* Check bit 4 of word 10h. If it is 0, firmware is done updating |
| 5222 | * 10h-12h. Checksum may need to be fixed. */ |
| 5223 | e1000_read_eeprom(hw, 0x10, 1, &eeprom_data); |
| 5224 | if ((eeprom_data & 0x10) == 0) { |
| 5225 | /* Read 0x23 and check bit 15. This bit is a 1 when the checksum |
| 5226 | * has already been fixed. If the checksum is still wrong and this |
| 5227 | * bit is a 1, we need to return bad checksum. Otherwise, we need |
| 5228 | * to set this bit to a 1 and update the checksum. */ |
| 5229 | e1000_read_eeprom(hw, 0x23, 1, &eeprom_data); |
| 5230 | if ((eeprom_data & 0x8000) == 0) { |
| 5231 | eeprom_data |= 0x8000; |
| 5232 | e1000_write_eeprom(hw, 0x23, 1, &eeprom_data); |
| 5233 | e1000_update_eeprom_checksum(hw); |
| 5234 | } |
| 5235 | } |
| 5236 | } |
| 5237 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5238 | if (hw->mac_type == e1000_ich8lan) { |
| 5239 | /* Drivers must allocate the shadow ram structure for the |
| 5240 | * EEPROM checksum to be updated. Otherwise, this bit as well |
| 5241 | * as the checksum must both be set correctly for this |
| 5242 | * validation to pass. |
| 5243 | */ |
| 5244 | e1000_read_eeprom(hw, 0x19, 1, &eeprom_data); |
| 5245 | if ((eeprom_data & 0x40) == 0) { |
| 5246 | eeprom_data |= 0x40; |
| 5247 | e1000_write_eeprom(hw, 0x19, 1, &eeprom_data); |
| 5248 | e1000_update_eeprom_checksum(hw); |
| 5249 | } |
| 5250 | } |
| 5251 | |
| 5252 | for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) { |
| 5253 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5254 | DEBUGOUT("EEPROM Read Error\n"); |
| 5255 | return -E1000_ERR_EEPROM; |
| 5256 | } |
| 5257 | checksum += eeprom_data; |
| 5258 | } |
| 5259 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5260 | if (checksum == (uint16_t) EEPROM_SUM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5261 | return E1000_SUCCESS; |
| 5262 | else { |
| 5263 | DEBUGOUT("EEPROM Checksum Invalid\n"); |
| 5264 | return -E1000_ERR_EEPROM; |
| 5265 | } |
| 5266 | } |
| 5267 | |
| 5268 | /****************************************************************************** |
| 5269 | * Calculates the EEPROM checksum and writes it to the EEPROM |
| 5270 | * |
| 5271 | * hw - Struct containing variables accessed by shared code |
| 5272 | * |
| 5273 | * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA. |
| 5274 | * Writes the difference to word offset 63 of the EEPROM. |
| 5275 | *****************************************************************************/ |
| 5276 | int32_t |
| 5277 | e1000_update_eeprom_checksum(struct e1000_hw *hw) |
| 5278 | { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5279 | uint32_t ctrl_ext; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5280 | uint16_t checksum = 0; |
| 5281 | uint16_t i, eeprom_data; |
| 5282 | |
| 5283 | DEBUGFUNC("e1000_update_eeprom_checksum"); |
| 5284 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5285 | for (i = 0; i < EEPROM_CHECKSUM_REG; i++) { |
| 5286 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5287 | DEBUGOUT("EEPROM Read Error\n"); |
| 5288 | return -E1000_ERR_EEPROM; |
| 5289 | } |
| 5290 | checksum += eeprom_data; |
| 5291 | } |
| 5292 | checksum = (uint16_t) EEPROM_SUM - checksum; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5293 | if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5294 | DEBUGOUT("EEPROM Write Error\n"); |
| 5295 | return -E1000_ERR_EEPROM; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5296 | } else if (hw->eeprom.type == e1000_eeprom_flash) { |
| 5297 | e1000_commit_shadow_ram(hw); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5298 | } else if (hw->eeprom.type == e1000_eeprom_ich8) { |
| 5299 | e1000_commit_shadow_ram(hw); |
| 5300 | /* Reload the EEPROM, or else modifications will not appear |
| 5301 | * until after next adapter reset. */ |
| 5302 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 5303 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; |
| 5304 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5305 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5306 | } |
| 5307 | return E1000_SUCCESS; |
| 5308 | } |
| 5309 | |
| 5310 | /****************************************************************************** |
| 5311 | * Parent function for writing words to the different EEPROM types. |
| 5312 | * |
| 5313 | * hw - Struct containing variables accessed by shared code |
| 5314 | * offset - offset within the EEPROM to be written to |
| 5315 | * words - number of words to write |
| 5316 | * data - 16 bit word to be written to the EEPROM |
| 5317 | * |
| 5318 | * If e1000_update_eeprom_checksum is not called after this function, the |
| 5319 | * EEPROM will most likely contain an invalid checksum. |
| 5320 | *****************************************************************************/ |
| 5321 | int32_t |
| 5322 | e1000_write_eeprom(struct e1000_hw *hw, |
| 5323 | uint16_t offset, |
| 5324 | uint16_t words, |
| 5325 | uint16_t *data) |
| 5326 | { |
| 5327 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 5328 | int32_t status = 0; |
| 5329 | |
| 5330 | DEBUGFUNC("e1000_write_eeprom"); |
| 5331 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5332 | /* If eeprom is not yet detected, do so now */ |
| 5333 | if (eeprom->word_size == 0) |
| 5334 | e1000_init_eeprom_params(hw); |
| 5335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5336 | /* A check for invalid values: offset too large, too many words, and not |
| 5337 | * enough words. |
| 5338 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5339 | if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5340 | (words == 0)) { |
| 5341 | DEBUGOUT("\"words\" parameter out of bounds\n"); |
| 5342 | return -E1000_ERR_EEPROM; |
| 5343 | } |
| 5344 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 5345 | /* 82573 writes only through eewr */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5346 | if (eeprom->use_eewr == TRUE) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5347 | return e1000_write_eeprom_eewr(hw, offset, words, data); |
| 5348 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5349 | if (eeprom->type == e1000_eeprom_ich8) |
| 5350 | return e1000_write_eeprom_ich8(hw, offset, words, data); |
| 5351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5352 | /* Prepare the EEPROM for writing */ |
| 5353 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) |
| 5354 | return -E1000_ERR_EEPROM; |
| 5355 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5356 | if (eeprom->type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5357 | status = e1000_write_eeprom_microwire(hw, offset, words, data); |
| 5358 | } else { |
| 5359 | status = e1000_write_eeprom_spi(hw, offset, words, data); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5360 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5361 | } |
| 5362 | |
| 5363 | /* Done with writing */ |
| 5364 | e1000_release_eeprom(hw); |
| 5365 | |
| 5366 | return status; |
| 5367 | } |
| 5368 | |
| 5369 | /****************************************************************************** |
| 5370 | * Writes a 16 bit word to a given offset in an SPI EEPROM. |
| 5371 | * |
| 5372 | * hw - Struct containing variables accessed by shared code |
| 5373 | * offset - offset within the EEPROM to be written to |
| 5374 | * words - number of words to write |
| 5375 | * data - pointer to array of 8 bit words to be written to the EEPROM |
| 5376 | * |
| 5377 | *****************************************************************************/ |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 5378 | static int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5379 | e1000_write_eeprom_spi(struct e1000_hw *hw, |
| 5380 | uint16_t offset, |
| 5381 | uint16_t words, |
| 5382 | uint16_t *data) |
| 5383 | { |
| 5384 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 5385 | uint16_t widx = 0; |
| 5386 | |
| 5387 | DEBUGFUNC("e1000_write_eeprom_spi"); |
| 5388 | |
| 5389 | while (widx < words) { |
| 5390 | uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI; |
| 5391 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5392 | if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5393 | |
| 5394 | e1000_standby_eeprom(hw); |
| 5395 | |
| 5396 | /* Send the WRITE ENABLE command (8 bit opcode ) */ |
| 5397 | e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI, |
| 5398 | eeprom->opcode_bits); |
| 5399 | |
| 5400 | e1000_standby_eeprom(hw); |
| 5401 | |
| 5402 | /* Some SPI eeproms use the 8th address bit embedded in the opcode */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5403 | if ((eeprom->address_bits == 8) && (offset >= 128)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5404 | write_opcode |= EEPROM_A8_OPCODE_SPI; |
| 5405 | |
| 5406 | /* Send the Write command (8-bit opcode + addr) */ |
| 5407 | e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits); |
| 5408 | |
| 5409 | e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2), |
| 5410 | eeprom->address_bits); |
| 5411 | |
| 5412 | /* Send the data */ |
| 5413 | |
| 5414 | /* Loop to allow for up to whole page write (32 bytes) of eeprom */ |
| 5415 | while (widx < words) { |
| 5416 | uint16_t word_out = data[widx]; |
| 5417 | word_out = (word_out >> 8) | (word_out << 8); |
| 5418 | e1000_shift_out_ee_bits(hw, word_out, 16); |
| 5419 | widx++; |
| 5420 | |
| 5421 | /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE |
| 5422 | * operation, while the smaller eeproms are capable of an 8-byte |
| 5423 | * PAGE WRITE operation. Break the inner loop to pass new address |
| 5424 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5425 | if ((((offset + widx)*2) % eeprom->page_size) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5426 | e1000_standby_eeprom(hw); |
| 5427 | break; |
| 5428 | } |
| 5429 | } |
| 5430 | } |
| 5431 | |
| 5432 | return E1000_SUCCESS; |
| 5433 | } |
| 5434 | |
| 5435 | /****************************************************************************** |
| 5436 | * Writes a 16 bit word to a given offset in a Microwire EEPROM. |
| 5437 | * |
| 5438 | * hw - Struct containing variables accessed by shared code |
| 5439 | * offset - offset within the EEPROM to be written to |
| 5440 | * words - number of words to write |
| 5441 | * data - pointer to array of 16 bit words to be written to the EEPROM |
| 5442 | * |
| 5443 | *****************************************************************************/ |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 5444 | static int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5445 | e1000_write_eeprom_microwire(struct e1000_hw *hw, |
| 5446 | uint16_t offset, |
| 5447 | uint16_t words, |
| 5448 | uint16_t *data) |
| 5449 | { |
| 5450 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
| 5451 | uint32_t eecd; |
| 5452 | uint16_t words_written = 0; |
| 5453 | uint16_t i = 0; |
| 5454 | |
| 5455 | DEBUGFUNC("e1000_write_eeprom_microwire"); |
| 5456 | |
| 5457 | /* Send the write enable command to the EEPROM (3-bit opcode plus |
| 5458 | * 6/8-bit dummy address beginning with 11). It's less work to include |
| 5459 | * the 11 of the dummy address as part of the opcode than it is to shift |
| 5460 | * it over the correct number of bits for the address. This puts the |
| 5461 | * EEPROM into write/erase mode. |
| 5462 | */ |
| 5463 | e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE, |
| 5464 | (uint16_t)(eeprom->opcode_bits + 2)); |
| 5465 | |
| 5466 | e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2)); |
| 5467 | |
| 5468 | /* Prepare the EEPROM */ |
| 5469 | e1000_standby_eeprom(hw); |
| 5470 | |
| 5471 | while (words_written < words) { |
| 5472 | /* Send the Write command (3-bit opcode + addr) */ |
| 5473 | e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE, |
| 5474 | eeprom->opcode_bits); |
| 5475 | |
| 5476 | e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written), |
| 5477 | eeprom->address_bits); |
| 5478 | |
| 5479 | /* Send the data */ |
| 5480 | e1000_shift_out_ee_bits(hw, data[words_written], 16); |
| 5481 | |
| 5482 | /* Toggle the CS line. This in effect tells the EEPROM to execute |
| 5483 | * the previous command. |
| 5484 | */ |
| 5485 | e1000_standby_eeprom(hw); |
| 5486 | |
| 5487 | /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will |
| 5488 | * signal that the command has been completed by raising the DO signal. |
| 5489 | * If DO does not go high in 10 milliseconds, then error out. |
| 5490 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5491 | for (i = 0; i < 200; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5492 | eecd = E1000_READ_REG(hw, EECD); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5493 | if (eecd & E1000_EECD_DO) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5494 | udelay(50); |
| 5495 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5496 | if (i == 200) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5497 | DEBUGOUT("EEPROM Write did not complete\n"); |
| 5498 | return -E1000_ERR_EEPROM; |
| 5499 | } |
| 5500 | |
| 5501 | /* Recover from write */ |
| 5502 | e1000_standby_eeprom(hw); |
| 5503 | |
| 5504 | words_written++; |
| 5505 | } |
| 5506 | |
| 5507 | /* Send the write disable command to the EEPROM (3-bit opcode plus |
| 5508 | * 6/8-bit dummy address beginning with 10). It's less work to include |
| 5509 | * the 10 of the dummy address as part of the opcode than it is to shift |
| 5510 | * it over the correct number of bits for the address. This takes the |
| 5511 | * EEPROM out of write/erase mode. |
| 5512 | */ |
| 5513 | e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE, |
| 5514 | (uint16_t)(eeprom->opcode_bits + 2)); |
| 5515 | |
| 5516 | e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2)); |
| 5517 | |
| 5518 | return E1000_SUCCESS; |
| 5519 | } |
| 5520 | |
| 5521 | /****************************************************************************** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5522 | * Flushes the cached eeprom to NVM. This is done by saving the modified values |
| 5523 | * in the eeprom cache and the non modified values in the currently active bank |
| 5524 | * to the new bank. |
| 5525 | * |
| 5526 | * hw - Struct containing variables accessed by shared code |
| 5527 | * offset - offset of word in the EEPROM to read |
| 5528 | * data - word read from the EEPROM |
| 5529 | * words - number of words to read |
| 5530 | *****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 5531 | static int32_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5532 | e1000_commit_shadow_ram(struct e1000_hw *hw) |
| 5533 | { |
| 5534 | uint32_t attempts = 100000; |
| 5535 | uint32_t eecd = 0; |
| 5536 | uint32_t flop = 0; |
| 5537 | uint32_t i = 0; |
| 5538 | int32_t error = E1000_SUCCESS; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5539 | uint32_t old_bank_offset = 0; |
| 5540 | uint32_t new_bank_offset = 0; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5541 | uint8_t low_byte = 0; |
| 5542 | uint8_t high_byte = 0; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5543 | boolean_t sector_write_failed = FALSE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5544 | |
| 5545 | if (hw->mac_type == e1000_82573) { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5546 | /* The flop register will be used to determine if flash type is STM */ |
| 5547 | flop = E1000_READ_REG(hw, FLOP); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5548 | for (i=0; i < attempts; i++) { |
| 5549 | eecd = E1000_READ_REG(hw, EECD); |
| 5550 | if ((eecd & E1000_EECD_FLUPD) == 0) { |
| 5551 | break; |
| 5552 | } |
| 5553 | udelay(5); |
| 5554 | } |
| 5555 | |
| 5556 | if (i == attempts) { |
| 5557 | return -E1000_ERR_EEPROM; |
| 5558 | } |
| 5559 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5560 | /* If STM opcode located in bits 15:8 of flop, reset firmware */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5561 | if ((flop & 0xFF00) == E1000_STM_OPCODE) { |
| 5562 | E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET); |
| 5563 | } |
| 5564 | |
| 5565 | /* Perform the flash update */ |
| 5566 | E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD); |
| 5567 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5568 | for (i=0; i < attempts; i++) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5569 | eecd = E1000_READ_REG(hw, EECD); |
| 5570 | if ((eecd & E1000_EECD_FLUPD) == 0) { |
| 5571 | break; |
| 5572 | } |
| 5573 | udelay(5); |
| 5574 | } |
| 5575 | |
| 5576 | if (i == attempts) { |
| 5577 | return -E1000_ERR_EEPROM; |
| 5578 | } |
| 5579 | } |
| 5580 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5581 | if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) { |
| 5582 | /* We're writing to the opposite bank so if we're on bank 1, |
| 5583 | * write to bank 0 etc. We also need to erase the segment that |
| 5584 | * is going to be written */ |
| 5585 | if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) { |
| 5586 | new_bank_offset = hw->flash_bank_size * 2; |
| 5587 | old_bank_offset = 0; |
| 5588 | e1000_erase_ich8_4k_segment(hw, 1); |
| 5589 | } else { |
| 5590 | old_bank_offset = hw->flash_bank_size * 2; |
| 5591 | new_bank_offset = 0; |
| 5592 | e1000_erase_ich8_4k_segment(hw, 0); |
| 5593 | } |
| 5594 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5595 | sector_write_failed = FALSE; |
| 5596 | /* Loop for every byte in the shadow RAM, |
| 5597 | * which is in units of words. */ |
| 5598 | for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) { |
| 5599 | /* Determine whether to write the value stored |
| 5600 | * in the other NVM bank or a modified value stored |
| 5601 | * in the shadow RAM */ |
| 5602 | if (hw->eeprom_shadow_ram[i].modified == TRUE) { |
| 5603 | low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word; |
| 5604 | udelay(100); |
| 5605 | error = e1000_verify_write_ich8_byte(hw, |
| 5606 | (i << 1) + new_bank_offset, low_byte); |
| 5607 | |
| 5608 | if (error != E1000_SUCCESS) |
| 5609 | sector_write_failed = TRUE; |
| 5610 | else { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5611 | high_byte = |
| 5612 | (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5613 | udelay(100); |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5614 | } |
| 5615 | } else { |
| 5616 | e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset, |
| 5617 | &low_byte); |
| 5618 | udelay(100); |
| 5619 | error = e1000_verify_write_ich8_byte(hw, |
| 5620 | (i << 1) + new_bank_offset, low_byte); |
| 5621 | |
| 5622 | if (error != E1000_SUCCESS) |
| 5623 | sector_write_failed = TRUE; |
| 5624 | else { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5625 | e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1, |
| 5626 | &high_byte); |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5627 | udelay(100); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5628 | } |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5629 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5630 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5631 | /* If the write of the low byte was successful, go ahread and |
| 5632 | * write the high byte while checking to make sure that if it |
| 5633 | * is the signature byte, then it is handled properly */ |
| 5634 | if (sector_write_failed == FALSE) { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5635 | /* If the word is 0x13, then make sure the signature bits |
| 5636 | * (15:14) are 11b until the commit has completed. |
| 5637 | * This will allow us to write 10b which indicates the |
| 5638 | * signature is valid. We want to do this after the write |
| 5639 | * has completed so that we don't mark the segment valid |
| 5640 | * while the write is still in progress */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 5641 | if (i == E1000_ICH_NVM_SIG_WORD) |
| 5642 | high_byte = E1000_ICH_NVM_SIG_MASK | high_byte; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5643 | |
| 5644 | error = e1000_verify_write_ich8_byte(hw, |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5645 | (i << 1) + new_bank_offset + 1, high_byte); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5646 | if (error != E1000_SUCCESS) |
| 5647 | sector_write_failed = TRUE; |
| 5648 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5649 | } else { |
| 5650 | /* If the write failed then break from the loop and |
| 5651 | * return an error */ |
| 5652 | break; |
| 5653 | } |
| 5654 | } |
| 5655 | |
| 5656 | /* Don't bother writing the segment valid bits if sector |
| 5657 | * programming failed. */ |
| 5658 | if (sector_write_failed == FALSE) { |
| 5659 | /* Finally validate the new segment by setting bit 15:14 |
| 5660 | * to 10b in word 0x13 , this can be done without an |
| 5661 | * erase as well since these bits are 11 to start with |
| 5662 | * and we need to change bit 14 to 0b */ |
| 5663 | e1000_read_ich8_byte(hw, |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 5664 | E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset, |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5665 | &high_byte); |
| 5666 | high_byte &= 0xBF; |
| 5667 | error = e1000_verify_write_ich8_byte(hw, |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 5668 | E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset, high_byte); |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5669 | /* And invalidate the previously valid segment by setting |
| 5670 | * its signature word (0x13) high_byte to 0b. This can be |
| 5671 | * done without an erase because flash erase sets all bits |
| 5672 | * to 1's. We can write 1's to 0's without an erase */ |
| 5673 | if (error == E1000_SUCCESS) { |
| 5674 | error = e1000_verify_write_ich8_byte(hw, |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 5675 | E1000_ICH_NVM_SIG_WORD * 2 + 1 + old_bank_offset, 0); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5676 | } |
| 5677 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5678 | /* Clear the now not used entry in the cache */ |
| 5679 | for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) { |
| 5680 | hw->eeprom_shadow_ram[i].modified = FALSE; |
| 5681 | hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5682 | } |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5683 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5684 | } |
| 5685 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5686 | return error; |
| 5687 | } |
| 5688 | |
| 5689 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5690 | * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the |
| 5691 | * second function of dual function devices |
| 5692 | * |
| 5693 | * hw - Struct containing variables accessed by shared code |
| 5694 | *****************************************************************************/ |
| 5695 | int32_t |
| 5696 | e1000_read_mac_addr(struct e1000_hw * hw) |
| 5697 | { |
| 5698 | uint16_t offset; |
| 5699 | uint16_t eeprom_data, i; |
| 5700 | |
| 5701 | DEBUGFUNC("e1000_read_mac_addr"); |
| 5702 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5703 | for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5704 | offset = i >> 1; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5705 | if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5706 | DEBUGOUT("EEPROM Read Error\n"); |
| 5707 | return -E1000_ERR_EEPROM; |
| 5708 | } |
| 5709 | hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF); |
| 5710 | hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8); |
| 5711 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5712 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 5713 | switch (hw->mac_type) { |
| 5714 | default: |
| 5715 | break; |
| 5716 | case e1000_82546: |
| 5717 | case e1000_82546_rev_3: |
| 5718 | case e1000_82571: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 5719 | case e1000_80003es2lan: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5720 | if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5721 | hw->perm_mac_addr[5] ^= 0x01; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 5722 | break; |
| 5723 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5724 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5725 | for (i = 0; i < NODE_ADDRESS_SIZE; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5726 | hw->mac_addr[i] = hw->perm_mac_addr[i]; |
| 5727 | return E1000_SUCCESS; |
| 5728 | } |
| 5729 | |
| 5730 | /****************************************************************************** |
| 5731 | * Initializes receive address filters. |
| 5732 | * |
| 5733 | * hw - Struct containing variables accessed by shared code |
| 5734 | * |
| 5735 | * Places the MAC address in receive address register 0 and clears the rest |
| 5736 | * of the receive addresss registers. Clears the multicast table. Assumes |
| 5737 | * the receiver is in reset when the routine is called. |
| 5738 | *****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 5739 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5740 | e1000_init_rx_addrs(struct e1000_hw *hw) |
| 5741 | { |
| 5742 | uint32_t i; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5743 | uint32_t rar_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5744 | |
| 5745 | DEBUGFUNC("e1000_init_rx_addrs"); |
| 5746 | |
| 5747 | /* Setup the receive address. */ |
| 5748 | DEBUGOUT("Programming MAC Address into RAR[0]\n"); |
| 5749 | |
| 5750 | e1000_rar_set(hw, hw->mac_addr, 0); |
| 5751 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5752 | rar_num = E1000_RAR_ENTRIES; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 5753 | |
| 5754 | /* Reserve a spot for the Locally Administered Address to work around |
| 5755 | * an 82571 issue in which a reset on one port will reload the MAC on |
| 5756 | * the other port. */ |
| 5757 | if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE)) |
| 5758 | rar_num -= 1; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5759 | if (hw->mac_type == e1000_ich8lan) |
| 5760 | rar_num = E1000_RAR_ENTRIES_ICH8LAN; |
| 5761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5762 | /* Zero out the other 15 receive addresses. */ |
| 5763 | DEBUGOUT("Clearing RAR[1-15]\n"); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5764 | for (i = 1; i < rar_num; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5765 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5766 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5767 | E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5768 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5769 | } |
| 5770 | } |
| 5771 | |
| 5772 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5773 | * Hashes an address to determine its location in the multicast table |
| 5774 | * |
| 5775 | * hw - Struct containing variables accessed by shared code |
| 5776 | * mc_addr - the multicast address to hash |
| 5777 | *****************************************************************************/ |
| 5778 | uint32_t |
| 5779 | e1000_hash_mc_addr(struct e1000_hw *hw, |
| 5780 | uint8_t *mc_addr) |
| 5781 | { |
| 5782 | uint32_t hash_value = 0; |
| 5783 | |
| 5784 | /* The portion of the address that is used for the hash table is |
| 5785 | * determined by the mc_filter_type setting. |
| 5786 | */ |
| 5787 | switch (hw->mc_filter_type) { |
| 5788 | /* [0] [1] [2] [3] [4] [5] |
| 5789 | * 01 AA 00 12 34 56 |
| 5790 | * LSB MSB |
| 5791 | */ |
| 5792 | case 0: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5793 | if (hw->mac_type == e1000_ich8lan) { |
| 5794 | /* [47:38] i.e. 0x158 for above example address */ |
| 5795 | hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2)); |
| 5796 | } else { |
| 5797 | /* [47:36] i.e. 0x563 for above example address */ |
| 5798 | hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4)); |
| 5799 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5800 | break; |
| 5801 | case 1: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5802 | if (hw->mac_type == e1000_ich8lan) { |
| 5803 | /* [46:37] i.e. 0x2B1 for above example address */ |
| 5804 | hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3)); |
| 5805 | } else { |
| 5806 | /* [46:35] i.e. 0xAC6 for above example address */ |
| 5807 | hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5)); |
| 5808 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5809 | break; |
| 5810 | case 2: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5811 | if (hw->mac_type == e1000_ich8lan) { |
| 5812 | /*[45:36] i.e. 0x163 for above example address */ |
| 5813 | hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4)); |
| 5814 | } else { |
| 5815 | /* [45:34] i.e. 0x5D8 for above example address */ |
| 5816 | hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6)); |
| 5817 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5818 | break; |
| 5819 | case 3: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5820 | if (hw->mac_type == e1000_ich8lan) { |
| 5821 | /* [43:34] i.e. 0x18D for above example address */ |
| 5822 | hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6)); |
| 5823 | } else { |
| 5824 | /* [43:32] i.e. 0x634 for above example address */ |
| 5825 | hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8)); |
| 5826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5827 | break; |
| 5828 | } |
| 5829 | |
| 5830 | hash_value &= 0xFFF; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5831 | if (hw->mac_type == e1000_ich8lan) |
| 5832 | hash_value &= 0x3FF; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5834 | return hash_value; |
| 5835 | } |
| 5836 | |
| 5837 | /****************************************************************************** |
| 5838 | * Sets the bit in the multicast table corresponding to the hash value. |
| 5839 | * |
| 5840 | * hw - Struct containing variables accessed by shared code |
| 5841 | * hash_value - Multicast address hash value |
| 5842 | *****************************************************************************/ |
| 5843 | void |
| 5844 | e1000_mta_set(struct e1000_hw *hw, |
| 5845 | uint32_t hash_value) |
| 5846 | { |
| 5847 | uint32_t hash_bit, hash_reg; |
| 5848 | uint32_t mta; |
| 5849 | uint32_t temp; |
| 5850 | |
| 5851 | /* The MTA is a register array of 128 32-bit registers. |
| 5852 | * It is treated like an array of 4096 bits. We want to set |
| 5853 | * bit BitArray[hash_value]. So we figure out what register |
| 5854 | * the bit is in, read it, OR in the new bit, then write |
| 5855 | * back the new value. The register is determined by the |
| 5856 | * upper 7 bits of the hash value and the bit within that |
| 5857 | * register are determined by the lower 5 bits of the value. |
| 5858 | */ |
| 5859 | hash_reg = (hash_value >> 5) & 0x7F; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5860 | if (hw->mac_type == e1000_ich8lan) |
| 5861 | hash_reg &= 0x1F; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 5862 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5863 | hash_bit = hash_value & 0x1F; |
| 5864 | |
| 5865 | mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg); |
| 5866 | |
| 5867 | mta |= (1 << hash_bit); |
| 5868 | |
| 5869 | /* If we are on an 82544 and we are trying to write an odd offset |
| 5870 | * in the MTA, save off the previous entry before writing and |
| 5871 | * restore the old value after writing. |
| 5872 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5873 | if ((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5874 | temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1)); |
| 5875 | E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5876 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5877 | E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5878 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5879 | } else { |
| 5880 | E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5881 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5882 | } |
| 5883 | } |
| 5884 | |
| 5885 | /****************************************************************************** |
| 5886 | * Puts an ethernet address into a receive address register. |
| 5887 | * |
| 5888 | * hw - Struct containing variables accessed by shared code |
| 5889 | * addr - Address to put into receive address register |
| 5890 | * index - Receive address register to write |
| 5891 | *****************************************************************************/ |
| 5892 | void |
| 5893 | e1000_rar_set(struct e1000_hw *hw, |
| 5894 | uint8_t *addr, |
| 5895 | uint32_t index) |
| 5896 | { |
| 5897 | uint32_t rar_low, rar_high; |
| 5898 | |
| 5899 | /* HW expects these in little endian so we reverse the byte order |
| 5900 | * from network order (big endian) to little endian |
| 5901 | */ |
| 5902 | rar_low = ((uint32_t) addr[0] | |
| 5903 | ((uint32_t) addr[1] << 8) | |
| 5904 | ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24)); |
Jeff Kirsher | 8df06e5 | 2006-03-02 18:18:32 -0800 | [diff] [blame] | 5905 | rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5906 | |
Jeff Kirsher | 8df06e5 | 2006-03-02 18:18:32 -0800 | [diff] [blame] | 5907 | /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx |
| 5908 | * unit hang. |
| 5909 | * |
| 5910 | * Description: |
| 5911 | * If there are any Rx frames queued up or otherwise present in the HW |
| 5912 | * before RSS is enabled, and then we enable RSS, the HW Rx unit will |
| 5913 | * hang. To work around this issue, we have to disable receives and |
| 5914 | * flush out all Rx frames before we enable RSS. To do so, we modify we |
| 5915 | * redirect all Rx traffic to manageability and then reset the HW. |
| 5916 | * This flushes away Rx frames, and (since the redirections to |
| 5917 | * manageability persists across resets) keeps new ones from coming in |
| 5918 | * while we work. Then, we clear the Address Valid AV bit for all MAC |
| 5919 | * addresses and undo the re-direction to manageability. |
| 5920 | * Now, frames are coming in again, but the MAC won't accept them, so |
| 5921 | * far so good. We now proceed to initialize RSS (if necessary) and |
| 5922 | * configure the Rx unit. Last, we re-enable the AV bits and continue |
| 5923 | * on our merry way. |
| 5924 | */ |
| 5925 | switch (hw->mac_type) { |
| 5926 | case e1000_82571: |
| 5927 | case e1000_82572: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 5928 | case e1000_80003es2lan: |
Jeff Kirsher | 8df06e5 | 2006-03-02 18:18:32 -0800 | [diff] [blame] | 5929 | if (hw->leave_av_bit_off == TRUE) |
| 5930 | break; |
| 5931 | default: |
| 5932 | /* Indicate to hardware the Address is Valid. */ |
| 5933 | rar_high |= E1000_RAH_AV; |
| 5934 | break; |
| 5935 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5936 | |
| 5937 | E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5938 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5939 | E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5940 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5941 | } |
| 5942 | |
| 5943 | /****************************************************************************** |
| 5944 | * Writes a value to the specified offset in the VLAN filter table. |
| 5945 | * |
| 5946 | * hw - Struct containing variables accessed by shared code |
| 5947 | * offset - Offset in VLAN filer table to write |
| 5948 | * value - Value to write into VLAN filter table |
| 5949 | *****************************************************************************/ |
| 5950 | void |
| 5951 | e1000_write_vfta(struct e1000_hw *hw, |
| 5952 | uint32_t offset, |
| 5953 | uint32_t value) |
| 5954 | { |
| 5955 | uint32_t temp; |
| 5956 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5957 | if (hw->mac_type == e1000_ich8lan) |
| 5958 | return; |
| 5959 | |
| 5960 | if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5961 | temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1)); |
| 5962 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5963 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5964 | E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5965 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5966 | } else { |
| 5967 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5968 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5969 | } |
| 5970 | } |
| 5971 | |
| 5972 | /****************************************************************************** |
| 5973 | * Clears the VLAN filer table |
| 5974 | * |
| 5975 | * hw - Struct containing variables accessed by shared code |
| 5976 | *****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 5977 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5978 | e1000_clear_vfta(struct e1000_hw *hw) |
| 5979 | { |
| 5980 | uint32_t offset; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5981 | uint32_t vfta_value = 0; |
| 5982 | uint32_t vfta_offset = 0; |
| 5983 | uint32_t vfta_bit_in_reg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5984 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5985 | if (hw->mac_type == e1000_ich8lan) |
| 5986 | return; |
| 5987 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5988 | if (hw->mac_type == e1000_82573) { |
| 5989 | if (hw->mng_cookie.vlan_id != 0) { |
| 5990 | /* The VFTA is a 4096b bit-field, each identifying a single VLAN |
| 5991 | * ID. The following operations determine which 32b entry |
| 5992 | * (i.e. offset) into the array we want to set the VLAN ID |
| 5993 | * (i.e. bit) of the manageability unit. */ |
| 5994 | vfta_offset = (hw->mng_cookie.vlan_id >> |
| 5995 | E1000_VFTA_ENTRY_SHIFT) & |
| 5996 | E1000_VFTA_ENTRY_MASK; |
| 5997 | vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id & |
| 5998 | E1000_VFTA_ENTRY_BIT_SHIFT_MASK); |
| 5999 | } |
| 6000 | } |
| 6001 | for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) { |
| 6002 | /* If the offset we want to clear is the same offset of the |
| 6003 | * manageability VLAN ID, then clear all bits except that of the |
| 6004 | * manageability unit */ |
| 6005 | vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0; |
| 6006 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 6007 | E1000_WRITE_FLUSH(hw); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6008 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6009 | } |
| 6010 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 6011 | static int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6012 | e1000_id_led_init(struct e1000_hw * hw) |
| 6013 | { |
| 6014 | uint32_t ledctl; |
| 6015 | const uint32_t ledctl_mask = 0x000000FF; |
| 6016 | const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON; |
| 6017 | const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF; |
| 6018 | uint16_t eeprom_data, i, temp; |
| 6019 | const uint16_t led_mask = 0x0F; |
| 6020 | |
| 6021 | DEBUGFUNC("e1000_id_led_init"); |
| 6022 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6023 | if (hw->mac_type < e1000_82540) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6024 | /* Nothing to do */ |
| 6025 | return E1000_SUCCESS; |
| 6026 | } |
| 6027 | |
| 6028 | ledctl = E1000_READ_REG(hw, LEDCTL); |
| 6029 | hw->ledctl_default = ledctl; |
| 6030 | hw->ledctl_mode1 = hw->ledctl_default; |
| 6031 | hw->ledctl_mode2 = hw->ledctl_default; |
| 6032 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6033 | if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6034 | DEBUGOUT("EEPROM Read Error\n"); |
| 6035 | return -E1000_ERR_EEPROM; |
| 6036 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6037 | |
| 6038 | if ((hw->mac_type == e1000_82573) && |
| 6039 | (eeprom_data == ID_LED_RESERVED_82573)) |
| 6040 | eeprom_data = ID_LED_DEFAULT_82573; |
| 6041 | else if ((eeprom_data == ID_LED_RESERVED_0000) || |
| 6042 | (eeprom_data == ID_LED_RESERVED_FFFF)) { |
| 6043 | if (hw->mac_type == e1000_ich8lan) |
| 6044 | eeprom_data = ID_LED_DEFAULT_ICH8LAN; |
| 6045 | else |
| 6046 | eeprom_data = ID_LED_DEFAULT; |
| 6047 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 6048 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6049 | for (i = 0; i < 4; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6050 | temp = (eeprom_data >> (i << 2)) & led_mask; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6051 | switch (temp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6052 | case ID_LED_ON1_DEF2: |
| 6053 | case ID_LED_ON1_ON2: |
| 6054 | case ID_LED_ON1_OFF2: |
| 6055 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); |
| 6056 | hw->ledctl_mode1 |= ledctl_on << (i << 3); |
| 6057 | break; |
| 6058 | case ID_LED_OFF1_DEF2: |
| 6059 | case ID_LED_OFF1_ON2: |
| 6060 | case ID_LED_OFF1_OFF2: |
| 6061 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); |
| 6062 | hw->ledctl_mode1 |= ledctl_off << (i << 3); |
| 6063 | break; |
| 6064 | default: |
| 6065 | /* Do nothing */ |
| 6066 | break; |
| 6067 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6068 | switch (temp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6069 | case ID_LED_DEF1_ON2: |
| 6070 | case ID_LED_ON1_ON2: |
| 6071 | case ID_LED_OFF1_ON2: |
| 6072 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); |
| 6073 | hw->ledctl_mode2 |= ledctl_on << (i << 3); |
| 6074 | break; |
| 6075 | case ID_LED_DEF1_OFF2: |
| 6076 | case ID_LED_ON1_OFF2: |
| 6077 | case ID_LED_OFF1_OFF2: |
| 6078 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); |
| 6079 | hw->ledctl_mode2 |= ledctl_off << (i << 3); |
| 6080 | break; |
| 6081 | default: |
| 6082 | /* Do nothing */ |
| 6083 | break; |
| 6084 | } |
| 6085 | } |
| 6086 | return E1000_SUCCESS; |
| 6087 | } |
| 6088 | |
| 6089 | /****************************************************************************** |
| 6090 | * Prepares SW controlable LED for use and saves the current state of the LED. |
| 6091 | * |
| 6092 | * hw - Struct containing variables accessed by shared code |
| 6093 | *****************************************************************************/ |
| 6094 | int32_t |
| 6095 | e1000_setup_led(struct e1000_hw *hw) |
| 6096 | { |
| 6097 | uint32_t ledctl; |
| 6098 | int32_t ret_val = E1000_SUCCESS; |
| 6099 | |
| 6100 | DEBUGFUNC("e1000_setup_led"); |
| 6101 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6102 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6103 | case e1000_82542_rev2_0: |
| 6104 | case e1000_82542_rev2_1: |
| 6105 | case e1000_82543: |
| 6106 | case e1000_82544: |
| 6107 | /* No setup necessary */ |
| 6108 | break; |
| 6109 | case e1000_82541: |
| 6110 | case e1000_82547: |
| 6111 | case e1000_82541_rev_2: |
| 6112 | case e1000_82547_rev_2: |
| 6113 | /* Turn off PHY Smart Power Down (if enabled) */ |
| 6114 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 6115 | &hw->phy_spd_default); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6116 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6117 | return ret_val; |
| 6118 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 6119 | (uint16_t)(hw->phy_spd_default & |
| 6120 | ~IGP01E1000_GMII_SPD)); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6121 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6122 | return ret_val; |
| 6123 | /* Fall Through */ |
| 6124 | default: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6125 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6126 | ledctl = E1000_READ_REG(hw, LEDCTL); |
| 6127 | /* Save current LEDCTL settings */ |
| 6128 | hw->ledctl_default = ledctl; |
| 6129 | /* Turn off LED0 */ |
| 6130 | ledctl &= ~(E1000_LEDCTL_LED0_IVRT | |
| 6131 | E1000_LEDCTL_LED0_BLINK | |
| 6132 | E1000_LEDCTL_LED0_MODE_MASK); |
| 6133 | ledctl |= (E1000_LEDCTL_MODE_LED_OFF << |
| 6134 | E1000_LEDCTL_LED0_MODE_SHIFT); |
| 6135 | E1000_WRITE_REG(hw, LEDCTL, ledctl); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6136 | } else if (hw->media_type == e1000_media_type_copper) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6137 | E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1); |
| 6138 | break; |
| 6139 | } |
| 6140 | |
| 6141 | return E1000_SUCCESS; |
| 6142 | } |
| 6143 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6145 | /****************************************************************************** |
Auke Kok | f1b3a85 | 2006-06-27 09:07:56 -0700 | [diff] [blame] | 6146 | * Used on 82571 and later Si that has LED blink bits. |
| 6147 | * Callers must use their own timer and should have already called |
| 6148 | * e1000_id_led_init() |
| 6149 | * Call e1000_cleanup led() to stop blinking |
| 6150 | * |
| 6151 | * hw - Struct containing variables accessed by shared code |
| 6152 | *****************************************************************************/ |
| 6153 | int32_t |
| 6154 | e1000_blink_led_start(struct e1000_hw *hw) |
| 6155 | { |
| 6156 | int16_t i; |
| 6157 | uint32_t ledctl_blink = 0; |
| 6158 | |
| 6159 | DEBUGFUNC("e1000_id_led_blink_on"); |
| 6160 | |
| 6161 | if (hw->mac_type < e1000_82571) { |
| 6162 | /* Nothing to do */ |
| 6163 | return E1000_SUCCESS; |
| 6164 | } |
| 6165 | if (hw->media_type == e1000_media_type_fiber) { |
| 6166 | /* always blink LED0 for PCI-E fiber */ |
| 6167 | ledctl_blink = E1000_LEDCTL_LED0_BLINK | |
| 6168 | (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT); |
| 6169 | } else { |
| 6170 | /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */ |
| 6171 | ledctl_blink = hw->ledctl_mode2; |
| 6172 | for (i=0; i < 4; i++) |
| 6173 | if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) == |
| 6174 | E1000_LEDCTL_MODE_LED_ON) |
| 6175 | ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8)); |
| 6176 | } |
| 6177 | |
| 6178 | E1000_WRITE_REG(hw, LEDCTL, ledctl_blink); |
| 6179 | |
| 6180 | return E1000_SUCCESS; |
| 6181 | } |
| 6182 | |
| 6183 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6184 | * Restores the saved state of the SW controlable LED. |
| 6185 | * |
| 6186 | * hw - Struct containing variables accessed by shared code |
| 6187 | *****************************************************************************/ |
| 6188 | int32_t |
| 6189 | e1000_cleanup_led(struct e1000_hw *hw) |
| 6190 | { |
| 6191 | int32_t ret_val = E1000_SUCCESS; |
| 6192 | |
| 6193 | DEBUGFUNC("e1000_cleanup_led"); |
| 6194 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6195 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6196 | case e1000_82542_rev2_0: |
| 6197 | case e1000_82542_rev2_1: |
| 6198 | case e1000_82543: |
| 6199 | case e1000_82544: |
| 6200 | /* No cleanup necessary */ |
| 6201 | break; |
| 6202 | case e1000_82541: |
| 6203 | case e1000_82547: |
| 6204 | case e1000_82541_rev_2: |
| 6205 | case e1000_82547_rev_2: |
| 6206 | /* Turn on PHY Smart Power Down (if previously enabled) */ |
| 6207 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 6208 | hw->phy_spd_default); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6209 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6210 | return ret_val; |
| 6211 | /* Fall Through */ |
| 6212 | default: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6213 | if (hw->phy_type == e1000_phy_ife) { |
| 6214 | e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0); |
| 6215 | break; |
| 6216 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6217 | /* Restore LEDCTL settings */ |
| 6218 | E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default); |
| 6219 | break; |
| 6220 | } |
| 6221 | |
| 6222 | return E1000_SUCCESS; |
| 6223 | } |
| 6224 | |
| 6225 | /****************************************************************************** |
| 6226 | * Turns on the software controllable LED |
| 6227 | * |
| 6228 | * hw - Struct containing variables accessed by shared code |
| 6229 | *****************************************************************************/ |
| 6230 | int32_t |
| 6231 | e1000_led_on(struct e1000_hw *hw) |
| 6232 | { |
| 6233 | uint32_t ctrl = E1000_READ_REG(hw, CTRL); |
| 6234 | |
| 6235 | DEBUGFUNC("e1000_led_on"); |
| 6236 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6237 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6238 | case e1000_82542_rev2_0: |
| 6239 | case e1000_82542_rev2_1: |
| 6240 | case e1000_82543: |
| 6241 | /* Set SW Defineable Pin 0 to turn on the LED */ |
| 6242 | ctrl |= E1000_CTRL_SWDPIN0; |
| 6243 | ctrl |= E1000_CTRL_SWDPIO0; |
| 6244 | break; |
| 6245 | case e1000_82544: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6246 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6247 | /* Set SW Defineable Pin 0 to turn on the LED */ |
| 6248 | ctrl |= E1000_CTRL_SWDPIN0; |
| 6249 | ctrl |= E1000_CTRL_SWDPIO0; |
| 6250 | } else { |
| 6251 | /* Clear SW Defineable Pin 0 to turn on the LED */ |
| 6252 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 6253 | ctrl |= E1000_CTRL_SWDPIO0; |
| 6254 | } |
| 6255 | break; |
| 6256 | default: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6257 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6258 | /* Clear SW Defineable Pin 0 to turn on the LED */ |
| 6259 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 6260 | ctrl |= E1000_CTRL_SWDPIO0; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6261 | } else if (hw->phy_type == e1000_phy_ife) { |
| 6262 | e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, |
| 6263 | (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON)); |
| 6264 | } else if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6265 | E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2); |
| 6266 | return E1000_SUCCESS; |
| 6267 | } |
| 6268 | break; |
| 6269 | } |
| 6270 | |
| 6271 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 6272 | |
| 6273 | return E1000_SUCCESS; |
| 6274 | } |
| 6275 | |
| 6276 | /****************************************************************************** |
| 6277 | * Turns off the software controllable LED |
| 6278 | * |
| 6279 | * hw - Struct containing variables accessed by shared code |
| 6280 | *****************************************************************************/ |
| 6281 | int32_t |
| 6282 | e1000_led_off(struct e1000_hw *hw) |
| 6283 | { |
| 6284 | uint32_t ctrl = E1000_READ_REG(hw, CTRL); |
| 6285 | |
| 6286 | DEBUGFUNC("e1000_led_off"); |
| 6287 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6288 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6289 | case e1000_82542_rev2_0: |
| 6290 | case e1000_82542_rev2_1: |
| 6291 | case e1000_82543: |
| 6292 | /* Clear SW Defineable Pin 0 to turn off the LED */ |
| 6293 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 6294 | ctrl |= E1000_CTRL_SWDPIO0; |
| 6295 | break; |
| 6296 | case e1000_82544: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6297 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6298 | /* Clear SW Defineable Pin 0 to turn off the LED */ |
| 6299 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 6300 | ctrl |= E1000_CTRL_SWDPIO0; |
| 6301 | } else { |
| 6302 | /* Set SW Defineable Pin 0 to turn off the LED */ |
| 6303 | ctrl |= E1000_CTRL_SWDPIN0; |
| 6304 | ctrl |= E1000_CTRL_SWDPIO0; |
| 6305 | } |
| 6306 | break; |
| 6307 | default: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6308 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6309 | /* Set SW Defineable Pin 0 to turn off the LED */ |
| 6310 | ctrl |= E1000_CTRL_SWDPIN0; |
| 6311 | ctrl |= E1000_CTRL_SWDPIO0; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6312 | } else if (hw->phy_type == e1000_phy_ife) { |
| 6313 | e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, |
| 6314 | (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF)); |
| 6315 | } else if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6316 | E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1); |
| 6317 | return E1000_SUCCESS; |
| 6318 | } |
| 6319 | break; |
| 6320 | } |
| 6321 | |
| 6322 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 6323 | |
| 6324 | return E1000_SUCCESS; |
| 6325 | } |
| 6326 | |
| 6327 | /****************************************************************************** |
| 6328 | * Clears all hardware statistics counters. |
| 6329 | * |
| 6330 | * hw - Struct containing variables accessed by shared code |
| 6331 | *****************************************************************************/ |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 6332 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6333 | e1000_clear_hw_cntrs(struct e1000_hw *hw) |
| 6334 | { |
| 6335 | volatile uint32_t temp; |
| 6336 | |
| 6337 | temp = E1000_READ_REG(hw, CRCERRS); |
| 6338 | temp = E1000_READ_REG(hw, SYMERRS); |
| 6339 | temp = E1000_READ_REG(hw, MPC); |
| 6340 | temp = E1000_READ_REG(hw, SCC); |
| 6341 | temp = E1000_READ_REG(hw, ECOL); |
| 6342 | temp = E1000_READ_REG(hw, MCC); |
| 6343 | temp = E1000_READ_REG(hw, LATECOL); |
| 6344 | temp = E1000_READ_REG(hw, COLC); |
| 6345 | temp = E1000_READ_REG(hw, DC); |
| 6346 | temp = E1000_READ_REG(hw, SEC); |
| 6347 | temp = E1000_READ_REG(hw, RLEC); |
| 6348 | temp = E1000_READ_REG(hw, XONRXC); |
| 6349 | temp = E1000_READ_REG(hw, XONTXC); |
| 6350 | temp = E1000_READ_REG(hw, XOFFRXC); |
| 6351 | temp = E1000_READ_REG(hw, XOFFTXC); |
| 6352 | temp = E1000_READ_REG(hw, FCRUC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6353 | |
| 6354 | if (hw->mac_type != e1000_ich8lan) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6355 | temp = E1000_READ_REG(hw, PRC64); |
| 6356 | temp = E1000_READ_REG(hw, PRC127); |
| 6357 | temp = E1000_READ_REG(hw, PRC255); |
| 6358 | temp = E1000_READ_REG(hw, PRC511); |
| 6359 | temp = E1000_READ_REG(hw, PRC1023); |
| 6360 | temp = E1000_READ_REG(hw, PRC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6361 | } |
| 6362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6363 | temp = E1000_READ_REG(hw, GPRC); |
| 6364 | temp = E1000_READ_REG(hw, BPRC); |
| 6365 | temp = E1000_READ_REG(hw, MPRC); |
| 6366 | temp = E1000_READ_REG(hw, GPTC); |
| 6367 | temp = E1000_READ_REG(hw, GORCL); |
| 6368 | temp = E1000_READ_REG(hw, GORCH); |
| 6369 | temp = E1000_READ_REG(hw, GOTCL); |
| 6370 | temp = E1000_READ_REG(hw, GOTCH); |
| 6371 | temp = E1000_READ_REG(hw, RNBC); |
| 6372 | temp = E1000_READ_REG(hw, RUC); |
| 6373 | temp = E1000_READ_REG(hw, RFC); |
| 6374 | temp = E1000_READ_REG(hw, ROC); |
| 6375 | temp = E1000_READ_REG(hw, RJC); |
| 6376 | temp = E1000_READ_REG(hw, TORL); |
| 6377 | temp = E1000_READ_REG(hw, TORH); |
| 6378 | temp = E1000_READ_REG(hw, TOTL); |
| 6379 | temp = E1000_READ_REG(hw, TOTH); |
| 6380 | temp = E1000_READ_REG(hw, TPR); |
| 6381 | temp = E1000_READ_REG(hw, TPT); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6382 | |
| 6383 | if (hw->mac_type != e1000_ich8lan) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6384 | temp = E1000_READ_REG(hw, PTC64); |
| 6385 | temp = E1000_READ_REG(hw, PTC127); |
| 6386 | temp = E1000_READ_REG(hw, PTC255); |
| 6387 | temp = E1000_READ_REG(hw, PTC511); |
| 6388 | temp = E1000_READ_REG(hw, PTC1023); |
| 6389 | temp = E1000_READ_REG(hw, PTC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6390 | } |
| 6391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6392 | temp = E1000_READ_REG(hw, MPTC); |
| 6393 | temp = E1000_READ_REG(hw, BPTC); |
| 6394 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6395 | if (hw->mac_type < e1000_82543) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6396 | |
| 6397 | temp = E1000_READ_REG(hw, ALGNERRC); |
| 6398 | temp = E1000_READ_REG(hw, RXERRC); |
| 6399 | temp = E1000_READ_REG(hw, TNCRS); |
| 6400 | temp = E1000_READ_REG(hw, CEXTERR); |
| 6401 | temp = E1000_READ_REG(hw, TSCTC); |
| 6402 | temp = E1000_READ_REG(hw, TSCTFC); |
| 6403 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6404 | if (hw->mac_type <= e1000_82544) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6405 | |
| 6406 | temp = E1000_READ_REG(hw, MGTPRC); |
| 6407 | temp = E1000_READ_REG(hw, MGTPDC); |
| 6408 | temp = E1000_READ_REG(hw, MGTPTC); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6409 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6410 | if (hw->mac_type <= e1000_82547_rev_2) return; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6411 | |
| 6412 | temp = E1000_READ_REG(hw, IAC); |
| 6413 | temp = E1000_READ_REG(hw, ICRXOC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6414 | |
| 6415 | if (hw->mac_type == e1000_ich8lan) return; |
| 6416 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6417 | temp = E1000_READ_REG(hw, ICRXPTC); |
| 6418 | temp = E1000_READ_REG(hw, ICRXATC); |
| 6419 | temp = E1000_READ_REG(hw, ICTXPTC); |
| 6420 | temp = E1000_READ_REG(hw, ICTXATC); |
| 6421 | temp = E1000_READ_REG(hw, ICTXQEC); |
| 6422 | temp = E1000_READ_REG(hw, ICTXQMTC); |
| 6423 | temp = E1000_READ_REG(hw, ICRXDMTC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6424 | } |
| 6425 | |
| 6426 | /****************************************************************************** |
| 6427 | * Resets Adaptive IFS to its default state. |
| 6428 | * |
| 6429 | * hw - Struct containing variables accessed by shared code |
| 6430 | * |
| 6431 | * Call this after e1000_init_hw. You may override the IFS defaults by setting |
| 6432 | * hw->ifs_params_forced to TRUE. However, you must initialize hw-> |
| 6433 | * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio |
| 6434 | * before calling this function. |
| 6435 | *****************************************************************************/ |
| 6436 | void |
| 6437 | e1000_reset_adaptive(struct e1000_hw *hw) |
| 6438 | { |
| 6439 | DEBUGFUNC("e1000_reset_adaptive"); |
| 6440 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6441 | if (hw->adaptive_ifs) { |
| 6442 | if (!hw->ifs_params_forced) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6443 | hw->current_ifs_val = 0; |
| 6444 | hw->ifs_min_val = IFS_MIN; |
| 6445 | hw->ifs_max_val = IFS_MAX; |
| 6446 | hw->ifs_step_size = IFS_STEP; |
| 6447 | hw->ifs_ratio = IFS_RATIO; |
| 6448 | } |
| 6449 | hw->in_ifs_mode = FALSE; |
| 6450 | E1000_WRITE_REG(hw, AIT, 0); |
| 6451 | } else { |
| 6452 | DEBUGOUT("Not in Adaptive IFS mode!\n"); |
| 6453 | } |
| 6454 | } |
| 6455 | |
| 6456 | /****************************************************************************** |
| 6457 | * Called during the callback/watchdog routine to update IFS value based on |
| 6458 | * the ratio of transmits to collisions. |
| 6459 | * |
| 6460 | * hw - Struct containing variables accessed by shared code |
| 6461 | * tx_packets - Number of transmits since last callback |
| 6462 | * total_collisions - Number of collisions since last callback |
| 6463 | *****************************************************************************/ |
| 6464 | void |
| 6465 | e1000_update_adaptive(struct e1000_hw *hw) |
| 6466 | { |
| 6467 | DEBUGFUNC("e1000_update_adaptive"); |
| 6468 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6469 | if (hw->adaptive_ifs) { |
| 6470 | if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) { |
| 6471 | if (hw->tx_packet_delta > MIN_NUM_XMITS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6472 | hw->in_ifs_mode = TRUE; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6473 | if (hw->current_ifs_val < hw->ifs_max_val) { |
| 6474 | if (hw->current_ifs_val == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6475 | hw->current_ifs_val = hw->ifs_min_val; |
| 6476 | else |
| 6477 | hw->current_ifs_val += hw->ifs_step_size; |
| 6478 | E1000_WRITE_REG(hw, AIT, hw->current_ifs_val); |
| 6479 | } |
| 6480 | } |
| 6481 | } else { |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6482 | if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6483 | hw->current_ifs_val = 0; |
| 6484 | hw->in_ifs_mode = FALSE; |
| 6485 | E1000_WRITE_REG(hw, AIT, 0); |
| 6486 | } |
| 6487 | } |
| 6488 | } else { |
| 6489 | DEBUGOUT("Not in Adaptive IFS mode!\n"); |
| 6490 | } |
| 6491 | } |
| 6492 | |
| 6493 | /****************************************************************************** |
| 6494 | * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT |
| 6495 | * |
| 6496 | * hw - Struct containing variables accessed by shared code |
| 6497 | * frame_len - The length of the frame in question |
| 6498 | * mac_addr - The Ethernet destination address of the frame in question |
| 6499 | *****************************************************************************/ |
| 6500 | void |
| 6501 | e1000_tbi_adjust_stats(struct e1000_hw *hw, |
| 6502 | struct e1000_hw_stats *stats, |
| 6503 | uint32_t frame_len, |
| 6504 | uint8_t *mac_addr) |
| 6505 | { |
| 6506 | uint64_t carry_bit; |
| 6507 | |
| 6508 | /* First adjust the frame length. */ |
| 6509 | frame_len--; |
| 6510 | /* We need to adjust the statistics counters, since the hardware |
| 6511 | * counters overcount this packet as a CRC error and undercount |
| 6512 | * the packet as a good packet |
| 6513 | */ |
| 6514 | /* This packet should not be counted as a CRC error. */ |
| 6515 | stats->crcerrs--; |
| 6516 | /* This packet does count as a Good Packet Received. */ |
| 6517 | stats->gprc++; |
| 6518 | |
| 6519 | /* Adjust the Good Octets received counters */ |
| 6520 | carry_bit = 0x80000000 & stats->gorcl; |
| 6521 | stats->gorcl += frame_len; |
| 6522 | /* If the high bit of Gorcl (the low 32 bits of the Good Octets |
| 6523 | * Received Count) was one before the addition, |
| 6524 | * AND it is zero after, then we lost the carry out, |
| 6525 | * need to add one to Gorch (Good Octets Received Count High). |
| 6526 | * This could be simplified if all environments supported |
| 6527 | * 64-bit integers. |
| 6528 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6529 | if (carry_bit && ((stats->gorcl & 0x80000000) == 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6530 | stats->gorch++; |
| 6531 | /* Is this a broadcast or multicast? Check broadcast first, |
| 6532 | * since the test for a multicast frame will test positive on |
| 6533 | * a broadcast frame. |
| 6534 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6535 | if ((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6536 | /* Broadcast packet */ |
| 6537 | stats->bprc++; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6538 | else if (*mac_addr & 0x01) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6539 | /* Multicast packet */ |
| 6540 | stats->mprc++; |
| 6541 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6542 | if (frame_len == hw->max_frame_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6543 | /* In this case, the hardware has overcounted the number of |
| 6544 | * oversize frames. |
| 6545 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6546 | if (stats->roc > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6547 | stats->roc--; |
| 6548 | } |
| 6549 | |
| 6550 | /* Adjust the bin counters when the extra byte put the frame in the |
| 6551 | * wrong bin. Remember that the frame_len was adjusted above. |
| 6552 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6553 | if (frame_len == 64) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6554 | stats->prc64++; |
| 6555 | stats->prc127--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6556 | } else if (frame_len == 127) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6557 | stats->prc127++; |
| 6558 | stats->prc255--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6559 | } else if (frame_len == 255) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6560 | stats->prc255++; |
| 6561 | stats->prc511--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6562 | } else if (frame_len == 511) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6563 | stats->prc511++; |
| 6564 | stats->prc1023--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6565 | } else if (frame_len == 1023) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6566 | stats->prc1023++; |
| 6567 | stats->prc1522--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6568 | } else if (frame_len == 1522) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6569 | stats->prc1522++; |
| 6570 | } |
| 6571 | } |
| 6572 | |
| 6573 | /****************************************************************************** |
| 6574 | * Gets the current PCI bus type, speed, and width of the hardware |
| 6575 | * |
| 6576 | * hw - Struct containing variables accessed by shared code |
| 6577 | *****************************************************************************/ |
| 6578 | void |
| 6579 | e1000_get_bus_info(struct e1000_hw *hw) |
| 6580 | { |
Jeff Kirsher | caeccb6 | 2006-09-27 12:53:57 -0700 | [diff] [blame] | 6581 | int32_t ret_val; |
| 6582 | uint16_t pci_ex_link_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6583 | uint32_t status; |
| 6584 | |
| 6585 | switch (hw->mac_type) { |
| 6586 | case e1000_82542_rev2_0: |
| 6587 | case e1000_82542_rev2_1: |
| 6588 | hw->bus_type = e1000_bus_type_unknown; |
| 6589 | hw->bus_speed = e1000_bus_speed_unknown; |
| 6590 | hw->bus_width = e1000_bus_width_unknown; |
| 6591 | break; |
Jeff Kirsher | caeccb6 | 2006-09-27 12:53:57 -0700 | [diff] [blame] | 6592 | case e1000_82571: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 6593 | case e1000_82572: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6594 | case e1000_82573: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 6595 | case e1000_80003es2lan: |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 6596 | hw->bus_type = e1000_bus_type_pci_express; |
| 6597 | hw->bus_speed = e1000_bus_speed_2500; |
Jeff Kirsher | caeccb6 | 2006-09-27 12:53:57 -0700 | [diff] [blame] | 6598 | ret_val = e1000_read_pcie_cap_reg(hw, |
| 6599 | PCI_EX_LINK_STATUS, |
| 6600 | &pci_ex_link_status); |
| 6601 | if (ret_val) |
| 6602 | hw->bus_width = e1000_bus_width_unknown; |
| 6603 | else |
| 6604 | hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >> |
| 6605 | PCI_EX_LINK_WIDTH_SHIFT; |
| 6606 | break; |
| 6607 | case e1000_ich8lan: |
| 6608 | hw->bus_type = e1000_bus_type_pci_express; |
| 6609 | hw->bus_speed = e1000_bus_speed_2500; |
| 6610 | hw->bus_width = e1000_bus_width_pciex_1; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6611 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6612 | default: |
| 6613 | status = E1000_READ_REG(hw, STATUS); |
| 6614 | hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ? |
| 6615 | e1000_bus_type_pcix : e1000_bus_type_pci; |
| 6616 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6617 | if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6618 | hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ? |
| 6619 | e1000_bus_speed_66 : e1000_bus_speed_120; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6620 | } else if (hw->bus_type == e1000_bus_type_pci) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6621 | hw->bus_speed = (status & E1000_STATUS_PCI66) ? |
| 6622 | e1000_bus_speed_66 : e1000_bus_speed_33; |
| 6623 | } else { |
| 6624 | switch (status & E1000_STATUS_PCIX_SPEED) { |
| 6625 | case E1000_STATUS_PCIX_SPEED_66: |
| 6626 | hw->bus_speed = e1000_bus_speed_66; |
| 6627 | break; |
| 6628 | case E1000_STATUS_PCIX_SPEED_100: |
| 6629 | hw->bus_speed = e1000_bus_speed_100; |
| 6630 | break; |
| 6631 | case E1000_STATUS_PCIX_SPEED_133: |
| 6632 | hw->bus_speed = e1000_bus_speed_133; |
| 6633 | break; |
| 6634 | default: |
| 6635 | hw->bus_speed = e1000_bus_speed_reserved; |
| 6636 | break; |
| 6637 | } |
| 6638 | } |
| 6639 | hw->bus_width = (status & E1000_STATUS_BUS64) ? |
| 6640 | e1000_bus_width_64 : e1000_bus_width_32; |
| 6641 | break; |
| 6642 | } |
| 6643 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6644 | |
| 6645 | /****************************************************************************** |
| 6646 | * Writes a value to one of the devices registers using port I/O (as opposed to |
| 6647 | * memory mapped I/O). Only 82544 and newer devices support port I/O. |
| 6648 | * |
| 6649 | * hw - Struct containing variables accessed by shared code |
| 6650 | * offset - offset to write to |
| 6651 | * value - value to write |
| 6652 | *****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 6653 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6654 | e1000_write_reg_io(struct e1000_hw *hw, |
| 6655 | uint32_t offset, |
| 6656 | uint32_t value) |
| 6657 | { |
| 6658 | unsigned long io_addr = hw->io_base; |
| 6659 | unsigned long io_data = hw->io_base + 4; |
| 6660 | |
| 6661 | e1000_io_write(hw, io_addr, offset); |
| 6662 | e1000_io_write(hw, io_data, value); |
| 6663 | } |
| 6664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6665 | /****************************************************************************** |
| 6666 | * Estimates the cable length. |
| 6667 | * |
| 6668 | * hw - Struct containing variables accessed by shared code |
| 6669 | * min_length - The estimated minimum length |
| 6670 | * max_length - The estimated maximum length |
| 6671 | * |
| 6672 | * returns: - E1000_ERR_XXX |
| 6673 | * E1000_SUCCESS |
| 6674 | * |
| 6675 | * This function always returns a ranged length (minimum & maximum). |
| 6676 | * So for M88 phy's, this function interprets the one value returned from the |
| 6677 | * register to the minimum and maximum range. |
| 6678 | * For IGP phy's, the function calculates the range by the AGC registers. |
| 6679 | *****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 6680 | static int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6681 | e1000_get_cable_length(struct e1000_hw *hw, |
| 6682 | uint16_t *min_length, |
| 6683 | uint16_t *max_length) |
| 6684 | { |
| 6685 | int32_t ret_val; |
| 6686 | uint16_t agc_value = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6687 | uint16_t i, phy_data; |
| 6688 | uint16_t cable_length; |
| 6689 | |
| 6690 | DEBUGFUNC("e1000_get_cable_length"); |
| 6691 | |
| 6692 | *min_length = *max_length = 0; |
| 6693 | |
| 6694 | /* Use old method for Phy older than IGP */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6695 | if (hw->phy_type == e1000_phy_m88) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6697 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 6698 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6699 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6700 | return ret_val; |
| 6701 | cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >> |
| 6702 | M88E1000_PSSR_CABLE_LENGTH_SHIFT; |
| 6703 | |
| 6704 | /* Convert the enum value to ranged values */ |
| 6705 | switch (cable_length) { |
| 6706 | case e1000_cable_length_50: |
| 6707 | *min_length = 0; |
| 6708 | *max_length = e1000_igp_cable_length_50; |
| 6709 | break; |
| 6710 | case e1000_cable_length_50_80: |
| 6711 | *min_length = e1000_igp_cable_length_50; |
| 6712 | *max_length = e1000_igp_cable_length_80; |
| 6713 | break; |
| 6714 | case e1000_cable_length_80_110: |
| 6715 | *min_length = e1000_igp_cable_length_80; |
| 6716 | *max_length = e1000_igp_cable_length_110; |
| 6717 | break; |
| 6718 | case e1000_cable_length_110_140: |
| 6719 | *min_length = e1000_igp_cable_length_110; |
| 6720 | *max_length = e1000_igp_cable_length_140; |
| 6721 | break; |
| 6722 | case e1000_cable_length_140: |
| 6723 | *min_length = e1000_igp_cable_length_140; |
| 6724 | *max_length = e1000_igp_cable_length_170; |
| 6725 | break; |
| 6726 | default: |
| 6727 | return -E1000_ERR_PHY; |
| 6728 | break; |
| 6729 | } |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 6730 | } else if (hw->phy_type == e1000_phy_gg82563) { |
| 6731 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE, |
| 6732 | &phy_data); |
| 6733 | if (ret_val) |
| 6734 | return ret_val; |
| 6735 | cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH; |
| 6736 | |
| 6737 | switch (cable_length) { |
| 6738 | case e1000_gg_cable_length_60: |
| 6739 | *min_length = 0; |
| 6740 | *max_length = e1000_igp_cable_length_60; |
| 6741 | break; |
| 6742 | case e1000_gg_cable_length_60_115: |
| 6743 | *min_length = e1000_igp_cable_length_60; |
| 6744 | *max_length = e1000_igp_cable_length_115; |
| 6745 | break; |
| 6746 | case e1000_gg_cable_length_115_150: |
| 6747 | *min_length = e1000_igp_cable_length_115; |
| 6748 | *max_length = e1000_igp_cable_length_150; |
| 6749 | break; |
| 6750 | case e1000_gg_cable_length_150: |
| 6751 | *min_length = e1000_igp_cable_length_150; |
| 6752 | *max_length = e1000_igp_cable_length_180; |
| 6753 | break; |
| 6754 | default: |
| 6755 | return -E1000_ERR_PHY; |
| 6756 | break; |
| 6757 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6758 | } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6759 | uint16_t cur_agc_value; |
| 6760 | uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6761 | uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = |
| 6762 | {IGP01E1000_PHY_AGC_A, |
| 6763 | IGP01E1000_PHY_AGC_B, |
| 6764 | IGP01E1000_PHY_AGC_C, |
| 6765 | IGP01E1000_PHY_AGC_D}; |
| 6766 | /* Read the AGC registers for all channels */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6767 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6768 | |
| 6769 | ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6770 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6771 | return ret_val; |
| 6772 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6773 | cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6774 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6775 | /* Value bound check. */ |
| 6776 | if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) || |
| 6777 | (cur_agc_value == 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6778 | return -E1000_ERR_PHY; |
| 6779 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6780 | agc_value += cur_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6781 | |
| 6782 | /* Update minimal AGC value. */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6783 | if (min_agc_value > cur_agc_value) |
| 6784 | min_agc_value = cur_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6785 | } |
| 6786 | |
| 6787 | /* Remove the minimal AGC result for length < 50m */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6788 | if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) { |
| 6789 | agc_value -= min_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6790 | |
| 6791 | /* Get the average length of the remaining 3 channels */ |
| 6792 | agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1); |
| 6793 | } else { |
| 6794 | /* Get the average length of all the 4 channels. */ |
| 6795 | agc_value /= IGP01E1000_PHY_CHANNEL_NUM; |
| 6796 | } |
| 6797 | |
| 6798 | /* Set the range of the calculated length. */ |
| 6799 | *min_length = ((e1000_igp_cable_length_table[agc_value] - |
| 6800 | IGP01E1000_AGC_RANGE) > 0) ? |
| 6801 | (e1000_igp_cable_length_table[agc_value] - |
| 6802 | IGP01E1000_AGC_RANGE) : 0; |
| 6803 | *max_length = e1000_igp_cable_length_table[agc_value] + |
| 6804 | IGP01E1000_AGC_RANGE; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6805 | } else if (hw->phy_type == e1000_phy_igp_2 || |
| 6806 | hw->phy_type == e1000_phy_igp_3) { |
| 6807 | uint16_t cur_agc_index, max_agc_index = 0; |
| 6808 | uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 6809 | uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = |
| 6810 | {IGP02E1000_PHY_AGC_A, |
| 6811 | IGP02E1000_PHY_AGC_B, |
| 6812 | IGP02E1000_PHY_AGC_C, |
| 6813 | IGP02E1000_PHY_AGC_D}; |
| 6814 | /* Read the AGC registers for all channels */ |
| 6815 | for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) { |
| 6816 | ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data); |
| 6817 | if (ret_val) |
| 6818 | return ret_val; |
| 6819 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6820 | /* Getting bits 15:9, which represent the combination of course and |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 6821 | * fine gain values. The result is a number that can be put into |
| 6822 | * the lookup table to obtain the approximate cable length. */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6823 | cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) & |
| 6824 | IGP02E1000_AGC_LENGTH_MASK; |
| 6825 | |
| 6826 | /* Array index bound check. */ |
| 6827 | if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) || |
| 6828 | (cur_agc_index == 0)) |
| 6829 | return -E1000_ERR_PHY; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 6830 | |
| 6831 | /* Remove min & max AGC values from calculation. */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6832 | if (e1000_igp_2_cable_length_table[min_agc_index] > |
| 6833 | e1000_igp_2_cable_length_table[cur_agc_index]) |
| 6834 | min_agc_index = cur_agc_index; |
| 6835 | if (e1000_igp_2_cable_length_table[max_agc_index] < |
| 6836 | e1000_igp_2_cable_length_table[cur_agc_index]) |
| 6837 | max_agc_index = cur_agc_index; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 6838 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6839 | agc_value += e1000_igp_2_cable_length_table[cur_agc_index]; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 6840 | } |
| 6841 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6842 | agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] + |
| 6843 | e1000_igp_2_cable_length_table[max_agc_index]); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 6844 | agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2); |
| 6845 | |
| 6846 | /* Calculate cable length with the error range of +/- 10 meters. */ |
| 6847 | *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ? |
| 6848 | (agc_value - IGP02E1000_AGC_RANGE) : 0; |
| 6849 | *max_length = agc_value + IGP02E1000_AGC_RANGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6850 | } |
| 6851 | |
| 6852 | return E1000_SUCCESS; |
| 6853 | } |
| 6854 | |
| 6855 | /****************************************************************************** |
| 6856 | * Check the cable polarity |
| 6857 | * |
| 6858 | * hw - Struct containing variables accessed by shared code |
| 6859 | * polarity - output parameter : 0 - Polarity is not reversed |
| 6860 | * 1 - Polarity is reversed. |
| 6861 | * |
| 6862 | * returns: - E1000_ERR_XXX |
| 6863 | * E1000_SUCCESS |
| 6864 | * |
| 6865 | * For phy's older then IGP, this function simply reads the polarity bit in the |
| 6866 | * Phy Status register. For IGP phy's, this bit is valid only if link speed is |
| 6867 | * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will |
| 6868 | * return 0. If the link speed is 1000 Mbps the polarity status is in the |
| 6869 | * IGP01E1000_PHY_PCS_INIT_REG. |
| 6870 | *****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 6871 | static int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6872 | e1000_check_polarity(struct e1000_hw *hw, |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 6873 | e1000_rev_polarity *polarity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6874 | { |
| 6875 | int32_t ret_val; |
| 6876 | uint16_t phy_data; |
| 6877 | |
| 6878 | DEBUGFUNC("e1000_check_polarity"); |
| 6879 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 6880 | if ((hw->phy_type == e1000_phy_m88) || |
| 6881 | (hw->phy_type == e1000_phy_gg82563)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6882 | /* return the Polarity bit in the Status register. */ |
| 6883 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 6884 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6885 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6886 | return ret_val; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 6887 | *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >> |
| 6888 | M88E1000_PSSR_REV_POLARITY_SHIFT) ? |
| 6889 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
| 6890 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6891 | } else if (hw->phy_type == e1000_phy_igp || |
| 6892 | hw->phy_type == e1000_phy_igp_3 || |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6893 | hw->phy_type == e1000_phy_igp_2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6894 | /* Read the Status register to check the speed */ |
| 6895 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, |
| 6896 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6897 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6898 | return ret_val; |
| 6899 | |
| 6900 | /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to |
| 6901 | * find the polarity status */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6902 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6903 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
| 6904 | |
| 6905 | /* Read the GIG initialization PCS register (0x00B4) */ |
| 6906 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG, |
| 6907 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6908 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6909 | return ret_val; |
| 6910 | |
| 6911 | /* Check the polarity bits */ |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 6912 | *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? |
| 6913 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6914 | } else { |
| 6915 | /* For 10 Mbps, read the polarity bit in the status register. (for |
| 6916 | * 100 Mbps this bit is always 0) */ |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 6917 | *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ? |
| 6918 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6919 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6920 | } else if (hw->phy_type == e1000_phy_ife) { |
| 6921 | ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL, |
| 6922 | &phy_data); |
| 6923 | if (ret_val) |
| 6924 | return ret_val; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 6925 | *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >> |
| 6926 | IFE_PESC_POLARITY_REVERSED_SHIFT) ? |
| 6927 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6928 | } |
| 6929 | return E1000_SUCCESS; |
| 6930 | } |
| 6931 | |
| 6932 | /****************************************************************************** |
| 6933 | * Check if Downshift occured |
| 6934 | * |
| 6935 | * hw - Struct containing variables accessed by shared code |
| 6936 | * downshift - output parameter : 0 - No Downshift ocured. |
| 6937 | * 1 - Downshift ocured. |
| 6938 | * |
| 6939 | * returns: - E1000_ERR_XXX |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 6940 | * E1000_SUCCESS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6941 | * |
| 6942 | * For phy's older then IGP, this function reads the Downshift bit in the Phy |
| 6943 | * Specific Status register. For IGP phy's, it reads the Downgrade bit in the |
| 6944 | * Link Health register. In IGP this bit is latched high, so the driver must |
| 6945 | * read it immediately after link is established. |
| 6946 | *****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 6947 | static int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6948 | e1000_check_downshift(struct e1000_hw *hw) |
| 6949 | { |
| 6950 | int32_t ret_val; |
| 6951 | uint16_t phy_data; |
| 6952 | |
| 6953 | DEBUGFUNC("e1000_check_downshift"); |
| 6954 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6955 | if (hw->phy_type == e1000_phy_igp || |
| 6956 | hw->phy_type == e1000_phy_igp_3 || |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6957 | hw->phy_type == e1000_phy_igp_2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6958 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH, |
| 6959 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6960 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6961 | return ret_val; |
| 6962 | |
| 6963 | hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 6964 | } else if ((hw->phy_type == e1000_phy_m88) || |
| 6965 | (hw->phy_type == e1000_phy_gg82563)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6966 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 6967 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6968 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6969 | return ret_val; |
| 6970 | |
| 6971 | hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >> |
| 6972 | M88E1000_PSSR_DOWNSHIFT_SHIFT; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6973 | } else if (hw->phy_type == e1000_phy_ife) { |
| 6974 | /* e1000_phy_ife supports 10/100 speed only */ |
| 6975 | hw->speed_downgraded = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6976 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6978 | return E1000_SUCCESS; |
| 6979 | } |
| 6980 | |
| 6981 | /***************************************************************************** |
| 6982 | * |
| 6983 | * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a |
| 6984 | * gigabit link is achieved to improve link quality. |
| 6985 | * |
| 6986 | * hw: Struct containing variables accessed by shared code |
| 6987 | * |
| 6988 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 6989 | * E1000_SUCCESS at any other case. |
| 6990 | * |
| 6991 | ****************************************************************************/ |
| 6992 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 6993 | static int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6994 | e1000_config_dsp_after_link_change(struct e1000_hw *hw, |
| 6995 | boolean_t link_up) |
| 6996 | { |
| 6997 | int32_t ret_val; |
| 6998 | uint16_t phy_data, phy_saved_data, speed, duplex, i; |
| 6999 | uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = |
| 7000 | {IGP01E1000_PHY_AGC_PARAM_A, |
| 7001 | IGP01E1000_PHY_AGC_PARAM_B, |
| 7002 | IGP01E1000_PHY_AGC_PARAM_C, |
| 7003 | IGP01E1000_PHY_AGC_PARAM_D}; |
| 7004 | uint16_t min_length, max_length; |
| 7005 | |
| 7006 | DEBUGFUNC("e1000_config_dsp_after_link_change"); |
| 7007 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7008 | if (hw->phy_type != e1000_phy_igp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7009 | return E1000_SUCCESS; |
| 7010 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7011 | if (link_up) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7012 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7013 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7014 | DEBUGOUT("Error getting link speed and duplex\n"); |
| 7015 | return ret_val; |
| 7016 | } |
| 7017 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7018 | if (speed == SPEED_1000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7019 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7020 | ret_val = e1000_get_cable_length(hw, &min_length, &max_length); |
| 7021 | if (ret_val) |
| 7022 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7023 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7024 | if ((hw->dsp_config_state == e1000_dsp_config_enabled) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7025 | min_length >= e1000_igp_cable_length_50) { |
| 7026 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7027 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7028 | ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], |
| 7029 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7030 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7031 | return ret_val; |
| 7032 | |
| 7033 | phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX; |
| 7034 | |
| 7035 | ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i], |
| 7036 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7037 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7038 | return ret_val; |
| 7039 | } |
| 7040 | hw->dsp_config_state = e1000_dsp_config_activated; |
| 7041 | } |
| 7042 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7043 | if ((hw->ffe_config_state == e1000_ffe_config_enabled) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7044 | (min_length < e1000_igp_cable_length_50)) { |
| 7045 | |
| 7046 | uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20; |
| 7047 | uint32_t idle_errs = 0; |
| 7048 | |
| 7049 | /* clear previous idle error counts */ |
| 7050 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, |
| 7051 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7052 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7053 | return ret_val; |
| 7054 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7055 | for (i = 0; i < ffe_idle_err_timeout; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7056 | udelay(1000); |
| 7057 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, |
| 7058 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7059 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7060 | return ret_val; |
| 7061 | |
| 7062 | idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7063 | if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7064 | hw->ffe_config_state = e1000_ffe_config_active; |
| 7065 | |
| 7066 | ret_val = e1000_write_phy_reg(hw, |
| 7067 | IGP01E1000_PHY_DSP_FFE, |
| 7068 | IGP01E1000_PHY_DSP_FFE_CM_CP); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7069 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7070 | return ret_val; |
| 7071 | break; |
| 7072 | } |
| 7073 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7074 | if (idle_errs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7075 | ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100; |
| 7076 | } |
| 7077 | } |
| 7078 | } |
| 7079 | } else { |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7080 | if (hw->dsp_config_state == e1000_dsp_config_activated) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7081 | /* Save off the current value of register 0x2F5B to be restored at |
| 7082 | * the end of the routines. */ |
| 7083 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
| 7084 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7085 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7086 | return ret_val; |
| 7087 | |
| 7088 | /* Disable the PHY transmitter */ |
| 7089 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 7090 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7091 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7092 | return ret_val; |
| 7093 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7094 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7095 | |
| 7096 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 7097 | IGP01E1000_IEEE_FORCE_GIGA); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7098 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7099 | return ret_val; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7100 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7101 | ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7102 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7103 | return ret_val; |
| 7104 | |
| 7105 | phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX; |
| 7106 | phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS; |
| 7107 | |
| 7108 | ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7109 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7110 | return ret_val; |
| 7111 | } |
| 7112 | |
| 7113 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 7114 | IGP01E1000_IEEE_RESTART_AUTONEG); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7115 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7116 | return ret_val; |
| 7117 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7118 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7119 | |
| 7120 | /* Now enable the transmitter */ |
| 7121 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
| 7122 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7123 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7124 | return ret_val; |
| 7125 | |
| 7126 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 7127 | } |
| 7128 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7129 | if (hw->ffe_config_state == e1000_ffe_config_active) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7130 | /* Save off the current value of register 0x2F5B to be restored at |
| 7131 | * the end of the routines. */ |
| 7132 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
| 7133 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7134 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7135 | return ret_val; |
| 7136 | |
| 7137 | /* Disable the PHY transmitter */ |
| 7138 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 7139 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7140 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7141 | return ret_val; |
| 7142 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7143 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7144 | |
| 7145 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 7146 | IGP01E1000_IEEE_FORCE_GIGA); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7147 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7148 | return ret_val; |
| 7149 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE, |
| 7150 | IGP01E1000_PHY_DSP_FFE_DEFAULT); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7151 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7152 | return ret_val; |
| 7153 | |
| 7154 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 7155 | IGP01E1000_IEEE_RESTART_AUTONEG); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7156 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7157 | return ret_val; |
| 7158 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7159 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7160 | |
| 7161 | /* Now enable the transmitter */ |
| 7162 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
| 7163 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7164 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7165 | return ret_val; |
| 7166 | |
| 7167 | hw->ffe_config_state = e1000_ffe_config_enabled; |
| 7168 | } |
| 7169 | } |
| 7170 | return E1000_SUCCESS; |
| 7171 | } |
| 7172 | |
| 7173 | /***************************************************************************** |
| 7174 | * Set PHY to class A mode |
| 7175 | * Assumes the following operations will follow to enable the new class mode. |
| 7176 | * 1. Do a PHY soft reset |
| 7177 | * 2. Restart auto-negotiation or force link. |
| 7178 | * |
| 7179 | * hw - Struct containing variables accessed by shared code |
| 7180 | ****************************************************************************/ |
| 7181 | static int32_t |
| 7182 | e1000_set_phy_mode(struct e1000_hw *hw) |
| 7183 | { |
| 7184 | int32_t ret_val; |
| 7185 | uint16_t eeprom_data; |
| 7186 | |
| 7187 | DEBUGFUNC("e1000_set_phy_mode"); |
| 7188 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7189 | if ((hw->mac_type == e1000_82545_rev_3) && |
| 7190 | (hw->media_type == e1000_media_type_copper)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7191 | ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7192 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7193 | return ret_val; |
| 7194 | } |
| 7195 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7196 | if ((eeprom_data != EEPROM_RESERVED_WORD) && |
| 7197 | (eeprom_data & EEPROM_PHY_CLASS_A)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7198 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7199 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7200 | return ret_val; |
| 7201 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7202 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7203 | return ret_val; |
| 7204 | |
| 7205 | hw->phy_reset_disable = FALSE; |
| 7206 | } |
| 7207 | } |
| 7208 | |
| 7209 | return E1000_SUCCESS; |
| 7210 | } |
| 7211 | |
| 7212 | /***************************************************************************** |
| 7213 | * |
| 7214 | * This function sets the lplu state according to the active flag. When |
| 7215 | * activating lplu this function also disables smart speed and vise versa. |
| 7216 | * lplu will not be activated unless the device autonegotiation advertisment |
| 7217 | * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes. |
| 7218 | * hw: Struct containing variables accessed by shared code |
| 7219 | * active - true to enable lplu false to disable lplu. |
| 7220 | * |
| 7221 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 7222 | * E1000_SUCCESS at any other case. |
| 7223 | * |
| 7224 | ****************************************************************************/ |
| 7225 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 7226 | static int32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7227 | e1000_set_d3_lplu_state(struct e1000_hw *hw, |
| 7228 | boolean_t active) |
| 7229 | { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7230 | uint32_t phy_ctrl = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7231 | int32_t ret_val; |
| 7232 | uint16_t phy_data; |
| 7233 | DEBUGFUNC("e1000_set_d3_lplu_state"); |
| 7234 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7235 | if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2 |
| 7236 | && hw->phy_type != e1000_phy_igp_3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7237 | return E1000_SUCCESS; |
| 7238 | |
| 7239 | /* During driver activity LPLU should not be used or it will attain link |
| 7240 | * from the lowest speeds starting from 10Mbps. The capability is used for |
| 7241 | * Dx transitions and states */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7242 | if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7243 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7244 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7245 | return ret_val; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7246 | } else if (hw->mac_type == e1000_ich8lan) { |
| 7247 | /* MAC writes into PHY register based on the state transition |
| 7248 | * and start auto-negotiation. SW driver can overwrite the settings |
| 7249 | * in CSR PHY power control E1000_PHY_CTRL register. */ |
| 7250 | phy_ctrl = E1000_READ_REG(hw, PHY_CTRL); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7251 | } else { |
| 7252 | ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7253 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7254 | return ret_val; |
| 7255 | } |
| 7256 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7257 | if (!active) { |
| 7258 | if (hw->mac_type == e1000_82541_rev_2 || |
| 7259 | hw->mac_type == e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7260 | phy_data &= ~IGP01E1000_GMII_FLEX_SPD; |
| 7261 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7262 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7263 | return ret_val; |
| 7264 | } else { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7265 | if (hw->mac_type == e1000_ich8lan) { |
| 7266 | phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU; |
| 7267 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
| 7268 | } else { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7269 | phy_data &= ~IGP02E1000_PM_D3_LPLU; |
| 7270 | ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
| 7271 | phy_data); |
| 7272 | if (ret_val) |
| 7273 | return ret_val; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7274 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7275 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7276 | |
| 7277 | /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during |
| 7278 | * Dx states where the power conservation is most important. During |
| 7279 | * driver activity we should enable SmartSpeed, so performance is |
| 7280 | * maintained. */ |
| 7281 | if (hw->smart_speed == e1000_smart_speed_on) { |
| 7282 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7283 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7284 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7285 | return ret_val; |
| 7286 | |
| 7287 | phy_data |= IGP01E1000_PSCFR_SMART_SPEED; |
| 7288 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7289 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7290 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7291 | return ret_val; |
| 7292 | } else if (hw->smart_speed == e1000_smart_speed_off) { |
| 7293 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7294 | &phy_data); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 7295 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7296 | return ret_val; |
| 7297 | |
| 7298 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 7299 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7300 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7301 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7302 | return ret_val; |
| 7303 | } |
| 7304 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7305 | } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) || |
| 7306 | (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) || |
| 7307 | (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7308 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7309 | if (hw->mac_type == e1000_82541_rev_2 || |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7310 | hw->mac_type == e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7311 | phy_data |= IGP01E1000_GMII_FLEX_SPD; |
| 7312 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7313 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7314 | return ret_val; |
| 7315 | } else { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7316 | if (hw->mac_type == e1000_ich8lan) { |
| 7317 | phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU; |
| 7318 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
| 7319 | } else { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7320 | phy_data |= IGP02E1000_PM_D3_LPLU; |
| 7321 | ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
| 7322 | phy_data); |
| 7323 | if (ret_val) |
| 7324 | return ret_val; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7325 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7326 | } |
| 7327 | |
| 7328 | /* When LPLU is enabled we should disable SmartSpeed */ |
| 7329 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7330 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7331 | return ret_val; |
| 7332 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7333 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 7334 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7335 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7336 | return ret_val; |
| 7337 | |
| 7338 | } |
| 7339 | return E1000_SUCCESS; |
| 7340 | } |
| 7341 | |
| 7342 | /***************************************************************************** |
| 7343 | * |
| 7344 | * This function sets the lplu d0 state according to the active flag. When |
| 7345 | * activating lplu this function also disables smart speed and vise versa. |
| 7346 | * lplu will not be activated unless the device autonegotiation advertisment |
| 7347 | * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes. |
| 7348 | * hw: Struct containing variables accessed by shared code |
| 7349 | * active - true to enable lplu false to disable lplu. |
| 7350 | * |
| 7351 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 7352 | * E1000_SUCCESS at any other case. |
| 7353 | * |
| 7354 | ****************************************************************************/ |
| 7355 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 7356 | static int32_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7357 | e1000_set_d0_lplu_state(struct e1000_hw *hw, |
| 7358 | boolean_t active) |
| 7359 | { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7360 | uint32_t phy_ctrl = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7361 | int32_t ret_val; |
| 7362 | uint16_t phy_data; |
| 7363 | DEBUGFUNC("e1000_set_d0_lplu_state"); |
| 7364 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7365 | if (hw->mac_type <= e1000_82547_rev_2) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7366 | return E1000_SUCCESS; |
| 7367 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7368 | if (hw->mac_type == e1000_ich8lan) { |
| 7369 | phy_ctrl = E1000_READ_REG(hw, PHY_CTRL); |
| 7370 | } else { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7371 | ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7372 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7373 | return ret_val; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7374 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7375 | |
| 7376 | if (!active) { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7377 | if (hw->mac_type == e1000_ich8lan) { |
| 7378 | phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU; |
| 7379 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
| 7380 | } else { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7381 | phy_data &= ~IGP02E1000_PM_D0_LPLU; |
| 7382 | ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 7383 | if (ret_val) |
| 7384 | return ret_val; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7385 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7386 | |
| 7387 | /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during |
| 7388 | * Dx states where the power conservation is most important. During |
| 7389 | * driver activity we should enable SmartSpeed, so performance is |
| 7390 | * maintained. */ |
| 7391 | if (hw->smart_speed == e1000_smart_speed_on) { |
| 7392 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7393 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7394 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7395 | return ret_val; |
| 7396 | |
| 7397 | phy_data |= IGP01E1000_PSCFR_SMART_SPEED; |
| 7398 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7399 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7400 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7401 | return ret_val; |
| 7402 | } else if (hw->smart_speed == e1000_smart_speed_off) { |
| 7403 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7404 | &phy_data); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 7405 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7406 | return ret_val; |
| 7407 | |
| 7408 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 7409 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7410 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7411 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7412 | return ret_val; |
| 7413 | } |
| 7414 | |
| 7415 | |
| 7416 | } else { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 7417 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7418 | if (hw->mac_type == e1000_ich8lan) { |
| 7419 | phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU; |
| 7420 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
| 7421 | } else { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 7422 | phy_data |= IGP02E1000_PM_D0_LPLU; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7423 | ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 7424 | if (ret_val) |
| 7425 | return ret_val; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7426 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7428 | /* When LPLU is enabled we should disable SmartSpeed */ |
| 7429 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7430 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7431 | return ret_val; |
| 7432 | |
| 7433 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 7434 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7435 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7436 | return ret_val; |
| 7437 | |
| 7438 | } |
| 7439 | return E1000_SUCCESS; |
| 7440 | } |
| 7441 | |
| 7442 | /****************************************************************************** |
| 7443 | * Change VCO speed register to improve Bit Error Rate performance of SERDES. |
| 7444 | * |
| 7445 | * hw - Struct containing variables accessed by shared code |
| 7446 | *****************************************************************************/ |
| 7447 | static int32_t |
| 7448 | e1000_set_vco_speed(struct e1000_hw *hw) |
| 7449 | { |
| 7450 | int32_t ret_val; |
| 7451 | uint16_t default_page = 0; |
| 7452 | uint16_t phy_data; |
| 7453 | |
| 7454 | DEBUGFUNC("e1000_set_vco_speed"); |
| 7455 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7456 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7457 | case e1000_82545_rev_3: |
| 7458 | case e1000_82546_rev_3: |
| 7459 | break; |
| 7460 | default: |
| 7461 | return E1000_SUCCESS; |
| 7462 | } |
| 7463 | |
| 7464 | /* Set PHY register 30, page 5, bit 8 to 0 */ |
| 7465 | |
| 7466 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7467 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7468 | return ret_val; |
| 7469 | |
| 7470 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7471 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7472 | return ret_val; |
| 7473 | |
| 7474 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7475 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7476 | return ret_val; |
| 7477 | |
| 7478 | phy_data &= ~M88E1000_PHY_VCO_REG_BIT8; |
| 7479 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7480 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7481 | return ret_val; |
| 7482 | |
| 7483 | /* Set PHY register 30, page 4, bit 11 to 1 */ |
| 7484 | |
| 7485 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7486 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7487 | return ret_val; |
| 7488 | |
| 7489 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7490 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7491 | return ret_val; |
| 7492 | |
| 7493 | phy_data |= M88E1000_PHY_VCO_REG_BIT11; |
| 7494 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7495 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7496 | return ret_val; |
| 7497 | |
| 7498 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7499 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7500 | return ret_val; |
| 7501 | |
| 7502 | return E1000_SUCCESS; |
| 7503 | } |
| 7504 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7505 | |
| 7506 | /***************************************************************************** |
| 7507 | * This function reads the cookie from ARC ram. |
| 7508 | * |
| 7509 | * returns: - E1000_SUCCESS . |
| 7510 | ****************************************************************************/ |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 7511 | static int32_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7512 | e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer) |
| 7513 | { |
| 7514 | uint8_t i; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 7515 | uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7516 | uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH; |
| 7517 | |
| 7518 | length = (length >> 2); |
| 7519 | offset = (offset >> 2); |
| 7520 | |
| 7521 | for (i = 0; i < length; i++) { |
| 7522 | *((uint32_t *) buffer + i) = |
| 7523 | E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i); |
| 7524 | } |
| 7525 | return E1000_SUCCESS; |
| 7526 | } |
| 7527 | |
| 7528 | |
| 7529 | /***************************************************************************** |
| 7530 | * This function checks whether the HOST IF is enabled for command operaton |
| 7531 | * and also checks whether the previous command is completed. |
| 7532 | * It busy waits in case of previous command is not completed. |
| 7533 | * |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 7534 | * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7535 | * timeout |
| 7536 | * - E1000_SUCCESS for success. |
| 7537 | ****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 7538 | static int32_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7539 | e1000_mng_enable_host_if(struct e1000_hw * hw) |
| 7540 | { |
| 7541 | uint32_t hicr; |
| 7542 | uint8_t i; |
| 7543 | |
| 7544 | /* Check that the host interface is enabled. */ |
| 7545 | hicr = E1000_READ_REG(hw, HICR); |
| 7546 | if ((hicr & E1000_HICR_EN) == 0) { |
| 7547 | DEBUGOUT("E1000_HOST_EN bit disabled.\n"); |
| 7548 | return -E1000_ERR_HOST_INTERFACE_COMMAND; |
| 7549 | } |
| 7550 | /* check the previous command is completed */ |
| 7551 | for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) { |
| 7552 | hicr = E1000_READ_REG(hw, HICR); |
| 7553 | if (!(hicr & E1000_HICR_C)) |
| 7554 | break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7555 | mdelay(1); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7556 | } |
| 7557 | |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 7558 | if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7559 | DEBUGOUT("Previous command timeout failed .\n"); |
| 7560 | return -E1000_ERR_HOST_INTERFACE_COMMAND; |
| 7561 | } |
| 7562 | return E1000_SUCCESS; |
| 7563 | } |
| 7564 | |
| 7565 | /***************************************************************************** |
| 7566 | * This function writes the buffer content at the offset given on the host if. |
| 7567 | * It also does alignment considerations to do the writes in most efficient way. |
| 7568 | * Also fills up the sum of the buffer in *buffer parameter. |
| 7569 | * |
| 7570 | * returns - E1000_SUCCESS for success. |
| 7571 | ****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 7572 | static int32_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7573 | e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer, |
| 7574 | uint16_t length, uint16_t offset, uint8_t *sum) |
| 7575 | { |
| 7576 | uint8_t *tmp; |
| 7577 | uint8_t *bufptr = buffer; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7578 | uint32_t data = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7579 | uint16_t remaining, i, j, prev_bytes; |
| 7580 | |
| 7581 | /* sum = only sum of the data and it is not checksum */ |
| 7582 | |
| 7583 | if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) { |
| 7584 | return -E1000_ERR_PARAM; |
| 7585 | } |
| 7586 | |
| 7587 | tmp = (uint8_t *)&data; |
| 7588 | prev_bytes = offset & 0x3; |
| 7589 | offset &= 0xFFFC; |
| 7590 | offset >>= 2; |
| 7591 | |
| 7592 | if (prev_bytes) { |
| 7593 | data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset); |
| 7594 | for (j = prev_bytes; j < sizeof(uint32_t); j++) { |
| 7595 | *(tmp + j) = *bufptr++; |
| 7596 | *sum += *(tmp + j); |
| 7597 | } |
| 7598 | E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data); |
| 7599 | length -= j - prev_bytes; |
| 7600 | offset++; |
| 7601 | } |
| 7602 | |
| 7603 | remaining = length & 0x3; |
| 7604 | length -= remaining; |
| 7605 | |
| 7606 | /* Calculate length in DWORDs */ |
| 7607 | length >>= 2; |
| 7608 | |
| 7609 | /* The device driver writes the relevant command block into the |
| 7610 | * ram area. */ |
| 7611 | for (i = 0; i < length; i++) { |
| 7612 | for (j = 0; j < sizeof(uint32_t); j++) { |
| 7613 | *(tmp + j) = *bufptr++; |
| 7614 | *sum += *(tmp + j); |
| 7615 | } |
| 7616 | |
| 7617 | E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data); |
| 7618 | } |
| 7619 | if (remaining) { |
| 7620 | for (j = 0; j < sizeof(uint32_t); j++) { |
| 7621 | if (j < remaining) |
| 7622 | *(tmp + j) = *bufptr++; |
| 7623 | else |
| 7624 | *(tmp + j) = 0; |
| 7625 | |
| 7626 | *sum += *(tmp + j); |
| 7627 | } |
| 7628 | E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data); |
| 7629 | } |
| 7630 | |
| 7631 | return E1000_SUCCESS; |
| 7632 | } |
| 7633 | |
| 7634 | |
| 7635 | /***************************************************************************** |
| 7636 | * This function writes the command header after does the checksum calculation. |
| 7637 | * |
| 7638 | * returns - E1000_SUCCESS for success. |
| 7639 | ****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 7640 | static int32_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7641 | e1000_mng_write_cmd_header(struct e1000_hw * hw, |
| 7642 | struct e1000_host_mng_command_header * hdr) |
| 7643 | { |
| 7644 | uint16_t i; |
| 7645 | uint8_t sum; |
| 7646 | uint8_t *buffer; |
| 7647 | |
| 7648 | /* Write the whole command header structure which includes sum of |
| 7649 | * the buffer */ |
| 7650 | |
| 7651 | uint16_t length = sizeof(struct e1000_host_mng_command_header); |
| 7652 | |
| 7653 | sum = hdr->checksum; |
| 7654 | hdr->checksum = 0; |
| 7655 | |
| 7656 | buffer = (uint8_t *) hdr; |
| 7657 | i = length; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7658 | while (i--) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7659 | sum += buffer[i]; |
| 7660 | |
| 7661 | hdr->checksum = 0 - sum; |
| 7662 | |
| 7663 | length >>= 2; |
| 7664 | /* The device driver writes the relevant command block into the ram area. */ |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 7665 | for (i = 0; i < length; i++) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7666 | E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i)); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 7667 | E1000_WRITE_FLUSH(hw); |
| 7668 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7669 | |
| 7670 | return E1000_SUCCESS; |
| 7671 | } |
| 7672 | |
| 7673 | |
| 7674 | /***************************************************************************** |
| 7675 | * This function indicates to ARC that a new command is pending which completes |
| 7676 | * one write operation by the driver. |
| 7677 | * |
| 7678 | * returns - E1000_SUCCESS for success. |
| 7679 | ****************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 7680 | static int32_t |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7681 | e1000_mng_write_commit(struct e1000_hw * hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7682 | { |
| 7683 | uint32_t hicr; |
| 7684 | |
| 7685 | hicr = E1000_READ_REG(hw, HICR); |
| 7686 | /* Setting this bit tells the ARC that a new command is pending. */ |
| 7687 | E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C); |
| 7688 | |
| 7689 | return E1000_SUCCESS; |
| 7690 | } |
| 7691 | |
| 7692 | |
| 7693 | /***************************************************************************** |
| 7694 | * This function checks the mode of the firmware. |
| 7695 | * |
| 7696 | * returns - TRUE when the mode is IAMT or FALSE. |
| 7697 | ****************************************************************************/ |
| 7698 | boolean_t |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7699 | e1000_check_mng_mode(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7700 | { |
| 7701 | uint32_t fwsm; |
| 7702 | |
| 7703 | fwsm = E1000_READ_REG(hw, FWSM); |
| 7704 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7705 | if (hw->mac_type == e1000_ich8lan) { |
| 7706 | if ((fwsm & E1000_FWSM_MODE_MASK) == |
| 7707 | (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT)) |
| 7708 | return TRUE; |
| 7709 | } else if ((fwsm & E1000_FWSM_MODE_MASK) == |
| 7710 | (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7711 | return TRUE; |
| 7712 | |
| 7713 | return FALSE; |
| 7714 | } |
| 7715 | |
| 7716 | |
| 7717 | /***************************************************************************** |
| 7718 | * This function writes the dhcp info . |
| 7719 | ****************************************************************************/ |
| 7720 | int32_t |
| 7721 | e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 7722 | uint16_t length) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7723 | { |
| 7724 | int32_t ret_val; |
| 7725 | struct e1000_host_mng_command_header hdr; |
| 7726 | |
| 7727 | hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD; |
| 7728 | hdr.command_length = length; |
| 7729 | hdr.reserved1 = 0; |
| 7730 | hdr.reserved2 = 0; |
| 7731 | hdr.checksum = 0; |
| 7732 | |
| 7733 | ret_val = e1000_mng_enable_host_if(hw); |
| 7734 | if (ret_val == E1000_SUCCESS) { |
| 7735 | ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr), |
| 7736 | &(hdr.checksum)); |
| 7737 | if (ret_val == E1000_SUCCESS) { |
| 7738 | ret_val = e1000_mng_write_cmd_header(hw, &hdr); |
| 7739 | if (ret_val == E1000_SUCCESS) |
| 7740 | ret_val = e1000_mng_write_commit(hw); |
| 7741 | } |
| 7742 | } |
| 7743 | return ret_val; |
| 7744 | } |
| 7745 | |
| 7746 | |
| 7747 | /***************************************************************************** |
| 7748 | * This function calculates the checksum. |
| 7749 | * |
| 7750 | * returns - checksum of buffer contents. |
| 7751 | ****************************************************************************/ |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 7752 | static uint8_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7753 | e1000_calculate_mng_checksum(char *buffer, uint32_t length) |
| 7754 | { |
| 7755 | uint8_t sum = 0; |
| 7756 | uint32_t i; |
| 7757 | |
| 7758 | if (!buffer) |
| 7759 | return 0; |
| 7760 | |
| 7761 | for (i=0; i < length; i++) |
| 7762 | sum += buffer[i]; |
| 7763 | |
| 7764 | return (uint8_t) (0 - sum); |
| 7765 | } |
| 7766 | |
| 7767 | /***************************************************************************** |
| 7768 | * This function checks whether tx pkt filtering needs to be enabled or not. |
| 7769 | * |
| 7770 | * returns - TRUE for packet filtering or FALSE. |
| 7771 | ****************************************************************************/ |
| 7772 | boolean_t |
| 7773 | e1000_enable_tx_pkt_filtering(struct e1000_hw *hw) |
| 7774 | { |
| 7775 | /* called in init as well as watchdog timer functions */ |
| 7776 | |
| 7777 | int32_t ret_val, checksum; |
| 7778 | boolean_t tx_filter = FALSE; |
| 7779 | struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie); |
| 7780 | uint8_t *buffer = (uint8_t *) &(hw->mng_cookie); |
| 7781 | |
| 7782 | if (e1000_check_mng_mode(hw)) { |
| 7783 | ret_val = e1000_mng_enable_host_if(hw); |
| 7784 | if (ret_val == E1000_SUCCESS) { |
| 7785 | ret_val = e1000_host_if_read_cookie(hw, buffer); |
| 7786 | if (ret_val == E1000_SUCCESS) { |
| 7787 | checksum = hdr->checksum; |
| 7788 | hdr->checksum = 0; |
| 7789 | if ((hdr->signature == E1000_IAMT_SIGNATURE) && |
| 7790 | checksum == e1000_calculate_mng_checksum((char *)buffer, |
| 7791 | E1000_MNG_DHCP_COOKIE_LENGTH)) { |
| 7792 | if (hdr->status & |
| 7793 | E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT) |
| 7794 | tx_filter = TRUE; |
| 7795 | } else |
| 7796 | tx_filter = TRUE; |
| 7797 | } else |
| 7798 | tx_filter = TRUE; |
| 7799 | } |
| 7800 | } |
| 7801 | |
| 7802 | hw->tx_pkt_filtering = tx_filter; |
| 7803 | return tx_filter; |
| 7804 | } |
| 7805 | |
| 7806 | /****************************************************************************** |
| 7807 | * Verifies the hardware needs to allow ARPs to be processed by the host |
| 7808 | * |
| 7809 | * hw - Struct containing variables accessed by shared code |
| 7810 | * |
| 7811 | * returns: - TRUE/FALSE |
| 7812 | * |
| 7813 | *****************************************************************************/ |
| 7814 | uint32_t |
| 7815 | e1000_enable_mng_pass_thru(struct e1000_hw *hw) |
| 7816 | { |
| 7817 | uint32_t manc; |
| 7818 | uint32_t fwsm, factps; |
| 7819 | |
| 7820 | if (hw->asf_firmware_present) { |
| 7821 | manc = E1000_READ_REG(hw, MANC); |
| 7822 | |
| 7823 | if (!(manc & E1000_MANC_RCV_TCO_EN) || |
| 7824 | !(manc & E1000_MANC_EN_MAC_ADDR_FILTER)) |
| 7825 | return FALSE; |
| 7826 | if (e1000_arc_subsystem_valid(hw) == TRUE) { |
| 7827 | fwsm = E1000_READ_REG(hw, FWSM); |
| 7828 | factps = E1000_READ_REG(hw, FACTPS); |
| 7829 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 7830 | if ((((fwsm & E1000_FWSM_MODE_MASK) >> E1000_FWSM_MODE_SHIFT) == |
| 7831 | e1000_mng_mode_pt) && !(factps & E1000_FACTPS_MNGCG)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7832 | return TRUE; |
| 7833 | } else |
| 7834 | if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN)) |
| 7835 | return TRUE; |
| 7836 | } |
| 7837 | return FALSE; |
| 7838 | } |
| 7839 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7840 | static int32_t |
| 7841 | e1000_polarity_reversal_workaround(struct e1000_hw *hw) |
| 7842 | { |
| 7843 | int32_t ret_val; |
| 7844 | uint16_t mii_status_reg; |
| 7845 | uint16_t i; |
| 7846 | |
| 7847 | /* Polarity reversal workaround for forced 10F/10H links. */ |
| 7848 | |
| 7849 | /* Disable the transmitter on the PHY */ |
| 7850 | |
| 7851 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7852 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7853 | return ret_val; |
| 7854 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7855 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7856 | return ret_val; |
| 7857 | |
| 7858 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7859 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7860 | return ret_val; |
| 7861 | |
| 7862 | /* This loop will early-out if the NO link condition has been met. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7863 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7864 | /* Read the MII Status Register and wait for Link Status bit |
| 7865 | * to be clear. |
| 7866 | */ |
| 7867 | |
| 7868 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7869 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7870 | return ret_val; |
| 7871 | |
| 7872 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7873 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7874 | return ret_val; |
| 7875 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7876 | if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7877 | mdelay(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7878 | } |
| 7879 | |
| 7880 | /* Recommended delay time after link has been lost */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7881 | mdelay(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7882 | |
| 7883 | /* Now we will re-enable th transmitter on the PHY */ |
| 7884 | |
| 7885 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7886 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7887 | return ret_val; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7888 | mdelay(50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7889 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7890 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7891 | return ret_val; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7892 | mdelay(50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7893 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7894 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7895 | return ret_val; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7896 | mdelay(50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7897 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7898 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7899 | return ret_val; |
| 7900 | |
| 7901 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7902 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7903 | return ret_val; |
| 7904 | |
| 7905 | /* This loop will early-out if the link condition has been met. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7906 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7907 | /* Read the MII Status Register and wait for Link Status bit |
| 7908 | * to be set. |
| 7909 | */ |
| 7910 | |
| 7911 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7912 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7913 | return ret_val; |
| 7914 | |
| 7915 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7916 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7917 | return ret_val; |
| 7918 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7919 | if (mii_status_reg & MII_SR_LINK_STATUS) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7920 | mdelay(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7921 | } |
| 7922 | return E1000_SUCCESS; |
| 7923 | } |
| 7924 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7925 | /*************************************************************************** |
| 7926 | * |
| 7927 | * Disables PCI-Express master access. |
| 7928 | * |
| 7929 | * hw: Struct containing variables accessed by shared code |
| 7930 | * |
| 7931 | * returns: - none. |
| 7932 | * |
| 7933 | ***************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 7934 | static void |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7935 | e1000_set_pci_express_master_disable(struct e1000_hw *hw) |
| 7936 | { |
| 7937 | uint32_t ctrl; |
| 7938 | |
| 7939 | DEBUGFUNC("e1000_set_pci_express_master_disable"); |
| 7940 | |
| 7941 | if (hw->bus_type != e1000_bus_type_pci_express) |
| 7942 | return; |
| 7943 | |
| 7944 | ctrl = E1000_READ_REG(hw, CTRL); |
| 7945 | ctrl |= E1000_CTRL_GIO_MASTER_DISABLE; |
| 7946 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 7947 | } |
| 7948 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7949 | /******************************************************************************* |
| 7950 | * |
| 7951 | * Disables PCI-Express master access and verifies there are no pending requests |
| 7952 | * |
| 7953 | * hw: Struct containing variables accessed by shared code |
| 7954 | * |
| 7955 | * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't |
| 7956 | * caused the master requests to be disabled. |
| 7957 | * E1000_SUCCESS master requests disabled. |
| 7958 | * |
| 7959 | ******************************************************************************/ |
| 7960 | int32_t |
| 7961 | e1000_disable_pciex_master(struct e1000_hw *hw) |
| 7962 | { |
| 7963 | int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */ |
| 7964 | |
| 7965 | DEBUGFUNC("e1000_disable_pciex_master"); |
| 7966 | |
| 7967 | if (hw->bus_type != e1000_bus_type_pci_express) |
| 7968 | return E1000_SUCCESS; |
| 7969 | |
| 7970 | e1000_set_pci_express_master_disable(hw); |
| 7971 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7972 | while (timeout) { |
| 7973 | if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7974 | break; |
| 7975 | else |
| 7976 | udelay(100); |
| 7977 | timeout--; |
| 7978 | } |
| 7979 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7980 | if (!timeout) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7981 | DEBUGOUT("Master requests are pending.\n"); |
| 7982 | return -E1000_ERR_MASTER_REQUESTS_PENDING; |
| 7983 | } |
| 7984 | |
| 7985 | return E1000_SUCCESS; |
| 7986 | } |
| 7987 | |
| 7988 | /******************************************************************************* |
| 7989 | * |
| 7990 | * Check for EEPROM Auto Read bit done. |
| 7991 | * |
| 7992 | * hw: Struct containing variables accessed by shared code |
| 7993 | * |
| 7994 | * returns: - E1000_ERR_RESET if fail to reset MAC |
| 7995 | * E1000_SUCCESS at any other case. |
| 7996 | * |
| 7997 | ******************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 7998 | static int32_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7999 | e1000_get_auto_rd_done(struct e1000_hw *hw) |
| 8000 | { |
| 8001 | int32_t timeout = AUTO_READ_DONE_TIMEOUT; |
| 8002 | |
| 8003 | DEBUGFUNC("e1000_get_auto_rd_done"); |
| 8004 | |
| 8005 | switch (hw->mac_type) { |
| 8006 | default: |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 8007 | msleep(5); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8008 | break; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 8009 | case e1000_82571: |
| 8010 | case e1000_82572: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8011 | case e1000_82573: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8012 | case e1000_80003es2lan: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 8013 | case e1000_ich8lan: |
| 8014 | while (timeout) { |
| 8015 | if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) |
| 8016 | break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 8017 | else msleep(1); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8018 | timeout--; |
| 8019 | } |
| 8020 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 8021 | if (!timeout) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8022 | DEBUGOUT("Auto read by HW from EEPROM has not completed.\n"); |
| 8023 | return -E1000_ERR_RESET; |
| 8024 | } |
| 8025 | break; |
| 8026 | } |
| 8027 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 8028 | /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high. |
| 8029 | * Need to wait for PHY configuration completion before accessing NVM |
| 8030 | * and PHY. */ |
| 8031 | if (hw->mac_type == e1000_82573) |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 8032 | msleep(25); |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 8033 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8034 | return E1000_SUCCESS; |
| 8035 | } |
| 8036 | |
| 8037 | /*************************************************************************** |
| 8038 | * Checks if the PHY configuration is done |
| 8039 | * |
| 8040 | * hw: Struct containing variables accessed by shared code |
| 8041 | * |
| 8042 | * returns: - E1000_ERR_RESET if fail to reset MAC |
| 8043 | * E1000_SUCCESS at any other case. |
| 8044 | * |
| 8045 | ***************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 8046 | static int32_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8047 | e1000_get_phy_cfg_done(struct e1000_hw *hw) |
| 8048 | { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 8049 | int32_t timeout = PHY_CFG_TIMEOUT; |
| 8050 | uint32_t cfg_mask = E1000_EEPROM_CFG_DONE; |
| 8051 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8052 | DEBUGFUNC("e1000_get_phy_cfg_done"); |
| 8053 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 8054 | switch (hw->mac_type) { |
| 8055 | default: |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 8056 | mdelay(10); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 8057 | break; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8058 | case e1000_80003es2lan: |
| 8059 | /* Separate *_CFG_DONE_* bit for each port */ |
| 8060 | if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) |
| 8061 | cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1; |
| 8062 | /* Fall Through */ |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 8063 | case e1000_82571: |
| 8064 | case e1000_82572: |
| 8065 | while (timeout) { |
| 8066 | if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask) |
| 8067 | break; |
| 8068 | else |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 8069 | msleep(1); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 8070 | timeout--; |
| 8071 | } |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 8072 | if (!timeout) { |
| 8073 | DEBUGOUT("MNG configuration cycle has not completed.\n"); |
| 8074 | return -E1000_ERR_RESET; |
| 8075 | } |
| 8076 | break; |
| 8077 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8078 | |
| 8079 | return E1000_SUCCESS; |
| 8080 | } |
| 8081 | |
| 8082 | /*************************************************************************** |
| 8083 | * |
| 8084 | * Using the combination of SMBI and SWESMBI semaphore bits when resetting |
| 8085 | * adapter or Eeprom access. |
| 8086 | * |
| 8087 | * hw: Struct containing variables accessed by shared code |
| 8088 | * |
| 8089 | * returns: - E1000_ERR_EEPROM if fail to access EEPROM. |
| 8090 | * E1000_SUCCESS at any other case. |
| 8091 | * |
| 8092 | ***************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 8093 | static int32_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8094 | e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw) |
| 8095 | { |
| 8096 | int32_t timeout; |
| 8097 | uint32_t swsm; |
| 8098 | |
| 8099 | DEBUGFUNC("e1000_get_hw_eeprom_semaphore"); |
| 8100 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 8101 | if (!hw->eeprom_semaphore_present) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8102 | return E1000_SUCCESS; |
| 8103 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8104 | if (hw->mac_type == e1000_80003es2lan) { |
| 8105 | /* Get the SW semaphore. */ |
| 8106 | if (e1000_get_software_semaphore(hw) != E1000_SUCCESS) |
| 8107 | return -E1000_ERR_EEPROM; |
| 8108 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8109 | |
| 8110 | /* Get the FW semaphore. */ |
| 8111 | timeout = hw->eeprom.word_size + 1; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 8112 | while (timeout) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8113 | swsm = E1000_READ_REG(hw, SWSM); |
| 8114 | swsm |= E1000_SWSM_SWESMBI; |
| 8115 | E1000_WRITE_REG(hw, SWSM, swsm); |
| 8116 | /* if we managed to set the bit we got the semaphore. */ |
| 8117 | swsm = E1000_READ_REG(hw, SWSM); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 8118 | if (swsm & E1000_SWSM_SWESMBI) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8119 | break; |
| 8120 | |
| 8121 | udelay(50); |
| 8122 | timeout--; |
| 8123 | } |
| 8124 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 8125 | if (!timeout) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8126 | /* Release semaphores */ |
| 8127 | e1000_put_hw_eeprom_semaphore(hw); |
| 8128 | DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n"); |
| 8129 | return -E1000_ERR_EEPROM; |
| 8130 | } |
| 8131 | |
| 8132 | return E1000_SUCCESS; |
| 8133 | } |
| 8134 | |
| 8135 | /*************************************************************************** |
| 8136 | * This function clears HW semaphore bits. |
| 8137 | * |
| 8138 | * hw: Struct containing variables accessed by shared code |
| 8139 | * |
| 8140 | * returns: - None. |
| 8141 | * |
| 8142 | ***************************************************************************/ |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 8143 | static void |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8144 | e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw) |
| 8145 | { |
| 8146 | uint32_t swsm; |
| 8147 | |
| 8148 | DEBUGFUNC("e1000_put_hw_eeprom_semaphore"); |
| 8149 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 8150 | if (!hw->eeprom_semaphore_present) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8151 | return; |
| 8152 | |
| 8153 | swsm = E1000_READ_REG(hw, SWSM); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8154 | if (hw->mac_type == e1000_80003es2lan) { |
| 8155 | /* Release both semaphores. */ |
| 8156 | swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI); |
| 8157 | } else |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 8158 | swsm &= ~(E1000_SWSM_SWESMBI); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8159 | E1000_WRITE_REG(hw, SWSM, swsm); |
| 8160 | } |
| 8161 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8162 | /*************************************************************************** |
| 8163 | * |
| 8164 | * Obtaining software semaphore bit (SMBI) before resetting PHY. |
| 8165 | * |
| 8166 | * hw: Struct containing variables accessed by shared code |
| 8167 | * |
| 8168 | * returns: - E1000_ERR_RESET if fail to obtain semaphore. |
| 8169 | * E1000_SUCCESS at any other case. |
| 8170 | * |
| 8171 | ***************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8172 | static int32_t |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8173 | e1000_get_software_semaphore(struct e1000_hw *hw) |
| 8174 | { |
| 8175 | int32_t timeout = hw->eeprom.word_size + 1; |
| 8176 | uint32_t swsm; |
| 8177 | |
| 8178 | DEBUGFUNC("e1000_get_software_semaphore"); |
| 8179 | |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 8180 | if (hw->mac_type != e1000_80003es2lan) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8181 | return E1000_SUCCESS; |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 8182 | } |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8183 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 8184 | while (timeout) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8185 | swsm = E1000_READ_REG(hw, SWSM); |
| 8186 | /* If SMBI bit cleared, it is now set and we hold the semaphore */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 8187 | if (!(swsm & E1000_SWSM_SMBI)) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8188 | break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 8189 | mdelay(1); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8190 | timeout--; |
| 8191 | } |
| 8192 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 8193 | if (!timeout) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8194 | DEBUGOUT("Driver can't access device - SMBI bit is set.\n"); |
| 8195 | return -E1000_ERR_RESET; |
| 8196 | } |
| 8197 | |
| 8198 | return E1000_SUCCESS; |
| 8199 | } |
| 8200 | |
| 8201 | /*************************************************************************** |
| 8202 | * |
| 8203 | * Release semaphore bit (SMBI). |
| 8204 | * |
| 8205 | * hw: Struct containing variables accessed by shared code |
| 8206 | * |
| 8207 | ***************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8208 | static void |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8209 | e1000_release_software_semaphore(struct e1000_hw *hw) |
| 8210 | { |
| 8211 | uint32_t swsm; |
| 8212 | |
| 8213 | DEBUGFUNC("e1000_release_software_semaphore"); |
| 8214 | |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 8215 | if (hw->mac_type != e1000_80003es2lan) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8216 | return; |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 8217 | } |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8218 | |
| 8219 | swsm = E1000_READ_REG(hw, SWSM); |
| 8220 | /* Release the SW semaphores.*/ |
| 8221 | swsm &= ~E1000_SWSM_SMBI; |
| 8222 | E1000_WRITE_REG(hw, SWSM, swsm); |
| 8223 | } |
| 8224 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8225 | /****************************************************************************** |
| 8226 | * Checks if PHY reset is blocked due to SOL/IDER session, for example. |
| 8227 | * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to |
| 8228 | * the caller to figure out how to deal with it. |
| 8229 | * |
| 8230 | * hw - Struct containing variables accessed by shared code |
| 8231 | * |
| 8232 | * returns: - E1000_BLK_PHY_RESET |
| 8233 | * E1000_SUCCESS |
| 8234 | * |
| 8235 | *****************************************************************************/ |
| 8236 | int32_t |
| 8237 | e1000_check_phy_reset_block(struct e1000_hw *hw) |
| 8238 | { |
| 8239 | uint32_t manc = 0; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 8240 | uint32_t fwsm = 0; |
| 8241 | |
| 8242 | if (hw->mac_type == e1000_ich8lan) { |
| 8243 | fwsm = E1000_READ_REG(hw, FWSM); |
| 8244 | return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS |
| 8245 | : E1000_BLK_PHY_RESET; |
| 8246 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 8247 | |
| 8248 | if (hw->mac_type > e1000_82547_rev_2) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8249 | manc = E1000_READ_REG(hw, MANC); |
| 8250 | return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ? |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 8251 | E1000_BLK_PHY_RESET : E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8252 | } |
| 8253 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 8254 | static uint8_t |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8255 | e1000_arc_subsystem_valid(struct e1000_hw *hw) |
| 8256 | { |
| 8257 | uint32_t fwsm; |
| 8258 | |
| 8259 | /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC |
| 8260 | * may not be provided a DMA clock when no manageability features are |
| 8261 | * enabled. We do not want to perform any reads/writes to these registers |
| 8262 | * if this is the case. We read FWSM to determine the manageability mode. |
| 8263 | */ |
| 8264 | switch (hw->mac_type) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 8265 | case e1000_82571: |
| 8266 | case e1000_82572: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8267 | case e1000_82573: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8268 | case e1000_80003es2lan: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8269 | fwsm = E1000_READ_REG(hw, FWSM); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 8270 | if ((fwsm & E1000_FWSM_MODE_MASK) != 0) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8271 | return TRUE; |
| 8272 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 8273 | case e1000_ich8lan: |
| 8274 | return TRUE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8275 | default: |
| 8276 | break; |
| 8277 | } |
| 8278 | return FALSE; |
| 8279 | } |
| 8280 | |
| 8281 | |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8282 | /****************************************************************************** |
| 8283 | * Configure PCI-Ex no-snoop |
| 8284 | * |
| 8285 | * hw - Struct containing variables accessed by shared code. |
| 8286 | * no_snoop - Bitmap of no-snoop events. |
| 8287 | * |
| 8288 | * returns: E1000_SUCCESS |
| 8289 | * |
| 8290 | *****************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8291 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8292 | e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop) |
| 8293 | { |
| 8294 | uint32_t gcr_reg = 0; |
| 8295 | |
| 8296 | DEBUGFUNC("e1000_set_pci_ex_no_snoop"); |
| 8297 | |
| 8298 | if (hw->bus_type == e1000_bus_type_unknown) |
| 8299 | e1000_get_bus_info(hw); |
| 8300 | |
| 8301 | if (hw->bus_type != e1000_bus_type_pci_express) |
| 8302 | return E1000_SUCCESS; |
| 8303 | |
| 8304 | if (no_snoop) { |
| 8305 | gcr_reg = E1000_READ_REG(hw, GCR); |
| 8306 | gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL); |
| 8307 | gcr_reg |= no_snoop; |
| 8308 | E1000_WRITE_REG(hw, GCR, gcr_reg); |
| 8309 | } |
| 8310 | if (hw->mac_type == e1000_ich8lan) { |
| 8311 | uint32_t ctrl_ext; |
| 8312 | |
| 8313 | E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL); |
| 8314 | |
| 8315 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 8316 | ctrl_ext |= E1000_CTRL_EXT_RO_DIS; |
| 8317 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 8318 | } |
| 8319 | |
| 8320 | return E1000_SUCCESS; |
| 8321 | } |
| 8322 | |
| 8323 | /*************************************************************************** |
| 8324 | * |
| 8325 | * Get software semaphore FLAG bit (SWFLAG). |
| 8326 | * SWFLAG is used to synchronize the access to all shared resource between |
| 8327 | * SW, FW and HW. |
| 8328 | * |
| 8329 | * hw: Struct containing variables accessed by shared code |
| 8330 | * |
| 8331 | ***************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8332 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8333 | e1000_get_software_flag(struct e1000_hw *hw) |
| 8334 | { |
| 8335 | int32_t timeout = PHY_CFG_TIMEOUT; |
| 8336 | uint32_t extcnf_ctrl; |
| 8337 | |
| 8338 | DEBUGFUNC("e1000_get_software_flag"); |
| 8339 | |
| 8340 | if (hw->mac_type == e1000_ich8lan) { |
| 8341 | while (timeout) { |
| 8342 | extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL); |
| 8343 | extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG; |
| 8344 | E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl); |
| 8345 | |
| 8346 | extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL); |
| 8347 | if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) |
| 8348 | break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 8349 | mdelay(1); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8350 | timeout--; |
| 8351 | } |
| 8352 | |
| 8353 | if (!timeout) { |
| 8354 | DEBUGOUT("FW or HW locks the resource too long.\n"); |
| 8355 | return -E1000_ERR_CONFIG; |
| 8356 | } |
| 8357 | } |
| 8358 | |
| 8359 | return E1000_SUCCESS; |
| 8360 | } |
| 8361 | |
| 8362 | /*************************************************************************** |
| 8363 | * |
| 8364 | * Release software semaphore FLAG bit (SWFLAG). |
| 8365 | * SWFLAG is used to synchronize the access to all shared resource between |
| 8366 | * SW, FW and HW. |
| 8367 | * |
| 8368 | * hw: Struct containing variables accessed by shared code |
| 8369 | * |
| 8370 | ***************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8371 | static void |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8372 | e1000_release_software_flag(struct e1000_hw *hw) |
| 8373 | { |
| 8374 | uint32_t extcnf_ctrl; |
| 8375 | |
| 8376 | DEBUGFUNC("e1000_release_software_flag"); |
| 8377 | |
| 8378 | if (hw->mac_type == e1000_ich8lan) { |
| 8379 | extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL); |
| 8380 | extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG; |
| 8381 | E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl); |
| 8382 | } |
| 8383 | |
| 8384 | return; |
| 8385 | } |
| 8386 | |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8387 | /****************************************************************************** |
| 8388 | * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access |
| 8389 | * register. |
| 8390 | * |
| 8391 | * hw - Struct containing variables accessed by shared code |
| 8392 | * offset - offset of word in the EEPROM to read |
| 8393 | * data - word read from the EEPROM |
| 8394 | * words - number of words to read |
| 8395 | *****************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8396 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8397 | e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, |
| 8398 | uint16_t *data) |
| 8399 | { |
| 8400 | int32_t error = E1000_SUCCESS; |
| 8401 | uint32_t flash_bank = 0; |
| 8402 | uint32_t act_offset = 0; |
| 8403 | uint32_t bank_offset = 0; |
| 8404 | uint16_t word = 0; |
| 8405 | uint16_t i = 0; |
| 8406 | |
| 8407 | /* We need to know which is the valid flash bank. In the event |
| 8408 | * that we didn't allocate eeprom_shadow_ram, we may not be |
| 8409 | * managing flash_bank. So it cannot be trusted and needs |
| 8410 | * to be updated with each read. |
| 8411 | */ |
| 8412 | /* Value of bit 22 corresponds to the flash bank we're on. */ |
| 8413 | flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0; |
| 8414 | |
| 8415 | /* Adjust offset appropriately if we're on bank 1 - adjust for word size */ |
| 8416 | bank_offset = flash_bank * (hw->flash_bank_size * 2); |
| 8417 | |
| 8418 | error = e1000_get_software_flag(hw); |
| 8419 | if (error != E1000_SUCCESS) |
| 8420 | return error; |
| 8421 | |
| 8422 | for (i = 0; i < words; i++) { |
| 8423 | if (hw->eeprom_shadow_ram != NULL && |
| 8424 | hw->eeprom_shadow_ram[offset+i].modified == TRUE) { |
| 8425 | data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word; |
| 8426 | } else { |
| 8427 | /* The NVM part needs a byte offset, hence * 2 */ |
| 8428 | act_offset = bank_offset + ((offset + i) * 2); |
| 8429 | error = e1000_read_ich8_word(hw, act_offset, &word); |
| 8430 | if (error != E1000_SUCCESS) |
| 8431 | break; |
| 8432 | data[i] = word; |
| 8433 | } |
| 8434 | } |
| 8435 | |
| 8436 | e1000_release_software_flag(hw); |
| 8437 | |
| 8438 | return error; |
| 8439 | } |
| 8440 | |
| 8441 | /****************************************************************************** |
| 8442 | * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access |
| 8443 | * register. Actually, writes are written to the shadow ram cache in the hw |
| 8444 | * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to |
| 8445 | * the NVM, which occurs when the NVM checksum is updated. |
| 8446 | * |
| 8447 | * hw - Struct containing variables accessed by shared code |
| 8448 | * offset - offset of word in the EEPROM to write |
| 8449 | * words - number of words to write |
| 8450 | * data - words to write to the EEPROM |
| 8451 | *****************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8452 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8453 | e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, |
| 8454 | uint16_t *data) |
| 8455 | { |
| 8456 | uint32_t i = 0; |
| 8457 | int32_t error = E1000_SUCCESS; |
| 8458 | |
| 8459 | error = e1000_get_software_flag(hw); |
| 8460 | if (error != E1000_SUCCESS) |
| 8461 | return error; |
| 8462 | |
| 8463 | /* A driver can write to the NVM only if it has eeprom_shadow_ram |
| 8464 | * allocated. Subsequent reads to the modified words are read from |
| 8465 | * this cached structure as well. Writes will only go into this |
| 8466 | * cached structure unless it's followed by a call to |
| 8467 | * e1000_update_eeprom_checksum() where it will commit the changes |
| 8468 | * and clear the "modified" field. |
| 8469 | */ |
| 8470 | if (hw->eeprom_shadow_ram != NULL) { |
| 8471 | for (i = 0; i < words; i++) { |
| 8472 | if ((offset + i) < E1000_SHADOW_RAM_WORDS) { |
| 8473 | hw->eeprom_shadow_ram[offset+i].modified = TRUE; |
| 8474 | hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i]; |
| 8475 | } else { |
| 8476 | error = -E1000_ERR_EEPROM; |
| 8477 | break; |
| 8478 | } |
| 8479 | } |
| 8480 | } else { |
| 8481 | /* Drivers have the option to not allocate eeprom_shadow_ram as long |
| 8482 | * as they don't perform any NVM writes. An attempt in doing so |
| 8483 | * will result in this error. |
| 8484 | */ |
| 8485 | error = -E1000_ERR_EEPROM; |
| 8486 | } |
| 8487 | |
| 8488 | e1000_release_software_flag(hw); |
| 8489 | |
| 8490 | return error; |
| 8491 | } |
| 8492 | |
| 8493 | /****************************************************************************** |
| 8494 | * This function does initial flash setup so that a new read/write/erase cycle |
| 8495 | * can be started. |
| 8496 | * |
| 8497 | * hw - The pointer to the hw structure |
| 8498 | ****************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8499 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8500 | e1000_ich8_cycle_init(struct e1000_hw *hw) |
| 8501 | { |
| 8502 | union ich8_hws_flash_status hsfsts; |
| 8503 | int32_t error = E1000_ERR_EEPROM; |
| 8504 | int32_t i = 0; |
| 8505 | |
| 8506 | DEBUGFUNC("e1000_ich8_cycle_init"); |
| 8507 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8508 | hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8509 | |
| 8510 | /* May be check the Flash Des Valid bit in Hw status */ |
| 8511 | if (hsfsts.hsf_status.fldesvalid == 0) { |
| 8512 | DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used."); |
| 8513 | return error; |
| 8514 | } |
| 8515 | |
| 8516 | /* Clear FCERR in Hw status by writing 1 */ |
| 8517 | /* Clear DAEL in Hw status by writing a 1 */ |
| 8518 | hsfsts.hsf_status.flcerr = 1; |
| 8519 | hsfsts.hsf_status.dael = 1; |
| 8520 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8521 | E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8522 | |
| 8523 | /* Either we should have a hardware SPI cycle in progress bit to check |
| 8524 | * against, in order to start a new cycle or FDONE bit should be changed |
| 8525 | * in the hardware so that it is 1 after harware reset, which can then be |
| 8526 | * used as an indication whether a cycle is in progress or has been |
| 8527 | * completed .. we should also have some software semaphore mechanism to |
| 8528 | * guard FDONE or the cycle in progress bit so that two threads access to |
| 8529 | * those bits can be sequentiallized or a way so that 2 threads dont |
| 8530 | * start the cycle at the same time */ |
| 8531 | |
| 8532 | if (hsfsts.hsf_status.flcinprog == 0) { |
| 8533 | /* There is no cycle running at present, so we can start a cycle */ |
| 8534 | /* Begin by setting Flash Cycle Done. */ |
| 8535 | hsfsts.hsf_status.flcdone = 1; |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8536 | E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8537 | error = E1000_SUCCESS; |
| 8538 | } else { |
| 8539 | /* otherwise poll for sometime so the current cycle has a chance |
| 8540 | * to end before giving up. */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8541 | for (i = 0; i < ICH_FLASH_COMMAND_TIMEOUT; i++) { |
| 8542 | hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8543 | if (hsfsts.hsf_status.flcinprog == 0) { |
| 8544 | error = E1000_SUCCESS; |
| 8545 | break; |
| 8546 | } |
| 8547 | udelay(1); |
| 8548 | } |
| 8549 | if (error == E1000_SUCCESS) { |
| 8550 | /* Successful in waiting for previous cycle to timeout, |
| 8551 | * now set the Flash Cycle Done. */ |
| 8552 | hsfsts.hsf_status.flcdone = 1; |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8553 | E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8554 | } else { |
| 8555 | DEBUGOUT("Flash controller busy, cannot get access"); |
| 8556 | } |
| 8557 | } |
| 8558 | return error; |
| 8559 | } |
| 8560 | |
| 8561 | /****************************************************************************** |
| 8562 | * This function starts a flash cycle and waits for its completion |
| 8563 | * |
| 8564 | * hw - The pointer to the hw structure |
| 8565 | ****************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8566 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8567 | e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout) |
| 8568 | { |
| 8569 | union ich8_hws_flash_ctrl hsflctl; |
| 8570 | union ich8_hws_flash_status hsfsts; |
| 8571 | int32_t error = E1000_ERR_EEPROM; |
| 8572 | uint32_t i = 0; |
| 8573 | |
| 8574 | /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8575 | hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8576 | hsflctl.hsf_ctrl.flcgo = 1; |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8577 | E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8578 | |
| 8579 | /* wait till FDONE bit is set to 1 */ |
| 8580 | do { |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8581 | hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8582 | if (hsfsts.hsf_status.flcdone == 1) |
| 8583 | break; |
| 8584 | udelay(1); |
| 8585 | i++; |
| 8586 | } while (i < timeout); |
| 8587 | if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) { |
| 8588 | error = E1000_SUCCESS; |
| 8589 | } |
| 8590 | return error; |
| 8591 | } |
| 8592 | |
| 8593 | /****************************************************************************** |
| 8594 | * Reads a byte or word from the NVM using the ICH8 flash access registers. |
| 8595 | * |
| 8596 | * hw - The pointer to the hw structure |
| 8597 | * index - The index of the byte or word to read. |
| 8598 | * size - Size of data to read, 1=byte 2=word |
| 8599 | * data - Pointer to the word to store the value read. |
| 8600 | *****************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8601 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8602 | e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index, |
| 8603 | uint32_t size, uint16_t* data) |
| 8604 | { |
| 8605 | union ich8_hws_flash_status hsfsts; |
| 8606 | union ich8_hws_flash_ctrl hsflctl; |
| 8607 | uint32_t flash_linear_address; |
| 8608 | uint32_t flash_data = 0; |
| 8609 | int32_t error = -E1000_ERR_EEPROM; |
| 8610 | int32_t count = 0; |
| 8611 | |
| 8612 | DEBUGFUNC("e1000_read_ich8_data"); |
| 8613 | |
| 8614 | if (size < 1 || size > 2 || data == 0x0 || |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8615 | index > ICH_FLASH_LINEAR_ADDR_MASK) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8616 | return error; |
| 8617 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8618 | flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) + |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8619 | hw->flash_base_addr; |
| 8620 | |
| 8621 | do { |
| 8622 | udelay(1); |
| 8623 | /* Steps */ |
| 8624 | error = e1000_ich8_cycle_init(hw); |
| 8625 | if (error != E1000_SUCCESS) |
| 8626 | break; |
| 8627 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8628 | hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8629 | /* 0b/1b corresponds to 1 or 2 byte size, respectively. */ |
| 8630 | hsflctl.hsf_ctrl.fldbcount = size - 1; |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8631 | hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ; |
| 8632 | E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8633 | |
| 8634 | /* Write the last 24 bits of index into Flash Linear address field in |
| 8635 | * Flash Address */ |
| 8636 | /* TODO: TBD maybe check the index against the size of flash */ |
| 8637 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8638 | E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8639 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8640 | error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8641 | |
| 8642 | /* Check if FCERR is set to 1, if set to 1, clear it and try the whole |
| 8643 | * sequence a few more times, else read in (shift in) the Flash Data0, |
| 8644 | * the order is least significant byte first msb to lsb */ |
| 8645 | if (error == E1000_SUCCESS) { |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8646 | flash_data = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8647 | if (size == 1) { |
| 8648 | *data = (uint8_t)(flash_data & 0x000000FF); |
| 8649 | } else if (size == 2) { |
| 8650 | *data = (uint16_t)(flash_data & 0x0000FFFF); |
| 8651 | } |
| 8652 | break; |
| 8653 | } else { |
| 8654 | /* If we've gotten here, then things are probably completely hosed, |
| 8655 | * but if the error condition is detected, it won't hurt to give |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8656 | * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times. |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8657 | */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8658 | hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8659 | if (hsfsts.hsf_status.flcerr == 1) { |
| 8660 | /* Repeat for some time before giving up. */ |
| 8661 | continue; |
| 8662 | } else if (hsfsts.hsf_status.flcdone == 0) { |
| 8663 | DEBUGOUT("Timeout error - flash cycle did not complete."); |
| 8664 | break; |
| 8665 | } |
| 8666 | } |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8667 | } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8668 | |
| 8669 | return error; |
| 8670 | } |
| 8671 | |
| 8672 | /****************************************************************************** |
| 8673 | * Writes One /two bytes to the NVM using the ICH8 flash access registers. |
| 8674 | * |
| 8675 | * hw - The pointer to the hw structure |
| 8676 | * index - The index of the byte/word to read. |
| 8677 | * size - Size of data to read, 1=byte 2=word |
| 8678 | * data - The byte(s) to write to the NVM. |
| 8679 | *****************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8680 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8681 | e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, |
| 8682 | uint16_t data) |
| 8683 | { |
| 8684 | union ich8_hws_flash_status hsfsts; |
| 8685 | union ich8_hws_flash_ctrl hsflctl; |
| 8686 | uint32_t flash_linear_address; |
| 8687 | uint32_t flash_data = 0; |
| 8688 | int32_t error = -E1000_ERR_EEPROM; |
| 8689 | int32_t count = 0; |
| 8690 | |
| 8691 | DEBUGFUNC("e1000_write_ich8_data"); |
| 8692 | |
| 8693 | if (size < 1 || size > 2 || data > size * 0xff || |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8694 | index > ICH_FLASH_LINEAR_ADDR_MASK) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8695 | return error; |
| 8696 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8697 | flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) + |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8698 | hw->flash_base_addr; |
| 8699 | |
| 8700 | do { |
| 8701 | udelay(1); |
| 8702 | /* Steps */ |
| 8703 | error = e1000_ich8_cycle_init(hw); |
| 8704 | if (error != E1000_SUCCESS) |
| 8705 | break; |
| 8706 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8707 | hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8708 | /* 0b/1b corresponds to 1 or 2 byte size, respectively. */ |
| 8709 | hsflctl.hsf_ctrl.fldbcount = size -1; |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8710 | hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE; |
| 8711 | E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8712 | |
| 8713 | /* Write the last 24 bits of index into Flash Linear address field in |
| 8714 | * Flash Address */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8715 | E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8716 | |
| 8717 | if (size == 1) |
| 8718 | flash_data = (uint32_t)data & 0x00FF; |
| 8719 | else |
| 8720 | flash_data = (uint32_t)data; |
| 8721 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8722 | E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8723 | |
| 8724 | /* check if FCERR is set to 1 , if set to 1, clear it and try the whole |
| 8725 | * sequence a few more times else done */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8726 | error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8727 | if (error == E1000_SUCCESS) { |
| 8728 | break; |
| 8729 | } else { |
| 8730 | /* If we're here, then things are most likely completely hosed, |
| 8731 | * but if the error condition is detected, it won't hurt to give |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8732 | * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times. |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8733 | */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8734 | hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8735 | if (hsfsts.hsf_status.flcerr == 1) { |
| 8736 | /* Repeat for some time before giving up. */ |
| 8737 | continue; |
| 8738 | } else if (hsfsts.hsf_status.flcdone == 0) { |
| 8739 | DEBUGOUT("Timeout error - flash cycle did not complete."); |
| 8740 | break; |
| 8741 | } |
| 8742 | } |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8743 | } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8744 | |
| 8745 | return error; |
| 8746 | } |
| 8747 | |
| 8748 | /****************************************************************************** |
| 8749 | * Reads a single byte from the NVM using the ICH8 flash access registers. |
| 8750 | * |
| 8751 | * hw - pointer to e1000_hw structure |
| 8752 | * index - The index of the byte to read. |
| 8753 | * data - Pointer to a byte to store the value read. |
| 8754 | *****************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8755 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8756 | e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data) |
| 8757 | { |
| 8758 | int32_t status = E1000_SUCCESS; |
| 8759 | uint16_t word = 0; |
| 8760 | |
| 8761 | status = e1000_read_ich8_data(hw, index, 1, &word); |
| 8762 | if (status == E1000_SUCCESS) { |
| 8763 | *data = (uint8_t)word; |
| 8764 | } |
| 8765 | |
| 8766 | return status; |
| 8767 | } |
| 8768 | |
| 8769 | /****************************************************************************** |
| 8770 | * Writes a single byte to the NVM using the ICH8 flash access registers. |
| 8771 | * Performs verification by reading back the value and then going through |
| 8772 | * a retry algorithm before giving up. |
| 8773 | * |
| 8774 | * hw - pointer to e1000_hw structure |
| 8775 | * index - The index of the byte to write. |
| 8776 | * byte - The byte to write to the NVM. |
| 8777 | *****************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8778 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8779 | e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte) |
| 8780 | { |
| 8781 | int32_t error = E1000_SUCCESS; |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8782 | int32_t program_retries = 0; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8783 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8784 | DEBUGOUT2("Byte := %2.2X Offset := %d\n", byte, index); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8785 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8786 | error = e1000_write_ich8_byte(hw, index, byte); |
| 8787 | |
| 8788 | if (error != E1000_SUCCESS) { |
| 8789 | for (program_retries = 0; program_retries < 100; program_retries++) { |
| 8790 | DEBUGOUT2("Retrying \t Byte := %2.2X Offset := %d\n", byte, index); |
| 8791 | error = e1000_write_ich8_byte(hw, index, byte); |
| 8792 | udelay(100); |
| 8793 | if (error == E1000_SUCCESS) |
| 8794 | break; |
| 8795 | } |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8796 | } |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8797 | |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8798 | if (program_retries == 100) |
| 8799 | error = E1000_ERR_EEPROM; |
| 8800 | |
| 8801 | return error; |
| 8802 | } |
| 8803 | |
| 8804 | /****************************************************************************** |
| 8805 | * Writes a single byte to the NVM using the ICH8 flash access registers. |
| 8806 | * |
| 8807 | * hw - pointer to e1000_hw structure |
| 8808 | * index - The index of the byte to read. |
| 8809 | * data - The byte to write to the NVM. |
| 8810 | *****************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8811 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8812 | e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data) |
| 8813 | { |
| 8814 | int32_t status = E1000_SUCCESS; |
| 8815 | uint16_t word = (uint16_t)data; |
| 8816 | |
| 8817 | status = e1000_write_ich8_data(hw, index, 1, word); |
| 8818 | |
| 8819 | return status; |
| 8820 | } |
| 8821 | |
| 8822 | /****************************************************************************** |
| 8823 | * Reads a word from the NVM using the ICH8 flash access registers. |
| 8824 | * |
| 8825 | * hw - pointer to e1000_hw structure |
| 8826 | * index - The starting byte index of the word to read. |
| 8827 | * data - Pointer to a word to store the value read. |
| 8828 | *****************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8829 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8830 | e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data) |
| 8831 | { |
| 8832 | int32_t status = E1000_SUCCESS; |
| 8833 | status = e1000_read_ich8_data(hw, index, 2, data); |
| 8834 | return status; |
| 8835 | } |
| 8836 | |
| 8837 | /****************************************************************************** |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8838 | * Erases the bank specified. Each bank may be a 4, 8 or 64k block. Banks are 0 |
| 8839 | * based. |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8840 | * |
| 8841 | * hw - pointer to e1000_hw structure |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8842 | * bank - 0 for first bank, 1 for second bank |
| 8843 | * |
| 8844 | * Note that this function may actually erase as much as 8 or 64 KBytes. The |
| 8845 | * amount of NVM used in each bank is a *minimum* of 4 KBytes, but in fact the |
| 8846 | * bank size may be 4, 8 or 64 KBytes |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8847 | *****************************************************************************/ |
| 8848 | int32_t |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8849 | e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8850 | { |
| 8851 | union ich8_hws_flash_status hsfsts; |
| 8852 | union ich8_hws_flash_ctrl hsflctl; |
| 8853 | uint32_t flash_linear_address; |
| 8854 | int32_t count = 0; |
| 8855 | int32_t error = E1000_ERR_EEPROM; |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8856 | int32_t iteration; |
| 8857 | int32_t sub_sector_size = 0; |
| 8858 | int32_t bank_size; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8859 | int32_t j = 0; |
| 8860 | int32_t error_flag = 0; |
| 8861 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8862 | hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8863 | |
| 8864 | /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */ |
| 8865 | /* 00: The Hw sector is 256 bytes, hence we need to erase 16 |
| 8866 | * consecutive sectors. The start index for the nth Hw sector can be |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8867 | * calculated as bank * 4096 + n * 256 |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8868 | * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector. |
| 8869 | * The start index for the nth Hw sector can be calculated |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8870 | * as bank * 4096 |
| 8871 | * 10: The HW sector is 8K bytes |
| 8872 | * 11: The Hw sector size is 64K bytes */ |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8873 | if (hsfsts.hsf_status.berasesz == 0x0) { |
| 8874 | /* Hw sector size 256 */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8875 | sub_sector_size = ICH_FLASH_SEG_SIZE_256; |
| 8876 | bank_size = ICH_FLASH_SECTOR_SIZE; |
| 8877 | iteration = ICH_FLASH_SECTOR_SIZE / ICH_FLASH_SEG_SIZE_256; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8878 | } else if (hsfsts.hsf_status.berasesz == 0x1) { |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8879 | bank_size = ICH_FLASH_SEG_SIZE_4K; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8880 | iteration = 1; |
| 8881 | } else if (hsfsts.hsf_status.berasesz == 0x3) { |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8882 | bank_size = ICH_FLASH_SEG_SIZE_64K; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8883 | iteration = 1; |
| 8884 | } else { |
| 8885 | return error; |
| 8886 | } |
| 8887 | |
| 8888 | for (j = 0; j < iteration ; j++) { |
| 8889 | do { |
| 8890 | count++; |
| 8891 | /* Steps */ |
| 8892 | error = e1000_ich8_cycle_init(hw); |
| 8893 | if (error != E1000_SUCCESS) { |
| 8894 | error_flag = 1; |
| 8895 | break; |
| 8896 | } |
| 8897 | |
| 8898 | /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash |
| 8899 | * Control */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8900 | hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL); |
| 8901 | hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE; |
| 8902 | E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8903 | |
| 8904 | /* Write the last 24 bits of an index within the block into Flash |
| 8905 | * Linear address field in Flash Address. This probably needs to |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8906 | * be calculated here based off the on-chip erase sector size and |
| 8907 | * the software bank size (4, 8 or 64 KBytes) */ |
| 8908 | flash_linear_address = bank * bank_size + j * sub_sector_size; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8909 | flash_linear_address += hw->flash_base_addr; |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8910 | flash_linear_address &= ICH_FLASH_LINEAR_ADDR_MASK; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8911 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8912 | E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8913 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8914 | error = e1000_ich8_flash_cycle(hw, ICH_FLASH_ERASE_TIMEOUT); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8915 | /* Check if FCERR is set to 1. If 1, clear it and try the whole |
| 8916 | * sequence a few more times else Done */ |
| 8917 | if (error == E1000_SUCCESS) { |
| 8918 | break; |
| 8919 | } else { |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8920 | hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8921 | if (hsfsts.hsf_status.flcerr == 1) { |
| 8922 | /* repeat for some time before giving up */ |
| 8923 | continue; |
| 8924 | } else if (hsfsts.hsf_status.flcdone == 0) { |
| 8925 | error_flag = 1; |
| 8926 | break; |
| 8927 | } |
| 8928 | } |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8929 | } while ((count < ICH_FLASH_CYCLE_REPEAT_COUNT) && !error_flag); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8930 | if (error_flag == 1) |
| 8931 | break; |
| 8932 | } |
| 8933 | if (error_flag != 1) |
| 8934 | error = E1000_SUCCESS; |
| 8935 | return error; |
| 8936 | } |
| 8937 | |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8938 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8939 | e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw, |
| 8940 | uint32_t cnf_base_addr, uint32_t cnf_size) |
| 8941 | { |
| 8942 | uint32_t ret_val = E1000_SUCCESS; |
| 8943 | uint16_t word_addr, reg_data, reg_addr; |
| 8944 | uint16_t i; |
| 8945 | |
| 8946 | /* cnf_base_addr is in DWORD */ |
| 8947 | word_addr = (uint16_t)(cnf_base_addr << 1); |
| 8948 | |
| 8949 | /* cnf_size is returned in size of dwords */ |
| 8950 | for (i = 0; i < cnf_size; i++) { |
| 8951 | ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, ®_data); |
| 8952 | if (ret_val) |
| 8953 | return ret_val; |
| 8954 | |
| 8955 | ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, ®_addr); |
| 8956 | if (ret_val) |
| 8957 | return ret_val; |
| 8958 | |
| 8959 | ret_val = e1000_get_software_flag(hw); |
| 8960 | if (ret_val != E1000_SUCCESS) |
| 8961 | return ret_val; |
| 8962 | |
| 8963 | ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data); |
| 8964 | |
| 8965 | e1000_release_software_flag(hw); |
| 8966 | } |
| 8967 | |
| 8968 | return ret_val; |
| 8969 | } |
| 8970 | |
| 8971 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8972 | /****************************************************************************** |
| 8973 | * This function initializes the PHY from the NVM on ICH8 platforms. This |
| 8974 | * is needed due to an issue where the NVM configuration is not properly |
| 8975 | * autoloaded after power transitions. Therefore, after each PHY reset, we |
| 8976 | * will load the configuration data out of the NVM manually. |
| 8977 | * |
| 8978 | * hw: Struct containing variables accessed by shared code |
| 8979 | *****************************************************************************/ |
Adrian Bunk | e4c780b | 2006-08-14 23:00:10 -0700 | [diff] [blame] | 8980 | static int32_t |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8981 | e1000_init_lcd_from_nvm(struct e1000_hw *hw) |
| 8982 | { |
| 8983 | uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop; |
| 8984 | |
| 8985 | if (hw->phy_type != e1000_phy_igp_3) |
| 8986 | return E1000_SUCCESS; |
| 8987 | |
| 8988 | /* Check if SW needs configure the PHY */ |
| 8989 | reg_data = E1000_READ_REG(hw, FEXTNVM); |
| 8990 | if (!(reg_data & FEXTNVM_SW_CONFIG)) |
| 8991 | return E1000_SUCCESS; |
| 8992 | |
| 8993 | /* Wait for basic configuration completes before proceeding*/ |
| 8994 | loop = 0; |
| 8995 | do { |
| 8996 | reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE; |
| 8997 | udelay(100); |
| 8998 | loop++; |
| 8999 | } while ((!reg_data) && (loop < 50)); |
| 9000 | |
| 9001 | /* Clear the Init Done bit for the next init event */ |
| 9002 | reg_data = E1000_READ_REG(hw, STATUS); |
| 9003 | reg_data &= ~E1000_STATUS_LAN_INIT_DONE; |
| 9004 | E1000_WRITE_REG(hw, STATUS, reg_data); |
| 9005 | |
| 9006 | /* Make sure HW does not configure LCD from PHY extended configuration |
| 9007 | before SW configuration */ |
| 9008 | reg_data = E1000_READ_REG(hw, EXTCNF_CTRL); |
| 9009 | if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) { |
| 9010 | reg_data = E1000_READ_REG(hw, EXTCNF_SIZE); |
| 9011 | cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH; |
| 9012 | cnf_size >>= 16; |
| 9013 | if (cnf_size) { |
| 9014 | reg_data = E1000_READ_REG(hw, EXTCNF_CTRL); |
| 9015 | cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER; |
| 9016 | /* cnf_base_addr is in DWORD */ |
| 9017 | cnf_base_addr >>= 16; |
| 9018 | |
| 9019 | /* Configure LCD from extended configuration region. */ |
| 9020 | ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr, |
| 9021 | cnf_size); |
| 9022 | if (ret_val) |
| 9023 | return ret_val; |
| 9024 | } |
| 9025 | } |
| 9026 | |
| 9027 | return E1000_SUCCESS; |
| 9028 | } |
| 9029 | |