Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 3 | Intel PRO/1000 Linux driver |
| 4 | Copyright(c) 1999 - 2006 Intel Corporation. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | more details. |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | You should have received a copy of the GNU General Public License along with |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | Contact Information: |
| 23 | Linux NICS <linux.nics@intel.com> |
Auke Kok | 3d41e30 | 2006-04-14 19:05:31 -0700 | [diff] [blame] | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | /* e1000_hw.c |
| 30 | * Shared functions for accessing and configuring the MAC |
| 31 | */ |
| 32 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include "e1000_hw.h" |
| 35 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 36 | static s32 e1000_swfw_sync_acquire(struct e1000_hw *hw, u16 mask); |
| 37 | static void e1000_swfw_sync_release(struct e1000_hw *hw, u16 mask); |
| 38 | static s32 e1000_read_kmrn_reg(struct e1000_hw *hw, u32 reg_addr, u16 *data); |
| 39 | static s32 e1000_write_kmrn_reg(struct e1000_hw *hw, u32 reg_addr, u16 data); |
| 40 | static s32 e1000_get_software_semaphore(struct e1000_hw *hw); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 41 | static void e1000_release_software_semaphore(struct e1000_hw *hw); |
| 42 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 43 | static u8 e1000_arc_subsystem_valid(struct e1000_hw *hw); |
| 44 | static s32 e1000_check_downshift(struct e1000_hw *hw); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 45 | static s32 e1000_check_polarity(struct e1000_hw *hw, |
| 46 | e1000_rev_polarity *polarity); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 47 | static void e1000_clear_hw_cntrs(struct e1000_hw *hw); |
| 48 | static void e1000_clear_vfta(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 49 | static s32 e1000_commit_shadow_ram(struct e1000_hw *hw); |
| 50 | static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 51 | bool link_up); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 52 | static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw); |
| 53 | static s32 e1000_detect_gig_phy(struct e1000_hw *hw); |
| 54 | static s32 e1000_erase_ich8_4k_segment(struct e1000_hw *hw, u32 bank); |
| 55 | static s32 e1000_get_auto_rd_done(struct e1000_hw *hw); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 56 | static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length, |
| 57 | u16 *max_length); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 58 | static s32 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw); |
| 59 | static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw); |
| 60 | static s32 e1000_get_software_flag(struct e1000_hw *hw); |
| 61 | static s32 e1000_ich8_cycle_init(struct e1000_hw *hw); |
| 62 | static s32 e1000_ich8_flash_cycle(struct e1000_hw *hw, u32 timeout); |
| 63 | static s32 e1000_id_led_init(struct e1000_hw *hw); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 64 | static s32 e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw, |
| 65 | u32 cnf_base_addr, |
| 66 | u32 cnf_size); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 67 | static s32 e1000_init_lcd_from_nvm(struct e1000_hw *hw); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 68 | static void e1000_init_rx_addrs(struct e1000_hw *hw); |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 69 | static void e1000_initialize_hardware_bits(struct e1000_hw *hw); |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 70 | static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 71 | static s32 e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw); |
| 72 | static s32 e1000_mng_enable_host_if(struct e1000_hw *hw); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 73 | static s32 e1000_mng_host_if_write(struct e1000_hw *hw, u8 *buffer, u16 length, |
| 74 | u16 offset, u8 *sum); |
| 75 | static s32 e1000_mng_write_cmd_header(struct e1000_hw* hw, |
| 76 | struct e1000_host_mng_command_header |
| 77 | *hdr); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 78 | static s32 e1000_mng_write_commit(struct e1000_hw *hw); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 79 | static s32 e1000_phy_ife_get_info(struct e1000_hw *hw, |
| 80 | struct e1000_phy_info *phy_info); |
| 81 | static s32 e1000_phy_igp_get_info(struct e1000_hw *hw, |
| 82 | struct e1000_phy_info *phy_info); |
| 83 | static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words, |
| 84 | u16 *data); |
| 85 | static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words, |
| 86 | u16 *data); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 87 | static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 88 | static s32 e1000_phy_m88_get_info(struct e1000_hw *hw, |
| 89 | struct e1000_phy_info *phy_info); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 90 | static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 91 | static s32 e1000_read_ich8_byte(struct e1000_hw *hw, u32 index, u8 *data); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 92 | static s32 e1000_verify_write_ich8_byte(struct e1000_hw *hw, u32 index, |
| 93 | u8 byte); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 94 | static s32 e1000_write_ich8_byte(struct e1000_hw *hw, u32 index, u8 byte); |
| 95 | static s32 e1000_read_ich8_word(struct e1000_hw *hw, u32 index, u16 *data); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 96 | static s32 e1000_read_ich8_data(struct e1000_hw *hw, u32 index, u32 size, |
| 97 | u16 *data); |
| 98 | static s32 e1000_write_ich8_data(struct e1000_hw *hw, u32 index, u32 size, |
| 99 | u16 data); |
| 100 | static s32 e1000_read_eeprom_ich8(struct e1000_hw *hw, u16 offset, u16 words, |
| 101 | u16 *data); |
| 102 | static s32 e1000_write_eeprom_ich8(struct e1000_hw *hw, u16 offset, u16 words, |
| 103 | u16 *data); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 104 | static void e1000_release_software_flag(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 105 | static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active); |
| 106 | static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active); |
| 107 | static s32 e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, u32 no_snoop); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 108 | static void e1000_set_pci_express_master_disable(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 109 | static s32 e1000_wait_autoneg(struct e1000_hw *hw); |
| 110 | static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value); |
| 111 | static s32 e1000_set_phy_type(struct e1000_hw *hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | static void e1000_phy_init_script(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 113 | static s32 e1000_setup_copper_link(struct e1000_hw *hw); |
| 114 | static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw); |
| 115 | static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw); |
| 116 | static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw); |
| 117 | static s32 e1000_config_mac_to_phy(struct e1000_hw *hw); |
| 118 | static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl); |
| 119 | static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl); |
| 120 | static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 121 | u16 count); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 122 | static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw); |
| 123 | static s32 e1000_phy_reset_dsp(struct e1000_hw *hw); |
| 124 | static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, |
| 125 | u16 words, u16 *data); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 126 | static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset, |
| 127 | u16 words, u16 *data); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 128 | static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw); |
| 129 | static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd); |
| 130 | static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 131 | static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 132 | static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 133 | u16 phy_data); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 134 | static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw,u32 reg_addr, |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 135 | u16 *phy_data); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 136 | static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count); |
| 137 | static s32 e1000_acquire_eeprom(struct e1000_hw *hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | static void e1000_release_eeprom(struct e1000_hw *hw); |
| 139 | static void e1000_standby_eeprom(struct e1000_hw *hw); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 140 | static s32 e1000_set_vco_speed(struct e1000_hw *hw); |
| 141 | static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw); |
| 142 | static s32 e1000_set_phy_mode(struct e1000_hw *hw); |
| 143 | static s32 e1000_host_if_read_cookie(struct e1000_hw *hw, u8 *buffer); |
| 144 | static u8 e1000_calculate_mng_checksum(char *buffer, u32 length); |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 145 | static s32 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, u16 duplex); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 146 | static s32 e1000_configure_kmrn_for_1000(struct e1000_hw *hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | /* IGP cable length table */ |
| 149 | static const |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 150 | u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
| 152 | 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25, |
| 153 | 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40, |
| 154 | 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, |
| 155 | 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90, |
| 156 | 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, |
| 157 | 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, |
| 158 | 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120}; |
| 159 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 160 | static const |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 161 | u16 e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] = |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 162 | { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, |
| 163 | 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, |
| 164 | 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, |
| 165 | 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, |
| 166 | 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, |
| 167 | 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, |
| 168 | 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124, |
| 169 | 104, 109, 114, 118, 121, 124}; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | /****************************************************************************** |
| 172 | * Set the phy type member in the hw struct. |
| 173 | * |
| 174 | * hw - Struct containing variables accessed by shared code |
| 175 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 176 | static s32 e1000_set_phy_type(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | { |
| 178 | DEBUGFUNC("e1000_set_phy_type"); |
| 179 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 180 | if (hw->mac_type == e1000_undefined) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 181 | return -E1000_ERR_PHY_TYPE; |
| 182 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 183 | switch (hw->phy_id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | case M88E1000_E_PHY_ID: |
| 185 | case M88E1000_I_PHY_ID: |
| 186 | case M88E1011_I_PHY_ID: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 187 | case M88E1111_I_PHY_ID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | hw->phy_type = e1000_phy_m88; |
| 189 | break; |
| 190 | case IGP01E1000_I_PHY_ID: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 191 | if (hw->mac_type == e1000_82541 || |
| 192 | hw->mac_type == e1000_82541_rev_2 || |
| 193 | hw->mac_type == e1000_82547 || |
| 194 | hw->mac_type == e1000_82547_rev_2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | hw->phy_type = e1000_phy_igp; |
| 196 | break; |
| 197 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 198 | case IGP03E1000_E_PHY_ID: |
| 199 | hw->phy_type = e1000_phy_igp_3; |
| 200 | break; |
| 201 | case IFE_E_PHY_ID: |
| 202 | case IFE_PLUS_E_PHY_ID: |
| 203 | case IFE_C_E_PHY_ID: |
| 204 | hw->phy_type = e1000_phy_ife; |
| 205 | break; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 206 | case GG82563_E_PHY_ID: |
| 207 | if (hw->mac_type == e1000_80003es2lan) { |
| 208 | hw->phy_type = e1000_phy_gg82563; |
| 209 | break; |
| 210 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | /* Fall Through */ |
| 212 | default: |
| 213 | /* Should never have loaded on this device */ |
| 214 | hw->phy_type = e1000_phy_undefined; |
| 215 | return -E1000_ERR_PHY_TYPE; |
| 216 | } |
| 217 | |
| 218 | return E1000_SUCCESS; |
| 219 | } |
| 220 | |
| 221 | /****************************************************************************** |
| 222 | * IGP phy init script - initializes the GbE PHY |
| 223 | * |
| 224 | * hw - Struct containing variables accessed by shared code |
| 225 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 226 | static void e1000_phy_init_script(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 228 | u32 ret_val; |
| 229 | u16 phy_saved_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
| 231 | DEBUGFUNC("e1000_phy_init_script"); |
| 232 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 233 | if (hw->phy_init_script) { |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 234 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
| 236 | /* Save off the current value of register 0x2F5B to be restored at |
| 237 | * the end of this routine. */ |
| 238 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
| 239 | |
| 240 | /* Disabled the PHY transmitter */ |
| 241 | e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 242 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 243 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
| 245 | e1000_write_phy_reg(hw,0x0000,0x0140); |
| 246 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 247 | msleep(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 249 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | case e1000_82541: |
| 251 | case e1000_82547: |
| 252 | e1000_write_phy_reg(hw, 0x1F95, 0x0001); |
| 253 | |
| 254 | e1000_write_phy_reg(hw, 0x1F71, 0xBD21); |
| 255 | |
| 256 | e1000_write_phy_reg(hw, 0x1F79, 0x0018); |
| 257 | |
| 258 | e1000_write_phy_reg(hw, 0x1F30, 0x1600); |
| 259 | |
| 260 | e1000_write_phy_reg(hw, 0x1F31, 0x0014); |
| 261 | |
| 262 | e1000_write_phy_reg(hw, 0x1F32, 0x161C); |
| 263 | |
| 264 | e1000_write_phy_reg(hw, 0x1F94, 0x0003); |
| 265 | |
| 266 | e1000_write_phy_reg(hw, 0x1F96, 0x003F); |
| 267 | |
| 268 | e1000_write_phy_reg(hw, 0x2010, 0x0008); |
| 269 | break; |
| 270 | |
| 271 | case e1000_82541_rev_2: |
| 272 | case e1000_82547_rev_2: |
| 273 | e1000_write_phy_reg(hw, 0x1F73, 0x0099); |
| 274 | break; |
| 275 | default: |
| 276 | break; |
| 277 | } |
| 278 | |
| 279 | e1000_write_phy_reg(hw, 0x0000, 0x3300); |
| 280 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 281 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
| 283 | /* Now enable the transmitter */ |
| 284 | e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
| 285 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 286 | if (hw->mac_type == e1000_82547) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 287 | u16 fused, fine, coarse; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
| 289 | /* Move to analog registers page */ |
| 290 | e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused); |
| 291 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 292 | if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused); |
| 294 | |
| 295 | fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK; |
| 296 | coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK; |
| 297 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 298 | if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10; |
| 300 | fine -= IGP01E1000_ANALOG_FUSE_FINE_1; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 301 | } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | fine -= IGP01E1000_ANALOG_FUSE_FINE_10; |
| 303 | |
| 304 | fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) | |
| 305 | (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) | |
| 306 | (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK); |
| 307 | |
| 308 | e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused); |
| 309 | e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS, |
| 310 | IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL); |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | /****************************************************************************** |
| 317 | * Set the mac type member in the hw struct. |
| 318 | * |
| 319 | * hw - Struct containing variables accessed by shared code |
| 320 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 321 | s32 e1000_set_mac_type(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 323 | DEBUGFUNC("e1000_set_mac_type"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 325 | switch (hw->device_id) { |
| 326 | case E1000_DEV_ID_82542: |
| 327 | switch (hw->revision_id) { |
| 328 | case E1000_82542_2_0_REV_ID: |
| 329 | hw->mac_type = e1000_82542_rev2_0; |
| 330 | break; |
| 331 | case E1000_82542_2_1_REV_ID: |
| 332 | hw->mac_type = e1000_82542_rev2_1; |
| 333 | break; |
| 334 | default: |
| 335 | /* Invalid 82542 revision ID */ |
| 336 | return -E1000_ERR_MAC_TYPE; |
| 337 | } |
| 338 | break; |
| 339 | case E1000_DEV_ID_82543GC_FIBER: |
| 340 | case E1000_DEV_ID_82543GC_COPPER: |
| 341 | hw->mac_type = e1000_82543; |
| 342 | break; |
| 343 | case E1000_DEV_ID_82544EI_COPPER: |
| 344 | case E1000_DEV_ID_82544EI_FIBER: |
| 345 | case E1000_DEV_ID_82544GC_COPPER: |
| 346 | case E1000_DEV_ID_82544GC_LOM: |
| 347 | hw->mac_type = e1000_82544; |
| 348 | break; |
| 349 | case E1000_DEV_ID_82540EM: |
| 350 | case E1000_DEV_ID_82540EM_LOM: |
| 351 | case E1000_DEV_ID_82540EP: |
| 352 | case E1000_DEV_ID_82540EP_LOM: |
| 353 | case E1000_DEV_ID_82540EP_LP: |
| 354 | hw->mac_type = e1000_82540; |
| 355 | break; |
| 356 | case E1000_DEV_ID_82545EM_COPPER: |
| 357 | case E1000_DEV_ID_82545EM_FIBER: |
| 358 | hw->mac_type = e1000_82545; |
| 359 | break; |
| 360 | case E1000_DEV_ID_82545GM_COPPER: |
| 361 | case E1000_DEV_ID_82545GM_FIBER: |
| 362 | case E1000_DEV_ID_82545GM_SERDES: |
| 363 | hw->mac_type = e1000_82545_rev_3; |
| 364 | break; |
| 365 | case E1000_DEV_ID_82546EB_COPPER: |
| 366 | case E1000_DEV_ID_82546EB_FIBER: |
| 367 | case E1000_DEV_ID_82546EB_QUAD_COPPER: |
| 368 | hw->mac_type = e1000_82546; |
| 369 | break; |
| 370 | case E1000_DEV_ID_82546GB_COPPER: |
| 371 | case E1000_DEV_ID_82546GB_FIBER: |
| 372 | case E1000_DEV_ID_82546GB_SERDES: |
| 373 | case E1000_DEV_ID_82546GB_PCIE: |
| 374 | case E1000_DEV_ID_82546GB_QUAD_COPPER: |
| 375 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
| 376 | hw->mac_type = e1000_82546_rev_3; |
| 377 | break; |
| 378 | case E1000_DEV_ID_82541EI: |
| 379 | case E1000_DEV_ID_82541EI_MOBILE: |
| 380 | case E1000_DEV_ID_82541ER_LOM: |
| 381 | hw->mac_type = e1000_82541; |
| 382 | break; |
| 383 | case E1000_DEV_ID_82541ER: |
| 384 | case E1000_DEV_ID_82541GI: |
| 385 | case E1000_DEV_ID_82541GI_LF: |
| 386 | case E1000_DEV_ID_82541GI_MOBILE: |
| 387 | hw->mac_type = e1000_82541_rev_2; |
| 388 | break; |
| 389 | case E1000_DEV_ID_82547EI: |
| 390 | case E1000_DEV_ID_82547EI_MOBILE: |
| 391 | hw->mac_type = e1000_82547; |
| 392 | break; |
| 393 | case E1000_DEV_ID_82547GI: |
| 394 | hw->mac_type = e1000_82547_rev_2; |
| 395 | break; |
| 396 | case E1000_DEV_ID_82571EB_COPPER: |
| 397 | case E1000_DEV_ID_82571EB_FIBER: |
| 398 | case E1000_DEV_ID_82571EB_SERDES: |
Auke Kok | ce57a02 | 2007-08-09 14:09:34 -0700 | [diff] [blame] | 399 | case E1000_DEV_ID_82571EB_SERDES_DUAL: |
| 400 | case E1000_DEV_ID_82571EB_SERDES_QUAD: |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 401 | case E1000_DEV_ID_82571EB_QUAD_COPPER: |
Auke Kok | f4ec7f9 | 2007-08-30 11:23:58 -0700 | [diff] [blame] | 402 | case E1000_DEV_ID_82571PT_QUAD_COPPER: |
Auke Kok | ce57a02 | 2007-08-09 14:09:34 -0700 | [diff] [blame] | 403 | case E1000_DEV_ID_82571EB_QUAD_FIBER: |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 404 | case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE: |
| 405 | hw->mac_type = e1000_82571; |
| 406 | break; |
| 407 | case E1000_DEV_ID_82572EI_COPPER: |
| 408 | case E1000_DEV_ID_82572EI_FIBER: |
| 409 | case E1000_DEV_ID_82572EI_SERDES: |
| 410 | case E1000_DEV_ID_82572EI: |
| 411 | hw->mac_type = e1000_82572; |
| 412 | break; |
| 413 | case E1000_DEV_ID_82573E: |
| 414 | case E1000_DEV_ID_82573E_IAMT: |
| 415 | case E1000_DEV_ID_82573L: |
| 416 | hw->mac_type = e1000_82573; |
| 417 | break; |
| 418 | case E1000_DEV_ID_80003ES2LAN_COPPER_SPT: |
| 419 | case E1000_DEV_ID_80003ES2LAN_SERDES_SPT: |
| 420 | case E1000_DEV_ID_80003ES2LAN_COPPER_DPT: |
| 421 | case E1000_DEV_ID_80003ES2LAN_SERDES_DPT: |
| 422 | hw->mac_type = e1000_80003es2lan; |
| 423 | break; |
| 424 | case E1000_DEV_ID_ICH8_IGP_M_AMT: |
| 425 | case E1000_DEV_ID_ICH8_IGP_AMT: |
| 426 | case E1000_DEV_ID_ICH8_IGP_C: |
| 427 | case E1000_DEV_ID_ICH8_IFE: |
| 428 | case E1000_DEV_ID_ICH8_IFE_GT: |
| 429 | case E1000_DEV_ID_ICH8_IFE_G: |
| 430 | case E1000_DEV_ID_ICH8_IGP_M: |
| 431 | hw->mac_type = e1000_ich8lan; |
| 432 | break; |
| 433 | default: |
| 434 | /* Should never have loaded on this device */ |
| 435 | return -E1000_ERR_MAC_TYPE; |
| 436 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 438 | switch (hw->mac_type) { |
| 439 | case e1000_ich8lan: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 440 | hw->swfwhw_semaphore_present = true; |
| 441 | hw->asf_firmware_present = true; |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 442 | break; |
| 443 | case e1000_80003es2lan: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 444 | hw->swfw_sync_present = true; |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 445 | /* fall through */ |
| 446 | case e1000_82571: |
| 447 | case e1000_82572: |
| 448 | case e1000_82573: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 449 | hw->eeprom_semaphore_present = true; |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 450 | /* fall through */ |
| 451 | case e1000_82541: |
| 452 | case e1000_82547: |
| 453 | case e1000_82541_rev_2: |
| 454 | case e1000_82547_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 455 | hw->asf_firmware_present = true; |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 456 | break; |
| 457 | default: |
| 458 | break; |
| 459 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 461 | /* The 82543 chip does not count tx_carrier_errors properly in |
| 462 | * FD mode |
| 463 | */ |
| 464 | if (hw->mac_type == e1000_82543) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 465 | hw->bad_tx_carr_stats_fd = true; |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 466 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 467 | /* capable of receiving management packets to the host */ |
| 468 | if (hw->mac_type >= e1000_82571) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 469 | hw->has_manc2h = true; |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 470 | |
Jeff Garzik | bb8e331 | 2006-12-15 11:06:17 -0500 | [diff] [blame] | 471 | /* In rare occasions, ESB2 systems would end up started without |
| 472 | * the RX unit being turned on. |
| 473 | */ |
| 474 | if (hw->mac_type == e1000_80003es2lan) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 475 | hw->rx_needs_kicking = true; |
Jeff Garzik | bb8e331 | 2006-12-15 11:06:17 -0500 | [diff] [blame] | 476 | |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 477 | if (hw->mac_type > e1000_82544) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 478 | hw->has_smbus = true; |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 479 | |
Jeff Garzik | bd2371e | 2006-12-15 10:31:40 -0500 | [diff] [blame] | 480 | return E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | /***************************************************************************** |
| 484 | * Set media type and TBI compatibility. |
| 485 | * |
| 486 | * hw - Struct containing variables accessed by shared code |
| 487 | * **************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 488 | void e1000_set_media_type(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 490 | u32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
| 492 | DEBUGFUNC("e1000_set_media_type"); |
| 493 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 494 | if (hw->mac_type != e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | /* tbi_compatibility is only valid on 82543 */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 496 | hw->tbi_compatibility_en = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | switch (hw->device_id) { |
| 500 | case E1000_DEV_ID_82545GM_SERDES: |
| 501 | case E1000_DEV_ID_82546GB_SERDES: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 502 | case E1000_DEV_ID_82571EB_SERDES: |
Auke Kok | ce57a02 | 2007-08-09 14:09:34 -0700 | [diff] [blame] | 503 | case E1000_DEV_ID_82571EB_SERDES_DUAL: |
| 504 | case E1000_DEV_ID_82571EB_SERDES_QUAD: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 505 | case E1000_DEV_ID_82572EI_SERDES: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 506 | case E1000_DEV_ID_80003ES2LAN_SERDES_DPT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | hw->media_type = e1000_media_type_internal_serdes; |
| 508 | break; |
| 509 | default: |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 510 | switch (hw->mac_type) { |
| 511 | case e1000_82542_rev2_0: |
| 512 | case e1000_82542_rev2_1: |
| 513 | hw->media_type = e1000_media_type_fiber; |
| 514 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 515 | case e1000_ich8lan: |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 516 | case e1000_82573: |
| 517 | /* The STATUS_TBIMODE bit is reserved or reused for the this |
| 518 | * device. |
| 519 | */ |
| 520 | hw->media_type = e1000_media_type_copper; |
| 521 | break; |
| 522 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | status = E1000_READ_REG(hw, STATUS); |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 524 | if (status & E1000_STATUS_TBIMODE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | hw->media_type = e1000_media_type_fiber; |
| 526 | /* tbi_compatibility not valid on fiber */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 527 | hw->tbi_compatibility_en = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | } else { |
| 529 | hw->media_type = e1000_media_type_copper; |
| 530 | } |
Malli Chilakala | 3893d54 | 2005-06-17 17:44:49 -0700 | [diff] [blame] | 531 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | /****************************************************************************** |
| 537 | * Reset the transmit and receive units; mask and clear all interrupts. |
| 538 | * |
| 539 | * hw - Struct containing variables accessed by shared code |
| 540 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 541 | s32 e1000_reset_hw(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 543 | u32 ctrl; |
| 544 | u32 ctrl_ext; |
| 545 | u32 icr; |
| 546 | u32 manc; |
| 547 | u32 led_ctrl; |
| 548 | u32 timeout; |
| 549 | u32 extcnf_ctrl; |
| 550 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
| 552 | DEBUGFUNC("e1000_reset_hw"); |
| 553 | |
| 554 | /* For 82542 (rev 2.0), disable MWI before issuing a device reset */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 555 | if (hw->mac_type == e1000_82542_rev2_0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); |
| 557 | e1000_pci_clear_mwi(hw); |
| 558 | } |
| 559 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 560 | if (hw->bus_type == e1000_bus_type_pci_express) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 561 | /* Prevent the PCI-E bus from sticking if there is no TLP connection |
| 562 | * on the last TLP read/write transaction when MAC is reset. |
| 563 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 564 | if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 565 | DEBUGOUT("PCI-E Master disable polling has failed.\n"); |
| 566 | } |
| 567 | } |
| 568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | /* Clear interrupt mask to stop board from generating interrupts */ |
| 570 | DEBUGOUT("Masking off all interrupts\n"); |
| 571 | E1000_WRITE_REG(hw, IMC, 0xffffffff); |
| 572 | |
| 573 | /* Disable the Transmit and Receive units. Then delay to allow |
| 574 | * any pending transactions to complete before we hit the MAC with |
| 575 | * the global reset. |
| 576 | */ |
| 577 | E1000_WRITE_REG(hw, RCTL, 0); |
| 578 | E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP); |
| 579 | E1000_WRITE_FLUSH(hw); |
| 580 | |
| 581 | /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 582 | hw->tbi_compatibility_on = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
| 584 | /* Delay to allow any outstanding PCI transactions to complete before |
| 585 | * resetting the device |
| 586 | */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 587 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
| 589 | ctrl = E1000_READ_REG(hw, CTRL); |
| 590 | |
| 591 | /* Must reset the PHY before resetting the MAC */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 592 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 593 | E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST)); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 594 | msleep(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 597 | /* Must acquire the MDIO ownership before MAC reset. |
| 598 | * Ownership defaults to firmware after a reset. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 599 | if (hw->mac_type == e1000_82573) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 600 | timeout = 10; |
| 601 | |
| 602 | extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL); |
| 603 | extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP; |
| 604 | |
| 605 | do { |
| 606 | E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl); |
| 607 | extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL); |
| 608 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 609 | if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 610 | break; |
| 611 | else |
| 612 | extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP; |
| 613 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 614 | msleep(2); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 615 | timeout--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 616 | } while (timeout); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 619 | /* Workaround for ICH8 bit corruption issue in FIFO memory */ |
| 620 | if (hw->mac_type == e1000_ich8lan) { |
| 621 | /* Set Tx and Rx buffer allocation to 8k apiece. */ |
| 622 | E1000_WRITE_REG(hw, PBA, E1000_PBA_8K); |
| 623 | /* Set Packet Buffer Size to 16k. */ |
| 624 | E1000_WRITE_REG(hw, PBS, E1000_PBS_16K); |
| 625 | } |
| 626 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | /* Issue a global reset to the MAC. This will reset the chip's |
| 628 | * transmit, receive, DMA, and link units. It will not effect |
| 629 | * the current PCI configuration. The global reset bit is self- |
| 630 | * clearing, and should clear within a microsecond. |
| 631 | */ |
| 632 | DEBUGOUT("Issuing a global reset to MAC\n"); |
| 633 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 634 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | case e1000_82544: |
| 636 | case e1000_82540: |
| 637 | case e1000_82545: |
| 638 | case e1000_82546: |
| 639 | case e1000_82541: |
| 640 | case e1000_82541_rev_2: |
| 641 | /* These controllers can't ack the 64-bit write when issuing the |
| 642 | * reset, so use IO-mapping as a workaround to issue the reset */ |
| 643 | E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST)); |
| 644 | break; |
| 645 | case e1000_82545_rev_3: |
| 646 | case e1000_82546_rev_3: |
| 647 | /* Reset is performed on a shadow of the control register */ |
| 648 | E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST)); |
| 649 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 650 | case e1000_ich8lan: |
| 651 | if (!hw->phy_reset_disable && |
| 652 | e1000_check_phy_reset_block(hw) == E1000_SUCCESS) { |
| 653 | /* e1000_ich8lan PHY HW reset requires MAC CORE reset |
| 654 | * at the same time to make sure the interface between |
| 655 | * MAC and the external PHY is reset. |
| 656 | */ |
| 657 | ctrl |= E1000_CTRL_PHY_RST; |
| 658 | } |
| 659 | |
| 660 | e1000_get_software_flag(hw); |
| 661 | E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST)); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 662 | msleep(5); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 663 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | default: |
| 665 | E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST)); |
| 666 | break; |
| 667 | } |
| 668 | |
| 669 | /* After MAC reset, force reload of EEPROM to restore power-on settings to |
| 670 | * device. Later controllers reload the EEPROM automatically, so just wait |
| 671 | * for reload to complete. |
| 672 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 673 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | case e1000_82542_rev2_0: |
| 675 | case e1000_82542_rev2_1: |
| 676 | case e1000_82543: |
| 677 | case e1000_82544: |
| 678 | /* Wait for reset to complete */ |
| 679 | udelay(10); |
| 680 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 681 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; |
| 682 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 683 | E1000_WRITE_FLUSH(hw); |
| 684 | /* Wait for EEPROM reload */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 685 | msleep(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | break; |
| 687 | case e1000_82541: |
| 688 | case e1000_82541_rev_2: |
| 689 | case e1000_82547: |
| 690 | case e1000_82547_rev_2: |
| 691 | /* Wait for EEPROM reload */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 692 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 694 | case e1000_82573: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 695 | if (!e1000_is_onboard_nvm_eeprom(hw)) { |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 696 | udelay(10); |
| 697 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 698 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; |
| 699 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 700 | E1000_WRITE_FLUSH(hw); |
| 701 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 702 | /* fall through */ |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 703 | default: |
| 704 | /* Auto read done will delay 5ms or poll based on mac type */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 705 | ret_val = e1000_get_auto_rd_done(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 706 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 707 | return ret_val; |
| 708 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | /* Disable HW ARPs on ASF enabled adapters */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 712 | 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] | 713 | manc = E1000_READ_REG(hw, MANC); |
| 714 | manc &= ~(E1000_MANC_ARP_EN); |
| 715 | E1000_WRITE_REG(hw, MANC, manc); |
| 716 | } |
| 717 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 718 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | e1000_phy_init_script(hw); |
| 720 | |
| 721 | /* Configure activity LED after PHY reset */ |
| 722 | led_ctrl = E1000_READ_REG(hw, LEDCTL); |
| 723 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 724 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 725 | E1000_WRITE_REG(hw, LEDCTL, led_ctrl); |
| 726 | } |
| 727 | |
| 728 | /* Clear interrupt mask to stop board from generating interrupts */ |
| 729 | DEBUGOUT("Masking off all interrupts\n"); |
| 730 | E1000_WRITE_REG(hw, IMC, 0xffffffff); |
| 731 | |
| 732 | /* Clear any pending interrupt events. */ |
| 733 | icr = E1000_READ_REG(hw, ICR); |
| 734 | |
| 735 | /* If MWI was previously enabled, reenable it. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 736 | if (hw->mac_type == e1000_82542_rev2_0) { |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 737 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | e1000_pci_set_mwi(hw); |
| 739 | } |
| 740 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 741 | if (hw->mac_type == e1000_ich8lan) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 742 | u32 kab = E1000_READ_REG(hw, KABGTXD); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 743 | kab |= E1000_KABGTXD_BGSQLBIAS; |
| 744 | E1000_WRITE_REG(hw, KABGTXD, kab); |
| 745 | } |
| 746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | return E1000_SUCCESS; |
| 748 | } |
| 749 | |
| 750 | /****************************************************************************** |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 751 | * |
| 752 | * Initialize a number of hardware-dependent bits |
| 753 | * |
| 754 | * hw: Struct containing variables accessed by shared code |
| 755 | * |
| 756 | * This function contains hardware limitation workarounds for PCI-E adapters |
| 757 | * |
| 758 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 759 | static void e1000_initialize_hardware_bits(struct e1000_hw *hw) |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 760 | { |
| 761 | if ((hw->mac_type >= e1000_82571) && (!hw->initialize_hw_bits_disable)) { |
| 762 | /* Settings common to all PCI-express silicon */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 763 | u32 reg_ctrl, reg_ctrl_ext; |
| 764 | u32 reg_tarc0, reg_tarc1; |
| 765 | u32 reg_tctl; |
| 766 | u32 reg_txdctl, reg_txdctl1; |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 767 | |
| 768 | /* link autonegotiation/sync workarounds */ |
| 769 | reg_tarc0 = E1000_READ_REG(hw, TARC0); |
| 770 | reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)); |
| 771 | |
| 772 | /* Enable not-done TX descriptor counting */ |
| 773 | reg_txdctl = E1000_READ_REG(hw, TXDCTL); |
| 774 | reg_txdctl |= E1000_TXDCTL_COUNT_DESC; |
| 775 | E1000_WRITE_REG(hw, TXDCTL, reg_txdctl); |
| 776 | reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1); |
| 777 | reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC; |
| 778 | E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1); |
| 779 | |
| 780 | switch (hw->mac_type) { |
| 781 | case e1000_82571: |
| 782 | case e1000_82572: |
| 783 | /* Clear PHY TX compatible mode bits */ |
| 784 | reg_tarc1 = E1000_READ_REG(hw, TARC1); |
| 785 | reg_tarc1 &= ~((1 << 30)|(1 << 29)); |
| 786 | |
| 787 | /* link autonegotiation/sync workarounds */ |
| 788 | reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23)); |
| 789 | |
| 790 | /* TX ring control fixes */ |
| 791 | reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24)); |
| 792 | |
| 793 | /* Multiple read bit is reversed polarity */ |
| 794 | reg_tctl = E1000_READ_REG(hw, TCTL); |
| 795 | if (reg_tctl & E1000_TCTL_MULR) |
| 796 | reg_tarc1 &= ~(1 << 28); |
| 797 | else |
| 798 | reg_tarc1 |= (1 << 28); |
| 799 | |
| 800 | E1000_WRITE_REG(hw, TARC1, reg_tarc1); |
| 801 | break; |
| 802 | case e1000_82573: |
| 803 | reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 804 | reg_ctrl_ext &= ~(1 << 23); |
| 805 | reg_ctrl_ext |= (1 << 22); |
| 806 | |
| 807 | /* TX byte count fix */ |
| 808 | reg_ctrl = E1000_READ_REG(hw, CTRL); |
| 809 | reg_ctrl &= ~(1 << 29); |
| 810 | |
| 811 | E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext); |
| 812 | E1000_WRITE_REG(hw, CTRL, reg_ctrl); |
| 813 | break; |
| 814 | case e1000_80003es2lan: |
| 815 | /* improve small packet performace for fiber/serdes */ |
| 816 | if ((hw->media_type == e1000_media_type_fiber) || |
| 817 | (hw->media_type == e1000_media_type_internal_serdes)) { |
| 818 | reg_tarc0 &= ~(1 << 20); |
| 819 | } |
| 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 | E1000_WRITE_REG(hw, TARC1, reg_tarc1); |
| 830 | break; |
| 831 | case e1000_ich8lan: |
| 832 | /* Reduce concurrent DMA requests to 3 from 4 */ |
| 833 | if ((hw->revision_id < 3) || |
| 834 | ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) && |
| 835 | (hw->device_id != E1000_DEV_ID_ICH8_IGP_M))) |
| 836 | reg_tarc0 |= ((1 << 29)|(1 << 28)); |
| 837 | |
| 838 | reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 839 | reg_ctrl_ext |= (1 << 22); |
| 840 | E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext); |
| 841 | |
| 842 | /* workaround TX hang with TSO=on */ |
| 843 | reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23)); |
| 844 | |
| 845 | /* Multiple read bit is reversed polarity */ |
| 846 | reg_tctl = E1000_READ_REG(hw, TCTL); |
| 847 | reg_tarc1 = E1000_READ_REG(hw, TARC1); |
| 848 | if (reg_tctl & E1000_TCTL_MULR) |
| 849 | reg_tarc1 &= ~(1 << 28); |
| 850 | else |
| 851 | reg_tarc1 |= (1 << 28); |
| 852 | |
| 853 | /* workaround TX hang with TSO=on */ |
| 854 | reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24)); |
| 855 | |
| 856 | E1000_WRITE_REG(hw, TARC1, reg_tarc1); |
| 857 | break; |
| 858 | default: |
| 859 | break; |
| 860 | } |
| 861 | |
| 862 | E1000_WRITE_REG(hw, TARC0, reg_tarc0); |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | * Performs basic configuration of the adapter. |
| 868 | * |
| 869 | * hw - Struct containing variables accessed by shared code |
| 870 | * |
| 871 | * Assumes that the controller has previously been reset and is in a |
| 872 | * post-reset uninitialized state. Initializes the receive address registers, |
| 873 | * multicast table, and VLAN filter table. Calls routines to setup link |
| 874 | * configuration and flow control settings. Clears all on-chip counters. Leaves |
| 875 | * the transmit and receive units disabled and uninitialized. |
| 876 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 877 | s32 e1000_init_hw(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 879 | u32 ctrl; |
| 880 | u32 i; |
| 881 | s32 ret_val; |
| 882 | u32 mta_size; |
| 883 | u32 reg_data; |
| 884 | u32 ctrl_ext; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 885 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | DEBUGFUNC("e1000_init_hw"); |
| 887 | |
Jeff Kirsher | 7820d42 | 2006-08-16 13:39:00 -0700 | [diff] [blame] | 888 | /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */ |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 889 | if ((hw->mac_type == e1000_ich8lan) && |
| 890 | ((hw->revision_id < 3) || |
| 891 | ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) && |
| 892 | (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) { |
| 893 | reg_data = E1000_READ_REG(hw, STATUS); |
| 894 | reg_data &= ~0x80000000; |
| 895 | E1000_WRITE_REG(hw, STATUS, reg_data); |
Jeff Kirsher | 7820d42 | 2006-08-16 13:39:00 -0700 | [diff] [blame] | 896 | } |
| 897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | /* Initialize Identification LED */ |
| 899 | ret_val = e1000_id_led_init(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 900 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | DEBUGOUT("Error Initializing Identification LED\n"); |
| 902 | return ret_val; |
| 903 | } |
| 904 | |
| 905 | /* Set the media type and TBI compatibility */ |
| 906 | e1000_set_media_type(hw); |
| 907 | |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 908 | /* Must be called after e1000_set_media_type because media_type is used */ |
| 909 | e1000_initialize_hardware_bits(hw); |
| 910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | /* Disabling VLAN filtering. */ |
| 912 | DEBUGOUT("Initializing the IEEE VLAN\n"); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 913 | /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */ |
| 914 | if (hw->mac_type != e1000_ich8lan) { |
| 915 | if (hw->mac_type < e1000_82545_rev_3) |
| 916 | E1000_WRITE_REG(hw, VET, 0); |
| 917 | e1000_clear_vfta(hw); |
| 918 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | |
| 920 | /* 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] | 921 | if (hw->mac_type == e1000_82542_rev2_0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | DEBUGOUT("Disabling MWI on 82542 rev 2.0\n"); |
| 923 | e1000_pci_clear_mwi(hw); |
| 924 | E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST); |
| 925 | E1000_WRITE_FLUSH(hw); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 926 | msleep(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | /* Setup the receive address. This involves initializing all of the Receive |
| 930 | * Address Registers (RARs 0 - 15). |
| 931 | */ |
| 932 | e1000_init_rx_addrs(hw); |
| 933 | |
| 934 | /* 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] | 935 | if (hw->mac_type == e1000_82542_rev2_0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | E1000_WRITE_REG(hw, RCTL, 0); |
| 937 | E1000_WRITE_FLUSH(hw); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 938 | msleep(1); |
| 939 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | e1000_pci_set_mwi(hw); |
| 941 | } |
| 942 | |
| 943 | /* Zero out the Multicast HASH table */ |
| 944 | DEBUGOUT("Zeroing the MTA\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 945 | mta_size = E1000_MC_TBL_SIZE; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 946 | if (hw->mac_type == e1000_ich8lan) |
| 947 | mta_size = E1000_MC_TBL_SIZE_ICH8LAN; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 948 | for (i = 0; i < mta_size; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 950 | /* use write flush to prevent Memory Write Block (MWB) from |
| 951 | * occuring when accessing our register space */ |
| 952 | E1000_WRITE_FLUSH(hw); |
| 953 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
| 955 | /* Set the PCI priority bit correctly in the CTRL register. This |
| 956 | * determines if the adapter gives priority to receives, or if it |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 957 | * gives equal priority to transmits and receives. Valid only on |
| 958 | * 82542 and 82543 silicon. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 960 | if (hw->dma_fairness && hw->mac_type <= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | ctrl = E1000_READ_REG(hw, CTRL); |
| 962 | E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR); |
| 963 | } |
| 964 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 965 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | case e1000_82545_rev_3: |
| 967 | case e1000_82546_rev_3: |
| 968 | break; |
| 969 | default: |
| 970 | /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */ |
Peter Oruba | 007755e | 2007-09-28 22:42:06 -0700 | [diff] [blame] | 971 | if (hw->bus_type == e1000_bus_type_pcix && e1000_pcix_get_mmrbc(hw) > 2048) |
| 972 | e1000_pcix_set_mmrbc(hw, 2048); |
| 973 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | } |
| 975 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 976 | /* More time needed for PHY to initialize */ |
| 977 | if (hw->mac_type == e1000_ich8lan) |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 978 | msleep(15); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | /* Call a subroutine to configure the link and setup flow control. */ |
| 981 | ret_val = e1000_setup_link(hw); |
| 982 | |
| 983 | /* Set the transmit descriptor write-back policy */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 984 | if (hw->mac_type > e1000_82544) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | ctrl = E1000_READ_REG(hw, TXDCTL); |
| 986 | ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB; |
| 987 | E1000_WRITE_REG(hw, TXDCTL, ctrl); |
| 988 | } |
| 989 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 990 | if (hw->mac_type == e1000_82573) { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 991 | e1000_enable_tx_pkt_filtering(hw); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 992 | } |
| 993 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 994 | switch (hw->mac_type) { |
| 995 | default: |
| 996 | break; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 997 | case e1000_80003es2lan: |
| 998 | /* Enable retransmit on late collisions */ |
| 999 | reg_data = E1000_READ_REG(hw, TCTL); |
| 1000 | reg_data |= E1000_TCTL_RTLC; |
| 1001 | E1000_WRITE_REG(hw, TCTL, reg_data); |
| 1002 | |
| 1003 | /* Configure Gigabit Carry Extend Padding */ |
| 1004 | reg_data = E1000_READ_REG(hw, TCTL_EXT); |
| 1005 | reg_data &= ~E1000_TCTL_EXT_GCEX_MASK; |
| 1006 | reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX; |
| 1007 | E1000_WRITE_REG(hw, TCTL_EXT, reg_data); |
| 1008 | |
| 1009 | /* Configure Transmit Inter-Packet Gap */ |
| 1010 | reg_data = E1000_READ_REG(hw, TIPG); |
| 1011 | reg_data &= ~E1000_TIPG_IPGT_MASK; |
| 1012 | reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000; |
| 1013 | E1000_WRITE_REG(hw, TIPG, reg_data); |
| 1014 | |
| 1015 | reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001); |
| 1016 | reg_data &= ~0x00100000; |
| 1017 | E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data); |
| 1018 | /* Fall through */ |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 1019 | case e1000_82571: |
Mallikarjuna R Chilakala | a7990ba | 2005-10-04 07:08:19 -0400 | [diff] [blame] | 1020 | case e1000_82572: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1021 | case e1000_ich8lan: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 1022 | ctrl = E1000_READ_REG(hw, TXDCTL1); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1023 | ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 1024 | E1000_WRITE_REG(hw, TXDCTL1, ctrl); |
| 1025 | break; |
| 1026 | } |
| 1027 | |
| 1028 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 1029 | if (hw->mac_type == e1000_82573) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1030 | u32 gcr = E1000_READ_REG(hw, GCR); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 1031 | gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX; |
| 1032 | E1000_WRITE_REG(hw, GCR, gcr); |
| 1033 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | /* Clear all of the statistics registers (clear on read). It is |
| 1036 | * important that we do this after we have tried to establish link |
| 1037 | * because the symbol error count will increment wildly if there |
| 1038 | * is no link. |
| 1039 | */ |
| 1040 | e1000_clear_hw_cntrs(hw); |
| 1041 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1042 | /* ICH8 No-snoop bits are opposite polarity. |
| 1043 | * Set to snoop by default after reset. */ |
| 1044 | if (hw->mac_type == e1000_ich8lan) |
| 1045 | e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL); |
| 1046 | |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 1047 | if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER || |
| 1048 | hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) { |
| 1049 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 1050 | /* Relaxed ordering must be disabled to avoid a parity |
| 1051 | * error crash in a PCI slot. */ |
| 1052 | ctrl_ext |= E1000_CTRL_EXT_RO_DIS; |
| 1053 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 1054 | } |
| 1055 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | return ret_val; |
| 1057 | } |
| 1058 | |
| 1059 | /****************************************************************************** |
| 1060 | * Adjust SERDES output amplitude based on EEPROM setting. |
| 1061 | * |
| 1062 | * hw - Struct containing variables accessed by shared code. |
| 1063 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 1064 | static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1066 | u16 eeprom_data; |
| 1067 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | |
| 1069 | DEBUGFUNC("e1000_adjust_serdes_amplitude"); |
| 1070 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1071 | if (hw->media_type != e1000_media_type_internal_serdes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | return E1000_SUCCESS; |
| 1073 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1074 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | case e1000_82545_rev_3: |
| 1076 | case e1000_82546_rev_3: |
| 1077 | break; |
| 1078 | default: |
| 1079 | return E1000_SUCCESS; |
| 1080 | } |
| 1081 | |
| 1082 | ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data); |
| 1083 | if (ret_val) { |
| 1084 | return ret_val; |
| 1085 | } |
| 1086 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1087 | if (eeprom_data != EEPROM_RESERVED_WORD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | /* Adjust SERDES output amplitude only. */ |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1089 | eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | 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] | 1091 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | return ret_val; |
| 1093 | } |
| 1094 | |
| 1095 | return E1000_SUCCESS; |
| 1096 | } |
| 1097 | |
| 1098 | /****************************************************************************** |
| 1099 | * Configures flow control and link settings. |
| 1100 | * |
| 1101 | * hw - Struct containing variables accessed by shared code |
| 1102 | * |
| 1103 | * Determines which flow control settings to use. Calls the apropriate media- |
| 1104 | * specific link configuration function. Configures the flow control settings. |
| 1105 | * Assuming the adapter has a valid link partner, a valid link should be |
| 1106 | * established. Assumes the hardware has previously been reset and the |
| 1107 | * transmitter and receiver are not enabled. |
| 1108 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 1109 | s32 e1000_setup_link(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1111 | u32 ctrl_ext; |
| 1112 | s32 ret_val; |
| 1113 | u16 eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | |
| 1115 | DEBUGFUNC("e1000_setup_link"); |
| 1116 | |
Jeff Kirsher | 526f995 | 2006-01-12 16:50:46 -0800 | [diff] [blame] | 1117 | /* In the case of the phy reset being blocked, we already have a link. |
| 1118 | * We do not have to set it up again. */ |
| 1119 | if (e1000_check_phy_reset_block(hw)) |
| 1120 | return E1000_SUCCESS; |
| 1121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | /* Read and store word 0x0F of the EEPROM. This word contains bits |
| 1123 | * that determine the hardware's default PAUSE (flow control) mode, |
| 1124 | * a bit that determines whether the HW defaults to enabling or |
| 1125 | * disabling auto-negotiation, and the direction of the |
| 1126 | * SW defined pins. If there is no SW over-ride of the flow |
| 1127 | * control setting, then the variable hw->fc will |
| 1128 | * be initialized based on a value in the EEPROM. |
| 1129 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1130 | if (hw->fc == E1000_FC_DEFAULT) { |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1131 | switch (hw->mac_type) { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1132 | case e1000_ich8lan: |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1133 | case e1000_82573: |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1134 | hw->fc = E1000_FC_FULL; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1135 | break; |
| 1136 | default: |
| 1137 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, |
| 1138 | 1, &eeprom_data); |
| 1139 | if (ret_val) { |
| 1140 | DEBUGOUT("EEPROM Read Error\n"); |
| 1141 | return -E1000_ERR_EEPROM; |
| 1142 | } |
| 1143 | if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1144 | hw->fc = E1000_FC_NONE; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1145 | else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == |
| 1146 | EEPROM_WORD0F_ASM_DIR) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1147 | hw->fc = E1000_FC_TX_PAUSE; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1148 | else |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1149 | hw->fc = E1000_FC_FULL; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1150 | break; |
| 1151 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | /* We want to save off the original Flow Control configuration just |
| 1155 | * in case we get disconnected and then reconnected into a different |
| 1156 | * hub or switch with different Flow Control capabilities. |
| 1157 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1158 | if (hw->mac_type == e1000_82542_rev2_0) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1159 | hw->fc &= (~E1000_FC_TX_PAUSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1161 | if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1)) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1162 | hw->fc &= (~E1000_FC_RX_PAUSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | |
| 1164 | hw->original_fc = hw->fc; |
| 1165 | |
| 1166 | DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc); |
| 1167 | |
| 1168 | /* Take the 4 bits from EEPROM word 0x0F that determine the initial |
| 1169 | * polarity value for the SW controlled pins, and setup the |
| 1170 | * Extended Device Control reg with that info. |
| 1171 | * This is needed because one of the SW controlled pins is used for |
| 1172 | * signal detection. So this should be done before e1000_setup_pcs_link() |
| 1173 | * or e1000_phy_setup() is called. |
| 1174 | */ |
Jeff Kirsher | 497fce5 | 2006-03-02 18:18:20 -0800 | [diff] [blame] | 1175 | if (hw->mac_type == e1000_82543) { |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1176 | ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, |
| 1177 | 1, &eeprom_data); |
| 1178 | if (ret_val) { |
| 1179 | DEBUGOUT("EEPROM Read Error\n"); |
| 1180 | return -E1000_ERR_EEPROM; |
| 1181 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) << |
| 1183 | SWDPIO__EXT_SHIFT); |
| 1184 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 1185 | } |
| 1186 | |
| 1187 | /* Call the necessary subroutine to configure the link. */ |
| 1188 | ret_val = (hw->media_type == e1000_media_type_copper) ? |
| 1189 | e1000_setup_copper_link(hw) : |
| 1190 | e1000_setup_fiber_serdes_link(hw); |
| 1191 | |
| 1192 | /* Initialize the flow control address, type, and PAUSE timer |
| 1193 | * registers to their default values. This is done even if flow |
| 1194 | * control is disabled, because it does not hurt anything to |
| 1195 | * initialize these registers. |
| 1196 | */ |
| 1197 | DEBUGOUT("Initializing the Flow Control address, type and timer regs\n"); |
| 1198 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1199 | /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */ |
| 1200 | if (hw->mac_type != e1000_ich8lan) { |
| 1201 | E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE); |
| 1202 | E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH); |
| 1203 | E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW); |
| 1204 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time); |
| 1207 | |
| 1208 | /* Set the flow control receive threshold registers. Normally, |
| 1209 | * these registers will be set to a default threshold that may be |
| 1210 | * adjusted later by the driver's runtime code. However, if the |
| 1211 | * ability to transmit pause frames in not enabled, then these |
| 1212 | * registers will be set to 0. |
| 1213 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1214 | if (!(hw->fc & E1000_FC_TX_PAUSE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | E1000_WRITE_REG(hw, FCRTL, 0); |
| 1216 | E1000_WRITE_REG(hw, FCRTH, 0); |
| 1217 | } else { |
| 1218 | /* We need to set up the Receive Threshold high and low water marks |
| 1219 | * as well as (optionally) enabling the transmission of XON frames. |
| 1220 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1221 | if (hw->fc_send_xon) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE)); |
| 1223 | E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water); |
| 1224 | } else { |
| 1225 | E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water); |
| 1226 | E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water); |
| 1227 | } |
| 1228 | } |
| 1229 | return ret_val; |
| 1230 | } |
| 1231 | |
| 1232 | /****************************************************************************** |
| 1233 | * Sets up link for a fiber based or serdes based adapter |
| 1234 | * |
| 1235 | * hw - Struct containing variables accessed by shared code |
| 1236 | * |
| 1237 | * Manipulates Physical Coding Sublayer functions in order to configure |
| 1238 | * link. Assumes the hardware has been previously reset and the transmitter |
| 1239 | * and receiver are not enabled. |
| 1240 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 1241 | static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1243 | u32 ctrl; |
| 1244 | u32 status; |
| 1245 | u32 txcw = 0; |
| 1246 | u32 i; |
| 1247 | u32 signal = 0; |
| 1248 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | |
| 1250 | DEBUGFUNC("e1000_setup_fiber_serdes_link"); |
| 1251 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 1252 | /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists |
| 1253 | * until explicitly turned off or a power cycle is performed. A read to |
| 1254 | * the register does not indicate its status. Therefore, we ensure |
| 1255 | * loopback mode is disabled during initialization. |
| 1256 | */ |
| 1257 | if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) |
| 1258 | E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK); |
| 1259 | |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 1260 | /* On adapters with a MAC newer than 82544, SWDP 1 will be |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | * set when the optics detect a signal. On older adapters, it will be |
| 1262 | * cleared when there is a signal. This applies to fiber media only. |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 1263 | * If we're on serdes media, adjust the output amplitude to value |
| 1264 | * set in the EEPROM. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | */ |
| 1266 | ctrl = E1000_READ_REG(hw, CTRL); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1267 | if (hw->media_type == e1000_media_type_fiber) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; |
| 1269 | |
| 1270 | ret_val = e1000_adjust_serdes_amplitude(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1271 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | return ret_val; |
| 1273 | |
| 1274 | /* Take the link out of reset */ |
| 1275 | ctrl &= ~(E1000_CTRL_LRST); |
| 1276 | |
| 1277 | /* Adjust VCO speed to improve BER performance */ |
| 1278 | ret_val = e1000_set_vco_speed(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1279 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | return ret_val; |
| 1281 | |
| 1282 | e1000_config_collision_dist(hw); |
| 1283 | |
| 1284 | /* Check for a software override of the flow control settings, and setup |
| 1285 | * the device accordingly. If auto-negotiation is enabled, then software |
| 1286 | * will have to set the "PAUSE" bits to the correct value in the Tranmsit |
| 1287 | * Config Word Register (TXCW) and re-start auto-negotiation. However, if |
| 1288 | * auto-negotiation is disabled, then software will have to manually |
| 1289 | * configure the two flow control enable bits in the CTRL register. |
| 1290 | * |
| 1291 | * The possible values of the "fc" parameter are: |
| 1292 | * 0: Flow control is completely disabled |
| 1293 | * 1: Rx flow control is enabled (we can receive pause frames, but |
| 1294 | * not send pause frames). |
| 1295 | * 2: Tx flow control is enabled (we can send pause frames but we do |
| 1296 | * not support receiving pause frames). |
| 1297 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
| 1298 | */ |
| 1299 | switch (hw->fc) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1300 | case E1000_FC_NONE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | /* Flow control is completely disabled by a software over-ride. */ |
| 1302 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); |
| 1303 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1304 | case E1000_FC_RX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | /* RX Flow control is enabled and TX Flow control is disabled by a |
| 1306 | * software over-ride. Since there really isn't a way to advertise |
| 1307 | * that we are capable of RX Pause ONLY, we will advertise that we |
| 1308 | * support both symmetric and asymmetric RX PAUSE. Later, we will |
| 1309 | * disable the adapter's ability to send PAUSE frames. |
| 1310 | */ |
| 1311 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 1312 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1313 | case E1000_FC_TX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | /* TX Flow control is enabled, and RX Flow control is disabled, by a |
| 1315 | * software over-ride. |
| 1316 | */ |
| 1317 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); |
| 1318 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 1319 | case E1000_FC_FULL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | /* Flow control (both RX and TX) is enabled by a software over-ride. */ |
| 1321 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); |
| 1322 | break; |
| 1323 | default: |
| 1324 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 1325 | return -E1000_ERR_CONFIG; |
| 1326 | break; |
| 1327 | } |
| 1328 | |
| 1329 | /* Since auto-negotiation is enabled, take the link out of reset (the link |
| 1330 | * will be in reset, because we previously reset the chip). This will |
| 1331 | * restart auto-negotiation. If auto-neogtiation is successful then the |
| 1332 | * link-up status bit will be set and the flow control enable bits (RFCE |
| 1333 | * and TFCE) will be set according to their negotiated value. |
| 1334 | */ |
| 1335 | DEBUGOUT("Auto-negotiation enabled\n"); |
| 1336 | |
| 1337 | E1000_WRITE_REG(hw, TXCW, txcw); |
| 1338 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 1339 | E1000_WRITE_FLUSH(hw); |
| 1340 | |
| 1341 | hw->txcw = txcw; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1342 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | |
| 1344 | /* If we have a signal (the cable is plugged in) then poll for a "Link-Up" |
| 1345 | * indication in the Device Status Register. Time-out if a link isn't |
| 1346 | * seen in 500 milliseconds seconds (Auto-negotiation should complete in |
| 1347 | * less than 500 milliseconds even if the other end is doing it in SW). |
| 1348 | * For internal serdes, we just assume a signal is present, then poll. |
| 1349 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1350 | if (hw->media_type == e1000_media_type_internal_serdes || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) { |
| 1352 | DEBUGOUT("Looking for Link\n"); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1353 | for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) { |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1354 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | status = E1000_READ_REG(hw, STATUS); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1356 | if (status & E1000_STATUS_LU) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1358 | if (i == (LINK_UP_TIMEOUT / 10)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | DEBUGOUT("Never got a valid link from auto-neg!!!\n"); |
| 1360 | hw->autoneg_failed = 1; |
| 1361 | /* AutoNeg failed to achieve a link, so we'll call |
| 1362 | * e1000_check_for_link. This routine will force the link up if |
| 1363 | * we detect a signal. This will allow us to communicate with |
| 1364 | * non-autonegotiating link partners. |
| 1365 | */ |
| 1366 | ret_val = e1000_check_for_link(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1367 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | DEBUGOUT("Error while checking for link\n"); |
| 1369 | return ret_val; |
| 1370 | } |
| 1371 | hw->autoneg_failed = 0; |
| 1372 | } else { |
| 1373 | hw->autoneg_failed = 0; |
| 1374 | DEBUGOUT("Valid Link Found\n"); |
| 1375 | } |
| 1376 | } else { |
| 1377 | DEBUGOUT("No Signal Detected\n"); |
| 1378 | } |
| 1379 | return E1000_SUCCESS; |
| 1380 | } |
| 1381 | |
| 1382 | /****************************************************************************** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1383 | * 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] | 1384 | * |
| 1385 | * hw - Struct containing variables accessed by shared code |
| 1386 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 1387 | static s32 e1000_copper_link_preconfig(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1389 | u32 ctrl; |
| 1390 | s32 ret_val; |
| 1391 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1435 | hw->phy_reset_disable = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | *********************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 1446 | static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1447 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1448 | u32 led_ctrl; |
| 1449 | s32 ret_val; |
| 1450 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1452 | DEBUGFUNC("e1000_copper_link_igp_setup"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1454 | if (hw->phy_reset_disable) |
| 1455 | return E1000_SUCCESS; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1456 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1457 | ret_val = e1000_phy_reset(hw); |
| 1458 | if (ret_val) { |
| 1459 | DEBUGOUT("Error Resetting the PHY\n"); |
| 1460 | return ret_val; |
| 1461 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1463 | /* Wait 15ms for MAC to configure PHY from eeprom settings */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1464 | msleep(15); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1465 | if (hw->mac_type != e1000_ich8lan) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1466 | /* Configure activity LED after PHY reset */ |
| 1467 | led_ctrl = E1000_READ_REG(hw, LEDCTL); |
| 1468 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 1469 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 1470 | E1000_WRITE_REG(hw, LEDCTL, led_ctrl); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1471 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1472 | |
Jeff Kirsher | c9c1b83 | 2006-08-16 13:38:54 -0700 | [diff] [blame] | 1473 | /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */ |
| 1474 | if (hw->phy_type == e1000_phy_igp) { |
| 1475 | /* disable lplu d3 during driver init */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1476 | ret_val = e1000_set_d3_lplu_state(hw, false); |
Jeff Kirsher | c9c1b83 | 2006-08-16 13:38:54 -0700 | [diff] [blame] | 1477 | if (ret_val) { |
| 1478 | DEBUGOUT("Error Disabling LPLU D3\n"); |
| 1479 | return ret_val; |
| 1480 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | /* disable lplu d0 during driver init */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1484 | ret_val = e1000_set_d0_lplu_state(hw, false); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1485 | if (ret_val) { |
| 1486 | DEBUGOUT("Error Disabling LPLU D0\n"); |
| 1487 | return ret_val; |
| 1488 | } |
| 1489 | /* Configure mdi-mdix settings */ |
| 1490 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); |
| 1491 | if (ret_val) |
| 1492 | return ret_val; |
| 1493 | |
| 1494 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
| 1495 | hw->dsp_config_state = e1000_dsp_config_disabled; |
| 1496 | /* Force MDI for earlier revs of the IGP PHY */ |
| 1497 | phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX); |
| 1498 | hw->mdix = 1; |
| 1499 | |
| 1500 | } else { |
| 1501 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 1502 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 1503 | |
| 1504 | switch (hw->mdix) { |
| 1505 | case 1: |
| 1506 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 1507 | break; |
| 1508 | case 2: |
| 1509 | phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 1510 | break; |
| 1511 | case 0: |
| 1512 | default: |
| 1513 | phy_data |= IGP01E1000_PSCR_AUTO_MDIX; |
| 1514 | break; |
| 1515 | } |
| 1516 | } |
| 1517 | 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] | 1518 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1519 | return ret_val; |
| 1520 | |
| 1521 | /* set auto-master slave resolution settings */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1522 | if (hw->autoneg) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1523 | e1000_ms_type phy_ms_setting = hw->master_slave; |
| 1524 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1525 | if (hw->ffe_config_state == e1000_ffe_config_active) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1526 | hw->ffe_config_state = e1000_ffe_config_enabled; |
| 1527 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1528 | if (hw->dsp_config_state == e1000_dsp_config_activated) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1529 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 1530 | |
| 1531 | /* when autonegotiation advertisment is only 1000Mbps then we |
| 1532 | * should disable SmartSpeed and enable Auto MasterSlave |
| 1533 | * resolution as hardware default. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1534 | if (hw->autoneg_advertised == ADVERTISE_1000_FULL) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1535 | /* Disable SmartSpeed */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1536 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 1537 | &phy_data); |
| 1538 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1540 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1541 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 1542 | phy_data); |
| 1543 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1545 | /* Set auto Master/Slave resolution process */ |
| 1546 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1547 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1548 | return ret_val; |
| 1549 | phy_data &= ~CR_1000T_MS_ENABLE; |
| 1550 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1551 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1552 | return ret_val; |
| 1553 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1555 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1556 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1557 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1559 | /* load defaults for future use */ |
| 1560 | hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ? |
| 1561 | ((phy_data & CR_1000T_MS_VALUE) ? |
| 1562 | e1000_ms_force_master : |
| 1563 | e1000_ms_force_slave) : |
| 1564 | e1000_ms_auto; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1566 | switch (phy_ms_setting) { |
| 1567 | case e1000_ms_force_master: |
| 1568 | phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE); |
| 1569 | break; |
| 1570 | case e1000_ms_force_slave: |
| 1571 | phy_data |= CR_1000T_MS_ENABLE; |
| 1572 | phy_data &= ~(CR_1000T_MS_VALUE); |
| 1573 | break; |
| 1574 | case e1000_ms_auto: |
| 1575 | phy_data &= ~CR_1000T_MS_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | default: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1577 | break; |
| 1578 | } |
| 1579 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1580 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1581 | return ret_val; |
Malli Chilakala | 2b02893 | 2005-06-17 17:46:06 -0700 | [diff] [blame] | 1582 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | |
Malli Chilakala | 2b02893 | 2005-06-17 17:46:06 -0700 | [diff] [blame] | 1584 | return E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1585 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1587 | /******************************************************************** |
| 1588 | * Copper link setup for e1000_phy_gg82563 series. |
| 1589 | * |
| 1590 | * hw - Struct containing variables accessed by shared code |
| 1591 | *********************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 1592 | static s32 e1000_copper_link_ggp_setup(struct e1000_hw *hw) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1593 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1594 | s32 ret_val; |
| 1595 | u16 phy_data; |
| 1596 | u32 reg_data; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1597 | |
| 1598 | DEBUGFUNC("e1000_copper_link_ggp_setup"); |
| 1599 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1600 | if (!hw->phy_reset_disable) { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1601 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1602 | /* Enable CRS on TX for half-duplex operation. */ |
| 1603 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, |
| 1604 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1605 | if (ret_val) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1606 | return ret_val; |
| 1607 | |
| 1608 | phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX; |
| 1609 | /* Use 25MHz for both link down and 1000BASE-T for Tx clock */ |
| 1610 | phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ; |
| 1611 | |
| 1612 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, |
| 1613 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1614 | if (ret_val) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1615 | return ret_val; |
| 1616 | |
| 1617 | /* Options: |
| 1618 | * MDI/MDI-X = 0 (default) |
| 1619 | * 0 - Auto for all speeds |
| 1620 | * 1 - MDI mode |
| 1621 | * 2 - MDI-X mode |
| 1622 | * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) |
| 1623 | */ |
| 1624 | 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] | 1625 | if (ret_val) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1626 | return ret_val; |
| 1627 | |
| 1628 | phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK; |
| 1629 | |
| 1630 | switch (hw->mdix) { |
| 1631 | case 1: |
| 1632 | phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI; |
| 1633 | break; |
| 1634 | case 2: |
| 1635 | phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX; |
| 1636 | break; |
| 1637 | case 0: |
| 1638 | default: |
| 1639 | phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO; |
| 1640 | break; |
| 1641 | } |
| 1642 | |
| 1643 | /* Options: |
| 1644 | * disable_polarity_correction = 0 (default) |
| 1645 | * Automatic Correction for Reversed Cable Polarity |
| 1646 | * 0 - Disabled |
| 1647 | * 1 - Enabled |
| 1648 | */ |
| 1649 | phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1650 | if (hw->disable_polarity_correction == 1) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1651 | phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE; |
| 1652 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data); |
| 1653 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1654 | if (ret_val) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1655 | return ret_val; |
| 1656 | |
| 1657 | /* SW Reset the PHY so all changes take effect */ |
| 1658 | ret_val = e1000_phy_reset(hw); |
| 1659 | if (ret_val) { |
| 1660 | DEBUGOUT("Error Resetting the PHY\n"); |
| 1661 | return ret_val; |
| 1662 | } |
| 1663 | } /* phy_reset_disable */ |
| 1664 | |
| 1665 | if (hw->mac_type == e1000_80003es2lan) { |
| 1666 | /* Bypass RX and TX FIFO's */ |
| 1667 | ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL, |
| 1668 | E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS | |
| 1669 | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS); |
| 1670 | if (ret_val) |
| 1671 | return ret_val; |
| 1672 | |
| 1673 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data); |
| 1674 | if (ret_val) |
| 1675 | return ret_val; |
| 1676 | |
| 1677 | phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG; |
| 1678 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data); |
| 1679 | |
| 1680 | if (ret_val) |
| 1681 | return ret_val; |
| 1682 | |
| 1683 | reg_data = E1000_READ_REG(hw, CTRL_EXT); |
| 1684 | reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK); |
| 1685 | E1000_WRITE_REG(hw, CTRL_EXT, reg_data); |
| 1686 | |
| 1687 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL, |
| 1688 | &phy_data); |
| 1689 | if (ret_val) |
| 1690 | return ret_val; |
| 1691 | |
| 1692 | /* Do not init these registers when the HW is in IAMT mode, since the |
| 1693 | * firmware will have already initialized them. We only initialize |
| 1694 | * them if the HW is not in IAMT mode. |
| 1695 | */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1696 | if (!e1000_check_mng_mode(hw)) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1697 | /* Enable Electrical Idle on the PHY */ |
| 1698 | phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE; |
| 1699 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL, |
| 1700 | phy_data); |
| 1701 | if (ret_val) |
| 1702 | return ret_val; |
| 1703 | |
| 1704 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, |
| 1705 | &phy_data); |
| 1706 | if (ret_val) |
| 1707 | return ret_val; |
| 1708 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1709 | phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1710 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, |
| 1711 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1712 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1713 | if (ret_val) |
| 1714 | return ret_val; |
| 1715 | } |
| 1716 | |
| 1717 | /* Workaround: Disable padding in Kumeran interface in the MAC |
| 1718 | * and in the PHY to avoid CRC errors. |
| 1719 | */ |
| 1720 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL, |
| 1721 | &phy_data); |
| 1722 | if (ret_val) |
| 1723 | return ret_val; |
| 1724 | phy_data |= GG82563_ICR_DIS_PADDING; |
| 1725 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL, |
| 1726 | phy_data); |
| 1727 | if (ret_val) |
| 1728 | return ret_val; |
| 1729 | } |
| 1730 | |
| 1731 | return E1000_SUCCESS; |
| 1732 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1734 | /******************************************************************** |
| 1735 | * Copper link setup for e1000_phy_m88 series. |
| 1736 | * |
| 1737 | * hw - Struct containing variables accessed by shared code |
| 1738 | *********************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 1739 | static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1740 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1741 | s32 ret_val; |
| 1742 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1744 | DEBUGFUNC("e1000_copper_link_mgp_setup"); |
| 1745 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1746 | if (hw->phy_reset_disable) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1747 | return E1000_SUCCESS; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1748 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1749 | /* Enable CRS on TX. This must be set for half-duplex operation. */ |
| 1750 | 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] | 1751 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1752 | return ret_val; |
| 1753 | |
| 1754 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 1755 | |
| 1756 | /* Options: |
| 1757 | * MDI/MDI-X = 0 (default) |
| 1758 | * 0 - Auto for all speeds |
| 1759 | * 1 - MDI mode |
| 1760 | * 2 - MDI-X mode |
| 1761 | * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) |
| 1762 | */ |
| 1763 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 1764 | |
| 1765 | switch (hw->mdix) { |
| 1766 | case 1: |
| 1767 | phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE; |
| 1768 | break; |
| 1769 | case 2: |
| 1770 | phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE; |
| 1771 | break; |
| 1772 | case 3: |
| 1773 | phy_data |= M88E1000_PSCR_AUTO_X_1000T; |
| 1774 | break; |
| 1775 | case 0: |
| 1776 | default: |
| 1777 | phy_data |= M88E1000_PSCR_AUTO_X_MODE; |
| 1778 | break; |
| 1779 | } |
| 1780 | |
| 1781 | /* Options: |
| 1782 | * disable_polarity_correction = 0 (default) |
| 1783 | * Automatic Correction for Reversed Cable Polarity |
| 1784 | * 0 - Disabled |
| 1785 | * 1 - Enabled |
| 1786 | */ |
| 1787 | phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1788 | if (hw->disable_polarity_correction == 1) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1789 | phy_data |= M88E1000_PSCR_POLARITY_REVERSAL; |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1790 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 1791 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1792 | return ret_val; |
| 1793 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1794 | if (hw->phy_revision < M88E1011_I_REV_4) { |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1795 | /* Force TX_CLK in the Extended PHY Specific Control Register |
| 1796 | * to 25MHz clock. |
| 1797 | */ |
| 1798 | ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data); |
| 1799 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1800 | return ret_val; |
Auke Kok | ee04022 | 2006-06-27 09:08:03 -0700 | [diff] [blame] | 1801 | |
| 1802 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
| 1803 | |
| 1804 | if ((hw->phy_revision == E1000_REVISION_2) && |
| 1805 | (hw->phy_id == M88E1111_I_PHY_ID)) { |
| 1806 | /* Vidalia Phy, set the downshift counter to 5x */ |
| 1807 | phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK); |
| 1808 | phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X; |
| 1809 | ret_val = e1000_write_phy_reg(hw, |
| 1810 | M88E1000_EXT_PHY_SPEC_CTRL, phy_data); |
| 1811 | if (ret_val) |
| 1812 | return ret_val; |
| 1813 | } else { |
| 1814 | /* Configure Master and Slave downshift values */ |
| 1815 | phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK | |
| 1816 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK); |
| 1817 | phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X | |
| 1818 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X); |
| 1819 | ret_val = e1000_write_phy_reg(hw, |
| 1820 | M88E1000_EXT_PHY_SPEC_CTRL, phy_data); |
| 1821 | if (ret_val) |
| 1822 | return ret_val; |
| 1823 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1824 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1826 | /* SW Reset the PHY so all changes take effect */ |
| 1827 | ret_val = e1000_phy_reset(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1828 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1829 | DEBUGOUT("Error Resetting the PHY\n"); |
| 1830 | return ret_val; |
| 1831 | } |
| 1832 | |
| 1833 | return E1000_SUCCESS; |
| 1834 | } |
| 1835 | |
| 1836 | /******************************************************************** |
| 1837 | * Setup auto-negotiation and flow control advertisements, |
| 1838 | * and then perform auto-negotiation. |
| 1839 | * |
| 1840 | * hw - Struct containing variables accessed by shared code |
| 1841 | *********************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 1842 | static s32 e1000_copper_link_autoneg(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1843 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1844 | s32 ret_val; |
| 1845 | u16 phy_data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1846 | |
| 1847 | DEBUGFUNC("e1000_copper_link_autoneg"); |
| 1848 | |
| 1849 | /* Perform some bounds checking on the hw->autoneg_advertised |
| 1850 | * parameter. If this variable is zero, then set it to the default. |
| 1851 | */ |
| 1852 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT; |
| 1853 | |
| 1854 | /* If autoneg_advertised is zero, we assume it was not defaulted |
| 1855 | * by the calling code so we set to advertise full capability. |
| 1856 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1857 | if (hw->autoneg_advertised == 0) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1858 | hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT; |
| 1859 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1860 | /* IFE phy only supports 10/100 */ |
| 1861 | if (hw->phy_type == e1000_phy_ife) |
| 1862 | hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL; |
| 1863 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1864 | DEBUGOUT("Reconfiguring auto-neg advertisement params\n"); |
| 1865 | ret_val = e1000_phy_setup_autoneg(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1866 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1867 | DEBUGOUT("Error Setting up Auto-Negotiation\n"); |
| 1868 | return ret_val; |
| 1869 | } |
| 1870 | DEBUGOUT("Restarting Auto-Neg\n"); |
| 1871 | |
| 1872 | /* Restart auto-negotiation by setting the Auto Neg Enable bit and |
| 1873 | * the Auto Neg Restart bit in the PHY control register. |
| 1874 | */ |
| 1875 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1876 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1877 | return ret_val; |
| 1878 | |
| 1879 | phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); |
| 1880 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1881 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1882 | return ret_val; |
| 1883 | |
| 1884 | /* Does the user want to wait for Auto-Neg to complete here, or |
| 1885 | * check at a later time (for example, callback routine). |
| 1886 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1887 | if (hw->wait_autoneg_complete) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1888 | ret_val = e1000_wait_autoneg(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1889 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1890 | DEBUGOUT("Error while waiting for autoneg to complete\n"); |
| 1891 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1893 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1895 | hw->get_link_status = true; |
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 | return E1000_SUCCESS; |
| 1898 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1900 | /****************************************************************************** |
| 1901 | * Config the MAC and the PHY after link is up. |
| 1902 | * 1) Set up the MAC to the current PHY speed/duplex |
| 1903 | * if we are on 82543. If we |
| 1904 | * are on newer silicon, we only need to configure |
| 1905 | * collision distance in the Transmit Control Register. |
| 1906 | * 2) Set up flow control on the MAC to that established with |
| 1907 | * the link partner. |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1908 | * 3) Config DSP to improve Gigabit link quality for some PHY revisions. |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1909 | * |
| 1910 | * hw - Struct containing variables accessed by shared code |
| 1911 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 1912 | static s32 e1000_copper_link_postconfig(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1913 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1914 | s32 ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1915 | DEBUGFUNC("e1000_copper_link_postconfig"); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1916 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1917 | if (hw->mac_type >= e1000_82544) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1918 | e1000_config_collision_dist(hw); |
| 1919 | } else { |
| 1920 | ret_val = e1000_config_mac_to_phy(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1921 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1922 | DEBUGOUT("Error configuring MAC to PHY settings\n"); |
| 1923 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1925 | } |
| 1926 | ret_val = e1000_config_fc_after_link_up(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1927 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1928 | DEBUGOUT("Error Configuring Flow Control\n"); |
| 1929 | return ret_val; |
| 1930 | } |
| 1931 | |
| 1932 | /* Config DSP to improve Giga link quality */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1933 | if (hw->phy_type == e1000_phy_igp) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1934 | ret_val = e1000_config_dsp_after_link_change(hw, true); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1935 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1936 | DEBUGOUT("Error Configuring DSP after link up\n"); |
| 1937 | return ret_val; |
| 1938 | } |
| 1939 | } |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1940 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1941 | return E1000_SUCCESS; |
| 1942 | } |
| 1943 | |
| 1944 | /****************************************************************************** |
| 1945 | * Detects which PHY is present and setup the speed and duplex |
| 1946 | * |
| 1947 | * hw - Struct containing variables accessed by shared code |
| 1948 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 1949 | static s32 e1000_setup_copper_link(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1950 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1951 | s32 ret_val; |
| 1952 | u16 i; |
| 1953 | u16 phy_data; |
| 1954 | u16 reg_data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1955 | |
| 1956 | DEBUGFUNC("e1000_setup_copper_link"); |
| 1957 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1958 | switch (hw->mac_type) { |
| 1959 | case e1000_80003es2lan: |
| 1960 | case e1000_ich8lan: |
| 1961 | /* Set the mac to wait the maximum time between each |
| 1962 | * iteration and increase the max iterations when |
| 1963 | * polling the phy; this fixes erroneous timeouts at 10Mbps. */ |
| 1964 | ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF); |
| 1965 | if (ret_val) |
| 1966 | return ret_val; |
| 1967 | ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), ®_data); |
| 1968 | if (ret_val) |
| 1969 | return ret_val; |
| 1970 | reg_data |= 0x3F; |
| 1971 | ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data); |
| 1972 | if (ret_val) |
| 1973 | return ret_val; |
| 1974 | default: |
| 1975 | break; |
| 1976 | } |
| 1977 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1978 | /* Check if it is a valid PHY and set PHY mode if necessary. */ |
| 1979 | ret_val = e1000_copper_link_preconfig(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1980 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1981 | return ret_val; |
| 1982 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1983 | switch (hw->mac_type) { |
| 1984 | case e1000_80003es2lan: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1985 | /* Kumeran registers are written-only */ |
| 1986 | reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1987 | reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING; |
| 1988 | ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL, |
| 1989 | reg_data); |
| 1990 | if (ret_val) |
| 1991 | return ret_val; |
| 1992 | break; |
| 1993 | default: |
| 1994 | break; |
| 1995 | } |
| 1996 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1997 | if (hw->phy_type == e1000_phy_igp || |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1998 | hw->phy_type == e1000_phy_igp_3 || |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1999 | hw->phy_type == e1000_phy_igp_2) { |
| 2000 | ret_val = e1000_copper_link_igp_setup(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2001 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2002 | return ret_val; |
| 2003 | } else if (hw->phy_type == e1000_phy_m88) { |
| 2004 | ret_val = e1000_copper_link_mgp_setup(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2005 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2006 | return ret_val; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2007 | } else if (hw->phy_type == e1000_phy_gg82563) { |
| 2008 | ret_val = e1000_copper_link_ggp_setup(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2009 | if (ret_val) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2010 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2013 | if (hw->autoneg) { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2014 | /* Setup autoneg and flow control advertisement |
| 2015 | * and perform autonegotiation */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2016 | ret_val = e1000_copper_link_autoneg(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2017 | if (ret_val) |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2018 | return ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2019 | } else { |
| 2020 | /* PHY will be set to 10H, 10F, 100H,or 100F |
| 2021 | * depending on value from forced_speed_duplex. */ |
| 2022 | DEBUGOUT("Forcing speed and duplex\n"); |
| 2023 | ret_val = e1000_phy_force_speed_duplex(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2024 | if (ret_val) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2025 | DEBUGOUT("Error Forcing Speed and Duplex\n"); |
| 2026 | return ret_val; |
| 2027 | } |
| 2028 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | |
| 2030 | /* Check link status. Wait up to 100 microseconds for link to become |
| 2031 | * valid. |
| 2032 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2033 | for (i = 0; i < 10; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2035 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | return ret_val; |
| 2037 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2038 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | return ret_val; |
| 2040 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2041 | if (phy_data & MII_SR_LINK_STATUS) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2042 | /* Config the MAC and PHY after link is up */ |
| 2043 | ret_val = e1000_copper_link_postconfig(hw); |
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; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | DEBUGOUT("Valid link established!!!\n"); |
| 2048 | return E1000_SUCCESS; |
| 2049 | } |
| 2050 | udelay(10); |
| 2051 | } |
| 2052 | |
| 2053 | DEBUGOUT("Unable to establish link!!!\n"); |
| 2054 | return E1000_SUCCESS; |
| 2055 | } |
| 2056 | |
| 2057 | /****************************************************************************** |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2058 | * Configure the MAC-to-PHY interface for 10/100Mbps |
| 2059 | * |
| 2060 | * hw - Struct containing variables accessed by shared code |
| 2061 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 2062 | static s32 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, u16 duplex) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2063 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2064 | s32 ret_val = E1000_SUCCESS; |
| 2065 | u32 tipg; |
| 2066 | u16 reg_data; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2067 | |
| 2068 | DEBUGFUNC("e1000_configure_kmrn_for_10_100"); |
| 2069 | |
| 2070 | reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT; |
| 2071 | ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL, |
| 2072 | reg_data); |
| 2073 | if (ret_val) |
| 2074 | return ret_val; |
| 2075 | |
| 2076 | /* Configure Transmit Inter-Packet Gap */ |
| 2077 | tipg = E1000_READ_REG(hw, TIPG); |
| 2078 | tipg &= ~E1000_TIPG_IPGT_MASK; |
| 2079 | tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100; |
| 2080 | E1000_WRITE_REG(hw, TIPG, tipg); |
| 2081 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2082 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data); |
| 2083 | |
| 2084 | if (ret_val) |
| 2085 | return ret_val; |
| 2086 | |
| 2087 | if (duplex == HALF_DUPLEX) |
| 2088 | reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER; |
| 2089 | else |
| 2090 | reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER; |
| 2091 | |
| 2092 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data); |
| 2093 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2094 | return ret_val; |
| 2095 | } |
| 2096 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 2097 | static s32 e1000_configure_kmrn_for_1000(struct e1000_hw *hw) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2098 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2099 | s32 ret_val = E1000_SUCCESS; |
| 2100 | u16 reg_data; |
| 2101 | u32 tipg; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2102 | |
| 2103 | DEBUGFUNC("e1000_configure_kmrn_for_1000"); |
| 2104 | |
| 2105 | reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT; |
| 2106 | ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL, |
| 2107 | reg_data); |
| 2108 | if (ret_val) |
| 2109 | return ret_val; |
| 2110 | |
| 2111 | /* Configure Transmit Inter-Packet Gap */ |
| 2112 | tipg = E1000_READ_REG(hw, TIPG); |
| 2113 | tipg &= ~E1000_TIPG_IPGT_MASK; |
| 2114 | tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000; |
| 2115 | E1000_WRITE_REG(hw, TIPG, tipg); |
| 2116 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2117 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data); |
| 2118 | |
| 2119 | if (ret_val) |
| 2120 | return ret_val; |
| 2121 | |
| 2122 | reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER; |
| 2123 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data); |
| 2124 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2125 | return ret_val; |
| 2126 | } |
| 2127 | |
| 2128 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | * Configures PHY autoneg and flow control advertisement settings |
| 2130 | * |
| 2131 | * hw - Struct containing variables accessed by shared code |
| 2132 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 2133 | s32 e1000_phy_setup_autoneg(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2135 | s32 ret_val; |
| 2136 | u16 mii_autoneg_adv_reg; |
| 2137 | u16 mii_1000t_ctrl_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | |
| 2139 | DEBUGFUNC("e1000_phy_setup_autoneg"); |
| 2140 | |
| 2141 | /* Read the MII Auto-Neg Advertisement Register (Address 4). */ |
| 2142 | 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] | 2143 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | return ret_val; |
| 2145 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2146 | if (hw->phy_type != e1000_phy_ife) { |
| 2147 | /* Read the MII 1000Base-T Control Register (Address 9). */ |
| 2148 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg); |
| 2149 | if (ret_val) |
| 2150 | return ret_val; |
| 2151 | } else |
| 2152 | mii_1000t_ctrl_reg=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | |
| 2154 | /* Need to parse both autoneg_advertised and fc and set up |
| 2155 | * the appropriate PHY registers. First we will parse for |
| 2156 | * autoneg_advertised software override. Since we can advertise |
| 2157 | * a plethora of combinations, we need to check each bit |
| 2158 | * individually. |
| 2159 | */ |
| 2160 | |
| 2161 | /* First we clear all the 10/100 mb speed bits in the Auto-Neg |
| 2162 | * Advertisement Register (Address 4) and the 1000 mb speed bits in |
| 2163 | * the 1000Base-T Control Register (Address 9). |
| 2164 | */ |
| 2165 | mii_autoneg_adv_reg &= ~REG4_SPEED_MASK; |
| 2166 | mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK; |
| 2167 | |
| 2168 | DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised); |
| 2169 | |
| 2170 | /* Do we want to advertise 10 Mb Half Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2171 | if (hw->autoneg_advertised & ADVERTISE_10_HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | DEBUGOUT("Advertise 10mb Half duplex\n"); |
| 2173 | mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS; |
| 2174 | } |
| 2175 | |
| 2176 | /* Do we want to advertise 10 Mb Full Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2177 | if (hw->autoneg_advertised & ADVERTISE_10_FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | DEBUGOUT("Advertise 10mb Full duplex\n"); |
| 2179 | mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS; |
| 2180 | } |
| 2181 | |
| 2182 | /* Do we want to advertise 100 Mb Half Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2183 | if (hw->autoneg_advertised & ADVERTISE_100_HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | DEBUGOUT("Advertise 100mb Half duplex\n"); |
| 2185 | mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS; |
| 2186 | } |
| 2187 | |
| 2188 | /* Do we want to advertise 100 Mb Full Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2189 | if (hw->autoneg_advertised & ADVERTISE_100_FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | DEBUGOUT("Advertise 100mb Full duplex\n"); |
| 2191 | mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS; |
| 2192 | } |
| 2193 | |
| 2194 | /* We do not allow the Phy to advertise 1000 Mb Half Duplex */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2195 | if (hw->autoneg_advertised & ADVERTISE_1000_HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n"); |
| 2197 | } |
| 2198 | |
| 2199 | /* Do we want to advertise 1000 Mb Full Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2200 | if (hw->autoneg_advertised & ADVERTISE_1000_FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | DEBUGOUT("Advertise 1000mb Full duplex\n"); |
| 2202 | mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2203 | if (hw->phy_type == e1000_phy_ife) { |
| 2204 | DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n"); |
| 2205 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | /* Check for a software override of the flow control settings, and |
| 2209 | * setup the PHY advertisement registers accordingly. If |
| 2210 | * auto-negotiation is enabled, then software will have to set the |
| 2211 | * "PAUSE" bits to the correct value in the Auto-Negotiation |
| 2212 | * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation. |
| 2213 | * |
| 2214 | * The possible values of the "fc" parameter are: |
| 2215 | * 0: Flow control is completely disabled |
| 2216 | * 1: Rx flow control is enabled (we can receive pause frames |
| 2217 | * but not send pause frames). |
| 2218 | * 2: Tx flow control is enabled (we can send pause frames |
| 2219 | * but we do not support receiving pause frames). |
| 2220 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
| 2221 | * other: No software override. The flow control configuration |
| 2222 | * in the EEPROM is used. |
| 2223 | */ |
| 2224 | switch (hw->fc) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2225 | case E1000_FC_NONE: /* 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | /* Flow control (RX & TX) is completely disabled by a |
| 2227 | * software over-ride. |
| 2228 | */ |
| 2229 | mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 2230 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2231 | case E1000_FC_RX_PAUSE: /* 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | /* RX Flow control is enabled, and TX Flow control is |
| 2233 | * disabled, by a software over-ride. |
| 2234 | */ |
| 2235 | /* Since there really isn't a way to advertise that we are |
| 2236 | * capable of RX Pause ONLY, we will advertise that we |
| 2237 | * support both symmetric and asymmetric RX PAUSE. Later |
| 2238 | * (in e1000_config_fc_after_link_up) we will disable the |
| 2239 | *hw's ability to send PAUSE frames. |
| 2240 | */ |
| 2241 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 2242 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2243 | case E1000_FC_TX_PAUSE: /* 2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | /* TX Flow control is enabled, and RX Flow control is |
| 2245 | * disabled, by a software over-ride. |
| 2246 | */ |
| 2247 | mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR; |
| 2248 | mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE; |
| 2249 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2250 | case E1000_FC_FULL: /* 3 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | /* Flow control (both RX and TX) is enabled by a software |
| 2252 | * over-ride. |
| 2253 | */ |
| 2254 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 2255 | break; |
| 2256 | default: |
| 2257 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 2258 | return -E1000_ERR_CONFIG; |
| 2259 | } |
| 2260 | |
| 2261 | 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] | 2262 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | return ret_val; |
| 2264 | |
| 2265 | DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg); |
| 2266 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2267 | if (hw->phy_type != e1000_phy_ife) { |
| 2268 | ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg); |
| 2269 | if (ret_val) |
| 2270 | return ret_val; |
| 2271 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | |
| 2273 | return E1000_SUCCESS; |
| 2274 | } |
| 2275 | |
| 2276 | /****************************************************************************** |
| 2277 | * Force PHY speed and duplex settings to hw->forced_speed_duplex |
| 2278 | * |
| 2279 | * hw - Struct containing variables accessed by shared code |
| 2280 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 2281 | static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2283 | u32 ctrl; |
| 2284 | s32 ret_val; |
| 2285 | u16 mii_ctrl_reg; |
| 2286 | u16 mii_status_reg; |
| 2287 | u16 phy_data; |
| 2288 | u16 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | |
| 2290 | DEBUGFUNC("e1000_phy_force_speed_duplex"); |
| 2291 | |
| 2292 | /* Turn off Flow control if we are forcing speed and duplex. */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2293 | hw->fc = E1000_FC_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | |
| 2295 | DEBUGOUT1("hw->fc = %d\n", hw->fc); |
| 2296 | |
| 2297 | /* Read the Device Control Register. */ |
| 2298 | ctrl = E1000_READ_REG(hw, CTRL); |
| 2299 | |
| 2300 | /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */ |
| 2301 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 2302 | ctrl &= ~(DEVICE_SPEED_MASK); |
| 2303 | |
| 2304 | /* Clear the Auto Speed Detect Enable bit. */ |
| 2305 | ctrl &= ~E1000_CTRL_ASDE; |
| 2306 | |
| 2307 | /* Read the MII Control Register. */ |
| 2308 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2309 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | return ret_val; |
| 2311 | |
| 2312 | /* We need to disable autoneg in order to force link and duplex. */ |
| 2313 | |
| 2314 | mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN; |
| 2315 | |
| 2316 | /* Are we forcing Full or Half Duplex? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2317 | if (hw->forced_speed_duplex == e1000_100_full || |
| 2318 | hw->forced_speed_duplex == e1000_10_full) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | /* We want to force full duplex so we SET the full duplex bits in the |
| 2320 | * Device and MII Control Registers. |
| 2321 | */ |
| 2322 | ctrl |= E1000_CTRL_FD; |
| 2323 | mii_ctrl_reg |= MII_CR_FULL_DUPLEX; |
| 2324 | DEBUGOUT("Full Duplex\n"); |
| 2325 | } else { |
| 2326 | /* We want to force half duplex so we CLEAR the full duplex bits in |
| 2327 | * the Device and MII Control Registers. |
| 2328 | */ |
| 2329 | ctrl &= ~E1000_CTRL_FD; |
| 2330 | mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX; |
| 2331 | DEBUGOUT("Half Duplex\n"); |
| 2332 | } |
| 2333 | |
| 2334 | /* Are we forcing 100Mbps??? */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2335 | if (hw->forced_speed_duplex == e1000_100_full || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | hw->forced_speed_duplex == e1000_100_half) { |
| 2337 | /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */ |
| 2338 | ctrl |= E1000_CTRL_SPD_100; |
| 2339 | mii_ctrl_reg |= MII_CR_SPEED_100; |
| 2340 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10); |
| 2341 | DEBUGOUT("Forcing 100mb "); |
| 2342 | } else { |
| 2343 | /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */ |
| 2344 | ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100); |
| 2345 | mii_ctrl_reg |= MII_CR_SPEED_10; |
| 2346 | mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100); |
| 2347 | DEBUGOUT("Forcing 10mb "); |
| 2348 | } |
| 2349 | |
| 2350 | e1000_config_collision_dist(hw); |
| 2351 | |
| 2352 | /* Write the configured values back to the Device Control Reg. */ |
| 2353 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 2354 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2355 | if ((hw->phy_type == e1000_phy_m88) || |
| 2356 | (hw->phy_type == e1000_phy_gg82563)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | 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] | 2358 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | return ret_val; |
| 2360 | |
| 2361 | /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI |
| 2362 | * forced whenever speed are duplex are forced. |
| 2363 | */ |
| 2364 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 2365 | 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] | 2366 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | return ret_val; |
| 2368 | |
| 2369 | DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data); |
| 2370 | |
| 2371 | /* Need to reset the PHY or these changes will be ignored */ |
| 2372 | mii_ctrl_reg |= MII_CR_RESET; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2373 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2374 | /* Disable MDI-X support for 10/100 */ |
| 2375 | } else if (hw->phy_type == e1000_phy_ife) { |
| 2376 | ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data); |
| 2377 | if (ret_val) |
| 2378 | return ret_val; |
| 2379 | |
| 2380 | phy_data &= ~IFE_PMC_AUTO_MDIX; |
| 2381 | phy_data &= ~IFE_PMC_FORCE_MDIX; |
| 2382 | |
| 2383 | ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data); |
| 2384 | if (ret_val) |
| 2385 | return ret_val; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | } else { |
| 2388 | /* Clear Auto-Crossover to force MDI manually. IGP requires MDI |
| 2389 | * forced whenever speed or duplex are forced. |
| 2390 | */ |
| 2391 | 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] | 2392 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | return ret_val; |
| 2394 | |
| 2395 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 2396 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 2397 | |
| 2398 | 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] | 2399 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | return ret_val; |
| 2401 | } |
| 2402 | |
| 2403 | /* Write back the modified PHY MII control register. */ |
| 2404 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2405 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | return ret_val; |
| 2407 | |
| 2408 | udelay(1); |
| 2409 | |
| 2410 | /* The wait_autoneg_complete flag may be a little misleading here. |
| 2411 | * Since we are forcing speed and duplex, Auto-Neg is not enabled. |
| 2412 | * But we do want to delay for a period while forcing only so we |
| 2413 | * don't generate false No Link messages. So we will wait here |
| 2414 | * only if the user has set wait_autoneg_complete to 1, which is |
| 2415 | * the default. |
| 2416 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2417 | if (hw->wait_autoneg_complete) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | /* We will wait for autoneg to complete. */ |
| 2419 | DEBUGOUT("Waiting for forced speed/duplex link.\n"); |
| 2420 | mii_status_reg = 0; |
| 2421 | |
| 2422 | /* 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] | 2423 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | /* Read the MII Status Register and wait for Auto-Neg Complete bit |
| 2425 | * to be set. |
| 2426 | */ |
| 2427 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2428 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | return ret_val; |
| 2430 | |
| 2431 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2432 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | return ret_val; |
| 2434 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2435 | if (mii_status_reg & MII_SR_LINK_STATUS) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 2436 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2438 | if ((i == 0) && |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2439 | ((hw->phy_type == e1000_phy_m88) || |
| 2440 | (hw->phy_type == e1000_phy_gg82563))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | /* We didn't get link. Reset the DSP and wait again for link. */ |
| 2442 | ret_val = e1000_phy_reset_dsp(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2443 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | DEBUGOUT("Error Resetting PHY DSP\n"); |
| 2445 | return ret_val; |
| 2446 | } |
| 2447 | } |
| 2448 | /* This loop will early-out if the link condition has been met. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2449 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
| 2450 | if (mii_status_reg & MII_SR_LINK_STATUS) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 2451 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2452 | /* Read the MII Status Register and wait for Auto-Neg Complete bit |
| 2453 | * to be set. |
| 2454 | */ |
| 2455 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2456 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2457 | return ret_val; |
| 2458 | |
| 2459 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2460 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | return ret_val; |
| 2462 | } |
| 2463 | } |
| 2464 | |
| 2465 | if (hw->phy_type == e1000_phy_m88) { |
| 2466 | /* Because we reset the PHY above, we need to re-force TX_CLK in the |
| 2467 | * Extended PHY Specific Control Register to 25MHz clock. This value |
| 2468 | * defaults back to a 2.5MHz clock when the PHY is reset. |
| 2469 | */ |
| 2470 | 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] | 2471 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | return ret_val; |
| 2473 | |
| 2474 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
| 2475 | 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] | 2476 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | return ret_val; |
| 2478 | |
| 2479 | /* In addition, because of the s/w reset above, we need to enable CRS on |
| 2480 | * TX. This must be set for both full and half duplex operation. |
| 2481 | */ |
| 2482 | 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] | 2483 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | return ret_val; |
| 2485 | |
| 2486 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 2487 | 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] | 2488 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | return ret_val; |
| 2490 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2491 | if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) && |
| 2492 | (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full || |
| 2493 | hw->forced_speed_duplex == e1000_10_half)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | ret_val = e1000_polarity_reversal_workaround(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2495 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | return ret_val; |
| 2497 | } |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 2498 | } else if (hw->phy_type == e1000_phy_gg82563) { |
| 2499 | /* The TX_CLK of the Extended PHY Specific Control Register defaults |
| 2500 | * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if |
| 2501 | * we're not in a forced 10/duplex configuration. */ |
| 2502 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data); |
| 2503 | if (ret_val) |
| 2504 | return ret_val; |
| 2505 | |
| 2506 | phy_data &= ~GG82563_MSCR_TX_CLK_MASK; |
| 2507 | if ((hw->forced_speed_duplex == e1000_10_full) || |
| 2508 | (hw->forced_speed_duplex == e1000_10_half)) |
| 2509 | phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ; |
| 2510 | else |
| 2511 | phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ; |
| 2512 | |
| 2513 | /* Also due to the reset, we need to enable CRS on Tx. */ |
| 2514 | phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX; |
| 2515 | |
| 2516 | ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data); |
| 2517 | if (ret_val) |
| 2518 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | } |
| 2520 | return E1000_SUCCESS; |
| 2521 | } |
| 2522 | |
| 2523 | /****************************************************************************** |
| 2524 | * Sets the collision distance in the Transmit Control register |
| 2525 | * |
| 2526 | * hw - Struct containing variables accessed by shared code |
| 2527 | * |
| 2528 | * Link should have been established previously. Reads the speed and duplex |
| 2529 | * information from the Device Status register. |
| 2530 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 2531 | void e1000_config_collision_dist(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2533 | u32 tctl, coll_dist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | |
| 2535 | DEBUGFUNC("e1000_config_collision_dist"); |
| 2536 | |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 2537 | if (hw->mac_type < e1000_82543) |
| 2538 | coll_dist = E1000_COLLISION_DISTANCE_82542; |
| 2539 | else |
| 2540 | coll_dist = E1000_COLLISION_DISTANCE; |
| 2541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | tctl = E1000_READ_REG(hw, TCTL); |
| 2543 | |
| 2544 | tctl &= ~E1000_TCTL_COLD; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 2545 | tctl |= coll_dist << E1000_COLD_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | |
| 2547 | E1000_WRITE_REG(hw, TCTL, tctl); |
| 2548 | E1000_WRITE_FLUSH(hw); |
| 2549 | } |
| 2550 | |
| 2551 | /****************************************************************************** |
| 2552 | * Sets MAC speed and duplex settings to reflect the those in the PHY |
| 2553 | * |
| 2554 | * hw - Struct containing variables accessed by shared code |
| 2555 | * mii_reg - data to write to the MII control register |
| 2556 | * |
| 2557 | * The contents of the PHY register containing the needed information need to |
| 2558 | * be passed in. |
| 2559 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 2560 | static s32 e1000_config_mac_to_phy(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2562 | u32 ctrl; |
| 2563 | s32 ret_val; |
| 2564 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | |
| 2566 | DEBUGFUNC("e1000_config_mac_to_phy"); |
| 2567 | |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2568 | /* 82544 or newer MAC, Auto Speed Detection takes care of |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2569 | * MAC speed/duplex configuration.*/ |
| 2570 | if (hw->mac_type >= e1000_82544) |
| 2571 | return E1000_SUCCESS; |
| 2572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | /* Read the Device Control Register and set the bits to Force Speed |
| 2574 | * and Duplex. |
| 2575 | */ |
| 2576 | ctrl = E1000_READ_REG(hw, CTRL); |
| 2577 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 2578 | ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS); |
| 2579 | |
| 2580 | /* Set up duplex in the Device Control and Transmit Control |
| 2581 | * registers depending on negotiated values. |
| 2582 | */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2583 | 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] | 2584 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2585 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2587 | if (phy_data & M88E1000_PSSR_DPLX) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2588 | ctrl |= E1000_CTRL_FD; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 2589 | else |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2590 | ctrl &= ~E1000_CTRL_FD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2592 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2594 | /* Set up speed in the Device Control register depending on |
| 2595 | * negotiated values. |
| 2596 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2597 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2598 | ctrl |= E1000_CTRL_SPD_1000; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2599 | else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2600 | ctrl |= E1000_CTRL_SPD_100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | /* Write the configured values back to the Device Control Reg. */ |
| 2603 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 2604 | return E1000_SUCCESS; |
| 2605 | } |
| 2606 | |
| 2607 | /****************************************************************************** |
| 2608 | * Forces the MAC's flow control settings. |
| 2609 | * |
| 2610 | * hw - Struct containing variables accessed by shared code |
| 2611 | * |
| 2612 | * Sets the TFCE and RFCE bits in the device control register to reflect |
| 2613 | * the adapter settings. TFCE and RFCE need to be explicitly set by |
| 2614 | * software when a Copper PHY is used because autonegotiation is managed |
| 2615 | * by the PHY rather than the MAC. Software must also configure these |
| 2616 | * bits when link is forced on a fiber connection. |
| 2617 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 2618 | s32 e1000_force_mac_fc(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2620 | u32 ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2621 | |
| 2622 | DEBUGFUNC("e1000_force_mac_fc"); |
| 2623 | |
| 2624 | /* Get the current configuration of the Device Control Register */ |
| 2625 | ctrl = E1000_READ_REG(hw, CTRL); |
| 2626 | |
| 2627 | /* Because we didn't get link via the internal auto-negotiation |
| 2628 | * mechanism (we either forced link or we got link via PHY |
| 2629 | * auto-neg), we have to manually enable/disable transmit an |
| 2630 | * receive flow control. |
| 2631 | * |
| 2632 | * The "Case" statement below enables/disable flow control |
| 2633 | * according to the "hw->fc" parameter. |
| 2634 | * |
| 2635 | * The possible values of the "fc" parameter are: |
| 2636 | * 0: Flow control is completely disabled |
| 2637 | * 1: Rx flow control is enabled (we can receive pause |
| 2638 | * frames but not send pause frames). |
| 2639 | * 2: Tx flow control is enabled (we can send pause frames |
| 2640 | * frames but we do not receive pause frames). |
| 2641 | * 3: Both Rx and TX flow control (symmetric) is enabled. |
| 2642 | * other: No other values should be possible at this point. |
| 2643 | */ |
| 2644 | |
| 2645 | switch (hw->fc) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2646 | case E1000_FC_NONE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); |
| 2648 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2649 | case E1000_FC_RX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2650 | ctrl &= (~E1000_CTRL_TFCE); |
| 2651 | ctrl |= E1000_CTRL_RFCE; |
| 2652 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2653 | case E1000_FC_TX_PAUSE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | ctrl &= (~E1000_CTRL_RFCE); |
| 2655 | ctrl |= E1000_CTRL_TFCE; |
| 2656 | break; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2657 | case E1000_FC_FULL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2658 | ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); |
| 2659 | break; |
| 2660 | default: |
| 2661 | DEBUGOUT("Flow control param set incorrectly\n"); |
| 2662 | return -E1000_ERR_CONFIG; |
| 2663 | } |
| 2664 | |
| 2665 | /* Disable TX Flow Control for 82542 (rev 2.0) */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2666 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | ctrl &= (~E1000_CTRL_TFCE); |
| 2668 | |
| 2669 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 2670 | return E1000_SUCCESS; |
| 2671 | } |
| 2672 | |
| 2673 | /****************************************************************************** |
| 2674 | * Configures flow control settings after link is established |
| 2675 | * |
| 2676 | * hw - Struct containing variables accessed by shared code |
| 2677 | * |
| 2678 | * Should be called immediately after a valid link has been established. |
| 2679 | * Forces MAC flow control settings if link was forced. When in MII/GMII mode |
| 2680 | * and autonegotiation is enabled, the MAC flow control settings will be set |
| 2681 | * based on the flow control negotiated by the PHY. In TBI mode, the TFCE |
| 2682 | * and RFCE bits will be automaticaly set to the negotiated flow control mode. |
| 2683 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 2684 | static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2686 | s32 ret_val; |
| 2687 | u16 mii_status_reg; |
| 2688 | u16 mii_nway_adv_reg; |
| 2689 | u16 mii_nway_lp_ability_reg; |
| 2690 | u16 speed; |
| 2691 | u16 duplex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | |
| 2693 | DEBUGFUNC("e1000_config_fc_after_link_up"); |
| 2694 | |
| 2695 | /* Check for the case where we have fiber media and auto-neg failed |
| 2696 | * so we had to force link. In this case, we need to force the |
| 2697 | * configuration of the MAC to match the "fc" parameter. |
| 2698 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2699 | if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) || |
| 2700 | ((hw->media_type == e1000_media_type_internal_serdes) && |
| 2701 | (hw->autoneg_failed)) || |
| 2702 | ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | ret_val = e1000_force_mac_fc(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2704 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | DEBUGOUT("Error forcing flow control settings\n"); |
| 2706 | return ret_val; |
| 2707 | } |
| 2708 | } |
| 2709 | |
| 2710 | /* Check for the case where we have copper media and auto-neg is |
| 2711 | * enabled. In this case, we need to check and see if Auto-Neg |
| 2712 | * has completed, and if so, how the PHY and link partner has |
| 2713 | * flow control configured. |
| 2714 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2715 | if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | /* Read the MII Status Register and check to see if AutoNeg |
| 2717 | * has completed. We read this twice because this reg has |
| 2718 | * some "sticky" (latched) bits. |
| 2719 | */ |
| 2720 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2721 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | return ret_val; |
| 2723 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2724 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | return ret_val; |
| 2726 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2727 | if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | /* The AutoNeg process has completed, so we now need to |
| 2729 | * read both the Auto Negotiation Advertisement Register |
| 2730 | * (Address 4) and the Auto_Negotiation Base Page Ability |
| 2731 | * Register (Address 5) to determine how flow control was |
| 2732 | * negotiated. |
| 2733 | */ |
| 2734 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, |
| 2735 | &mii_nway_adv_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2736 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | return ret_val; |
| 2738 | ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, |
| 2739 | &mii_nway_lp_ability_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2740 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | return ret_val; |
| 2742 | |
| 2743 | /* Two bits in the Auto Negotiation Advertisement Register |
| 2744 | * (Address 4) and two bits in the Auto Negotiation Base |
| 2745 | * Page Ability Register (Address 5) determine flow control |
| 2746 | * for both the PHY and the link partner. The following |
| 2747 | * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, |
| 2748 | * 1999, describes these PAUSE resolution bits and how flow |
| 2749 | * control is determined based upon these settings. |
| 2750 | * NOTE: DC = Don't Care |
| 2751 | * |
| 2752 | * LOCAL DEVICE | LINK PARTNER |
| 2753 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution |
| 2754 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2755 | * 0 | 0 | DC | DC | E1000_FC_NONE |
| 2756 | * 0 | 1 | 0 | DC | E1000_FC_NONE |
| 2757 | * 0 | 1 | 1 | 0 | E1000_FC_NONE |
| 2758 | * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE |
| 2759 | * 1 | 0 | 0 | DC | E1000_FC_NONE |
| 2760 | * 1 | DC | 1 | DC | E1000_FC_FULL |
| 2761 | * 1 | 1 | 0 | 0 | E1000_FC_NONE |
| 2762 | * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | * |
| 2764 | */ |
| 2765 | /* Are both PAUSE bits set to 1? If so, this implies |
| 2766 | * Symmetric Flow Control is enabled at both ends. The |
| 2767 | * ASM_DIR bits are irrelevant per the spec. |
| 2768 | * |
| 2769 | * For Symmetric Flow Control: |
| 2770 | * |
| 2771 | * LOCAL DEVICE | LINK PARTNER |
| 2772 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 2773 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2774 | * 1 | DC | 1 | DC | E1000_FC_FULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | * |
| 2776 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2777 | if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2778 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | /* Now we need to check if the user selected RX ONLY |
| 2780 | * of pause frames. In this case, we had to advertise |
| 2781 | * FULL flow control because we could not advertise RX |
| 2782 | * ONLY. Hence, we must now check to see if we need to |
| 2783 | * turn OFF the TRANSMISSION of PAUSE frames. |
| 2784 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2785 | if (hw->original_fc == E1000_FC_FULL) { |
| 2786 | hw->fc = E1000_FC_FULL; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2787 | DEBUGOUT("Flow Control = FULL.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | } else { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2789 | hw->fc = E1000_FC_RX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2790 | DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | } |
| 2792 | } |
| 2793 | /* For receiving PAUSE frames ONLY. |
| 2794 | * |
| 2795 | * LOCAL DEVICE | LINK PARTNER |
| 2796 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 2797 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2798 | * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | * |
| 2800 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2801 | else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2802 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 2803 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 2804 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2805 | hw->fc = E1000_FC_TX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2806 | DEBUGOUT("Flow Control = TX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | } |
| 2808 | /* For transmitting PAUSE frames ONLY. |
| 2809 | * |
| 2810 | * LOCAL DEVICE | LINK PARTNER |
| 2811 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 2812 | *-------|---------|-------|---------|-------------------- |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2813 | * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | * |
| 2815 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2816 | else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 2817 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 2818 | !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 2819 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2820 | hw->fc = E1000_FC_RX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2821 | DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | } |
| 2823 | /* Per the IEEE spec, at this point flow control should be |
| 2824 | * disabled. However, we want to consider that we could |
| 2825 | * be connected to a legacy switch that doesn't advertise |
| 2826 | * desired flow control, but can be forced on the link |
| 2827 | * partner. So if we advertised no flow control, that is |
| 2828 | * what we will resolve to. If we advertised some kind of |
| 2829 | * receive capability (Rx Pause Only or Full Flow Control) |
| 2830 | * and the link partner advertised none, we will configure |
| 2831 | * ourselves to enable Rx Flow Control only. We can do |
| 2832 | * this safely for two reasons: If the link partner really |
| 2833 | * didn't want flow control enabled, and we enable Rx, no |
| 2834 | * harm done since we won't be receiving any PAUSE frames |
| 2835 | * anyway. If the intent on the link partner was to have |
| 2836 | * flow control enabled, then by us enabling RX only, we |
| 2837 | * can at least receive pause frames and process them. |
| 2838 | * This is a good idea because in most cases, since we are |
| 2839 | * predominantly a server NIC, more times than not we will |
| 2840 | * be asked to delay transmission of packets than asking |
| 2841 | * our link partner to pause transmission of frames. |
| 2842 | */ |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2843 | else if ((hw->original_fc == E1000_FC_NONE || |
| 2844 | hw->original_fc == E1000_FC_TX_PAUSE) || |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2845 | hw->fc_strict_ieee) { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2846 | hw->fc = E1000_FC_NONE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2847 | DEBUGOUT("Flow Control = NONE.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | } else { |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2849 | hw->fc = E1000_FC_RX_PAUSE; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2850 | DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | /* Now we need to do one last check... If we auto- |
| 2854 | * negotiated to HALF DUPLEX, flow control should not be |
| 2855 | * enabled per IEEE 802.3 spec. |
| 2856 | */ |
| 2857 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2858 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | DEBUGOUT("Error getting link speed and duplex\n"); |
| 2860 | return ret_val; |
| 2861 | } |
| 2862 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2863 | if (duplex == HALF_DUPLEX) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame] | 2864 | hw->fc = E1000_FC_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | |
| 2866 | /* Now we call a subroutine to actually force the MAC |
| 2867 | * controller to use the correct flow control settings. |
| 2868 | */ |
| 2869 | ret_val = e1000_force_mac_fc(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2870 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | DEBUGOUT("Error forcing flow control settings\n"); |
| 2872 | return ret_val; |
| 2873 | } |
| 2874 | } else { |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 2875 | DEBUGOUT("Copper PHY and Auto Neg has not completed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | } |
| 2877 | } |
| 2878 | return E1000_SUCCESS; |
| 2879 | } |
| 2880 | |
| 2881 | /****************************************************************************** |
| 2882 | * Checks to see if the link status of the hardware has changed. |
| 2883 | * |
| 2884 | * hw - Struct containing variables accessed by shared code |
| 2885 | * |
| 2886 | * Called by any function that needs to check the link status of the adapter. |
| 2887 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 2888 | s32 e1000_check_for_link(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2890 | u32 rxcw = 0; |
| 2891 | u32 ctrl; |
| 2892 | u32 status; |
| 2893 | u32 rctl; |
| 2894 | u32 icr; |
| 2895 | u32 signal = 0; |
| 2896 | s32 ret_val; |
| 2897 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | |
| 2899 | DEBUGFUNC("e1000_check_for_link"); |
| 2900 | |
| 2901 | ctrl = E1000_READ_REG(hw, CTRL); |
| 2902 | status = E1000_READ_REG(hw, STATUS); |
| 2903 | |
| 2904 | /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be |
| 2905 | * set when the optics detect a signal. On older adapters, it will be |
| 2906 | * cleared when there is a signal. This applies to fiber media only. |
| 2907 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2908 | if ((hw->media_type == e1000_media_type_fiber) || |
| 2909 | (hw->media_type == e1000_media_type_internal_serdes)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | rxcw = E1000_READ_REG(hw, RXCW); |
| 2911 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2912 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2914 | if (status & E1000_STATUS_LU) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2915 | hw->get_link_status = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | } |
| 2917 | } |
| 2918 | |
| 2919 | /* If we have a copper PHY then we only want to go out to the PHY |
| 2920 | * registers to see if Auto-Neg has completed and/or if our link |
| 2921 | * status has changed. The get_link_status flag will be set if we |
| 2922 | * receive a Link Status Change interrupt or we have Rx Sequence |
| 2923 | * Errors. |
| 2924 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2925 | if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | /* First we want to see if the MII Status Register reports |
| 2927 | * link. If so, then we want to get the current speed/duplex |
| 2928 | * of the PHY. |
| 2929 | * Read the register twice since the link bit is sticky. |
| 2930 | */ |
| 2931 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2932 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | return ret_val; |
| 2934 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2935 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | return ret_val; |
| 2937 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2938 | if (phy_data & MII_SR_LINK_STATUS) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2939 | hw->get_link_status = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | /* Check if there was DownShift, must be checked immediately after |
| 2941 | * link-up */ |
| 2942 | e1000_check_downshift(hw); |
| 2943 | |
| 2944 | /* If we are on 82544 or 82543 silicon and speed/duplex |
| 2945 | * are forced to 10H or 10F, then we will implement the polarity |
| 2946 | * reversal workaround. We disable interrupts first, and upon |
| 2947 | * returning, place the devices interrupt state to its previous |
| 2948 | * value except for the link status change interrupt which will |
| 2949 | * happen due to the execution of this workaround. |
| 2950 | */ |
| 2951 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2952 | if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) && |
| 2953 | (!hw->autoneg) && |
| 2954 | (hw->forced_speed_duplex == e1000_10_full || |
| 2955 | hw->forced_speed_duplex == e1000_10_half)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | E1000_WRITE_REG(hw, IMC, 0xffffffff); |
| 2957 | ret_val = e1000_polarity_reversal_workaround(hw); |
| 2958 | icr = E1000_READ_REG(hw, ICR); |
| 2959 | E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC)); |
| 2960 | E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK); |
| 2961 | } |
| 2962 | |
| 2963 | } else { |
| 2964 | /* No link detected */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2965 | e1000_config_dsp_after_link_change(hw, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | return 0; |
| 2967 | } |
| 2968 | |
| 2969 | /* If we are forcing speed/duplex, then we simply return since |
| 2970 | * we have already determined whether we have link or not. |
| 2971 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2972 | if (!hw->autoneg) return -E1000_ERR_CONFIG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | |
| 2974 | /* optimize the dsp settings for the igp phy */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2975 | e1000_config_dsp_after_link_change(hw, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2976 | |
| 2977 | /* We have a M88E1000 PHY and Auto-Neg is enabled. If we |
| 2978 | * have Si on board that is 82544 or newer, Auto |
| 2979 | * Speed Detection takes care of MAC speed/duplex |
| 2980 | * configuration. So we only need to configure Collision |
| 2981 | * Distance in the MAC. Otherwise, we need to force |
| 2982 | * speed/duplex on the MAC to the current PHY speed/duplex |
| 2983 | * settings. |
| 2984 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2985 | if (hw->mac_type >= e1000_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | e1000_config_collision_dist(hw); |
| 2987 | else { |
| 2988 | ret_val = e1000_config_mac_to_phy(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2989 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | DEBUGOUT("Error configuring MAC to PHY settings\n"); |
| 2991 | return ret_val; |
| 2992 | } |
| 2993 | } |
| 2994 | |
| 2995 | /* Configure Flow Control now that Auto-Neg has completed. First, we |
| 2996 | * need to restore the desired flow control settings because we may |
| 2997 | * have had to re-autoneg with a different link partner. |
| 2998 | */ |
| 2999 | ret_val = e1000_config_fc_after_link_up(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3000 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | DEBUGOUT("Error configuring flow control\n"); |
| 3002 | return ret_val; |
| 3003 | } |
| 3004 | |
| 3005 | /* At this point we know that we are on copper and we have |
| 3006 | * auto-negotiated link. These are conditions for checking the link |
| 3007 | * partner capability register. We use the link speed to determine if |
| 3008 | * TBI compatibility needs to be turned on or off. If the link is not |
| 3009 | * at gigabit speed, then TBI compatibility is not needed. If we are |
| 3010 | * at gigabit speed, we turn on TBI compatibility. |
| 3011 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3012 | if (hw->tbi_compatibility_en) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3013 | u16 speed, duplex; |
Auke Kok | 592600a | 2006-06-27 09:08:09 -0700 | [diff] [blame] | 3014 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); |
| 3015 | if (ret_val) { |
| 3016 | DEBUGOUT("Error getting link speed and duplex\n"); |
| 3017 | return ret_val; |
| 3018 | } |
| 3019 | if (speed != SPEED_1000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | /* If link speed is not set to gigabit speed, we do not need |
| 3021 | * to enable TBI compatibility. |
| 3022 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3023 | if (hw->tbi_compatibility_on) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | /* If we previously were in the mode, turn it off. */ |
| 3025 | rctl = E1000_READ_REG(hw, RCTL); |
| 3026 | rctl &= ~E1000_RCTL_SBP; |
| 3027 | E1000_WRITE_REG(hw, RCTL, rctl); |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3028 | hw->tbi_compatibility_on = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | } |
| 3030 | } else { |
| 3031 | /* If TBI compatibility is was previously off, turn it on. For |
| 3032 | * compatibility with a TBI link partner, we will store bad |
| 3033 | * packets. Some frames have an additional byte on the end and |
| 3034 | * will look like CRC errors to to the hardware. |
| 3035 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3036 | if (!hw->tbi_compatibility_on) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3037 | hw->tbi_compatibility_on = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | rctl = E1000_READ_REG(hw, RCTL); |
| 3039 | rctl |= E1000_RCTL_SBP; |
| 3040 | E1000_WRITE_REG(hw, RCTL, rctl); |
| 3041 | } |
| 3042 | } |
| 3043 | } |
| 3044 | } |
| 3045 | /* If we don't have link (auto-negotiation failed or link partner cannot |
| 3046 | * auto-negotiate), the cable is plugged in (we have signal), and our |
| 3047 | * link partner is not trying to auto-negotiate with us (we are receiving |
| 3048 | * idles or data), we need to force link up. We also need to give |
| 3049 | * auto-negotiation time to complete, in case the cable was just plugged |
| 3050 | * in. The autoneg_failed flag does this. |
| 3051 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3052 | else if ((((hw->media_type == e1000_media_type_fiber) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | ((ctrl & E1000_CTRL_SWDPIN1) == signal)) || |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3054 | (hw->media_type == e1000_media_type_internal_serdes)) && |
| 3055 | (!(status & E1000_STATUS_LU)) && |
| 3056 | (!(rxcw & E1000_RXCW_C))) { |
| 3057 | if (hw->autoneg_failed == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | hw->autoneg_failed = 1; |
| 3059 | return 0; |
| 3060 | } |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 3061 | DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | |
| 3063 | /* Disable auto-negotiation in the TXCW register */ |
| 3064 | E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE)); |
| 3065 | |
| 3066 | /* Force link-up and also force full-duplex. */ |
| 3067 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3068 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); |
| 3069 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 3070 | |
| 3071 | /* Configure Flow Control after forcing link up. */ |
| 3072 | ret_val = e1000_config_fc_after_link_up(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3073 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | DEBUGOUT("Error configuring flow control\n"); |
| 3075 | return ret_val; |
| 3076 | } |
| 3077 | } |
| 3078 | /* If we are forcing link and we are receiving /C/ ordered sets, re-enable |
| 3079 | * auto-negotiation in the TXCW register and disable forced link in the |
| 3080 | * Device Control register in an attempt to auto-negotiate with our link |
| 3081 | * partner. |
| 3082 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3083 | else if (((hw->media_type == e1000_media_type_fiber) || |
| 3084 | (hw->media_type == e1000_media_type_internal_serdes)) && |
| 3085 | (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 3086 | DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | E1000_WRITE_REG(hw, TXCW, hw->txcw); |
| 3088 | E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU)); |
| 3089 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3090 | hw->serdes_link_down = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | } |
| 3092 | /* If we force link for non-auto-negotiation switch, check link status |
| 3093 | * based on MAC synchronization for internal serdes media type. |
| 3094 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3095 | else if ((hw->media_type == e1000_media_type_internal_serdes) && |
| 3096 | !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | /* SYNCH bit and IV bit are sticky. */ |
| 3098 | udelay(10); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3099 | if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) { |
| 3100 | if (!(rxcw & E1000_RXCW_IV)) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3101 | hw->serdes_link_down = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | DEBUGOUT("SERDES: Link is up.\n"); |
| 3103 | } |
| 3104 | } else { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3105 | hw->serdes_link_down = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | DEBUGOUT("SERDES: Link is down.\n"); |
| 3107 | } |
| 3108 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3109 | if ((hw->media_type == e1000_media_type_internal_serdes) && |
| 3110 | (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS)); |
| 3112 | } |
| 3113 | return E1000_SUCCESS; |
| 3114 | } |
| 3115 | |
| 3116 | /****************************************************************************** |
| 3117 | * Detects the current speed and duplex settings of the hardware. |
| 3118 | * |
| 3119 | * hw - Struct containing variables accessed by shared code |
| 3120 | * speed - Speed of the connection |
| 3121 | * duplex - Duplex setting of the connection |
| 3122 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3123 | s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3125 | u32 status; |
| 3126 | s32 ret_val; |
| 3127 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | |
| 3129 | DEBUGFUNC("e1000_get_speed_and_duplex"); |
| 3130 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3131 | if (hw->mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | status = E1000_READ_REG(hw, STATUS); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3133 | if (status & E1000_STATUS_SPEED_1000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | *speed = SPEED_1000; |
| 3135 | DEBUGOUT("1000 Mbs, "); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3136 | } else if (status & E1000_STATUS_SPEED_100) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | *speed = SPEED_100; |
| 3138 | DEBUGOUT("100 Mbs, "); |
| 3139 | } else { |
| 3140 | *speed = SPEED_10; |
| 3141 | DEBUGOUT("10 Mbs, "); |
| 3142 | } |
| 3143 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3144 | if (status & E1000_STATUS_FD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | *duplex = FULL_DUPLEX; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 3146 | DEBUGOUT("Full Duplex\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | } else { |
| 3148 | *duplex = HALF_DUPLEX; |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 3149 | DEBUGOUT(" Half Duplex\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | } |
| 3151 | } else { |
Auke Kok | a42a507 | 2006-05-23 13:36:01 -0700 | [diff] [blame] | 3152 | DEBUGOUT("1000 Mbs, Full Duplex\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | *speed = SPEED_1000; |
| 3154 | *duplex = FULL_DUPLEX; |
| 3155 | } |
| 3156 | |
| 3157 | /* IGP01 PHY may advertise full duplex operation after speed downgrade even |
| 3158 | * if it is operating at half duplex. Here we set the duplex settings to |
| 3159 | * match the duplex in the link partner's capabilities. |
| 3160 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3161 | if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3163 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | return ret_val; |
| 3165 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3166 | if (!(phy_data & NWAY_ER_LP_NWAY_CAPS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | *duplex = HALF_DUPLEX; |
| 3168 | else { |
| 3169 | ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3170 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | return ret_val; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3172 | if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS))) |
| 3174 | *duplex = HALF_DUPLEX; |
| 3175 | } |
| 3176 | } |
| 3177 | |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3178 | if ((hw->mac_type == e1000_80003es2lan) && |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3179 | (hw->media_type == e1000_media_type_copper)) { |
| 3180 | if (*speed == SPEED_1000) |
| 3181 | ret_val = e1000_configure_kmrn_for_1000(hw); |
| 3182 | else |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3183 | ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex); |
| 3184 | if (ret_val) |
| 3185 | return ret_val; |
| 3186 | } |
| 3187 | |
| 3188 | if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) { |
| 3189 | ret_val = e1000_kumeran_lock_loss_workaround(hw); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3190 | if (ret_val) |
| 3191 | return ret_val; |
| 3192 | } |
| 3193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | return E1000_SUCCESS; |
| 3195 | } |
| 3196 | |
| 3197 | /****************************************************************************** |
| 3198 | * Blocks until autoneg completes or times out (~4.5 seconds) |
| 3199 | * |
| 3200 | * hw - Struct containing variables accessed by shared code |
| 3201 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3202 | static s32 e1000_wait_autoneg(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3204 | s32 ret_val; |
| 3205 | u16 i; |
| 3206 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | |
| 3208 | DEBUGFUNC("e1000_wait_autoneg"); |
| 3209 | DEBUGOUT("Waiting for Auto-Neg to complete.\n"); |
| 3210 | |
| 3211 | /* 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] | 3212 | for (i = PHY_AUTO_NEG_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | /* Read the MII Status Register and wait for Auto-Neg |
| 3214 | * Complete bit to be set. |
| 3215 | */ |
| 3216 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3217 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | return ret_val; |
| 3219 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3220 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | return ret_val; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3222 | if (phy_data & MII_SR_AUTONEG_COMPLETE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | return E1000_SUCCESS; |
| 3224 | } |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 3225 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | } |
| 3227 | return E1000_SUCCESS; |
| 3228 | } |
| 3229 | |
| 3230 | /****************************************************************************** |
| 3231 | * Raises the Management Data Clock |
| 3232 | * |
| 3233 | * hw - Struct containing variables accessed by shared code |
| 3234 | * ctrl - Device control register's current value |
| 3235 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3236 | static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | { |
| 3238 | /* Raise the clock input to the Management Data Clock (by setting the MDC |
| 3239 | * bit), and then delay 10 microseconds. |
| 3240 | */ |
| 3241 | E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC)); |
| 3242 | E1000_WRITE_FLUSH(hw); |
| 3243 | udelay(10); |
| 3244 | } |
| 3245 | |
| 3246 | /****************************************************************************** |
| 3247 | * Lowers the Management Data Clock |
| 3248 | * |
| 3249 | * hw - Struct containing variables accessed by shared code |
| 3250 | * ctrl - Device control register's current value |
| 3251 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3252 | static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | { |
| 3254 | /* Lower the clock input to the Management Data Clock (by clearing the MDC |
| 3255 | * bit), and then delay 10 microseconds. |
| 3256 | */ |
| 3257 | E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC)); |
| 3258 | E1000_WRITE_FLUSH(hw); |
| 3259 | udelay(10); |
| 3260 | } |
| 3261 | |
| 3262 | /****************************************************************************** |
| 3263 | * Shifts data bits out to the PHY |
| 3264 | * |
| 3265 | * hw - Struct containing variables accessed by shared code |
| 3266 | * data - Data to send out to the PHY |
| 3267 | * count - Number of bits to shift out |
| 3268 | * |
| 3269 | * Bits are shifted out in MSB to LSB order. |
| 3270 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3271 | static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3273 | u32 ctrl; |
| 3274 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | |
| 3276 | /* We need to shift "count" number of bits out to the PHY. So, the value |
| 3277 | * in the "data" parameter will be shifted out to the PHY one bit at a |
| 3278 | * time. In order to do this, "data" must be broken down into bits. |
| 3279 | */ |
| 3280 | mask = 0x01; |
| 3281 | mask <<= (count - 1); |
| 3282 | |
| 3283 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3284 | |
| 3285 | /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */ |
| 3286 | ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR); |
| 3287 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3288 | while (mask) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3289 | /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and |
| 3290 | * then raising and lowering the Management Data Clock. A "0" is |
| 3291 | * shifted out to the PHY by setting the MDIO bit to "0" and then |
| 3292 | * raising and lowering the clock. |
| 3293 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3294 | if (data & mask) |
| 3295 | ctrl |= E1000_CTRL_MDIO; |
| 3296 | else |
| 3297 | ctrl &= ~E1000_CTRL_MDIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | |
| 3299 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 3300 | E1000_WRITE_FLUSH(hw); |
| 3301 | |
| 3302 | udelay(10); |
| 3303 | |
| 3304 | e1000_raise_mdi_clk(hw, &ctrl); |
| 3305 | e1000_lower_mdi_clk(hw, &ctrl); |
| 3306 | |
| 3307 | mask = mask >> 1; |
| 3308 | } |
| 3309 | } |
| 3310 | |
| 3311 | /****************************************************************************** |
| 3312 | * Shifts data bits in from the PHY |
| 3313 | * |
| 3314 | * hw - Struct containing variables accessed by shared code |
| 3315 | * |
| 3316 | * Bits are shifted in in MSB to LSB order. |
| 3317 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3318 | static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3319 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3320 | u32 ctrl; |
| 3321 | u16 data = 0; |
| 3322 | u8 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | |
| 3324 | /* In order to read a register from the PHY, we need to shift in a total |
| 3325 | * of 18 bits from the PHY. The first two bit (turnaround) times are used |
| 3326 | * to avoid contention on the MDIO pin when a read operation is performed. |
| 3327 | * These two bits are ignored by us and thrown away. Bits are "shifted in" |
| 3328 | * by raising the input to the Management Data Clock (setting the MDC bit), |
| 3329 | * and then reading the value of the MDIO bit. |
| 3330 | */ |
| 3331 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3332 | |
| 3333 | /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */ |
| 3334 | ctrl &= ~E1000_CTRL_MDIO_DIR; |
| 3335 | ctrl &= ~E1000_CTRL_MDIO; |
| 3336 | |
| 3337 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 3338 | E1000_WRITE_FLUSH(hw); |
| 3339 | |
| 3340 | /* Raise and Lower the clock before reading in the data. This accounts for |
| 3341 | * the turnaround bits. The first clock occurred when we clocked out the |
| 3342 | * last bit of the Register Address. |
| 3343 | */ |
| 3344 | e1000_raise_mdi_clk(hw, &ctrl); |
| 3345 | e1000_lower_mdi_clk(hw, &ctrl); |
| 3346 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3347 | for (data = 0, i = 0; i < 16; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | data = data << 1; |
| 3349 | e1000_raise_mdi_clk(hw, &ctrl); |
| 3350 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3351 | /* Check to see if we shifted in a "1". */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3352 | if (ctrl & E1000_CTRL_MDIO) |
| 3353 | data |= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | e1000_lower_mdi_clk(hw, &ctrl); |
| 3355 | } |
| 3356 | |
| 3357 | e1000_raise_mdi_clk(hw, &ctrl); |
| 3358 | e1000_lower_mdi_clk(hw, &ctrl); |
| 3359 | |
| 3360 | return data; |
| 3361 | } |
| 3362 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3363 | static s32 e1000_swfw_sync_acquire(struct e1000_hw *hw, u16 mask) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3364 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3365 | u32 swfw_sync = 0; |
| 3366 | u32 swmask = mask; |
| 3367 | u32 fwmask = mask << 16; |
| 3368 | s32 timeout = 200; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3369 | |
| 3370 | DEBUGFUNC("e1000_swfw_sync_acquire"); |
| 3371 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3372 | if (hw->swfwhw_semaphore_present) |
| 3373 | return e1000_get_software_flag(hw); |
| 3374 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3375 | if (!hw->swfw_sync_present) |
| 3376 | return e1000_get_hw_eeprom_semaphore(hw); |
| 3377 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3378 | while (timeout) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3379 | if (e1000_get_hw_eeprom_semaphore(hw)) |
| 3380 | return -E1000_ERR_SWFW_SYNC; |
| 3381 | |
| 3382 | swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC); |
| 3383 | if (!(swfw_sync & (fwmask | swmask))) { |
| 3384 | break; |
| 3385 | } |
| 3386 | |
| 3387 | /* firmware currently using resource (fwmask) */ |
| 3388 | /* or other software thread currently using resource (swmask) */ |
| 3389 | e1000_put_hw_eeprom_semaphore(hw); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 3390 | mdelay(5); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3391 | timeout--; |
| 3392 | } |
| 3393 | |
| 3394 | if (!timeout) { |
| 3395 | DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n"); |
| 3396 | return -E1000_ERR_SWFW_SYNC; |
| 3397 | } |
| 3398 | |
| 3399 | swfw_sync |= swmask; |
| 3400 | E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync); |
| 3401 | |
| 3402 | e1000_put_hw_eeprom_semaphore(hw); |
| 3403 | return E1000_SUCCESS; |
| 3404 | } |
| 3405 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3406 | static void e1000_swfw_sync_release(struct e1000_hw *hw, u16 mask) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3407 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3408 | u32 swfw_sync; |
| 3409 | u32 swmask = mask; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3410 | |
| 3411 | DEBUGFUNC("e1000_swfw_sync_release"); |
| 3412 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3413 | if (hw->swfwhw_semaphore_present) { |
| 3414 | e1000_release_software_flag(hw); |
| 3415 | return; |
| 3416 | } |
| 3417 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3418 | if (!hw->swfw_sync_present) { |
| 3419 | e1000_put_hw_eeprom_semaphore(hw); |
| 3420 | return; |
| 3421 | } |
| 3422 | |
| 3423 | /* if (e1000_get_hw_eeprom_semaphore(hw)) |
| 3424 | * return -E1000_ERR_SWFW_SYNC; */ |
| 3425 | while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS); |
| 3426 | /* empty */ |
| 3427 | |
| 3428 | swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC); |
| 3429 | swfw_sync &= ~swmask; |
| 3430 | E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync); |
| 3431 | |
| 3432 | e1000_put_hw_eeprom_semaphore(hw); |
| 3433 | } |
| 3434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | /***************************************************************************** |
| 3436 | * Reads the value from a PHY register, if the value is on a specific non zero |
| 3437 | * page, sets the page first. |
| 3438 | * hw - Struct containing variables accessed by shared code |
| 3439 | * reg_addr - address of the PHY register to read |
| 3440 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3441 | s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3443 | u32 ret_val; |
| 3444 | u16 swfw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3445 | |
| 3446 | DEBUGFUNC("e1000_read_phy_reg"); |
| 3447 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3448 | if ((hw->mac_type == e1000_80003es2lan) && |
| 3449 | (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) { |
| 3450 | swfw = E1000_SWFW_PHY1_SM; |
| 3451 | } else { |
| 3452 | swfw = E1000_SWFW_PHY0_SM; |
| 3453 | } |
| 3454 | if (e1000_swfw_sync_acquire(hw, swfw)) |
| 3455 | return -E1000_ERR_SWFW_SYNC; |
| 3456 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3457 | if ((hw->phy_type == e1000_phy_igp || |
| 3458 | hw->phy_type == e1000_phy_igp_3 || |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3459 | hw->phy_type == e1000_phy_igp_2) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { |
| 3461 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3462 | (u16)reg_addr); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3463 | if (ret_val) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3464 | e1000_swfw_sync_release(hw, swfw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 | return ret_val; |
| 3466 | } |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3467 | } else if (hw->phy_type == e1000_phy_gg82563) { |
| 3468 | if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) || |
| 3469 | (hw->mac_type == e1000_80003es2lan)) { |
| 3470 | /* Select Configuration Page */ |
| 3471 | if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) { |
| 3472 | ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3473 | (u16)((u16)reg_addr >> GG82563_PAGE_SHIFT)); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3474 | } else { |
| 3475 | /* Use Alternative Page Select register to access |
| 3476 | * registers 30 and 31 |
| 3477 | */ |
| 3478 | ret_val = e1000_write_phy_reg_ex(hw, |
| 3479 | GG82563_PHY_PAGE_SELECT_ALT, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3480 | (u16)((u16)reg_addr >> GG82563_PAGE_SHIFT)); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3481 | } |
| 3482 | |
| 3483 | if (ret_val) { |
| 3484 | e1000_swfw_sync_release(hw, swfw); |
| 3485 | return ret_val; |
| 3486 | } |
| 3487 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | } |
| 3489 | |
| 3490 | ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, |
| 3491 | phy_data); |
| 3492 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3493 | e1000_swfw_sync_release(hw, swfw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | return ret_val; |
| 3495 | } |
| 3496 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3497 | static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, |
| 3498 | u16 *phy_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3500 | u32 i; |
| 3501 | u32 mdic = 0; |
| 3502 | const u32 phy_addr = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | |
| 3504 | DEBUGFUNC("e1000_read_phy_reg_ex"); |
| 3505 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3506 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3507 | DEBUGOUT1("PHY Address %d is out of range\n", reg_addr); |
| 3508 | return -E1000_ERR_PARAM; |
| 3509 | } |
| 3510 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3511 | if (hw->mac_type > e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | /* Set up Op-code, Phy Address, and register address in the MDI |
| 3513 | * Control register. The MAC will take care of interfacing with the |
| 3514 | * PHY to retrieve the desired data. |
| 3515 | */ |
| 3516 | mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) | |
| 3517 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 3518 | (E1000_MDIC_OP_READ)); |
| 3519 | |
| 3520 | E1000_WRITE_REG(hw, MDIC, mdic); |
| 3521 | |
| 3522 | /* Poll the ready bit to see if the MDI read completed */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3523 | for (i = 0; i < 64; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | udelay(50); |
| 3525 | mdic = E1000_READ_REG(hw, MDIC); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3526 | if (mdic & E1000_MDIC_READY) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3528 | if (!(mdic & E1000_MDIC_READY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | DEBUGOUT("MDI Read did not complete\n"); |
| 3530 | return -E1000_ERR_PHY; |
| 3531 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3532 | if (mdic & E1000_MDIC_ERROR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | DEBUGOUT("MDI Error\n"); |
| 3534 | return -E1000_ERR_PHY; |
| 3535 | } |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3536 | *phy_data = (u16) mdic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | } else { |
| 3538 | /* We must first send a preamble through the MDIO pin to signal the |
| 3539 | * beginning of an MII instruction. This is done by sending 32 |
| 3540 | * consecutive "1" bits. |
| 3541 | */ |
| 3542 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
| 3543 | |
| 3544 | /* Now combine the next few fields that are required for a read |
| 3545 | * operation. We use this method instead of calling the |
| 3546 | * e1000_shift_out_mdi_bits routine five different times. The format of |
| 3547 | * a MII read instruction consists of a shift out of 14 bits and is |
| 3548 | * defined as follows: |
| 3549 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr> |
| 3550 | * followed by a shift in of 18 bits. This first two bits shifted in |
| 3551 | * are TurnAround bits used to avoid contention on the MDIO pin when a |
| 3552 | * READ operation is performed. These two bits are thrown away |
| 3553 | * followed by a shift in of 16 bits which contains the desired data. |
| 3554 | */ |
| 3555 | mdic = ((reg_addr) | (phy_addr << 5) | |
| 3556 | (PHY_OP_READ << 10) | (PHY_SOF << 12)); |
| 3557 | |
| 3558 | e1000_shift_out_mdi_bits(hw, mdic, 14); |
| 3559 | |
| 3560 | /* Now that we've shifted out the read command to the MII, we need to |
| 3561 | * "shift in" the 16-bit value (18 total bits) of the requested PHY |
| 3562 | * register address. |
| 3563 | */ |
| 3564 | *phy_data = e1000_shift_in_mdi_bits(hw); |
| 3565 | } |
| 3566 | return E1000_SUCCESS; |
| 3567 | } |
| 3568 | |
| 3569 | /****************************************************************************** |
| 3570 | * Writes a value to a PHY register |
| 3571 | * |
| 3572 | * hw - Struct containing variables accessed by shared code |
| 3573 | * reg_addr - address of the PHY register to write |
| 3574 | * data - data to write to the PHY |
| 3575 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3576 | s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3578 | u32 ret_val; |
| 3579 | u16 swfw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | |
| 3581 | DEBUGFUNC("e1000_write_phy_reg"); |
| 3582 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3583 | if ((hw->mac_type == e1000_80003es2lan) && |
| 3584 | (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) { |
| 3585 | swfw = E1000_SWFW_PHY1_SM; |
| 3586 | } else { |
| 3587 | swfw = E1000_SWFW_PHY0_SM; |
| 3588 | } |
| 3589 | if (e1000_swfw_sync_acquire(hw, swfw)) |
| 3590 | return -E1000_ERR_SWFW_SYNC; |
| 3591 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3592 | if ((hw->phy_type == e1000_phy_igp || |
| 3593 | hw->phy_type == e1000_phy_igp_3 || |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3594 | hw->phy_type == e1000_phy_igp_2) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | (reg_addr > MAX_PHY_MULTI_PAGE_REG)) { |
| 3596 | ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3597 | (u16)reg_addr); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3598 | if (ret_val) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3599 | e1000_swfw_sync_release(hw, swfw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3600 | return ret_val; |
| 3601 | } |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3602 | } else if (hw->phy_type == e1000_phy_gg82563) { |
| 3603 | if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) || |
| 3604 | (hw->mac_type == e1000_80003es2lan)) { |
| 3605 | /* Select Configuration Page */ |
| 3606 | if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) { |
| 3607 | ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3608 | (u16)((u16)reg_addr >> GG82563_PAGE_SHIFT)); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3609 | } else { |
| 3610 | /* Use Alternative Page Select register to access |
| 3611 | * registers 30 and 31 |
| 3612 | */ |
| 3613 | ret_val = e1000_write_phy_reg_ex(hw, |
| 3614 | GG82563_PHY_PAGE_SELECT_ALT, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3615 | (u16)((u16)reg_addr >> GG82563_PAGE_SHIFT)); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | if (ret_val) { |
| 3619 | e1000_swfw_sync_release(hw, swfw); |
| 3620 | return ret_val; |
| 3621 | } |
| 3622 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr, |
| 3626 | phy_data); |
| 3627 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3628 | e1000_swfw_sync_release(hw, swfw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3629 | return ret_val; |
| 3630 | } |
| 3631 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3632 | static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr, |
| 3633 | u16 phy_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3635 | u32 i; |
| 3636 | u32 mdic = 0; |
| 3637 | const u32 phy_addr = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | |
| 3639 | DEBUGFUNC("e1000_write_phy_reg_ex"); |
| 3640 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3641 | if (reg_addr > MAX_PHY_REG_ADDRESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | DEBUGOUT1("PHY Address %d is out of range\n", reg_addr); |
| 3643 | return -E1000_ERR_PARAM; |
| 3644 | } |
| 3645 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3646 | if (hw->mac_type > e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | /* Set up Op-code, Phy Address, register address, and data intended |
| 3648 | * for the PHY register in the MDI Control register. The MAC will take |
| 3649 | * care of interfacing with the PHY to send the desired data. |
| 3650 | */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3651 | mdic = (((u32) phy_data) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | (reg_addr << E1000_MDIC_REG_SHIFT) | |
| 3653 | (phy_addr << E1000_MDIC_PHY_SHIFT) | |
| 3654 | (E1000_MDIC_OP_WRITE)); |
| 3655 | |
| 3656 | E1000_WRITE_REG(hw, MDIC, mdic); |
| 3657 | |
| 3658 | /* Poll the ready bit to see if the MDI read completed */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3659 | for (i = 0; i < 641; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | udelay(5); |
| 3661 | mdic = E1000_READ_REG(hw, MDIC); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3662 | if (mdic & E1000_MDIC_READY) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3663 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3664 | if (!(mdic & E1000_MDIC_READY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3665 | DEBUGOUT("MDI Write did not complete\n"); |
| 3666 | return -E1000_ERR_PHY; |
| 3667 | } |
| 3668 | } else { |
| 3669 | /* We'll need to use the SW defined pins to shift the write command |
| 3670 | * out to the PHY. We first send a preamble to the PHY to signal the |
| 3671 | * beginning of the MII instruction. This is done by sending 32 |
| 3672 | * consecutive "1" bits. |
| 3673 | */ |
| 3674 | e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE); |
| 3675 | |
| 3676 | /* Now combine the remaining required fields that will indicate a |
| 3677 | * write operation. We use this method instead of calling the |
| 3678 | * e1000_shift_out_mdi_bits routine for each field in the command. The |
| 3679 | * format of a MII write instruction is as follows: |
| 3680 | * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>. |
| 3681 | */ |
| 3682 | mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) | |
| 3683 | (PHY_OP_WRITE << 12) | (PHY_SOF << 14)); |
| 3684 | mdic <<= 16; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3685 | mdic |= (u32) phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | |
| 3687 | e1000_shift_out_mdi_bits(hw, mdic, 32); |
| 3688 | } |
| 3689 | |
| 3690 | return E1000_SUCCESS; |
| 3691 | } |
| 3692 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3693 | static s32 e1000_read_kmrn_reg(struct e1000_hw *hw, u32 reg_addr, u16 *data) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3694 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3695 | u32 reg_val; |
| 3696 | u16 swfw; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3697 | DEBUGFUNC("e1000_read_kmrn_reg"); |
| 3698 | |
| 3699 | if ((hw->mac_type == e1000_80003es2lan) && |
| 3700 | (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) { |
| 3701 | swfw = E1000_SWFW_PHY1_SM; |
| 3702 | } else { |
| 3703 | swfw = E1000_SWFW_PHY0_SM; |
| 3704 | } |
| 3705 | if (e1000_swfw_sync_acquire(hw, swfw)) |
| 3706 | return -E1000_ERR_SWFW_SYNC; |
| 3707 | |
| 3708 | /* Write register address */ |
| 3709 | reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) & |
| 3710 | E1000_KUMCTRLSTA_OFFSET) | |
| 3711 | E1000_KUMCTRLSTA_REN; |
| 3712 | E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val); |
| 3713 | udelay(2); |
| 3714 | |
| 3715 | /* Read the data returned */ |
| 3716 | reg_val = E1000_READ_REG(hw, KUMCTRLSTA); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3717 | *data = (u16)reg_val; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3718 | |
| 3719 | e1000_swfw_sync_release(hw, swfw); |
| 3720 | return E1000_SUCCESS; |
| 3721 | } |
| 3722 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3723 | static s32 e1000_write_kmrn_reg(struct e1000_hw *hw, u32 reg_addr, u16 data) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3724 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3725 | u32 reg_val; |
| 3726 | u16 swfw; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3727 | DEBUGFUNC("e1000_write_kmrn_reg"); |
| 3728 | |
| 3729 | if ((hw->mac_type == e1000_80003es2lan) && |
| 3730 | (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) { |
| 3731 | swfw = E1000_SWFW_PHY1_SM; |
| 3732 | } else { |
| 3733 | swfw = E1000_SWFW_PHY0_SM; |
| 3734 | } |
| 3735 | if (e1000_swfw_sync_acquire(hw, swfw)) |
| 3736 | return -E1000_ERR_SWFW_SYNC; |
| 3737 | |
| 3738 | reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) & |
| 3739 | E1000_KUMCTRLSTA_OFFSET) | data; |
| 3740 | E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val); |
| 3741 | udelay(2); |
| 3742 | |
| 3743 | e1000_swfw_sync_release(hw, swfw); |
| 3744 | return E1000_SUCCESS; |
| 3745 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | /****************************************************************************** |
| 3748 | * Returns the PHY to the power-on reset state |
| 3749 | * |
| 3750 | * hw - Struct containing variables accessed by shared code |
| 3751 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3752 | s32 e1000_phy_hw_reset(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3753 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3754 | u32 ctrl, ctrl_ext; |
| 3755 | u32 led_ctrl; |
| 3756 | s32 ret_val; |
| 3757 | u16 swfw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | |
| 3759 | DEBUGFUNC("e1000_phy_hw_reset"); |
| 3760 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3761 | /* In the case of the phy reset being blocked, it's not an error, we |
| 3762 | * simply return success without performing the reset. */ |
| 3763 | ret_val = e1000_check_phy_reset_block(hw); |
| 3764 | if (ret_val) |
| 3765 | return E1000_SUCCESS; |
| 3766 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3767 | DEBUGOUT("Resetting Phy...\n"); |
| 3768 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3769 | if (hw->mac_type > e1000_82543) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3770 | if ((hw->mac_type == e1000_80003es2lan) && |
| 3771 | (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) { |
| 3772 | swfw = E1000_SWFW_PHY1_SM; |
| 3773 | } else { |
| 3774 | swfw = E1000_SWFW_PHY0_SM; |
| 3775 | } |
| 3776 | if (e1000_swfw_sync_acquire(hw, swfw)) { |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3777 | DEBUGOUT("Unable to acquire swfw sync\n"); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3778 | return -E1000_ERR_SWFW_SYNC; |
| 3779 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3780 | /* Read the device control register and assert the E1000_CTRL_PHY_RST |
| 3781 | * bit. Then, take it out of reset. |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3782 | * For pre-e1000_82571 hardware, we delay for 10ms between the assert |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3783 | * and deassert. For e1000_82571 hardware and later, we instead delay |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 3784 | * for 50us between and 10ms after the deassertion. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | */ |
| 3786 | ctrl = E1000_READ_REG(hw, CTRL); |
| 3787 | E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST); |
| 3788 | E1000_WRITE_FLUSH(hw); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3789 | |
| 3790 | if (hw->mac_type < e1000_82571) |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 3791 | msleep(10); |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 3792 | else |
| 3793 | udelay(100); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3794 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 3796 | E1000_WRITE_FLUSH(hw); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3797 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3798 | if (hw->mac_type >= e1000_82571) |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 3799 | mdelay(10); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 3800 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3801 | e1000_swfw_sync_release(hw, swfw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | } else { |
| 3803 | /* Read the Extended Device Control Register, assert the PHY_RESET_DIR |
| 3804 | * bit to put the PHY into reset. Then, take it out of reset. |
| 3805 | */ |
| 3806 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 3807 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR; |
| 3808 | ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA; |
| 3809 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 3810 | E1000_WRITE_FLUSH(hw); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 3811 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA; |
| 3813 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 3814 | E1000_WRITE_FLUSH(hw); |
| 3815 | } |
| 3816 | udelay(150); |
| 3817 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3818 | if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | /* Configure activity LED after PHY reset */ |
| 3820 | led_ctrl = E1000_READ_REG(hw, LEDCTL); |
| 3821 | led_ctrl &= IGP_ACTIVITY_LED_MASK; |
| 3822 | led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE); |
| 3823 | E1000_WRITE_REG(hw, LEDCTL, led_ctrl); |
| 3824 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3825 | |
| 3826 | /* Wait for FW to finish PHY configuration. */ |
| 3827 | ret_val = e1000_get_phy_cfg_done(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3828 | if (ret_val != E1000_SUCCESS) |
| 3829 | return ret_val; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 3830 | e1000_release_software_semaphore(hw); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3831 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3832 | if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3)) |
| 3833 | ret_val = e1000_init_lcd_from_nvm(hw); |
| 3834 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3835 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | } |
| 3837 | |
| 3838 | /****************************************************************************** |
| 3839 | * Resets the PHY |
| 3840 | * |
| 3841 | * hw - Struct containing variables accessed by shared code |
| 3842 | * |
Matt LaPlante | 0779bf2 | 2006-11-30 05:24:39 +0100 | [diff] [blame] | 3843 | * Sets bit 15 of the MII Control register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3844 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3845 | s32 e1000_phy_reset(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3847 | s32 ret_val; |
| 3848 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3849 | |
| 3850 | DEBUGFUNC("e1000_phy_reset"); |
| 3851 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3852 | /* In the case of the phy reset being blocked, it's not an error, we |
| 3853 | * simply return success without performing the reset. */ |
| 3854 | ret_val = e1000_check_phy_reset_block(hw); |
| 3855 | if (ret_val) |
| 3856 | return E1000_SUCCESS; |
| 3857 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 3858 | switch (hw->phy_type) { |
| 3859 | case e1000_phy_igp: |
| 3860 | case e1000_phy_igp_2: |
| 3861 | case e1000_phy_igp_3: |
| 3862 | case e1000_phy_ife: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3863 | ret_val = e1000_phy_hw_reset(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3864 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3865 | return ret_val; |
| 3866 | break; |
| 3867 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3868 | ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3869 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | return ret_val; |
| 3871 | |
| 3872 | phy_data |= MII_CR_RESET; |
| 3873 | ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3874 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | return ret_val; |
| 3876 | |
| 3877 | udelay(1); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3878 | break; |
| 3879 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3880 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3881 | 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] | 3882 | e1000_phy_init_script(hw); |
| 3883 | |
| 3884 | return E1000_SUCCESS; |
| 3885 | } |
| 3886 | |
| 3887 | /****************************************************************************** |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3888 | * Work-around for 82566 power-down: on D3 entry- |
| 3889 | * 1) disable gigabit link |
| 3890 | * 2) write VR power-down enable |
| 3891 | * 3) read it back |
| 3892 | * if successful continue, else issue LCD reset and repeat |
| 3893 | * |
| 3894 | * hw - struct containing variables accessed by shared code |
| 3895 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3896 | void e1000_phy_powerdown_workaround(struct e1000_hw *hw) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3897 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3898 | s32 reg; |
| 3899 | u16 phy_data; |
| 3900 | s32 retry = 0; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3901 | |
| 3902 | DEBUGFUNC("e1000_phy_powerdown_workaround"); |
| 3903 | |
| 3904 | if (hw->phy_type != e1000_phy_igp_3) |
| 3905 | return; |
| 3906 | |
| 3907 | do { |
| 3908 | /* Disable link */ |
| 3909 | reg = E1000_READ_REG(hw, PHY_CTRL); |
| 3910 | E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE | |
| 3911 | E1000_PHY_CTRL_NOND0A_GBE_DISABLE); |
| 3912 | |
Jeff Kirsher | 070f6ff | 2006-11-01 08:47:44 -0800 | [diff] [blame] | 3913 | /* Write VR power-down enable - bits 9:8 should be 10b */ |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3914 | e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data); |
Jeff Kirsher | 070f6ff | 2006-11-01 08:47:44 -0800 | [diff] [blame] | 3915 | phy_data |= (1 << 9); |
| 3916 | phy_data &= ~(1 << 8); |
| 3917 | e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3918 | |
| 3919 | /* Read it back and test */ |
| 3920 | e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data); |
Jeff Kirsher | 070f6ff | 2006-11-01 08:47:44 -0800 | [diff] [blame] | 3921 | 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] | 3922 | break; |
| 3923 | |
| 3924 | /* Issue PHY reset and repeat at most one more time */ |
| 3925 | reg = E1000_READ_REG(hw, CTRL); |
| 3926 | E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST); |
| 3927 | retry++; |
| 3928 | } while (retry); |
| 3929 | |
| 3930 | return; |
| 3931 | |
| 3932 | } |
| 3933 | |
| 3934 | /****************************************************************************** |
| 3935 | * Work-around for 82566 Kumeran PCS lock loss: |
| 3936 | * On link status change (i.e. PCI reset, speed change) and link is up and |
| 3937 | * speed is gigabit- |
| 3938 | * 0) if workaround is optionally disabled do nothing |
| 3939 | * 1) wait 1ms for Kumeran link to come up |
| 3940 | * 2) check Kumeran Diagnostic register PCS lock loss bit |
| 3941 | * 3) if not set the link is locked (all is good), otherwise... |
| 3942 | * 4) reset the PHY |
| 3943 | * 5) repeat up to 10 times |
| 3944 | * Note: this is only called for IGP3 copper when speed is 1gb. |
| 3945 | * |
| 3946 | * hw - struct containing variables accessed by shared code |
| 3947 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 3948 | static s32 e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3949 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3950 | s32 ret_val; |
| 3951 | s32 reg; |
| 3952 | s32 cnt; |
| 3953 | u16 phy_data; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3954 | |
| 3955 | if (hw->kmrn_lock_loss_workaround_disabled) |
| 3956 | return E1000_SUCCESS; |
| 3957 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 3958 | /* Make sure link is up before proceeding. If not just return. |
| 3959 | * Attempting this while link is negotiating fouled up link |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3960 | * stability */ |
| 3961 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 3962 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
| 3963 | |
| 3964 | if (phy_data & MII_SR_LINK_STATUS) { |
| 3965 | for (cnt = 0; cnt < 10; cnt++) { |
| 3966 | /* read once to clear */ |
| 3967 | ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data); |
| 3968 | if (ret_val) |
| 3969 | return ret_val; |
| 3970 | /* and again to get new status */ |
| 3971 | ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data); |
| 3972 | if (ret_val) |
| 3973 | return ret_val; |
| 3974 | |
| 3975 | /* check for PCS lock */ |
| 3976 | if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS)) |
| 3977 | return E1000_SUCCESS; |
| 3978 | |
| 3979 | /* Issue PHY reset */ |
| 3980 | e1000_phy_hw_reset(hw); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 3981 | mdelay(5); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 3982 | } |
| 3983 | /* Disable GigE link negotiation */ |
| 3984 | reg = E1000_READ_REG(hw, PHY_CTRL); |
| 3985 | E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE | |
| 3986 | E1000_PHY_CTRL_NOND0A_GBE_DISABLE); |
| 3987 | |
| 3988 | /* unable to acquire PCS lock */ |
| 3989 | return E1000_ERR_PHY; |
| 3990 | } |
| 3991 | |
| 3992 | return E1000_SUCCESS; |
| 3993 | } |
| 3994 | |
| 3995 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | * Probes the expected PHY address for known PHY IDs |
| 3997 | * |
| 3998 | * hw - Struct containing variables accessed by shared code |
| 3999 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4000 | static s32 e1000_detect_gig_phy(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4002 | s32 phy_init_status, ret_val; |
| 4003 | u16 phy_id_high, phy_id_low; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4004 | bool match = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4005 | |
| 4006 | DEBUGFUNC("e1000_detect_gig_phy"); |
| 4007 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4008 | if (hw->phy_id != 0) |
| 4009 | return E1000_SUCCESS; |
| 4010 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4011 | /* The 82571 firmware may still be configuring the PHY. In this |
| 4012 | * case, we cannot access the PHY until the configuration is done. So |
| 4013 | * we explicitly set the PHY values. */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4014 | if (hw->mac_type == e1000_82571 || |
| 4015 | hw->mac_type == e1000_82572) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4016 | hw->phy_id = IGP01E1000_I_PHY_ID; |
| 4017 | hw->phy_type = e1000_phy_igp_2; |
| 4018 | return E1000_SUCCESS; |
| 4019 | } |
| 4020 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4021 | /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work- |
| 4022 | * around that forces PHY page 0 to be set or the reads fail. The rest of |
| 4023 | * the code in this routine uses e1000_read_phy_reg to read the PHY ID. |
| 4024 | * So for ESB-2 we need to have this set so our reads won't fail. If the |
| 4025 | * attached PHY is not a e1000_phy_gg82563, the routines below will figure |
| 4026 | * this out as well. */ |
| 4027 | if (hw->mac_type == e1000_80003es2lan) |
| 4028 | hw->phy_type = e1000_phy_gg82563; |
| 4029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | /* Read the PHY ID Registers to identify which PHY is onboard. */ |
| 4031 | ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4032 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | return ret_val; |
| 4034 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4035 | hw->phy_id = (u32) (phy_id_high << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 | udelay(20); |
| 4037 | ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4038 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | return ret_val; |
| 4040 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4041 | hw->phy_id |= (u32) (phy_id_low & PHY_REVISION_MASK); |
| 4042 | hw->phy_revision = (u32) phy_id_low & ~PHY_REVISION_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4044 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | case e1000_82543: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4046 | if (hw->phy_id == M88E1000_E_PHY_ID) match = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | break; |
| 4048 | case e1000_82544: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4049 | if (hw->phy_id == M88E1000_I_PHY_ID) match = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | break; |
| 4051 | case e1000_82540: |
| 4052 | case e1000_82545: |
| 4053 | case e1000_82545_rev_3: |
| 4054 | case e1000_82546: |
| 4055 | case e1000_82546_rev_3: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4056 | if (hw->phy_id == M88E1011_I_PHY_ID) match = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4057 | break; |
| 4058 | case e1000_82541: |
| 4059 | case e1000_82541_rev_2: |
| 4060 | case e1000_82547: |
| 4061 | case e1000_82547_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4062 | if (hw->phy_id == IGP01E1000_I_PHY_ID) match = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4064 | case e1000_82573: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4065 | if (hw->phy_id == M88E1111_I_PHY_ID) match = true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4066 | break; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4067 | case e1000_80003es2lan: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4068 | if (hw->phy_id == GG82563_E_PHY_ID) match = true; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4069 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4070 | case e1000_ich8lan: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4071 | if (hw->phy_id == IGP03E1000_E_PHY_ID) match = true; |
| 4072 | if (hw->phy_id == IFE_E_PHY_ID) match = true; |
| 4073 | if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = true; |
| 4074 | if (hw->phy_id == IFE_C_E_PHY_ID) match = true; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4075 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4076 | default: |
| 4077 | DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type); |
| 4078 | return -E1000_ERR_CONFIG; |
| 4079 | } |
| 4080 | phy_init_status = e1000_set_phy_type(hw); |
| 4081 | |
| 4082 | if ((match) && (phy_init_status == E1000_SUCCESS)) { |
| 4083 | DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id); |
| 4084 | return E1000_SUCCESS; |
| 4085 | } |
| 4086 | DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id); |
| 4087 | return -E1000_ERR_PHY; |
| 4088 | } |
| 4089 | |
| 4090 | /****************************************************************************** |
| 4091 | * Resets the PHY's DSP |
| 4092 | * |
| 4093 | * hw - Struct containing variables accessed by shared code |
| 4094 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4095 | static s32 e1000_phy_reset_dsp(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4097 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4098 | DEBUGFUNC("e1000_phy_reset_dsp"); |
| 4099 | |
| 4100 | do { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4101 | if (hw->phy_type != e1000_phy_gg82563) { |
| 4102 | ret_val = e1000_write_phy_reg(hw, 29, 0x001d); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4103 | if (ret_val) break; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4105 | ret_val = e1000_write_phy_reg(hw, 30, 0x00c1); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4106 | if (ret_val) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | ret_val = e1000_write_phy_reg(hw, 30, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4108 | if (ret_val) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | ret_val = E1000_SUCCESS; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4110 | } while (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4111 | |
| 4112 | return ret_val; |
| 4113 | } |
| 4114 | |
| 4115 | /****************************************************************************** |
| 4116 | * Get PHY information from various PHY registers for igp PHY only. |
| 4117 | * |
| 4118 | * hw - Struct containing variables accessed by shared code |
| 4119 | * phy_info - PHY information structure |
| 4120 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4121 | static s32 e1000_phy_igp_get_info(struct e1000_hw *hw, |
| 4122 | struct e1000_phy_info *phy_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4124 | s32 ret_val; |
| 4125 | u16 phy_data, min_length, max_length, average; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4126 | e1000_rev_polarity polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4127 | |
| 4128 | DEBUGFUNC("e1000_phy_igp_get_info"); |
| 4129 | |
| 4130 | /* The downshift status is checked only once, after link is established, |
| 4131 | * and it stored in the hw->speed_downgraded parameter. */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4132 | phy_info->downshift = (e1000_downshift)hw->speed_downgraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | |
| 4134 | /* IGP01E1000 does not need to support it. */ |
| 4135 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal; |
| 4136 | |
| 4137 | /* IGP01E1000 always correct polarity reversal */ |
| 4138 | phy_info->polarity_correction = e1000_polarity_reversal_enabled; |
| 4139 | |
| 4140 | /* Check polarity status */ |
| 4141 | ret_val = e1000_check_polarity(hw, &polarity); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4142 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4143 | return ret_val; |
| 4144 | |
| 4145 | phy_info->cable_polarity = polarity; |
| 4146 | |
| 4147 | 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] | 4148 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | return ret_val; |
| 4150 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4151 | phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >> |
| 4152 | IGP01E1000_PSSR_MDIX_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4154 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
| 4156 | /* Local/Remote Receiver Information are only valid at 1000 Mbps */ |
| 4157 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4158 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | return ret_val; |
| 4160 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4161 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> |
| 4162 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? |
| 4163 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
| 4164 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> |
| 4165 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? |
| 4166 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4167 | |
| 4168 | /* Get cable length */ |
| 4169 | ret_val = e1000_get_cable_length(hw, &min_length, &max_length); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4170 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4171 | return ret_val; |
| 4172 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4173 | /* Translate to old method */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | average = (max_length + min_length) / 2; |
| 4175 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4176 | if (average <= e1000_igp_cable_length_50) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | phy_info->cable_length = e1000_cable_length_50; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4178 | else if (average <= e1000_igp_cable_length_80) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | phy_info->cable_length = e1000_cable_length_50_80; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4180 | else if (average <= e1000_igp_cable_length_110) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | phy_info->cable_length = e1000_cable_length_80_110; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4182 | else if (average <= e1000_igp_cable_length_140) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | phy_info->cable_length = e1000_cable_length_110_140; |
| 4184 | else |
| 4185 | phy_info->cable_length = e1000_cable_length_140; |
| 4186 | } |
| 4187 | |
| 4188 | return E1000_SUCCESS; |
| 4189 | } |
| 4190 | |
| 4191 | /****************************************************************************** |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 4192 | * Get PHY information from various PHY registers for ife PHY only. |
| 4193 | * |
| 4194 | * hw - Struct containing variables accessed by shared code |
| 4195 | * phy_info - PHY information structure |
| 4196 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4197 | static s32 e1000_phy_ife_get_info(struct e1000_hw *hw, |
| 4198 | struct e1000_phy_info *phy_info) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 4199 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4200 | s32 ret_val; |
| 4201 | u16 phy_data; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4202 | e1000_rev_polarity polarity; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 4203 | |
| 4204 | DEBUGFUNC("e1000_phy_ife_get_info"); |
| 4205 | |
| 4206 | phy_info->downshift = (e1000_downshift)hw->speed_downgraded; |
| 4207 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal; |
| 4208 | |
| 4209 | ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data); |
| 4210 | if (ret_val) |
| 4211 | return ret_val; |
| 4212 | phy_info->polarity_correction = |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4213 | ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >> |
| 4214 | IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ? |
| 4215 | e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 4216 | |
| 4217 | if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) { |
| 4218 | ret_val = e1000_check_polarity(hw, &polarity); |
| 4219 | if (ret_val) |
| 4220 | return ret_val; |
| 4221 | } else { |
| 4222 | /* Polarity is forced. */ |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4223 | polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >> |
| 4224 | IFE_PSC_FORCE_POLARITY_SHIFT) ? |
| 4225 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 4226 | } |
| 4227 | phy_info->cable_polarity = polarity; |
| 4228 | |
| 4229 | ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data); |
| 4230 | if (ret_val) |
| 4231 | return ret_val; |
| 4232 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4233 | phy_info->mdix_mode = (e1000_auto_x_mode) |
| 4234 | ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >> |
| 4235 | IFE_PMC_MDIX_MODE_SHIFT); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 4236 | |
| 4237 | return E1000_SUCCESS; |
| 4238 | } |
| 4239 | |
| 4240 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | * Get PHY information from various PHY registers fot m88 PHY only. |
| 4242 | * |
| 4243 | * hw - Struct containing variables accessed by shared code |
| 4244 | * phy_info - PHY information structure |
| 4245 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4246 | static s32 e1000_phy_m88_get_info(struct e1000_hw *hw, |
| 4247 | struct e1000_phy_info *phy_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4249 | s32 ret_val; |
| 4250 | u16 phy_data; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4251 | e1000_rev_polarity polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | |
| 4253 | DEBUGFUNC("e1000_phy_m88_get_info"); |
| 4254 | |
| 4255 | /* The downshift status is checked only once, after link is established, |
| 4256 | * and it stored in the hw->speed_downgraded parameter. */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4257 | phy_info->downshift = (e1000_downshift)hw->speed_downgraded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | |
| 4259 | 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] | 4260 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4261 | return ret_val; |
| 4262 | |
| 4263 | phy_info->extended_10bt_distance = |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4264 | ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >> |
| 4265 | M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ? |
| 4266 | e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal; |
| 4267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | phy_info->polarity_correction = |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4269 | ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >> |
| 4270 | M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ? |
| 4271 | e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | |
| 4273 | /* Check polarity status */ |
| 4274 | ret_val = e1000_check_polarity(hw, &polarity); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4275 | if (ret_val) |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 4276 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | phy_info->cable_polarity = polarity; |
| 4278 | |
| 4279 | 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] | 4280 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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)((phy_data & M88E1000_PSSR_MDIX) >> |
| 4284 | M88E1000_PSSR_MDIX_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | |
| 4286 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) { |
| 4287 | /* Cable Length Estimation and Local/Remote Receiver Information |
| 4288 | * are only valid at 1000 Mbps. |
| 4289 | */ |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4290 | if (hw->phy_type != e1000_phy_gg82563) { |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4291 | 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] | 4292 | M88E1000_PSSR_CABLE_LENGTH_SHIFT); |
| 4293 | } else { |
| 4294 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE, |
| 4295 | &phy_data); |
| 4296 | if (ret_val) |
| 4297 | return ret_val; |
| 4298 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4299 | 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] | 4300 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | |
| 4302 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4303 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | return ret_val; |
| 4305 | |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 4306 | phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >> |
| 4307 | SR_1000T_LOCAL_RX_STATUS_SHIFT) ? |
| 4308 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
| 4309 | phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >> |
| 4310 | SR_1000T_REMOTE_RX_STATUS_SHIFT) ? |
| 4311 | e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4313 | } |
| 4314 | |
| 4315 | return E1000_SUCCESS; |
| 4316 | } |
| 4317 | |
| 4318 | /****************************************************************************** |
| 4319 | * Get PHY information from various PHY registers |
| 4320 | * |
| 4321 | * hw - Struct containing variables accessed by shared code |
| 4322 | * phy_info - PHY information structure |
| 4323 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4324 | s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4326 | s32 ret_val; |
| 4327 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | |
| 4329 | DEBUGFUNC("e1000_phy_get_info"); |
| 4330 | |
| 4331 | phy_info->cable_length = e1000_cable_length_undefined; |
| 4332 | phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined; |
| 4333 | phy_info->cable_polarity = e1000_rev_polarity_undefined; |
| 4334 | phy_info->downshift = e1000_downshift_undefined; |
| 4335 | phy_info->polarity_correction = e1000_polarity_reversal_undefined; |
| 4336 | phy_info->mdix_mode = e1000_auto_x_mode_undefined; |
| 4337 | phy_info->local_rx = e1000_1000t_rx_status_undefined; |
| 4338 | phy_info->remote_rx = e1000_1000t_rx_status_undefined; |
| 4339 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4340 | if (hw->media_type != e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | DEBUGOUT("PHY info is only valid for copper media\n"); |
| 4342 | return -E1000_ERR_CONFIG; |
| 4343 | } |
| 4344 | |
| 4345 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4346 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | return ret_val; |
| 4348 | |
| 4349 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4350 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4351 | return ret_val; |
| 4352 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4353 | if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4354 | DEBUGOUT("PHY info is only valid if link is up\n"); |
| 4355 | return -E1000_ERR_CONFIG; |
| 4356 | } |
| 4357 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4358 | if (hw->phy_type == e1000_phy_igp || |
| 4359 | hw->phy_type == e1000_phy_igp_3 || |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4360 | hw->phy_type == e1000_phy_igp_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | return e1000_phy_igp_get_info(hw, phy_info); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4362 | else if (hw->phy_type == e1000_phy_ife) |
| 4363 | return e1000_phy_ife_get_info(hw, phy_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | else |
| 4365 | return e1000_phy_m88_get_info(hw, phy_info); |
| 4366 | } |
| 4367 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4368 | s32 e1000_validate_mdi_setting(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4369 | { |
| 4370 | DEBUGFUNC("e1000_validate_mdi_settings"); |
| 4371 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4372 | if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4373 | DEBUGOUT("Invalid MDI setting detected\n"); |
| 4374 | hw->mdix = 1; |
| 4375 | return -E1000_ERR_CONFIG; |
| 4376 | } |
| 4377 | return E1000_SUCCESS; |
| 4378 | } |
| 4379 | |
| 4380 | |
| 4381 | /****************************************************************************** |
| 4382 | * 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] | 4383 | * is configured. Additionally, if this is ICH8, the flash controller GbE |
| 4384 | * registers must be mapped, or this will crash. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | * |
| 4386 | * hw - Struct containing variables accessed by shared code |
| 4387 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4388 | s32 e1000_init_eeprom_params(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4389 | { |
| 4390 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4391 | u32 eecd = E1000_READ_REG(hw, EECD); |
| 4392 | s32 ret_val = E1000_SUCCESS; |
| 4393 | u16 eeprom_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4394 | |
| 4395 | DEBUGFUNC("e1000_init_eeprom_params"); |
| 4396 | |
| 4397 | switch (hw->mac_type) { |
| 4398 | case e1000_82542_rev2_0: |
| 4399 | case e1000_82542_rev2_1: |
| 4400 | case e1000_82543: |
| 4401 | case e1000_82544: |
| 4402 | eeprom->type = e1000_eeprom_microwire; |
| 4403 | eeprom->word_size = 64; |
| 4404 | eeprom->opcode_bits = 3; |
| 4405 | eeprom->address_bits = 6; |
| 4406 | eeprom->delay_usec = 50; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4407 | eeprom->use_eerd = false; |
| 4408 | eeprom->use_eewr = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4409 | break; |
| 4410 | case e1000_82540: |
| 4411 | case e1000_82545: |
| 4412 | case e1000_82545_rev_3: |
| 4413 | case e1000_82546: |
| 4414 | case e1000_82546_rev_3: |
| 4415 | eeprom->type = e1000_eeprom_microwire; |
| 4416 | eeprom->opcode_bits = 3; |
| 4417 | eeprom->delay_usec = 50; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4418 | if (eecd & E1000_EECD_SIZE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | eeprom->word_size = 256; |
| 4420 | eeprom->address_bits = 8; |
| 4421 | } else { |
| 4422 | eeprom->word_size = 64; |
| 4423 | eeprom->address_bits = 6; |
| 4424 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4425 | eeprom->use_eerd = false; |
| 4426 | eeprom->use_eewr = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | break; |
| 4428 | case e1000_82541: |
| 4429 | case e1000_82541_rev_2: |
| 4430 | case e1000_82547: |
| 4431 | case e1000_82547_rev_2: |
| 4432 | if (eecd & E1000_EECD_TYPE) { |
| 4433 | eeprom->type = e1000_eeprom_spi; |
| 4434 | eeprom->opcode_bits = 8; |
| 4435 | eeprom->delay_usec = 1; |
| 4436 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 4437 | eeprom->page_size = 32; |
| 4438 | eeprom->address_bits = 16; |
| 4439 | } else { |
| 4440 | eeprom->page_size = 8; |
| 4441 | eeprom->address_bits = 8; |
| 4442 | } |
| 4443 | } else { |
| 4444 | eeprom->type = e1000_eeprom_microwire; |
| 4445 | eeprom->opcode_bits = 3; |
| 4446 | eeprom->delay_usec = 50; |
| 4447 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 4448 | eeprom->word_size = 256; |
| 4449 | eeprom->address_bits = 8; |
| 4450 | } else { |
| 4451 | eeprom->word_size = 64; |
| 4452 | eeprom->address_bits = 6; |
| 4453 | } |
| 4454 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4455 | eeprom->use_eerd = false; |
| 4456 | eeprom->use_eewr = false; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4457 | break; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4458 | case e1000_82571: |
| 4459 | case e1000_82572: |
| 4460 | eeprom->type = e1000_eeprom_spi; |
| 4461 | eeprom->opcode_bits = 8; |
| 4462 | eeprom->delay_usec = 1; |
| 4463 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 4464 | eeprom->page_size = 32; |
| 4465 | eeprom->address_bits = 16; |
| 4466 | } else { |
| 4467 | eeprom->page_size = 8; |
| 4468 | eeprom->address_bits = 8; |
| 4469 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4470 | eeprom->use_eerd = false; |
| 4471 | eeprom->use_eewr = false; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4472 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4473 | case e1000_82573: |
| 4474 | eeprom->type = e1000_eeprom_spi; |
| 4475 | eeprom->opcode_bits = 8; |
| 4476 | eeprom->delay_usec = 1; |
| 4477 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 4478 | eeprom->page_size = 32; |
| 4479 | eeprom->address_bits = 16; |
| 4480 | } else { |
| 4481 | eeprom->page_size = 8; |
| 4482 | eeprom->address_bits = 8; |
| 4483 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4484 | eeprom->use_eerd = true; |
| 4485 | eeprom->use_eewr = true; |
| 4486 | if (!e1000_is_onboard_nvm_eeprom(hw)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4487 | eeprom->type = e1000_eeprom_flash; |
| 4488 | eeprom->word_size = 2048; |
| 4489 | |
| 4490 | /* Ensure that the Autonomous FLASH update bit is cleared due to |
| 4491 | * Flash update issue on parts which use a FLASH for NVM. */ |
| 4492 | eecd &= ~E1000_EECD_AUPDEN; |
| 4493 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4494 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | break; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4496 | case e1000_80003es2lan: |
| 4497 | eeprom->type = e1000_eeprom_spi; |
| 4498 | eeprom->opcode_bits = 8; |
| 4499 | eeprom->delay_usec = 1; |
| 4500 | if (eecd & E1000_EECD_ADDR_BITS) { |
| 4501 | eeprom->page_size = 32; |
| 4502 | eeprom->address_bits = 16; |
| 4503 | } else { |
| 4504 | eeprom->page_size = 8; |
| 4505 | eeprom->address_bits = 8; |
| 4506 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4507 | eeprom->use_eerd = true; |
| 4508 | eeprom->use_eewr = false; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4509 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4510 | case e1000_ich8lan: |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 4511 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4512 | s32 i = 0; |
| 4513 | u32 flash_size = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_GFPREG); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4514 | |
| 4515 | eeprom->type = e1000_eeprom_ich8; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4516 | eeprom->use_eerd = false; |
| 4517 | eeprom->use_eewr = false; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4518 | eeprom->word_size = E1000_SHADOW_RAM_WORDS; |
| 4519 | |
| 4520 | /* Zero the shadow RAM structure. But don't load it from NVM |
| 4521 | * so as to save time for driver init */ |
| 4522 | if (hw->eeprom_shadow_ram != NULL) { |
| 4523 | for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4524 | hw->eeprom_shadow_ram[i].modified = false; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4525 | hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF; |
| 4526 | } |
| 4527 | } |
| 4528 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 4529 | hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) * |
| 4530 | ICH_FLASH_SECTOR_SIZE; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4531 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 4532 | hw->flash_bank_size = ((flash_size >> 16) & ICH_GFPREG_BASE_MASK) + 1; |
| 4533 | hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK); |
| 4534 | |
| 4535 | hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE; |
| 4536 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4537 | hw->flash_bank_size /= 2 * sizeof(u16); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4538 | |
| 4539 | break; |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 4540 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | default: |
| 4542 | break; |
| 4543 | } |
| 4544 | |
| 4545 | if (eeprom->type == e1000_eeprom_spi) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4546 | /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to |
| 4547 | * 32KB (incremented by powers of 2). |
| 4548 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4549 | if (hw->mac_type <= e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4550 | /* Set to default value for initial eeprom read. */ |
| 4551 | eeprom->word_size = 64; |
| 4552 | ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4553 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4554 | return ret_val; |
| 4555 | eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT; |
| 4556 | /* 256B eeprom size was not supported in earlier hardware, so we |
| 4557 | * bump eeprom_size up one to ensure that "1" (which maps to 256B) |
| 4558 | * is never the result used in the shifting logic below. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4559 | if (eeprom_size) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4560 | eeprom_size++; |
| 4561 | } else { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4562 | eeprom_size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >> |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4563 | E1000_EECD_SIZE_EX_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4564 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4565 | |
| 4566 | eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4568 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | /****************************************************************************** |
| 4572 | * Raises the EEPROM's clock input. |
| 4573 | * |
| 4574 | * hw - Struct containing variables accessed by shared code |
| 4575 | * eecd - EECD's current value |
| 4576 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4577 | static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | { |
| 4579 | /* Raise the clock input to the EEPROM (by setting the SK bit), and then |
| 4580 | * wait <delay> microseconds. |
| 4581 | */ |
| 4582 | *eecd = *eecd | E1000_EECD_SK; |
| 4583 | E1000_WRITE_REG(hw, EECD, *eecd); |
| 4584 | E1000_WRITE_FLUSH(hw); |
| 4585 | udelay(hw->eeprom.delay_usec); |
| 4586 | } |
| 4587 | |
| 4588 | /****************************************************************************** |
| 4589 | * Lowers the EEPROM's clock input. |
| 4590 | * |
| 4591 | * hw - Struct containing variables accessed by shared code |
| 4592 | * eecd - EECD's current value |
| 4593 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4594 | static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | { |
| 4596 | /* Lower the clock input to the EEPROM (by clearing the SK bit), and then |
| 4597 | * wait 50 microseconds. |
| 4598 | */ |
| 4599 | *eecd = *eecd & ~E1000_EECD_SK; |
| 4600 | E1000_WRITE_REG(hw, EECD, *eecd); |
| 4601 | E1000_WRITE_FLUSH(hw); |
| 4602 | udelay(hw->eeprom.delay_usec); |
| 4603 | } |
| 4604 | |
| 4605 | /****************************************************************************** |
| 4606 | * Shift data bits out to the EEPROM. |
| 4607 | * |
| 4608 | * hw - Struct containing variables accessed by shared code |
| 4609 | * data - data to send to the EEPROM |
| 4610 | * count - number of bits to shift out |
| 4611 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4612 | static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | { |
| 4614 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4615 | u32 eecd; |
| 4616 | u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | |
| 4618 | /* We need to shift "count" bits out to the EEPROM. So, value in the |
| 4619 | * "data" parameter will be shifted out to the EEPROM one bit at a time. |
| 4620 | * In order to do this, "data" must be broken down into bits. |
| 4621 | */ |
| 4622 | mask = 0x01 << (count - 1); |
| 4623 | eecd = E1000_READ_REG(hw, EECD); |
| 4624 | if (eeprom->type == e1000_eeprom_microwire) { |
| 4625 | eecd &= ~E1000_EECD_DO; |
| 4626 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 4627 | eecd |= E1000_EECD_DO; |
| 4628 | } |
| 4629 | do { |
| 4630 | /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1", |
| 4631 | * and then raising and then lowering the clock (the SK bit controls |
| 4632 | * the clock input to the EEPROM). A "0" is shifted out to the EEPROM |
| 4633 | * by setting "DI" to "0" and then raising and then lowering the clock. |
| 4634 | */ |
| 4635 | eecd &= ~E1000_EECD_DI; |
| 4636 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4637 | if (data & mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4638 | eecd |= E1000_EECD_DI; |
| 4639 | |
| 4640 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4641 | E1000_WRITE_FLUSH(hw); |
| 4642 | |
| 4643 | udelay(eeprom->delay_usec); |
| 4644 | |
| 4645 | e1000_raise_ee_clk(hw, &eecd); |
| 4646 | e1000_lower_ee_clk(hw, &eecd); |
| 4647 | |
| 4648 | mask = mask >> 1; |
| 4649 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4650 | } while (mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4651 | |
| 4652 | /* We leave the "DI" bit set to "0" when we leave this routine. */ |
| 4653 | eecd &= ~E1000_EECD_DI; |
| 4654 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4655 | } |
| 4656 | |
| 4657 | /****************************************************************************** |
| 4658 | * Shift data bits in from the EEPROM |
| 4659 | * |
| 4660 | * hw - Struct containing variables accessed by shared code |
| 4661 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4662 | static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4664 | u32 eecd; |
| 4665 | u32 i; |
| 4666 | u16 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4667 | |
| 4668 | /* In order to read a register from the EEPROM, we need to shift 'count' |
| 4669 | * bits in from the EEPROM. Bits are "shifted in" by raising the clock |
| 4670 | * input to the EEPROM (setting the SK bit), and then reading the value of |
| 4671 | * the "DO" bit. During this "shifting in" process the "DI" bit should |
| 4672 | * always be clear. |
| 4673 | */ |
| 4674 | |
| 4675 | eecd = E1000_READ_REG(hw, EECD); |
| 4676 | |
| 4677 | eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); |
| 4678 | data = 0; |
| 4679 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4680 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4681 | data = data << 1; |
| 4682 | e1000_raise_ee_clk(hw, &eecd); |
| 4683 | |
| 4684 | eecd = E1000_READ_REG(hw, EECD); |
| 4685 | |
| 4686 | eecd &= ~(E1000_EECD_DI); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4687 | if (eecd & E1000_EECD_DO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4688 | data |= 1; |
| 4689 | |
| 4690 | e1000_lower_ee_clk(hw, &eecd); |
| 4691 | } |
| 4692 | |
| 4693 | return data; |
| 4694 | } |
| 4695 | |
| 4696 | /****************************************************************************** |
| 4697 | * Prepares EEPROM for access |
| 4698 | * |
| 4699 | * hw - Struct containing variables accessed by shared code |
| 4700 | * |
| 4701 | * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This |
| 4702 | * function should be called before issuing a command to the EEPROM. |
| 4703 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4704 | static s32 e1000_acquire_eeprom(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4705 | { |
| 4706 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4707 | u32 eecd, i=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | |
| 4709 | DEBUGFUNC("e1000_acquire_eeprom"); |
| 4710 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4711 | if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM)) |
| 4712 | return -E1000_ERR_SWFW_SYNC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4713 | eecd = E1000_READ_REG(hw, EECD); |
| 4714 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4715 | if (hw->mac_type != e1000_82573) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4716 | /* Request EEPROM Access */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4717 | if (hw->mac_type > e1000_82544) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4718 | eecd |= E1000_EECD_REQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | E1000_WRITE_REG(hw, EECD, eecd); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4720 | eecd = E1000_READ_REG(hw, EECD); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4721 | while ((!(eecd & E1000_EECD_GNT)) && |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4722 | (i < E1000_EEPROM_GRANT_ATTEMPTS)) { |
| 4723 | i++; |
| 4724 | udelay(5); |
| 4725 | eecd = E1000_READ_REG(hw, EECD); |
| 4726 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4727 | if (!(eecd & E1000_EECD_GNT)) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4728 | eecd &= ~E1000_EECD_REQ; |
| 4729 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4730 | DEBUGOUT("Could not acquire EEPROM grant\n"); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4731 | e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 4732 | return -E1000_ERR_EEPROM; |
| 4733 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4734 | } |
| 4735 | } |
| 4736 | |
| 4737 | /* Setup EEPROM for Read/Write */ |
| 4738 | |
| 4739 | if (eeprom->type == e1000_eeprom_microwire) { |
| 4740 | /* Clear SK and DI */ |
| 4741 | eecd &= ~(E1000_EECD_DI | E1000_EECD_SK); |
| 4742 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4743 | |
| 4744 | /* Set CS */ |
| 4745 | eecd |= E1000_EECD_CS; |
| 4746 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4747 | } else if (eeprom->type == e1000_eeprom_spi) { |
| 4748 | /* Clear SK and CS */ |
| 4749 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
| 4750 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4751 | udelay(1); |
| 4752 | } |
| 4753 | |
| 4754 | return E1000_SUCCESS; |
| 4755 | } |
| 4756 | |
| 4757 | /****************************************************************************** |
| 4758 | * Returns EEPROM to a "standby" state |
| 4759 | * |
| 4760 | * hw - Struct containing variables accessed by shared code |
| 4761 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4762 | static void e1000_standby_eeprom(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4763 | { |
| 4764 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4765 | u32 eecd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4766 | |
| 4767 | eecd = E1000_READ_REG(hw, EECD); |
| 4768 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4769 | if (eeprom->type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4770 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); |
| 4771 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4772 | E1000_WRITE_FLUSH(hw); |
| 4773 | udelay(eeprom->delay_usec); |
| 4774 | |
| 4775 | /* Clock high */ |
| 4776 | eecd |= E1000_EECD_SK; |
| 4777 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4778 | E1000_WRITE_FLUSH(hw); |
| 4779 | udelay(eeprom->delay_usec); |
| 4780 | |
| 4781 | /* Select EEPROM */ |
| 4782 | eecd |= E1000_EECD_CS; |
| 4783 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4784 | E1000_WRITE_FLUSH(hw); |
| 4785 | udelay(eeprom->delay_usec); |
| 4786 | |
| 4787 | /* Clock low */ |
| 4788 | eecd &= ~E1000_EECD_SK; |
| 4789 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4790 | E1000_WRITE_FLUSH(hw); |
| 4791 | udelay(eeprom->delay_usec); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4792 | } else if (eeprom->type == e1000_eeprom_spi) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4793 | /* Toggle CS to flush commands */ |
| 4794 | eecd |= E1000_EECD_CS; |
| 4795 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4796 | E1000_WRITE_FLUSH(hw); |
| 4797 | udelay(eeprom->delay_usec); |
| 4798 | eecd &= ~E1000_EECD_CS; |
| 4799 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4800 | E1000_WRITE_FLUSH(hw); |
| 4801 | udelay(eeprom->delay_usec); |
| 4802 | } |
| 4803 | } |
| 4804 | |
| 4805 | /****************************************************************************** |
| 4806 | * Terminates a command by inverting the EEPROM's chip select pin |
| 4807 | * |
| 4808 | * hw - Struct containing variables accessed by shared code |
| 4809 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4810 | static void e1000_release_eeprom(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4812 | u32 eecd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4813 | |
| 4814 | DEBUGFUNC("e1000_release_eeprom"); |
| 4815 | |
| 4816 | eecd = E1000_READ_REG(hw, EECD); |
| 4817 | |
| 4818 | if (hw->eeprom.type == e1000_eeprom_spi) { |
| 4819 | eecd |= E1000_EECD_CS; /* Pull CS high */ |
| 4820 | eecd &= ~E1000_EECD_SK; /* Lower SCK */ |
| 4821 | |
| 4822 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4823 | |
| 4824 | udelay(hw->eeprom.delay_usec); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4825 | } else if (hw->eeprom.type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4826 | /* cleanup eeprom */ |
| 4827 | |
| 4828 | /* CS on Microwire is active-high */ |
| 4829 | eecd &= ~(E1000_EECD_CS | E1000_EECD_DI); |
| 4830 | |
| 4831 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4832 | |
| 4833 | /* Rising edge of clock */ |
| 4834 | eecd |= E1000_EECD_SK; |
| 4835 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4836 | E1000_WRITE_FLUSH(hw); |
| 4837 | udelay(hw->eeprom.delay_usec); |
| 4838 | |
| 4839 | /* Falling edge of clock */ |
| 4840 | eecd &= ~E1000_EECD_SK; |
| 4841 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4842 | E1000_WRITE_FLUSH(hw); |
| 4843 | udelay(hw->eeprom.delay_usec); |
| 4844 | } |
| 4845 | |
| 4846 | /* Stop requesting EEPROM access */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4847 | if (hw->mac_type > e1000_82544) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4848 | eecd &= ~E1000_EECD_REQ; |
| 4849 | E1000_WRITE_REG(hw, EECD, eecd); |
| 4850 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4851 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 4852 | e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4853 | } |
| 4854 | |
| 4855 | /****************************************************************************** |
| 4856 | * Reads a 16 bit word from the EEPROM. |
| 4857 | * |
| 4858 | * hw - Struct containing variables accessed by shared code |
| 4859 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4860 | static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4861 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4862 | u16 retry_count = 0; |
| 4863 | u8 spi_stat_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4864 | |
| 4865 | DEBUGFUNC("e1000_spi_eeprom_ready"); |
| 4866 | |
| 4867 | /* Read "Status Register" repeatedly until the LSB is cleared. The |
| 4868 | * EEPROM will signal that the command has been completed by clearing |
| 4869 | * bit 0 of the internal status register. If it's not cleared within |
| 4870 | * 5 milliseconds, then error out. |
| 4871 | */ |
| 4872 | retry_count = 0; |
| 4873 | do { |
| 4874 | e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI, |
| 4875 | hw->eeprom.opcode_bits); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4876 | spi_stat_reg = (u8)e1000_shift_in_ee_bits(hw, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4877 | if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI)) |
| 4878 | break; |
| 4879 | |
| 4880 | udelay(5); |
| 4881 | retry_count += 5; |
| 4882 | |
| 4883 | e1000_standby_eeprom(hw); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4884 | } while (retry_count < EEPROM_MAX_RETRY_SPI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4885 | |
| 4886 | /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and |
| 4887 | * only 0-5mSec on 5V devices) |
| 4888 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4889 | if (retry_count >= EEPROM_MAX_RETRY_SPI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4890 | DEBUGOUT("SPI EEPROM Status error\n"); |
| 4891 | return -E1000_ERR_EEPROM; |
| 4892 | } |
| 4893 | |
| 4894 | return E1000_SUCCESS; |
| 4895 | } |
| 4896 | |
| 4897 | /****************************************************************************** |
| 4898 | * Reads a 16 bit word from the EEPROM. |
| 4899 | * |
| 4900 | * hw - Struct containing variables accessed by shared code |
| 4901 | * offset - offset of word in the EEPROM to read |
| 4902 | * data - word read from the EEPROM |
| 4903 | * words - number of words to read |
| 4904 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 4905 | s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4906 | { |
| 4907 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4908 | u32 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4909 | |
| 4910 | DEBUGFUNC("e1000_read_eeprom"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4911 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4912 | /* If eeprom is not yet detected, do so now */ |
| 4913 | if (eeprom->word_size == 0) |
| 4914 | e1000_init_eeprom_params(hw); |
| 4915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | /* A check for invalid values: offset too large, too many words, and not |
| 4917 | * enough words. |
| 4918 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4919 | if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | (words == 0)) { |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4921 | 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] | 4922 | return -E1000_ERR_EEPROM; |
| 4923 | } |
| 4924 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4925 | /* EEPROM's that don't use EERD to read require us to bit-bang the SPI |
| 4926 | * directly. In this case, we need to acquire the EEPROM so that |
| 4927 | * FW or other port software does not interrupt. |
| 4928 | */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4929 | if (e1000_is_onboard_nvm_eeprom(hw) && !hw->eeprom.use_eerd) { |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4930 | /* Prepare the EEPROM for bit-bang reading */ |
| 4931 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) |
| 4932 | return -E1000_ERR_EEPROM; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4933 | } |
| 4934 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4935 | /* Eerd register EEPROM access requires no eeprom aquire/release */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4936 | if (eeprom->use_eerd) |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4937 | return e1000_read_eeprom_eerd(hw, offset, words, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4938 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4939 | /* ICH EEPROM access is done via the ICH flash controller */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4940 | if (eeprom->type == e1000_eeprom_ich8) |
| 4941 | return e1000_read_eeprom_ich8(hw, offset, words, data); |
| 4942 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 4943 | /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have |
| 4944 | * acquired the EEPROM at this point, so any returns should relase it */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4945 | if (eeprom->type == e1000_eeprom_spi) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4946 | u16 word_in; |
| 4947 | u8 read_opcode = EEPROM_READ_OPCODE_SPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4948 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4949 | if (e1000_spi_eeprom_ready(hw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4950 | e1000_release_eeprom(hw); |
| 4951 | return -E1000_ERR_EEPROM; |
| 4952 | } |
| 4953 | |
| 4954 | e1000_standby_eeprom(hw); |
| 4955 | |
| 4956 | /* Some SPI eeproms use the 8th address bit embedded in the opcode */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4957 | if ((eeprom->address_bits == 8) && (offset >= 128)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4958 | read_opcode |= EEPROM_A8_OPCODE_SPI; |
| 4959 | |
| 4960 | /* Send the READ command (opcode + addr) */ |
| 4961 | e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4962 | e1000_shift_out_ee_bits(hw, (u16)(offset*2), eeprom->address_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4963 | |
| 4964 | /* Read the data. The address of the eeprom internally increments with |
| 4965 | * each byte (spi) being read, saving on the overhead of eeprom setup |
| 4966 | * and tear-down. The address counter will roll over if reading beyond |
| 4967 | * the size of the eeprom, thus allowing the entire memory to be read |
| 4968 | * starting from any offset. */ |
| 4969 | for (i = 0; i < words; i++) { |
| 4970 | word_in = e1000_shift_in_ee_bits(hw, 16); |
| 4971 | data[i] = (word_in >> 8) | (word_in << 8); |
| 4972 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4973 | } else if (eeprom->type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4974 | for (i = 0; i < words; i++) { |
| 4975 | /* Send the READ command (opcode + addr) */ |
| 4976 | e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE, |
| 4977 | eeprom->opcode_bits); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4978 | e1000_shift_out_ee_bits(hw, (u16)(offset + i), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4979 | eeprom->address_bits); |
| 4980 | |
| 4981 | /* Read the data. For microwire, each word requires the overhead |
| 4982 | * of eeprom setup and tear-down. */ |
| 4983 | data[i] = e1000_shift_in_ee_bits(hw, 16); |
| 4984 | e1000_standby_eeprom(hw); |
| 4985 | } |
| 4986 | } |
| 4987 | |
| 4988 | /* End this read operation */ |
| 4989 | e1000_release_eeprom(hw); |
| 4990 | |
| 4991 | return E1000_SUCCESS; |
| 4992 | } |
| 4993 | |
| 4994 | /****************************************************************************** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4995 | * Reads a 16 bit word from the EEPROM using the EERD register. |
| 4996 | * |
| 4997 | * hw - Struct containing variables accessed by shared code |
| 4998 | * offset - offset of word in the EEPROM to read |
| 4999 | * data - word read from the EEPROM |
| 5000 | * words - number of words to read |
| 5001 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5002 | static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words, |
| 5003 | u16 *data) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5004 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5005 | u32 i, eerd = 0; |
| 5006 | s32 error = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5007 | |
| 5008 | for (i = 0; i < words; i++) { |
| 5009 | eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) + |
| 5010 | E1000_EEPROM_RW_REG_START; |
| 5011 | |
| 5012 | E1000_WRITE_REG(hw, EERD, eerd); |
| 5013 | error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5014 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5015 | if (error) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5016 | break; |
| 5017 | } |
| 5018 | data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5019 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5020 | } |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5021 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5022 | return error; |
| 5023 | } |
| 5024 | |
| 5025 | /****************************************************************************** |
| 5026 | * Writes a 16 bit word from the EEPROM using the EEWR register. |
| 5027 | * |
| 5028 | * hw - Struct containing variables accessed by shared code |
| 5029 | * offset - offset of word in the EEPROM to read |
| 5030 | * data - word read from the EEPROM |
| 5031 | * words - number of words to read |
| 5032 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5033 | static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words, |
| 5034 | u16 *data) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5035 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5036 | u32 register_value = 0; |
| 5037 | u32 i = 0; |
| 5038 | s32 error = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5039 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 5040 | if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM)) |
| 5041 | return -E1000_ERR_SWFW_SYNC; |
| 5042 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5043 | for (i = 0; i < words; i++) { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5044 | register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) | |
| 5045 | ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5046 | E1000_EEPROM_RW_REG_START; |
| 5047 | |
| 5048 | error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5049 | if (error) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5050 | break; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5051 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5052 | |
| 5053 | E1000_WRITE_REG(hw, EEWR, register_value); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5054 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5055 | error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5056 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5057 | if (error) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5058 | break; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5059 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5060 | } |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5061 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 5062 | e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5063 | return error; |
| 5064 | } |
| 5065 | |
| 5066 | /****************************************************************************** |
| 5067 | * Polls the status bit (bit 1) of the EERD to determine when the read is done. |
| 5068 | * |
| 5069 | * hw - Struct containing variables accessed by shared code |
| 5070 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5071 | static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5072 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5073 | u32 attempts = 100000; |
| 5074 | u32 i, reg = 0; |
| 5075 | s32 done = E1000_ERR_EEPROM; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5076 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5077 | for (i = 0; i < attempts; i++) { |
| 5078 | if (eerd == E1000_EEPROM_POLL_READ) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5079 | reg = E1000_READ_REG(hw, EERD); |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 5080 | else |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5081 | reg = E1000_READ_REG(hw, EEWR); |
| 5082 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5083 | if (reg & E1000_EEPROM_RW_REG_DONE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5084 | done = E1000_SUCCESS; |
| 5085 | break; |
| 5086 | } |
| 5087 | udelay(5); |
| 5088 | } |
| 5089 | |
| 5090 | return done; |
| 5091 | } |
| 5092 | |
| 5093 | /*************************************************************************** |
| 5094 | * Description: Determines if the onboard NVM is FLASH or EEPROM. |
| 5095 | * |
| 5096 | * hw - Struct containing variables accessed by shared code |
| 5097 | ****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5098 | static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5099 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5100 | u32 eecd = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5101 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 5102 | DEBUGFUNC("e1000_is_onboard_nvm_eeprom"); |
| 5103 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5104 | if (hw->mac_type == e1000_ich8lan) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5105 | return false; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5106 | |
| 5107 | if (hw->mac_type == e1000_82573) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5108 | eecd = E1000_READ_REG(hw, EECD); |
| 5109 | |
| 5110 | /* Isolate bits 15 & 16 */ |
| 5111 | eecd = ((eecd >> 15) & 0x03); |
| 5112 | |
| 5113 | /* If both bits are set, device is Flash type */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5114 | if (eecd == 0x03) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5115 | return false; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5116 | } |
| 5117 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5118 | return true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5119 | } |
| 5120 | |
| 5121 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5122 | * Verifies that the EEPROM has a valid checksum |
| 5123 | * |
| 5124 | * hw - Struct containing variables accessed by shared code |
| 5125 | * |
| 5126 | * Reads the first 64 16 bit words of the EEPROM and sums the values read. |
| 5127 | * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is |
| 5128 | * valid. |
| 5129 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5130 | s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5131 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5132 | u16 checksum = 0; |
| 5133 | u16 i, eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5134 | |
| 5135 | DEBUGFUNC("e1000_validate_eeprom_checksum"); |
| 5136 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5137 | if ((hw->mac_type == e1000_82573) && !e1000_is_onboard_nvm_eeprom(hw)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5138 | /* Check bit 4 of word 10h. If it is 0, firmware is done updating |
| 5139 | * 10h-12h. Checksum may need to be fixed. */ |
| 5140 | e1000_read_eeprom(hw, 0x10, 1, &eeprom_data); |
| 5141 | if ((eeprom_data & 0x10) == 0) { |
| 5142 | /* Read 0x23 and check bit 15. This bit is a 1 when the checksum |
| 5143 | * has already been fixed. If the checksum is still wrong and this |
| 5144 | * bit is a 1, we need to return bad checksum. Otherwise, we need |
| 5145 | * to set this bit to a 1 and update the checksum. */ |
| 5146 | e1000_read_eeprom(hw, 0x23, 1, &eeprom_data); |
| 5147 | if ((eeprom_data & 0x8000) == 0) { |
| 5148 | eeprom_data |= 0x8000; |
| 5149 | e1000_write_eeprom(hw, 0x23, 1, &eeprom_data); |
| 5150 | e1000_update_eeprom_checksum(hw); |
| 5151 | } |
| 5152 | } |
| 5153 | } |
| 5154 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5155 | if (hw->mac_type == e1000_ich8lan) { |
| 5156 | /* Drivers must allocate the shadow ram structure for the |
| 5157 | * EEPROM checksum to be updated. Otherwise, this bit as well |
| 5158 | * as the checksum must both be set correctly for this |
| 5159 | * validation to pass. |
| 5160 | */ |
| 5161 | e1000_read_eeprom(hw, 0x19, 1, &eeprom_data); |
| 5162 | if ((eeprom_data & 0x40) == 0) { |
| 5163 | eeprom_data |= 0x40; |
| 5164 | e1000_write_eeprom(hw, 0x19, 1, &eeprom_data); |
| 5165 | e1000_update_eeprom_checksum(hw); |
| 5166 | } |
| 5167 | } |
| 5168 | |
| 5169 | for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) { |
| 5170 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5171 | DEBUGOUT("EEPROM Read Error\n"); |
| 5172 | return -E1000_ERR_EEPROM; |
| 5173 | } |
| 5174 | checksum += eeprom_data; |
| 5175 | } |
| 5176 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5177 | if (checksum == (u16) EEPROM_SUM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5178 | return E1000_SUCCESS; |
| 5179 | else { |
| 5180 | DEBUGOUT("EEPROM Checksum Invalid\n"); |
| 5181 | return -E1000_ERR_EEPROM; |
| 5182 | } |
| 5183 | } |
| 5184 | |
| 5185 | /****************************************************************************** |
| 5186 | * Calculates the EEPROM checksum and writes it to the EEPROM |
| 5187 | * |
| 5188 | * hw - Struct containing variables accessed by shared code |
| 5189 | * |
| 5190 | * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA. |
| 5191 | * Writes the difference to word offset 63 of the EEPROM. |
| 5192 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5193 | s32 e1000_update_eeprom_checksum(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5194 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5195 | u32 ctrl_ext; |
| 5196 | u16 checksum = 0; |
| 5197 | u16 i, eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5198 | |
| 5199 | DEBUGFUNC("e1000_update_eeprom_checksum"); |
| 5200 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5201 | for (i = 0; i < EEPROM_CHECKSUM_REG; i++) { |
| 5202 | if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5203 | DEBUGOUT("EEPROM Read Error\n"); |
| 5204 | return -E1000_ERR_EEPROM; |
| 5205 | } |
| 5206 | checksum += eeprom_data; |
| 5207 | } |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5208 | checksum = (u16) EEPROM_SUM - checksum; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5209 | if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5210 | DEBUGOUT("EEPROM Write Error\n"); |
| 5211 | return -E1000_ERR_EEPROM; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5212 | } else if (hw->eeprom.type == e1000_eeprom_flash) { |
| 5213 | e1000_commit_shadow_ram(hw); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5214 | } else if (hw->eeprom.type == e1000_eeprom_ich8) { |
| 5215 | e1000_commit_shadow_ram(hw); |
| 5216 | /* Reload the EEPROM, or else modifications will not appear |
| 5217 | * until after next adapter reset. */ |
| 5218 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 5219 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; |
| 5220 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5221 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5222 | } |
| 5223 | return E1000_SUCCESS; |
| 5224 | } |
| 5225 | |
| 5226 | /****************************************************************************** |
| 5227 | * Parent function for writing words to the different EEPROM types. |
| 5228 | * |
| 5229 | * hw - Struct containing variables accessed by shared code |
| 5230 | * offset - offset within the EEPROM to be written to |
| 5231 | * words - number of words to write |
| 5232 | * data - 16 bit word to be written to the EEPROM |
| 5233 | * |
| 5234 | * If e1000_update_eeprom_checksum is not called after this function, the |
| 5235 | * EEPROM will most likely contain an invalid checksum. |
| 5236 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5237 | s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5238 | { |
| 5239 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5240 | s32 status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5241 | |
| 5242 | DEBUGFUNC("e1000_write_eeprom"); |
| 5243 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5244 | /* If eeprom is not yet detected, do so now */ |
| 5245 | if (eeprom->word_size == 0) |
| 5246 | e1000_init_eeprom_params(hw); |
| 5247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5248 | /* A check for invalid values: offset too large, too many words, and not |
| 5249 | * enough words. |
| 5250 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5251 | if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5252 | (words == 0)) { |
| 5253 | DEBUGOUT("\"words\" parameter out of bounds\n"); |
| 5254 | return -E1000_ERR_EEPROM; |
| 5255 | } |
| 5256 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 5257 | /* 82573 writes only through eewr */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5258 | if (eeprom->use_eewr) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5259 | return e1000_write_eeprom_eewr(hw, offset, words, data); |
| 5260 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5261 | if (eeprom->type == e1000_eeprom_ich8) |
| 5262 | return e1000_write_eeprom_ich8(hw, offset, words, data); |
| 5263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5264 | /* Prepare the EEPROM for writing */ |
| 5265 | if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) |
| 5266 | return -E1000_ERR_EEPROM; |
| 5267 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5268 | if (eeprom->type == e1000_eeprom_microwire) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5269 | status = e1000_write_eeprom_microwire(hw, offset, words, data); |
| 5270 | } else { |
| 5271 | status = e1000_write_eeprom_spi(hw, offset, words, data); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 5272 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | /* Done with writing */ |
| 5276 | e1000_release_eeprom(hw); |
| 5277 | |
| 5278 | return status; |
| 5279 | } |
| 5280 | |
| 5281 | /****************************************************************************** |
| 5282 | * Writes a 16 bit word to a given offset in an SPI EEPROM. |
| 5283 | * |
| 5284 | * hw - Struct containing variables accessed by shared code |
| 5285 | * offset - offset within the EEPROM to be written to |
| 5286 | * words - number of words to write |
| 5287 | * data - pointer to array of 8 bit words to be written to the EEPROM |
| 5288 | * |
| 5289 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5290 | static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words, |
| 5291 | u16 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5292 | { |
| 5293 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5294 | u16 widx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5295 | |
| 5296 | DEBUGFUNC("e1000_write_eeprom_spi"); |
| 5297 | |
| 5298 | while (widx < words) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5299 | u8 write_opcode = EEPROM_WRITE_OPCODE_SPI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5300 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5301 | if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5302 | |
| 5303 | e1000_standby_eeprom(hw); |
| 5304 | |
| 5305 | /* Send the WRITE ENABLE command (8 bit opcode ) */ |
| 5306 | e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI, |
| 5307 | eeprom->opcode_bits); |
| 5308 | |
| 5309 | e1000_standby_eeprom(hw); |
| 5310 | |
| 5311 | /* Some SPI eeproms use the 8th address bit embedded in the opcode */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5312 | if ((eeprom->address_bits == 8) && (offset >= 128)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5313 | write_opcode |= EEPROM_A8_OPCODE_SPI; |
| 5314 | |
| 5315 | /* Send the Write command (8-bit opcode + addr) */ |
| 5316 | e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits); |
| 5317 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5318 | e1000_shift_out_ee_bits(hw, (u16)((offset + widx)*2), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5319 | eeprom->address_bits); |
| 5320 | |
| 5321 | /* Send the data */ |
| 5322 | |
| 5323 | /* Loop to allow for up to whole page write (32 bytes) of eeprom */ |
| 5324 | while (widx < words) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5325 | u16 word_out = data[widx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5326 | word_out = (word_out >> 8) | (word_out << 8); |
| 5327 | e1000_shift_out_ee_bits(hw, word_out, 16); |
| 5328 | widx++; |
| 5329 | |
| 5330 | /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE |
| 5331 | * operation, while the smaller eeproms are capable of an 8-byte |
| 5332 | * PAGE WRITE operation. Break the inner loop to pass new address |
| 5333 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5334 | if ((((offset + widx)*2) % eeprom->page_size) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5335 | e1000_standby_eeprom(hw); |
| 5336 | break; |
| 5337 | } |
| 5338 | } |
| 5339 | } |
| 5340 | |
| 5341 | return E1000_SUCCESS; |
| 5342 | } |
| 5343 | |
| 5344 | /****************************************************************************** |
| 5345 | * Writes a 16 bit word to a given offset in a Microwire EEPROM. |
| 5346 | * |
| 5347 | * hw - Struct containing variables accessed by shared code |
| 5348 | * offset - offset within the EEPROM to be written to |
| 5349 | * words - number of words to write |
| 5350 | * data - pointer to array of 16 bit words to be written to the EEPROM |
| 5351 | * |
| 5352 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5353 | static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset, |
| 5354 | u16 words, u16 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5355 | { |
| 5356 | struct e1000_eeprom_info *eeprom = &hw->eeprom; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5357 | u32 eecd; |
| 5358 | u16 words_written = 0; |
| 5359 | u16 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5360 | |
| 5361 | DEBUGFUNC("e1000_write_eeprom_microwire"); |
| 5362 | |
| 5363 | /* Send the write enable command to the EEPROM (3-bit opcode plus |
| 5364 | * 6/8-bit dummy address beginning with 11). It's less work to include |
| 5365 | * the 11 of the dummy address as part of the opcode than it is to shift |
| 5366 | * it over the correct number of bits for the address. This puts the |
| 5367 | * EEPROM into write/erase mode. |
| 5368 | */ |
| 5369 | e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5370 | (u16)(eeprom->opcode_bits + 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5371 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5372 | e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5373 | |
| 5374 | /* Prepare the EEPROM */ |
| 5375 | e1000_standby_eeprom(hw); |
| 5376 | |
| 5377 | while (words_written < words) { |
| 5378 | /* Send the Write command (3-bit opcode + addr) */ |
| 5379 | e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE, |
| 5380 | eeprom->opcode_bits); |
| 5381 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5382 | e1000_shift_out_ee_bits(hw, (u16)(offset + words_written), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5383 | eeprom->address_bits); |
| 5384 | |
| 5385 | /* Send the data */ |
| 5386 | e1000_shift_out_ee_bits(hw, data[words_written], 16); |
| 5387 | |
| 5388 | /* Toggle the CS line. This in effect tells the EEPROM to execute |
| 5389 | * the previous command. |
| 5390 | */ |
| 5391 | e1000_standby_eeprom(hw); |
| 5392 | |
| 5393 | /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will |
| 5394 | * signal that the command has been completed by raising the DO signal. |
| 5395 | * If DO does not go high in 10 milliseconds, then error out. |
| 5396 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5397 | for (i = 0; i < 200; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5398 | eecd = E1000_READ_REG(hw, EECD); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5399 | if (eecd & E1000_EECD_DO) break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5400 | udelay(50); |
| 5401 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5402 | if (i == 200) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5403 | DEBUGOUT("EEPROM Write did not complete\n"); |
| 5404 | return -E1000_ERR_EEPROM; |
| 5405 | } |
| 5406 | |
| 5407 | /* Recover from write */ |
| 5408 | e1000_standby_eeprom(hw); |
| 5409 | |
| 5410 | words_written++; |
| 5411 | } |
| 5412 | |
| 5413 | /* Send the write disable command to the EEPROM (3-bit opcode plus |
| 5414 | * 6/8-bit dummy address beginning with 10). It's less work to include |
| 5415 | * the 10 of the dummy address as part of the opcode than it is to shift |
| 5416 | * it over the correct number of bits for the address. This takes the |
| 5417 | * EEPROM out of write/erase mode. |
| 5418 | */ |
| 5419 | e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5420 | (u16)(eeprom->opcode_bits + 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5421 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5422 | e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5423 | |
| 5424 | return E1000_SUCCESS; |
| 5425 | } |
| 5426 | |
| 5427 | /****************************************************************************** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5428 | * Flushes the cached eeprom to NVM. This is done by saving the modified values |
| 5429 | * in the eeprom cache and the non modified values in the currently active bank |
| 5430 | * to the new bank. |
| 5431 | * |
| 5432 | * hw - Struct containing variables accessed by shared code |
| 5433 | * offset - offset of word in the EEPROM to read |
| 5434 | * data - word read from the EEPROM |
| 5435 | * words - number of words to read |
| 5436 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5437 | static s32 e1000_commit_shadow_ram(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5438 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5439 | u32 attempts = 100000; |
| 5440 | u32 eecd = 0; |
| 5441 | u32 flop = 0; |
| 5442 | u32 i = 0; |
| 5443 | s32 error = E1000_SUCCESS; |
| 5444 | u32 old_bank_offset = 0; |
| 5445 | u32 new_bank_offset = 0; |
| 5446 | u8 low_byte = 0; |
| 5447 | u8 high_byte = 0; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5448 | bool sector_write_failed = false; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5449 | |
| 5450 | if (hw->mac_type == e1000_82573) { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5451 | /* The flop register will be used to determine if flash type is STM */ |
| 5452 | flop = E1000_READ_REG(hw, FLOP); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5453 | for (i=0; i < attempts; i++) { |
| 5454 | eecd = E1000_READ_REG(hw, EECD); |
| 5455 | if ((eecd & E1000_EECD_FLUPD) == 0) { |
| 5456 | break; |
| 5457 | } |
| 5458 | udelay(5); |
| 5459 | } |
| 5460 | |
| 5461 | if (i == attempts) { |
| 5462 | return -E1000_ERR_EEPROM; |
| 5463 | } |
| 5464 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5465 | /* If STM opcode located in bits 15:8 of flop, reset firmware */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5466 | if ((flop & 0xFF00) == E1000_STM_OPCODE) { |
| 5467 | E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET); |
| 5468 | } |
| 5469 | |
| 5470 | /* Perform the flash update */ |
| 5471 | E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD); |
| 5472 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5473 | for (i=0; i < attempts; i++) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5474 | eecd = E1000_READ_REG(hw, EECD); |
| 5475 | if ((eecd & E1000_EECD_FLUPD) == 0) { |
| 5476 | break; |
| 5477 | } |
| 5478 | udelay(5); |
| 5479 | } |
| 5480 | |
| 5481 | if (i == attempts) { |
| 5482 | return -E1000_ERR_EEPROM; |
| 5483 | } |
| 5484 | } |
| 5485 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5486 | if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) { |
| 5487 | /* We're writing to the opposite bank so if we're on bank 1, |
| 5488 | * write to bank 0 etc. We also need to erase the segment that |
| 5489 | * is going to be written */ |
| 5490 | if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) { |
| 5491 | new_bank_offset = hw->flash_bank_size * 2; |
| 5492 | old_bank_offset = 0; |
| 5493 | e1000_erase_ich8_4k_segment(hw, 1); |
| 5494 | } else { |
| 5495 | old_bank_offset = hw->flash_bank_size * 2; |
| 5496 | new_bank_offset = 0; |
| 5497 | e1000_erase_ich8_4k_segment(hw, 0); |
| 5498 | } |
| 5499 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5500 | sector_write_failed = false; |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5501 | /* Loop for every byte in the shadow RAM, |
| 5502 | * which is in units of words. */ |
| 5503 | for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) { |
| 5504 | /* Determine whether to write the value stored |
| 5505 | * in the other NVM bank or a modified value stored |
| 5506 | * in the shadow RAM */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5507 | if (hw->eeprom_shadow_ram[i].modified) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5508 | low_byte = (u8)hw->eeprom_shadow_ram[i].eeprom_word; |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5509 | udelay(100); |
| 5510 | error = e1000_verify_write_ich8_byte(hw, |
| 5511 | (i << 1) + new_bank_offset, low_byte); |
| 5512 | |
| 5513 | if (error != E1000_SUCCESS) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5514 | sector_write_failed = true; |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5515 | else { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5516 | high_byte = |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5517 | (u8)(hw->eeprom_shadow_ram[i].eeprom_word >> 8); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5518 | udelay(100); |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5519 | } |
| 5520 | } else { |
| 5521 | e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset, |
| 5522 | &low_byte); |
| 5523 | udelay(100); |
| 5524 | error = e1000_verify_write_ich8_byte(hw, |
| 5525 | (i << 1) + new_bank_offset, low_byte); |
| 5526 | |
| 5527 | if (error != E1000_SUCCESS) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5528 | sector_write_failed = true; |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5529 | else { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5530 | e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1, |
| 5531 | &high_byte); |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5532 | udelay(100); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5533 | } |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5534 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5535 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5536 | /* If the write of the low byte was successful, go ahead and |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5537 | * write the high byte while checking to make sure that if it |
| 5538 | * is the signature byte, then it is handled properly */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5539 | if (!sector_write_failed) { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5540 | /* If the word is 0x13, then make sure the signature bits |
| 5541 | * (15:14) are 11b until the commit has completed. |
| 5542 | * This will allow us to write 10b which indicates the |
| 5543 | * signature is valid. We want to do this after the write |
| 5544 | * has completed so that we don't mark the segment valid |
| 5545 | * while the write is still in progress */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 5546 | if (i == E1000_ICH_NVM_SIG_WORD) |
| 5547 | high_byte = E1000_ICH_NVM_SIG_MASK | high_byte; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5548 | |
| 5549 | error = e1000_verify_write_ich8_byte(hw, |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5550 | (i << 1) + new_bank_offset + 1, high_byte); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5551 | if (error != E1000_SUCCESS) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5552 | sector_write_failed = true; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5553 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5554 | } else { |
| 5555 | /* If the write failed then break from the loop and |
| 5556 | * return an error */ |
| 5557 | break; |
| 5558 | } |
| 5559 | } |
| 5560 | |
| 5561 | /* Don't bother writing the segment valid bits if sector |
| 5562 | * programming failed. */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5563 | if (!sector_write_failed) { |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5564 | /* Finally validate the new segment by setting bit 15:14 |
| 5565 | * to 10b in word 0x13 , this can be done without an |
| 5566 | * erase as well since these bits are 11 to start with |
| 5567 | * and we need to change bit 14 to 0b */ |
| 5568 | e1000_read_ich8_byte(hw, |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 5569 | E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset, |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5570 | &high_byte); |
| 5571 | high_byte &= 0xBF; |
| 5572 | error = e1000_verify_write_ich8_byte(hw, |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 5573 | E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset, high_byte); |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5574 | /* And invalidate the previously valid segment by setting |
| 5575 | * its signature word (0x13) high_byte to 0b. This can be |
| 5576 | * done without an erase because flash erase sets all bits |
| 5577 | * to 1's. We can write 1's to 0's without an erase */ |
| 5578 | if (error == E1000_SUCCESS) { |
| 5579 | error = e1000_verify_write_ich8_byte(hw, |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 5580 | E1000_ICH_NVM_SIG_WORD * 2 + 1 + old_bank_offset, 0); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5581 | } |
| 5582 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5583 | /* Clear the now not used entry in the cache */ |
| 5584 | for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5585 | hw->eeprom_shadow_ram[i].modified = false; |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5586 | hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5587 | } |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 5588 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5589 | } |
| 5590 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5591 | return error; |
| 5592 | } |
| 5593 | |
| 5594 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5595 | * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the |
| 5596 | * second function of dual function devices |
| 5597 | * |
| 5598 | * hw - Struct containing variables accessed by shared code |
| 5599 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5600 | s32 e1000_read_mac_addr(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5601 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5602 | u16 offset; |
| 5603 | u16 eeprom_data, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5604 | |
| 5605 | DEBUGFUNC("e1000_read_mac_addr"); |
| 5606 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5607 | for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5608 | offset = i >> 1; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5609 | if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5610 | DEBUGOUT("EEPROM Read Error\n"); |
| 5611 | return -E1000_ERR_EEPROM; |
| 5612 | } |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5613 | hw->perm_mac_addr[i] = (u8) (eeprom_data & 0x00FF); |
| 5614 | hw->perm_mac_addr[i+1] = (u8) (eeprom_data >> 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5615 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5616 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 5617 | switch (hw->mac_type) { |
| 5618 | default: |
| 5619 | break; |
| 5620 | case e1000_82546: |
| 5621 | case e1000_82546_rev_3: |
| 5622 | case e1000_82571: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 5623 | case e1000_80003es2lan: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5624 | if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5625 | hw->perm_mac_addr[5] ^= 0x01; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 5626 | break; |
| 5627 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5628 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5629 | for (i = 0; i < NODE_ADDRESS_SIZE; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5630 | hw->mac_addr[i] = hw->perm_mac_addr[i]; |
| 5631 | return E1000_SUCCESS; |
| 5632 | } |
| 5633 | |
| 5634 | /****************************************************************************** |
| 5635 | * Initializes receive address filters. |
| 5636 | * |
| 5637 | * hw - Struct containing variables accessed by shared code |
| 5638 | * |
| 5639 | * Places the MAC address in receive address register 0 and clears the rest |
| 5640 | * of the receive addresss registers. Clears the multicast table. Assumes |
| 5641 | * the receiver is in reset when the routine is called. |
| 5642 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5643 | static void e1000_init_rx_addrs(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5644 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5645 | u32 i; |
| 5646 | u32 rar_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5647 | |
| 5648 | DEBUGFUNC("e1000_init_rx_addrs"); |
| 5649 | |
| 5650 | /* Setup the receive address. */ |
| 5651 | DEBUGOUT("Programming MAC Address into RAR[0]\n"); |
| 5652 | |
| 5653 | e1000_rar_set(hw, hw->mac_addr, 0); |
| 5654 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5655 | rar_num = E1000_RAR_ENTRIES; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 5656 | |
| 5657 | /* Reserve a spot for the Locally Administered Address to work around |
| 5658 | * an 82571 issue in which a reset on one port will reload the MAC on |
| 5659 | * the other port. */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5660 | if ((hw->mac_type == e1000_82571) && (hw->laa_is_present)) |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 5661 | rar_num -= 1; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5662 | if (hw->mac_type == e1000_ich8lan) |
| 5663 | rar_num = E1000_RAR_ENTRIES_ICH8LAN; |
| 5664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5665 | /* Zero out the other 15 receive addresses. */ |
| 5666 | DEBUGOUT("Clearing RAR[1-15]\n"); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5667 | for (i = 1; i < rar_num; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5668 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5669 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5670 | E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5671 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5672 | } |
| 5673 | } |
| 5674 | |
| 5675 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5676 | * Hashes an address to determine its location in the multicast table |
| 5677 | * |
| 5678 | * hw - Struct containing variables accessed by shared code |
| 5679 | * mc_addr - the multicast address to hash |
| 5680 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5681 | u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5682 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5683 | u32 hash_value = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5684 | |
| 5685 | /* The portion of the address that is used for the hash table is |
| 5686 | * determined by the mc_filter_type setting. |
| 5687 | */ |
| 5688 | switch (hw->mc_filter_type) { |
| 5689 | /* [0] [1] [2] [3] [4] [5] |
| 5690 | * 01 AA 00 12 34 56 |
| 5691 | * LSB MSB |
| 5692 | */ |
| 5693 | case 0: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5694 | if (hw->mac_type == e1000_ich8lan) { |
| 5695 | /* [47:38] i.e. 0x158 for above example address */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5696 | hash_value = ((mc_addr[4] >> 6) | (((u16) mc_addr[5]) << 2)); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5697 | } else { |
| 5698 | /* [47:36] i.e. 0x563 for above example address */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5699 | hash_value = ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4)); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5700 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5701 | break; |
| 5702 | case 1: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5703 | if (hw->mac_type == e1000_ich8lan) { |
| 5704 | /* [46:37] i.e. 0x2B1 for above example address */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5705 | hash_value = ((mc_addr[4] >> 5) | (((u16) mc_addr[5]) << 3)); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5706 | } else { |
| 5707 | /* [46:35] i.e. 0xAC6 for above example address */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5708 | hash_value = ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5)); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5709 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5710 | break; |
| 5711 | case 2: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5712 | if (hw->mac_type == e1000_ich8lan) { |
| 5713 | /*[45:36] i.e. 0x163 for above example address */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5714 | hash_value = ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4)); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5715 | } else { |
| 5716 | /* [45:34] i.e. 0x5D8 for above example address */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5717 | hash_value = ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6)); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5718 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5719 | break; |
| 5720 | case 3: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5721 | if (hw->mac_type == e1000_ich8lan) { |
| 5722 | /* [43:34] i.e. 0x18D for above example address */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5723 | hash_value = ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6)); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5724 | } else { |
| 5725 | /* [43:32] i.e. 0x634 for above example address */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5726 | hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8)); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5727 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5728 | break; |
| 5729 | } |
| 5730 | |
| 5731 | hash_value &= 0xFFF; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5732 | if (hw->mac_type == e1000_ich8lan) |
| 5733 | hash_value &= 0x3FF; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5734 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 | return hash_value; |
| 5736 | } |
| 5737 | |
| 5738 | /****************************************************************************** |
| 5739 | * Sets the bit in the multicast table corresponding to the hash value. |
| 5740 | * |
| 5741 | * hw - Struct containing variables accessed by shared code |
| 5742 | * hash_value - Multicast address hash value |
| 5743 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5744 | void e1000_mta_set(struct e1000_hw *hw, u32 hash_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5745 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5746 | u32 hash_bit, hash_reg; |
| 5747 | u32 mta; |
| 5748 | u32 temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5749 | |
| 5750 | /* The MTA is a register array of 128 32-bit registers. |
| 5751 | * It is treated like an array of 4096 bits. We want to set |
| 5752 | * bit BitArray[hash_value]. So we figure out what register |
| 5753 | * the bit is in, read it, OR in the new bit, then write |
| 5754 | * back the new value. The register is determined by the |
| 5755 | * upper 7 bits of the hash value and the bit within that |
| 5756 | * register are determined by the lower 5 bits of the value. |
| 5757 | */ |
| 5758 | hash_reg = (hash_value >> 5) & 0x7F; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5759 | if (hw->mac_type == e1000_ich8lan) |
| 5760 | hash_reg &= 0x1F; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 5761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5762 | hash_bit = hash_value & 0x1F; |
| 5763 | |
| 5764 | mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg); |
| 5765 | |
| 5766 | mta |= (1 << hash_bit); |
| 5767 | |
| 5768 | /* If we are on an 82544 and we are trying to write an odd offset |
| 5769 | * in the MTA, save off the previous entry before writing and |
| 5770 | * restore the old value after writing. |
| 5771 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5772 | if ((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5773 | temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1)); |
| 5774 | E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5775 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5776 | E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5777 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5778 | } else { |
| 5779 | E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5780 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5781 | } |
| 5782 | } |
| 5783 | |
| 5784 | /****************************************************************************** |
| 5785 | * Puts an ethernet address into a receive address register. |
| 5786 | * |
| 5787 | * hw - Struct containing variables accessed by shared code |
| 5788 | * addr - Address to put into receive address register |
| 5789 | * index - Receive address register to write |
| 5790 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5791 | void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5792 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5793 | u32 rar_low, rar_high; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5794 | |
| 5795 | /* HW expects these in little endian so we reverse the byte order |
| 5796 | * from network order (big endian) to little endian |
| 5797 | */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5798 | rar_low = ((u32) addr[0] | |
| 5799 | ((u32) addr[1] << 8) | |
| 5800 | ((u32) addr[2] << 16) | ((u32) addr[3] << 24)); |
| 5801 | rar_high = ((u32) addr[4] | ((u32) addr[5] << 8)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5802 | |
Jeff Kirsher | 8df06e5 | 2006-03-02 18:18:32 -0800 | [diff] [blame] | 5803 | /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx |
| 5804 | * unit hang. |
| 5805 | * |
| 5806 | * Description: |
| 5807 | * If there are any Rx frames queued up or otherwise present in the HW |
| 5808 | * before RSS is enabled, and then we enable RSS, the HW Rx unit will |
| 5809 | * hang. To work around this issue, we have to disable receives and |
| 5810 | * flush out all Rx frames before we enable RSS. To do so, we modify we |
| 5811 | * redirect all Rx traffic to manageability and then reset the HW. |
| 5812 | * This flushes away Rx frames, and (since the redirections to |
| 5813 | * manageability persists across resets) keeps new ones from coming in |
| 5814 | * while we work. Then, we clear the Address Valid AV bit for all MAC |
| 5815 | * addresses and undo the re-direction to manageability. |
| 5816 | * Now, frames are coming in again, but the MAC won't accept them, so |
| 5817 | * far so good. We now proceed to initialize RSS (if necessary) and |
| 5818 | * configure the Rx unit. Last, we re-enable the AV bits and continue |
| 5819 | * on our merry way. |
| 5820 | */ |
| 5821 | switch (hw->mac_type) { |
| 5822 | case e1000_82571: |
| 5823 | case e1000_82572: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 5824 | case e1000_80003es2lan: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 5825 | if (hw->leave_av_bit_off) |
Jeff Kirsher | 8df06e5 | 2006-03-02 18:18:32 -0800 | [diff] [blame] | 5826 | break; |
| 5827 | default: |
| 5828 | /* Indicate to hardware the Address is Valid. */ |
| 5829 | rar_high |= E1000_RAH_AV; |
| 5830 | break; |
| 5831 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5832 | |
| 5833 | E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5834 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5835 | E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5836 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5837 | } |
| 5838 | |
| 5839 | /****************************************************************************** |
| 5840 | * Writes a value to the specified offset in the VLAN filter table. |
| 5841 | * |
| 5842 | * hw - Struct containing variables accessed by shared code |
| 5843 | * offset - Offset in VLAN filer table to write |
| 5844 | * value - Value to write into VLAN filter table |
| 5845 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5846 | void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5847 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5848 | u32 temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5849 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5850 | if (hw->mac_type == e1000_ich8lan) |
| 5851 | return; |
| 5852 | |
| 5853 | if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5854 | temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1)); |
| 5855 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5856 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5857 | E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5858 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5859 | } else { |
| 5860 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5861 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5862 | } |
| 5863 | } |
| 5864 | |
| 5865 | /****************************************************************************** |
| 5866 | * Clears the VLAN filer table |
| 5867 | * |
| 5868 | * hw - Struct containing variables accessed by shared code |
| 5869 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5870 | static void e1000_clear_vfta(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5871 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5872 | u32 offset; |
| 5873 | u32 vfta_value = 0; |
| 5874 | u32 vfta_offset = 0; |
| 5875 | u32 vfta_bit_in_reg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5876 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5877 | if (hw->mac_type == e1000_ich8lan) |
| 5878 | return; |
| 5879 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5880 | if (hw->mac_type == e1000_82573) { |
| 5881 | if (hw->mng_cookie.vlan_id != 0) { |
| 5882 | /* The VFTA is a 4096b bit-field, each identifying a single VLAN |
| 5883 | * ID. The following operations determine which 32b entry |
| 5884 | * (i.e. offset) into the array we want to set the VLAN ID |
| 5885 | * (i.e. bit) of the manageability unit. */ |
| 5886 | vfta_offset = (hw->mng_cookie.vlan_id >> |
| 5887 | E1000_VFTA_ENTRY_SHIFT) & |
| 5888 | E1000_VFTA_ENTRY_MASK; |
| 5889 | vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id & |
| 5890 | E1000_VFTA_ENTRY_BIT_SHIFT_MASK); |
| 5891 | } |
| 5892 | } |
| 5893 | for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) { |
| 5894 | /* If the offset we want to clear is the same offset of the |
| 5895 | * manageability VLAN ID, then clear all bits except that of the |
| 5896 | * manageability unit */ |
| 5897 | vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0; |
| 5898 | E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 5899 | E1000_WRITE_FLUSH(hw); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5900 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5901 | } |
| 5902 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5903 | static s32 e1000_id_led_init(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5904 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5905 | u32 ledctl; |
| 5906 | const u32 ledctl_mask = 0x000000FF; |
| 5907 | const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON; |
| 5908 | const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF; |
| 5909 | u16 eeprom_data, i, temp; |
| 5910 | const u16 led_mask = 0x0F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5911 | |
| 5912 | DEBUGFUNC("e1000_id_led_init"); |
| 5913 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5914 | if (hw->mac_type < e1000_82540) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5915 | /* Nothing to do */ |
| 5916 | return E1000_SUCCESS; |
| 5917 | } |
| 5918 | |
| 5919 | ledctl = E1000_READ_REG(hw, LEDCTL); |
| 5920 | hw->ledctl_default = ledctl; |
| 5921 | hw->ledctl_mode1 = hw->ledctl_default; |
| 5922 | hw->ledctl_mode2 = hw->ledctl_default; |
| 5923 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5924 | 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] | 5925 | DEBUGOUT("EEPROM Read Error\n"); |
| 5926 | return -E1000_ERR_EEPROM; |
| 5927 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5928 | |
| 5929 | if ((hw->mac_type == e1000_82573) && |
| 5930 | (eeprom_data == ID_LED_RESERVED_82573)) |
| 5931 | eeprom_data = ID_LED_DEFAULT_82573; |
| 5932 | else if ((eeprom_data == ID_LED_RESERVED_0000) || |
| 5933 | (eeprom_data == ID_LED_RESERVED_FFFF)) { |
| 5934 | if (hw->mac_type == e1000_ich8lan) |
| 5935 | eeprom_data = ID_LED_DEFAULT_ICH8LAN; |
| 5936 | else |
| 5937 | eeprom_data = ID_LED_DEFAULT; |
| 5938 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 5939 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5940 | for (i = 0; i < 4; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5941 | temp = (eeprom_data >> (i << 2)) & led_mask; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5942 | switch (temp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5943 | case ID_LED_ON1_DEF2: |
| 5944 | case ID_LED_ON1_ON2: |
| 5945 | case ID_LED_ON1_OFF2: |
| 5946 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); |
| 5947 | hw->ledctl_mode1 |= ledctl_on << (i << 3); |
| 5948 | break; |
| 5949 | case ID_LED_OFF1_DEF2: |
| 5950 | case ID_LED_OFF1_ON2: |
| 5951 | case ID_LED_OFF1_OFF2: |
| 5952 | hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); |
| 5953 | hw->ledctl_mode1 |= ledctl_off << (i << 3); |
| 5954 | break; |
| 5955 | default: |
| 5956 | /* Do nothing */ |
| 5957 | break; |
| 5958 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5959 | switch (temp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5960 | case ID_LED_DEF1_ON2: |
| 5961 | case ID_LED_ON1_ON2: |
| 5962 | case ID_LED_OFF1_ON2: |
| 5963 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); |
| 5964 | hw->ledctl_mode2 |= ledctl_on << (i << 3); |
| 5965 | break; |
| 5966 | case ID_LED_DEF1_OFF2: |
| 5967 | case ID_LED_ON1_OFF2: |
| 5968 | case ID_LED_OFF1_OFF2: |
| 5969 | hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); |
| 5970 | hw->ledctl_mode2 |= ledctl_off << (i << 3); |
| 5971 | break; |
| 5972 | default: |
| 5973 | /* Do nothing */ |
| 5974 | break; |
| 5975 | } |
| 5976 | } |
| 5977 | return E1000_SUCCESS; |
| 5978 | } |
| 5979 | |
| 5980 | /****************************************************************************** |
| 5981 | * Prepares SW controlable LED for use and saves the current state of the LED. |
| 5982 | * |
| 5983 | * hw - Struct containing variables accessed by shared code |
| 5984 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 5985 | s32 e1000_setup_led(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5986 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5987 | u32 ledctl; |
| 5988 | s32 ret_val = E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5989 | |
| 5990 | DEBUGFUNC("e1000_setup_led"); |
| 5991 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 5992 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5993 | case e1000_82542_rev2_0: |
| 5994 | case e1000_82542_rev2_1: |
| 5995 | case e1000_82543: |
| 5996 | case e1000_82544: |
| 5997 | /* No setup necessary */ |
| 5998 | break; |
| 5999 | case e1000_82541: |
| 6000 | case e1000_82547: |
| 6001 | case e1000_82541_rev_2: |
| 6002 | case e1000_82547_rev_2: |
| 6003 | /* Turn off PHY Smart Power Down (if enabled) */ |
| 6004 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 6005 | &hw->phy_spd_default); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6006 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6007 | return ret_val; |
| 6008 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6009 | (u16)(hw->phy_spd_default & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6010 | ~IGP01E1000_GMII_SPD)); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6011 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6012 | return ret_val; |
| 6013 | /* Fall Through */ |
| 6014 | default: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6015 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6016 | ledctl = E1000_READ_REG(hw, LEDCTL); |
| 6017 | /* Save current LEDCTL settings */ |
| 6018 | hw->ledctl_default = ledctl; |
| 6019 | /* Turn off LED0 */ |
| 6020 | ledctl &= ~(E1000_LEDCTL_LED0_IVRT | |
| 6021 | E1000_LEDCTL_LED0_BLINK | |
| 6022 | E1000_LEDCTL_LED0_MODE_MASK); |
| 6023 | ledctl |= (E1000_LEDCTL_MODE_LED_OFF << |
| 6024 | E1000_LEDCTL_LED0_MODE_SHIFT); |
| 6025 | E1000_WRITE_REG(hw, LEDCTL, ledctl); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6026 | } else if (hw->media_type == e1000_media_type_copper) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6027 | E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1); |
| 6028 | break; |
| 6029 | } |
| 6030 | |
| 6031 | return E1000_SUCCESS; |
| 6032 | } |
| 6033 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6035 | /****************************************************************************** |
Auke Kok | f1b3a85 | 2006-06-27 09:07:56 -0700 | [diff] [blame] | 6036 | * Used on 82571 and later Si that has LED blink bits. |
| 6037 | * Callers must use their own timer and should have already called |
| 6038 | * e1000_id_led_init() |
| 6039 | * Call e1000_cleanup led() to stop blinking |
| 6040 | * |
| 6041 | * hw - Struct containing variables accessed by shared code |
| 6042 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 6043 | s32 e1000_blink_led_start(struct e1000_hw *hw) |
Auke Kok | f1b3a85 | 2006-06-27 09:07:56 -0700 | [diff] [blame] | 6044 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6045 | s16 i; |
| 6046 | u32 ledctl_blink = 0; |
Auke Kok | f1b3a85 | 2006-06-27 09:07:56 -0700 | [diff] [blame] | 6047 | |
| 6048 | DEBUGFUNC("e1000_id_led_blink_on"); |
| 6049 | |
| 6050 | if (hw->mac_type < e1000_82571) { |
| 6051 | /* Nothing to do */ |
| 6052 | return E1000_SUCCESS; |
| 6053 | } |
| 6054 | if (hw->media_type == e1000_media_type_fiber) { |
| 6055 | /* always blink LED0 for PCI-E fiber */ |
| 6056 | ledctl_blink = E1000_LEDCTL_LED0_BLINK | |
| 6057 | (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT); |
| 6058 | } else { |
| 6059 | /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */ |
| 6060 | ledctl_blink = hw->ledctl_mode2; |
| 6061 | for (i=0; i < 4; i++) |
| 6062 | if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) == |
| 6063 | E1000_LEDCTL_MODE_LED_ON) |
| 6064 | ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8)); |
| 6065 | } |
| 6066 | |
| 6067 | E1000_WRITE_REG(hw, LEDCTL, ledctl_blink); |
| 6068 | |
| 6069 | return E1000_SUCCESS; |
| 6070 | } |
| 6071 | |
| 6072 | /****************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6073 | * Restores the saved state of the SW controlable LED. |
| 6074 | * |
| 6075 | * hw - Struct containing variables accessed by shared code |
| 6076 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 6077 | s32 e1000_cleanup_led(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6078 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6079 | s32 ret_val = E1000_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6080 | |
| 6081 | DEBUGFUNC("e1000_cleanup_led"); |
| 6082 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6083 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6084 | case e1000_82542_rev2_0: |
| 6085 | case e1000_82542_rev2_1: |
| 6086 | case e1000_82543: |
| 6087 | case e1000_82544: |
| 6088 | /* No cleanup necessary */ |
| 6089 | break; |
| 6090 | case e1000_82541: |
| 6091 | case e1000_82547: |
| 6092 | case e1000_82541_rev_2: |
| 6093 | case e1000_82547_rev_2: |
| 6094 | /* Turn on PHY Smart Power Down (if previously enabled) */ |
| 6095 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, |
| 6096 | hw->phy_spd_default); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6097 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6098 | return ret_val; |
| 6099 | /* Fall Through */ |
| 6100 | default: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6101 | if (hw->phy_type == e1000_phy_ife) { |
| 6102 | e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0); |
| 6103 | break; |
| 6104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6105 | /* Restore LEDCTL settings */ |
| 6106 | E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default); |
| 6107 | break; |
| 6108 | } |
| 6109 | |
| 6110 | return E1000_SUCCESS; |
| 6111 | } |
| 6112 | |
| 6113 | /****************************************************************************** |
| 6114 | * Turns on the software controllable LED |
| 6115 | * |
| 6116 | * hw - Struct containing variables accessed by shared code |
| 6117 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 6118 | s32 e1000_led_on(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6119 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6120 | u32 ctrl = E1000_READ_REG(hw, CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6121 | |
| 6122 | DEBUGFUNC("e1000_led_on"); |
| 6123 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6124 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6125 | case e1000_82542_rev2_0: |
| 6126 | case e1000_82542_rev2_1: |
| 6127 | case e1000_82543: |
| 6128 | /* Set SW Defineable Pin 0 to turn on the LED */ |
| 6129 | ctrl |= E1000_CTRL_SWDPIN0; |
| 6130 | ctrl |= E1000_CTRL_SWDPIO0; |
| 6131 | break; |
| 6132 | case e1000_82544: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6133 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6134 | /* Set SW Defineable Pin 0 to turn on the LED */ |
| 6135 | ctrl |= E1000_CTRL_SWDPIN0; |
| 6136 | ctrl |= E1000_CTRL_SWDPIO0; |
| 6137 | } else { |
| 6138 | /* Clear SW Defineable Pin 0 to turn on the LED */ |
| 6139 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 6140 | ctrl |= E1000_CTRL_SWDPIO0; |
| 6141 | } |
| 6142 | break; |
| 6143 | default: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6144 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6145 | /* Clear SW Defineable Pin 0 to turn on the LED */ |
| 6146 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 6147 | ctrl |= E1000_CTRL_SWDPIO0; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6148 | } else if (hw->phy_type == e1000_phy_ife) { |
| 6149 | e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, |
| 6150 | (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON)); |
| 6151 | } else if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6152 | E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2); |
| 6153 | return E1000_SUCCESS; |
| 6154 | } |
| 6155 | break; |
| 6156 | } |
| 6157 | |
| 6158 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 6159 | |
| 6160 | return E1000_SUCCESS; |
| 6161 | } |
| 6162 | |
| 6163 | /****************************************************************************** |
| 6164 | * Turns off the software controllable LED |
| 6165 | * |
| 6166 | * hw - Struct containing variables accessed by shared code |
| 6167 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 6168 | s32 e1000_led_off(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6169 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6170 | u32 ctrl = E1000_READ_REG(hw, CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6171 | |
| 6172 | DEBUGFUNC("e1000_led_off"); |
| 6173 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6174 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6175 | case e1000_82542_rev2_0: |
| 6176 | case e1000_82542_rev2_1: |
| 6177 | case e1000_82543: |
| 6178 | /* Clear SW Defineable Pin 0 to turn off the LED */ |
| 6179 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 6180 | ctrl |= E1000_CTRL_SWDPIO0; |
| 6181 | break; |
| 6182 | case e1000_82544: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6183 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6184 | /* Clear SW Defineable Pin 0 to turn off the LED */ |
| 6185 | ctrl &= ~E1000_CTRL_SWDPIN0; |
| 6186 | ctrl |= E1000_CTRL_SWDPIO0; |
| 6187 | } else { |
| 6188 | /* Set SW Defineable Pin 0 to turn off the LED */ |
| 6189 | ctrl |= E1000_CTRL_SWDPIN0; |
| 6190 | ctrl |= E1000_CTRL_SWDPIO0; |
| 6191 | } |
| 6192 | break; |
| 6193 | default: |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6194 | if (hw->media_type == e1000_media_type_fiber) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6195 | /* Set SW Defineable Pin 0 to turn off the LED */ |
| 6196 | ctrl |= E1000_CTRL_SWDPIN0; |
| 6197 | ctrl |= E1000_CTRL_SWDPIO0; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6198 | } else if (hw->phy_type == e1000_phy_ife) { |
| 6199 | e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, |
| 6200 | (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF)); |
| 6201 | } else if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6202 | E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1); |
| 6203 | return E1000_SUCCESS; |
| 6204 | } |
| 6205 | break; |
| 6206 | } |
| 6207 | |
| 6208 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 6209 | |
| 6210 | return E1000_SUCCESS; |
| 6211 | } |
| 6212 | |
| 6213 | /****************************************************************************** |
| 6214 | * Clears all hardware statistics counters. |
| 6215 | * |
| 6216 | * hw - Struct containing variables accessed by shared code |
| 6217 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 6218 | static void e1000_clear_hw_cntrs(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6219 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6220 | volatile u32 temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6221 | |
| 6222 | temp = E1000_READ_REG(hw, CRCERRS); |
| 6223 | temp = E1000_READ_REG(hw, SYMERRS); |
| 6224 | temp = E1000_READ_REG(hw, MPC); |
| 6225 | temp = E1000_READ_REG(hw, SCC); |
| 6226 | temp = E1000_READ_REG(hw, ECOL); |
| 6227 | temp = E1000_READ_REG(hw, MCC); |
| 6228 | temp = E1000_READ_REG(hw, LATECOL); |
| 6229 | temp = E1000_READ_REG(hw, COLC); |
| 6230 | temp = E1000_READ_REG(hw, DC); |
| 6231 | temp = E1000_READ_REG(hw, SEC); |
| 6232 | temp = E1000_READ_REG(hw, RLEC); |
| 6233 | temp = E1000_READ_REG(hw, XONRXC); |
| 6234 | temp = E1000_READ_REG(hw, XONTXC); |
| 6235 | temp = E1000_READ_REG(hw, XOFFRXC); |
| 6236 | temp = E1000_READ_REG(hw, XOFFTXC); |
| 6237 | temp = E1000_READ_REG(hw, FCRUC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6238 | |
| 6239 | if (hw->mac_type != e1000_ich8lan) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6240 | temp = E1000_READ_REG(hw, PRC64); |
| 6241 | temp = E1000_READ_REG(hw, PRC127); |
| 6242 | temp = E1000_READ_REG(hw, PRC255); |
| 6243 | temp = E1000_READ_REG(hw, PRC511); |
| 6244 | temp = E1000_READ_REG(hw, PRC1023); |
| 6245 | temp = E1000_READ_REG(hw, PRC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6246 | } |
| 6247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6248 | temp = E1000_READ_REG(hw, GPRC); |
| 6249 | temp = E1000_READ_REG(hw, BPRC); |
| 6250 | temp = E1000_READ_REG(hw, MPRC); |
| 6251 | temp = E1000_READ_REG(hw, GPTC); |
| 6252 | temp = E1000_READ_REG(hw, GORCL); |
| 6253 | temp = E1000_READ_REG(hw, GORCH); |
| 6254 | temp = E1000_READ_REG(hw, GOTCL); |
| 6255 | temp = E1000_READ_REG(hw, GOTCH); |
| 6256 | temp = E1000_READ_REG(hw, RNBC); |
| 6257 | temp = E1000_READ_REG(hw, RUC); |
| 6258 | temp = E1000_READ_REG(hw, RFC); |
| 6259 | temp = E1000_READ_REG(hw, ROC); |
| 6260 | temp = E1000_READ_REG(hw, RJC); |
| 6261 | temp = E1000_READ_REG(hw, TORL); |
| 6262 | temp = E1000_READ_REG(hw, TORH); |
| 6263 | temp = E1000_READ_REG(hw, TOTL); |
| 6264 | temp = E1000_READ_REG(hw, TOTH); |
| 6265 | temp = E1000_READ_REG(hw, TPR); |
| 6266 | temp = E1000_READ_REG(hw, TPT); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6267 | |
| 6268 | if (hw->mac_type != e1000_ich8lan) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6269 | temp = E1000_READ_REG(hw, PTC64); |
| 6270 | temp = E1000_READ_REG(hw, PTC127); |
| 6271 | temp = E1000_READ_REG(hw, PTC255); |
| 6272 | temp = E1000_READ_REG(hw, PTC511); |
| 6273 | temp = E1000_READ_REG(hw, PTC1023); |
| 6274 | temp = E1000_READ_REG(hw, PTC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6275 | } |
| 6276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6277 | temp = E1000_READ_REG(hw, MPTC); |
| 6278 | temp = E1000_READ_REG(hw, BPTC); |
| 6279 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6280 | if (hw->mac_type < e1000_82543) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6281 | |
| 6282 | temp = E1000_READ_REG(hw, ALGNERRC); |
| 6283 | temp = E1000_READ_REG(hw, RXERRC); |
| 6284 | temp = E1000_READ_REG(hw, TNCRS); |
| 6285 | temp = E1000_READ_REG(hw, CEXTERR); |
| 6286 | temp = E1000_READ_REG(hw, TSCTC); |
| 6287 | temp = E1000_READ_REG(hw, TSCTFC); |
| 6288 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6289 | if (hw->mac_type <= e1000_82544) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6290 | |
| 6291 | temp = E1000_READ_REG(hw, MGTPRC); |
| 6292 | temp = E1000_READ_REG(hw, MGTPDC); |
| 6293 | temp = E1000_READ_REG(hw, MGTPTC); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6294 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6295 | if (hw->mac_type <= e1000_82547_rev_2) return; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6296 | |
| 6297 | temp = E1000_READ_REG(hw, IAC); |
| 6298 | temp = E1000_READ_REG(hw, ICRXOC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6299 | |
| 6300 | if (hw->mac_type == e1000_ich8lan) return; |
| 6301 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6302 | temp = E1000_READ_REG(hw, ICRXPTC); |
| 6303 | temp = E1000_READ_REG(hw, ICRXATC); |
| 6304 | temp = E1000_READ_REG(hw, ICTXPTC); |
| 6305 | temp = E1000_READ_REG(hw, ICTXATC); |
| 6306 | temp = E1000_READ_REG(hw, ICTXQEC); |
| 6307 | temp = E1000_READ_REG(hw, ICTXQMTC); |
| 6308 | temp = E1000_READ_REG(hw, ICRXDMTC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6309 | } |
| 6310 | |
| 6311 | /****************************************************************************** |
| 6312 | * Resets Adaptive IFS to its default state. |
| 6313 | * |
| 6314 | * hw - Struct containing variables accessed by shared code |
| 6315 | * |
| 6316 | * Call this after e1000_init_hw. You may override the IFS defaults by setting |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 6317 | * hw->ifs_params_forced to true. However, you must initialize hw-> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6318 | * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio |
| 6319 | * before calling this function. |
| 6320 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 6321 | void e1000_reset_adaptive(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6322 | { |
| 6323 | DEBUGFUNC("e1000_reset_adaptive"); |
| 6324 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6325 | if (hw->adaptive_ifs) { |
| 6326 | if (!hw->ifs_params_forced) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6327 | hw->current_ifs_val = 0; |
| 6328 | hw->ifs_min_val = IFS_MIN; |
| 6329 | hw->ifs_max_val = IFS_MAX; |
| 6330 | hw->ifs_step_size = IFS_STEP; |
| 6331 | hw->ifs_ratio = IFS_RATIO; |
| 6332 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 6333 | hw->in_ifs_mode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6334 | E1000_WRITE_REG(hw, AIT, 0); |
| 6335 | } else { |
| 6336 | DEBUGOUT("Not in Adaptive IFS mode!\n"); |
| 6337 | } |
| 6338 | } |
| 6339 | |
| 6340 | /****************************************************************************** |
| 6341 | * Called during the callback/watchdog routine to update IFS value based on |
| 6342 | * the ratio of transmits to collisions. |
| 6343 | * |
| 6344 | * hw - Struct containing variables accessed by shared code |
| 6345 | * tx_packets - Number of transmits since last callback |
| 6346 | * total_collisions - Number of collisions since last callback |
| 6347 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 6348 | void e1000_update_adaptive(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6349 | { |
| 6350 | DEBUGFUNC("e1000_update_adaptive"); |
| 6351 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6352 | if (hw->adaptive_ifs) { |
| 6353 | if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) { |
| 6354 | if (hw->tx_packet_delta > MIN_NUM_XMITS) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 6355 | hw->in_ifs_mode = true; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6356 | if (hw->current_ifs_val < hw->ifs_max_val) { |
| 6357 | if (hw->current_ifs_val == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6358 | hw->current_ifs_val = hw->ifs_min_val; |
| 6359 | else |
| 6360 | hw->current_ifs_val += hw->ifs_step_size; |
| 6361 | E1000_WRITE_REG(hw, AIT, hw->current_ifs_val); |
| 6362 | } |
| 6363 | } |
| 6364 | } else { |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6365 | if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6366 | hw->current_ifs_val = 0; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 6367 | hw->in_ifs_mode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6368 | E1000_WRITE_REG(hw, AIT, 0); |
| 6369 | } |
| 6370 | } |
| 6371 | } else { |
| 6372 | DEBUGOUT("Not in Adaptive IFS mode!\n"); |
| 6373 | } |
| 6374 | } |
| 6375 | |
| 6376 | /****************************************************************************** |
| 6377 | * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT |
| 6378 | * |
| 6379 | * hw - Struct containing variables accessed by shared code |
| 6380 | * frame_len - The length of the frame in question |
| 6381 | * mac_addr - The Ethernet destination address of the frame in question |
| 6382 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 6383 | void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats, |
| 6384 | u32 frame_len, u8 *mac_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6385 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6386 | u64 carry_bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6387 | |
| 6388 | /* First adjust the frame length. */ |
| 6389 | frame_len--; |
| 6390 | /* We need to adjust the statistics counters, since the hardware |
| 6391 | * counters overcount this packet as a CRC error and undercount |
| 6392 | * the packet as a good packet |
| 6393 | */ |
| 6394 | /* This packet should not be counted as a CRC error. */ |
| 6395 | stats->crcerrs--; |
| 6396 | /* This packet does count as a Good Packet Received. */ |
| 6397 | stats->gprc++; |
| 6398 | |
| 6399 | /* Adjust the Good Octets received counters */ |
| 6400 | carry_bit = 0x80000000 & stats->gorcl; |
| 6401 | stats->gorcl += frame_len; |
| 6402 | /* If the high bit of Gorcl (the low 32 bits of the Good Octets |
| 6403 | * Received Count) was one before the addition, |
| 6404 | * AND it is zero after, then we lost the carry out, |
| 6405 | * need to add one to Gorch (Good Octets Received Count High). |
| 6406 | * This could be simplified if all environments supported |
| 6407 | * 64-bit integers. |
| 6408 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6409 | if (carry_bit && ((stats->gorcl & 0x80000000) == 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6410 | stats->gorch++; |
| 6411 | /* Is this a broadcast or multicast? Check broadcast first, |
| 6412 | * since the test for a multicast frame will test positive on |
| 6413 | * a broadcast frame. |
| 6414 | */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6415 | if ((mac_addr[0] == (u8) 0xff) && (mac_addr[1] == (u8) 0xff)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6416 | /* Broadcast packet */ |
| 6417 | stats->bprc++; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6418 | else if (*mac_addr & 0x01) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6419 | /* Multicast packet */ |
| 6420 | stats->mprc++; |
| 6421 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6422 | if (frame_len == hw->max_frame_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6423 | /* In this case, the hardware has overcounted the number of |
| 6424 | * oversize frames. |
| 6425 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6426 | if (stats->roc > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6427 | stats->roc--; |
| 6428 | } |
| 6429 | |
| 6430 | /* Adjust the bin counters when the extra byte put the frame in the |
| 6431 | * wrong bin. Remember that the frame_len was adjusted above. |
| 6432 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6433 | if (frame_len == 64) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6434 | stats->prc64++; |
| 6435 | stats->prc127--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6436 | } else if (frame_len == 127) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6437 | stats->prc127++; |
| 6438 | stats->prc255--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6439 | } else if (frame_len == 255) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6440 | stats->prc255++; |
| 6441 | stats->prc511--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6442 | } else if (frame_len == 511) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6443 | stats->prc511++; |
| 6444 | stats->prc1023--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6445 | } else if (frame_len == 1023) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6446 | stats->prc1023++; |
| 6447 | stats->prc1522--; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6448 | } else if (frame_len == 1522) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6449 | stats->prc1522++; |
| 6450 | } |
| 6451 | } |
| 6452 | |
| 6453 | /****************************************************************************** |
| 6454 | * Gets the current PCI bus type, speed, and width of the hardware |
| 6455 | * |
| 6456 | * hw - Struct containing variables accessed by shared code |
| 6457 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 6458 | void e1000_get_bus_info(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6459 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6460 | s32 ret_val; |
| 6461 | u16 pci_ex_link_status; |
| 6462 | u32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6463 | |
| 6464 | switch (hw->mac_type) { |
| 6465 | case e1000_82542_rev2_0: |
| 6466 | case e1000_82542_rev2_1: |
Jeff Kirsher | c3813ae | 2006-12-15 10:37:32 +0100 | [diff] [blame] | 6467 | hw->bus_type = e1000_bus_type_pci; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6468 | hw->bus_speed = e1000_bus_speed_unknown; |
| 6469 | hw->bus_width = e1000_bus_width_unknown; |
| 6470 | break; |
Jeff Kirsher | caeccb6 | 2006-09-27 12:53:57 -0700 | [diff] [blame] | 6471 | case e1000_82571: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 6472 | case e1000_82572: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6473 | case e1000_82573: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 6474 | case e1000_80003es2lan: |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 6475 | hw->bus_type = e1000_bus_type_pci_express; |
| 6476 | hw->bus_speed = e1000_bus_speed_2500; |
Jeff Kirsher | caeccb6 | 2006-09-27 12:53:57 -0700 | [diff] [blame] | 6477 | ret_val = e1000_read_pcie_cap_reg(hw, |
| 6478 | PCI_EX_LINK_STATUS, |
| 6479 | &pci_ex_link_status); |
| 6480 | if (ret_val) |
| 6481 | hw->bus_width = e1000_bus_width_unknown; |
| 6482 | else |
| 6483 | hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >> |
| 6484 | PCI_EX_LINK_WIDTH_SHIFT; |
| 6485 | break; |
| 6486 | case e1000_ich8lan: |
| 6487 | hw->bus_type = e1000_bus_type_pci_express; |
| 6488 | hw->bus_speed = e1000_bus_speed_2500; |
| 6489 | hw->bus_width = e1000_bus_width_pciex_1; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6490 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6491 | default: |
| 6492 | status = E1000_READ_REG(hw, STATUS); |
| 6493 | hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ? |
| 6494 | e1000_bus_type_pcix : e1000_bus_type_pci; |
| 6495 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6496 | if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6497 | hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ? |
| 6498 | e1000_bus_speed_66 : e1000_bus_speed_120; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6499 | } else if (hw->bus_type == e1000_bus_type_pci) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6500 | hw->bus_speed = (status & E1000_STATUS_PCI66) ? |
| 6501 | e1000_bus_speed_66 : e1000_bus_speed_33; |
| 6502 | } else { |
| 6503 | switch (status & E1000_STATUS_PCIX_SPEED) { |
| 6504 | case E1000_STATUS_PCIX_SPEED_66: |
| 6505 | hw->bus_speed = e1000_bus_speed_66; |
| 6506 | break; |
| 6507 | case E1000_STATUS_PCIX_SPEED_100: |
| 6508 | hw->bus_speed = e1000_bus_speed_100; |
| 6509 | break; |
| 6510 | case E1000_STATUS_PCIX_SPEED_133: |
| 6511 | hw->bus_speed = e1000_bus_speed_133; |
| 6512 | break; |
| 6513 | default: |
| 6514 | hw->bus_speed = e1000_bus_speed_reserved; |
| 6515 | break; |
| 6516 | } |
| 6517 | } |
| 6518 | hw->bus_width = (status & E1000_STATUS_BUS64) ? |
| 6519 | e1000_bus_width_64 : e1000_bus_width_32; |
| 6520 | break; |
| 6521 | } |
| 6522 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6523 | |
| 6524 | /****************************************************************************** |
| 6525 | * Writes a value to one of the devices registers using port I/O (as opposed to |
| 6526 | * memory mapped I/O). Only 82544 and newer devices support port I/O. |
| 6527 | * |
| 6528 | * hw - Struct containing variables accessed by shared code |
| 6529 | * offset - offset to write to |
| 6530 | * value - value to write |
| 6531 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 6532 | static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6533 | { |
| 6534 | unsigned long io_addr = hw->io_base; |
| 6535 | unsigned long io_data = hw->io_base + 4; |
| 6536 | |
| 6537 | e1000_io_write(hw, io_addr, offset); |
| 6538 | e1000_io_write(hw, io_data, value); |
| 6539 | } |
| 6540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6541 | /****************************************************************************** |
| 6542 | * Estimates the cable length. |
| 6543 | * |
| 6544 | * hw - Struct containing variables accessed by shared code |
| 6545 | * min_length - The estimated minimum length |
| 6546 | * max_length - The estimated maximum length |
| 6547 | * |
| 6548 | * returns: - E1000_ERR_XXX |
| 6549 | * E1000_SUCCESS |
| 6550 | * |
| 6551 | * This function always returns a ranged length (minimum & maximum). |
| 6552 | * So for M88 phy's, this function interprets the one value returned from the |
| 6553 | * register to the minimum and maximum range. |
| 6554 | * For IGP phy's, the function calculates the range by the AGC registers. |
| 6555 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 6556 | static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length, |
| 6557 | u16 *max_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6558 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6559 | s32 ret_val; |
| 6560 | u16 agc_value = 0; |
| 6561 | u16 i, phy_data; |
| 6562 | u16 cable_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6563 | |
| 6564 | DEBUGFUNC("e1000_get_cable_length"); |
| 6565 | |
| 6566 | *min_length = *max_length = 0; |
| 6567 | |
| 6568 | /* Use old method for Phy older than IGP */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6569 | if (hw->phy_type == e1000_phy_m88) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6571 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 6572 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6573 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6574 | return ret_val; |
| 6575 | cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >> |
| 6576 | M88E1000_PSSR_CABLE_LENGTH_SHIFT; |
| 6577 | |
| 6578 | /* Convert the enum value to ranged values */ |
| 6579 | switch (cable_length) { |
| 6580 | case e1000_cable_length_50: |
| 6581 | *min_length = 0; |
| 6582 | *max_length = e1000_igp_cable_length_50; |
| 6583 | break; |
| 6584 | case e1000_cable_length_50_80: |
| 6585 | *min_length = e1000_igp_cable_length_50; |
| 6586 | *max_length = e1000_igp_cable_length_80; |
| 6587 | break; |
| 6588 | case e1000_cable_length_80_110: |
| 6589 | *min_length = e1000_igp_cable_length_80; |
| 6590 | *max_length = e1000_igp_cable_length_110; |
| 6591 | break; |
| 6592 | case e1000_cable_length_110_140: |
| 6593 | *min_length = e1000_igp_cable_length_110; |
| 6594 | *max_length = e1000_igp_cable_length_140; |
| 6595 | break; |
| 6596 | case e1000_cable_length_140: |
| 6597 | *min_length = e1000_igp_cable_length_140; |
| 6598 | *max_length = e1000_igp_cable_length_170; |
| 6599 | break; |
| 6600 | default: |
| 6601 | return -E1000_ERR_PHY; |
| 6602 | break; |
| 6603 | } |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 6604 | } else if (hw->phy_type == e1000_phy_gg82563) { |
| 6605 | ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE, |
| 6606 | &phy_data); |
| 6607 | if (ret_val) |
| 6608 | return ret_val; |
| 6609 | cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH; |
| 6610 | |
| 6611 | switch (cable_length) { |
| 6612 | case e1000_gg_cable_length_60: |
| 6613 | *min_length = 0; |
| 6614 | *max_length = e1000_igp_cable_length_60; |
| 6615 | break; |
| 6616 | case e1000_gg_cable_length_60_115: |
| 6617 | *min_length = e1000_igp_cable_length_60; |
| 6618 | *max_length = e1000_igp_cable_length_115; |
| 6619 | break; |
| 6620 | case e1000_gg_cable_length_115_150: |
| 6621 | *min_length = e1000_igp_cable_length_115; |
| 6622 | *max_length = e1000_igp_cable_length_150; |
| 6623 | break; |
| 6624 | case e1000_gg_cable_length_150: |
| 6625 | *min_length = e1000_igp_cable_length_150; |
| 6626 | *max_length = e1000_igp_cable_length_180; |
| 6627 | break; |
| 6628 | default: |
| 6629 | return -E1000_ERR_PHY; |
| 6630 | break; |
| 6631 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6632 | } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6633 | u16 cur_agc_value; |
| 6634 | u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE; |
| 6635 | u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6636 | {IGP01E1000_PHY_AGC_A, |
| 6637 | IGP01E1000_PHY_AGC_B, |
| 6638 | IGP01E1000_PHY_AGC_C, |
| 6639 | IGP01E1000_PHY_AGC_D}; |
| 6640 | /* Read the AGC registers for all channels */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6641 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6642 | |
| 6643 | 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] | 6644 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6645 | return ret_val; |
| 6646 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6647 | cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6648 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6649 | /* Value bound check. */ |
| 6650 | if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) || |
| 6651 | (cur_agc_value == 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6652 | return -E1000_ERR_PHY; |
| 6653 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6654 | agc_value += cur_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6655 | |
| 6656 | /* Update minimal AGC value. */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6657 | if (min_agc_value > cur_agc_value) |
| 6658 | min_agc_value = cur_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6659 | } |
| 6660 | |
| 6661 | /* Remove the minimal AGC result for length < 50m */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6662 | if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) { |
| 6663 | agc_value -= min_agc_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6664 | |
| 6665 | /* Get the average length of the remaining 3 channels */ |
| 6666 | agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1); |
| 6667 | } else { |
| 6668 | /* Get the average length of all the 4 channels. */ |
| 6669 | agc_value /= IGP01E1000_PHY_CHANNEL_NUM; |
| 6670 | } |
| 6671 | |
| 6672 | /* Set the range of the calculated length. */ |
| 6673 | *min_length = ((e1000_igp_cable_length_table[agc_value] - |
| 6674 | IGP01E1000_AGC_RANGE) > 0) ? |
| 6675 | (e1000_igp_cable_length_table[agc_value] - |
| 6676 | IGP01E1000_AGC_RANGE) : 0; |
| 6677 | *max_length = e1000_igp_cable_length_table[agc_value] + |
| 6678 | IGP01E1000_AGC_RANGE; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6679 | } else if (hw->phy_type == e1000_phy_igp_2 || |
| 6680 | hw->phy_type == e1000_phy_igp_3) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6681 | u16 cur_agc_index, max_agc_index = 0; |
| 6682 | u16 min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1; |
| 6683 | u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 6684 | {IGP02E1000_PHY_AGC_A, |
| 6685 | IGP02E1000_PHY_AGC_B, |
| 6686 | IGP02E1000_PHY_AGC_C, |
| 6687 | IGP02E1000_PHY_AGC_D}; |
| 6688 | /* Read the AGC registers for all channels */ |
| 6689 | for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) { |
| 6690 | ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data); |
| 6691 | if (ret_val) |
| 6692 | return ret_val; |
| 6693 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6694 | /* Getting bits 15:9, which represent the combination of course and |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 6695 | * fine gain values. The result is a number that can be put into |
| 6696 | * the lookup table to obtain the approximate cable length. */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6697 | cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) & |
| 6698 | IGP02E1000_AGC_LENGTH_MASK; |
| 6699 | |
| 6700 | /* Array index bound check. */ |
| 6701 | if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) || |
| 6702 | (cur_agc_index == 0)) |
| 6703 | return -E1000_ERR_PHY; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 6704 | |
| 6705 | /* Remove min & max AGC values from calculation. */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6706 | if (e1000_igp_2_cable_length_table[min_agc_index] > |
| 6707 | e1000_igp_2_cable_length_table[cur_agc_index]) |
| 6708 | min_agc_index = cur_agc_index; |
| 6709 | if (e1000_igp_2_cable_length_table[max_agc_index] < |
| 6710 | e1000_igp_2_cable_length_table[cur_agc_index]) |
| 6711 | max_agc_index = cur_agc_index; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 6712 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6713 | agc_value += e1000_igp_2_cable_length_table[cur_agc_index]; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 6714 | } |
| 6715 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6716 | agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] + |
| 6717 | e1000_igp_2_cable_length_table[max_agc_index]); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 6718 | agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2); |
| 6719 | |
| 6720 | /* Calculate cable length with the error range of +/- 10 meters. */ |
| 6721 | *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ? |
| 6722 | (agc_value - IGP02E1000_AGC_RANGE) : 0; |
| 6723 | *max_length = agc_value + IGP02E1000_AGC_RANGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6724 | } |
| 6725 | |
| 6726 | return E1000_SUCCESS; |
| 6727 | } |
| 6728 | |
| 6729 | /****************************************************************************** |
| 6730 | * Check the cable polarity |
| 6731 | * |
| 6732 | * hw - Struct containing variables accessed by shared code |
| 6733 | * polarity - output parameter : 0 - Polarity is not reversed |
| 6734 | * 1 - Polarity is reversed. |
| 6735 | * |
| 6736 | * returns: - E1000_ERR_XXX |
| 6737 | * E1000_SUCCESS |
| 6738 | * |
| 6739 | * For phy's older then IGP, this function simply reads the polarity bit in the |
| 6740 | * Phy Status register. For IGP phy's, this bit is valid only if link speed is |
| 6741 | * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will |
| 6742 | * return 0. If the link speed is 1000 Mbps the polarity status is in the |
| 6743 | * IGP01E1000_PHY_PCS_INIT_REG. |
| 6744 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 6745 | static s32 e1000_check_polarity(struct e1000_hw *hw, |
| 6746 | e1000_rev_polarity *polarity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6747 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6748 | s32 ret_val; |
| 6749 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6750 | |
| 6751 | DEBUGFUNC("e1000_check_polarity"); |
| 6752 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 6753 | if ((hw->phy_type == e1000_phy_m88) || |
| 6754 | (hw->phy_type == e1000_phy_gg82563)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6755 | /* return the Polarity bit in the Status register. */ |
| 6756 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 6757 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6758 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6759 | return ret_val; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 6760 | *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >> |
| 6761 | M88E1000_PSSR_REV_POLARITY_SHIFT) ? |
| 6762 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
| 6763 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6764 | } else if (hw->phy_type == e1000_phy_igp || |
| 6765 | hw->phy_type == e1000_phy_igp_3 || |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6766 | hw->phy_type == e1000_phy_igp_2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6767 | /* Read the Status register to check the speed */ |
| 6768 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, |
| 6769 | &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 | |
| 6773 | /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to |
| 6774 | * find the polarity status */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6775 | if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6776 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
| 6777 | |
| 6778 | /* Read the GIG initialization PCS register (0x00B4) */ |
| 6779 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG, |
| 6780 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6781 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6782 | return ret_val; |
| 6783 | |
| 6784 | /* Check the polarity bits */ |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 6785 | *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? |
| 6786 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6787 | } else { |
| 6788 | /* For 10 Mbps, read the polarity bit in the status register. (for |
| 6789 | * 100 Mbps this bit is always 0) */ |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 6790 | *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ? |
| 6791 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6792 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6793 | } else if (hw->phy_type == e1000_phy_ife) { |
| 6794 | ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL, |
| 6795 | &phy_data); |
| 6796 | if (ret_val) |
| 6797 | return ret_val; |
Jeff Kirsher | 70c6f30 | 2006-09-27 12:53:31 -0700 | [diff] [blame] | 6798 | *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >> |
| 6799 | IFE_PESC_POLARITY_REVERSED_SHIFT) ? |
| 6800 | e1000_rev_polarity_reversed : e1000_rev_polarity_normal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6801 | } |
| 6802 | return E1000_SUCCESS; |
| 6803 | } |
| 6804 | |
| 6805 | /****************************************************************************** |
| 6806 | * Check if Downshift occured |
| 6807 | * |
| 6808 | * hw - Struct containing variables accessed by shared code |
| 6809 | * downshift - output parameter : 0 - No Downshift ocured. |
| 6810 | * 1 - Downshift ocured. |
| 6811 | * |
| 6812 | * returns: - E1000_ERR_XXX |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 6813 | * E1000_SUCCESS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6814 | * |
| 6815 | * For phy's older then IGP, this function reads the Downshift bit in the Phy |
| 6816 | * Specific Status register. For IGP phy's, it reads the Downgrade bit in the |
| 6817 | * Link Health register. In IGP this bit is latched high, so the driver must |
| 6818 | * read it immediately after link is established. |
| 6819 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 6820 | static s32 e1000_check_downshift(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6821 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6822 | s32 ret_val; |
| 6823 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6824 | |
| 6825 | DEBUGFUNC("e1000_check_downshift"); |
| 6826 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6827 | if (hw->phy_type == e1000_phy_igp || |
| 6828 | hw->phy_type == e1000_phy_igp_3 || |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6829 | hw->phy_type == e1000_phy_igp_2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6830 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH, |
| 6831 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6832 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6833 | return ret_val; |
| 6834 | |
| 6835 | hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 6836 | } else if ((hw->phy_type == e1000_phy_m88) || |
| 6837 | (hw->phy_type == e1000_phy_gg82563)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6838 | ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, |
| 6839 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6840 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6841 | return ret_val; |
| 6842 | |
| 6843 | hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >> |
| 6844 | M88E1000_PSSR_DOWNSHIFT_SHIFT; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6845 | } else if (hw->phy_type == e1000_phy_ife) { |
| 6846 | /* e1000_phy_ife supports 10/100 speed only */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 6847 | hw->speed_downgraded = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6848 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 6849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6850 | return E1000_SUCCESS; |
| 6851 | } |
| 6852 | |
| 6853 | /***************************************************************************** |
| 6854 | * |
| 6855 | * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a |
| 6856 | * gigabit link is achieved to improve link quality. |
| 6857 | * |
| 6858 | * hw: Struct containing variables accessed by shared code |
| 6859 | * |
| 6860 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 6861 | * E1000_SUCCESS at any other case. |
| 6862 | * |
| 6863 | ****************************************************************************/ |
| 6864 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 6865 | static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6866 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6867 | s32 ret_val; |
| 6868 | u16 phy_data, phy_saved_data, speed, duplex, i; |
| 6869 | u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6870 | {IGP01E1000_PHY_AGC_PARAM_A, |
| 6871 | IGP01E1000_PHY_AGC_PARAM_B, |
| 6872 | IGP01E1000_PHY_AGC_PARAM_C, |
| 6873 | IGP01E1000_PHY_AGC_PARAM_D}; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6874 | u16 min_length, max_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6875 | |
| 6876 | DEBUGFUNC("e1000_config_dsp_after_link_change"); |
| 6877 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6878 | if (hw->phy_type != e1000_phy_igp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6879 | return E1000_SUCCESS; |
| 6880 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6881 | if (link_up) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6882 | ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6883 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6884 | DEBUGOUT("Error getting link speed and duplex\n"); |
| 6885 | return ret_val; |
| 6886 | } |
| 6887 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6888 | if (speed == SPEED_1000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6889 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 6890 | ret_val = e1000_get_cable_length(hw, &min_length, &max_length); |
| 6891 | if (ret_val) |
| 6892 | return ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6893 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6894 | if ((hw->dsp_config_state == e1000_dsp_config_enabled) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6895 | min_length >= e1000_igp_cable_length_50) { |
| 6896 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6897 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6898 | ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], |
| 6899 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6900 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6901 | return ret_val; |
| 6902 | |
| 6903 | phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX; |
| 6904 | |
| 6905 | ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i], |
| 6906 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6907 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6908 | return ret_val; |
| 6909 | } |
| 6910 | hw->dsp_config_state = e1000_dsp_config_activated; |
| 6911 | } |
| 6912 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6913 | if ((hw->ffe_config_state == e1000_ffe_config_enabled) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6914 | (min_length < e1000_igp_cable_length_50)) { |
| 6915 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 6916 | u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20; |
| 6917 | u32 idle_errs = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6918 | |
| 6919 | /* clear previous idle error counts */ |
| 6920 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, |
| 6921 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6922 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6923 | return ret_val; |
| 6924 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6925 | for (i = 0; i < ffe_idle_err_timeout; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6926 | udelay(1000); |
| 6927 | ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, |
| 6928 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6929 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6930 | return ret_val; |
| 6931 | |
| 6932 | idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6933 | if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6934 | hw->ffe_config_state = e1000_ffe_config_active; |
| 6935 | |
| 6936 | ret_val = e1000_write_phy_reg(hw, |
| 6937 | IGP01E1000_PHY_DSP_FFE, |
| 6938 | IGP01E1000_PHY_DSP_FFE_CM_CP); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6939 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6940 | return ret_val; |
| 6941 | break; |
| 6942 | } |
| 6943 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6944 | if (idle_errs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6945 | ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100; |
| 6946 | } |
| 6947 | } |
| 6948 | } |
| 6949 | } else { |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6950 | if (hw->dsp_config_state == e1000_dsp_config_activated) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6951 | /* Save off the current value of register 0x2F5B to be restored at |
| 6952 | * the end of the routines. */ |
| 6953 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
| 6954 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6955 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6956 | return ret_val; |
| 6957 | |
| 6958 | /* Disable the PHY transmitter */ |
| 6959 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 6960 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6961 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6962 | return ret_val; |
| 6963 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 6964 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6965 | |
| 6966 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 6967 | IGP01E1000_IEEE_FORCE_GIGA); |
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; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6970 | for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6971 | 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] | 6972 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6973 | return ret_val; |
| 6974 | |
| 6975 | phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX; |
| 6976 | phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS; |
| 6977 | |
| 6978 | 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] | 6979 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6980 | return ret_val; |
| 6981 | } |
| 6982 | |
| 6983 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 6984 | IGP01E1000_IEEE_RESTART_AUTONEG); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6985 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6986 | return ret_val; |
| 6987 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 6988 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6989 | |
| 6990 | /* Now enable the transmitter */ |
| 6991 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
| 6992 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6993 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6994 | return ret_val; |
| 6995 | |
| 6996 | hw->dsp_config_state = e1000_dsp_config_enabled; |
| 6997 | } |
| 6998 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 6999 | if (hw->ffe_config_state == e1000_ffe_config_active) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7000 | /* Save off the current value of register 0x2F5B to be restored at |
| 7001 | * the end of the routines. */ |
| 7002 | ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data); |
| 7003 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7004 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7005 | return ret_val; |
| 7006 | |
| 7007 | /* Disable the PHY transmitter */ |
| 7008 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003); |
| 7009 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7010 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7011 | return ret_val; |
| 7012 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7013 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7014 | |
| 7015 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 7016 | IGP01E1000_IEEE_FORCE_GIGA); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7017 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7018 | return ret_val; |
| 7019 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE, |
| 7020 | IGP01E1000_PHY_DSP_FFE_DEFAULT); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7021 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7022 | return ret_val; |
| 7023 | |
| 7024 | ret_val = e1000_write_phy_reg(hw, 0x0000, |
| 7025 | IGP01E1000_IEEE_RESTART_AUTONEG); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7026 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7027 | return ret_val; |
| 7028 | |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7029 | mdelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7030 | |
| 7031 | /* Now enable the transmitter */ |
| 7032 | ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data); |
| 7033 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7034 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7035 | return ret_val; |
| 7036 | |
| 7037 | hw->ffe_config_state = e1000_ffe_config_enabled; |
| 7038 | } |
| 7039 | } |
| 7040 | return E1000_SUCCESS; |
| 7041 | } |
| 7042 | |
| 7043 | /***************************************************************************** |
| 7044 | * Set PHY to class A mode |
| 7045 | * Assumes the following operations will follow to enable the new class mode. |
| 7046 | * 1. Do a PHY soft reset |
| 7047 | * 2. Restart auto-negotiation or force link. |
| 7048 | * |
| 7049 | * hw - Struct containing variables accessed by shared code |
| 7050 | ****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7051 | static s32 e1000_set_phy_mode(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7052 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7053 | s32 ret_val; |
| 7054 | u16 eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7055 | |
| 7056 | DEBUGFUNC("e1000_set_phy_mode"); |
| 7057 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7058 | if ((hw->mac_type == e1000_82545_rev_3) && |
| 7059 | (hw->media_type == e1000_media_type_copper)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7060 | 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] | 7061 | if (ret_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7062 | return ret_val; |
| 7063 | } |
| 7064 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7065 | if ((eeprom_data != EEPROM_RESERVED_WORD) && |
| 7066 | (eeprom_data & EEPROM_PHY_CLASS_A)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7067 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7068 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7069 | return ret_val; |
| 7070 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7071 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7072 | return ret_val; |
| 7073 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 7074 | hw->phy_reset_disable = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7075 | } |
| 7076 | } |
| 7077 | |
| 7078 | return E1000_SUCCESS; |
| 7079 | } |
| 7080 | |
| 7081 | /***************************************************************************** |
| 7082 | * |
| 7083 | * This function sets the lplu state according to the active flag. When |
| 7084 | * activating lplu this function also disables smart speed and vise versa. |
| 7085 | * lplu will not be activated unless the device autonegotiation advertisment |
| 7086 | * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes. |
| 7087 | * hw: Struct containing variables accessed by shared code |
| 7088 | * active - true to enable lplu false to disable lplu. |
| 7089 | * |
| 7090 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 7091 | * E1000_SUCCESS at any other case. |
| 7092 | * |
| 7093 | ****************************************************************************/ |
| 7094 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7095 | static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7096 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7097 | u32 phy_ctrl = 0; |
| 7098 | s32 ret_val; |
| 7099 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7100 | DEBUGFUNC("e1000_set_d3_lplu_state"); |
| 7101 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7102 | if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2 |
| 7103 | && hw->phy_type != e1000_phy_igp_3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7104 | return E1000_SUCCESS; |
| 7105 | |
| 7106 | /* During driver activity LPLU should not be used or it will attain link |
| 7107 | * from the lowest speeds starting from 10Mbps. The capability is used for |
| 7108 | * Dx transitions and states */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7109 | 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] | 7110 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7111 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7112 | return ret_val; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7113 | } else if (hw->mac_type == e1000_ich8lan) { |
| 7114 | /* MAC writes into PHY register based on the state transition |
| 7115 | * and start auto-negotiation. SW driver can overwrite the settings |
| 7116 | * in CSR PHY power control E1000_PHY_CTRL register. */ |
| 7117 | phy_ctrl = E1000_READ_REG(hw, PHY_CTRL); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7118 | } else { |
| 7119 | 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] | 7120 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7121 | return ret_val; |
| 7122 | } |
| 7123 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7124 | if (!active) { |
| 7125 | if (hw->mac_type == e1000_82541_rev_2 || |
| 7126 | hw->mac_type == e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7127 | phy_data &= ~IGP01E1000_GMII_FLEX_SPD; |
| 7128 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7129 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7130 | return ret_val; |
| 7131 | } else { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7132 | if (hw->mac_type == e1000_ich8lan) { |
| 7133 | phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU; |
| 7134 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
| 7135 | } else { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7136 | phy_data &= ~IGP02E1000_PM_D3_LPLU; |
| 7137 | ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
| 7138 | phy_data); |
| 7139 | if (ret_val) |
| 7140 | return ret_val; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7141 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7142 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7143 | |
| 7144 | /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during |
| 7145 | * Dx states where the power conservation is most important. During |
| 7146 | * driver activity we should enable SmartSpeed, so performance is |
| 7147 | * maintained. */ |
| 7148 | if (hw->smart_speed == e1000_smart_speed_on) { |
| 7149 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7150 | &phy_data); |
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 | phy_data |= IGP01E1000_PSCFR_SMART_SPEED; |
| 7155 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7156 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7157 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7158 | return ret_val; |
| 7159 | } else if (hw->smart_speed == e1000_smart_speed_off) { |
| 7160 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7161 | &phy_data); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 7162 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7163 | return ret_val; |
| 7164 | |
| 7165 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 7166 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7167 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7168 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7169 | return ret_val; |
| 7170 | } |
| 7171 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7172 | } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) || |
| 7173 | (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) || |
| 7174 | (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7175 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7176 | if (hw->mac_type == e1000_82541_rev_2 || |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7177 | hw->mac_type == e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7178 | phy_data |= IGP01E1000_GMII_FLEX_SPD; |
| 7179 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7180 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7181 | return ret_val; |
| 7182 | } else { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7183 | if (hw->mac_type == e1000_ich8lan) { |
| 7184 | phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU; |
| 7185 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
| 7186 | } else { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7187 | phy_data |= IGP02E1000_PM_D3_LPLU; |
| 7188 | ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
| 7189 | phy_data); |
| 7190 | if (ret_val) |
| 7191 | return ret_val; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7192 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7193 | } |
| 7194 | |
| 7195 | /* When LPLU is enabled we should disable SmartSpeed */ |
| 7196 | 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] | 7197 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7198 | return ret_val; |
| 7199 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7200 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 7201 | 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] | 7202 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7203 | return ret_val; |
| 7204 | |
| 7205 | } |
| 7206 | return E1000_SUCCESS; |
| 7207 | } |
| 7208 | |
| 7209 | /***************************************************************************** |
| 7210 | * |
| 7211 | * This function sets the lplu d0 state according to the active flag. When |
| 7212 | * activating lplu this function also disables smart speed and vise versa. |
| 7213 | * lplu will not be activated unless the device autonegotiation advertisment |
| 7214 | * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes. |
| 7215 | * hw: Struct containing variables accessed by shared code |
| 7216 | * active - true to enable lplu false to disable lplu. |
| 7217 | * |
| 7218 | * returns: - E1000_ERR_PHY if fail to read/write the PHY |
| 7219 | * E1000_SUCCESS at any other case. |
| 7220 | * |
| 7221 | ****************************************************************************/ |
| 7222 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7223 | static s32 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7224 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7225 | u32 phy_ctrl = 0; |
| 7226 | s32 ret_val; |
| 7227 | u16 phy_data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7228 | DEBUGFUNC("e1000_set_d0_lplu_state"); |
| 7229 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7230 | if (hw->mac_type <= e1000_82547_rev_2) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7231 | return E1000_SUCCESS; |
| 7232 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7233 | if (hw->mac_type == e1000_ich8lan) { |
| 7234 | phy_ctrl = E1000_READ_REG(hw, PHY_CTRL); |
| 7235 | } else { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7236 | 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] | 7237 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7238 | return ret_val; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7239 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7240 | |
| 7241 | if (!active) { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7242 | if (hw->mac_type == e1000_ich8lan) { |
| 7243 | phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU; |
| 7244 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
| 7245 | } else { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7246 | phy_data &= ~IGP02E1000_PM_D0_LPLU; |
| 7247 | ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 7248 | if (ret_val) |
| 7249 | return ret_val; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7250 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7251 | |
| 7252 | /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during |
| 7253 | * Dx states where the power conservation is most important. During |
| 7254 | * driver activity we should enable SmartSpeed, so performance is |
| 7255 | * maintained. */ |
| 7256 | if (hw->smart_speed == e1000_smart_speed_on) { |
| 7257 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7258 | &phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7259 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7260 | return ret_val; |
| 7261 | |
| 7262 | phy_data |= IGP01E1000_PSCFR_SMART_SPEED; |
| 7263 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7264 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7265 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7266 | return ret_val; |
| 7267 | } else if (hw->smart_speed == e1000_smart_speed_off) { |
| 7268 | ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7269 | &phy_data); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 7270 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7271 | return ret_val; |
| 7272 | |
| 7273 | phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
| 7274 | ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
| 7275 | phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7276 | if (ret_val) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7277 | return ret_val; |
| 7278 | } |
| 7279 | |
| 7280 | |
| 7281 | } else { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 7282 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7283 | if (hw->mac_type == e1000_ich8lan) { |
| 7284 | phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU; |
| 7285 | E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl); |
| 7286 | } else { |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 7287 | phy_data |= IGP02E1000_PM_D0_LPLU; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7288 | ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data); |
| 7289 | if (ret_val) |
| 7290 | return ret_val; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7291 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7293 | /* When LPLU is enabled we should disable SmartSpeed */ |
| 7294 | 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] | 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, phy_data); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7300 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7301 | return ret_val; |
| 7302 | |
| 7303 | } |
| 7304 | return E1000_SUCCESS; |
| 7305 | } |
| 7306 | |
| 7307 | /****************************************************************************** |
| 7308 | * Change VCO speed register to improve Bit Error Rate performance of SERDES. |
| 7309 | * |
| 7310 | * hw - Struct containing variables accessed by shared code |
| 7311 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7312 | static s32 e1000_set_vco_speed(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7313 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7314 | s32 ret_val; |
| 7315 | u16 default_page = 0; |
| 7316 | u16 phy_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7317 | |
| 7318 | DEBUGFUNC("e1000_set_vco_speed"); |
| 7319 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7320 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7321 | case e1000_82545_rev_3: |
| 7322 | case e1000_82546_rev_3: |
| 7323 | break; |
| 7324 | default: |
| 7325 | return E1000_SUCCESS; |
| 7326 | } |
| 7327 | |
| 7328 | /* Set PHY register 30, page 5, bit 8 to 0 */ |
| 7329 | |
| 7330 | 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] | 7331 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7332 | return ret_val; |
| 7333 | |
| 7334 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7335 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7336 | return ret_val; |
| 7337 | |
| 7338 | 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] | 7339 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7340 | return ret_val; |
| 7341 | |
| 7342 | phy_data &= ~M88E1000_PHY_VCO_REG_BIT8; |
| 7343 | 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] | 7344 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7345 | return ret_val; |
| 7346 | |
| 7347 | /* Set PHY register 30, page 4, bit 11 to 1 */ |
| 7348 | |
| 7349 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7350 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7351 | return ret_val; |
| 7352 | |
| 7353 | 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] | 7354 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7355 | return ret_val; |
| 7356 | |
| 7357 | phy_data |= M88E1000_PHY_VCO_REG_BIT11; |
| 7358 | 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] | 7359 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7360 | return ret_val; |
| 7361 | |
| 7362 | 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] | 7363 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7364 | return ret_val; |
| 7365 | |
| 7366 | return E1000_SUCCESS; |
| 7367 | } |
| 7368 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7369 | |
| 7370 | /***************************************************************************** |
| 7371 | * This function reads the cookie from ARC ram. |
| 7372 | * |
| 7373 | * returns: - E1000_SUCCESS . |
| 7374 | ****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7375 | static s32 e1000_host_if_read_cookie(struct e1000_hw *hw, u8 *buffer) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7376 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7377 | u8 i; |
| 7378 | u32 offset = E1000_MNG_DHCP_COOKIE_OFFSET; |
| 7379 | u8 length = E1000_MNG_DHCP_COOKIE_LENGTH; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7380 | |
| 7381 | length = (length >> 2); |
| 7382 | offset = (offset >> 2); |
| 7383 | |
| 7384 | for (i = 0; i < length; i++) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7385 | *((u32 *) buffer + i) = |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7386 | E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i); |
| 7387 | } |
| 7388 | return E1000_SUCCESS; |
| 7389 | } |
| 7390 | |
| 7391 | |
| 7392 | /***************************************************************************** |
| 7393 | * This function checks whether the HOST IF is enabled for command operaton |
| 7394 | * and also checks whether the previous command is completed. |
| 7395 | * It busy waits in case of previous command is not completed. |
| 7396 | * |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 7397 | * 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] | 7398 | * timeout |
| 7399 | * - E1000_SUCCESS for success. |
| 7400 | ****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7401 | static s32 e1000_mng_enable_host_if(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7402 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7403 | u32 hicr; |
| 7404 | u8 i; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7405 | |
| 7406 | /* Check that the host interface is enabled. */ |
| 7407 | hicr = E1000_READ_REG(hw, HICR); |
| 7408 | if ((hicr & E1000_HICR_EN) == 0) { |
| 7409 | DEBUGOUT("E1000_HOST_EN bit disabled.\n"); |
| 7410 | return -E1000_ERR_HOST_INTERFACE_COMMAND; |
| 7411 | } |
| 7412 | /* check the previous command is completed */ |
| 7413 | for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) { |
| 7414 | hicr = E1000_READ_REG(hw, HICR); |
| 7415 | if (!(hicr & E1000_HICR_C)) |
| 7416 | break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7417 | mdelay(1); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7418 | } |
| 7419 | |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 7420 | if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7421 | DEBUGOUT("Previous command timeout failed .\n"); |
| 7422 | return -E1000_ERR_HOST_INTERFACE_COMMAND; |
| 7423 | } |
| 7424 | return E1000_SUCCESS; |
| 7425 | } |
| 7426 | |
| 7427 | /***************************************************************************** |
| 7428 | * This function writes the buffer content at the offset given on the host if. |
| 7429 | * It also does alignment considerations to do the writes in most efficient way. |
| 7430 | * Also fills up the sum of the buffer in *buffer parameter. |
| 7431 | * |
| 7432 | * returns - E1000_SUCCESS for success. |
| 7433 | ****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7434 | static s32 e1000_mng_host_if_write(struct e1000_hw *hw, u8 *buffer, u16 length, |
| 7435 | u16 offset, u8 *sum) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7436 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7437 | u8 *tmp; |
| 7438 | u8 *bufptr = buffer; |
| 7439 | u32 data = 0; |
| 7440 | u16 remaining, i, j, prev_bytes; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7441 | |
| 7442 | /* sum = only sum of the data and it is not checksum */ |
| 7443 | |
| 7444 | if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) { |
| 7445 | return -E1000_ERR_PARAM; |
| 7446 | } |
| 7447 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7448 | tmp = (u8 *)&data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7449 | prev_bytes = offset & 0x3; |
| 7450 | offset &= 0xFFFC; |
| 7451 | offset >>= 2; |
| 7452 | |
| 7453 | if (prev_bytes) { |
| 7454 | data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7455 | for (j = prev_bytes; j < sizeof(u32); j++) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7456 | *(tmp + j) = *bufptr++; |
| 7457 | *sum += *(tmp + j); |
| 7458 | } |
| 7459 | E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data); |
| 7460 | length -= j - prev_bytes; |
| 7461 | offset++; |
| 7462 | } |
| 7463 | |
| 7464 | remaining = length & 0x3; |
| 7465 | length -= remaining; |
| 7466 | |
| 7467 | /* Calculate length in DWORDs */ |
| 7468 | length >>= 2; |
| 7469 | |
| 7470 | /* The device driver writes the relevant command block into the |
| 7471 | * ram area. */ |
| 7472 | for (i = 0; i < length; i++) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7473 | for (j = 0; j < sizeof(u32); j++) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7474 | *(tmp + j) = *bufptr++; |
| 7475 | *sum += *(tmp + j); |
| 7476 | } |
| 7477 | |
| 7478 | E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data); |
| 7479 | } |
| 7480 | if (remaining) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7481 | for (j = 0; j < sizeof(u32); j++) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7482 | if (j < remaining) |
| 7483 | *(tmp + j) = *bufptr++; |
| 7484 | else |
| 7485 | *(tmp + j) = 0; |
| 7486 | |
| 7487 | *sum += *(tmp + j); |
| 7488 | } |
| 7489 | E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data); |
| 7490 | } |
| 7491 | |
| 7492 | return E1000_SUCCESS; |
| 7493 | } |
| 7494 | |
| 7495 | |
| 7496 | /***************************************************************************** |
| 7497 | * This function writes the command header after does the checksum calculation. |
| 7498 | * |
| 7499 | * returns - E1000_SUCCESS for success. |
| 7500 | ****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7501 | static s32 e1000_mng_write_cmd_header(struct e1000_hw *hw, |
| 7502 | struct e1000_host_mng_command_header *hdr) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7503 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7504 | u16 i; |
| 7505 | u8 sum; |
| 7506 | u8 *buffer; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7507 | |
| 7508 | /* Write the whole command header structure which includes sum of |
| 7509 | * the buffer */ |
| 7510 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7511 | u16 length = sizeof(struct e1000_host_mng_command_header); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7512 | |
| 7513 | sum = hdr->checksum; |
| 7514 | hdr->checksum = 0; |
| 7515 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7516 | buffer = (u8 *) hdr; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7517 | i = length; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7518 | while (i--) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7519 | sum += buffer[i]; |
| 7520 | |
| 7521 | hdr->checksum = 0 - sum; |
| 7522 | |
| 7523 | length >>= 2; |
| 7524 | /* The device driver writes the relevant command block into the ram area. */ |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 7525 | for (i = 0; i < length; i++) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7526 | E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((u32 *) hdr + i)); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 7527 | E1000_WRITE_FLUSH(hw); |
| 7528 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7529 | |
| 7530 | return E1000_SUCCESS; |
| 7531 | } |
| 7532 | |
| 7533 | |
| 7534 | /***************************************************************************** |
| 7535 | * This function indicates to ARC that a new command is pending which completes |
| 7536 | * one write operation by the driver. |
| 7537 | * |
| 7538 | * returns - E1000_SUCCESS for success. |
| 7539 | ****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7540 | static s32 e1000_mng_write_commit(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7541 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7542 | u32 hicr; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7543 | |
| 7544 | hicr = E1000_READ_REG(hw, HICR); |
| 7545 | /* Setting this bit tells the ARC that a new command is pending. */ |
| 7546 | E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C); |
| 7547 | |
| 7548 | return E1000_SUCCESS; |
| 7549 | } |
| 7550 | |
| 7551 | |
| 7552 | /***************************************************************************** |
| 7553 | * This function checks the mode of the firmware. |
| 7554 | * |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 7555 | * returns - true when the mode is IAMT or false. |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7556 | ****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7557 | bool e1000_check_mng_mode(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7558 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7559 | u32 fwsm; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7560 | |
| 7561 | fwsm = E1000_READ_REG(hw, FWSM); |
| 7562 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7563 | if (hw->mac_type == e1000_ich8lan) { |
| 7564 | if ((fwsm & E1000_FWSM_MODE_MASK) == |
| 7565 | (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT)) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 7566 | return true; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7567 | } else if ((fwsm & E1000_FWSM_MODE_MASK) == |
| 7568 | (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT)) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 7569 | return true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7570 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 7571 | return false; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7572 | } |
| 7573 | |
| 7574 | |
| 7575 | /***************************************************************************** |
| 7576 | * This function writes the dhcp info . |
| 7577 | ****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7578 | s32 e1000_mng_write_dhcp_info(struct e1000_hw *hw, u8 *buffer, u16 length) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7579 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7580 | s32 ret_val; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7581 | struct e1000_host_mng_command_header hdr; |
| 7582 | |
| 7583 | hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD; |
| 7584 | hdr.command_length = length; |
| 7585 | hdr.reserved1 = 0; |
| 7586 | hdr.reserved2 = 0; |
| 7587 | hdr.checksum = 0; |
| 7588 | |
| 7589 | ret_val = e1000_mng_enable_host_if(hw); |
| 7590 | if (ret_val == E1000_SUCCESS) { |
| 7591 | ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr), |
| 7592 | &(hdr.checksum)); |
| 7593 | if (ret_val == E1000_SUCCESS) { |
| 7594 | ret_val = e1000_mng_write_cmd_header(hw, &hdr); |
| 7595 | if (ret_val == E1000_SUCCESS) |
| 7596 | ret_val = e1000_mng_write_commit(hw); |
| 7597 | } |
| 7598 | } |
| 7599 | return ret_val; |
| 7600 | } |
| 7601 | |
| 7602 | |
| 7603 | /***************************************************************************** |
| 7604 | * This function calculates the checksum. |
| 7605 | * |
| 7606 | * returns - checksum of buffer contents. |
| 7607 | ****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7608 | static u8 e1000_calculate_mng_checksum(char *buffer, u32 length) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7609 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7610 | u8 sum = 0; |
| 7611 | u32 i; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7612 | |
| 7613 | if (!buffer) |
| 7614 | return 0; |
| 7615 | |
| 7616 | for (i=0; i < length; i++) |
| 7617 | sum += buffer[i]; |
| 7618 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7619 | return (u8) (0 - sum); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7620 | } |
| 7621 | |
| 7622 | /***************************************************************************** |
| 7623 | * This function checks whether tx pkt filtering needs to be enabled or not. |
| 7624 | * |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 7625 | * returns - true for packet filtering or false. |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7626 | ****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7627 | bool e1000_enable_tx_pkt_filtering(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7628 | { |
| 7629 | /* called in init as well as watchdog timer functions */ |
| 7630 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7631 | s32 ret_val, checksum; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 7632 | bool tx_filter = false; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7633 | struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7634 | u8 *buffer = (u8 *) &(hw->mng_cookie); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7635 | |
| 7636 | if (e1000_check_mng_mode(hw)) { |
| 7637 | ret_val = e1000_mng_enable_host_if(hw); |
| 7638 | if (ret_val == E1000_SUCCESS) { |
| 7639 | ret_val = e1000_host_if_read_cookie(hw, buffer); |
| 7640 | if (ret_val == E1000_SUCCESS) { |
| 7641 | checksum = hdr->checksum; |
| 7642 | hdr->checksum = 0; |
| 7643 | if ((hdr->signature == E1000_IAMT_SIGNATURE) && |
| 7644 | checksum == e1000_calculate_mng_checksum((char *)buffer, |
| 7645 | E1000_MNG_DHCP_COOKIE_LENGTH)) { |
| 7646 | if (hdr->status & |
| 7647 | E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 7648 | tx_filter = true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7649 | } else |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 7650 | tx_filter = true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7651 | } else |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 7652 | tx_filter = true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7653 | } |
| 7654 | } |
| 7655 | |
| 7656 | hw->tx_pkt_filtering = tx_filter; |
| 7657 | return tx_filter; |
| 7658 | } |
| 7659 | |
| 7660 | /****************************************************************************** |
| 7661 | * Verifies the hardware needs to allow ARPs to be processed by the host |
| 7662 | * |
| 7663 | * hw - Struct containing variables accessed by shared code |
| 7664 | * |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 7665 | * returns: - true/false |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7666 | * |
| 7667 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7668 | u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7669 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7670 | u32 manc; |
| 7671 | u32 fwsm, factps; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7672 | |
| 7673 | if (hw->asf_firmware_present) { |
| 7674 | manc = E1000_READ_REG(hw, MANC); |
| 7675 | |
| 7676 | if (!(manc & E1000_MANC_RCV_TCO_EN) || |
| 7677 | !(manc & E1000_MANC_EN_MAC_ADDR_FILTER)) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 7678 | return false; |
| 7679 | if (e1000_arc_subsystem_valid(hw)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7680 | fwsm = E1000_READ_REG(hw, FWSM); |
| 7681 | factps = E1000_READ_REG(hw, FACTPS); |
| 7682 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 7683 | if ((((fwsm & E1000_FWSM_MODE_MASK) >> E1000_FWSM_MODE_SHIFT) == |
| 7684 | e1000_mng_mode_pt) && !(factps & E1000_FACTPS_MNGCG)) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 7685 | return true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7686 | } else |
| 7687 | if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN)) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 7688 | return true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7689 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 7690 | return false; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7691 | } |
| 7692 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7693 | static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7694 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7695 | s32 ret_val; |
| 7696 | u16 mii_status_reg; |
| 7697 | u16 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7698 | |
| 7699 | /* Polarity reversal workaround for forced 10F/10H links. */ |
| 7700 | |
| 7701 | /* Disable the transmitter on the PHY */ |
| 7702 | |
| 7703 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7704 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7705 | return ret_val; |
| 7706 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7707 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7708 | return ret_val; |
| 7709 | |
| 7710 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7711 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7712 | return ret_val; |
| 7713 | |
| 7714 | /* 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] | 7715 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7716 | /* Read the MII Status Register and wait for Link Status bit |
| 7717 | * to be clear. |
| 7718 | */ |
| 7719 | |
| 7720 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7721 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7722 | return ret_val; |
| 7723 | |
| 7724 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7725 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7726 | return ret_val; |
| 7727 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7728 | if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7729 | mdelay(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7730 | } |
| 7731 | |
| 7732 | /* Recommended delay time after link has been lost */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7733 | mdelay(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7734 | |
| 7735 | /* Now we will re-enable th transmitter on the PHY */ |
| 7736 | |
| 7737 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7738 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7739 | return ret_val; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7740 | mdelay(50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7741 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7742 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7743 | return ret_val; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7744 | mdelay(50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7745 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7746 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7747 | return ret_val; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7748 | mdelay(50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7749 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7750 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7751 | return ret_val; |
| 7752 | |
| 7753 | ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7754 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7755 | return ret_val; |
| 7756 | |
| 7757 | /* This loop will early-out if the link condition has been met. */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7758 | for (i = PHY_FORCE_TIME; i > 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7759 | /* Read the MII Status Register and wait for Link Status bit |
| 7760 | * to be set. |
| 7761 | */ |
| 7762 | |
| 7763 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7764 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7765 | return ret_val; |
| 7766 | |
| 7767 | ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7768 | if (ret_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7769 | return ret_val; |
| 7770 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7771 | if (mii_status_reg & MII_SR_LINK_STATUS) break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7772 | mdelay(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7773 | } |
| 7774 | return E1000_SUCCESS; |
| 7775 | } |
| 7776 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7777 | /*************************************************************************** |
| 7778 | * |
| 7779 | * Disables PCI-Express master access. |
| 7780 | * |
| 7781 | * hw: Struct containing variables accessed by shared code |
| 7782 | * |
| 7783 | * returns: - none. |
| 7784 | * |
| 7785 | ***************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7786 | static void e1000_set_pci_express_master_disable(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7787 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7788 | u32 ctrl; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7789 | |
| 7790 | DEBUGFUNC("e1000_set_pci_express_master_disable"); |
| 7791 | |
| 7792 | if (hw->bus_type != e1000_bus_type_pci_express) |
| 7793 | return; |
| 7794 | |
| 7795 | ctrl = E1000_READ_REG(hw, CTRL); |
| 7796 | ctrl |= E1000_CTRL_GIO_MASTER_DISABLE; |
| 7797 | E1000_WRITE_REG(hw, CTRL, ctrl); |
| 7798 | } |
| 7799 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7800 | /******************************************************************************* |
| 7801 | * |
| 7802 | * Disables PCI-Express master access and verifies there are no pending requests |
| 7803 | * |
| 7804 | * hw: Struct containing variables accessed by shared code |
| 7805 | * |
| 7806 | * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't |
| 7807 | * caused the master requests to be disabled. |
| 7808 | * E1000_SUCCESS master requests disabled. |
| 7809 | * |
| 7810 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7811 | s32 e1000_disable_pciex_master(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7812 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7813 | s32 timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7814 | |
| 7815 | DEBUGFUNC("e1000_disable_pciex_master"); |
| 7816 | |
| 7817 | if (hw->bus_type != e1000_bus_type_pci_express) |
| 7818 | return E1000_SUCCESS; |
| 7819 | |
| 7820 | e1000_set_pci_express_master_disable(hw); |
| 7821 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7822 | while (timeout) { |
| 7823 | if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7824 | break; |
| 7825 | else |
| 7826 | udelay(100); |
| 7827 | timeout--; |
| 7828 | } |
| 7829 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7830 | if (!timeout) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7831 | DEBUGOUT("Master requests are pending.\n"); |
| 7832 | return -E1000_ERR_MASTER_REQUESTS_PENDING; |
| 7833 | } |
| 7834 | |
| 7835 | return E1000_SUCCESS; |
| 7836 | } |
| 7837 | |
| 7838 | /******************************************************************************* |
| 7839 | * |
| 7840 | * Check for EEPROM Auto Read bit done. |
| 7841 | * |
| 7842 | * hw: Struct containing variables accessed by shared code |
| 7843 | * |
| 7844 | * returns: - E1000_ERR_RESET if fail to reset MAC |
| 7845 | * E1000_SUCCESS at any other case. |
| 7846 | * |
| 7847 | ******************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7848 | static s32 e1000_get_auto_rd_done(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7849 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7850 | s32 timeout = AUTO_READ_DONE_TIMEOUT; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7851 | |
| 7852 | DEBUGFUNC("e1000_get_auto_rd_done"); |
| 7853 | |
| 7854 | switch (hw->mac_type) { |
| 7855 | default: |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7856 | msleep(5); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7857 | break; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 7858 | case e1000_82571: |
| 7859 | case e1000_82572: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7860 | case e1000_82573: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 7861 | case e1000_80003es2lan: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 7862 | case e1000_ich8lan: |
| 7863 | while (timeout) { |
| 7864 | if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) |
| 7865 | break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7866 | else msleep(1); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7867 | timeout--; |
| 7868 | } |
| 7869 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7870 | if (!timeout) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7871 | DEBUGOUT("Auto read by HW from EEPROM has not completed.\n"); |
| 7872 | return -E1000_ERR_RESET; |
| 7873 | } |
| 7874 | break; |
| 7875 | } |
| 7876 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 7877 | /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high. |
| 7878 | * Need to wait for PHY configuration completion before accessing NVM |
| 7879 | * and PHY. */ |
| 7880 | if (hw->mac_type == e1000_82573) |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7881 | msleep(25); |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 7882 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7883 | return E1000_SUCCESS; |
| 7884 | } |
| 7885 | |
| 7886 | /*************************************************************************** |
| 7887 | * Checks if the PHY configuration is done |
| 7888 | * |
| 7889 | * hw: Struct containing variables accessed by shared code |
| 7890 | * |
| 7891 | * returns: - E1000_ERR_RESET if fail to reset MAC |
| 7892 | * E1000_SUCCESS at any other case. |
| 7893 | * |
| 7894 | ***************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7895 | static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7896 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7897 | s32 timeout = PHY_CFG_TIMEOUT; |
| 7898 | u32 cfg_mask = E1000_EEPROM_CFG_DONE; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 7899 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7900 | DEBUGFUNC("e1000_get_phy_cfg_done"); |
| 7901 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 7902 | switch (hw->mac_type) { |
| 7903 | default: |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7904 | mdelay(10); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 7905 | break; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 7906 | case e1000_80003es2lan: |
| 7907 | /* Separate *_CFG_DONE_* bit for each port */ |
| 7908 | if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) |
| 7909 | cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1; |
| 7910 | /* Fall Through */ |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 7911 | case e1000_82571: |
| 7912 | case e1000_82572: |
| 7913 | while (timeout) { |
| 7914 | if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask) |
| 7915 | break; |
| 7916 | else |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 7917 | msleep(1); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 7918 | timeout--; |
| 7919 | } |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 7920 | if (!timeout) { |
| 7921 | DEBUGOUT("MNG configuration cycle has not completed.\n"); |
| 7922 | return -E1000_ERR_RESET; |
| 7923 | } |
| 7924 | break; |
| 7925 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7926 | |
| 7927 | return E1000_SUCCESS; |
| 7928 | } |
| 7929 | |
| 7930 | /*************************************************************************** |
| 7931 | * |
| 7932 | * Using the combination of SMBI and SWESMBI semaphore bits when resetting |
| 7933 | * adapter or Eeprom access. |
| 7934 | * |
| 7935 | * hw: Struct containing variables accessed by shared code |
| 7936 | * |
| 7937 | * returns: - E1000_ERR_EEPROM if fail to access EEPROM. |
| 7938 | * E1000_SUCCESS at any other case. |
| 7939 | * |
| 7940 | ***************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7941 | static s32 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7942 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7943 | s32 timeout; |
| 7944 | u32 swsm; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7945 | |
| 7946 | DEBUGFUNC("e1000_get_hw_eeprom_semaphore"); |
| 7947 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7948 | if (!hw->eeprom_semaphore_present) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7949 | return E1000_SUCCESS; |
| 7950 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 7951 | if (hw->mac_type == e1000_80003es2lan) { |
| 7952 | /* Get the SW semaphore. */ |
| 7953 | if (e1000_get_software_semaphore(hw) != E1000_SUCCESS) |
| 7954 | return -E1000_ERR_EEPROM; |
| 7955 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7956 | |
| 7957 | /* Get the FW semaphore. */ |
| 7958 | timeout = hw->eeprom.word_size + 1; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7959 | while (timeout) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7960 | swsm = E1000_READ_REG(hw, SWSM); |
| 7961 | swsm |= E1000_SWSM_SWESMBI; |
| 7962 | E1000_WRITE_REG(hw, SWSM, swsm); |
| 7963 | /* if we managed to set the bit we got the semaphore. */ |
| 7964 | swsm = E1000_READ_REG(hw, SWSM); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7965 | if (swsm & E1000_SWSM_SWESMBI) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7966 | break; |
| 7967 | |
| 7968 | udelay(50); |
| 7969 | timeout--; |
| 7970 | } |
| 7971 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7972 | if (!timeout) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7973 | /* Release semaphores */ |
| 7974 | e1000_put_hw_eeprom_semaphore(hw); |
| 7975 | DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n"); |
| 7976 | return -E1000_ERR_EEPROM; |
| 7977 | } |
| 7978 | |
| 7979 | return E1000_SUCCESS; |
| 7980 | } |
| 7981 | |
| 7982 | /*************************************************************************** |
| 7983 | * This function clears HW semaphore bits. |
| 7984 | * |
| 7985 | * hw: Struct containing variables accessed by shared code |
| 7986 | * |
| 7987 | * returns: - None. |
| 7988 | * |
| 7989 | ***************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 7990 | static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7991 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 7992 | u32 swsm; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7993 | |
| 7994 | DEBUGFUNC("e1000_put_hw_eeprom_semaphore"); |
| 7995 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 7996 | if (!hw->eeprom_semaphore_present) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 7997 | return; |
| 7998 | |
| 7999 | swsm = E1000_READ_REG(hw, SWSM); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8000 | if (hw->mac_type == e1000_80003es2lan) { |
| 8001 | /* Release both semaphores. */ |
| 8002 | swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI); |
| 8003 | } else |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 8004 | swsm &= ~(E1000_SWSM_SWESMBI); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8005 | E1000_WRITE_REG(hw, SWSM, swsm); |
| 8006 | } |
| 8007 | |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8008 | /*************************************************************************** |
| 8009 | * |
| 8010 | * Obtaining software semaphore bit (SMBI) before resetting PHY. |
| 8011 | * |
| 8012 | * hw: Struct containing variables accessed by shared code |
| 8013 | * |
| 8014 | * returns: - E1000_ERR_RESET if fail to obtain semaphore. |
| 8015 | * E1000_SUCCESS at any other case. |
| 8016 | * |
| 8017 | ***************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8018 | static s32 e1000_get_software_semaphore(struct e1000_hw *hw) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8019 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8020 | s32 timeout = hw->eeprom.word_size + 1; |
| 8021 | u32 swsm; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8022 | |
| 8023 | DEBUGFUNC("e1000_get_software_semaphore"); |
| 8024 | |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 8025 | if (hw->mac_type != e1000_80003es2lan) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8026 | return E1000_SUCCESS; |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 8027 | } |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8028 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 8029 | while (timeout) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8030 | swsm = E1000_READ_REG(hw, SWSM); |
| 8031 | /* 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] | 8032 | if (!(swsm & E1000_SWSM_SMBI)) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8033 | break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 8034 | mdelay(1); |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8035 | timeout--; |
| 8036 | } |
| 8037 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 8038 | if (!timeout) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8039 | DEBUGOUT("Driver can't access device - SMBI bit is set.\n"); |
| 8040 | return -E1000_ERR_RESET; |
| 8041 | } |
| 8042 | |
| 8043 | return E1000_SUCCESS; |
| 8044 | } |
| 8045 | |
| 8046 | /*************************************************************************** |
| 8047 | * |
| 8048 | * Release semaphore bit (SMBI). |
| 8049 | * |
| 8050 | * hw: Struct containing variables accessed by shared code |
| 8051 | * |
| 8052 | ***************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8053 | static void e1000_release_software_semaphore(struct e1000_hw *hw) |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8054 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8055 | u32 swsm; |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8056 | |
| 8057 | DEBUGFUNC("e1000_release_software_semaphore"); |
| 8058 | |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 8059 | if (hw->mac_type != e1000_80003es2lan) { |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8060 | return; |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 8061 | } |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8062 | |
| 8063 | swsm = E1000_READ_REG(hw, SWSM); |
| 8064 | /* Release the SW semaphores.*/ |
| 8065 | swsm &= ~E1000_SWSM_SMBI; |
| 8066 | E1000_WRITE_REG(hw, SWSM, swsm); |
| 8067 | } |
| 8068 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8069 | /****************************************************************************** |
| 8070 | * Checks if PHY reset is blocked due to SOL/IDER session, for example. |
| 8071 | * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to |
| 8072 | * the caller to figure out how to deal with it. |
| 8073 | * |
| 8074 | * hw - Struct containing variables accessed by shared code |
| 8075 | * |
| 8076 | * returns: - E1000_BLK_PHY_RESET |
| 8077 | * E1000_SUCCESS |
| 8078 | * |
| 8079 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8080 | s32 e1000_check_phy_reset_block(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8081 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8082 | u32 manc = 0; |
| 8083 | u32 fwsm = 0; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 8084 | |
| 8085 | if (hw->mac_type == e1000_ich8lan) { |
| 8086 | fwsm = E1000_READ_REG(hw, FWSM); |
| 8087 | return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS |
| 8088 | : E1000_BLK_PHY_RESET; |
| 8089 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 8090 | |
| 8091 | if (hw->mac_type > e1000_82547_rev_2) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8092 | manc = E1000_READ_REG(hw, MANC); |
| 8093 | return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ? |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 8094 | E1000_BLK_PHY_RESET : E1000_SUCCESS; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8095 | } |
| 8096 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8097 | static u8 e1000_arc_subsystem_valid(struct e1000_hw *hw) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8098 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8099 | u32 fwsm; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8100 | |
| 8101 | /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC |
| 8102 | * may not be provided a DMA clock when no manageability features are |
| 8103 | * enabled. We do not want to perform any reads/writes to these registers |
| 8104 | * if this is the case. We read FWSM to determine the manageability mode. |
| 8105 | */ |
| 8106 | switch (hw->mac_type) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 8107 | case e1000_82571: |
| 8108 | case e1000_82572: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8109 | case e1000_82573: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 8110 | case e1000_80003es2lan: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8111 | fwsm = E1000_READ_REG(hw, FWSM); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 8112 | if ((fwsm & E1000_FWSM_MODE_MASK) != 0) |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 8113 | return true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8114 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 8115 | case e1000_ich8lan: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 8116 | return true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8117 | default: |
| 8118 | break; |
| 8119 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 8120 | return false; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 8121 | } |
| 8122 | |
| 8123 | |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8124 | /****************************************************************************** |
| 8125 | * Configure PCI-Ex no-snoop |
| 8126 | * |
| 8127 | * hw - Struct containing variables accessed by shared code. |
| 8128 | * no_snoop - Bitmap of no-snoop events. |
| 8129 | * |
| 8130 | * returns: E1000_SUCCESS |
| 8131 | * |
| 8132 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8133 | static s32 e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, u32 no_snoop) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8134 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8135 | u32 gcr_reg = 0; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8136 | |
| 8137 | DEBUGFUNC("e1000_set_pci_ex_no_snoop"); |
| 8138 | |
| 8139 | if (hw->bus_type == e1000_bus_type_unknown) |
| 8140 | e1000_get_bus_info(hw); |
| 8141 | |
| 8142 | if (hw->bus_type != e1000_bus_type_pci_express) |
| 8143 | return E1000_SUCCESS; |
| 8144 | |
| 8145 | if (no_snoop) { |
| 8146 | gcr_reg = E1000_READ_REG(hw, GCR); |
| 8147 | gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL); |
| 8148 | gcr_reg |= no_snoop; |
| 8149 | E1000_WRITE_REG(hw, GCR, gcr_reg); |
| 8150 | } |
| 8151 | if (hw->mac_type == e1000_ich8lan) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8152 | u32 ctrl_ext; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8153 | |
| 8154 | E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL); |
| 8155 | |
| 8156 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
| 8157 | ctrl_ext |= E1000_CTRL_EXT_RO_DIS; |
| 8158 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 8159 | } |
| 8160 | |
| 8161 | return E1000_SUCCESS; |
| 8162 | } |
| 8163 | |
| 8164 | /*************************************************************************** |
| 8165 | * |
| 8166 | * Get software semaphore FLAG bit (SWFLAG). |
| 8167 | * SWFLAG is used to synchronize the access to all shared resource between |
| 8168 | * SW, FW and HW. |
| 8169 | * |
| 8170 | * hw: Struct containing variables accessed by shared code |
| 8171 | * |
| 8172 | ***************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8173 | static s32 e1000_get_software_flag(struct e1000_hw *hw) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8174 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8175 | s32 timeout = PHY_CFG_TIMEOUT; |
| 8176 | u32 extcnf_ctrl; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8177 | |
| 8178 | DEBUGFUNC("e1000_get_software_flag"); |
| 8179 | |
| 8180 | if (hw->mac_type == e1000_ich8lan) { |
| 8181 | while (timeout) { |
| 8182 | extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL); |
| 8183 | extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG; |
| 8184 | E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl); |
| 8185 | |
| 8186 | extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL); |
| 8187 | if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) |
| 8188 | break; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 8189 | mdelay(1); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8190 | timeout--; |
| 8191 | } |
| 8192 | |
| 8193 | if (!timeout) { |
| 8194 | DEBUGOUT("FW or HW locks the resource too long.\n"); |
| 8195 | return -E1000_ERR_CONFIG; |
| 8196 | } |
| 8197 | } |
| 8198 | |
| 8199 | return E1000_SUCCESS; |
| 8200 | } |
| 8201 | |
| 8202 | /*************************************************************************** |
| 8203 | * |
| 8204 | * Release software semaphore FLAG bit (SWFLAG). |
| 8205 | * SWFLAG is used to synchronize the access to all shared resource between |
| 8206 | * SW, FW and HW. |
| 8207 | * |
| 8208 | * hw: Struct containing variables accessed by shared code |
| 8209 | * |
| 8210 | ***************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8211 | static void e1000_release_software_flag(struct e1000_hw *hw) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8212 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8213 | u32 extcnf_ctrl; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8214 | |
| 8215 | DEBUGFUNC("e1000_release_software_flag"); |
| 8216 | |
| 8217 | if (hw->mac_type == e1000_ich8lan) { |
| 8218 | extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL); |
| 8219 | extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG; |
| 8220 | E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl); |
| 8221 | } |
| 8222 | |
| 8223 | return; |
| 8224 | } |
| 8225 | |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8226 | /****************************************************************************** |
| 8227 | * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access |
| 8228 | * register. |
| 8229 | * |
| 8230 | * hw - Struct containing variables accessed by shared code |
| 8231 | * offset - offset of word in the EEPROM to read |
| 8232 | * data - word read from the EEPROM |
| 8233 | * words - number of words to read |
| 8234 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8235 | static s32 e1000_read_eeprom_ich8(struct e1000_hw *hw, u16 offset, u16 words, |
| 8236 | u16 *data) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8237 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8238 | s32 error = E1000_SUCCESS; |
| 8239 | u32 flash_bank = 0; |
| 8240 | u32 act_offset = 0; |
| 8241 | u32 bank_offset = 0; |
| 8242 | u16 word = 0; |
| 8243 | u16 i = 0; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8244 | |
| 8245 | /* We need to know which is the valid flash bank. In the event |
| 8246 | * that we didn't allocate eeprom_shadow_ram, we may not be |
| 8247 | * managing flash_bank. So it cannot be trusted and needs |
| 8248 | * to be updated with each read. |
| 8249 | */ |
| 8250 | /* Value of bit 22 corresponds to the flash bank we're on. */ |
| 8251 | flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0; |
| 8252 | |
| 8253 | /* Adjust offset appropriately if we're on bank 1 - adjust for word size */ |
| 8254 | bank_offset = flash_bank * (hw->flash_bank_size * 2); |
| 8255 | |
| 8256 | error = e1000_get_software_flag(hw); |
| 8257 | if (error != E1000_SUCCESS) |
| 8258 | return error; |
| 8259 | |
| 8260 | for (i = 0; i < words; i++) { |
| 8261 | if (hw->eeprom_shadow_ram != NULL && |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 8262 | hw->eeprom_shadow_ram[offset+i].modified) { |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8263 | data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word; |
| 8264 | } else { |
| 8265 | /* The NVM part needs a byte offset, hence * 2 */ |
| 8266 | act_offset = bank_offset + ((offset + i) * 2); |
| 8267 | error = e1000_read_ich8_word(hw, act_offset, &word); |
| 8268 | if (error != E1000_SUCCESS) |
| 8269 | break; |
| 8270 | data[i] = word; |
| 8271 | } |
| 8272 | } |
| 8273 | |
| 8274 | e1000_release_software_flag(hw); |
| 8275 | |
| 8276 | return error; |
| 8277 | } |
| 8278 | |
| 8279 | /****************************************************************************** |
| 8280 | * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access |
| 8281 | * register. Actually, writes are written to the shadow ram cache in the hw |
| 8282 | * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to |
| 8283 | * the NVM, which occurs when the NVM checksum is updated. |
| 8284 | * |
| 8285 | * hw - Struct containing variables accessed by shared code |
| 8286 | * offset - offset of word in the EEPROM to write |
| 8287 | * words - number of words to write |
| 8288 | * data - words to write to the EEPROM |
| 8289 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8290 | static s32 e1000_write_eeprom_ich8(struct e1000_hw *hw, u16 offset, u16 words, |
| 8291 | u16 *data) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8292 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8293 | u32 i = 0; |
| 8294 | s32 error = E1000_SUCCESS; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8295 | |
| 8296 | error = e1000_get_software_flag(hw); |
| 8297 | if (error != E1000_SUCCESS) |
| 8298 | return error; |
| 8299 | |
| 8300 | /* A driver can write to the NVM only if it has eeprom_shadow_ram |
| 8301 | * allocated. Subsequent reads to the modified words are read from |
| 8302 | * this cached structure as well. Writes will only go into this |
| 8303 | * cached structure unless it's followed by a call to |
| 8304 | * e1000_update_eeprom_checksum() where it will commit the changes |
| 8305 | * and clear the "modified" field. |
| 8306 | */ |
| 8307 | if (hw->eeprom_shadow_ram != NULL) { |
| 8308 | for (i = 0; i < words; i++) { |
| 8309 | if ((offset + i) < E1000_SHADOW_RAM_WORDS) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 8310 | hw->eeprom_shadow_ram[offset+i].modified = true; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8311 | hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i]; |
| 8312 | } else { |
| 8313 | error = -E1000_ERR_EEPROM; |
| 8314 | break; |
| 8315 | } |
| 8316 | } |
| 8317 | } else { |
| 8318 | /* Drivers have the option to not allocate eeprom_shadow_ram as long |
| 8319 | * as they don't perform any NVM writes. An attempt in doing so |
| 8320 | * will result in this error. |
| 8321 | */ |
| 8322 | error = -E1000_ERR_EEPROM; |
| 8323 | } |
| 8324 | |
| 8325 | e1000_release_software_flag(hw); |
| 8326 | |
| 8327 | return error; |
| 8328 | } |
| 8329 | |
| 8330 | /****************************************************************************** |
| 8331 | * This function does initial flash setup so that a new read/write/erase cycle |
| 8332 | * can be started. |
| 8333 | * |
| 8334 | * hw - The pointer to the hw structure |
| 8335 | ****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8336 | static s32 e1000_ich8_cycle_init(struct e1000_hw *hw) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8337 | { |
| 8338 | union ich8_hws_flash_status hsfsts; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8339 | s32 error = E1000_ERR_EEPROM; |
| 8340 | s32 i = 0; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8341 | |
| 8342 | DEBUGFUNC("e1000_ich8_cycle_init"); |
| 8343 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8344 | hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8345 | |
| 8346 | /* May be check the Flash Des Valid bit in Hw status */ |
| 8347 | if (hsfsts.hsf_status.fldesvalid == 0) { |
| 8348 | DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used."); |
| 8349 | return error; |
| 8350 | } |
| 8351 | |
| 8352 | /* Clear FCERR in Hw status by writing 1 */ |
| 8353 | /* Clear DAEL in Hw status by writing a 1 */ |
| 8354 | hsfsts.hsf_status.flcerr = 1; |
| 8355 | hsfsts.hsf_status.dael = 1; |
| 8356 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8357 | E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8358 | |
| 8359 | /* Either we should have a hardware SPI cycle in progress bit to check |
| 8360 | * against, in order to start a new cycle or FDONE bit should be changed |
| 8361 | * in the hardware so that it is 1 after harware reset, which can then be |
| 8362 | * used as an indication whether a cycle is in progress or has been |
| 8363 | * completed .. we should also have some software semaphore mechanism to |
| 8364 | * guard FDONE or the cycle in progress bit so that two threads access to |
| 8365 | * those bits can be sequentiallized or a way so that 2 threads dont |
| 8366 | * start the cycle at the same time */ |
| 8367 | |
| 8368 | if (hsfsts.hsf_status.flcinprog == 0) { |
| 8369 | /* There is no cycle running at present, so we can start a cycle */ |
| 8370 | /* Begin by setting Flash Cycle Done. */ |
| 8371 | hsfsts.hsf_status.flcdone = 1; |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8372 | E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8373 | error = E1000_SUCCESS; |
| 8374 | } else { |
| 8375 | /* otherwise poll for sometime so the current cycle has a chance |
| 8376 | * to end before giving up. */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8377 | for (i = 0; i < ICH_FLASH_COMMAND_TIMEOUT; i++) { |
| 8378 | hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8379 | if (hsfsts.hsf_status.flcinprog == 0) { |
| 8380 | error = E1000_SUCCESS; |
| 8381 | break; |
| 8382 | } |
| 8383 | udelay(1); |
| 8384 | } |
| 8385 | if (error == E1000_SUCCESS) { |
| 8386 | /* Successful in waiting for previous cycle to timeout, |
| 8387 | * now set the Flash Cycle Done. */ |
| 8388 | hsfsts.hsf_status.flcdone = 1; |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8389 | E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8390 | } else { |
| 8391 | DEBUGOUT("Flash controller busy, cannot get access"); |
| 8392 | } |
| 8393 | } |
| 8394 | return error; |
| 8395 | } |
| 8396 | |
| 8397 | /****************************************************************************** |
| 8398 | * This function starts a flash cycle and waits for its completion |
| 8399 | * |
| 8400 | * hw - The pointer to the hw structure |
| 8401 | ****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8402 | static s32 e1000_ich8_flash_cycle(struct e1000_hw *hw, u32 timeout) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8403 | { |
| 8404 | union ich8_hws_flash_ctrl hsflctl; |
| 8405 | union ich8_hws_flash_status hsfsts; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8406 | s32 error = E1000_ERR_EEPROM; |
| 8407 | u32 i = 0; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8408 | |
| 8409 | /* 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] | 8410 | hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8411 | hsflctl.hsf_ctrl.flcgo = 1; |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8412 | E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8413 | |
| 8414 | /* wait till FDONE bit is set to 1 */ |
| 8415 | do { |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8416 | hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8417 | if (hsfsts.hsf_status.flcdone == 1) |
| 8418 | break; |
| 8419 | udelay(1); |
| 8420 | i++; |
| 8421 | } while (i < timeout); |
| 8422 | if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) { |
| 8423 | error = E1000_SUCCESS; |
| 8424 | } |
| 8425 | return error; |
| 8426 | } |
| 8427 | |
| 8428 | /****************************************************************************** |
| 8429 | * Reads a byte or word from the NVM using the ICH8 flash access registers. |
| 8430 | * |
| 8431 | * hw - The pointer to the hw structure |
| 8432 | * index - The index of the byte or word to read. |
| 8433 | * size - Size of data to read, 1=byte 2=word |
| 8434 | * data - Pointer to the word to store the value read. |
| 8435 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8436 | static s32 e1000_read_ich8_data(struct e1000_hw *hw, u32 index, u32 size, |
| 8437 | u16 *data) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8438 | { |
| 8439 | union ich8_hws_flash_status hsfsts; |
| 8440 | union ich8_hws_flash_ctrl hsflctl; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8441 | u32 flash_linear_address; |
| 8442 | u32 flash_data = 0; |
| 8443 | s32 error = -E1000_ERR_EEPROM; |
| 8444 | s32 count = 0; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8445 | |
| 8446 | DEBUGFUNC("e1000_read_ich8_data"); |
| 8447 | |
Stephen Hemminger | abec42a | 2007-10-29 10:46:19 -0700 | [diff] [blame] | 8448 | if (size < 1 || size > 2 || data == NULL || |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8449 | index > ICH_FLASH_LINEAR_ADDR_MASK) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8450 | return error; |
| 8451 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8452 | flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) + |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8453 | hw->flash_base_addr; |
| 8454 | |
| 8455 | do { |
| 8456 | udelay(1); |
| 8457 | /* Steps */ |
| 8458 | error = e1000_ich8_cycle_init(hw); |
| 8459 | if (error != E1000_SUCCESS) |
| 8460 | break; |
| 8461 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8462 | hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8463 | /* 0b/1b corresponds to 1 or 2 byte size, respectively. */ |
| 8464 | hsflctl.hsf_ctrl.fldbcount = size - 1; |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8465 | hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ; |
| 8466 | E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8467 | |
| 8468 | /* Write the last 24 bits of index into Flash Linear address field in |
| 8469 | * Flash Address */ |
| 8470 | /* TODO: TBD maybe check the index against the size of flash */ |
| 8471 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8472 | E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8473 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8474 | error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8475 | |
| 8476 | /* Check if FCERR is set to 1, if set to 1, clear it and try the whole |
| 8477 | * sequence a few more times, else read in (shift in) the Flash Data0, |
| 8478 | * the order is least significant byte first msb to lsb */ |
| 8479 | if (error == E1000_SUCCESS) { |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8480 | flash_data = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8481 | if (size == 1) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8482 | *data = (u8)(flash_data & 0x000000FF); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8483 | } else if (size == 2) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8484 | *data = (u16)(flash_data & 0x0000FFFF); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8485 | } |
| 8486 | break; |
| 8487 | } else { |
| 8488 | /* If we've gotten here, then things are probably completely hosed, |
| 8489 | * 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] | 8490 | * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times. |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8491 | */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8492 | hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8493 | if (hsfsts.hsf_status.flcerr == 1) { |
| 8494 | /* Repeat for some time before giving up. */ |
| 8495 | continue; |
| 8496 | } else if (hsfsts.hsf_status.flcdone == 0) { |
| 8497 | DEBUGOUT("Timeout error - flash cycle did not complete."); |
| 8498 | break; |
| 8499 | } |
| 8500 | } |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8501 | } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8502 | |
| 8503 | return error; |
| 8504 | } |
| 8505 | |
| 8506 | /****************************************************************************** |
| 8507 | * Writes One /two bytes to the NVM using the ICH8 flash access registers. |
| 8508 | * |
| 8509 | * hw - The pointer to the hw structure |
| 8510 | * index - The index of the byte/word to read. |
| 8511 | * size - Size of data to read, 1=byte 2=word |
| 8512 | * data - The byte(s) to write to the NVM. |
| 8513 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8514 | static s32 e1000_write_ich8_data(struct e1000_hw *hw, u32 index, u32 size, |
| 8515 | u16 data) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8516 | { |
| 8517 | union ich8_hws_flash_status hsfsts; |
| 8518 | union ich8_hws_flash_ctrl hsflctl; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8519 | u32 flash_linear_address; |
| 8520 | u32 flash_data = 0; |
| 8521 | s32 error = -E1000_ERR_EEPROM; |
| 8522 | s32 count = 0; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8523 | |
| 8524 | DEBUGFUNC("e1000_write_ich8_data"); |
| 8525 | |
| 8526 | if (size < 1 || size > 2 || data > size * 0xff || |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8527 | index > ICH_FLASH_LINEAR_ADDR_MASK) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8528 | return error; |
| 8529 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8530 | flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) + |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8531 | hw->flash_base_addr; |
| 8532 | |
| 8533 | do { |
| 8534 | udelay(1); |
| 8535 | /* Steps */ |
| 8536 | error = e1000_ich8_cycle_init(hw); |
| 8537 | if (error != E1000_SUCCESS) |
| 8538 | break; |
| 8539 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8540 | hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8541 | /* 0b/1b corresponds to 1 or 2 byte size, respectively. */ |
| 8542 | hsflctl.hsf_ctrl.fldbcount = size -1; |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8543 | hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE; |
| 8544 | E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8545 | |
| 8546 | /* Write the last 24 bits of index into Flash Linear address field in |
| 8547 | * Flash Address */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8548 | E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8549 | |
| 8550 | if (size == 1) |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8551 | flash_data = (u32)data & 0x00FF; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8552 | else |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8553 | flash_data = (u32)data; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8554 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8555 | E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8556 | |
| 8557 | /* check if FCERR is set to 1 , if set to 1, clear it and try the whole |
| 8558 | * sequence a few more times else done */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8559 | error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8560 | if (error == E1000_SUCCESS) { |
| 8561 | break; |
| 8562 | } else { |
| 8563 | /* If we're here, then things are most likely completely hosed, |
| 8564 | * 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] | 8565 | * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times. |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8566 | */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8567 | hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8568 | if (hsfsts.hsf_status.flcerr == 1) { |
| 8569 | /* Repeat for some time before giving up. */ |
| 8570 | continue; |
| 8571 | } else if (hsfsts.hsf_status.flcdone == 0) { |
| 8572 | DEBUGOUT("Timeout error - flash cycle did not complete."); |
| 8573 | break; |
| 8574 | } |
| 8575 | } |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8576 | } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8577 | |
| 8578 | return error; |
| 8579 | } |
| 8580 | |
| 8581 | /****************************************************************************** |
| 8582 | * Reads a single byte from the NVM using the ICH8 flash access registers. |
| 8583 | * |
| 8584 | * hw - pointer to e1000_hw structure |
| 8585 | * index - The index of the byte to read. |
| 8586 | * data - Pointer to a byte to store the value read. |
| 8587 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8588 | static s32 e1000_read_ich8_byte(struct e1000_hw *hw, u32 index, u8 *data) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8589 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8590 | s32 status = E1000_SUCCESS; |
| 8591 | u16 word = 0; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8592 | |
| 8593 | status = e1000_read_ich8_data(hw, index, 1, &word); |
| 8594 | if (status == E1000_SUCCESS) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8595 | *data = (u8)word; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8596 | } |
| 8597 | |
| 8598 | return status; |
| 8599 | } |
| 8600 | |
| 8601 | /****************************************************************************** |
| 8602 | * Writes a single byte to the NVM using the ICH8 flash access registers. |
| 8603 | * Performs verification by reading back the value and then going through |
| 8604 | * a retry algorithm before giving up. |
| 8605 | * |
| 8606 | * hw - pointer to e1000_hw structure |
| 8607 | * index - The index of the byte to write. |
| 8608 | * byte - The byte to write to the NVM. |
| 8609 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8610 | static s32 e1000_verify_write_ich8_byte(struct e1000_hw *hw, u32 index, u8 byte) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8611 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8612 | s32 error = E1000_SUCCESS; |
| 8613 | s32 program_retries = 0; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8614 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8615 | DEBUGOUT2("Byte := %2.2X Offset := %d\n", byte, index); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8616 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8617 | error = e1000_write_ich8_byte(hw, index, byte); |
| 8618 | |
| 8619 | if (error != E1000_SUCCESS) { |
| 8620 | for (program_retries = 0; program_retries < 100; program_retries++) { |
| 8621 | DEBUGOUT2("Retrying \t Byte := %2.2X Offset := %d\n", byte, index); |
| 8622 | error = e1000_write_ich8_byte(hw, index, byte); |
| 8623 | udelay(100); |
| 8624 | if (error == E1000_SUCCESS) |
| 8625 | break; |
| 8626 | } |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8627 | } |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8628 | |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8629 | if (program_retries == 100) |
| 8630 | error = E1000_ERR_EEPROM; |
| 8631 | |
| 8632 | return error; |
| 8633 | } |
| 8634 | |
| 8635 | /****************************************************************************** |
| 8636 | * Writes a single byte to the NVM using the ICH8 flash access registers. |
| 8637 | * |
| 8638 | * hw - pointer to e1000_hw structure |
| 8639 | * index - The index of the byte to read. |
| 8640 | * data - The byte to write to the NVM. |
| 8641 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8642 | static s32 e1000_write_ich8_byte(struct e1000_hw *hw, u32 index, u8 data) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8643 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8644 | s32 status = E1000_SUCCESS; |
| 8645 | u16 word = (u16)data; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8646 | |
| 8647 | status = e1000_write_ich8_data(hw, index, 1, word); |
| 8648 | |
| 8649 | return status; |
| 8650 | } |
| 8651 | |
| 8652 | /****************************************************************************** |
| 8653 | * Reads a word from the NVM using the ICH8 flash access registers. |
| 8654 | * |
| 8655 | * hw - pointer to e1000_hw structure |
| 8656 | * index - The starting byte index of the word to read. |
| 8657 | * data - Pointer to a word to store the value read. |
| 8658 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8659 | static s32 e1000_read_ich8_word(struct e1000_hw *hw, u32 index, u16 *data) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8660 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8661 | s32 status = E1000_SUCCESS; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8662 | status = e1000_read_ich8_data(hw, index, 2, data); |
| 8663 | return status; |
| 8664 | } |
| 8665 | |
| 8666 | /****************************************************************************** |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8667 | * Erases the bank specified. Each bank may be a 4, 8 or 64k block. Banks are 0 |
| 8668 | * based. |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8669 | * |
| 8670 | * hw - pointer to e1000_hw structure |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8671 | * bank - 0 for first bank, 1 for second bank |
| 8672 | * |
| 8673 | * Note that this function may actually erase as much as 8 or 64 KBytes. The |
| 8674 | * amount of NVM used in each bank is a *minimum* of 4 KBytes, but in fact the |
| 8675 | * bank size may be 4, 8 or 64 KBytes |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8676 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8677 | static s32 e1000_erase_ich8_4k_segment(struct e1000_hw *hw, u32 bank) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8678 | { |
| 8679 | union ich8_hws_flash_status hsfsts; |
| 8680 | union ich8_hws_flash_ctrl hsflctl; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8681 | u32 flash_linear_address; |
| 8682 | s32 count = 0; |
| 8683 | s32 error = E1000_ERR_EEPROM; |
| 8684 | s32 iteration; |
| 8685 | s32 sub_sector_size = 0; |
| 8686 | s32 bank_size; |
| 8687 | s32 j = 0; |
| 8688 | s32 error_flag = 0; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8689 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8690 | hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8691 | |
| 8692 | /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */ |
| 8693 | /* 00: The Hw sector is 256 bytes, hence we need to erase 16 |
| 8694 | * consecutive sectors. The start index for the nth Hw sector can be |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8695 | * calculated as bank * 4096 + n * 256 |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8696 | * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector. |
| 8697 | * The start index for the nth Hw sector can be calculated |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8698 | * as bank * 4096 |
| 8699 | * 10: The HW sector is 8K bytes |
| 8700 | * 11: The Hw sector size is 64K bytes */ |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8701 | if (hsfsts.hsf_status.berasesz == 0x0) { |
| 8702 | /* Hw sector size 256 */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8703 | sub_sector_size = ICH_FLASH_SEG_SIZE_256; |
| 8704 | bank_size = ICH_FLASH_SECTOR_SIZE; |
| 8705 | iteration = ICH_FLASH_SECTOR_SIZE / ICH_FLASH_SEG_SIZE_256; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8706 | } else if (hsfsts.hsf_status.berasesz == 0x1) { |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8707 | bank_size = ICH_FLASH_SEG_SIZE_4K; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8708 | iteration = 1; |
| 8709 | } else if (hsfsts.hsf_status.berasesz == 0x3) { |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8710 | bank_size = ICH_FLASH_SEG_SIZE_64K; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8711 | iteration = 1; |
| 8712 | } else { |
| 8713 | return error; |
| 8714 | } |
| 8715 | |
| 8716 | for (j = 0; j < iteration ; j++) { |
| 8717 | do { |
| 8718 | count++; |
| 8719 | /* Steps */ |
| 8720 | error = e1000_ich8_cycle_init(hw); |
| 8721 | if (error != E1000_SUCCESS) { |
| 8722 | error_flag = 1; |
| 8723 | break; |
| 8724 | } |
| 8725 | |
| 8726 | /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash |
| 8727 | * Control */ |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8728 | hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL); |
| 8729 | hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE; |
| 8730 | E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8731 | |
| 8732 | /* Write the last 24 bits of an index within the block into Flash |
| 8733 | * Linear address field in Flash Address. This probably needs to |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8734 | * be calculated here based off the on-chip erase sector size and |
| 8735 | * the software bank size (4, 8 or 64 KBytes) */ |
| 8736 | flash_linear_address = bank * bank_size + j * sub_sector_size; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8737 | flash_linear_address += hw->flash_base_addr; |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8738 | flash_linear_address &= ICH_FLASH_LINEAR_ADDR_MASK; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8739 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8740 | E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8741 | |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8742 | error = e1000_ich8_flash_cycle(hw, ICH_FLASH_ERASE_TIMEOUT); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8743 | /* Check if FCERR is set to 1. If 1, clear it and try the whole |
| 8744 | * sequence a few more times else Done */ |
| 8745 | if (error == E1000_SUCCESS) { |
| 8746 | break; |
| 8747 | } else { |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8748 | hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8749 | if (hsfsts.hsf_status.flcerr == 1) { |
| 8750 | /* repeat for some time before giving up */ |
| 8751 | continue; |
| 8752 | } else if (hsfsts.hsf_status.flcdone == 0) { |
| 8753 | error_flag = 1; |
| 8754 | break; |
| 8755 | } |
| 8756 | } |
Jeff Kirsher | 2df7d59 | 2006-11-01 08:48:02 -0800 | [diff] [blame] | 8757 | } while ((count < ICH_FLASH_CYCLE_REPEAT_COUNT) && !error_flag); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8758 | if (error_flag == 1) |
| 8759 | break; |
| 8760 | } |
| 8761 | if (error_flag != 1) |
| 8762 | error = E1000_SUCCESS; |
| 8763 | return error; |
| 8764 | } |
| 8765 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8766 | static s32 e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw, |
| 8767 | u32 cnf_base_addr, |
| 8768 | u32 cnf_size) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8769 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8770 | u32 ret_val = E1000_SUCCESS; |
| 8771 | u16 word_addr, reg_data, reg_addr; |
| 8772 | u16 i; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8773 | |
| 8774 | /* cnf_base_addr is in DWORD */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8775 | word_addr = (u16)(cnf_base_addr << 1); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8776 | |
| 8777 | /* cnf_size is returned in size of dwords */ |
| 8778 | for (i = 0; i < cnf_size; i++) { |
| 8779 | ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, ®_data); |
| 8780 | if (ret_val) |
| 8781 | return ret_val; |
| 8782 | |
| 8783 | ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, ®_addr); |
| 8784 | if (ret_val) |
| 8785 | return ret_val; |
| 8786 | |
| 8787 | ret_val = e1000_get_software_flag(hw); |
| 8788 | if (ret_val != E1000_SUCCESS) |
| 8789 | return ret_val; |
| 8790 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8791 | ret_val = e1000_write_phy_reg_ex(hw, (u32)reg_addr, reg_data); |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8792 | |
| 8793 | e1000_release_software_flag(hw); |
| 8794 | } |
| 8795 | |
| 8796 | return ret_val; |
| 8797 | } |
| 8798 | |
| 8799 | |
Jeff Kirsher | 2a88c17 | 2006-09-27 12:54:05 -0700 | [diff] [blame] | 8800 | /****************************************************************************** |
| 8801 | * This function initializes the PHY from the NVM on ICH8 platforms. This |
| 8802 | * is needed due to an issue where the NVM configuration is not properly |
| 8803 | * autoloaded after power transitions. Therefore, after each PHY reset, we |
| 8804 | * will load the configuration data out of the NVM manually. |
| 8805 | * |
| 8806 | * hw: Struct containing variables accessed by shared code |
| 8807 | *****************************************************************************/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame^] | 8808 | static s32 e1000_init_lcd_from_nvm(struct e1000_hw *hw) |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8809 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 8810 | u32 reg_data, cnf_base_addr, cnf_size, ret_val, loop; |
Auke Kok | d37ea5d | 2006-06-27 09:08:17 -0700 | [diff] [blame] | 8811 | |
| 8812 | if (hw->phy_type != e1000_phy_igp_3) |
| 8813 | return E1000_SUCCESS; |
| 8814 | |
| 8815 | /* Check if SW needs configure the PHY */ |
| 8816 | reg_data = E1000_READ_REG(hw, FEXTNVM); |
| 8817 | if (!(reg_data & FEXTNVM_SW_CONFIG)) |
| 8818 | return E1000_SUCCESS; |
| 8819 | |
| 8820 | /* Wait for basic configuration completes before proceeding*/ |
| 8821 | loop = 0; |
| 8822 | do { |
| 8823 | reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE; |
| 8824 | udelay(100); |
| 8825 | loop++; |
| 8826 | } while ((!reg_data) && (loop < 50)); |
| 8827 | |
| 8828 | /* Clear the Init Done bit for the next init event */ |
| 8829 | reg_data = E1000_READ_REG(hw, STATUS); |
| 8830 | reg_data &= ~E1000_STATUS_LAN_INIT_DONE; |
| 8831 | E1000_WRITE_REG(hw, STATUS, reg_data); |
| 8832 | |
| 8833 | /* Make sure HW does not configure LCD from PHY extended configuration |
| 8834 | before SW configuration */ |
| 8835 | reg_data = E1000_READ_REG(hw, EXTCNF_CTRL); |
| 8836 | if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) { |
| 8837 | reg_data = E1000_READ_REG(hw, EXTCNF_SIZE); |
| 8838 | cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH; |
| 8839 | cnf_size >>= 16; |
| 8840 | if (cnf_size) { |
| 8841 | reg_data = E1000_READ_REG(hw, EXTCNF_CTRL); |
| 8842 | cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER; |
| 8843 | /* cnf_base_addr is in DWORD */ |
| 8844 | cnf_base_addr >>= 16; |
| 8845 | |
| 8846 | /* Configure LCD from extended configuration region. */ |
| 8847 | ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr, |
| 8848 | cnf_size); |
| 8849 | if (ret_val) |
| 8850 | return ret_val; |
| 8851 | } |
| 8852 | } |
| 8853 | |
| 8854 | return E1000_SUCCESS; |
| 8855 | } |
| 8856 | |