blob: 7c6888c58c21d2e6e6033a9b6219caf3a6a8f6b6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 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 Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 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 Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 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 Kok8fc897b2006-08-28 14:56:16 -070033
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "e1000_hw.h"
35
Nicholas Nunley35574762006-09-27 12:53:34 -070036static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
37static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
38static int32_t e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data);
39static int32_t e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data);
40static int32_t e1000_get_software_semaphore(struct e1000_hw *hw);
41static void e1000_release_software_semaphore(struct e1000_hw *hw);
42
43static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
44static int32_t e1000_check_downshift(struct e1000_hw *hw);
45static int32_t e1000_check_polarity(struct e1000_hw *hw, e1000_rev_polarity *polarity);
46static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
47static void e1000_clear_vfta(struct e1000_hw *hw);
48static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
49static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw, boolean_t link_up);
50static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
51static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
52static int32_t e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank);
53static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
54static int32_t e1000_get_cable_length(struct e1000_hw *hw, uint16_t *min_length, uint16_t *max_length);
55static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
56static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
57static int32_t e1000_get_software_flag(struct e1000_hw *hw);
58static int32_t e1000_ich8_cycle_init(struct e1000_hw *hw);
59static int32_t e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout);
60static int32_t e1000_id_led_init(struct e1000_hw *hw);
61static int32_t e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw, uint32_t cnf_base_addr, uint32_t cnf_size);
62static int32_t e1000_init_lcd_from_nvm(struct e1000_hw *hw);
63static void e1000_init_rx_addrs(struct e1000_hw *hw);
Jeff Kirsher09ae3e82006-09-27 12:53:51 -070064static void e1000_initialize_hardware_bits(struct e1000_hw *hw);
Nicholas Nunley35574762006-09-27 12:53:34 -070065static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
66static int32_t e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw);
67static int32_t e1000_mng_enable_host_if(struct e1000_hw *hw);
68static int32_t e1000_mng_host_if_write(struct e1000_hw *hw, uint8_t *buffer, uint16_t length, uint16_t offset, uint8_t *sum);
69static int32_t e1000_mng_write_cmd_header(struct e1000_hw* hw, struct e1000_host_mng_command_header* hdr);
70static int32_t e1000_mng_write_commit(struct e1000_hw *hw);
71static int32_t e1000_phy_ife_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
72static int32_t e1000_phy_igp_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
73static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
74static int32_t e1000_write_eeprom_eewr(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
75static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
76static int32_t e1000_phy_m88_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info);
77static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
78static int32_t e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t *data);
79static int32_t e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
80static int32_t e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte);
81static int32_t e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data);
82static int32_t e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t *data);
83static int32_t e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size, uint16_t data);
84static int32_t e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
85static int32_t e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words, uint16_t *data);
86static void e1000_release_software_flag(struct e1000_hw *hw);
87static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
88static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
89static int32_t e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop);
90static void e1000_set_pci_express_master_disable(struct e1000_hw *hw);
91static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
92static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset, uint32_t value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093static int32_t e1000_set_phy_type(struct e1000_hw *hw);
94static void e1000_phy_init_script(struct e1000_hw *hw);
95static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
96static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
97static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
98static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
99static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
100static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
101static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
102static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
103 uint16_t count);
104static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
105static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
106static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
107 uint16_t words, uint16_t *data);
108static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
109 uint16_t offset, uint16_t words,
110 uint16_t *data);
111static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
112static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
113static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
114static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
115 uint16_t count);
116static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
117 uint16_t phy_data);
118static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
119 uint16_t *phy_data);
120static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
121static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
122static void e1000_release_eeprom(struct e1000_hw *hw);
123static void e1000_standby_eeprom(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
125static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
126static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700127static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
128static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
Auke Kokcd94dd02006-06-27 09:08:22 -0700129static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw,
130 uint16_t duplex);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800131static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/* IGP cable length table */
134static const
135uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
136 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
137 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
138 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
139 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
140 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
141 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
142 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
143 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
144
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700145static const
146uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400147 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
148 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
149 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
150 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
151 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
152 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
153 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
154 104, 109, 114, 118, 121, 124};
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156/******************************************************************************
157 * Set the phy type member in the hw struct.
158 *
159 * hw - Struct containing variables accessed by shared code
160 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -0700161static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162e1000_set_phy_type(struct e1000_hw *hw)
163{
164 DEBUGFUNC("e1000_set_phy_type");
165
Auke Kok8fc897b2006-08-28 14:56:16 -0700166 if (hw->mac_type == e1000_undefined)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700167 return -E1000_ERR_PHY_TYPE;
168
Auke Kok8fc897b2006-08-28 14:56:16 -0700169 switch (hw->phy_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 case M88E1000_E_PHY_ID:
171 case M88E1000_I_PHY_ID:
172 case M88E1011_I_PHY_ID:
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700173 case M88E1111_I_PHY_ID:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 hw->phy_type = e1000_phy_m88;
175 break;
176 case IGP01E1000_I_PHY_ID:
Auke Kok8fc897b2006-08-28 14:56:16 -0700177 if (hw->mac_type == e1000_82541 ||
178 hw->mac_type == e1000_82541_rev_2 ||
179 hw->mac_type == e1000_82547 ||
180 hw->mac_type == e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 hw->phy_type = e1000_phy_igp;
182 break;
183 }
Auke Kokcd94dd02006-06-27 09:08:22 -0700184 case IGP03E1000_E_PHY_ID:
185 hw->phy_type = e1000_phy_igp_3;
186 break;
187 case IFE_E_PHY_ID:
188 case IFE_PLUS_E_PHY_ID:
189 case IFE_C_E_PHY_ID:
190 hw->phy_type = e1000_phy_ife;
191 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800192 case GG82563_E_PHY_ID:
193 if (hw->mac_type == e1000_80003es2lan) {
194 hw->phy_type = e1000_phy_gg82563;
195 break;
196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 /* Fall Through */
198 default:
199 /* Should never have loaded on this device */
200 hw->phy_type = e1000_phy_undefined;
201 return -E1000_ERR_PHY_TYPE;
202 }
203
204 return E1000_SUCCESS;
205}
206
207/******************************************************************************
208 * IGP phy init script - initializes the GbE PHY
209 *
210 * hw - Struct containing variables accessed by shared code
211 *****************************************************************************/
212static void
213e1000_phy_init_script(struct e1000_hw *hw)
214{
215 uint32_t ret_val;
216 uint16_t phy_saved_data;
217
218 DEBUGFUNC("e1000_phy_init_script");
219
Auke Kok8fc897b2006-08-28 14:56:16 -0700220 if (hw->phy_init_script) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400221 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 /* Save off the current value of register 0x2F5B to be restored at
224 * the end of this routine. */
225 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
226
227 /* Disabled the PHY transmitter */
228 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
229
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400230 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 e1000_write_phy_reg(hw,0x0000,0x0140);
233
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400234 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Auke Kok8fc897b2006-08-28 14:56:16 -0700236 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 case e1000_82541:
238 case e1000_82547:
239 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
240
241 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
242
243 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
244
245 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
246
247 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
248
249 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
250
251 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
252
253 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
254
255 e1000_write_phy_reg(hw, 0x2010, 0x0008);
256 break;
257
258 case e1000_82541_rev_2:
259 case e1000_82547_rev_2:
260 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
261 break;
262 default:
263 break;
264 }
265
266 e1000_write_phy_reg(hw, 0x0000, 0x3300);
267
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400268 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 /* Now enable the transmitter */
271 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
272
Auke Kok8fc897b2006-08-28 14:56:16 -0700273 if (hw->mac_type == e1000_82547) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 uint16_t fused, fine, coarse;
275
276 /* Move to analog registers page */
277 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
278
Auke Kok8fc897b2006-08-28 14:56:16 -0700279 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
281
282 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
283 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
284
Auke Kok8fc897b2006-08-28 14:56:16 -0700285 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
287 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
Auke Kok8fc897b2006-08-28 14:56:16 -0700288 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
290
291 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
292 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
293 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
294
295 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
296 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
297 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
298 }
299 }
300 }
301}
302
303/******************************************************************************
304 * Set the mac type member in the hw struct.
305 *
306 * hw - Struct containing variables accessed by shared code
307 *****************************************************************************/
308int32_t
309e1000_set_mac_type(struct e1000_hw *hw)
310{
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500311 DEBUGFUNC("e1000_set_mac_type");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500313 switch (hw->device_id) {
314 case E1000_DEV_ID_82542:
315 switch (hw->revision_id) {
316 case E1000_82542_2_0_REV_ID:
317 hw->mac_type = e1000_82542_rev2_0;
318 break;
319 case E1000_82542_2_1_REV_ID:
320 hw->mac_type = e1000_82542_rev2_1;
321 break;
322 default:
323 /* Invalid 82542 revision ID */
324 return -E1000_ERR_MAC_TYPE;
325 }
326 break;
327 case E1000_DEV_ID_82543GC_FIBER:
328 case E1000_DEV_ID_82543GC_COPPER:
329 hw->mac_type = e1000_82543;
330 break;
331 case E1000_DEV_ID_82544EI_COPPER:
332 case E1000_DEV_ID_82544EI_FIBER:
333 case E1000_DEV_ID_82544GC_COPPER:
334 case E1000_DEV_ID_82544GC_LOM:
335 hw->mac_type = e1000_82544;
336 break;
337 case E1000_DEV_ID_82540EM:
338 case E1000_DEV_ID_82540EM_LOM:
339 case E1000_DEV_ID_82540EP:
340 case E1000_DEV_ID_82540EP_LOM:
341 case E1000_DEV_ID_82540EP_LP:
342 hw->mac_type = e1000_82540;
343 break;
344 case E1000_DEV_ID_82545EM_COPPER:
345 case E1000_DEV_ID_82545EM_FIBER:
346 hw->mac_type = e1000_82545;
347 break;
348 case E1000_DEV_ID_82545GM_COPPER:
349 case E1000_DEV_ID_82545GM_FIBER:
350 case E1000_DEV_ID_82545GM_SERDES:
351 hw->mac_type = e1000_82545_rev_3;
352 break;
353 case E1000_DEV_ID_82546EB_COPPER:
354 case E1000_DEV_ID_82546EB_FIBER:
355 case E1000_DEV_ID_82546EB_QUAD_COPPER:
356 hw->mac_type = e1000_82546;
357 break;
358 case E1000_DEV_ID_82546GB_COPPER:
359 case E1000_DEV_ID_82546GB_FIBER:
360 case E1000_DEV_ID_82546GB_SERDES:
361 case E1000_DEV_ID_82546GB_PCIE:
362 case E1000_DEV_ID_82546GB_QUAD_COPPER:
363 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
364 hw->mac_type = e1000_82546_rev_3;
365 break;
366 case E1000_DEV_ID_82541EI:
367 case E1000_DEV_ID_82541EI_MOBILE:
368 case E1000_DEV_ID_82541ER_LOM:
369 hw->mac_type = e1000_82541;
370 break;
371 case E1000_DEV_ID_82541ER:
372 case E1000_DEV_ID_82541GI:
373 case E1000_DEV_ID_82541GI_LF:
374 case E1000_DEV_ID_82541GI_MOBILE:
375 hw->mac_type = e1000_82541_rev_2;
376 break;
377 case E1000_DEV_ID_82547EI:
378 case E1000_DEV_ID_82547EI_MOBILE:
379 hw->mac_type = e1000_82547;
380 break;
381 case E1000_DEV_ID_82547GI:
382 hw->mac_type = e1000_82547_rev_2;
383 break;
384 case E1000_DEV_ID_82571EB_COPPER:
385 case E1000_DEV_ID_82571EB_FIBER:
386 case E1000_DEV_ID_82571EB_SERDES:
Auke Kokce57a022007-08-09 14:09:34 -0700387 case E1000_DEV_ID_82571EB_SERDES_DUAL:
388 case E1000_DEV_ID_82571EB_SERDES_QUAD:
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500389 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokf4ec7f92007-08-30 11:23:58 -0700390 case E1000_DEV_ID_82571PT_QUAD_COPPER:
Auke Kokce57a022007-08-09 14:09:34 -0700391 case E1000_DEV_ID_82571EB_QUAD_FIBER:
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500392 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
393 hw->mac_type = e1000_82571;
394 break;
395 case E1000_DEV_ID_82572EI_COPPER:
396 case E1000_DEV_ID_82572EI_FIBER:
397 case E1000_DEV_ID_82572EI_SERDES:
398 case E1000_DEV_ID_82572EI:
399 hw->mac_type = e1000_82572;
400 break;
401 case E1000_DEV_ID_82573E:
402 case E1000_DEV_ID_82573E_IAMT:
403 case E1000_DEV_ID_82573L:
404 hw->mac_type = e1000_82573;
405 break;
406 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
407 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
408 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
409 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
410 hw->mac_type = e1000_80003es2lan;
411 break;
412 case E1000_DEV_ID_ICH8_IGP_M_AMT:
413 case E1000_DEV_ID_ICH8_IGP_AMT:
414 case E1000_DEV_ID_ICH8_IGP_C:
415 case E1000_DEV_ID_ICH8_IFE:
416 case E1000_DEV_ID_ICH8_IFE_GT:
417 case E1000_DEV_ID_ICH8_IFE_G:
418 case E1000_DEV_ID_ICH8_IGP_M:
419 hw->mac_type = e1000_ich8lan;
420 break;
421 default:
422 /* Should never have loaded on this device */
423 return -E1000_ERR_MAC_TYPE;
424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500426 switch (hw->mac_type) {
427 case e1000_ich8lan:
428 hw->swfwhw_semaphore_present = TRUE;
429 hw->asf_firmware_present = TRUE;
430 break;
431 case e1000_80003es2lan:
432 hw->swfw_sync_present = TRUE;
433 /* fall through */
434 case e1000_82571:
435 case e1000_82572:
436 case e1000_82573:
437 hw->eeprom_semaphore_present = TRUE;
438 /* fall through */
439 case e1000_82541:
440 case e1000_82547:
441 case e1000_82541_rev_2:
442 case e1000_82547_rev_2:
443 hw->asf_firmware_present = TRUE;
444 break;
445 default:
446 break;
447 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Jeff Garzik167fb282006-12-15 10:41:15 -0500449 /* The 82543 chip does not count tx_carrier_errors properly in
450 * FD mode
451 */
452 if (hw->mac_type == e1000_82543)
453 hw->bad_tx_carr_stats_fd = TRUE;
454
Jeff Garzik0fccd0e2006-12-15 10:56:10 -0500455 /* capable of receiving management packets to the host */
456 if (hw->mac_type >= e1000_82571)
457 hw->has_manc2h = TRUE;
458
Jeff Garzikbb8e3312006-12-15 11:06:17 -0500459 /* In rare occasions, ESB2 systems would end up started without
460 * the RX unit being turned on.
461 */
462 if (hw->mac_type == e1000_80003es2lan)
463 hw->rx_needs_kicking = TRUE;
464
Jeff Garzik15e376b2006-12-15 11:16:33 -0500465 if (hw->mac_type > e1000_82544)
466 hw->has_smbus = TRUE;
467
Jeff Garzikbd2371e2006-12-15 10:31:40 -0500468 return E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469}
470
471/*****************************************************************************
472 * Set media type and TBI compatibility.
473 *
474 * hw - Struct containing variables accessed by shared code
475 * **************************************************************************/
476void
477e1000_set_media_type(struct e1000_hw *hw)
478{
479 uint32_t status;
480
481 DEBUGFUNC("e1000_set_media_type");
482
Auke Kok8fc897b2006-08-28 14:56:16 -0700483 if (hw->mac_type != e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 /* tbi_compatibility is only valid on 82543 */
485 hw->tbi_compatibility_en = FALSE;
486 }
487
488 switch (hw->device_id) {
489 case E1000_DEV_ID_82545GM_SERDES:
490 case E1000_DEV_ID_82546GB_SERDES:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400491 case E1000_DEV_ID_82571EB_SERDES:
Auke Kokce57a022007-08-09 14:09:34 -0700492 case E1000_DEV_ID_82571EB_SERDES_DUAL:
493 case E1000_DEV_ID_82571EB_SERDES_QUAD:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400494 case E1000_DEV_ID_82572EI_SERDES:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800495 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 hw->media_type = e1000_media_type_internal_serdes;
497 break;
498 default:
Malli Chilakala3893d542005-06-17 17:44:49 -0700499 switch (hw->mac_type) {
500 case e1000_82542_rev2_0:
501 case e1000_82542_rev2_1:
502 hw->media_type = e1000_media_type_fiber;
503 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700504 case e1000_ich8lan:
Malli Chilakala3893d542005-06-17 17:44:49 -0700505 case e1000_82573:
506 /* The STATUS_TBIMODE bit is reserved or reused for the this
507 * device.
508 */
509 hw->media_type = e1000_media_type_copper;
510 break;
511 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 status = E1000_READ_REG(hw, STATUS);
Malli Chilakala3893d542005-06-17 17:44:49 -0700513 if (status & E1000_STATUS_TBIMODE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 hw->media_type = e1000_media_type_fiber;
515 /* tbi_compatibility not valid on fiber */
516 hw->tbi_compatibility_en = FALSE;
517 } else {
518 hw->media_type = e1000_media_type_copper;
519 }
Malli Chilakala3893d542005-06-17 17:44:49 -0700520 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
522 }
523}
524
525/******************************************************************************
526 * Reset the transmit and receive units; mask and clear all interrupts.
527 *
528 * hw - Struct containing variables accessed by shared code
529 *****************************************************************************/
530int32_t
531e1000_reset_hw(struct e1000_hw *hw)
532{
533 uint32_t ctrl;
534 uint32_t ctrl_ext;
535 uint32_t icr;
536 uint32_t manc;
537 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700538 uint32_t timeout;
539 uint32_t extcnf_ctrl;
540 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 DEBUGFUNC("e1000_reset_hw");
543
544 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700545 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
547 e1000_pci_clear_mwi(hw);
548 }
549
Auke Kok8fc897b2006-08-28 14:56:16 -0700550 if (hw->bus_type == e1000_bus_type_pci_express) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700551 /* Prevent the PCI-E bus from sticking if there is no TLP connection
552 * on the last TLP read/write transaction when MAC is reset.
553 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700554 if (e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700555 DEBUGOUT("PCI-E Master disable polling has failed.\n");
556 }
557 }
558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 /* Clear interrupt mask to stop board from generating interrupts */
560 DEBUGOUT("Masking off all interrupts\n");
561 E1000_WRITE_REG(hw, IMC, 0xffffffff);
562
563 /* Disable the Transmit and Receive units. Then delay to allow
564 * any pending transactions to complete before we hit the MAC with
565 * the global reset.
566 */
567 E1000_WRITE_REG(hw, RCTL, 0);
568 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
569 E1000_WRITE_FLUSH(hw);
570
571 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
572 hw->tbi_compatibility_on = FALSE;
573
574 /* Delay to allow any outstanding PCI transactions to complete before
575 * resetting the device
576 */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400577 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
579 ctrl = E1000_READ_REG(hw, CTRL);
580
581 /* Must reset the PHY before resetting the MAC */
Auke Kok8fc897b2006-08-28 14:56:16 -0700582 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700583 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400584 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700587 /* Must acquire the MDIO ownership before MAC reset.
588 * Ownership defaults to firmware after a reset. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700589 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700590 timeout = 10;
591
592 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
593 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
594
595 do {
596 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
597 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
598
Auke Kok8fc897b2006-08-28 14:56:16 -0700599 if (extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700600 break;
601 else
602 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
603
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400604 msleep(2);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700605 timeout--;
Auke Kok8fc897b2006-08-28 14:56:16 -0700606 } while (timeout);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700607 }
608
Auke Kokcd94dd02006-06-27 09:08:22 -0700609 /* Workaround for ICH8 bit corruption issue in FIFO memory */
610 if (hw->mac_type == e1000_ich8lan) {
611 /* Set Tx and Rx buffer allocation to 8k apiece. */
612 E1000_WRITE_REG(hw, PBA, E1000_PBA_8K);
613 /* Set Packet Buffer Size to 16k. */
614 E1000_WRITE_REG(hw, PBS, E1000_PBS_16K);
615 }
616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 /* Issue a global reset to the MAC. This will reset the chip's
618 * transmit, receive, DMA, and link units. It will not effect
619 * the current PCI configuration. The global reset bit is self-
620 * clearing, and should clear within a microsecond.
621 */
622 DEBUGOUT("Issuing a global reset to MAC\n");
623
Auke Kok8fc897b2006-08-28 14:56:16 -0700624 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 case e1000_82544:
626 case e1000_82540:
627 case e1000_82545:
628 case e1000_82546:
629 case e1000_82541:
630 case e1000_82541_rev_2:
631 /* These controllers can't ack the 64-bit write when issuing the
632 * reset, so use IO-mapping as a workaround to issue the reset */
633 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
634 break;
635 case e1000_82545_rev_3:
636 case e1000_82546_rev_3:
637 /* Reset is performed on a shadow of the control register */
638 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
639 break;
Auke Kokcd94dd02006-06-27 09:08:22 -0700640 case e1000_ich8lan:
641 if (!hw->phy_reset_disable &&
642 e1000_check_phy_reset_block(hw) == E1000_SUCCESS) {
643 /* e1000_ich8lan PHY HW reset requires MAC CORE reset
644 * at the same time to make sure the interface between
645 * MAC and the external PHY is reset.
646 */
647 ctrl |= E1000_CTRL_PHY_RST;
648 }
649
650 e1000_get_software_flag(hw);
651 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400652 msleep(5);
Auke Kokcd94dd02006-06-27 09:08:22 -0700653 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 default:
655 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
656 break;
657 }
658
659 /* After MAC reset, force reload of EEPROM to restore power-on settings to
660 * device. Later controllers reload the EEPROM automatically, so just wait
661 * for reload to complete.
662 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700663 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 case e1000_82542_rev2_0:
665 case e1000_82542_rev2_1:
666 case e1000_82543:
667 case e1000_82544:
668 /* Wait for reset to complete */
669 udelay(10);
670 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
671 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
672 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
673 E1000_WRITE_FLUSH(hw);
674 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400675 msleep(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 break;
677 case e1000_82541:
678 case e1000_82541_rev_2:
679 case e1000_82547:
680 case e1000_82547_rev_2:
681 /* Wait for EEPROM reload */
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400682 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700684 case e1000_82573:
Jeff Kirsherfd803242005-12-13 00:06:22 -0500685 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
686 udelay(10);
687 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
688 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
689 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
690 E1000_WRITE_FLUSH(hw);
691 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700692 /* fall through */
Jeff Kirsher2a88c172006-09-27 12:54:05 -0700693 default:
694 /* Auto read done will delay 5ms or poll based on mac type */
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700695 ret_val = e1000_get_auto_rd_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700696 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700697 return ret_val;
698 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 }
700
701 /* Disable HW ARPs on ASF enabled adapters */
Auke Kok8fc897b2006-08-28 14:56:16 -0700702 if (hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 manc = E1000_READ_REG(hw, MANC);
704 manc &= ~(E1000_MANC_ARP_EN);
705 E1000_WRITE_REG(hw, MANC, manc);
706 }
707
Auke Kok8fc897b2006-08-28 14:56:16 -0700708 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 e1000_phy_init_script(hw);
710
711 /* Configure activity LED after PHY reset */
712 led_ctrl = E1000_READ_REG(hw, LEDCTL);
713 led_ctrl &= IGP_ACTIVITY_LED_MASK;
714 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
715 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
716 }
717
718 /* Clear interrupt mask to stop board from generating interrupts */
719 DEBUGOUT("Masking off all interrupts\n");
720 E1000_WRITE_REG(hw, IMC, 0xffffffff);
721
722 /* Clear any pending interrupt events. */
723 icr = E1000_READ_REG(hw, ICR);
724
725 /* If MWI was previously enabled, reenable it. */
Auke Kok8fc897b2006-08-28 14:56:16 -0700726 if (hw->mac_type == e1000_82542_rev2_0) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400727 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 e1000_pci_set_mwi(hw);
729 }
730
Auke Kokcd94dd02006-06-27 09:08:22 -0700731 if (hw->mac_type == e1000_ich8lan) {
732 uint32_t kab = E1000_READ_REG(hw, KABGTXD);
733 kab |= E1000_KABGTXD_BGSQLBIAS;
734 E1000_WRITE_REG(hw, KABGTXD, kab);
735 }
736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 return E1000_SUCCESS;
738}
739
740/******************************************************************************
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700741 *
742 * Initialize a number of hardware-dependent bits
743 *
744 * hw: Struct containing variables accessed by shared code
745 *
746 * This function contains hardware limitation workarounds for PCI-E adapters
747 *
748 *****************************************************************************/
749static void
750e1000_initialize_hardware_bits(struct e1000_hw *hw)
751{
752 if ((hw->mac_type >= e1000_82571) && (!hw->initialize_hw_bits_disable)) {
753 /* Settings common to all PCI-express silicon */
754 uint32_t reg_ctrl, reg_ctrl_ext;
755 uint32_t reg_tarc0, reg_tarc1;
756 uint32_t reg_tctl;
757 uint32_t reg_txdctl, reg_txdctl1;
758
759 /* link autonegotiation/sync workarounds */
760 reg_tarc0 = E1000_READ_REG(hw, TARC0);
761 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
762
763 /* Enable not-done TX descriptor counting */
764 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
765 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
766 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
767 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
768 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
769 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
770
771 switch (hw->mac_type) {
772 case e1000_82571:
773 case e1000_82572:
774 /* Clear PHY TX compatible mode bits */
775 reg_tarc1 = E1000_READ_REG(hw, TARC1);
776 reg_tarc1 &= ~((1 << 30)|(1 << 29));
777
778 /* link autonegotiation/sync workarounds */
779 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
780
781 /* TX ring control fixes */
782 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
783
784 /* Multiple read bit is reversed polarity */
785 reg_tctl = E1000_READ_REG(hw, TCTL);
786 if (reg_tctl & E1000_TCTL_MULR)
787 reg_tarc1 &= ~(1 << 28);
788 else
789 reg_tarc1 |= (1 << 28);
790
791 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
792 break;
793 case e1000_82573:
794 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
795 reg_ctrl_ext &= ~(1 << 23);
796 reg_ctrl_ext |= (1 << 22);
797
798 /* TX byte count fix */
799 reg_ctrl = E1000_READ_REG(hw, CTRL);
800 reg_ctrl &= ~(1 << 29);
801
802 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
803 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
804 break;
805 case e1000_80003es2lan:
806 /* improve small packet performace for fiber/serdes */
807 if ((hw->media_type == e1000_media_type_fiber) ||
808 (hw->media_type == e1000_media_type_internal_serdes)) {
809 reg_tarc0 &= ~(1 << 20);
810 }
811
812 /* Multiple read bit is reversed polarity */
813 reg_tctl = E1000_READ_REG(hw, TCTL);
814 reg_tarc1 = E1000_READ_REG(hw, TARC1);
815 if (reg_tctl & E1000_TCTL_MULR)
816 reg_tarc1 &= ~(1 << 28);
817 else
818 reg_tarc1 |= (1 << 28);
819
820 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
821 break;
822 case e1000_ich8lan:
823 /* Reduce concurrent DMA requests to 3 from 4 */
824 if ((hw->revision_id < 3) ||
825 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
826 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
827 reg_tarc0 |= ((1 << 29)|(1 << 28));
828
829 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
830 reg_ctrl_ext |= (1 << 22);
831 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
832
833 /* workaround TX hang with TSO=on */
834 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
835
836 /* Multiple read bit is reversed polarity */
837 reg_tctl = E1000_READ_REG(hw, TCTL);
838 reg_tarc1 = E1000_READ_REG(hw, TARC1);
839 if (reg_tctl & E1000_TCTL_MULR)
840 reg_tarc1 &= ~(1 << 28);
841 else
842 reg_tarc1 |= (1 << 28);
843
844 /* workaround TX hang with TSO=on */
845 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
846
847 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
848 break;
849 default:
850 break;
851 }
852
853 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
854 }
855}
856
857/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 * Performs basic configuration of the adapter.
859 *
860 * hw - Struct containing variables accessed by shared code
861 *
862 * Assumes that the controller has previously been reset and is in a
863 * post-reset uninitialized state. Initializes the receive address registers,
864 * multicast table, and VLAN filter table. Calls routines to setup link
865 * configuration and flow control settings. Clears all on-chip counters. Leaves
866 * the transmit and receive units disabled and uninitialized.
867 *****************************************************************************/
868int32_t
869e1000_init_hw(struct e1000_hw *hw)
870{
871 uint32_t ctrl;
872 uint32_t i;
873 int32_t ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700874 uint32_t mta_size;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800875 uint32_t reg_data;
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -0800876 uint32_t ctrl_ext;
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700877
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 DEBUGFUNC("e1000_init_hw");
879
Jeff Kirsher7820d422006-08-16 13:39:00 -0700880 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700881 if ((hw->mac_type == e1000_ich8lan) &&
882 ((hw->revision_id < 3) ||
883 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
884 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
885 reg_data = E1000_READ_REG(hw, STATUS);
886 reg_data &= ~0x80000000;
887 E1000_WRITE_REG(hw, STATUS, reg_data);
Jeff Kirsher7820d422006-08-16 13:39:00 -0700888 }
889
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 /* Initialize Identification LED */
891 ret_val = e1000_id_led_init(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -0700892 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 DEBUGOUT("Error Initializing Identification LED\n");
894 return ret_val;
895 }
896
897 /* Set the media type and TBI compatibility */
898 e1000_set_media_type(hw);
899
Jeff Kirsher09ae3e82006-09-27 12:53:51 -0700900 /* Must be called after e1000_set_media_type because media_type is used */
901 e1000_initialize_hardware_bits(hw);
902
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 /* Disabling VLAN filtering. */
904 DEBUGOUT("Initializing the IEEE VLAN\n");
Auke Kokcd94dd02006-06-27 09:08:22 -0700905 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
906 if (hw->mac_type != e1000_ich8lan) {
907 if (hw->mac_type < e1000_82545_rev_3)
908 E1000_WRITE_REG(hw, VET, 0);
909 e1000_clear_vfta(hw);
910 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
Auke Kok8fc897b2006-08-28 14:56:16 -0700913 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
915 e1000_pci_clear_mwi(hw);
916 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
917 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400918 msleep(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 }
920
921 /* Setup the receive address. This involves initializing all of the Receive
922 * Address Registers (RARs 0 - 15).
923 */
924 e1000_init_rx_addrs(hw);
925
926 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
Auke Kok8fc897b2006-08-28 14:56:16 -0700927 if (hw->mac_type == e1000_82542_rev2_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 E1000_WRITE_REG(hw, RCTL, 0);
929 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400930 msleep(1);
931 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 e1000_pci_set_mwi(hw);
933 }
934
935 /* Zero out the Multicast HASH table */
936 DEBUGOUT("Zeroing the MTA\n");
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700937 mta_size = E1000_MC_TBL_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -0700938 if (hw->mac_type == e1000_ich8lan)
939 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
Auke Kok8fc897b2006-08-28 14:56:16 -0700940 for (i = 0; i < mta_size; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
Auke Kok4ca213a2006-06-27 09:07:08 -0700942 /* use write flush to prevent Memory Write Block (MWB) from
943 * occuring when accessing our register space */
944 E1000_WRITE_FLUSH(hw);
945 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
947 /* Set the PCI priority bit correctly in the CTRL register. This
948 * determines if the adapter gives priority to receives, or if it
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700949 * gives equal priority to transmits and receives. Valid only on
950 * 82542 and 82543 silicon.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 */
Auke Kok8fc897b2006-08-28 14:56:16 -0700952 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 ctrl = E1000_READ_REG(hw, CTRL);
954 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
955 }
956
Auke Kok8fc897b2006-08-28 14:56:16 -0700957 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 case e1000_82545_rev_3:
959 case e1000_82546_rev_3:
960 break;
961 default:
962 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
Peter Oruba007755e2007-09-28 22:42:06 -0700963 if (hw->bus_type == e1000_bus_type_pcix && e1000_pcix_get_mmrbc(hw) > 2048)
964 e1000_pcix_set_mmrbc(hw, 2048);
965 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 }
967
Auke Kokcd94dd02006-06-27 09:08:22 -0700968 /* More time needed for PHY to initialize */
969 if (hw->mac_type == e1000_ich8lan)
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400970 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -0700971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 /* Call a subroutine to configure the link and setup flow control. */
973 ret_val = e1000_setup_link(hw);
974
975 /* Set the transmit descriptor write-back policy */
Auke Kok8fc897b2006-08-28 14:56:16 -0700976 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 ctrl = E1000_READ_REG(hw, TXDCTL);
978 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
979 E1000_WRITE_REG(hw, TXDCTL, ctrl);
980 }
981
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700982 if (hw->mac_type == e1000_82573) {
Auke Kok76c224b2006-05-23 13:36:06 -0700983 e1000_enable_tx_pkt_filtering(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -0700984 }
985
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400986 switch (hw->mac_type) {
987 default:
988 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800989 case e1000_80003es2lan:
990 /* Enable retransmit on late collisions */
991 reg_data = E1000_READ_REG(hw, TCTL);
992 reg_data |= E1000_TCTL_RTLC;
993 E1000_WRITE_REG(hw, TCTL, reg_data);
994
995 /* Configure Gigabit Carry Extend Padding */
996 reg_data = E1000_READ_REG(hw, TCTL_EXT);
997 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
998 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
999 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1000
1001 /* Configure Transmit Inter-Packet Gap */
1002 reg_data = E1000_READ_REG(hw, TIPG);
1003 reg_data &= ~E1000_TIPG_IPGT_MASK;
1004 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1005 E1000_WRITE_REG(hw, TIPG, reg_data);
1006
1007 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1008 reg_data &= ~0x00100000;
1009 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1010 /* Fall through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001011 case e1000_82571:
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -04001012 case e1000_82572:
Auke Kokcd94dd02006-06-27 09:08:22 -07001013 case e1000_ich8lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001014 ctrl = E1000_READ_REG(hw, TXDCTL1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001015 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001016 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1017 break;
1018 }
1019
1020
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001021 if (hw->mac_type == e1000_82573) {
1022 uint32_t gcr = E1000_READ_REG(hw, GCR);
1023 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1024 E1000_WRITE_REG(hw, GCR, gcr);
1025 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001026
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 /* Clear all of the statistics registers (clear on read). It is
1028 * important that we do this after we have tried to establish link
1029 * because the symbol error count will increment wildly if there
1030 * is no link.
1031 */
1032 e1000_clear_hw_cntrs(hw);
1033
Auke Kokcd94dd02006-06-27 09:08:22 -07001034 /* ICH8 No-snoop bits are opposite polarity.
1035 * Set to snoop by default after reset. */
1036 if (hw->mac_type == e1000_ich8lan)
1037 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1038
Jeff Kirsherb7ee49d2006-01-12 16:51:21 -08001039 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1040 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1041 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1042 /* Relaxed ordering must be disabled to avoid a parity
1043 * error crash in a PCI slot. */
1044 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1045 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1046 }
1047
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 return ret_val;
1049}
1050
1051/******************************************************************************
1052 * Adjust SERDES output amplitude based on EEPROM setting.
1053 *
1054 * hw - Struct containing variables accessed by shared code.
1055 *****************************************************************************/
1056static int32_t
1057e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
1058{
1059 uint16_t eeprom_data;
1060 int32_t ret_val;
1061
1062 DEBUGFUNC("e1000_adjust_serdes_amplitude");
1063
Auke Kok8fc897b2006-08-28 14:56:16 -07001064 if (hw->media_type != e1000_media_type_internal_serdes)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 return E1000_SUCCESS;
1066
Auke Kok8fc897b2006-08-28 14:56:16 -07001067 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 case e1000_82545_rev_3:
1069 case e1000_82546_rev_3:
1070 break;
1071 default:
1072 return E1000_SUCCESS;
1073 }
1074
1075 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
1076 if (ret_val) {
1077 return ret_val;
1078 }
1079
Auke Kok8fc897b2006-08-28 14:56:16 -07001080 if (eeprom_data != EEPROM_RESERVED_WORD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 /* Adjust SERDES output amplitude only. */
Auke Kok76c224b2006-05-23 13:36:06 -07001082 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001084 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 return ret_val;
1086 }
1087
1088 return E1000_SUCCESS;
1089}
1090
1091/******************************************************************************
1092 * Configures flow control and link settings.
1093 *
1094 * hw - Struct containing variables accessed by shared code
1095 *
1096 * Determines which flow control settings to use. Calls the apropriate media-
1097 * specific link configuration function. Configures the flow control settings.
1098 * Assuming the adapter has a valid link partner, a valid link should be
1099 * established. Assumes the hardware has previously been reset and the
1100 * transmitter and receiver are not enabled.
1101 *****************************************************************************/
1102int32_t
1103e1000_setup_link(struct e1000_hw *hw)
1104{
1105 uint32_t ctrl_ext;
1106 int32_t ret_val;
1107 uint16_t eeprom_data;
1108
1109 DEBUGFUNC("e1000_setup_link");
1110
Jeff Kirsher526f9952006-01-12 16:50:46 -08001111 /* In the case of the phy reset being blocked, we already have a link.
1112 * We do not have to set it up again. */
1113 if (e1000_check_phy_reset_block(hw))
1114 return E1000_SUCCESS;
1115
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 /* Read and store word 0x0F of the EEPROM. This word contains bits
1117 * that determine the hardware's default PAUSE (flow control) mode,
1118 * a bit that determines whether the HW defaults to enabling or
1119 * disabling auto-negotiation, and the direction of the
1120 * SW defined pins. If there is no SW over-ride of the flow
1121 * control setting, then the variable hw->fc will
1122 * be initialized based on a value in the EEPROM.
1123 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001124 if (hw->fc == E1000_FC_DEFAULT) {
Jeff Kirsherfd803242005-12-13 00:06:22 -05001125 switch (hw->mac_type) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001126 case e1000_ich8lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05001127 case e1000_82573:
Jeff Kirsher11241b12006-09-27 12:53:28 -07001128 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001129 break;
1130 default:
1131 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1132 1, &eeprom_data);
1133 if (ret_val) {
1134 DEBUGOUT("EEPROM Read Error\n");
1135 return -E1000_ERR_EEPROM;
1136 }
1137 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001138 hw->fc = E1000_FC_NONE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001139 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1140 EEPROM_WORD0F_ASM_DIR)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001141 hw->fc = E1000_FC_TX_PAUSE;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001142 else
Jeff Kirsher11241b12006-09-27 12:53:28 -07001143 hw->fc = E1000_FC_FULL;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001144 break;
1145 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 }
1147
1148 /* We want to save off the original Flow Control configuration just
1149 * in case we get disconnected and then reconnected into a different
1150 * hub or switch with different Flow Control capabilities.
1151 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001152 if (hw->mac_type == e1000_82542_rev2_0)
Jeff Kirsher11241b12006-09-27 12:53:28 -07001153 hw->fc &= (~E1000_FC_TX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
Auke Kok8fc897b2006-08-28 14:56:16 -07001155 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
Jeff Kirsher11241b12006-09-27 12:53:28 -07001156 hw->fc &= (~E1000_FC_RX_PAUSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
1158 hw->original_fc = hw->fc;
1159
1160 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
1161
1162 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1163 * polarity value for the SW controlled pins, and setup the
1164 * Extended Device Control reg with that info.
1165 * This is needed because one of the SW controlled pins is used for
1166 * signal detection. So this should be done before e1000_setup_pcs_link()
1167 * or e1000_phy_setup() is called.
1168 */
Jeff Kirsher497fce52006-03-02 18:18:20 -08001169 if (hw->mac_type == e1000_82543) {
Auke Kok8fc897b2006-08-28 14:56:16 -07001170 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
1171 1, &eeprom_data);
1172 if (ret_val) {
1173 DEBUGOUT("EEPROM Read Error\n");
1174 return -E1000_ERR_EEPROM;
1175 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1177 SWDPIO__EXT_SHIFT);
1178 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1179 }
1180
1181 /* Call the necessary subroutine to configure the link. */
1182 ret_val = (hw->media_type == e1000_media_type_copper) ?
1183 e1000_setup_copper_link(hw) :
1184 e1000_setup_fiber_serdes_link(hw);
1185
1186 /* Initialize the flow control address, type, and PAUSE timer
1187 * registers to their default values. This is done even if flow
1188 * control is disabled, because it does not hurt anything to
1189 * initialize these registers.
1190 */
1191 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
1192
Auke Kokcd94dd02006-06-27 09:08:22 -07001193 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1194 if (hw->mac_type != e1000_ich8lan) {
1195 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1196 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1197 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1198 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001199
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1201
1202 /* Set the flow control receive threshold registers. Normally,
1203 * these registers will be set to a default threshold that may be
1204 * adjusted later by the driver's runtime code. However, if the
1205 * ability to transmit pause frames in not enabled, then these
1206 * registers will be set to 0.
1207 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07001208 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 E1000_WRITE_REG(hw, FCRTL, 0);
1210 E1000_WRITE_REG(hw, FCRTH, 0);
1211 } else {
1212 /* We need to set up the Receive Threshold high and low water marks
1213 * as well as (optionally) enabling the transmission of XON frames.
1214 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001215 if (hw->fc_send_xon) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
1217 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1218 } else {
1219 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1220 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1221 }
1222 }
1223 return ret_val;
1224}
1225
1226/******************************************************************************
1227 * Sets up link for a fiber based or serdes based adapter
1228 *
1229 * hw - Struct containing variables accessed by shared code
1230 *
1231 * Manipulates Physical Coding Sublayer functions in order to configure
1232 * link. Assumes the hardware has been previously reset and the transmitter
1233 * and receiver are not enabled.
1234 *****************************************************************************/
1235static int32_t
1236e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
1237{
1238 uint32_t ctrl;
1239 uint32_t status;
1240 uint32_t txcw = 0;
1241 uint32_t i;
1242 uint32_t signal = 0;
1243 int32_t ret_val;
1244
1245 DEBUGFUNC("e1000_setup_fiber_serdes_link");
1246
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001247 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
1248 * until explicitly turned off or a power cycle is performed. A read to
1249 * the register does not indicate its status. Therefore, we ensure
1250 * loopback mode is disabled during initialization.
1251 */
1252 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
1253 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
1254
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001255 /* On adapters with a MAC newer than 82544, SWDP 1 will be
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 * set when the optics detect a signal. On older adapters, it will be
1257 * cleared when there is a signal. This applies to fiber media only.
Jeff Kirsher09ae3e82006-09-27 12:53:51 -07001258 * If we're on serdes media, adjust the output amplitude to value
1259 * set in the EEPROM.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 */
1261 ctrl = E1000_READ_REG(hw, CTRL);
Auke Kok8fc897b2006-08-28 14:56:16 -07001262 if (hw->media_type == e1000_media_type_fiber)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1264
1265 ret_val = e1000_adjust_serdes_amplitude(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001266 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 return ret_val;
1268
1269 /* Take the link out of reset */
1270 ctrl &= ~(E1000_CTRL_LRST);
1271
1272 /* Adjust VCO speed to improve BER performance */
1273 ret_val = e1000_set_vco_speed(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001274 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 return ret_val;
1276
1277 e1000_config_collision_dist(hw);
1278
1279 /* Check for a software override of the flow control settings, and setup
1280 * the device accordingly. If auto-negotiation is enabled, then software
1281 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1282 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1283 * auto-negotiation is disabled, then software will have to manually
1284 * configure the two flow control enable bits in the CTRL register.
1285 *
1286 * The possible values of the "fc" parameter are:
1287 * 0: Flow control is completely disabled
1288 * 1: Rx flow control is enabled (we can receive pause frames, but
1289 * not send pause frames).
1290 * 2: Tx flow control is enabled (we can send pause frames but we do
1291 * not support receiving pause frames).
1292 * 3: Both Rx and TX flow control (symmetric) are enabled.
1293 */
1294 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07001295 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 /* Flow control is completely disabled by a software over-ride. */
1297 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1298 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001299 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 /* RX Flow control is enabled and TX Flow control is disabled by a
1301 * software over-ride. Since there really isn't a way to advertise
1302 * that we are capable of RX Pause ONLY, we will advertise that we
1303 * support both symmetric and asymmetric RX PAUSE. Later, we will
1304 * disable the adapter's ability to send PAUSE frames.
1305 */
1306 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1307 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001308 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1310 * software over-ride.
1311 */
1312 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1313 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07001314 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1316 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1317 break;
1318 default:
1319 DEBUGOUT("Flow control param set incorrectly\n");
1320 return -E1000_ERR_CONFIG;
1321 break;
1322 }
1323
1324 /* Since auto-negotiation is enabled, take the link out of reset (the link
1325 * will be in reset, because we previously reset the chip). This will
1326 * restart auto-negotiation. If auto-neogtiation is successful then the
1327 * link-up status bit will be set and the flow control enable bits (RFCE
1328 * and TFCE) will be set according to their negotiated value.
1329 */
1330 DEBUGOUT("Auto-negotiation enabled\n");
1331
1332 E1000_WRITE_REG(hw, TXCW, txcw);
1333 E1000_WRITE_REG(hw, CTRL, ctrl);
1334 E1000_WRITE_FLUSH(hw);
1335
1336 hw->txcw = txcw;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001337 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
1339 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1340 * indication in the Device Status Register. Time-out if a link isn't
1341 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1342 * less than 500 milliseconds even if the other end is doing it in SW).
1343 * For internal serdes, we just assume a signal is present, then poll.
1344 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001345 if (hw->media_type == e1000_media_type_internal_serdes ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1347 DEBUGOUT("Looking for Link\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07001348 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001349 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07001351 if (status & E1000_STATUS_LU) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 }
Auke Kok8fc897b2006-08-28 14:56:16 -07001353 if (i == (LINK_UP_TIMEOUT / 10)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1355 hw->autoneg_failed = 1;
1356 /* AutoNeg failed to achieve a link, so we'll call
1357 * e1000_check_for_link. This routine will force the link up if
1358 * we detect a signal. This will allow us to communicate with
1359 * non-autonegotiating link partners.
1360 */
1361 ret_val = e1000_check_for_link(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001362 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 DEBUGOUT("Error while checking for link\n");
1364 return ret_val;
1365 }
1366 hw->autoneg_failed = 0;
1367 } else {
1368 hw->autoneg_failed = 0;
1369 DEBUGOUT("Valid Link Found\n");
1370 }
1371 } else {
1372 DEBUGOUT("No Signal Detected\n");
1373 }
1374 return E1000_SUCCESS;
1375}
1376
1377/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001378* Make sure we have a valid PHY and change PHY mode before link setup.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379*
1380* hw - Struct containing variables accessed by shared code
1381******************************************************************************/
1382static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001383e1000_copper_link_preconfig(struct e1000_hw *hw)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384{
1385 uint32_t ctrl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 int32_t ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 uint16_t phy_data;
1388
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001389 DEBUGFUNC("e1000_copper_link_preconfig");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390
1391 ctrl = E1000_READ_REG(hw, CTRL);
1392 /* With 82543, we need to force speed and duplex on the MAC equal to what
1393 * the PHY speed and duplex configuration is. In addition, we need to
1394 * perform a hardware reset on the PHY to take it out of reset.
1395 */
Auke Kok8fc897b2006-08-28 14:56:16 -07001396 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 ctrl |= E1000_CTRL_SLU;
1398 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1399 E1000_WRITE_REG(hw, CTRL, ctrl);
1400 } else {
1401 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1402 E1000_WRITE_REG(hw, CTRL, ctrl);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001403 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001404 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001405 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 }
1407
1408 /* Make sure we have a valid PHY */
1409 ret_val = e1000_detect_gig_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001410 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 DEBUGOUT("Error, did not detect valid phy.\n");
1412 return ret_val;
1413 }
1414 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1415
1416 /* Set PHY to class A mode (if necessary) */
1417 ret_val = e1000_set_phy_mode(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001418 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 return ret_val;
1420
Auke Kok8fc897b2006-08-28 14:56:16 -07001421 if ((hw->mac_type == e1000_82545_rev_3) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 (hw->mac_type == e1000_82546_rev_3)) {
1423 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1424 phy_data |= 0x00000008;
1425 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1426 }
1427
Auke Kok8fc897b2006-08-28 14:56:16 -07001428 if (hw->mac_type <= e1000_82543 ||
1429 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1430 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 hw->phy_reset_disable = FALSE;
1432
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001433 return E1000_SUCCESS;
1434}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001437/********************************************************************
1438* Copper link setup for e1000_phy_igp series.
1439*
1440* hw - Struct containing variables accessed by shared code
1441*********************************************************************/
1442static int32_t
1443e1000_copper_link_igp_setup(struct e1000_hw *hw)
1444{
1445 uint32_t led_ctrl;
1446 int32_t ret_val;
1447 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001449 DEBUGFUNC("e1000_copper_link_igp_setup");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001451 if (hw->phy_reset_disable)
1452 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001453
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001454 ret_val = e1000_phy_reset(hw);
1455 if (ret_val) {
1456 DEBUGOUT("Error Resetting the PHY\n");
1457 return ret_val;
1458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Auke Kok8fc897b2006-08-28 14:56:16 -07001460 /* Wait 15ms for MAC to configure PHY from eeprom settings */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001461 msleep(15);
Auke Kokcd94dd02006-06-27 09:08:22 -07001462 if (hw->mac_type != e1000_ich8lan) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001463 /* Configure activity LED after PHY reset */
1464 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1465 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1466 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1467 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
Auke Kokcd94dd02006-06-27 09:08:22 -07001468 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001469
Jeff Kirsherc9c1b832006-08-16 13:38:54 -07001470 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1471 if (hw->phy_type == e1000_phy_igp) {
1472 /* disable lplu d3 during driver init */
1473 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1474 if (ret_val) {
1475 DEBUGOUT("Error Disabling LPLU D3\n");
1476 return ret_val;
1477 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001478 }
1479
1480 /* disable lplu d0 during driver init */
1481 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1482 if (ret_val) {
1483 DEBUGOUT("Error Disabling LPLU D0\n");
1484 return ret_val;
1485 }
1486 /* Configure mdi-mdix settings */
1487 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1488 if (ret_val)
1489 return ret_val;
1490
1491 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1492 hw->dsp_config_state = e1000_dsp_config_disabled;
1493 /* Force MDI for earlier revs of the IGP PHY */
1494 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1495 hw->mdix = 1;
1496
1497 } else {
1498 hw->dsp_config_state = e1000_dsp_config_enabled;
1499 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1500
1501 switch (hw->mdix) {
1502 case 1:
1503 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1504 break;
1505 case 2:
1506 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1507 break;
1508 case 0:
1509 default:
1510 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1511 break;
1512 }
1513 }
1514 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001515 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001516 return ret_val;
1517
1518 /* set auto-master slave resolution settings */
Auke Kok8fc897b2006-08-28 14:56:16 -07001519 if (hw->autoneg) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001520 e1000_ms_type phy_ms_setting = hw->master_slave;
1521
Auke Kok8fc897b2006-08-28 14:56:16 -07001522 if (hw->ffe_config_state == e1000_ffe_config_active)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001523 hw->ffe_config_state = e1000_ffe_config_enabled;
1524
Auke Kok8fc897b2006-08-28 14:56:16 -07001525 if (hw->dsp_config_state == e1000_dsp_config_activated)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001526 hw->dsp_config_state = e1000_dsp_config_enabled;
1527
1528 /* when autonegotiation advertisment is only 1000Mbps then we
1529 * should disable SmartSpeed and enable Auto MasterSlave
1530 * resolution as hardware default. */
Auke Kok8fc897b2006-08-28 14:56:16 -07001531 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001532 /* Disable SmartSpeed */
Auke Kok8fc897b2006-08-28 14:56:16 -07001533 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1534 &phy_data);
1535 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001537 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Auke Kok8fc897b2006-08-28 14:56:16 -07001538 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1539 phy_data);
1540 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001542 /* Set auto Master/Slave resolution process */
1543 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001544 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001545 return ret_val;
1546 phy_data &= ~CR_1000T_MS_ENABLE;
1547 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001548 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001549 return ret_val;
1550 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001552 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001553 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001554 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001556 /* load defaults for future use */
1557 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1558 ((phy_data & CR_1000T_MS_VALUE) ?
1559 e1000_ms_force_master :
1560 e1000_ms_force_slave) :
1561 e1000_ms_auto;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001563 switch (phy_ms_setting) {
1564 case e1000_ms_force_master:
1565 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1566 break;
1567 case e1000_ms_force_slave:
1568 phy_data |= CR_1000T_MS_ENABLE;
1569 phy_data &= ~(CR_1000T_MS_VALUE);
1570 break;
1571 case e1000_ms_auto:
1572 phy_data &= ~CR_1000T_MS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 default:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001574 break;
1575 }
1576 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001577 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001578 return ret_val;
Malli Chilakala2b028932005-06-17 17:46:06 -07001579 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
Malli Chilakala2b028932005-06-17 17:46:06 -07001581 return E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001582}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001584/********************************************************************
1585* Copper link setup for e1000_phy_gg82563 series.
1586*
1587* hw - Struct containing variables accessed by shared code
1588*********************************************************************/
1589static int32_t
1590e1000_copper_link_ggp_setup(struct e1000_hw *hw)
1591{
1592 int32_t ret_val;
1593 uint16_t phy_data;
1594 uint32_t reg_data;
1595
1596 DEBUGFUNC("e1000_copper_link_ggp_setup");
1597
Auke Kok8fc897b2006-08-28 14:56:16 -07001598 if (!hw->phy_reset_disable) {
Auke Kok76c224b2006-05-23 13:36:06 -07001599
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001600 /* Enable CRS on TX for half-duplex operation. */
1601 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1602 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001603 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001604 return ret_val;
1605
1606 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
1607 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
1608 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
1609
1610 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
1611 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001612 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001613 return ret_val;
1614
1615 /* Options:
1616 * MDI/MDI-X = 0 (default)
1617 * 0 - Auto for all speeds
1618 * 1 - MDI mode
1619 * 2 - MDI-X mode
1620 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1621 */
1622 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001623 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001624 return ret_val;
1625
1626 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
1627
1628 switch (hw->mdix) {
1629 case 1:
1630 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
1631 break;
1632 case 2:
1633 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
1634 break;
1635 case 0:
1636 default:
1637 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
1638 break;
1639 }
1640
1641 /* Options:
1642 * disable_polarity_correction = 0 (default)
1643 * Automatic Correction for Reversed Cable Polarity
1644 * 0 - Disabled
1645 * 1 - Enabled
1646 */
1647 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
Auke Kok8fc897b2006-08-28 14:56:16 -07001648 if (hw->disable_polarity_correction == 1)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001649 phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
1650 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
1651
Auke Kok8fc897b2006-08-28 14:56:16 -07001652 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001653 return ret_val;
1654
1655 /* SW Reset the PHY so all changes take effect */
1656 ret_val = e1000_phy_reset(hw);
1657 if (ret_val) {
1658 DEBUGOUT("Error Resetting the PHY\n");
1659 return ret_val;
1660 }
1661 } /* phy_reset_disable */
1662
1663 if (hw->mac_type == e1000_80003es2lan) {
1664 /* Bypass RX and TX FIFO's */
1665 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
1666 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
1667 E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
1668 if (ret_val)
1669 return ret_val;
1670
1671 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
1672 if (ret_val)
1673 return ret_val;
1674
1675 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
1676 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
1677
1678 if (ret_val)
1679 return ret_val;
1680
1681 reg_data = E1000_READ_REG(hw, CTRL_EXT);
1682 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
1683 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
1684
1685 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1686 &phy_data);
1687 if (ret_val)
1688 return ret_val;
1689
1690 /* Do not init these registers when the HW is in IAMT mode, since the
1691 * firmware will have already initialized them. We only initialize
1692 * them if the HW is not in IAMT mode.
1693 */
1694 if (e1000_check_mng_mode(hw) == FALSE) {
1695 /* Enable Electrical Idle on the PHY */
1696 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
1697 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
1698 phy_data);
1699 if (ret_val)
1700 return ret_val;
1701
1702 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1703 &phy_data);
1704 if (ret_val)
1705 return ret_val;
1706
Auke Kokcd94dd02006-06-27 09:08:22 -07001707 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001708 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
1709 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001710
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001711 if (ret_val)
1712 return ret_val;
1713 }
1714
1715 /* Workaround: Disable padding in Kumeran interface in the MAC
1716 * and in the PHY to avoid CRC errors.
1717 */
1718 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1719 &phy_data);
1720 if (ret_val)
1721 return ret_val;
1722 phy_data |= GG82563_ICR_DIS_PADDING;
1723 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
1724 phy_data);
1725 if (ret_val)
1726 return ret_val;
1727 }
1728
1729 return E1000_SUCCESS;
1730}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001732/********************************************************************
1733* Copper link setup for e1000_phy_m88 series.
1734*
1735* hw - Struct containing variables accessed by shared code
1736*********************************************************************/
1737static int32_t
1738e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1739{
1740 int32_t ret_val;
1741 uint16_t phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001743 DEBUGFUNC("e1000_copper_link_mgp_setup");
1744
Auke Kok8fc897b2006-08-28 14:56:16 -07001745 if (hw->phy_reset_disable)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001746 return E1000_SUCCESS;
Auke Kok76c224b2006-05-23 13:36:06 -07001747
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001748 /* Enable CRS on TX. This must be set for half-duplex operation. */
1749 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07001750 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001751 return ret_val;
1752
1753 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1754
1755 /* Options:
1756 * MDI/MDI-X = 0 (default)
1757 * 0 - Auto for all speeds
1758 * 1 - MDI mode
1759 * 2 - MDI-X mode
1760 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1761 */
1762 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1763
1764 switch (hw->mdix) {
1765 case 1:
1766 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1767 break;
1768 case 2:
1769 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1770 break;
1771 case 3:
1772 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1773 break;
1774 case 0:
1775 default:
1776 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1777 break;
1778 }
1779
1780 /* Options:
1781 * disable_polarity_correction = 0 (default)
1782 * Automatic Correction for Reversed Cable Polarity
1783 * 0 - Disabled
1784 * 1 - Enabled
1785 */
1786 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kok8fc897b2006-08-28 14:56:16 -07001787 if (hw->disable_polarity_correction == 1)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001788 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
Auke Kokee040222006-06-27 09:08:03 -07001789 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1790 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001791 return ret_val;
1792
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001793 if (hw->phy_revision < M88E1011_I_REV_4) {
Auke Kokee040222006-06-27 09:08:03 -07001794 /* Force TX_CLK in the Extended PHY Specific Control Register
1795 * to 25MHz clock.
1796 */
1797 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1798 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001799 return ret_val;
Auke Kokee040222006-06-27 09:08:03 -07001800
1801 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1802
1803 if ((hw->phy_revision == E1000_REVISION_2) &&
1804 (hw->phy_id == M88E1111_I_PHY_ID)) {
1805 /* Vidalia Phy, set the downshift counter to 5x */
1806 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1807 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1808 ret_val = e1000_write_phy_reg(hw,
1809 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1810 if (ret_val)
1811 return ret_val;
1812 } else {
1813 /* Configure Master and Slave downshift values */
1814 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1815 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1816 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1817 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1818 ret_val = e1000_write_phy_reg(hw,
1819 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1820 if (ret_val)
1821 return ret_val;
1822 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001823 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001825 /* SW Reset the PHY so all changes take effect */
1826 ret_val = e1000_phy_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001827 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001828 DEBUGOUT("Error Resetting the PHY\n");
1829 return ret_val;
1830 }
1831
1832 return E1000_SUCCESS;
1833}
1834
1835/********************************************************************
1836* Setup auto-negotiation and flow control advertisements,
1837* and then perform auto-negotiation.
1838*
1839* hw - Struct containing variables accessed by shared code
1840*********************************************************************/
1841static int32_t
1842e1000_copper_link_autoneg(struct e1000_hw *hw)
1843{
1844 int32_t ret_val;
1845 uint16_t phy_data;
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 Kok8fc897b2006-08-28 14:56:16 -07001857 if (hw->autoneg_advertised == 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001858 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1859
Auke Kokcd94dd02006-06-27 09:08:22 -07001860 /* 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 Chilakala2d7edb92005-04-28 19:43:52 -07001864 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1865 ret_val = e1000_phy_setup_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001866 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001867 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 Kok8fc897b2006-08-28 14:56:16 -07001876 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001877 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 Kok8fc897b2006-08-28 14:56:16 -07001881 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001882 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 Kok8fc897b2006-08-28 14:56:16 -07001887 if (hw->wait_autoneg_complete) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001888 ret_val = e1000_wait_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001889 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001890 DEBUGOUT("Error while waiting for autoneg to complete\n");
1891 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001893 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001895 hw->get_link_status = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001897 return E1000_SUCCESS;
1898}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001900/******************************************************************************
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 Kok76c224b2006-05-23 13:36:06 -07001908* 3) Config DSP to improve Gigabit link quality for some PHY revisions.
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001909*
1910* hw - Struct containing variables accessed by shared code
1911******************************************************************************/
1912static int32_t
1913e1000_copper_link_postconfig(struct e1000_hw *hw)
1914{
1915 int32_t ret_val;
1916 DEBUGFUNC("e1000_copper_link_postconfig");
Auke Kok76c224b2006-05-23 13:36:06 -07001917
Auke Kok8fc897b2006-08-28 14:56:16 -07001918 if (hw->mac_type >= e1000_82544) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001919 e1000_config_collision_dist(hw);
1920 } else {
1921 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001922 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001923 DEBUGOUT("Error configuring MAC to PHY settings\n");
1924 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001926 }
1927 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001928 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001929 DEBUGOUT("Error Configuring Flow Control\n");
1930 return ret_val;
1931 }
1932
1933 /* Config DSP to improve Giga link quality */
Auke Kok8fc897b2006-08-28 14:56:16 -07001934 if (hw->phy_type == e1000_phy_igp) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001935 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
Auke Kok8fc897b2006-08-28 14:56:16 -07001936 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001937 DEBUGOUT("Error Configuring DSP after link up\n");
1938 return ret_val;
1939 }
1940 }
Auke Kok76c224b2006-05-23 13:36:06 -07001941
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001942 return E1000_SUCCESS;
1943}
1944
1945/******************************************************************************
1946* Detects which PHY is present and setup the speed and duplex
1947*
1948* hw - Struct containing variables accessed by shared code
1949******************************************************************************/
1950static int32_t
1951e1000_setup_copper_link(struct e1000_hw *hw)
1952{
1953 int32_t ret_val;
1954 uint16_t i;
1955 uint16_t phy_data;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001956 uint16_t reg_data;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001957
1958 DEBUGFUNC("e1000_setup_copper_link");
1959
Auke Kokcd94dd02006-06-27 09:08:22 -07001960 switch (hw->mac_type) {
1961 case e1000_80003es2lan:
1962 case e1000_ich8lan:
1963 /* Set the mac to wait the maximum time between each
1964 * iteration and increase the max iterations when
1965 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
1966 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
1967 if (ret_val)
1968 return ret_val;
1969 ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
1970 if (ret_val)
1971 return ret_val;
1972 reg_data |= 0x3F;
1973 ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
1974 if (ret_val)
1975 return ret_val;
1976 default:
1977 break;
1978 }
1979
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001980 /* Check if it is a valid PHY and set PHY mode if necessary. */
1981 ret_val = e1000_copper_link_preconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07001982 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001983 return ret_val;
1984
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001985 switch (hw->mac_type) {
1986 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07001987 /* Kumeran registers are written-only */
1988 reg_data = E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001989 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
1990 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
1991 reg_data);
1992 if (ret_val)
1993 return ret_val;
1994 break;
1995 default:
1996 break;
1997 }
1998
Malli Chilakala2d7edb92005-04-28 19:43:52 -07001999 if (hw->phy_type == e1000_phy_igp ||
Auke Kokcd94dd02006-06-27 09:08:22 -07002000 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002001 hw->phy_type == e1000_phy_igp_2) {
2002 ret_val = e1000_copper_link_igp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002003 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002004 return ret_val;
2005 } else if (hw->phy_type == e1000_phy_m88) {
2006 ret_val = e1000_copper_link_mgp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002007 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002008 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002009 } else if (hw->phy_type == e1000_phy_gg82563) {
2010 ret_val = e1000_copper_link_ggp_setup(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002011 if (ret_val)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002012 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002013 }
2014
Auke Kok8fc897b2006-08-28 14:56:16 -07002015 if (hw->autoneg) {
Auke Kok76c224b2006-05-23 13:36:06 -07002016 /* Setup autoneg and flow control advertisement
2017 * and perform autonegotiation */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002018 ret_val = e1000_copper_link_autoneg(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002019 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07002020 return ret_val;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002021 } else {
2022 /* PHY will be set to 10H, 10F, 100H,or 100F
2023 * depending on value from forced_speed_duplex. */
2024 DEBUGOUT("Forcing speed and duplex\n");
2025 ret_val = e1000_phy_force_speed_duplex(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002026 if (ret_val) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002027 DEBUGOUT("Error Forcing Speed and Duplex\n");
2028 return ret_val;
2029 }
2030 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
2032 /* Check link status. Wait up to 100 microseconds for link to become
2033 * valid.
2034 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002035 for (i = 0; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002037 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 return ret_val;
2039 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002040 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 return ret_val;
2042
Auke Kok8fc897b2006-08-28 14:56:16 -07002043 if (phy_data & MII_SR_LINK_STATUS) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002044 /* Config the MAC and PHY after link is up */
2045 ret_val = e1000_copper_link_postconfig(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002046 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 return ret_val;
Auke Kok76c224b2006-05-23 13:36:06 -07002048
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 DEBUGOUT("Valid link established!!!\n");
2050 return E1000_SUCCESS;
2051 }
2052 udelay(10);
2053 }
2054
2055 DEBUGOUT("Unable to establish link!!!\n");
2056 return E1000_SUCCESS;
2057}
2058
2059/******************************************************************************
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002060* Configure the MAC-to-PHY interface for 10/100Mbps
2061*
2062* hw - Struct containing variables accessed by shared code
2063******************************************************************************/
2064static int32_t
Auke Kokcd94dd02006-06-27 09:08:22 -07002065e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002066{
2067 int32_t ret_val = E1000_SUCCESS;
2068 uint32_t tipg;
2069 uint16_t reg_data;
2070
2071 DEBUGFUNC("e1000_configure_kmrn_for_10_100");
2072
2073 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
2074 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2075 reg_data);
2076 if (ret_val)
2077 return ret_val;
2078
2079 /* Configure Transmit Inter-Packet Gap */
2080 tipg = E1000_READ_REG(hw, TIPG);
2081 tipg &= ~E1000_TIPG_IPGT_MASK;
2082 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
2083 E1000_WRITE_REG(hw, TIPG, tipg);
2084
Auke Kokcd94dd02006-06-27 09:08:22 -07002085 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2086
2087 if (ret_val)
2088 return ret_val;
2089
2090 if (duplex == HALF_DUPLEX)
2091 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
2092 else
2093 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2094
2095 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2096
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002097 return ret_val;
2098}
2099
2100static int32_t
2101e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
2102{
2103 int32_t ret_val = E1000_SUCCESS;
2104 uint16_t reg_data;
2105 uint32_t tipg;
2106
2107 DEBUGFUNC("e1000_configure_kmrn_for_1000");
2108
2109 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
2110 ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
2111 reg_data);
2112 if (ret_val)
2113 return ret_val;
2114
2115 /* Configure Transmit Inter-Packet Gap */
2116 tipg = E1000_READ_REG(hw, TIPG);
2117 tipg &= ~E1000_TIPG_IPGT_MASK;
2118 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2119 E1000_WRITE_REG(hw, TIPG, tipg);
2120
Auke Kokcd94dd02006-06-27 09:08:22 -07002121 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
2122
2123 if (ret_val)
2124 return ret_val;
2125
2126 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2127 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
2128
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002129 return ret_val;
2130}
2131
2132/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133* Configures PHY autoneg and flow control advertisement settings
2134*
2135* hw - Struct containing variables accessed by shared code
2136******************************************************************************/
2137int32_t
2138e1000_phy_setup_autoneg(struct e1000_hw *hw)
2139{
2140 int32_t ret_val;
2141 uint16_t mii_autoneg_adv_reg;
2142 uint16_t mii_1000t_ctrl_reg;
2143
2144 DEBUGFUNC("e1000_phy_setup_autoneg");
2145
2146 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
2147 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002148 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 return ret_val;
2150
Auke Kokcd94dd02006-06-27 09:08:22 -07002151 if (hw->phy_type != e1000_phy_ife) {
2152 /* Read the MII 1000Base-T Control Register (Address 9). */
2153 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
2154 if (ret_val)
2155 return ret_val;
2156 } else
2157 mii_1000t_ctrl_reg=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
2159 /* Need to parse both autoneg_advertised and fc and set up
2160 * the appropriate PHY registers. First we will parse for
2161 * autoneg_advertised software override. Since we can advertise
2162 * a plethora of combinations, we need to check each bit
2163 * individually.
2164 */
2165
2166 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
2167 * Advertisement Register (Address 4) and the 1000 mb speed bits in
2168 * the 1000Base-T Control Register (Address 9).
2169 */
2170 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
2171 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
2172
2173 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
2174
2175 /* Do we want to advertise 10 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002176 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 DEBUGOUT("Advertise 10mb Half duplex\n");
2178 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
2179 }
2180
2181 /* Do we want to advertise 10 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002182 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 DEBUGOUT("Advertise 10mb Full duplex\n");
2184 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
2185 }
2186
2187 /* Do we want to advertise 100 Mb Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002188 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 DEBUGOUT("Advertise 100mb Half duplex\n");
2190 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
2191 }
2192
2193 /* Do we want to advertise 100 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002194 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 DEBUGOUT("Advertise 100mb Full duplex\n");
2196 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
2197 }
2198
2199 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
Auke Kok8fc897b2006-08-28 14:56:16 -07002200 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
2202 }
2203
2204 /* Do we want to advertise 1000 Mb Full Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002205 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 DEBUGOUT("Advertise 1000mb Full duplex\n");
2207 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
Auke Kokcd94dd02006-06-27 09:08:22 -07002208 if (hw->phy_type == e1000_phy_ife) {
2209 DEBUGOUT("e1000_phy_ife is a 10/100 PHY. Gigabit speed is not supported.\n");
2210 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 }
2212
2213 /* Check for a software override of the flow control settings, and
2214 * setup the PHY advertisement registers accordingly. If
2215 * auto-negotiation is enabled, then software will have to set the
2216 * "PAUSE" bits to the correct value in the Auto-Negotiation
2217 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
2218 *
2219 * The possible values of the "fc" parameter are:
2220 * 0: Flow control is completely disabled
2221 * 1: Rx flow control is enabled (we can receive pause frames
2222 * but not send pause frames).
2223 * 2: Tx flow control is enabled (we can send pause frames
2224 * but we do not support receiving pause frames).
2225 * 3: Both Rx and TX flow control (symmetric) are enabled.
2226 * other: No software override. The flow control configuration
2227 * in the EEPROM is used.
2228 */
2229 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002230 case E1000_FC_NONE: /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 /* Flow control (RX & TX) is completely disabled by a
2232 * software over-ride.
2233 */
2234 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2235 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002236 case E1000_FC_RX_PAUSE: /* 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 /* RX Flow control is enabled, and TX Flow control is
2238 * disabled, by a software over-ride.
2239 */
2240 /* Since there really isn't a way to advertise that we are
2241 * capable of RX Pause ONLY, we will advertise that we
2242 * support both symmetric and asymmetric RX PAUSE. Later
2243 * (in e1000_config_fc_after_link_up) we will disable the
2244 *hw's ability to send PAUSE frames.
2245 */
2246 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2247 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002248 case E1000_FC_TX_PAUSE: /* 2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 /* TX Flow control is enabled, and RX Flow control is
2250 * disabled, by a software over-ride.
2251 */
2252 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
2253 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
2254 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002255 case E1000_FC_FULL: /* 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 /* Flow control (both RX and TX) is enabled by a software
2257 * over-ride.
2258 */
2259 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
2260 break;
2261 default:
2262 DEBUGOUT("Flow control param set incorrectly\n");
2263 return -E1000_ERR_CONFIG;
2264 }
2265
2266 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002267 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 return ret_val;
2269
2270 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
2271
Auke Kokcd94dd02006-06-27 09:08:22 -07002272 if (hw->phy_type != e1000_phy_ife) {
2273 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
2274 if (ret_val)
2275 return ret_val;
2276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277
2278 return E1000_SUCCESS;
2279}
2280
2281/******************************************************************************
2282* Force PHY speed and duplex settings to hw->forced_speed_duplex
2283*
2284* hw - Struct containing variables accessed by shared code
2285******************************************************************************/
2286static int32_t
2287e1000_phy_force_speed_duplex(struct e1000_hw *hw)
2288{
2289 uint32_t ctrl;
2290 int32_t ret_val;
2291 uint16_t mii_ctrl_reg;
2292 uint16_t mii_status_reg;
2293 uint16_t phy_data;
2294 uint16_t i;
2295
2296 DEBUGFUNC("e1000_phy_force_speed_duplex");
2297
2298 /* Turn off Flow control if we are forcing speed and duplex. */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002299 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
2301 DEBUGOUT1("hw->fc = %d\n", hw->fc);
2302
2303 /* Read the Device Control Register. */
2304 ctrl = E1000_READ_REG(hw, CTRL);
2305
2306 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
2307 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2308 ctrl &= ~(DEVICE_SPEED_MASK);
2309
2310 /* Clear the Auto Speed Detect Enable bit. */
2311 ctrl &= ~E1000_CTRL_ASDE;
2312
2313 /* Read the MII Control Register. */
2314 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002315 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 return ret_val;
2317
2318 /* We need to disable autoneg in order to force link and duplex. */
2319
2320 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
2321
2322 /* Are we forcing Full or Half Duplex? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002323 if (hw->forced_speed_duplex == e1000_100_full ||
2324 hw->forced_speed_duplex == e1000_10_full) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 /* We want to force full duplex so we SET the full duplex bits in the
2326 * Device and MII Control Registers.
2327 */
2328 ctrl |= E1000_CTRL_FD;
2329 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
2330 DEBUGOUT("Full Duplex\n");
2331 } else {
2332 /* We want to force half duplex so we CLEAR the full duplex bits in
2333 * the Device and MII Control Registers.
2334 */
2335 ctrl &= ~E1000_CTRL_FD;
2336 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
2337 DEBUGOUT("Half Duplex\n");
2338 }
2339
2340 /* Are we forcing 100Mbps??? */
Auke Kok8fc897b2006-08-28 14:56:16 -07002341 if (hw->forced_speed_duplex == e1000_100_full ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 hw->forced_speed_duplex == e1000_100_half) {
2343 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
2344 ctrl |= E1000_CTRL_SPD_100;
2345 mii_ctrl_reg |= MII_CR_SPEED_100;
2346 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
2347 DEBUGOUT("Forcing 100mb ");
2348 } else {
2349 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
2350 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
2351 mii_ctrl_reg |= MII_CR_SPEED_10;
2352 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
2353 DEBUGOUT("Forcing 10mb ");
2354 }
2355
2356 e1000_config_collision_dist(hw);
2357
2358 /* Write the configured values back to the Device Control Reg. */
2359 E1000_WRITE_REG(hw, CTRL, ctrl);
2360
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002361 if ((hw->phy_type == e1000_phy_m88) ||
2362 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002364 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 return ret_val;
2366
2367 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
2368 * forced whenever speed are duplex are forced.
2369 */
2370 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2371 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002372 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 return ret_val;
2374
2375 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
2376
2377 /* Need to reset the PHY or these changes will be ignored */
2378 mii_ctrl_reg |= MII_CR_RESET;
Auke Kok90fb5132006-11-01 08:47:30 -08002379
Auke Kokcd94dd02006-06-27 09:08:22 -07002380 /* Disable MDI-X support for 10/100 */
2381 } else if (hw->phy_type == e1000_phy_ife) {
2382 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
2383 if (ret_val)
2384 return ret_val;
2385
2386 phy_data &= ~IFE_PMC_AUTO_MDIX;
2387 phy_data &= ~IFE_PMC_FORCE_MDIX;
2388
2389 ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, phy_data);
2390 if (ret_val)
2391 return ret_val;
Auke Kok90fb5132006-11-01 08:47:30 -08002392
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 } else {
2394 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
2395 * forced whenever speed or duplex are forced.
2396 */
2397 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002398 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 return ret_val;
2400
2401 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2402 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2403
2404 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002405 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 return ret_val;
2407 }
2408
2409 /* Write back the modified PHY MII control register. */
2410 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002411 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 return ret_val;
2413
2414 udelay(1);
2415
2416 /* The wait_autoneg_complete flag may be a little misleading here.
2417 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
2418 * But we do want to delay for a period while forcing only so we
2419 * don't generate false No Link messages. So we will wait here
2420 * only if the user has set wait_autoneg_complete to 1, which is
2421 * the default.
2422 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002423 if (hw->wait_autoneg_complete) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 /* We will wait for autoneg to complete. */
2425 DEBUGOUT("Waiting for forced speed/duplex link.\n");
2426 mii_status_reg = 0;
2427
2428 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002429 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2431 * to be set.
2432 */
2433 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002434 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 return ret_val;
2436
2437 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002438 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 return ret_val;
2440
Auke Kok8fc897b2006-08-28 14:56:16 -07002441 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002442 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 }
Auke Kok8fc897b2006-08-28 14:56:16 -07002444 if ((i == 0) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002445 ((hw->phy_type == e1000_phy_m88) ||
2446 (hw->phy_type == e1000_phy_gg82563))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 /* We didn't get link. Reset the DSP and wait again for link. */
2448 ret_val = e1000_phy_reset_dsp(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002449 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 DEBUGOUT("Error Resetting PHY DSP\n");
2451 return ret_val;
2452 }
2453 }
2454 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07002455 for (i = PHY_FORCE_TIME; i > 0; i--) {
2456 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04002457 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 /* Read the MII Status Register and wait for Auto-Neg Complete bit
2459 * to be set.
2460 */
2461 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002462 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 return ret_val;
2464
2465 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002466 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 return ret_val;
2468 }
2469 }
2470
2471 if (hw->phy_type == e1000_phy_m88) {
2472 /* Because we reset the PHY above, we need to re-force TX_CLK in the
2473 * Extended PHY Specific Control Register to 25MHz clock. This value
2474 * defaults back to a 2.5MHz clock when the PHY is reset.
2475 */
2476 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002477 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 return ret_val;
2479
2480 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2481 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002482 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 return ret_val;
2484
2485 /* In addition, because of the s/w reset above, we need to enable CRS on
2486 * TX. This must be set for both full and half duplex operation.
2487 */
2488 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002489 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 return ret_val;
2491
2492 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2493 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002494 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 return ret_val;
2496
Auke Kok8fc897b2006-08-28 14:56:16 -07002497 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2498 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
2499 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 ret_val = e1000_polarity_reversal_workaround(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002501 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 return ret_val;
2503 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08002504 } else if (hw->phy_type == e1000_phy_gg82563) {
2505 /* The TX_CLK of the Extended PHY Specific Control Register defaults
2506 * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
2507 * we're not in a forced 10/duplex configuration. */
2508 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2509 if (ret_val)
2510 return ret_val;
2511
2512 phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
2513 if ((hw->forced_speed_duplex == e1000_10_full) ||
2514 (hw->forced_speed_duplex == e1000_10_half))
2515 phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
2516 else
2517 phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
2518
2519 /* Also due to the reset, we need to enable CRS on Tx. */
2520 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2521
2522 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2523 if (ret_val)
2524 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 }
2526 return E1000_SUCCESS;
2527}
2528
2529/******************************************************************************
2530* Sets the collision distance in the Transmit Control register
2531*
2532* hw - Struct containing variables accessed by shared code
2533*
2534* Link should have been established previously. Reads the speed and duplex
2535* information from the Device Status register.
2536******************************************************************************/
2537void
2538e1000_config_collision_dist(struct e1000_hw *hw)
2539{
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002540 uint32_t tctl, coll_dist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541
2542 DEBUGFUNC("e1000_config_collision_dist");
2543
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002544 if (hw->mac_type < e1000_82543)
2545 coll_dist = E1000_COLLISION_DISTANCE_82542;
2546 else
2547 coll_dist = E1000_COLLISION_DISTANCE;
2548
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 tctl = E1000_READ_REG(hw, TCTL);
2550
2551 tctl &= ~E1000_TCTL_COLD;
Jeff Kirsher0fadb052006-01-12 16:51:05 -08002552 tctl |= coll_dist << E1000_COLD_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553
2554 E1000_WRITE_REG(hw, TCTL, tctl);
2555 E1000_WRITE_FLUSH(hw);
2556}
2557
2558/******************************************************************************
2559* Sets MAC speed and duplex settings to reflect the those in the PHY
2560*
2561* hw - Struct containing variables accessed by shared code
2562* mii_reg - data to write to the MII control register
2563*
2564* The contents of the PHY register containing the needed information need to
2565* be passed in.
2566******************************************************************************/
2567static int32_t
2568e1000_config_mac_to_phy(struct e1000_hw *hw)
2569{
2570 uint32_t ctrl;
2571 int32_t ret_val;
2572 uint16_t phy_data;
2573
2574 DEBUGFUNC("e1000_config_mac_to_phy");
2575
Auke Kok76c224b2006-05-23 13:36:06 -07002576 /* 82544 or newer MAC, Auto Speed Detection takes care of
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002577 * MAC speed/duplex configuration.*/
2578 if (hw->mac_type >= e1000_82544)
2579 return E1000_SUCCESS;
2580
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 /* Read the Device Control Register and set the bits to Force Speed
2582 * and Duplex.
2583 */
2584 ctrl = E1000_READ_REG(hw, CTRL);
2585 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2586 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
2587
2588 /* Set up duplex in the Device Control and Transmit Control
2589 * registers depending on negotiated values.
2590 */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002591 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002592 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002593 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594
Auke Kok8fc897b2006-08-28 14:56:16 -07002595 if (phy_data & M88E1000_PSSR_DPLX)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002596 ctrl |= E1000_CTRL_FD;
Auke Kok76c224b2006-05-23 13:36:06 -07002597 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002598 ctrl &= ~E1000_CTRL_FD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002600 e1000_config_collision_dist(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002602 /* Set up speed in the Device Control register depending on
2603 * negotiated values.
2604 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002605 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002606 ctrl |= E1000_CTRL_SPD_1000;
Auke Kok8fc897b2006-08-28 14:56:16 -07002607 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07002608 ctrl |= E1000_CTRL_SPD_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 /* Write the configured values back to the Device Control Reg. */
2611 E1000_WRITE_REG(hw, CTRL, ctrl);
2612 return E1000_SUCCESS;
2613}
2614
2615/******************************************************************************
2616 * Forces the MAC's flow control settings.
2617 *
2618 * hw - Struct containing variables accessed by shared code
2619 *
2620 * Sets the TFCE and RFCE bits in the device control register to reflect
2621 * the adapter settings. TFCE and RFCE need to be explicitly set by
2622 * software when a Copper PHY is used because autonegotiation is managed
2623 * by the PHY rather than the MAC. Software must also configure these
2624 * bits when link is forced on a fiber connection.
2625 *****************************************************************************/
2626int32_t
2627e1000_force_mac_fc(struct e1000_hw *hw)
2628{
2629 uint32_t ctrl;
2630
2631 DEBUGFUNC("e1000_force_mac_fc");
2632
2633 /* Get the current configuration of the Device Control Register */
2634 ctrl = E1000_READ_REG(hw, CTRL);
2635
2636 /* Because we didn't get link via the internal auto-negotiation
2637 * mechanism (we either forced link or we got link via PHY
2638 * auto-neg), we have to manually enable/disable transmit an
2639 * receive flow control.
2640 *
2641 * The "Case" statement below enables/disable flow control
2642 * according to the "hw->fc" parameter.
2643 *
2644 * The possible values of the "fc" parameter are:
2645 * 0: Flow control is completely disabled
2646 * 1: Rx flow control is enabled (we can receive pause
2647 * frames but not send pause frames).
2648 * 2: Tx flow control is enabled (we can send pause frames
2649 * frames but we do not receive pause frames).
2650 * 3: Both Rx and TX flow control (symmetric) is enabled.
2651 * other: No other values should be possible at this point.
2652 */
2653
2654 switch (hw->fc) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002655 case E1000_FC_NONE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2657 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002658 case E1000_FC_RX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 ctrl &= (~E1000_CTRL_TFCE);
2660 ctrl |= E1000_CTRL_RFCE;
2661 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002662 case E1000_FC_TX_PAUSE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 ctrl &= (~E1000_CTRL_RFCE);
2664 ctrl |= E1000_CTRL_TFCE;
2665 break;
Jeff Kirsher11241b12006-09-27 12:53:28 -07002666 case E1000_FC_FULL:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2668 break;
2669 default:
2670 DEBUGOUT("Flow control param set incorrectly\n");
2671 return -E1000_ERR_CONFIG;
2672 }
2673
2674 /* Disable TX Flow Control for 82542 (rev 2.0) */
Auke Kok8fc897b2006-08-28 14:56:16 -07002675 if (hw->mac_type == e1000_82542_rev2_0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 ctrl &= (~E1000_CTRL_TFCE);
2677
2678 E1000_WRITE_REG(hw, CTRL, ctrl);
2679 return E1000_SUCCESS;
2680}
2681
2682/******************************************************************************
2683 * Configures flow control settings after link is established
2684 *
2685 * hw - Struct containing variables accessed by shared code
2686 *
2687 * Should be called immediately after a valid link has been established.
2688 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2689 * and autonegotiation is enabled, the MAC flow control settings will be set
2690 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2691 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2692 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01002693static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694e1000_config_fc_after_link_up(struct e1000_hw *hw)
2695{
2696 int32_t ret_val;
2697 uint16_t mii_status_reg;
2698 uint16_t mii_nway_adv_reg;
2699 uint16_t mii_nway_lp_ability_reg;
2700 uint16_t speed;
2701 uint16_t duplex;
2702
2703 DEBUGFUNC("e1000_config_fc_after_link_up");
2704
2705 /* Check for the case where we have fiber media and auto-neg failed
2706 * so we had to force link. In this case, we need to force the
2707 * configuration of the MAC to match the "fc" parameter.
2708 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002709 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2710 ((hw->media_type == e1000_media_type_internal_serdes) &&
2711 (hw->autoneg_failed)) ||
2712 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002714 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 DEBUGOUT("Error forcing flow control settings\n");
2716 return ret_val;
2717 }
2718 }
2719
2720 /* Check for the case where we have copper media and auto-neg is
2721 * enabled. In this case, we need to check and see if Auto-Neg
2722 * has completed, and if so, how the PHY and link partner has
2723 * flow control configured.
2724 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002725 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 /* Read the MII Status Register and check to see if AutoNeg
2727 * has completed. We read this twice because this reg has
2728 * some "sticky" (latched) bits.
2729 */
2730 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002731 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 return ret_val;
2733 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002734 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 return ret_val;
2736
Auke Kok8fc897b2006-08-28 14:56:16 -07002737 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 /* The AutoNeg process has completed, so we now need to
2739 * read both the Auto Negotiation Advertisement Register
2740 * (Address 4) and the Auto_Negotiation Base Page Ability
2741 * Register (Address 5) to determine how flow control was
2742 * negotiated.
2743 */
2744 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2745 &mii_nway_adv_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002746 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 return ret_val;
2748 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2749 &mii_nway_lp_ability_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07002750 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 return ret_val;
2752
2753 /* Two bits in the Auto Negotiation Advertisement Register
2754 * (Address 4) and two bits in the Auto Negotiation Base
2755 * Page Ability Register (Address 5) determine flow control
2756 * for both the PHY and the link partner. The following
2757 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2758 * 1999, describes these PAUSE resolution bits and how flow
2759 * control is determined based upon these settings.
2760 * NOTE: DC = Don't Care
2761 *
2762 * LOCAL DEVICE | LINK PARTNER
2763 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2764 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002765 * 0 | 0 | DC | DC | E1000_FC_NONE
2766 * 0 | 1 | 0 | DC | E1000_FC_NONE
2767 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2768 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2769 * 1 | 0 | 0 | DC | E1000_FC_NONE
2770 * 1 | DC | 1 | DC | E1000_FC_FULL
2771 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2772 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 *
2774 */
2775 /* Are both PAUSE bits set to 1? If so, this implies
2776 * Symmetric Flow Control is enabled at both ends. The
2777 * ASM_DIR bits are irrelevant per the spec.
2778 *
2779 * For Symmetric Flow Control:
2780 *
2781 * LOCAL DEVICE | LINK PARTNER
2782 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2783 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002784 * 1 | DC | 1 | DC | E1000_FC_FULL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 *
2786 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002787 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2788 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 /* Now we need to check if the user selected RX ONLY
2790 * of pause frames. In this case, we had to advertise
2791 * FULL flow control because we could not advertise RX
2792 * ONLY. Hence, we must now check to see if we need to
2793 * turn OFF the TRANSMISSION of PAUSE frames.
2794 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002795 if (hw->original_fc == E1000_FC_FULL) {
2796 hw->fc = E1000_FC_FULL;
Auke Koka42a5072006-05-23 13:36:01 -07002797 DEBUGOUT("Flow Control = FULL.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002799 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002800 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 }
2802 }
2803 /* For receiving PAUSE frames ONLY.
2804 *
2805 * LOCAL DEVICE | LINK PARTNER
2806 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2807 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002808 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 *
2810 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002811 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2812 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2813 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2814 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002815 hw->fc = E1000_FC_TX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002816 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 }
2818 /* For transmitting PAUSE frames ONLY.
2819 *
2820 * LOCAL DEVICE | LINK PARTNER
2821 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2822 *-------|---------|-------|---------|--------------------
Jeff Kirsher11241b12006-09-27 12:53:28 -07002823 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 *
2825 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002826 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2827 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2828 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2829 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002830 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002831 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 }
2833 /* Per the IEEE spec, at this point flow control should be
2834 * disabled. However, we want to consider that we could
2835 * be connected to a legacy switch that doesn't advertise
2836 * desired flow control, but can be forced on the link
2837 * partner. So if we advertised no flow control, that is
2838 * what we will resolve to. If we advertised some kind of
2839 * receive capability (Rx Pause Only or Full Flow Control)
2840 * and the link partner advertised none, we will configure
2841 * ourselves to enable Rx Flow Control only. We can do
2842 * this safely for two reasons: If the link partner really
2843 * didn't want flow control enabled, and we enable Rx, no
2844 * harm done since we won't be receiving any PAUSE frames
2845 * anyway. If the intent on the link partner was to have
2846 * flow control enabled, then by us enabling RX only, we
2847 * can at least receive pause frames and process them.
2848 * This is a good idea because in most cases, since we are
2849 * predominantly a server NIC, more times than not we will
2850 * be asked to delay transmission of packets than asking
2851 * our link partner to pause transmission of frames.
2852 */
Jeff Kirsher11241b12006-09-27 12:53:28 -07002853 else if ((hw->original_fc == E1000_FC_NONE ||
2854 hw->original_fc == E1000_FC_TX_PAUSE) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07002855 hw->fc_strict_ieee) {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002856 hw->fc = E1000_FC_NONE;
Auke Koka42a5072006-05-23 13:36:01 -07002857 DEBUGOUT("Flow Control = NONE.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 } else {
Jeff Kirsher11241b12006-09-27 12:53:28 -07002859 hw->fc = E1000_FC_RX_PAUSE;
Auke Koka42a5072006-05-23 13:36:01 -07002860 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 }
2862
2863 /* Now we need to do one last check... If we auto-
2864 * negotiated to HALF DUPLEX, flow control should not be
2865 * enabled per IEEE 802.3 spec.
2866 */
2867 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07002868 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 DEBUGOUT("Error getting link speed and duplex\n");
2870 return ret_val;
2871 }
2872
Auke Kok8fc897b2006-08-28 14:56:16 -07002873 if (duplex == HALF_DUPLEX)
Jeff Kirsher11241b12006-09-27 12:53:28 -07002874 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875
2876 /* Now we call a subroutine to actually force the MAC
2877 * controller to use the correct flow control settings.
2878 */
2879 ret_val = e1000_force_mac_fc(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07002880 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 DEBUGOUT("Error forcing flow control settings\n");
2882 return ret_val;
2883 }
2884 } else {
Auke Koka42a5072006-05-23 13:36:01 -07002885 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 }
2887 }
2888 return E1000_SUCCESS;
2889}
2890
2891/******************************************************************************
2892 * Checks to see if the link status of the hardware has changed.
2893 *
2894 * hw - Struct containing variables accessed by shared code
2895 *
2896 * Called by any function that needs to check the link status of the adapter.
2897 *****************************************************************************/
2898int32_t
2899e1000_check_for_link(struct e1000_hw *hw)
2900{
2901 uint32_t rxcw = 0;
2902 uint32_t ctrl;
2903 uint32_t status;
2904 uint32_t rctl;
2905 uint32_t icr;
2906 uint32_t signal = 0;
2907 int32_t ret_val;
2908 uint16_t phy_data;
2909
2910 DEBUGFUNC("e1000_check_for_link");
2911
2912 ctrl = E1000_READ_REG(hw, CTRL);
2913 status = E1000_READ_REG(hw, STATUS);
2914
2915 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2916 * set when the optics detect a signal. On older adapters, it will be
2917 * cleared when there is a signal. This applies to fiber media only.
2918 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002919 if ((hw->media_type == e1000_media_type_fiber) ||
2920 (hw->media_type == e1000_media_type_internal_serdes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 rxcw = E1000_READ_REG(hw, RXCW);
2922
Auke Kok8fc897b2006-08-28 14:56:16 -07002923 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
Auke Kok8fc897b2006-08-28 14:56:16 -07002925 if (status & E1000_STATUS_LU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 hw->get_link_status = FALSE;
2927 }
2928 }
2929
2930 /* If we have a copper PHY then we only want to go out to the PHY
2931 * registers to see if Auto-Neg has completed and/or if our link
2932 * status has changed. The get_link_status flag will be set if we
2933 * receive a Link Status Change interrupt or we have Rx Sequence
2934 * Errors.
2935 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002936 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 /* First we want to see if the MII Status Register reports
2938 * link. If so, then we want to get the current speed/duplex
2939 * of the PHY.
2940 * Read the register twice since the link bit is sticky.
2941 */
2942 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002943 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 return ret_val;
2945 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07002946 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 return ret_val;
2948
Auke Kok8fc897b2006-08-28 14:56:16 -07002949 if (phy_data & MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 hw->get_link_status = FALSE;
2951 /* Check if there was DownShift, must be checked immediately after
2952 * link-up */
2953 e1000_check_downshift(hw);
2954
2955 /* If we are on 82544 or 82543 silicon and speed/duplex
2956 * are forced to 10H or 10F, then we will implement the polarity
2957 * reversal workaround. We disable interrupts first, and upon
2958 * returning, place the devices interrupt state to its previous
2959 * value except for the link status change interrupt which will
2960 * happen due to the execution of this workaround.
2961 */
2962
Auke Kok8fc897b2006-08-28 14:56:16 -07002963 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2964 (!hw->autoneg) &&
2965 (hw->forced_speed_duplex == e1000_10_full ||
2966 hw->forced_speed_duplex == e1000_10_half)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2968 ret_val = e1000_polarity_reversal_workaround(hw);
2969 icr = E1000_READ_REG(hw, ICR);
2970 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2971 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2972 }
2973
2974 } else {
2975 /* No link detected */
2976 e1000_config_dsp_after_link_change(hw, FALSE);
2977 return 0;
2978 }
2979
2980 /* If we are forcing speed/duplex, then we simply return since
2981 * we have already determined whether we have link or not.
2982 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002983 if (!hw->autoneg) return -E1000_ERR_CONFIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984
2985 /* optimize the dsp settings for the igp phy */
2986 e1000_config_dsp_after_link_change(hw, TRUE);
2987
2988 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2989 * have Si on board that is 82544 or newer, Auto
2990 * Speed Detection takes care of MAC speed/duplex
2991 * configuration. So we only need to configure Collision
2992 * Distance in the MAC. Otherwise, we need to force
2993 * speed/duplex on the MAC to the current PHY speed/duplex
2994 * settings.
2995 */
Auke Kok8fc897b2006-08-28 14:56:16 -07002996 if (hw->mac_type >= e1000_82544)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 e1000_config_collision_dist(hw);
2998 else {
2999 ret_val = e1000_config_mac_to_phy(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003000 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 DEBUGOUT("Error configuring MAC to PHY settings\n");
3002 return ret_val;
3003 }
3004 }
3005
3006 /* Configure Flow Control now that Auto-Neg has completed. First, we
3007 * need to restore the desired flow control settings because we may
3008 * have had to re-autoneg with a different link partner.
3009 */
3010 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003011 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 DEBUGOUT("Error configuring flow control\n");
3013 return ret_val;
3014 }
3015
3016 /* At this point we know that we are on copper and we have
3017 * auto-negotiated link. These are conditions for checking the link
3018 * partner capability register. We use the link speed to determine if
3019 * TBI compatibility needs to be turned on or off. If the link is not
3020 * at gigabit speed, then TBI compatibility is not needed. If we are
3021 * at gigabit speed, we turn on TBI compatibility.
3022 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003023 if (hw->tbi_compatibility_en) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 uint16_t speed, duplex;
Auke Kok592600a2006-06-27 09:08:09 -07003025 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
3026 if (ret_val) {
3027 DEBUGOUT("Error getting link speed and duplex\n");
3028 return ret_val;
3029 }
3030 if (speed != SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 /* If link speed is not set to gigabit speed, we do not need
3032 * to enable TBI compatibility.
3033 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003034 if (hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 /* If we previously were in the mode, turn it off. */
3036 rctl = E1000_READ_REG(hw, RCTL);
3037 rctl &= ~E1000_RCTL_SBP;
3038 E1000_WRITE_REG(hw, RCTL, rctl);
3039 hw->tbi_compatibility_on = FALSE;
3040 }
3041 } else {
3042 /* If TBI compatibility is was previously off, turn it on. For
3043 * compatibility with a TBI link partner, we will store bad
3044 * packets. Some frames have an additional byte on the end and
3045 * will look like CRC errors to to the hardware.
3046 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003047 if (!hw->tbi_compatibility_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 hw->tbi_compatibility_on = TRUE;
3049 rctl = E1000_READ_REG(hw, RCTL);
3050 rctl |= E1000_RCTL_SBP;
3051 E1000_WRITE_REG(hw, RCTL, rctl);
3052 }
3053 }
3054 }
3055 }
3056 /* If we don't have link (auto-negotiation failed or link partner cannot
3057 * auto-negotiate), the cable is plugged in (we have signal), and our
3058 * link partner is not trying to auto-negotiate with us (we are receiving
3059 * idles or data), we need to force link up. We also need to give
3060 * auto-negotiation time to complete, in case the cable was just plugged
3061 * in. The autoneg_failed flag does this.
3062 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003063 else if ((((hw->media_type == e1000_media_type_fiber) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
Auke Kok8fc897b2006-08-28 14:56:16 -07003065 (hw->media_type == e1000_media_type_internal_serdes)) &&
3066 (!(status & E1000_STATUS_LU)) &&
3067 (!(rxcw & E1000_RXCW_C))) {
3068 if (hw->autoneg_failed == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 hw->autoneg_failed = 1;
3070 return 0;
3071 }
Auke Koka42a5072006-05-23 13:36:01 -07003072 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073
3074 /* Disable auto-negotiation in the TXCW register */
3075 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3076
3077 /* Force link-up and also force full-duplex. */
3078 ctrl = E1000_READ_REG(hw, CTRL);
3079 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3080 E1000_WRITE_REG(hw, CTRL, ctrl);
3081
3082 /* Configure Flow Control after forcing link up. */
3083 ret_val = e1000_config_fc_after_link_up(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003084 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 DEBUGOUT("Error configuring flow control\n");
3086 return ret_val;
3087 }
3088 }
3089 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3090 * auto-negotiation in the TXCW register and disable forced link in the
3091 * Device Control register in an attempt to auto-negotiate with our link
3092 * partner.
3093 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003094 else if (((hw->media_type == e1000_media_type_fiber) ||
3095 (hw->media_type == e1000_media_type_internal_serdes)) &&
3096 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Auke Koka42a5072006-05-23 13:36:01 -07003097 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3099 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3100
3101 hw->serdes_link_down = FALSE;
3102 }
3103 /* If we force link for non-auto-negotiation switch, check link status
3104 * based on MAC synchronization for internal serdes media type.
3105 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003106 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
3107 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 /* SYNCH bit and IV bit are sticky. */
3109 udelay(10);
Auke Kok8fc897b2006-08-28 14:56:16 -07003110 if (E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
3111 if (!(rxcw & E1000_RXCW_IV)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 hw->serdes_link_down = FALSE;
3113 DEBUGOUT("SERDES: Link is up.\n");
3114 }
3115 } else {
3116 hw->serdes_link_down = TRUE;
3117 DEBUGOUT("SERDES: Link is down.\n");
3118 }
3119 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003120 if ((hw->media_type == e1000_media_type_internal_serdes) &&
3121 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
3123 }
3124 return E1000_SUCCESS;
3125}
3126
3127/******************************************************************************
3128 * Detects the current speed and duplex settings of the hardware.
3129 *
3130 * hw - Struct containing variables accessed by shared code
3131 * speed - Speed of the connection
3132 * duplex - Duplex setting of the connection
3133 *****************************************************************************/
3134int32_t
3135e1000_get_speed_and_duplex(struct e1000_hw *hw,
3136 uint16_t *speed,
3137 uint16_t *duplex)
3138{
3139 uint32_t status;
3140 int32_t ret_val;
3141 uint16_t phy_data;
3142
3143 DEBUGFUNC("e1000_get_speed_and_duplex");
3144
Auke Kok8fc897b2006-08-28 14:56:16 -07003145 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 status = E1000_READ_REG(hw, STATUS);
Auke Kok8fc897b2006-08-28 14:56:16 -07003147 if (status & E1000_STATUS_SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148 *speed = SPEED_1000;
3149 DEBUGOUT("1000 Mbs, ");
Auke Kok8fc897b2006-08-28 14:56:16 -07003150 } else if (status & E1000_STATUS_SPEED_100) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 *speed = SPEED_100;
3152 DEBUGOUT("100 Mbs, ");
3153 } else {
3154 *speed = SPEED_10;
3155 DEBUGOUT("10 Mbs, ");
3156 }
3157
Auke Kok8fc897b2006-08-28 14:56:16 -07003158 if (status & E1000_STATUS_FD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 *duplex = FULL_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003160 DEBUGOUT("Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 } else {
3162 *duplex = HALF_DUPLEX;
Auke Koka42a5072006-05-23 13:36:01 -07003163 DEBUGOUT(" Half Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164 }
3165 } else {
Auke Koka42a5072006-05-23 13:36:01 -07003166 DEBUGOUT("1000 Mbs, Full Duplex\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 *speed = SPEED_1000;
3168 *duplex = FULL_DUPLEX;
3169 }
3170
3171 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
3172 * if it is operating at half duplex. Here we set the duplex settings to
3173 * match the duplex in the link partner's capabilities.
3174 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003175 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003177 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 return ret_val;
3179
Auke Kok8fc897b2006-08-28 14:56:16 -07003180 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 *duplex = HALF_DUPLEX;
3182 else {
3183 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003184 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003186 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3188 *duplex = HALF_DUPLEX;
3189 }
3190 }
3191
Auke Kok76c224b2006-05-23 13:36:06 -07003192 if ((hw->mac_type == e1000_80003es2lan) &&
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003193 (hw->media_type == e1000_media_type_copper)) {
3194 if (*speed == SPEED_1000)
3195 ret_val = e1000_configure_kmrn_for_1000(hw);
3196 else
Auke Kokcd94dd02006-06-27 09:08:22 -07003197 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3198 if (ret_val)
3199 return ret_val;
3200 }
3201
3202 if ((hw->phy_type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
3203 ret_val = e1000_kumeran_lock_loss_workaround(hw);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003204 if (ret_val)
3205 return ret_val;
3206 }
3207
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 return E1000_SUCCESS;
3209}
3210
3211/******************************************************************************
3212* Blocks until autoneg completes or times out (~4.5 seconds)
3213*
3214* hw - Struct containing variables accessed by shared code
3215******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01003216static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217e1000_wait_autoneg(struct e1000_hw *hw)
3218{
3219 int32_t ret_val;
3220 uint16_t i;
3221 uint16_t phy_data;
3222
3223 DEBUGFUNC("e1000_wait_autoneg");
3224 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3225
3226 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
Auke Kok8fc897b2006-08-28 14:56:16 -07003227 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 /* Read the MII Status Register and wait for Auto-Neg
3229 * Complete bit to be set.
3230 */
3231 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003232 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 return ret_val;
3234 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003235 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07003237 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 return E1000_SUCCESS;
3239 }
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003240 msleep(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 }
3242 return E1000_SUCCESS;
3243}
3244
3245/******************************************************************************
3246* Raises the Management Data Clock
3247*
3248* hw - Struct containing variables accessed by shared code
3249* ctrl - Device control register's current value
3250******************************************************************************/
3251static void
3252e1000_raise_mdi_clk(struct e1000_hw *hw,
3253 uint32_t *ctrl)
3254{
3255 /* Raise the clock input to the Management Data Clock (by setting the MDC
3256 * bit), and then delay 10 microseconds.
3257 */
3258 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3259 E1000_WRITE_FLUSH(hw);
3260 udelay(10);
3261}
3262
3263/******************************************************************************
3264* Lowers the Management Data Clock
3265*
3266* hw - Struct containing variables accessed by shared code
3267* ctrl - Device control register's current value
3268******************************************************************************/
3269static void
3270e1000_lower_mdi_clk(struct e1000_hw *hw,
3271 uint32_t *ctrl)
3272{
3273 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3274 * bit), and then delay 10 microseconds.
3275 */
3276 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3277 E1000_WRITE_FLUSH(hw);
3278 udelay(10);
3279}
3280
3281/******************************************************************************
3282* Shifts data bits out to the PHY
3283*
3284* hw - Struct containing variables accessed by shared code
3285* data - Data to send out to the PHY
3286* count - Number of bits to shift out
3287*
3288* Bits are shifted out in MSB to LSB order.
3289******************************************************************************/
3290static void
3291e1000_shift_out_mdi_bits(struct e1000_hw *hw,
3292 uint32_t data,
3293 uint16_t count)
3294{
3295 uint32_t ctrl;
3296 uint32_t mask;
3297
3298 /* We need to shift "count" number of bits out to the PHY. So, the value
3299 * in the "data" parameter will be shifted out to the PHY one bit at a
3300 * time. In order to do this, "data" must be broken down into bits.
3301 */
3302 mask = 0x01;
3303 mask <<= (count - 1);
3304
3305 ctrl = E1000_READ_REG(hw, CTRL);
3306
3307 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3308 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3309
Auke Kok8fc897b2006-08-28 14:56:16 -07003310 while (mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3312 * then raising and lowering the Management Data Clock. A "0" is
3313 * shifted out to the PHY by setting the MDIO bit to "0" and then
3314 * raising and lowering the clock.
3315 */
Auke Kok8fc897b2006-08-28 14:56:16 -07003316 if (data & mask)
3317 ctrl |= E1000_CTRL_MDIO;
3318 else
3319 ctrl &= ~E1000_CTRL_MDIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320
3321 E1000_WRITE_REG(hw, CTRL, ctrl);
3322 E1000_WRITE_FLUSH(hw);
3323
3324 udelay(10);
3325
3326 e1000_raise_mdi_clk(hw, &ctrl);
3327 e1000_lower_mdi_clk(hw, &ctrl);
3328
3329 mask = mask >> 1;
3330 }
3331}
3332
3333/******************************************************************************
3334* Shifts data bits in from the PHY
3335*
3336* hw - Struct containing variables accessed by shared code
3337*
3338* Bits are shifted in in MSB to LSB order.
3339******************************************************************************/
3340static uint16_t
3341e1000_shift_in_mdi_bits(struct e1000_hw *hw)
3342{
3343 uint32_t ctrl;
3344 uint16_t data = 0;
3345 uint8_t i;
3346
3347 /* In order to read a register from the PHY, we need to shift in a total
3348 * of 18 bits from the PHY. The first two bit (turnaround) times are used
3349 * to avoid contention on the MDIO pin when a read operation is performed.
3350 * These two bits are ignored by us and thrown away. Bits are "shifted in"
3351 * by raising the input to the Management Data Clock (setting the MDC bit),
3352 * and then reading the value of the MDIO bit.
3353 */
3354 ctrl = E1000_READ_REG(hw, CTRL);
3355
3356 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
3357 ctrl &= ~E1000_CTRL_MDIO_DIR;
3358 ctrl &= ~E1000_CTRL_MDIO;
3359
3360 E1000_WRITE_REG(hw, CTRL, ctrl);
3361 E1000_WRITE_FLUSH(hw);
3362
3363 /* Raise and Lower the clock before reading in the data. This accounts for
3364 * the turnaround bits. The first clock occurred when we clocked out the
3365 * last bit of the Register Address.
3366 */
3367 e1000_raise_mdi_clk(hw, &ctrl);
3368 e1000_lower_mdi_clk(hw, &ctrl);
3369
Auke Kok8fc897b2006-08-28 14:56:16 -07003370 for (data = 0, i = 0; i < 16; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 data = data << 1;
3372 e1000_raise_mdi_clk(hw, &ctrl);
3373 ctrl = E1000_READ_REG(hw, CTRL);
3374 /* Check to see if we shifted in a "1". */
Auke Kok8fc897b2006-08-28 14:56:16 -07003375 if (ctrl & E1000_CTRL_MDIO)
3376 data |= 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 e1000_lower_mdi_clk(hw, &ctrl);
3378 }
3379
3380 e1000_raise_mdi_clk(hw, &ctrl);
3381 e1000_lower_mdi_clk(hw, &ctrl);
3382
3383 return data;
3384}
3385
Adrian Bunke4c780b2006-08-14 23:00:10 -07003386static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003387e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
3388{
3389 uint32_t swfw_sync = 0;
3390 uint32_t swmask = mask;
3391 uint32_t fwmask = mask << 16;
3392 int32_t timeout = 200;
3393
3394 DEBUGFUNC("e1000_swfw_sync_acquire");
3395
Auke Kokcd94dd02006-06-27 09:08:22 -07003396 if (hw->swfwhw_semaphore_present)
3397 return e1000_get_software_flag(hw);
3398
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003399 if (!hw->swfw_sync_present)
3400 return e1000_get_hw_eeprom_semaphore(hw);
3401
Auke Kok8fc897b2006-08-28 14:56:16 -07003402 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003403 if (e1000_get_hw_eeprom_semaphore(hw))
3404 return -E1000_ERR_SWFW_SYNC;
3405
3406 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3407 if (!(swfw_sync & (fwmask | swmask))) {
3408 break;
3409 }
3410
3411 /* firmware currently using resource (fwmask) */
3412 /* or other software thread currently using resource (swmask) */
3413 e1000_put_hw_eeprom_semaphore(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003414 mdelay(5);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003415 timeout--;
3416 }
3417
3418 if (!timeout) {
3419 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
3420 return -E1000_ERR_SWFW_SYNC;
3421 }
3422
3423 swfw_sync |= swmask;
3424 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3425
3426 e1000_put_hw_eeprom_semaphore(hw);
3427 return E1000_SUCCESS;
3428}
3429
Adrian Bunke4c780b2006-08-14 23:00:10 -07003430static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003431e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
3432{
3433 uint32_t swfw_sync;
3434 uint32_t swmask = mask;
3435
3436 DEBUGFUNC("e1000_swfw_sync_release");
3437
Auke Kokcd94dd02006-06-27 09:08:22 -07003438 if (hw->swfwhw_semaphore_present) {
3439 e1000_release_software_flag(hw);
3440 return;
3441 }
3442
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003443 if (!hw->swfw_sync_present) {
3444 e1000_put_hw_eeprom_semaphore(hw);
3445 return;
3446 }
3447
3448 /* if (e1000_get_hw_eeprom_semaphore(hw))
3449 * return -E1000_ERR_SWFW_SYNC; */
3450 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
3451 /* empty */
3452
3453 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
3454 swfw_sync &= ~swmask;
3455 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
3456
3457 e1000_put_hw_eeprom_semaphore(hw);
3458}
3459
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460/*****************************************************************************
3461* Reads the value from a PHY register, if the value is on a specific non zero
3462* page, sets the page first.
3463* hw - Struct containing variables accessed by shared code
3464* reg_addr - address of the PHY register to read
3465******************************************************************************/
3466int32_t
3467e1000_read_phy_reg(struct e1000_hw *hw,
3468 uint32_t reg_addr,
3469 uint16_t *phy_data)
3470{
3471 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003472 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473
3474 DEBUGFUNC("e1000_read_phy_reg");
3475
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003476 if ((hw->mac_type == e1000_80003es2lan) &&
3477 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3478 swfw = E1000_SWFW_PHY1_SM;
3479 } else {
3480 swfw = E1000_SWFW_PHY0_SM;
3481 }
3482 if (e1000_swfw_sync_acquire(hw, swfw))
3483 return -E1000_ERR_SWFW_SYNC;
3484
Auke Kokcd94dd02006-06-27 09:08:22 -07003485 if ((hw->phy_type == e1000_phy_igp ||
3486 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003487 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3489 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3490 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003491 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003492 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493 return ret_val;
3494 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003495 } else if (hw->phy_type == e1000_phy_gg82563) {
3496 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3497 (hw->mac_type == e1000_80003es2lan)) {
3498 /* Select Configuration Page */
3499 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3500 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3501 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3502 } else {
3503 /* Use Alternative Page Select register to access
3504 * registers 30 and 31
3505 */
3506 ret_val = e1000_write_phy_reg_ex(hw,
3507 GG82563_PHY_PAGE_SELECT_ALT,
3508 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3509 }
3510
3511 if (ret_val) {
3512 e1000_swfw_sync_release(hw, swfw);
3513 return ret_val;
3514 }
3515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 }
3517
3518 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3519 phy_data);
3520
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003521 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 return ret_val;
3523}
3524
Nicholas Nunley35574762006-09-27 12:53:34 -07003525static int32_t
3526e1000_read_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527 uint16_t *phy_data)
3528{
3529 uint32_t i;
3530 uint32_t mdic = 0;
3531 const uint32_t phy_addr = 1;
3532
3533 DEBUGFUNC("e1000_read_phy_reg_ex");
3534
Auke Kok8fc897b2006-08-28 14:56:16 -07003535 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3537 return -E1000_ERR_PARAM;
3538 }
3539
Auke Kok8fc897b2006-08-28 14:56:16 -07003540 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 /* Set up Op-code, Phy Address, and register address in the MDI
3542 * Control register. The MAC will take care of interfacing with the
3543 * PHY to retrieve the desired data.
3544 */
3545 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
3546 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3547 (E1000_MDIC_OP_READ));
3548
3549 E1000_WRITE_REG(hw, MDIC, mdic);
3550
3551 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003552 for (i = 0; i < 64; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553 udelay(50);
3554 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003555 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003557 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558 DEBUGOUT("MDI Read did not complete\n");
3559 return -E1000_ERR_PHY;
3560 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003561 if (mdic & E1000_MDIC_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 DEBUGOUT("MDI Error\n");
3563 return -E1000_ERR_PHY;
3564 }
3565 *phy_data = (uint16_t) mdic;
3566 } else {
3567 /* We must first send a preamble through the MDIO pin to signal the
3568 * beginning of an MII instruction. This is done by sending 32
3569 * consecutive "1" bits.
3570 */
3571 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3572
3573 /* Now combine the next few fields that are required for a read
3574 * operation. We use this method instead of calling the
3575 * e1000_shift_out_mdi_bits routine five different times. The format of
3576 * a MII read instruction consists of a shift out of 14 bits and is
3577 * defined as follows:
3578 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
3579 * followed by a shift in of 18 bits. This first two bits shifted in
3580 * are TurnAround bits used to avoid contention on the MDIO pin when a
3581 * READ operation is performed. These two bits are thrown away
3582 * followed by a shift in of 16 bits which contains the desired data.
3583 */
3584 mdic = ((reg_addr) | (phy_addr << 5) |
3585 (PHY_OP_READ << 10) | (PHY_SOF << 12));
3586
3587 e1000_shift_out_mdi_bits(hw, mdic, 14);
3588
3589 /* Now that we've shifted out the read command to the MII, we need to
3590 * "shift in" the 16-bit value (18 total bits) of the requested PHY
3591 * register address.
3592 */
3593 *phy_data = e1000_shift_in_mdi_bits(hw);
3594 }
3595 return E1000_SUCCESS;
3596}
3597
3598/******************************************************************************
3599* Writes a value to a PHY register
3600*
3601* hw - Struct containing variables accessed by shared code
3602* reg_addr - address of the PHY register to write
3603* data - data to write to the PHY
3604******************************************************************************/
3605int32_t
Nicholas Nunley35574762006-09-27 12:53:34 -07003606e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607 uint16_t phy_data)
3608{
3609 uint32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003610 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611
3612 DEBUGFUNC("e1000_write_phy_reg");
3613
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003614 if ((hw->mac_type == e1000_80003es2lan) &&
3615 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3616 swfw = E1000_SWFW_PHY1_SM;
3617 } else {
3618 swfw = E1000_SWFW_PHY0_SM;
3619 }
3620 if (e1000_swfw_sync_acquire(hw, swfw))
3621 return -E1000_ERR_SWFW_SYNC;
3622
Auke Kokcd94dd02006-06-27 09:08:22 -07003623 if ((hw->phy_type == e1000_phy_igp ||
3624 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003625 hw->phy_type == e1000_phy_igp_2) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3627 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3628 (uint16_t)reg_addr);
Auke Kok8fc897b2006-08-28 14:56:16 -07003629 if (ret_val) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003630 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 return ret_val;
3632 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003633 } else if (hw->phy_type == e1000_phy_gg82563) {
3634 if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
3635 (hw->mac_type == e1000_80003es2lan)) {
3636 /* Select Configuration Page */
3637 if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
3638 ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
3639 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3640 } else {
3641 /* Use Alternative Page Select register to access
3642 * registers 30 and 31
3643 */
3644 ret_val = e1000_write_phy_reg_ex(hw,
3645 GG82563_PHY_PAGE_SELECT_ALT,
3646 (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
3647 }
3648
3649 if (ret_val) {
3650 e1000_swfw_sync_release(hw, swfw);
3651 return ret_val;
3652 }
3653 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654 }
3655
3656 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3657 phy_data);
3658
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003659 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660 return ret_val;
3661}
3662
Nicholas Nunley35574762006-09-27 12:53:34 -07003663static int32_t
3664e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
3665 uint16_t phy_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666{
3667 uint32_t i;
3668 uint32_t mdic = 0;
3669 const uint32_t phy_addr = 1;
3670
3671 DEBUGFUNC("e1000_write_phy_reg_ex");
3672
Auke Kok8fc897b2006-08-28 14:56:16 -07003673 if (reg_addr > MAX_PHY_REG_ADDRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
3675 return -E1000_ERR_PARAM;
3676 }
3677
Auke Kok8fc897b2006-08-28 14:56:16 -07003678 if (hw->mac_type > e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679 /* Set up Op-code, Phy Address, register address, and data intended
3680 * for the PHY register in the MDI Control register. The MAC will take
3681 * care of interfacing with the PHY to send the desired data.
3682 */
3683 mdic = (((uint32_t) phy_data) |
3684 (reg_addr << E1000_MDIC_REG_SHIFT) |
3685 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3686 (E1000_MDIC_OP_WRITE));
3687
3688 E1000_WRITE_REG(hw, MDIC, mdic);
3689
3690 /* Poll the ready bit to see if the MDI read completed */
Auke Kok8fc897b2006-08-28 14:56:16 -07003691 for (i = 0; i < 641; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 udelay(5);
3693 mdic = E1000_READ_REG(hw, MDIC);
Auke Kok8fc897b2006-08-28 14:56:16 -07003694 if (mdic & E1000_MDIC_READY) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 }
Auke Kok8fc897b2006-08-28 14:56:16 -07003696 if (!(mdic & E1000_MDIC_READY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 DEBUGOUT("MDI Write did not complete\n");
3698 return -E1000_ERR_PHY;
3699 }
3700 } else {
3701 /* We'll need to use the SW defined pins to shift the write command
3702 * out to the PHY. We first send a preamble to the PHY to signal the
3703 * beginning of the MII instruction. This is done by sending 32
3704 * consecutive "1" bits.
3705 */
3706 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3707
3708 /* Now combine the remaining required fields that will indicate a
3709 * write operation. We use this method instead of calling the
3710 * e1000_shift_out_mdi_bits routine for each field in the command. The
3711 * format of a MII write instruction is as follows:
3712 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
3713 */
3714 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3715 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3716 mdic <<= 16;
3717 mdic |= (uint32_t) phy_data;
3718
3719 e1000_shift_out_mdi_bits(hw, mdic, 32);
3720 }
3721
3722 return E1000_SUCCESS;
3723}
3724
Adrian Bunke4c780b2006-08-14 23:00:10 -07003725static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003726e1000_read_kmrn_reg(struct e1000_hw *hw,
3727 uint32_t reg_addr,
3728 uint16_t *data)
3729{
3730 uint32_t reg_val;
3731 uint16_t swfw;
3732 DEBUGFUNC("e1000_read_kmrn_reg");
3733
3734 if ((hw->mac_type == e1000_80003es2lan) &&
3735 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3736 swfw = E1000_SWFW_PHY1_SM;
3737 } else {
3738 swfw = E1000_SWFW_PHY0_SM;
3739 }
3740 if (e1000_swfw_sync_acquire(hw, swfw))
3741 return -E1000_ERR_SWFW_SYNC;
3742
3743 /* Write register address */
3744 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3745 E1000_KUMCTRLSTA_OFFSET) |
3746 E1000_KUMCTRLSTA_REN;
3747 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3748 udelay(2);
3749
3750 /* Read the data returned */
3751 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
3752 *data = (uint16_t)reg_val;
3753
3754 e1000_swfw_sync_release(hw, swfw);
3755 return E1000_SUCCESS;
3756}
3757
Adrian Bunke4c780b2006-08-14 23:00:10 -07003758static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003759e1000_write_kmrn_reg(struct e1000_hw *hw,
3760 uint32_t reg_addr,
3761 uint16_t data)
3762{
3763 uint32_t reg_val;
3764 uint16_t swfw;
3765 DEBUGFUNC("e1000_write_kmrn_reg");
3766
3767 if ((hw->mac_type == e1000_80003es2lan) &&
3768 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3769 swfw = E1000_SWFW_PHY1_SM;
3770 } else {
3771 swfw = E1000_SWFW_PHY0_SM;
3772 }
3773 if (e1000_swfw_sync_acquire(hw, swfw))
3774 return -E1000_ERR_SWFW_SYNC;
3775
3776 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
3777 E1000_KUMCTRLSTA_OFFSET) | data;
3778 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
3779 udelay(2);
3780
3781 e1000_swfw_sync_release(hw, swfw);
3782 return E1000_SUCCESS;
3783}
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003784
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785/******************************************************************************
3786* Returns the PHY to the power-on reset state
3787*
3788* hw - Struct containing variables accessed by shared code
3789******************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003790int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791e1000_phy_hw_reset(struct e1000_hw *hw)
3792{
3793 uint32_t ctrl, ctrl_ext;
3794 uint32_t led_ctrl;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003795 int32_t ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003796 uint16_t swfw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797
3798 DEBUGFUNC("e1000_phy_hw_reset");
3799
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003800 /* In the case of the phy reset being blocked, it's not an error, we
3801 * simply return success without performing the reset. */
3802 ret_val = e1000_check_phy_reset_block(hw);
3803 if (ret_val)
3804 return E1000_SUCCESS;
3805
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 DEBUGOUT("Resetting Phy...\n");
3807
Auke Kok8fc897b2006-08-28 14:56:16 -07003808 if (hw->mac_type > e1000_82543) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003809 if ((hw->mac_type == e1000_80003es2lan) &&
3810 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
3811 swfw = E1000_SWFW_PHY1_SM;
3812 } else {
3813 swfw = E1000_SWFW_PHY0_SM;
3814 }
3815 if (e1000_swfw_sync_acquire(hw, swfw)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003816 DEBUGOUT("Unable to acquire swfw sync\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003817 return -E1000_ERR_SWFW_SYNC;
3818 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 /* Read the device control register and assert the E1000_CTRL_PHY_RST
3820 * bit. Then, take it out of reset.
Auke Kok76c224b2006-05-23 13:36:06 -07003821 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
Jeff Kirsherfd803242005-12-13 00:06:22 -05003822 * and deassert. For e1000_82571 hardware and later, we instead delay
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08003823 * for 50us between and 10ms after the deassertion.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 */
3825 ctrl = E1000_READ_REG(hw, CTRL);
3826 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
3827 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003828
3829 if (hw->mac_type < e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003830 msleep(10);
Jeff Kirsherb55ccb32006-01-12 16:50:30 -08003831 else
3832 udelay(100);
Auke Kok76c224b2006-05-23 13:36:06 -07003833
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834 E1000_WRITE_REG(hw, CTRL, ctrl);
3835 E1000_WRITE_FLUSH(hw);
Auke Kok76c224b2006-05-23 13:36:06 -07003836
Jeff Kirsherfd803242005-12-13 00:06:22 -05003837 if (hw->mac_type >= e1000_82571)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003838 mdelay(10);
Nicholas Nunley35574762006-09-27 12:53:34 -07003839
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003840 e1000_swfw_sync_release(hw, swfw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 } else {
3842 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
3843 * bit to put the PHY into reset. Then, take it out of reset.
3844 */
3845 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
3846 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3847 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3848 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3849 E1000_WRITE_FLUSH(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04003850 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3852 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3853 E1000_WRITE_FLUSH(hw);
3854 }
3855 udelay(150);
3856
Auke Kok8fc897b2006-08-28 14:56:16 -07003857 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 /* Configure activity LED after PHY reset */
3859 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3860 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3861 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3862 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3863 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003864
3865 /* Wait for FW to finish PHY configuration. */
3866 ret_val = e1000_get_phy_cfg_done(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003867 if (ret_val != E1000_SUCCESS)
3868 return ret_val;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08003869 e1000_release_software_semaphore(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003870
Auke Kok8fc897b2006-08-28 14:56:16 -07003871 if ((hw->mac_type == e1000_ich8lan) && (hw->phy_type == e1000_phy_igp_3))
3872 ret_val = e1000_init_lcd_from_nvm(hw);
3873
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003874 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875}
3876
3877/******************************************************************************
3878* Resets the PHY
3879*
3880* hw - Struct containing variables accessed by shared code
3881*
Matt LaPlante0779bf22006-11-30 05:24:39 +01003882* Sets bit 15 of the MII Control register
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883******************************************************************************/
3884int32_t
3885e1000_phy_reset(struct e1000_hw *hw)
3886{
3887 int32_t ret_val;
3888 uint16_t phy_data;
3889
3890 DEBUGFUNC("e1000_phy_reset");
3891
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003892 /* In the case of the phy reset being blocked, it's not an error, we
3893 * simply return success without performing the reset. */
3894 ret_val = e1000_check_phy_reset_block(hw);
3895 if (ret_val)
3896 return E1000_SUCCESS;
3897
Jeff Kirsher2a88c172006-09-27 12:54:05 -07003898 switch (hw->phy_type) {
3899 case e1000_phy_igp:
3900 case e1000_phy_igp_2:
3901 case e1000_phy_igp_3:
3902 case e1000_phy_ife:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003903 ret_val = e1000_phy_hw_reset(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07003904 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003905 return ret_val;
3906 break;
3907 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003909 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 return ret_val;
3911
3912 phy_data |= MII_CR_RESET;
3913 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07003914 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915 return ret_val;
3916
3917 udelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07003918 break;
3919 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920
Auke Kok8fc897b2006-08-28 14:56:16 -07003921 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 e1000_phy_init_script(hw);
3923
3924 return E1000_SUCCESS;
3925}
3926
3927/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07003928* Work-around for 82566 power-down: on D3 entry-
3929* 1) disable gigabit link
3930* 2) write VR power-down enable
3931* 3) read it back
3932* if successful continue, else issue LCD reset and repeat
3933*
3934* hw - struct containing variables accessed by shared code
3935******************************************************************************/
3936void
3937e1000_phy_powerdown_workaround(struct e1000_hw *hw)
3938{
3939 int32_t reg;
3940 uint16_t phy_data;
3941 int32_t retry = 0;
3942
3943 DEBUGFUNC("e1000_phy_powerdown_workaround");
3944
3945 if (hw->phy_type != e1000_phy_igp_3)
3946 return;
3947
3948 do {
3949 /* Disable link */
3950 reg = E1000_READ_REG(hw, PHY_CTRL);
3951 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
3952 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
3953
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003954 /* Write VR power-down enable - bits 9:8 should be 10b */
Auke Kokd37ea5d2006-06-27 09:08:17 -07003955 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003956 phy_data |= (1 << 9);
3957 phy_data &= ~(1 << 8);
3958 e1000_write_phy_reg(hw, IGP3_VR_CTRL, phy_data);
Auke Kokd37ea5d2006-06-27 09:08:17 -07003959
3960 /* Read it back and test */
3961 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &phy_data);
Jeff Kirsher070f6ff2006-11-01 08:47:44 -08003962 if (((phy_data & IGP3_VR_CTRL_MODE_MASK) == IGP3_VR_CTRL_MODE_SHUT) || retry)
Auke Kokd37ea5d2006-06-27 09:08:17 -07003963 break;
3964
3965 /* Issue PHY reset and repeat at most one more time */
3966 reg = E1000_READ_REG(hw, CTRL);
3967 E1000_WRITE_REG(hw, CTRL, reg | E1000_CTRL_PHY_RST);
3968 retry++;
3969 } while (retry);
3970
3971 return;
3972
3973}
3974
3975/******************************************************************************
3976* Work-around for 82566 Kumeran PCS lock loss:
3977* On link status change (i.e. PCI reset, speed change) and link is up and
3978* speed is gigabit-
3979* 0) if workaround is optionally disabled do nothing
3980* 1) wait 1ms for Kumeran link to come up
3981* 2) check Kumeran Diagnostic register PCS lock loss bit
3982* 3) if not set the link is locked (all is good), otherwise...
3983* 4) reset the PHY
3984* 5) repeat up to 10 times
3985* Note: this is only called for IGP3 copper when speed is 1gb.
3986*
3987* hw - struct containing variables accessed by shared code
3988******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07003989static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07003990e1000_kumeran_lock_loss_workaround(struct e1000_hw *hw)
3991{
3992 int32_t ret_val;
3993 int32_t reg;
3994 int32_t cnt;
3995 uint16_t phy_data;
3996
3997 if (hw->kmrn_lock_loss_workaround_disabled)
3998 return E1000_SUCCESS;
3999
Auke Kok8fc897b2006-08-28 14:56:16 -07004000 /* Make sure link is up before proceeding. If not just return.
4001 * Attempting this while link is negotiating fouled up link
Auke Kokd37ea5d2006-06-27 09:08:17 -07004002 * stability */
4003 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4004 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
4005
4006 if (phy_data & MII_SR_LINK_STATUS) {
4007 for (cnt = 0; cnt < 10; cnt++) {
4008 /* read once to clear */
4009 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4010 if (ret_val)
4011 return ret_val;
4012 /* and again to get new status */
4013 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &phy_data);
4014 if (ret_val)
4015 return ret_val;
4016
4017 /* check for PCS lock */
4018 if (!(phy_data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
4019 return E1000_SUCCESS;
4020
4021 /* Issue PHY reset */
4022 e1000_phy_hw_reset(hw);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04004023 mdelay(5);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004024 }
4025 /* Disable GigE link negotiation */
4026 reg = E1000_READ_REG(hw, PHY_CTRL);
4027 E1000_WRITE_REG(hw, PHY_CTRL, reg | E1000_PHY_CTRL_GBE_DISABLE |
4028 E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
4029
4030 /* unable to acquire PCS lock */
4031 return E1000_ERR_PHY;
4032 }
4033
4034 return E1000_SUCCESS;
4035}
4036
4037/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038* Probes the expected PHY address for known PHY IDs
4039*
4040* hw - Struct containing variables accessed by shared code
4041******************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07004042static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043e1000_detect_gig_phy(struct e1000_hw *hw)
4044{
4045 int32_t phy_init_status, ret_val;
4046 uint16_t phy_id_high, phy_id_low;
4047 boolean_t match = FALSE;
4048
4049 DEBUGFUNC("e1000_detect_gig_phy");
4050
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004051 if (hw->phy_id != 0)
4052 return E1000_SUCCESS;
4053
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004054 /* The 82571 firmware may still be configuring the PHY. In this
4055 * case, we cannot access the PHY until the configuration is done. So
4056 * we explicitly set the PHY values. */
Auke Kokcd94dd02006-06-27 09:08:22 -07004057 if (hw->mac_type == e1000_82571 ||
4058 hw->mac_type == e1000_82572) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004059 hw->phy_id = IGP01E1000_I_PHY_ID;
4060 hw->phy_type = e1000_phy_igp_2;
4061 return E1000_SUCCESS;
4062 }
4063
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004064 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
4065 * around that forces PHY page 0 to be set or the reads fail. The rest of
4066 * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
4067 * So for ESB-2 we need to have this set so our reads won't fail. If the
4068 * attached PHY is not a e1000_phy_gg82563, the routines below will figure
4069 * this out as well. */
4070 if (hw->mac_type == e1000_80003es2lan)
4071 hw->phy_type = e1000_phy_gg82563;
4072
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 /* Read the PHY ID Registers to identify which PHY is onboard. */
4074 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
Auke Kokcd94dd02006-06-27 09:08:22 -07004075 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 return ret_val;
4077
4078 hw->phy_id = (uint32_t) (phy_id_high << 16);
4079 udelay(20);
4080 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
Auke Kok8fc897b2006-08-28 14:56:16 -07004081 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 return ret_val;
4083
4084 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4085 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4086
Auke Kok8fc897b2006-08-28 14:56:16 -07004087 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088 case e1000_82543:
Auke Kok8fc897b2006-08-28 14:56:16 -07004089 if (hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090 break;
4091 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07004092 if (hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093 break;
4094 case e1000_82540:
4095 case e1000_82545:
4096 case e1000_82545_rev_3:
4097 case e1000_82546:
4098 case e1000_82546_rev_3:
Auke Kok8fc897b2006-08-28 14:56:16 -07004099 if (hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100 break;
4101 case e1000_82541:
4102 case e1000_82541_rev_2:
4103 case e1000_82547:
4104 case e1000_82547_rev_2:
Auke Kok8fc897b2006-08-28 14:56:16 -07004105 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004107 case e1000_82573:
Auke Kok8fc897b2006-08-28 14:56:16 -07004108 if (hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004109 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004110 case e1000_80003es2lan:
4111 if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
4112 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004113 case e1000_ich8lan:
4114 if (hw->phy_id == IGP03E1000_E_PHY_ID) match = TRUE;
4115 if (hw->phy_id == IFE_E_PHY_ID) match = TRUE;
4116 if (hw->phy_id == IFE_PLUS_E_PHY_ID) match = TRUE;
4117 if (hw->phy_id == IFE_C_E_PHY_ID) match = TRUE;
4118 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119 default:
4120 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
4121 return -E1000_ERR_CONFIG;
4122 }
4123 phy_init_status = e1000_set_phy_type(hw);
4124
4125 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4126 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
4127 return E1000_SUCCESS;
4128 }
4129 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
4130 return -E1000_ERR_PHY;
4131}
4132
4133/******************************************************************************
4134* Resets the PHY's DSP
4135*
4136* hw - Struct containing variables accessed by shared code
4137******************************************************************************/
4138static int32_t
4139e1000_phy_reset_dsp(struct e1000_hw *hw)
4140{
4141 int32_t ret_val;
4142 DEBUGFUNC("e1000_phy_reset_dsp");
4143
4144 do {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004145 if (hw->phy_type != e1000_phy_gg82563) {
4146 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
Auke Kok8fc897b2006-08-28 14:56:16 -07004147 if (ret_val) break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004148 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
Auke Kok8fc897b2006-08-28 14:56:16 -07004150 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07004152 if (ret_val) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153 ret_val = E1000_SUCCESS;
Auke Kok8fc897b2006-08-28 14:56:16 -07004154 } while (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155
4156 return ret_val;
4157}
4158
4159/******************************************************************************
4160* Get PHY information from various PHY registers for igp PHY only.
4161*
4162* hw - Struct containing variables accessed by shared code
4163* phy_info - PHY information structure
4164******************************************************************************/
Adrian Bunkcff93eb2006-09-04 13:41:14 +02004165static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166e1000_phy_igp_get_info(struct e1000_hw *hw,
4167 struct e1000_phy_info *phy_info)
4168{
4169 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004170 uint16_t phy_data, min_length, max_length, average;
4171 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172
4173 DEBUGFUNC("e1000_phy_igp_get_info");
4174
4175 /* The downshift status is checked only once, after link is established,
4176 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004177 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178
4179 /* IGP01E1000 does not need to support it. */
4180 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4181
4182 /* IGP01E1000 always correct polarity reversal */
4183 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
4184
4185 /* Check polarity status */
4186 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004187 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188 return ret_val;
4189
4190 phy_info->cable_polarity = polarity;
4191
4192 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004193 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 return ret_val;
4195
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004196 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
4197 IGP01E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198
Auke Kok8fc897b2006-08-28 14:56:16 -07004199 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200 IGP01E1000_PSSR_SPEED_1000MBPS) {
4201 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
4202 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004203 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204 return ret_val;
4205
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004206 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4207 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4208 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4209 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4210 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4211 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212
4213 /* Get cable length */
4214 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
Auke Kok8fc897b2006-08-28 14:56:16 -07004215 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216 return ret_val;
4217
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004218 /* Translate to old method */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219 average = (max_length + min_length) / 2;
4220
Auke Kok8fc897b2006-08-28 14:56:16 -07004221 if (average <= e1000_igp_cable_length_50)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222 phy_info->cable_length = e1000_cable_length_50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004223 else if (average <= e1000_igp_cable_length_80)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 phy_info->cable_length = e1000_cable_length_50_80;
Auke Kok8fc897b2006-08-28 14:56:16 -07004225 else if (average <= e1000_igp_cable_length_110)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226 phy_info->cable_length = e1000_cable_length_80_110;
Auke Kok8fc897b2006-08-28 14:56:16 -07004227 else if (average <= e1000_igp_cable_length_140)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228 phy_info->cable_length = e1000_cable_length_110_140;
4229 else
4230 phy_info->cable_length = e1000_cable_length_140;
4231 }
4232
4233 return E1000_SUCCESS;
4234}
4235
4236/******************************************************************************
Auke Kokd37ea5d2006-06-27 09:08:17 -07004237* Get PHY information from various PHY registers for ife PHY only.
4238*
4239* hw - Struct containing variables accessed by shared code
4240* phy_info - PHY information structure
4241******************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07004242static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07004243e1000_phy_ife_get_info(struct e1000_hw *hw,
4244 struct e1000_phy_info *phy_info)
4245{
4246 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004247 uint16_t phy_data;
4248 e1000_rev_polarity polarity;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004249
4250 DEBUGFUNC("e1000_phy_ife_get_info");
4251
4252 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
4253 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
4254
4255 ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &phy_data);
4256 if (ret_val)
4257 return ret_val;
4258 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004259 ((phy_data & IFE_PSC_AUTO_POLARITY_DISABLE) >>
4260 IFE_PSC_AUTO_POLARITY_DISABLE_SHIFT) ?
4261 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004262
4263 if (phy_info->polarity_correction == e1000_polarity_reversal_enabled) {
4264 ret_val = e1000_check_polarity(hw, &polarity);
4265 if (ret_val)
4266 return ret_val;
4267 } else {
4268 /* Polarity is forced. */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004269 polarity = ((phy_data & IFE_PSC_FORCE_POLARITY) >>
4270 IFE_PSC_FORCE_POLARITY_SHIFT) ?
4271 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Auke Kokd37ea5d2006-06-27 09:08:17 -07004272 }
4273 phy_info->cable_polarity = polarity;
4274
4275 ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &phy_data);
4276 if (ret_val)
4277 return ret_val;
4278
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004279 phy_info->mdix_mode = (e1000_auto_x_mode)
4280 ((phy_data & (IFE_PMC_AUTO_MDIX | IFE_PMC_FORCE_MDIX)) >>
4281 IFE_PMC_MDIX_MODE_SHIFT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07004282
4283 return E1000_SUCCESS;
4284}
4285
4286/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287* Get PHY information from various PHY registers fot m88 PHY only.
4288*
4289* hw - Struct containing variables accessed by shared code
4290* phy_info - PHY information structure
4291******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01004292static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293e1000_phy_m88_get_info(struct e1000_hw *hw,
4294 struct e1000_phy_info *phy_info)
4295{
4296 int32_t ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004297 uint16_t phy_data;
4298 e1000_rev_polarity polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299
4300 DEBUGFUNC("e1000_phy_m88_get_info");
4301
4302 /* The downshift status is checked only once, after link is established,
4303 * and it stored in the hw->speed_downgraded parameter. */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004304 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305
4306 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004307 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308 return ret_val;
4309
4310 phy_info->extended_10bt_distance =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004311 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
4312 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
4313 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
4314
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 phy_info->polarity_correction =
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004316 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
4317 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
4318 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319
4320 /* Check polarity status */
4321 ret_val = e1000_check_polarity(hw, &polarity);
Auke Kok8fc897b2006-08-28 14:56:16 -07004322 if (ret_val)
Auke Kok76c224b2006-05-23 13:36:06 -07004323 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324 phy_info->cable_polarity = polarity;
4325
4326 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004327 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 return ret_val;
4329
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004330 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
4331 M88E1000_PSSR_MDIX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332
4333 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
4334 /* Cable Length Estimation and Local/Remote Receiver Information
4335 * are only valid at 1000 Mbps.
4336 */
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004337 if (hw->phy_type != e1000_phy_gg82563) {
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004338 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004339 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
4340 } else {
4341 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
4342 &phy_data);
4343 if (ret_val)
4344 return ret_val;
4345
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004346 phy_info->cable_length = (e1000_cable_length)(phy_data & GG82563_DSPD_CABLE_LENGTH);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004347 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348
4349 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004350 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351 return ret_val;
4352
Jeff Kirsher70c6f302006-09-27 12:53:31 -07004353 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
4354 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
4355 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
4356 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
4357 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
4358 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360 }
4361
4362 return E1000_SUCCESS;
4363}
4364
4365/******************************************************************************
4366* Get PHY information from various PHY registers
4367*
4368* hw - Struct containing variables accessed by shared code
4369* phy_info - PHY information structure
4370******************************************************************************/
4371int32_t
4372e1000_phy_get_info(struct e1000_hw *hw,
4373 struct e1000_phy_info *phy_info)
4374{
4375 int32_t ret_val;
4376 uint16_t phy_data;
4377
4378 DEBUGFUNC("e1000_phy_get_info");
4379
4380 phy_info->cable_length = e1000_cable_length_undefined;
4381 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
4382 phy_info->cable_polarity = e1000_rev_polarity_undefined;
4383 phy_info->downshift = e1000_downshift_undefined;
4384 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
4385 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
4386 phy_info->local_rx = e1000_1000t_rx_status_undefined;
4387 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
4388
Auke Kok8fc897b2006-08-28 14:56:16 -07004389 if (hw->media_type != e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390 DEBUGOUT("PHY info is only valid for copper media\n");
4391 return -E1000_ERR_CONFIG;
4392 }
4393
4394 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004395 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396 return ret_val;
4397
4398 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07004399 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400 return ret_val;
4401
Auke Kok8fc897b2006-08-28 14:56:16 -07004402 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004403 DEBUGOUT("PHY info is only valid if link is up\n");
4404 return -E1000_ERR_CONFIG;
4405 }
4406
Auke Kokcd94dd02006-06-27 09:08:22 -07004407 if (hw->phy_type == e1000_phy_igp ||
4408 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004409 hw->phy_type == e1000_phy_igp_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410 return e1000_phy_igp_get_info(hw, phy_info);
Auke Kokcd94dd02006-06-27 09:08:22 -07004411 else if (hw->phy_type == e1000_phy_ife)
4412 return e1000_phy_ife_get_info(hw, phy_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413 else
4414 return e1000_phy_m88_get_info(hw, phy_info);
4415}
4416
4417int32_t
4418e1000_validate_mdi_setting(struct e1000_hw *hw)
4419{
4420 DEBUGFUNC("e1000_validate_mdi_settings");
4421
Auke Kok8fc897b2006-08-28 14:56:16 -07004422 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004423 DEBUGOUT("Invalid MDI setting detected\n");
4424 hw->mdix = 1;
4425 return -E1000_ERR_CONFIG;
4426 }
4427 return E1000_SUCCESS;
4428}
4429
4430
4431/******************************************************************************
4432 * Sets up eeprom variables in the hw struct. Must be called after mac_type
Jeff Kirsher0f15a8f2006-03-02 18:46:29 -08004433 * is configured. Additionally, if this is ICH8, the flash controller GbE
4434 * registers must be mapped, or this will crash.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435 *
4436 * hw - Struct containing variables accessed by shared code
4437 *****************************************************************************/
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004438int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004439e1000_init_eeprom_params(struct e1000_hw *hw)
4440{
4441 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4442 uint32_t eecd = E1000_READ_REG(hw, EECD);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004443 int32_t ret_val = E1000_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444 uint16_t eeprom_size;
4445
4446 DEBUGFUNC("e1000_init_eeprom_params");
4447
4448 switch (hw->mac_type) {
4449 case e1000_82542_rev2_0:
4450 case e1000_82542_rev2_1:
4451 case e1000_82543:
4452 case e1000_82544:
4453 eeprom->type = e1000_eeprom_microwire;
4454 eeprom->word_size = 64;
4455 eeprom->opcode_bits = 3;
4456 eeprom->address_bits = 6;
4457 eeprom->delay_usec = 50;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004458 eeprom->use_eerd = FALSE;
4459 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460 break;
4461 case e1000_82540:
4462 case e1000_82545:
4463 case e1000_82545_rev_3:
4464 case e1000_82546:
4465 case e1000_82546_rev_3:
4466 eeprom->type = e1000_eeprom_microwire;
4467 eeprom->opcode_bits = 3;
4468 eeprom->delay_usec = 50;
Auke Kok8fc897b2006-08-28 14:56:16 -07004469 if (eecd & E1000_EECD_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470 eeprom->word_size = 256;
4471 eeprom->address_bits = 8;
4472 } else {
4473 eeprom->word_size = 64;
4474 eeprom->address_bits = 6;
4475 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004476 eeprom->use_eerd = FALSE;
4477 eeprom->use_eewr = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 break;
4479 case e1000_82541:
4480 case e1000_82541_rev_2:
4481 case e1000_82547:
4482 case e1000_82547_rev_2:
4483 if (eecd & E1000_EECD_TYPE) {
4484 eeprom->type = e1000_eeprom_spi;
4485 eeprom->opcode_bits = 8;
4486 eeprom->delay_usec = 1;
4487 if (eecd & E1000_EECD_ADDR_BITS) {
4488 eeprom->page_size = 32;
4489 eeprom->address_bits = 16;
4490 } else {
4491 eeprom->page_size = 8;
4492 eeprom->address_bits = 8;
4493 }
4494 } else {
4495 eeprom->type = e1000_eeprom_microwire;
4496 eeprom->opcode_bits = 3;
4497 eeprom->delay_usec = 50;
4498 if (eecd & E1000_EECD_ADDR_BITS) {
4499 eeprom->word_size = 256;
4500 eeprom->address_bits = 8;
4501 } else {
4502 eeprom->word_size = 64;
4503 eeprom->address_bits = 6;
4504 }
4505 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004506 eeprom->use_eerd = FALSE;
4507 eeprom->use_eewr = FALSE;
4508 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004509 case e1000_82571:
4510 case e1000_82572:
4511 eeprom->type = e1000_eeprom_spi;
4512 eeprom->opcode_bits = 8;
4513 eeprom->delay_usec = 1;
4514 if (eecd & E1000_EECD_ADDR_BITS) {
4515 eeprom->page_size = 32;
4516 eeprom->address_bits = 16;
4517 } else {
4518 eeprom->page_size = 8;
4519 eeprom->address_bits = 8;
4520 }
4521 eeprom->use_eerd = FALSE;
4522 eeprom->use_eewr = FALSE;
4523 break;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004524 case e1000_82573:
4525 eeprom->type = e1000_eeprom_spi;
4526 eeprom->opcode_bits = 8;
4527 eeprom->delay_usec = 1;
4528 if (eecd & E1000_EECD_ADDR_BITS) {
4529 eeprom->page_size = 32;
4530 eeprom->address_bits = 16;
4531 } else {
4532 eeprom->page_size = 8;
4533 eeprom->address_bits = 8;
4534 }
4535 eeprom->use_eerd = TRUE;
4536 eeprom->use_eewr = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07004537 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004538 eeprom->type = e1000_eeprom_flash;
4539 eeprom->word_size = 2048;
4540
4541 /* Ensure that the Autonomous FLASH update bit is cleared due to
4542 * Flash update issue on parts which use a FLASH for NVM. */
4543 eecd &= ~E1000_EECD_AUPDEN;
4544 E1000_WRITE_REG(hw, EECD, eecd);
4545 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004546 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004547 case e1000_80003es2lan:
4548 eeprom->type = e1000_eeprom_spi;
4549 eeprom->opcode_bits = 8;
4550 eeprom->delay_usec = 1;
4551 if (eecd & E1000_EECD_ADDR_BITS) {
4552 eeprom->page_size = 32;
4553 eeprom->address_bits = 16;
4554 } else {
4555 eeprom->page_size = 8;
4556 eeprom->address_bits = 8;
4557 }
4558 eeprom->use_eerd = TRUE;
4559 eeprom->use_eewr = FALSE;
4560 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07004561 case e1000_ich8lan:
Nicholas Nunley35574762006-09-27 12:53:34 -07004562 {
Auke Kokcd94dd02006-06-27 09:08:22 -07004563 int32_t i = 0;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08004564 uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_GFPREG);
Auke Kokcd94dd02006-06-27 09:08:22 -07004565
4566 eeprom->type = e1000_eeprom_ich8;
4567 eeprom->use_eerd = FALSE;
4568 eeprom->use_eewr = FALSE;
4569 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
4570
4571 /* Zero the shadow RAM structure. But don't load it from NVM
4572 * so as to save time for driver init */
4573 if (hw->eeprom_shadow_ram != NULL) {
4574 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
4575 hw->eeprom_shadow_ram[i].modified = FALSE;
4576 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
4577 }
4578 }
4579
Jeff Kirsher2df7d592006-11-01 08:48:02 -08004580 hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) *
4581 ICH_FLASH_SECTOR_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -07004582
Jeff Kirsher2df7d592006-11-01 08:48:02 -08004583 hw->flash_bank_size = ((flash_size >> 16) & ICH_GFPREG_BASE_MASK) + 1;
4584 hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK);
4585
4586 hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE;
4587
Auke Kokcd94dd02006-06-27 09:08:22 -07004588 hw->flash_bank_size /= 2 * sizeof(uint16_t);
4589
4590 break;
Nicholas Nunley35574762006-09-27 12:53:34 -07004591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 default:
4593 break;
4594 }
4595
4596 if (eeprom->type == e1000_eeprom_spi) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004597 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
4598 * 32KB (incremented by powers of 2).
4599 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004600 if (hw->mac_type <= e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004601 /* Set to default value for initial eeprom read. */
4602 eeprom->word_size = 64;
4603 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
Auke Kok8fc897b2006-08-28 14:56:16 -07004604 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004605 return ret_val;
4606 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
4607 /* 256B eeprom size was not supported in earlier hardware, so we
4608 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
4609 * is never the result used in the shifting logic below. */
Auke Kok8fc897b2006-08-28 14:56:16 -07004610 if (eeprom_size)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004611 eeprom_size++;
4612 } else {
4613 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
4614 E1000_EECD_SIZE_EX_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004615 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004616
4617 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004618 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004619 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004620}
4621
4622/******************************************************************************
4623 * Raises the EEPROM's clock input.
4624 *
4625 * hw - Struct containing variables accessed by shared code
4626 * eecd - EECD's current value
4627 *****************************************************************************/
4628static void
4629e1000_raise_ee_clk(struct e1000_hw *hw,
4630 uint32_t *eecd)
4631{
4632 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
4633 * wait <delay> microseconds.
4634 */
4635 *eecd = *eecd | E1000_EECD_SK;
4636 E1000_WRITE_REG(hw, EECD, *eecd);
4637 E1000_WRITE_FLUSH(hw);
4638 udelay(hw->eeprom.delay_usec);
4639}
4640
4641/******************************************************************************
4642 * Lowers the EEPROM's clock input.
4643 *
4644 * hw - Struct containing variables accessed by shared code
4645 * eecd - EECD's current value
4646 *****************************************************************************/
4647static void
4648e1000_lower_ee_clk(struct e1000_hw *hw,
4649 uint32_t *eecd)
4650{
4651 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
4652 * wait 50 microseconds.
4653 */
4654 *eecd = *eecd & ~E1000_EECD_SK;
4655 E1000_WRITE_REG(hw, EECD, *eecd);
4656 E1000_WRITE_FLUSH(hw);
4657 udelay(hw->eeprom.delay_usec);
4658}
4659
4660/******************************************************************************
4661 * Shift data bits out to the EEPROM.
4662 *
4663 * hw - Struct containing variables accessed by shared code
4664 * data - data to send to the EEPROM
4665 * count - number of bits to shift out
4666 *****************************************************************************/
4667static void
4668e1000_shift_out_ee_bits(struct e1000_hw *hw,
4669 uint16_t data,
4670 uint16_t count)
4671{
4672 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4673 uint32_t eecd;
4674 uint32_t mask;
4675
4676 /* We need to shift "count" bits out to the EEPROM. So, value in the
4677 * "data" parameter will be shifted out to the EEPROM one bit at a time.
4678 * In order to do this, "data" must be broken down into bits.
4679 */
4680 mask = 0x01 << (count - 1);
4681 eecd = E1000_READ_REG(hw, EECD);
4682 if (eeprom->type == e1000_eeprom_microwire) {
4683 eecd &= ~E1000_EECD_DO;
4684 } else if (eeprom->type == e1000_eeprom_spi) {
4685 eecd |= E1000_EECD_DO;
4686 }
4687 do {
4688 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
4689 * and then raising and then lowering the clock (the SK bit controls
4690 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
4691 * by setting "DI" to "0" and then raising and then lowering the clock.
4692 */
4693 eecd &= ~E1000_EECD_DI;
4694
Auke Kok8fc897b2006-08-28 14:56:16 -07004695 if (data & mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696 eecd |= E1000_EECD_DI;
4697
4698 E1000_WRITE_REG(hw, EECD, eecd);
4699 E1000_WRITE_FLUSH(hw);
4700
4701 udelay(eeprom->delay_usec);
4702
4703 e1000_raise_ee_clk(hw, &eecd);
4704 e1000_lower_ee_clk(hw, &eecd);
4705
4706 mask = mask >> 1;
4707
Auke Kok8fc897b2006-08-28 14:56:16 -07004708 } while (mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709
4710 /* We leave the "DI" bit set to "0" when we leave this routine. */
4711 eecd &= ~E1000_EECD_DI;
4712 E1000_WRITE_REG(hw, EECD, eecd);
4713}
4714
4715/******************************************************************************
4716 * Shift data bits in from the EEPROM
4717 *
4718 * hw - Struct containing variables accessed by shared code
4719 *****************************************************************************/
4720static uint16_t
4721e1000_shift_in_ee_bits(struct e1000_hw *hw,
4722 uint16_t count)
4723{
4724 uint32_t eecd;
4725 uint32_t i;
4726 uint16_t data;
4727
4728 /* In order to read a register from the EEPROM, we need to shift 'count'
4729 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
4730 * input to the EEPROM (setting the SK bit), and then reading the value of
4731 * the "DO" bit. During this "shifting in" process the "DI" bit should
4732 * always be clear.
4733 */
4734
4735 eecd = E1000_READ_REG(hw, EECD);
4736
4737 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
4738 data = 0;
4739
Auke Kok8fc897b2006-08-28 14:56:16 -07004740 for (i = 0; i < count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741 data = data << 1;
4742 e1000_raise_ee_clk(hw, &eecd);
4743
4744 eecd = E1000_READ_REG(hw, EECD);
4745
4746 eecd &= ~(E1000_EECD_DI);
Auke Kok8fc897b2006-08-28 14:56:16 -07004747 if (eecd & E1000_EECD_DO)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748 data |= 1;
4749
4750 e1000_lower_ee_clk(hw, &eecd);
4751 }
4752
4753 return data;
4754}
4755
4756/******************************************************************************
4757 * Prepares EEPROM for access
4758 *
4759 * hw - Struct containing variables accessed by shared code
4760 *
4761 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
4762 * function should be called before issuing a command to the EEPROM.
4763 *****************************************************************************/
4764static int32_t
4765e1000_acquire_eeprom(struct e1000_hw *hw)
4766{
4767 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4768 uint32_t eecd, i=0;
4769
4770 DEBUGFUNC("e1000_acquire_eeprom");
4771
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004772 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
4773 return -E1000_ERR_SWFW_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 eecd = E1000_READ_REG(hw, EECD);
4775
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004776 if (hw->mac_type != e1000_82573) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004777 /* Request EEPROM Access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004778 if (hw->mac_type > e1000_82544) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004779 eecd |= E1000_EECD_REQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780 E1000_WRITE_REG(hw, EECD, eecd);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004781 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07004782 while ((!(eecd & E1000_EECD_GNT)) &&
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004783 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
4784 i++;
4785 udelay(5);
4786 eecd = E1000_READ_REG(hw, EECD);
4787 }
Auke Kok8fc897b2006-08-28 14:56:16 -07004788 if (!(eecd & E1000_EECD_GNT)) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004789 eecd &= ~E1000_EECD_REQ;
4790 E1000_WRITE_REG(hw, EECD, eecd);
4791 DEBUGOUT("Could not acquire EEPROM grant\n");
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004792 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04004793 return -E1000_ERR_EEPROM;
4794 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795 }
4796 }
4797
4798 /* Setup EEPROM for Read/Write */
4799
4800 if (eeprom->type == e1000_eeprom_microwire) {
4801 /* Clear SK and DI */
4802 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
4803 E1000_WRITE_REG(hw, EECD, eecd);
4804
4805 /* Set CS */
4806 eecd |= E1000_EECD_CS;
4807 E1000_WRITE_REG(hw, EECD, eecd);
4808 } else if (eeprom->type == e1000_eeprom_spi) {
4809 /* Clear SK and CS */
4810 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4811 E1000_WRITE_REG(hw, EECD, eecd);
4812 udelay(1);
4813 }
4814
4815 return E1000_SUCCESS;
4816}
4817
4818/******************************************************************************
4819 * Returns EEPROM to a "standby" state
4820 *
4821 * hw - Struct containing variables accessed by shared code
4822 *****************************************************************************/
4823static void
4824e1000_standby_eeprom(struct e1000_hw *hw)
4825{
4826 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4827 uint32_t eecd;
4828
4829 eecd = E1000_READ_REG(hw, EECD);
4830
Auke Kok8fc897b2006-08-28 14:56:16 -07004831 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
4833 E1000_WRITE_REG(hw, EECD, eecd);
4834 E1000_WRITE_FLUSH(hw);
4835 udelay(eeprom->delay_usec);
4836
4837 /* Clock high */
4838 eecd |= E1000_EECD_SK;
4839 E1000_WRITE_REG(hw, EECD, eecd);
4840 E1000_WRITE_FLUSH(hw);
4841 udelay(eeprom->delay_usec);
4842
4843 /* Select EEPROM */
4844 eecd |= E1000_EECD_CS;
4845 E1000_WRITE_REG(hw, EECD, eecd);
4846 E1000_WRITE_FLUSH(hw);
4847 udelay(eeprom->delay_usec);
4848
4849 /* Clock low */
4850 eecd &= ~E1000_EECD_SK;
4851 E1000_WRITE_REG(hw, EECD, eecd);
4852 E1000_WRITE_FLUSH(hw);
4853 udelay(eeprom->delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004854 } else if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855 /* Toggle CS to flush commands */
4856 eecd |= E1000_EECD_CS;
4857 E1000_WRITE_REG(hw, EECD, eecd);
4858 E1000_WRITE_FLUSH(hw);
4859 udelay(eeprom->delay_usec);
4860 eecd &= ~E1000_EECD_CS;
4861 E1000_WRITE_REG(hw, EECD, eecd);
4862 E1000_WRITE_FLUSH(hw);
4863 udelay(eeprom->delay_usec);
4864 }
4865}
4866
4867/******************************************************************************
4868 * Terminates a command by inverting the EEPROM's chip select pin
4869 *
4870 * hw - Struct containing variables accessed by shared code
4871 *****************************************************************************/
4872static void
4873e1000_release_eeprom(struct e1000_hw *hw)
4874{
4875 uint32_t eecd;
4876
4877 DEBUGFUNC("e1000_release_eeprom");
4878
4879 eecd = E1000_READ_REG(hw, EECD);
4880
4881 if (hw->eeprom.type == e1000_eeprom_spi) {
4882 eecd |= E1000_EECD_CS; /* Pull CS high */
4883 eecd &= ~E1000_EECD_SK; /* Lower SCK */
4884
4885 E1000_WRITE_REG(hw, EECD, eecd);
4886
4887 udelay(hw->eeprom.delay_usec);
Auke Kok8fc897b2006-08-28 14:56:16 -07004888 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889 /* cleanup eeprom */
4890
4891 /* CS on Microwire is active-high */
4892 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
4893
4894 E1000_WRITE_REG(hw, EECD, eecd);
4895
4896 /* Rising edge of clock */
4897 eecd |= E1000_EECD_SK;
4898 E1000_WRITE_REG(hw, EECD, eecd);
4899 E1000_WRITE_FLUSH(hw);
4900 udelay(hw->eeprom.delay_usec);
4901
4902 /* Falling edge of clock */
4903 eecd &= ~E1000_EECD_SK;
4904 E1000_WRITE_REG(hw, EECD, eecd);
4905 E1000_WRITE_FLUSH(hw);
4906 udelay(hw->eeprom.delay_usec);
4907 }
4908
4909 /* Stop requesting EEPROM access */
Auke Kok8fc897b2006-08-28 14:56:16 -07004910 if (hw->mac_type > e1000_82544) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004911 eecd &= ~E1000_EECD_REQ;
4912 E1000_WRITE_REG(hw, EECD, eecd);
4913 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004914
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08004915 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916}
4917
4918/******************************************************************************
4919 * Reads a 16 bit word from the EEPROM.
4920 *
4921 * hw - Struct containing variables accessed by shared code
4922 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07004923static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07004924e1000_spi_eeprom_ready(struct e1000_hw *hw)
4925{
4926 uint16_t retry_count = 0;
4927 uint8_t spi_stat_reg;
4928
4929 DEBUGFUNC("e1000_spi_eeprom_ready");
4930
4931 /* Read "Status Register" repeatedly until the LSB is cleared. The
4932 * EEPROM will signal that the command has been completed by clearing
4933 * bit 0 of the internal status register. If it's not cleared within
4934 * 5 milliseconds, then error out.
4935 */
4936 retry_count = 0;
4937 do {
4938 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
4939 hw->eeprom.opcode_bits);
4940 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
4941 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
4942 break;
4943
4944 udelay(5);
4945 retry_count += 5;
4946
4947 e1000_standby_eeprom(hw);
Auke Kok8fc897b2006-08-28 14:56:16 -07004948 } while (retry_count < EEPROM_MAX_RETRY_SPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004949
4950 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
4951 * only 0-5mSec on 5V devices)
4952 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004953 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 DEBUGOUT("SPI EEPROM Status error\n");
4955 return -E1000_ERR_EEPROM;
4956 }
4957
4958 return E1000_SUCCESS;
4959}
4960
4961/******************************************************************************
4962 * Reads a 16 bit word from the EEPROM.
4963 *
4964 * hw - Struct containing variables accessed by shared code
4965 * offset - offset of word in the EEPROM to read
4966 * data - word read from the EEPROM
4967 * words - number of words to read
4968 *****************************************************************************/
4969int32_t
4970e1000_read_eeprom(struct e1000_hw *hw,
4971 uint16_t offset,
4972 uint16_t words,
4973 uint16_t *data)
4974{
4975 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4976 uint32_t i = 0;
4977
4978 DEBUGFUNC("e1000_read_eeprom");
Malli Chilakala2d7edb92005-04-28 19:43:52 -07004979
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004980 /* If eeprom is not yet detected, do so now */
4981 if (eeprom->word_size == 0)
4982 e1000_init_eeprom_params(hw);
4983
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984 /* A check for invalid values: offset too large, too many words, and not
4985 * enough words.
4986 */
Auke Kok8fc897b2006-08-28 14:56:16 -07004987 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988 (words == 0)) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004989 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990 return -E1000_ERR_EEPROM;
4991 }
4992
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004993 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
4994 * directly. In this case, we need to acquire the EEPROM so that
4995 * FW or other port software does not interrupt.
4996 */
Jeff Kirsher4d351852006-01-12 16:50:48 -08004997 if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
Auke Kok8fc897b2006-08-28 14:56:16 -07004998 hw->eeprom.use_eerd == FALSE) {
Jeff Kirsher2a88c172006-09-27 12:54:05 -07004999 /* Prepare the EEPROM for bit-bang reading */
5000 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5001 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005002 }
5003
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005004 /* Eerd register EEPROM access requires no eeprom aquire/release */
5005 if (eeprom->use_eerd == TRUE)
5006 return e1000_read_eeprom_eerd(hw, offset, words, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005008 /* ICH EEPROM access is done via the ICH flash controller */
Auke Kokcd94dd02006-06-27 09:08:22 -07005009 if (eeprom->type == e1000_eeprom_ich8)
5010 return e1000_read_eeprom_ich8(hw, offset, words, data);
5011
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005012 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
5013 * acquired the EEPROM at this point, so any returns should relase it */
Auke Kokcd94dd02006-06-27 09:08:22 -07005014 if (eeprom->type == e1000_eeprom_spi) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015 uint16_t word_in;
5016 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
5017
Auke Kok8fc897b2006-08-28 14:56:16 -07005018 if (e1000_spi_eeprom_ready(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019 e1000_release_eeprom(hw);
5020 return -E1000_ERR_EEPROM;
5021 }
5022
5023 e1000_standby_eeprom(hw);
5024
5025 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005026 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005027 read_opcode |= EEPROM_A8_OPCODE_SPI;
5028
5029 /* Send the READ command (opcode + addr) */
5030 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
5031 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
5032
5033 /* Read the data. The address of the eeprom internally increments with
5034 * each byte (spi) being read, saving on the overhead of eeprom setup
5035 * and tear-down. The address counter will roll over if reading beyond
5036 * the size of the eeprom, thus allowing the entire memory to be read
5037 * starting from any offset. */
5038 for (i = 0; i < words; i++) {
5039 word_in = e1000_shift_in_ee_bits(hw, 16);
5040 data[i] = (word_in >> 8) | (word_in << 8);
5041 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005042 } else if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005043 for (i = 0; i < words; i++) {
5044 /* Send the READ command (opcode + addr) */
5045 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
5046 eeprom->opcode_bits);
5047 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
5048 eeprom->address_bits);
5049
5050 /* Read the data. For microwire, each word requires the overhead
5051 * of eeprom setup and tear-down. */
5052 data[i] = e1000_shift_in_ee_bits(hw, 16);
5053 e1000_standby_eeprom(hw);
5054 }
5055 }
5056
5057 /* End this read operation */
5058 e1000_release_eeprom(hw);
5059
5060 return E1000_SUCCESS;
5061}
5062
5063/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005064 * Reads a 16 bit word from the EEPROM using the EERD register.
5065 *
5066 * hw - Struct containing variables accessed by shared code
5067 * offset - offset of word in the EEPROM to read
5068 * data - word read from the EEPROM
5069 * words - number of words to read
5070 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005071static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005072e1000_read_eeprom_eerd(struct e1000_hw *hw,
5073 uint16_t offset,
5074 uint16_t words,
5075 uint16_t *data)
5076{
5077 uint32_t i, eerd = 0;
5078 int32_t error = 0;
5079
5080 for (i = 0; i < words; i++) {
5081 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
5082 E1000_EEPROM_RW_REG_START;
5083
5084 E1000_WRITE_REG(hw, EERD, eerd);
5085 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
Auke Kok76c224b2006-05-23 13:36:06 -07005086
Auke Kok8fc897b2006-08-28 14:56:16 -07005087 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005088 break;
5089 }
5090 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
Auke Kok76c224b2006-05-23 13:36:06 -07005091
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005092 }
Auke Kok76c224b2006-05-23 13:36:06 -07005093
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005094 return error;
5095}
5096
5097/******************************************************************************
5098 * Writes a 16 bit word from the EEPROM using the EEWR register.
5099 *
5100 * hw - Struct containing variables accessed by shared code
5101 * offset - offset of word in the EEPROM to read
5102 * data - word read from the EEPROM
5103 * words - number of words to read
5104 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005105static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005106e1000_write_eeprom_eewr(struct e1000_hw *hw,
5107 uint16_t offset,
5108 uint16_t words,
5109 uint16_t *data)
5110{
5111 uint32_t register_value = 0;
5112 uint32_t i = 0;
5113 int32_t error = 0;
5114
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005115 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
5116 return -E1000_ERR_SWFW_SYNC;
5117
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005118 for (i = 0; i < words; i++) {
Auke Kok76c224b2006-05-23 13:36:06 -07005119 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
5120 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005121 E1000_EEPROM_RW_REG_START;
5122
5123 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok8fc897b2006-08-28 14:56:16 -07005124 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005125 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005126 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005127
5128 E1000_WRITE_REG(hw, EEWR, register_value);
Auke Kok76c224b2006-05-23 13:36:06 -07005129
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005130 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
Auke Kok76c224b2006-05-23 13:36:06 -07005131
Auke Kok8fc897b2006-08-28 14:56:16 -07005132 if (error) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005133 break;
Auke Kok76c224b2006-05-23 13:36:06 -07005134 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005135 }
Auke Kok76c224b2006-05-23 13:36:06 -07005136
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005137 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005138 return error;
5139}
5140
5141/******************************************************************************
5142 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
5143 *
5144 * hw - Struct containing variables accessed by shared code
5145 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005146static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005147e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
5148{
5149 uint32_t attempts = 100000;
5150 uint32_t i, reg = 0;
5151 int32_t done = E1000_ERR_EEPROM;
5152
Auke Kok8fc897b2006-08-28 14:56:16 -07005153 for (i = 0; i < attempts; i++) {
5154 if (eerd == E1000_EEPROM_POLL_READ)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005155 reg = E1000_READ_REG(hw, EERD);
Auke Kok76c224b2006-05-23 13:36:06 -07005156 else
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005157 reg = E1000_READ_REG(hw, EEWR);
5158
Auke Kok8fc897b2006-08-28 14:56:16 -07005159 if (reg & E1000_EEPROM_RW_REG_DONE) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005160 done = E1000_SUCCESS;
5161 break;
5162 }
5163 udelay(5);
5164 }
5165
5166 return done;
5167}
5168
5169/***************************************************************************
5170* Description: Determines if the onboard NVM is FLASH or EEPROM.
5171*
5172* hw - Struct containing variables accessed by shared code
5173****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005174static boolean_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005175e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
5176{
5177 uint32_t eecd = 0;
5178
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005179 DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
5180
Auke Kokcd94dd02006-06-27 09:08:22 -07005181 if (hw->mac_type == e1000_ich8lan)
5182 return FALSE;
5183
5184 if (hw->mac_type == e1000_82573) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005185 eecd = E1000_READ_REG(hw, EECD);
5186
5187 /* Isolate bits 15 & 16 */
5188 eecd = ((eecd >> 15) & 0x03);
5189
5190 /* If both bits are set, device is Flash type */
Auke Kok8fc897b2006-08-28 14:56:16 -07005191 if (eecd == 0x03) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005192 return FALSE;
5193 }
5194 }
5195 return TRUE;
5196}
5197
5198/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005199 * Verifies that the EEPROM has a valid checksum
5200 *
5201 * hw - Struct containing variables accessed by shared code
5202 *
5203 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
5204 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
5205 * valid.
5206 *****************************************************************************/
5207int32_t
5208e1000_validate_eeprom_checksum(struct e1000_hw *hw)
5209{
5210 uint16_t checksum = 0;
5211 uint16_t i, eeprom_data;
5212
5213 DEBUGFUNC("e1000_validate_eeprom_checksum");
5214
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005215 if ((hw->mac_type == e1000_82573) &&
5216 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
5217 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
5218 * 10h-12h. Checksum may need to be fixed. */
5219 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
5220 if ((eeprom_data & 0x10) == 0) {
5221 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
5222 * has already been fixed. If the checksum is still wrong and this
5223 * bit is a 1, we need to return bad checksum. Otherwise, we need
5224 * to set this bit to a 1 and update the checksum. */
5225 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
5226 if ((eeprom_data & 0x8000) == 0) {
5227 eeprom_data |= 0x8000;
5228 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
5229 e1000_update_eeprom_checksum(hw);
5230 }
5231 }
5232 }
5233
Auke Kokcd94dd02006-06-27 09:08:22 -07005234 if (hw->mac_type == e1000_ich8lan) {
5235 /* Drivers must allocate the shadow ram structure for the
5236 * EEPROM checksum to be updated. Otherwise, this bit as well
5237 * as the checksum must both be set correctly for this
5238 * validation to pass.
5239 */
5240 e1000_read_eeprom(hw, 0x19, 1, &eeprom_data);
5241 if ((eeprom_data & 0x40) == 0) {
5242 eeprom_data |= 0x40;
5243 e1000_write_eeprom(hw, 0x19, 1, &eeprom_data);
5244 e1000_update_eeprom_checksum(hw);
5245 }
5246 }
5247
5248 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
5249 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250 DEBUGOUT("EEPROM Read Error\n");
5251 return -E1000_ERR_EEPROM;
5252 }
5253 checksum += eeprom_data;
5254 }
5255
Auke Kok8fc897b2006-08-28 14:56:16 -07005256 if (checksum == (uint16_t) EEPROM_SUM)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005257 return E1000_SUCCESS;
5258 else {
5259 DEBUGOUT("EEPROM Checksum Invalid\n");
5260 return -E1000_ERR_EEPROM;
5261 }
5262}
5263
5264/******************************************************************************
5265 * Calculates the EEPROM checksum and writes it to the EEPROM
5266 *
5267 * hw - Struct containing variables accessed by shared code
5268 *
5269 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
5270 * Writes the difference to word offset 63 of the EEPROM.
5271 *****************************************************************************/
5272int32_t
5273e1000_update_eeprom_checksum(struct e1000_hw *hw)
5274{
Auke Kokcd94dd02006-06-27 09:08:22 -07005275 uint32_t ctrl_ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276 uint16_t checksum = 0;
5277 uint16_t i, eeprom_data;
5278
5279 DEBUGFUNC("e1000_update_eeprom_checksum");
5280
Auke Kok8fc897b2006-08-28 14:56:16 -07005281 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
5282 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005283 DEBUGOUT("EEPROM Read Error\n");
5284 return -E1000_ERR_EEPROM;
5285 }
5286 checksum += eeprom_data;
5287 }
5288 checksum = (uint16_t) EEPROM_SUM - checksum;
Auke Kok8fc897b2006-08-28 14:56:16 -07005289 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290 DEBUGOUT("EEPROM Write Error\n");
5291 return -E1000_ERR_EEPROM;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005292 } else if (hw->eeprom.type == e1000_eeprom_flash) {
5293 e1000_commit_shadow_ram(hw);
Auke Kokcd94dd02006-06-27 09:08:22 -07005294 } else if (hw->eeprom.type == e1000_eeprom_ich8) {
5295 e1000_commit_shadow_ram(hw);
5296 /* Reload the EEPROM, or else modifications will not appear
5297 * until after next adapter reset. */
5298 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5299 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
5300 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005301 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302 }
5303 return E1000_SUCCESS;
5304}
5305
5306/******************************************************************************
5307 * Parent function for writing words to the different EEPROM types.
5308 *
5309 * hw - Struct containing variables accessed by shared code
5310 * offset - offset within the EEPROM to be written to
5311 * words - number of words to write
5312 * data - 16 bit word to be written to the EEPROM
5313 *
5314 * If e1000_update_eeprom_checksum is not called after this function, the
5315 * EEPROM will most likely contain an invalid checksum.
5316 *****************************************************************************/
5317int32_t
5318e1000_write_eeprom(struct e1000_hw *hw,
5319 uint16_t offset,
5320 uint16_t words,
5321 uint16_t *data)
5322{
5323 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5324 int32_t status = 0;
5325
5326 DEBUGFUNC("e1000_write_eeprom");
5327
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005328 /* If eeprom is not yet detected, do so now */
5329 if (eeprom->word_size == 0)
5330 e1000_init_eeprom_params(hw);
5331
Linus Torvalds1da177e2005-04-16 15:20:36 -07005332 /* A check for invalid values: offset too large, too many words, and not
5333 * enough words.
5334 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005335 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07005336 (words == 0)) {
5337 DEBUGOUT("\"words\" parameter out of bounds\n");
5338 return -E1000_ERR_EEPROM;
5339 }
5340
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005341 /* 82573 writes only through eewr */
Auke Kok8fc897b2006-08-28 14:56:16 -07005342 if (eeprom->use_eewr == TRUE)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005343 return e1000_write_eeprom_eewr(hw, offset, words, data);
5344
Auke Kokcd94dd02006-06-27 09:08:22 -07005345 if (eeprom->type == e1000_eeprom_ich8)
5346 return e1000_write_eeprom_ich8(hw, offset, words, data);
5347
Linus Torvalds1da177e2005-04-16 15:20:36 -07005348 /* Prepare the EEPROM for writing */
5349 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
5350 return -E1000_ERR_EEPROM;
5351
Auke Kok8fc897b2006-08-28 14:56:16 -07005352 if (eeprom->type == e1000_eeprom_microwire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005353 status = e1000_write_eeprom_microwire(hw, offset, words, data);
5354 } else {
5355 status = e1000_write_eeprom_spi(hw, offset, words, data);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04005356 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005357 }
5358
5359 /* Done with writing */
5360 e1000_release_eeprom(hw);
5361
5362 return status;
5363}
5364
5365/******************************************************************************
5366 * Writes a 16 bit word to a given offset in an SPI EEPROM.
5367 *
5368 * hw - Struct containing variables accessed by shared code
5369 * offset - offset within the EEPROM to be written to
5370 * words - number of words to write
5371 * data - pointer to array of 8 bit words to be written to the EEPROM
5372 *
5373 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07005374static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005375e1000_write_eeprom_spi(struct e1000_hw *hw,
5376 uint16_t offset,
5377 uint16_t words,
5378 uint16_t *data)
5379{
5380 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5381 uint16_t widx = 0;
5382
5383 DEBUGFUNC("e1000_write_eeprom_spi");
5384
5385 while (widx < words) {
5386 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
5387
Auke Kok8fc897b2006-08-28 14:56:16 -07005388 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389
5390 e1000_standby_eeprom(hw);
5391
5392 /* Send the WRITE ENABLE command (8 bit opcode ) */
5393 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
5394 eeprom->opcode_bits);
5395
5396 e1000_standby_eeprom(hw);
5397
5398 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
Auke Kok8fc897b2006-08-28 14:56:16 -07005399 if ((eeprom->address_bits == 8) && (offset >= 128))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005400 write_opcode |= EEPROM_A8_OPCODE_SPI;
5401
5402 /* Send the Write command (8-bit opcode + addr) */
5403 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
5404
5405 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
5406 eeprom->address_bits);
5407
5408 /* Send the data */
5409
5410 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
5411 while (widx < words) {
5412 uint16_t word_out = data[widx];
5413 word_out = (word_out >> 8) | (word_out << 8);
5414 e1000_shift_out_ee_bits(hw, word_out, 16);
5415 widx++;
5416
5417 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
5418 * operation, while the smaller eeproms are capable of an 8-byte
5419 * PAGE WRITE operation. Break the inner loop to pass new address
5420 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005421 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005422 e1000_standby_eeprom(hw);
5423 break;
5424 }
5425 }
5426 }
5427
5428 return E1000_SUCCESS;
5429}
5430
5431/******************************************************************************
5432 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
5433 *
5434 * hw - Struct containing variables accessed by shared code
5435 * offset - offset within the EEPROM to be written to
5436 * words - number of words to write
5437 * data - pointer to array of 16 bit words to be written to the EEPROM
5438 *
5439 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07005440static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07005441e1000_write_eeprom_microwire(struct e1000_hw *hw,
5442 uint16_t offset,
5443 uint16_t words,
5444 uint16_t *data)
5445{
5446 struct e1000_eeprom_info *eeprom = &hw->eeprom;
5447 uint32_t eecd;
5448 uint16_t words_written = 0;
5449 uint16_t i = 0;
5450
5451 DEBUGFUNC("e1000_write_eeprom_microwire");
5452
5453 /* Send the write enable command to the EEPROM (3-bit opcode plus
5454 * 6/8-bit dummy address beginning with 11). It's less work to include
5455 * the 11 of the dummy address as part of the opcode than it is to shift
5456 * it over the correct number of bits for the address. This puts the
5457 * EEPROM into write/erase mode.
5458 */
5459 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
5460 (uint16_t)(eeprom->opcode_bits + 2));
5461
5462 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5463
5464 /* Prepare the EEPROM */
5465 e1000_standby_eeprom(hw);
5466
5467 while (words_written < words) {
5468 /* Send the Write command (3-bit opcode + addr) */
5469 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
5470 eeprom->opcode_bits);
5471
5472 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
5473 eeprom->address_bits);
5474
5475 /* Send the data */
5476 e1000_shift_out_ee_bits(hw, data[words_written], 16);
5477
5478 /* Toggle the CS line. This in effect tells the EEPROM to execute
5479 * the previous command.
5480 */
5481 e1000_standby_eeprom(hw);
5482
5483 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
5484 * signal that the command has been completed by raising the DO signal.
5485 * If DO does not go high in 10 milliseconds, then error out.
5486 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005487 for (i = 0; i < 200; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005488 eecd = E1000_READ_REG(hw, EECD);
Auke Kok8fc897b2006-08-28 14:56:16 -07005489 if (eecd & E1000_EECD_DO) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005490 udelay(50);
5491 }
Auke Kok8fc897b2006-08-28 14:56:16 -07005492 if (i == 200) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005493 DEBUGOUT("EEPROM Write did not complete\n");
5494 return -E1000_ERR_EEPROM;
5495 }
5496
5497 /* Recover from write */
5498 e1000_standby_eeprom(hw);
5499
5500 words_written++;
5501 }
5502
5503 /* Send the write disable command to the EEPROM (3-bit opcode plus
5504 * 6/8-bit dummy address beginning with 10). It's less work to include
5505 * the 10 of the dummy address as part of the opcode than it is to shift
5506 * it over the correct number of bits for the address. This takes the
5507 * EEPROM out of write/erase mode.
5508 */
5509 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
5510 (uint16_t)(eeprom->opcode_bits + 2));
5511
5512 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
5513
5514 return E1000_SUCCESS;
5515}
5516
5517/******************************************************************************
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005518 * Flushes the cached eeprom to NVM. This is done by saving the modified values
5519 * in the eeprom cache and the non modified values in the currently active bank
5520 * to the new bank.
5521 *
5522 * hw - Struct containing variables accessed by shared code
5523 * offset - offset of word in the EEPROM to read
5524 * data - word read from the EEPROM
5525 * words - number of words to read
5526 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005527static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005528e1000_commit_shadow_ram(struct e1000_hw *hw)
5529{
5530 uint32_t attempts = 100000;
5531 uint32_t eecd = 0;
5532 uint32_t flop = 0;
5533 uint32_t i = 0;
5534 int32_t error = E1000_SUCCESS;
Auke Kokcd94dd02006-06-27 09:08:22 -07005535 uint32_t old_bank_offset = 0;
5536 uint32_t new_bank_offset = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07005537 uint8_t low_byte = 0;
5538 uint8_t high_byte = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07005539 boolean_t sector_write_failed = FALSE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005540
5541 if (hw->mac_type == e1000_82573) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005542 /* The flop register will be used to determine if flash type is STM */
5543 flop = E1000_READ_REG(hw, FLOP);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005544 for (i=0; i < attempts; i++) {
5545 eecd = E1000_READ_REG(hw, EECD);
5546 if ((eecd & E1000_EECD_FLUPD) == 0) {
5547 break;
5548 }
5549 udelay(5);
5550 }
5551
5552 if (i == attempts) {
5553 return -E1000_ERR_EEPROM;
5554 }
5555
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005556 /* If STM opcode located in bits 15:8 of flop, reset firmware */
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005557 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
5558 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
5559 }
5560
5561 /* Perform the flash update */
5562 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
5563
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005564 for (i=0; i < attempts; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005565 eecd = E1000_READ_REG(hw, EECD);
5566 if ((eecd & E1000_EECD_FLUPD) == 0) {
5567 break;
5568 }
5569 udelay(5);
5570 }
5571
5572 if (i == attempts) {
5573 return -E1000_ERR_EEPROM;
5574 }
5575 }
5576
Auke Kokcd94dd02006-06-27 09:08:22 -07005577 if (hw->mac_type == e1000_ich8lan && hw->eeprom_shadow_ram != NULL) {
5578 /* We're writing to the opposite bank so if we're on bank 1,
5579 * write to bank 0 etc. We also need to erase the segment that
5580 * is going to be written */
5581 if (!(E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL)) {
5582 new_bank_offset = hw->flash_bank_size * 2;
5583 old_bank_offset = 0;
5584 e1000_erase_ich8_4k_segment(hw, 1);
5585 } else {
5586 old_bank_offset = hw->flash_bank_size * 2;
5587 new_bank_offset = 0;
5588 e1000_erase_ich8_4k_segment(hw, 0);
5589 }
5590
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005591 sector_write_failed = FALSE;
5592 /* Loop for every byte in the shadow RAM,
5593 * which is in units of words. */
5594 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5595 /* Determine whether to write the value stored
5596 * in the other NVM bank or a modified value stored
5597 * in the shadow RAM */
5598 if (hw->eeprom_shadow_ram[i].modified == TRUE) {
5599 low_byte = (uint8_t)hw->eeprom_shadow_ram[i].eeprom_word;
5600 udelay(100);
5601 error = e1000_verify_write_ich8_byte(hw,
5602 (i << 1) + new_bank_offset, low_byte);
5603
5604 if (error != E1000_SUCCESS)
5605 sector_write_failed = TRUE;
5606 else {
Auke Kokcd94dd02006-06-27 09:08:22 -07005607 high_byte =
5608 (uint8_t)(hw->eeprom_shadow_ram[i].eeprom_word >> 8);
Auke Kokcd94dd02006-06-27 09:08:22 -07005609 udelay(100);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005610 }
5611 } else {
5612 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset,
5613 &low_byte);
5614 udelay(100);
5615 error = e1000_verify_write_ich8_byte(hw,
5616 (i << 1) + new_bank_offset, low_byte);
5617
5618 if (error != E1000_SUCCESS)
5619 sector_write_failed = TRUE;
5620 else {
Auke Kokcd94dd02006-06-27 09:08:22 -07005621 e1000_read_ich8_byte(hw, (i << 1) + old_bank_offset + 1,
5622 &high_byte);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005623 udelay(100);
Auke Kokcd94dd02006-06-27 09:08:22 -07005624 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005625 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005626
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005627 /* If the write of the low byte was successful, go ahread and
5628 * write the high byte while checking to make sure that if it
5629 * is the signature byte, then it is handled properly */
5630 if (sector_write_failed == FALSE) {
Auke Kokcd94dd02006-06-27 09:08:22 -07005631 /* If the word is 0x13, then make sure the signature bits
5632 * (15:14) are 11b until the commit has completed.
5633 * This will allow us to write 10b which indicates the
5634 * signature is valid. We want to do this after the write
5635 * has completed so that we don't mark the segment valid
5636 * while the write is still in progress */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005637 if (i == E1000_ICH_NVM_SIG_WORD)
5638 high_byte = E1000_ICH_NVM_SIG_MASK | high_byte;
Auke Kokcd94dd02006-06-27 09:08:22 -07005639
5640 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005641 (i << 1) + new_bank_offset + 1, high_byte);
Auke Kokcd94dd02006-06-27 09:08:22 -07005642 if (error != E1000_SUCCESS)
5643 sector_write_failed = TRUE;
5644
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005645 } else {
5646 /* If the write failed then break from the loop and
5647 * return an error */
5648 break;
5649 }
5650 }
5651
5652 /* Don't bother writing the segment valid bits if sector
5653 * programming failed. */
5654 if (sector_write_failed == FALSE) {
5655 /* Finally validate the new segment by setting bit 15:14
5656 * to 10b in word 0x13 , this can be done without an
5657 * erase as well since these bits are 11 to start with
5658 * and we need to change bit 14 to 0b */
5659 e1000_read_ich8_byte(hw,
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005660 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset,
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005661 &high_byte);
5662 high_byte &= 0xBF;
5663 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005664 E1000_ICH_NVM_SIG_WORD * 2 + 1 + new_bank_offset, high_byte);
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005665 /* And invalidate the previously valid segment by setting
5666 * its signature word (0x13) high_byte to 0b. This can be
5667 * done without an erase because flash erase sets all bits
5668 * to 1's. We can write 1's to 0's without an erase */
5669 if (error == E1000_SUCCESS) {
5670 error = e1000_verify_write_ich8_byte(hw,
Jeff Kirsher2df7d592006-11-01 08:48:02 -08005671 E1000_ICH_NVM_SIG_WORD * 2 + 1 + old_bank_offset, 0);
Auke Kokcd94dd02006-06-27 09:08:22 -07005672 }
5673
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005674 /* Clear the now not used entry in the cache */
5675 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
5676 hw->eeprom_shadow_ram[i].modified = FALSE;
5677 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005678 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07005679 }
Auke Kokcd94dd02006-06-27 09:08:22 -07005680 }
5681
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005682 return error;
5683}
5684
5685/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005686 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
5687 * second function of dual function devices
5688 *
5689 * hw - Struct containing variables accessed by shared code
5690 *****************************************************************************/
5691int32_t
5692e1000_read_mac_addr(struct e1000_hw * hw)
5693{
5694 uint16_t offset;
5695 uint16_t eeprom_data, i;
5696
5697 DEBUGFUNC("e1000_read_mac_addr");
5698
Auke Kok8fc897b2006-08-28 14:56:16 -07005699 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005700 offset = i >> 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07005701 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005702 DEBUGOUT("EEPROM Read Error\n");
5703 return -E1000_ERR_EEPROM;
5704 }
5705 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
5706 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
5707 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08005708
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005709 switch (hw->mac_type) {
5710 default:
5711 break;
5712 case e1000_82546:
5713 case e1000_82546_rev_3:
5714 case e1000_82571:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005715 case e1000_80003es2lan:
Auke Kok8fc897b2006-08-28 14:56:16 -07005716 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005717 hw->perm_mac_addr[5] ^= 0x01;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005718 break;
5719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005720
Auke Kok8fc897b2006-08-28 14:56:16 -07005721 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005722 hw->mac_addr[i] = hw->perm_mac_addr[i];
5723 return E1000_SUCCESS;
5724}
5725
5726/******************************************************************************
5727 * Initializes receive address filters.
5728 *
5729 * hw - Struct containing variables accessed by shared code
5730 *
5731 * Places the MAC address in receive address register 0 and clears the rest
5732 * of the receive addresss registers. Clears the multicast table. Assumes
5733 * the receiver is in reset when the routine is called.
5734 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005735static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005736e1000_init_rx_addrs(struct e1000_hw *hw)
5737{
5738 uint32_t i;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005739 uint32_t rar_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005740
5741 DEBUGFUNC("e1000_init_rx_addrs");
5742
5743 /* Setup the receive address. */
5744 DEBUGOUT("Programming MAC Address into RAR[0]\n");
5745
5746 e1000_rar_set(hw, hw->mac_addr, 0);
5747
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005748 rar_num = E1000_RAR_ENTRIES;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04005749
5750 /* Reserve a spot for the Locally Administered Address to work around
5751 * an 82571 issue in which a reset on one port will reload the MAC on
5752 * the other port. */
5753 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
5754 rar_num -= 1;
Auke Kokcd94dd02006-06-27 09:08:22 -07005755 if (hw->mac_type == e1000_ich8lan)
5756 rar_num = E1000_RAR_ENTRIES_ICH8LAN;
5757
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758 /* Zero out the other 15 receive addresses. */
5759 DEBUGOUT("Clearing RAR[1-15]\n");
Auke Kok8fc897b2006-08-28 14:56:16 -07005760 for (i = 1; i < rar_num; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005761 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005762 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005763 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
Auke Kok4ca213a2006-06-27 09:07:08 -07005764 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005765 }
5766}
5767
5768/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07005769 * Hashes an address to determine its location in the multicast table
5770 *
5771 * hw - Struct containing variables accessed by shared code
5772 * mc_addr - the multicast address to hash
5773 *****************************************************************************/
5774uint32_t
5775e1000_hash_mc_addr(struct e1000_hw *hw,
5776 uint8_t *mc_addr)
5777{
5778 uint32_t hash_value = 0;
5779
5780 /* The portion of the address that is used for the hash table is
5781 * determined by the mc_filter_type setting.
5782 */
5783 switch (hw->mc_filter_type) {
5784 /* [0] [1] [2] [3] [4] [5]
5785 * 01 AA 00 12 34 56
5786 * LSB MSB
5787 */
5788 case 0:
Auke Kokcd94dd02006-06-27 09:08:22 -07005789 if (hw->mac_type == e1000_ich8lan) {
5790 /* [47:38] i.e. 0x158 for above example address */
5791 hash_value = ((mc_addr[4] >> 6) | (((uint16_t) mc_addr[5]) << 2));
5792 } else {
5793 /* [47:36] i.e. 0x563 for above example address */
5794 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5795 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005796 break;
5797 case 1:
Auke Kokcd94dd02006-06-27 09:08:22 -07005798 if (hw->mac_type == e1000_ich8lan) {
5799 /* [46:37] i.e. 0x2B1 for above example address */
5800 hash_value = ((mc_addr[4] >> 5) | (((uint16_t) mc_addr[5]) << 3));
5801 } else {
5802 /* [46:35] i.e. 0xAC6 for above example address */
5803 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
5804 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005805 break;
5806 case 2:
Auke Kokcd94dd02006-06-27 09:08:22 -07005807 if (hw->mac_type == e1000_ich8lan) {
5808 /*[45:36] i.e. 0x163 for above example address */
5809 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
5810 } else {
5811 /* [45:34] i.e. 0x5D8 for above example address */
5812 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5813 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005814 break;
5815 case 3:
Auke Kokcd94dd02006-06-27 09:08:22 -07005816 if (hw->mac_type == e1000_ich8lan) {
5817 /* [43:34] i.e. 0x18D for above example address */
5818 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
5819 } else {
5820 /* [43:32] i.e. 0x634 for above example address */
5821 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
5822 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005823 break;
5824 }
5825
5826 hash_value &= 0xFFF;
Auke Kokcd94dd02006-06-27 09:08:22 -07005827 if (hw->mac_type == e1000_ich8lan)
5828 hash_value &= 0x3FF;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005829
Linus Torvalds1da177e2005-04-16 15:20:36 -07005830 return hash_value;
5831}
5832
5833/******************************************************************************
5834 * Sets the bit in the multicast table corresponding to the hash value.
5835 *
5836 * hw - Struct containing variables accessed by shared code
5837 * hash_value - Multicast address hash value
5838 *****************************************************************************/
5839void
5840e1000_mta_set(struct e1000_hw *hw,
5841 uint32_t hash_value)
5842{
5843 uint32_t hash_bit, hash_reg;
5844 uint32_t mta;
5845 uint32_t temp;
5846
5847 /* The MTA is a register array of 128 32-bit registers.
5848 * It is treated like an array of 4096 bits. We want to set
5849 * bit BitArray[hash_value]. So we figure out what register
5850 * the bit is in, read it, OR in the new bit, then write
5851 * back the new value. The register is determined by the
5852 * upper 7 bits of the hash value and the bit within that
5853 * register are determined by the lower 5 bits of the value.
5854 */
5855 hash_reg = (hash_value >> 5) & 0x7F;
Auke Kokcd94dd02006-06-27 09:08:22 -07005856 if (hw->mac_type == e1000_ich8lan)
5857 hash_reg &= 0x1F;
Auke Kok90fb5132006-11-01 08:47:30 -08005858
Linus Torvalds1da177e2005-04-16 15:20:36 -07005859 hash_bit = hash_value & 0x1F;
5860
5861 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
5862
5863 mta |= (1 << hash_bit);
5864
5865 /* If we are on an 82544 and we are trying to write an odd offset
5866 * in the MTA, save off the previous entry before writing and
5867 * restore the old value after writing.
5868 */
Auke Kok8fc897b2006-08-28 14:56:16 -07005869 if ((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005870 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
5871 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005872 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005873 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005874 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005875 } else {
5876 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
Auke Kok4ca213a2006-06-27 09:07:08 -07005877 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005878 }
5879}
5880
5881/******************************************************************************
5882 * Puts an ethernet address into a receive address register.
5883 *
5884 * hw - Struct containing variables accessed by shared code
5885 * addr - Address to put into receive address register
5886 * index - Receive address register to write
5887 *****************************************************************************/
5888void
5889e1000_rar_set(struct e1000_hw *hw,
5890 uint8_t *addr,
5891 uint32_t index)
5892{
5893 uint32_t rar_low, rar_high;
5894
5895 /* HW expects these in little endian so we reverse the byte order
5896 * from network order (big endian) to little endian
5897 */
5898 rar_low = ((uint32_t) addr[0] |
5899 ((uint32_t) addr[1] << 8) |
5900 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005901 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005902
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005903 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
5904 * unit hang.
5905 *
5906 * Description:
5907 * If there are any Rx frames queued up or otherwise present in the HW
5908 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
5909 * hang. To work around this issue, we have to disable receives and
5910 * flush out all Rx frames before we enable RSS. To do so, we modify we
5911 * redirect all Rx traffic to manageability and then reset the HW.
5912 * This flushes away Rx frames, and (since the redirections to
5913 * manageability persists across resets) keeps new ones from coming in
5914 * while we work. Then, we clear the Address Valid AV bit for all MAC
5915 * addresses and undo the re-direction to manageability.
5916 * Now, frames are coming in again, but the MAC won't accept them, so
5917 * far so good. We now proceed to initialize RSS (if necessary) and
5918 * configure the Rx unit. Last, we re-enable the AV bits and continue
5919 * on our merry way.
5920 */
5921 switch (hw->mac_type) {
5922 case e1000_82571:
5923 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08005924 case e1000_80003es2lan:
Jeff Kirsher8df06e52006-03-02 18:18:32 -08005925 if (hw->leave_av_bit_off == TRUE)
5926 break;
5927 default:
5928 /* Indicate to hardware the Address is Valid. */
5929 rar_high |= E1000_RAH_AV;
5930 break;
5931 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005932
5933 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
Auke Kok4ca213a2006-06-27 09:07:08 -07005934 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005935 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
Auke Kok4ca213a2006-06-27 09:07:08 -07005936 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005937}
5938
5939/******************************************************************************
5940 * Writes a value to the specified offset in the VLAN filter table.
5941 *
5942 * hw - Struct containing variables accessed by shared code
5943 * offset - Offset in VLAN filer table to write
5944 * value - Value to write into VLAN filter table
5945 *****************************************************************************/
5946void
5947e1000_write_vfta(struct e1000_hw *hw,
5948 uint32_t offset,
5949 uint32_t value)
5950{
5951 uint32_t temp;
5952
Auke Kokcd94dd02006-06-27 09:08:22 -07005953 if (hw->mac_type == e1000_ich8lan)
5954 return;
5955
5956 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005957 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
5958 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005959 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005960 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
Auke Kok4ca213a2006-06-27 09:07:08 -07005961 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005962 } else {
5963 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
Auke Kok4ca213a2006-06-27 09:07:08 -07005964 E1000_WRITE_FLUSH(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005965 }
5966}
5967
5968/******************************************************************************
5969 * Clears the VLAN filer table
5970 *
5971 * hw - Struct containing variables accessed by shared code
5972 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01005973static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07005974e1000_clear_vfta(struct e1000_hw *hw)
5975{
5976 uint32_t offset;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005977 uint32_t vfta_value = 0;
5978 uint32_t vfta_offset = 0;
5979 uint32_t vfta_bit_in_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005980
Auke Kokcd94dd02006-06-27 09:08:22 -07005981 if (hw->mac_type == e1000_ich8lan)
5982 return;
5983
Malli Chilakala2d7edb92005-04-28 19:43:52 -07005984 if (hw->mac_type == e1000_82573) {
5985 if (hw->mng_cookie.vlan_id != 0) {
5986 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
5987 * ID. The following operations determine which 32b entry
5988 * (i.e. offset) into the array we want to set the VLAN ID
5989 * (i.e. bit) of the manageability unit. */
5990 vfta_offset = (hw->mng_cookie.vlan_id >>
5991 E1000_VFTA_ENTRY_SHIFT) &
5992 E1000_VFTA_ENTRY_MASK;
5993 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
5994 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
5995 }
5996 }
5997 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
5998 /* If the offset we want to clear is the same offset of the
5999 * manageability VLAN ID, then clear all bits except that of the
6000 * manageability unit */
6001 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
6002 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
Auke Kok4ca213a2006-06-27 09:07:08 -07006003 E1000_WRITE_FLUSH(hw);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006004 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006005}
6006
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006007static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008e1000_id_led_init(struct e1000_hw * hw)
6009{
6010 uint32_t ledctl;
6011 const uint32_t ledctl_mask = 0x000000FF;
6012 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
6013 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
6014 uint16_t eeprom_data, i, temp;
6015 const uint16_t led_mask = 0x0F;
6016
6017 DEBUGFUNC("e1000_id_led_init");
6018
Auke Kok8fc897b2006-08-28 14:56:16 -07006019 if (hw->mac_type < e1000_82540) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006020 /* Nothing to do */
6021 return E1000_SUCCESS;
6022 }
6023
6024 ledctl = E1000_READ_REG(hw, LEDCTL);
6025 hw->ledctl_default = ledctl;
6026 hw->ledctl_mode1 = hw->ledctl_default;
6027 hw->ledctl_mode2 = hw->ledctl_default;
6028
Auke Kok8fc897b2006-08-28 14:56:16 -07006029 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030 DEBUGOUT("EEPROM Read Error\n");
6031 return -E1000_ERR_EEPROM;
6032 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006033
6034 if ((hw->mac_type == e1000_82573) &&
6035 (eeprom_data == ID_LED_RESERVED_82573))
6036 eeprom_data = ID_LED_DEFAULT_82573;
6037 else if ((eeprom_data == ID_LED_RESERVED_0000) ||
6038 (eeprom_data == ID_LED_RESERVED_FFFF)) {
6039 if (hw->mac_type == e1000_ich8lan)
6040 eeprom_data = ID_LED_DEFAULT_ICH8LAN;
6041 else
6042 eeprom_data = ID_LED_DEFAULT;
6043 }
Auke Kok90fb5132006-11-01 08:47:30 -08006044
Auke Kokcd94dd02006-06-27 09:08:22 -07006045 for (i = 0; i < 4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006046 temp = (eeprom_data >> (i << 2)) & led_mask;
Auke Kok8fc897b2006-08-28 14:56:16 -07006047 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006048 case ID_LED_ON1_DEF2:
6049 case ID_LED_ON1_ON2:
6050 case ID_LED_ON1_OFF2:
6051 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6052 hw->ledctl_mode1 |= ledctl_on << (i << 3);
6053 break;
6054 case ID_LED_OFF1_DEF2:
6055 case ID_LED_OFF1_ON2:
6056 case ID_LED_OFF1_OFF2:
6057 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
6058 hw->ledctl_mode1 |= ledctl_off << (i << 3);
6059 break;
6060 default:
6061 /* Do nothing */
6062 break;
6063 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006064 switch (temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006065 case ID_LED_DEF1_ON2:
6066 case ID_LED_ON1_ON2:
6067 case ID_LED_OFF1_ON2:
6068 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6069 hw->ledctl_mode2 |= ledctl_on << (i << 3);
6070 break;
6071 case ID_LED_DEF1_OFF2:
6072 case ID_LED_ON1_OFF2:
6073 case ID_LED_OFF1_OFF2:
6074 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
6075 hw->ledctl_mode2 |= ledctl_off << (i << 3);
6076 break;
6077 default:
6078 /* Do nothing */
6079 break;
6080 }
6081 }
6082 return E1000_SUCCESS;
6083}
6084
6085/******************************************************************************
6086 * Prepares SW controlable LED for use and saves the current state of the LED.
6087 *
6088 * hw - Struct containing variables accessed by shared code
6089 *****************************************************************************/
6090int32_t
6091e1000_setup_led(struct e1000_hw *hw)
6092{
6093 uint32_t ledctl;
6094 int32_t ret_val = E1000_SUCCESS;
6095
6096 DEBUGFUNC("e1000_setup_led");
6097
Auke Kok8fc897b2006-08-28 14:56:16 -07006098 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006099 case e1000_82542_rev2_0:
6100 case e1000_82542_rev2_1:
6101 case e1000_82543:
6102 case e1000_82544:
6103 /* No setup necessary */
6104 break;
6105 case e1000_82541:
6106 case e1000_82547:
6107 case e1000_82541_rev_2:
6108 case e1000_82547_rev_2:
6109 /* Turn off PHY Smart Power Down (if enabled) */
6110 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
6111 &hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006112 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113 return ret_val;
6114 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6115 (uint16_t)(hw->phy_spd_default &
6116 ~IGP01E1000_GMII_SPD));
Auke Kok8fc897b2006-08-28 14:56:16 -07006117 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118 return ret_val;
6119 /* Fall Through */
6120 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006121 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006122 ledctl = E1000_READ_REG(hw, LEDCTL);
6123 /* Save current LEDCTL settings */
6124 hw->ledctl_default = ledctl;
6125 /* Turn off LED0 */
6126 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
6127 E1000_LEDCTL_LED0_BLINK |
6128 E1000_LEDCTL_LED0_MODE_MASK);
6129 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
6130 E1000_LEDCTL_LED0_MODE_SHIFT);
6131 E1000_WRITE_REG(hw, LEDCTL, ledctl);
Auke Kok8fc897b2006-08-28 14:56:16 -07006132 } else if (hw->media_type == e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6134 break;
6135 }
6136
6137 return E1000_SUCCESS;
6138}
6139
Auke Kok8fc897b2006-08-28 14:56:16 -07006140
Linus Torvalds1da177e2005-04-16 15:20:36 -07006141/******************************************************************************
Auke Kokf1b3a852006-06-27 09:07:56 -07006142 * Used on 82571 and later Si that has LED blink bits.
6143 * Callers must use their own timer and should have already called
6144 * e1000_id_led_init()
6145 * Call e1000_cleanup led() to stop blinking
6146 *
6147 * hw - Struct containing variables accessed by shared code
6148 *****************************************************************************/
6149int32_t
6150e1000_blink_led_start(struct e1000_hw *hw)
6151{
6152 int16_t i;
6153 uint32_t ledctl_blink = 0;
6154
6155 DEBUGFUNC("e1000_id_led_blink_on");
6156
6157 if (hw->mac_type < e1000_82571) {
6158 /* Nothing to do */
6159 return E1000_SUCCESS;
6160 }
6161 if (hw->media_type == e1000_media_type_fiber) {
6162 /* always blink LED0 for PCI-E fiber */
6163 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
6164 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
6165 } else {
6166 /* set the blink bit for each LED that's "on" (0x0E) in ledctl_mode2 */
6167 ledctl_blink = hw->ledctl_mode2;
6168 for (i=0; i < 4; i++)
6169 if (((hw->ledctl_mode2 >> (i * 8)) & 0xFF) ==
6170 E1000_LEDCTL_MODE_LED_ON)
6171 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << (i * 8));
6172 }
6173
6174 E1000_WRITE_REG(hw, LEDCTL, ledctl_blink);
6175
6176 return E1000_SUCCESS;
6177}
6178
6179/******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180 * Restores the saved state of the SW controlable LED.
6181 *
6182 * hw - Struct containing variables accessed by shared code
6183 *****************************************************************************/
6184int32_t
6185e1000_cleanup_led(struct e1000_hw *hw)
6186{
6187 int32_t ret_val = E1000_SUCCESS;
6188
6189 DEBUGFUNC("e1000_cleanup_led");
6190
Auke Kok8fc897b2006-08-28 14:56:16 -07006191 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192 case e1000_82542_rev2_0:
6193 case e1000_82542_rev2_1:
6194 case e1000_82543:
6195 case e1000_82544:
6196 /* No cleanup necessary */
6197 break;
6198 case e1000_82541:
6199 case e1000_82547:
6200 case e1000_82541_rev_2:
6201 case e1000_82547_rev_2:
6202 /* Turn on PHY Smart Power Down (if previously enabled) */
6203 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
6204 hw->phy_spd_default);
Auke Kok8fc897b2006-08-28 14:56:16 -07006205 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206 return ret_val;
6207 /* Fall Through */
6208 default:
Auke Kokcd94dd02006-06-27 09:08:22 -07006209 if (hw->phy_type == e1000_phy_ife) {
6210 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
6211 break;
6212 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006213 /* Restore LEDCTL settings */
6214 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
6215 break;
6216 }
6217
6218 return E1000_SUCCESS;
6219}
6220
6221/******************************************************************************
6222 * Turns on the software controllable LED
6223 *
6224 * hw - Struct containing variables accessed by shared code
6225 *****************************************************************************/
6226int32_t
6227e1000_led_on(struct e1000_hw *hw)
6228{
6229 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6230
6231 DEBUGFUNC("e1000_led_on");
6232
Auke Kok8fc897b2006-08-28 14:56:16 -07006233 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006234 case e1000_82542_rev2_0:
6235 case e1000_82542_rev2_1:
6236 case e1000_82543:
6237 /* Set SW Defineable Pin 0 to turn on the LED */
6238 ctrl |= E1000_CTRL_SWDPIN0;
6239 ctrl |= E1000_CTRL_SWDPIO0;
6240 break;
6241 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006242 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243 /* Set SW Defineable Pin 0 to turn on the LED */
6244 ctrl |= E1000_CTRL_SWDPIN0;
6245 ctrl |= E1000_CTRL_SWDPIO0;
6246 } else {
6247 /* Clear SW Defineable Pin 0 to turn on the LED */
6248 ctrl &= ~E1000_CTRL_SWDPIN0;
6249 ctrl |= E1000_CTRL_SWDPIO0;
6250 }
6251 break;
6252 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006253 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006254 /* Clear SW Defineable Pin 0 to turn on the LED */
6255 ctrl &= ~E1000_CTRL_SWDPIN0;
6256 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006257 } else if (hw->phy_type == e1000_phy_ife) {
6258 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6259 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
6260 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006261 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
6262 return E1000_SUCCESS;
6263 }
6264 break;
6265 }
6266
6267 E1000_WRITE_REG(hw, CTRL, ctrl);
6268
6269 return E1000_SUCCESS;
6270}
6271
6272/******************************************************************************
6273 * Turns off the software controllable LED
6274 *
6275 * hw - Struct containing variables accessed by shared code
6276 *****************************************************************************/
6277int32_t
6278e1000_led_off(struct e1000_hw *hw)
6279{
6280 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
6281
6282 DEBUGFUNC("e1000_led_off");
6283
Auke Kok8fc897b2006-08-28 14:56:16 -07006284 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285 case e1000_82542_rev2_0:
6286 case e1000_82542_rev2_1:
6287 case e1000_82543:
6288 /* Clear SW Defineable Pin 0 to turn off the LED */
6289 ctrl &= ~E1000_CTRL_SWDPIN0;
6290 ctrl |= E1000_CTRL_SWDPIO0;
6291 break;
6292 case e1000_82544:
Auke Kok8fc897b2006-08-28 14:56:16 -07006293 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006294 /* Clear SW Defineable Pin 0 to turn off the LED */
6295 ctrl &= ~E1000_CTRL_SWDPIN0;
6296 ctrl |= E1000_CTRL_SWDPIO0;
6297 } else {
6298 /* Set SW Defineable Pin 0 to turn off the LED */
6299 ctrl |= E1000_CTRL_SWDPIN0;
6300 ctrl |= E1000_CTRL_SWDPIO0;
6301 }
6302 break;
6303 default:
Auke Kok8fc897b2006-08-28 14:56:16 -07006304 if (hw->media_type == e1000_media_type_fiber) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006305 /* Set SW Defineable Pin 0 to turn off the LED */
6306 ctrl |= E1000_CTRL_SWDPIN0;
6307 ctrl |= E1000_CTRL_SWDPIO0;
Auke Kokcd94dd02006-06-27 09:08:22 -07006308 } else if (hw->phy_type == e1000_phy_ife) {
6309 e1000_write_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
6310 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
6311 } else if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006312 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
6313 return E1000_SUCCESS;
6314 }
6315 break;
6316 }
6317
6318 E1000_WRITE_REG(hw, CTRL, ctrl);
6319
6320 return E1000_SUCCESS;
6321}
6322
6323/******************************************************************************
6324 * Clears all hardware statistics counters.
6325 *
6326 * hw - Struct containing variables accessed by shared code
6327 *****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07006328static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006329e1000_clear_hw_cntrs(struct e1000_hw *hw)
6330{
6331 volatile uint32_t temp;
6332
6333 temp = E1000_READ_REG(hw, CRCERRS);
6334 temp = E1000_READ_REG(hw, SYMERRS);
6335 temp = E1000_READ_REG(hw, MPC);
6336 temp = E1000_READ_REG(hw, SCC);
6337 temp = E1000_READ_REG(hw, ECOL);
6338 temp = E1000_READ_REG(hw, MCC);
6339 temp = E1000_READ_REG(hw, LATECOL);
6340 temp = E1000_READ_REG(hw, COLC);
6341 temp = E1000_READ_REG(hw, DC);
6342 temp = E1000_READ_REG(hw, SEC);
6343 temp = E1000_READ_REG(hw, RLEC);
6344 temp = E1000_READ_REG(hw, XONRXC);
6345 temp = E1000_READ_REG(hw, XONTXC);
6346 temp = E1000_READ_REG(hw, XOFFRXC);
6347 temp = E1000_READ_REG(hw, XOFFTXC);
6348 temp = E1000_READ_REG(hw, FCRUC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006349
6350 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351 temp = E1000_READ_REG(hw, PRC64);
6352 temp = E1000_READ_REG(hw, PRC127);
6353 temp = E1000_READ_REG(hw, PRC255);
6354 temp = E1000_READ_REG(hw, PRC511);
6355 temp = E1000_READ_REG(hw, PRC1023);
6356 temp = E1000_READ_REG(hw, PRC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006357 }
6358
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359 temp = E1000_READ_REG(hw, GPRC);
6360 temp = E1000_READ_REG(hw, BPRC);
6361 temp = E1000_READ_REG(hw, MPRC);
6362 temp = E1000_READ_REG(hw, GPTC);
6363 temp = E1000_READ_REG(hw, GORCL);
6364 temp = E1000_READ_REG(hw, GORCH);
6365 temp = E1000_READ_REG(hw, GOTCL);
6366 temp = E1000_READ_REG(hw, GOTCH);
6367 temp = E1000_READ_REG(hw, RNBC);
6368 temp = E1000_READ_REG(hw, RUC);
6369 temp = E1000_READ_REG(hw, RFC);
6370 temp = E1000_READ_REG(hw, ROC);
6371 temp = E1000_READ_REG(hw, RJC);
6372 temp = E1000_READ_REG(hw, TORL);
6373 temp = E1000_READ_REG(hw, TORH);
6374 temp = E1000_READ_REG(hw, TOTL);
6375 temp = E1000_READ_REG(hw, TOTH);
6376 temp = E1000_READ_REG(hw, TPR);
6377 temp = E1000_READ_REG(hw, TPT);
Auke Kokcd94dd02006-06-27 09:08:22 -07006378
6379 if (hw->mac_type != e1000_ich8lan) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006380 temp = E1000_READ_REG(hw, PTC64);
6381 temp = E1000_READ_REG(hw, PTC127);
6382 temp = E1000_READ_REG(hw, PTC255);
6383 temp = E1000_READ_REG(hw, PTC511);
6384 temp = E1000_READ_REG(hw, PTC1023);
6385 temp = E1000_READ_REG(hw, PTC1522);
Auke Kokcd94dd02006-06-27 09:08:22 -07006386 }
6387
Linus Torvalds1da177e2005-04-16 15:20:36 -07006388 temp = E1000_READ_REG(hw, MPTC);
6389 temp = E1000_READ_REG(hw, BPTC);
6390
Auke Kok8fc897b2006-08-28 14:56:16 -07006391 if (hw->mac_type < e1000_82543) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006392
6393 temp = E1000_READ_REG(hw, ALGNERRC);
6394 temp = E1000_READ_REG(hw, RXERRC);
6395 temp = E1000_READ_REG(hw, TNCRS);
6396 temp = E1000_READ_REG(hw, CEXTERR);
6397 temp = E1000_READ_REG(hw, TSCTC);
6398 temp = E1000_READ_REG(hw, TSCTFC);
6399
Auke Kok8fc897b2006-08-28 14:56:16 -07006400 if (hw->mac_type <= e1000_82544) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006401
6402 temp = E1000_READ_REG(hw, MGTPRC);
6403 temp = E1000_READ_REG(hw, MGTPDC);
6404 temp = E1000_READ_REG(hw, MGTPTC);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006405
Auke Kok8fc897b2006-08-28 14:56:16 -07006406 if (hw->mac_type <= e1000_82547_rev_2) return;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006407
6408 temp = E1000_READ_REG(hw, IAC);
6409 temp = E1000_READ_REG(hw, ICRXOC);
Auke Kokcd94dd02006-06-27 09:08:22 -07006410
6411 if (hw->mac_type == e1000_ich8lan) return;
6412
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006413 temp = E1000_READ_REG(hw, ICRXPTC);
6414 temp = E1000_READ_REG(hw, ICRXATC);
6415 temp = E1000_READ_REG(hw, ICTXPTC);
6416 temp = E1000_READ_REG(hw, ICTXATC);
6417 temp = E1000_READ_REG(hw, ICTXQEC);
6418 temp = E1000_READ_REG(hw, ICTXQMTC);
6419 temp = E1000_READ_REG(hw, ICRXDMTC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420}
6421
6422/******************************************************************************
6423 * Resets Adaptive IFS to its default state.
6424 *
6425 * hw - Struct containing variables accessed by shared code
6426 *
6427 * Call this after e1000_init_hw. You may override the IFS defaults by setting
6428 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
6429 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
6430 * before calling this function.
6431 *****************************************************************************/
6432void
6433e1000_reset_adaptive(struct e1000_hw *hw)
6434{
6435 DEBUGFUNC("e1000_reset_adaptive");
6436
Auke Kok8fc897b2006-08-28 14:56:16 -07006437 if (hw->adaptive_ifs) {
6438 if (!hw->ifs_params_forced) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439 hw->current_ifs_val = 0;
6440 hw->ifs_min_val = IFS_MIN;
6441 hw->ifs_max_val = IFS_MAX;
6442 hw->ifs_step_size = IFS_STEP;
6443 hw->ifs_ratio = IFS_RATIO;
6444 }
6445 hw->in_ifs_mode = FALSE;
6446 E1000_WRITE_REG(hw, AIT, 0);
6447 } else {
6448 DEBUGOUT("Not in Adaptive IFS mode!\n");
6449 }
6450}
6451
6452/******************************************************************************
6453 * Called during the callback/watchdog routine to update IFS value based on
6454 * the ratio of transmits to collisions.
6455 *
6456 * hw - Struct containing variables accessed by shared code
6457 * tx_packets - Number of transmits since last callback
6458 * total_collisions - Number of collisions since last callback
6459 *****************************************************************************/
6460void
6461e1000_update_adaptive(struct e1000_hw *hw)
6462{
6463 DEBUGFUNC("e1000_update_adaptive");
6464
Auke Kok8fc897b2006-08-28 14:56:16 -07006465 if (hw->adaptive_ifs) {
6466 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
6467 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006468 hw->in_ifs_mode = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07006469 if (hw->current_ifs_val < hw->ifs_max_val) {
6470 if (hw->current_ifs_val == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471 hw->current_ifs_val = hw->ifs_min_val;
6472 else
6473 hw->current_ifs_val += hw->ifs_step_size;
6474 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
6475 }
6476 }
6477 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07006478 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479 hw->current_ifs_val = 0;
6480 hw->in_ifs_mode = FALSE;
6481 E1000_WRITE_REG(hw, AIT, 0);
6482 }
6483 }
6484 } else {
6485 DEBUGOUT("Not in Adaptive IFS mode!\n");
6486 }
6487}
6488
6489/******************************************************************************
6490 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
6491 *
6492 * hw - Struct containing variables accessed by shared code
6493 * frame_len - The length of the frame in question
6494 * mac_addr - The Ethernet destination address of the frame in question
6495 *****************************************************************************/
6496void
6497e1000_tbi_adjust_stats(struct e1000_hw *hw,
6498 struct e1000_hw_stats *stats,
6499 uint32_t frame_len,
6500 uint8_t *mac_addr)
6501{
6502 uint64_t carry_bit;
6503
6504 /* First adjust the frame length. */
6505 frame_len--;
6506 /* We need to adjust the statistics counters, since the hardware
6507 * counters overcount this packet as a CRC error and undercount
6508 * the packet as a good packet
6509 */
6510 /* This packet should not be counted as a CRC error. */
6511 stats->crcerrs--;
6512 /* This packet does count as a Good Packet Received. */
6513 stats->gprc++;
6514
6515 /* Adjust the Good Octets received counters */
6516 carry_bit = 0x80000000 & stats->gorcl;
6517 stats->gorcl += frame_len;
6518 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
6519 * Received Count) was one before the addition,
6520 * AND it is zero after, then we lost the carry out,
6521 * need to add one to Gorch (Good Octets Received Count High).
6522 * This could be simplified if all environments supported
6523 * 64-bit integers.
6524 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006525 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006526 stats->gorch++;
6527 /* Is this a broadcast or multicast? Check broadcast first,
6528 * since the test for a multicast frame will test positive on
6529 * a broadcast frame.
6530 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006531 if ((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006532 /* Broadcast packet */
6533 stats->bprc++;
Auke Kok8fc897b2006-08-28 14:56:16 -07006534 else if (*mac_addr & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535 /* Multicast packet */
6536 stats->mprc++;
6537
Auke Kok8fc897b2006-08-28 14:56:16 -07006538 if (frame_len == hw->max_frame_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539 /* In this case, the hardware has overcounted the number of
6540 * oversize frames.
6541 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006542 if (stats->roc > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543 stats->roc--;
6544 }
6545
6546 /* Adjust the bin counters when the extra byte put the frame in the
6547 * wrong bin. Remember that the frame_len was adjusted above.
6548 */
Auke Kok8fc897b2006-08-28 14:56:16 -07006549 if (frame_len == 64) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550 stats->prc64++;
6551 stats->prc127--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006552 } else if (frame_len == 127) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006553 stats->prc127++;
6554 stats->prc255--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006555 } else if (frame_len == 255) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556 stats->prc255++;
6557 stats->prc511--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006558 } else if (frame_len == 511) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559 stats->prc511++;
6560 stats->prc1023--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006561 } else if (frame_len == 1023) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006562 stats->prc1023++;
6563 stats->prc1522--;
Auke Kok8fc897b2006-08-28 14:56:16 -07006564 } else if (frame_len == 1522) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006565 stats->prc1522++;
6566 }
6567}
6568
6569/******************************************************************************
6570 * Gets the current PCI bus type, speed, and width of the hardware
6571 *
6572 * hw - Struct containing variables accessed by shared code
6573 *****************************************************************************/
6574void
6575e1000_get_bus_info(struct e1000_hw *hw)
6576{
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006577 int32_t ret_val;
6578 uint16_t pci_ex_link_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006579 uint32_t status;
6580
6581 switch (hw->mac_type) {
6582 case e1000_82542_rev2_0:
6583 case e1000_82542_rev2_1:
Jeff Kirsherc3813ae2006-12-15 10:37:32 +01006584 hw->bus_type = e1000_bus_type_pci;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006585 hw->bus_speed = e1000_bus_speed_unknown;
6586 hw->bus_width = e1000_bus_width_unknown;
6587 break;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006588 case e1000_82571:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006589 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006590 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006591 case e1000_80003es2lan:
Jeff Kirsherfd803242005-12-13 00:06:22 -05006592 hw->bus_type = e1000_bus_type_pci_express;
6593 hw->bus_speed = e1000_bus_speed_2500;
Jeff Kirshercaeccb62006-09-27 12:53:57 -07006594 ret_val = e1000_read_pcie_cap_reg(hw,
6595 PCI_EX_LINK_STATUS,
6596 &pci_ex_link_status);
6597 if (ret_val)
6598 hw->bus_width = e1000_bus_width_unknown;
6599 else
6600 hw->bus_width = (pci_ex_link_status & PCI_EX_LINK_WIDTH_MASK) >>
6601 PCI_EX_LINK_WIDTH_SHIFT;
6602 break;
6603 case e1000_ich8lan:
6604 hw->bus_type = e1000_bus_type_pci_express;
6605 hw->bus_speed = e1000_bus_speed_2500;
6606 hw->bus_width = e1000_bus_width_pciex_1;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006607 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006608 default:
6609 status = E1000_READ_REG(hw, STATUS);
6610 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
6611 e1000_bus_type_pcix : e1000_bus_type_pci;
6612
Auke Kok8fc897b2006-08-28 14:56:16 -07006613 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006614 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
6615 e1000_bus_speed_66 : e1000_bus_speed_120;
Auke Kok8fc897b2006-08-28 14:56:16 -07006616 } else if (hw->bus_type == e1000_bus_type_pci) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
6618 e1000_bus_speed_66 : e1000_bus_speed_33;
6619 } else {
6620 switch (status & E1000_STATUS_PCIX_SPEED) {
6621 case E1000_STATUS_PCIX_SPEED_66:
6622 hw->bus_speed = e1000_bus_speed_66;
6623 break;
6624 case E1000_STATUS_PCIX_SPEED_100:
6625 hw->bus_speed = e1000_bus_speed_100;
6626 break;
6627 case E1000_STATUS_PCIX_SPEED_133:
6628 hw->bus_speed = e1000_bus_speed_133;
6629 break;
6630 default:
6631 hw->bus_speed = e1000_bus_speed_reserved;
6632 break;
6633 }
6634 }
6635 hw->bus_width = (status & E1000_STATUS_BUS64) ?
6636 e1000_bus_width_64 : e1000_bus_width_32;
6637 break;
6638 }
6639}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640
6641/******************************************************************************
6642 * Writes a value to one of the devices registers using port I/O (as opposed to
6643 * memory mapped I/O). Only 82544 and newer devices support port I/O.
6644 *
6645 * hw - Struct containing variables accessed by shared code
6646 * offset - offset to write to
6647 * value - value to write
6648 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006649static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650e1000_write_reg_io(struct e1000_hw *hw,
6651 uint32_t offset,
6652 uint32_t value)
6653{
6654 unsigned long io_addr = hw->io_base;
6655 unsigned long io_data = hw->io_base + 4;
6656
6657 e1000_io_write(hw, io_addr, offset);
6658 e1000_io_write(hw, io_data, value);
6659}
6660
Linus Torvalds1da177e2005-04-16 15:20:36 -07006661/******************************************************************************
6662 * Estimates the cable length.
6663 *
6664 * hw - Struct containing variables accessed by shared code
6665 * min_length - The estimated minimum length
6666 * max_length - The estimated maximum length
6667 *
6668 * returns: - E1000_ERR_XXX
6669 * E1000_SUCCESS
6670 *
6671 * This function always returns a ranged length (minimum & maximum).
6672 * So for M88 phy's, this function interprets the one value returned from the
6673 * register to the minimum and maximum range.
6674 * For IGP phy's, the function calculates the range by the AGC registers.
6675 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006676static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006677e1000_get_cable_length(struct e1000_hw *hw,
6678 uint16_t *min_length,
6679 uint16_t *max_length)
6680{
6681 int32_t ret_val;
6682 uint16_t agc_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006683 uint16_t i, phy_data;
6684 uint16_t cable_length;
6685
6686 DEBUGFUNC("e1000_get_cable_length");
6687
6688 *min_length = *max_length = 0;
6689
6690 /* Use old method for Phy older than IGP */
Auke Kok8fc897b2006-08-28 14:56:16 -07006691 if (hw->phy_type == e1000_phy_m88) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006692
Linus Torvalds1da177e2005-04-16 15:20:36 -07006693 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6694 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006695 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006696 return ret_val;
6697 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
6698 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
6699
6700 /* Convert the enum value to ranged values */
6701 switch (cable_length) {
6702 case e1000_cable_length_50:
6703 *min_length = 0;
6704 *max_length = e1000_igp_cable_length_50;
6705 break;
6706 case e1000_cable_length_50_80:
6707 *min_length = e1000_igp_cable_length_50;
6708 *max_length = e1000_igp_cable_length_80;
6709 break;
6710 case e1000_cable_length_80_110:
6711 *min_length = e1000_igp_cable_length_80;
6712 *max_length = e1000_igp_cable_length_110;
6713 break;
6714 case e1000_cable_length_110_140:
6715 *min_length = e1000_igp_cable_length_110;
6716 *max_length = e1000_igp_cable_length_140;
6717 break;
6718 case e1000_cable_length_140:
6719 *min_length = e1000_igp_cable_length_140;
6720 *max_length = e1000_igp_cable_length_170;
6721 break;
6722 default:
6723 return -E1000_ERR_PHY;
6724 break;
6725 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006726 } else if (hw->phy_type == e1000_phy_gg82563) {
6727 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
6728 &phy_data);
6729 if (ret_val)
6730 return ret_val;
6731 cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
6732
6733 switch (cable_length) {
6734 case e1000_gg_cable_length_60:
6735 *min_length = 0;
6736 *max_length = e1000_igp_cable_length_60;
6737 break;
6738 case e1000_gg_cable_length_60_115:
6739 *min_length = e1000_igp_cable_length_60;
6740 *max_length = e1000_igp_cable_length_115;
6741 break;
6742 case e1000_gg_cable_length_115_150:
6743 *min_length = e1000_igp_cable_length_115;
6744 *max_length = e1000_igp_cable_length_150;
6745 break;
6746 case e1000_gg_cable_length_150:
6747 *min_length = e1000_igp_cable_length_150;
6748 *max_length = e1000_igp_cable_length_180;
6749 break;
6750 default:
6751 return -E1000_ERR_PHY;
6752 break;
6753 }
Auke Kok8fc897b2006-08-28 14:56:16 -07006754 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
Auke Kokcd94dd02006-06-27 09:08:22 -07006755 uint16_t cur_agc_value;
6756 uint16_t min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6758 {IGP01E1000_PHY_AGC_A,
6759 IGP01E1000_PHY_AGC_B,
6760 IGP01E1000_PHY_AGC_C,
6761 IGP01E1000_PHY_AGC_D};
6762 /* Read the AGC registers for all channels */
Auke Kok8fc897b2006-08-28 14:56:16 -07006763 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006764
6765 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006766 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006767 return ret_val;
6768
Auke Kokcd94dd02006-06-27 09:08:22 -07006769 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006770
Auke Kokcd94dd02006-06-27 09:08:22 -07006771 /* Value bound check. */
6772 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
6773 (cur_agc_value == 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006774 return -E1000_ERR_PHY;
6775
Auke Kokcd94dd02006-06-27 09:08:22 -07006776 agc_value += cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006777
6778 /* Update minimal AGC value. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006779 if (min_agc_value > cur_agc_value)
6780 min_agc_value = cur_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006781 }
6782
6783 /* Remove the minimal AGC result for length < 50m */
Auke Kokcd94dd02006-06-27 09:08:22 -07006784 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
6785 agc_value -= min_agc_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006786
6787 /* Get the average length of the remaining 3 channels */
6788 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
6789 } else {
6790 /* Get the average length of all the 4 channels. */
6791 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
6792 }
6793
6794 /* Set the range of the calculated length. */
6795 *min_length = ((e1000_igp_cable_length_table[agc_value] -
6796 IGP01E1000_AGC_RANGE) > 0) ?
6797 (e1000_igp_cable_length_table[agc_value] -
6798 IGP01E1000_AGC_RANGE) : 0;
6799 *max_length = e1000_igp_cable_length_table[agc_value] +
6800 IGP01E1000_AGC_RANGE;
Auke Kokcd94dd02006-06-27 09:08:22 -07006801 } else if (hw->phy_type == e1000_phy_igp_2 ||
6802 hw->phy_type == e1000_phy_igp_3) {
6803 uint16_t cur_agc_index, max_agc_index = 0;
6804 uint16_t min_agc_index = IGP02E1000_AGC_LENGTH_TABLE_SIZE - 1;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006805 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
6806 {IGP02E1000_PHY_AGC_A,
6807 IGP02E1000_PHY_AGC_B,
6808 IGP02E1000_PHY_AGC_C,
6809 IGP02E1000_PHY_AGC_D};
6810 /* Read the AGC registers for all channels */
6811 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
6812 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
6813 if (ret_val)
6814 return ret_val;
6815
Auke Kok8fc897b2006-08-28 14:56:16 -07006816 /* Getting bits 15:9, which represent the combination of course and
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006817 * fine gain values. The result is a number that can be put into
6818 * the lookup table to obtain the approximate cable length. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006819 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
6820 IGP02E1000_AGC_LENGTH_MASK;
6821
6822 /* Array index bound check. */
6823 if ((cur_agc_index >= IGP02E1000_AGC_LENGTH_TABLE_SIZE) ||
6824 (cur_agc_index == 0))
6825 return -E1000_ERR_PHY;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006826
6827 /* Remove min & max AGC values from calculation. */
Auke Kokcd94dd02006-06-27 09:08:22 -07006828 if (e1000_igp_2_cable_length_table[min_agc_index] >
6829 e1000_igp_2_cable_length_table[cur_agc_index])
6830 min_agc_index = cur_agc_index;
6831 if (e1000_igp_2_cable_length_table[max_agc_index] <
6832 e1000_igp_2_cable_length_table[cur_agc_index])
6833 max_agc_index = cur_agc_index;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006834
Auke Kokcd94dd02006-06-27 09:08:22 -07006835 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006836 }
6837
Auke Kokcd94dd02006-06-27 09:08:22 -07006838 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
6839 e1000_igp_2_cable_length_table[max_agc_index]);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04006840 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
6841
6842 /* Calculate cable length with the error range of +/- 10 meters. */
6843 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
6844 (agc_value - IGP02E1000_AGC_RANGE) : 0;
6845 *max_length = agc_value + IGP02E1000_AGC_RANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006846 }
6847
6848 return E1000_SUCCESS;
6849}
6850
6851/******************************************************************************
6852 * Check the cable polarity
6853 *
6854 * hw - Struct containing variables accessed by shared code
6855 * polarity - output parameter : 0 - Polarity is not reversed
6856 * 1 - Polarity is reversed.
6857 *
6858 * returns: - E1000_ERR_XXX
6859 * E1000_SUCCESS
6860 *
6861 * For phy's older then IGP, this function simply reads the polarity bit in the
6862 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
6863 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
6864 * return 0. If the link speed is 1000 Mbps the polarity status is in the
6865 * IGP01E1000_PHY_PCS_INIT_REG.
6866 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006867static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006868e1000_check_polarity(struct e1000_hw *hw,
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006869 e1000_rev_polarity *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006870{
6871 int32_t ret_val;
6872 uint16_t phy_data;
6873
6874 DEBUGFUNC("e1000_check_polarity");
6875
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006876 if ((hw->phy_type == e1000_phy_m88) ||
6877 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006878 /* return the Polarity bit in the Status register. */
6879 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6880 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006881 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006882 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006883 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
6884 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
6885 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
6886
Auke Kokcd94dd02006-06-27 09:08:22 -07006887 } else if (hw->phy_type == e1000_phy_igp ||
6888 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006889 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006890 /* Read the Status register to check the speed */
6891 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
6892 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006893 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006894 return ret_val;
6895
6896 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
6897 * find the polarity status */
Auke Kok8fc897b2006-08-28 14:56:16 -07006898 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07006899 IGP01E1000_PSSR_SPEED_1000MBPS) {
6900
6901 /* Read the GIG initialization PCS register (0x00B4) */
6902 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
6903 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006904 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006905 return ret_val;
6906
6907 /* Check the polarity bits */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006908 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
6909 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006910 } else {
6911 /* For 10 Mbps, read the polarity bit in the status register. (for
6912 * 100 Mbps this bit is always 0) */
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006913 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
6914 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006915 }
Auke Kokcd94dd02006-06-27 09:08:22 -07006916 } else if (hw->phy_type == e1000_phy_ife) {
6917 ret_val = e1000_read_phy_reg(hw, IFE_PHY_EXTENDED_STATUS_CONTROL,
6918 &phy_data);
6919 if (ret_val)
6920 return ret_val;
Jeff Kirsher70c6f302006-09-27 12:53:31 -07006921 *polarity = ((phy_data & IFE_PESC_POLARITY_REVERSED) >>
6922 IFE_PESC_POLARITY_REVERSED_SHIFT) ?
6923 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006924 }
6925 return E1000_SUCCESS;
6926}
6927
6928/******************************************************************************
6929 * Check if Downshift occured
6930 *
6931 * hw - Struct containing variables accessed by shared code
6932 * downshift - output parameter : 0 - No Downshift ocured.
6933 * 1 - Downshift ocured.
6934 *
6935 * returns: - E1000_ERR_XXX
Auke Kok76c224b2006-05-23 13:36:06 -07006936 * E1000_SUCCESS
Linus Torvalds1da177e2005-04-16 15:20:36 -07006937 *
6938 * For phy's older then IGP, this function reads the Downshift bit in the Phy
6939 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
6940 * Link Health register. In IGP this bit is latched high, so the driver must
6941 * read it immediately after link is established.
6942 *****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006943static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006944e1000_check_downshift(struct e1000_hw *hw)
6945{
6946 int32_t ret_val;
6947 uint16_t phy_data;
6948
6949 DEBUGFUNC("e1000_check_downshift");
6950
Auke Kokcd94dd02006-06-27 09:08:22 -07006951 if (hw->phy_type == e1000_phy_igp ||
6952 hw->phy_type == e1000_phy_igp_3 ||
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006953 hw->phy_type == e1000_phy_igp_2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006954 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
6955 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006956 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006957 return ret_val;
6958
6959 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08006960 } else if ((hw->phy_type == e1000_phy_m88) ||
6961 (hw->phy_type == e1000_phy_gg82563)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006962 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
6963 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07006964 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006965 return ret_val;
6966
6967 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
6968 M88E1000_PSSR_DOWNSHIFT_SHIFT;
Auke Kokcd94dd02006-06-27 09:08:22 -07006969 } else if (hw->phy_type == e1000_phy_ife) {
6970 /* e1000_phy_ife supports 10/100 speed only */
6971 hw->speed_downgraded = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006972 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07006973
Linus Torvalds1da177e2005-04-16 15:20:36 -07006974 return E1000_SUCCESS;
6975}
6976
6977/*****************************************************************************
6978 *
6979 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
6980 * gigabit link is achieved to improve link quality.
6981 *
6982 * hw: Struct containing variables accessed by shared code
6983 *
6984 * returns: - E1000_ERR_PHY if fail to read/write the PHY
6985 * E1000_SUCCESS at any other case.
6986 *
6987 ****************************************************************************/
6988
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01006989static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07006990e1000_config_dsp_after_link_change(struct e1000_hw *hw,
6991 boolean_t link_up)
6992{
6993 int32_t ret_val;
6994 uint16_t phy_data, phy_saved_data, speed, duplex, i;
6995 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
6996 {IGP01E1000_PHY_AGC_PARAM_A,
6997 IGP01E1000_PHY_AGC_PARAM_B,
6998 IGP01E1000_PHY_AGC_PARAM_C,
6999 IGP01E1000_PHY_AGC_PARAM_D};
7000 uint16_t min_length, max_length;
7001
7002 DEBUGFUNC("e1000_config_dsp_after_link_change");
7003
Auke Kok8fc897b2006-08-28 14:56:16 -07007004 if (hw->phy_type != e1000_phy_igp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007005 return E1000_SUCCESS;
7006
Auke Kok8fc897b2006-08-28 14:56:16 -07007007 if (link_up) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007008 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
Auke Kok8fc897b2006-08-28 14:56:16 -07007009 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007010 DEBUGOUT("Error getting link speed and duplex\n");
7011 return ret_val;
7012 }
7013
Auke Kok8fc897b2006-08-28 14:56:16 -07007014 if (speed == SPEED_1000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007015
Auke Kokcd94dd02006-06-27 09:08:22 -07007016 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
7017 if (ret_val)
7018 return ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007019
Auke Kok8fc897b2006-08-28 14:56:16 -07007020 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007021 min_length >= e1000_igp_cable_length_50) {
7022
Auke Kok8fc897b2006-08-28 14:56:16 -07007023 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007024 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
7025 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007026 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007027 return ret_val;
7028
7029 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7030
7031 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
7032 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007033 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007034 return ret_val;
7035 }
7036 hw->dsp_config_state = e1000_dsp_config_activated;
7037 }
7038
Auke Kok8fc897b2006-08-28 14:56:16 -07007039 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07007040 (min_length < e1000_igp_cable_length_50)) {
7041
7042 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
7043 uint32_t idle_errs = 0;
7044
7045 /* clear previous idle error counts */
7046 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7047 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007048 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007049 return ret_val;
7050
Auke Kok8fc897b2006-08-28 14:56:16 -07007051 for (i = 0; i < ffe_idle_err_timeout; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007052 udelay(1000);
7053 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
7054 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007055 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007056 return ret_val;
7057
7058 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007059 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007060 hw->ffe_config_state = e1000_ffe_config_active;
7061
7062 ret_val = e1000_write_phy_reg(hw,
7063 IGP01E1000_PHY_DSP_FFE,
7064 IGP01E1000_PHY_DSP_FFE_CM_CP);
Auke Kok8fc897b2006-08-28 14:56:16 -07007065 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007066 return ret_val;
7067 break;
7068 }
7069
Auke Kok8fc897b2006-08-28 14:56:16 -07007070 if (idle_errs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007071 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
7072 }
7073 }
7074 }
7075 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -07007076 if (hw->dsp_config_state == e1000_dsp_config_activated) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007077 /* Save off the current value of register 0x2F5B to be restored at
7078 * the end of the routines. */
7079 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7080
Auke Kok8fc897b2006-08-28 14:56:16 -07007081 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007082 return ret_val;
7083
7084 /* Disable the PHY transmitter */
7085 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7086
Auke Kok8fc897b2006-08-28 14:56:16 -07007087 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007088 return ret_val;
7089
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007090 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007091
7092 ret_val = e1000_write_phy_reg(hw, 0x0000,
7093 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007094 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007095 return ret_val;
Auke Kok8fc897b2006-08-28 14:56:16 -07007096 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007097 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007098 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007099 return ret_val;
7100
7101 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
7102 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
7103
7104 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007105 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007106 return ret_val;
7107 }
7108
7109 ret_val = e1000_write_phy_reg(hw, 0x0000,
7110 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007111 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007112 return ret_val;
7113
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007114 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007115
7116 /* Now enable the transmitter */
7117 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7118
Auke Kok8fc897b2006-08-28 14:56:16 -07007119 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007120 return ret_val;
7121
7122 hw->dsp_config_state = e1000_dsp_config_enabled;
7123 }
7124
Auke Kok8fc897b2006-08-28 14:56:16 -07007125 if (hw->ffe_config_state == e1000_ffe_config_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007126 /* Save off the current value of register 0x2F5B to be restored at
7127 * the end of the routines. */
7128 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
7129
Auke Kok8fc897b2006-08-28 14:56:16 -07007130 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007131 return ret_val;
7132
7133 /* Disable the PHY transmitter */
7134 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
7135
Auke Kok8fc897b2006-08-28 14:56:16 -07007136 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007137 return ret_val;
7138
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007139 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007140
7141 ret_val = e1000_write_phy_reg(hw, 0x0000,
7142 IGP01E1000_IEEE_FORCE_GIGA);
Auke Kok8fc897b2006-08-28 14:56:16 -07007143 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007144 return ret_val;
7145 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
7146 IGP01E1000_PHY_DSP_FFE_DEFAULT);
Auke Kok8fc897b2006-08-28 14:56:16 -07007147 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007148 return ret_val;
7149
7150 ret_val = e1000_write_phy_reg(hw, 0x0000,
7151 IGP01E1000_IEEE_RESTART_AUTONEG);
Auke Kok8fc897b2006-08-28 14:56:16 -07007152 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007153 return ret_val;
7154
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007155 mdelay(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007156
7157 /* Now enable the transmitter */
7158 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
7159
Auke Kok8fc897b2006-08-28 14:56:16 -07007160 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007161 return ret_val;
7162
7163 hw->ffe_config_state = e1000_ffe_config_enabled;
7164 }
7165 }
7166 return E1000_SUCCESS;
7167}
7168
7169/*****************************************************************************
7170 * Set PHY to class A mode
7171 * Assumes the following operations will follow to enable the new class mode.
7172 * 1. Do a PHY soft reset
7173 * 2. Restart auto-negotiation or force link.
7174 *
7175 * hw - Struct containing variables accessed by shared code
7176 ****************************************************************************/
7177static int32_t
7178e1000_set_phy_mode(struct e1000_hw *hw)
7179{
7180 int32_t ret_val;
7181 uint16_t eeprom_data;
7182
7183 DEBUGFUNC("e1000_set_phy_mode");
7184
Auke Kok8fc897b2006-08-28 14:56:16 -07007185 if ((hw->mac_type == e1000_82545_rev_3) &&
7186 (hw->media_type == e1000_media_type_copper)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007187 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007188 if (ret_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007189 return ret_val;
7190 }
7191
Auke Kok8fc897b2006-08-28 14:56:16 -07007192 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
7193 (eeprom_data & EEPROM_PHY_CLASS_A)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007194 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
Auke Kok8fc897b2006-08-28 14:56:16 -07007195 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007196 return ret_val;
7197 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
Auke Kok8fc897b2006-08-28 14:56:16 -07007198 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007199 return ret_val;
7200
7201 hw->phy_reset_disable = FALSE;
7202 }
7203 }
7204
7205 return E1000_SUCCESS;
7206}
7207
7208/*****************************************************************************
7209 *
7210 * This function sets the lplu state according to the active flag. When
7211 * activating lplu this function also disables smart speed and vise versa.
7212 * lplu will not be activated unless the device autonegotiation advertisment
7213 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7214 * hw: Struct containing variables accessed by shared code
7215 * active - true to enable lplu false to disable lplu.
7216 *
7217 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7218 * E1000_SUCCESS at any other case.
7219 *
7220 ****************************************************************************/
7221
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007222static int32_t
Linus Torvalds1da177e2005-04-16 15:20:36 -07007223e1000_set_d3_lplu_state(struct e1000_hw *hw,
7224 boolean_t active)
7225{
Auke Kokcd94dd02006-06-27 09:08:22 -07007226 uint32_t phy_ctrl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007227 int32_t ret_val;
7228 uint16_t phy_data;
7229 DEBUGFUNC("e1000_set_d3_lplu_state");
7230
Auke Kokcd94dd02006-06-27 09:08:22 -07007231 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
7232 && hw->phy_type != e1000_phy_igp_3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007233 return E1000_SUCCESS;
7234
7235 /* During driver activity LPLU should not be used or it will attain link
7236 * from the lowest speeds starting from 10Mbps. The capability is used for
7237 * Dx transitions and states */
Auke Kokcd94dd02006-06-27 09:08:22 -07007238 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007239 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
Auke Kokcd94dd02006-06-27 09:08:22 -07007240 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007241 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007242 } else if (hw->mac_type == e1000_ich8lan) {
7243 /* MAC writes into PHY register based on the state transition
7244 * and start auto-negotiation. SW driver can overwrite the settings
7245 * in CSR PHY power control E1000_PHY_CTRL register. */
7246 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007247 } else {
7248 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007249 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007250 return ret_val;
7251 }
7252
Auke Kok8fc897b2006-08-28 14:56:16 -07007253 if (!active) {
7254 if (hw->mac_type == e1000_82541_rev_2 ||
7255 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007256 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
7257 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007258 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007259 return ret_val;
7260 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007261 if (hw->mac_type == e1000_ich8lan) {
7262 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
7263 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7264 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007265 phy_data &= ~IGP02E1000_PM_D3_LPLU;
7266 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7267 phy_data);
7268 if (ret_val)
7269 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007270 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007271 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007272
7273 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7274 * Dx states where the power conservation is most important. During
7275 * driver activity we should enable SmartSpeed, so performance is
7276 * maintained. */
7277 if (hw->smart_speed == e1000_smart_speed_on) {
7278 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7279 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007280 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007281 return ret_val;
7282
7283 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7284 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7285 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007286 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007287 return ret_val;
7288 } else if (hw->smart_speed == e1000_smart_speed_off) {
7289 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7290 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007291 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007292 return ret_val;
7293
7294 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7295 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7296 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007297 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007298 return ret_val;
7299 }
7300
Auke Kok8fc897b2006-08-28 14:56:16 -07007301 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
7302 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
7303 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007304
Auke Kok8fc897b2006-08-28 14:56:16 -07007305 if (hw->mac_type == e1000_82541_rev_2 ||
Auke Kokcd94dd02006-06-27 09:08:22 -07007306 hw->mac_type == e1000_82547_rev_2) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007307 phy_data |= IGP01E1000_GMII_FLEX_SPD;
7308 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007309 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007310 return ret_val;
7311 } else {
Auke Kokcd94dd02006-06-27 09:08:22 -07007312 if (hw->mac_type == e1000_ich8lan) {
7313 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
7314 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7315 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007316 phy_data |= IGP02E1000_PM_D3_LPLU;
7317 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
7318 phy_data);
7319 if (ret_val)
7320 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007321 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007322 }
7323
7324 /* When LPLU is enabled we should disable SmartSpeed */
7325 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007326 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007327 return ret_val;
7328
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007329 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7330 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007331 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007332 return ret_val;
7333
7334 }
7335 return E1000_SUCCESS;
7336}
7337
7338/*****************************************************************************
7339 *
7340 * This function sets the lplu d0 state according to the active flag. When
7341 * activating lplu this function also disables smart speed and vise versa.
7342 * lplu will not be activated unless the device autonegotiation advertisment
7343 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
7344 * hw: Struct containing variables accessed by shared code
7345 * active - true to enable lplu false to disable lplu.
7346 *
7347 * returns: - E1000_ERR_PHY if fail to read/write the PHY
7348 * E1000_SUCCESS at any other case.
7349 *
7350 ****************************************************************************/
7351
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007352static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007353e1000_set_d0_lplu_state(struct e1000_hw *hw,
7354 boolean_t active)
7355{
Auke Kokcd94dd02006-06-27 09:08:22 -07007356 uint32_t phy_ctrl = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007357 int32_t ret_val;
7358 uint16_t phy_data;
7359 DEBUGFUNC("e1000_set_d0_lplu_state");
7360
Auke Kok8fc897b2006-08-28 14:56:16 -07007361 if (hw->mac_type <= e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007362 return E1000_SUCCESS;
7363
Auke Kokcd94dd02006-06-27 09:08:22 -07007364 if (hw->mac_type == e1000_ich8lan) {
7365 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
7366 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007367 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007368 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007369 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007370 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007371
7372 if (!active) {
Auke Kokcd94dd02006-06-27 09:08:22 -07007373 if (hw->mac_type == e1000_ich8lan) {
7374 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
7375 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7376 } else {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007377 phy_data &= ~IGP02E1000_PM_D0_LPLU;
7378 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7379 if (ret_val)
7380 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007381 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007382
7383 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
7384 * Dx states where the power conservation is most important. During
7385 * driver activity we should enable SmartSpeed, so performance is
7386 * maintained. */
7387 if (hw->smart_speed == e1000_smart_speed_on) {
7388 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7389 &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007390 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007391 return ret_val;
7392
7393 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
7394 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7395 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007396 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007397 return ret_val;
7398 } else if (hw->smart_speed == e1000_smart_speed_off) {
7399 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7400 &phy_data);
Nicholas Nunley35574762006-09-27 12:53:34 -07007401 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007402 return ret_val;
7403
7404 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7405 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
7406 phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007407 if (ret_val)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007408 return ret_val;
7409 }
7410
7411
7412 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007413
Auke Kokcd94dd02006-06-27 09:08:22 -07007414 if (hw->mac_type == e1000_ich8lan) {
7415 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
7416 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
7417 } else {
Auke Kok76c224b2006-05-23 13:36:06 -07007418 phy_data |= IGP02E1000_PM_D0_LPLU;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007419 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
7420 if (ret_val)
7421 return ret_val;
Auke Kokcd94dd02006-06-27 09:08:22 -07007422 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007423
Linus Torvalds1da177e2005-04-16 15:20:36 -07007424 /* When LPLU is enabled we should disable SmartSpeed */
7425 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007426 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007427 return ret_val;
7428
7429 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
7430 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007431 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007432 return ret_val;
7433
7434 }
7435 return E1000_SUCCESS;
7436}
7437
7438/******************************************************************************
7439 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
7440 *
7441 * hw - Struct containing variables accessed by shared code
7442 *****************************************************************************/
7443static int32_t
7444e1000_set_vco_speed(struct e1000_hw *hw)
7445{
7446 int32_t ret_val;
7447 uint16_t default_page = 0;
7448 uint16_t phy_data;
7449
7450 DEBUGFUNC("e1000_set_vco_speed");
7451
Auke Kok8fc897b2006-08-28 14:56:16 -07007452 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007453 case e1000_82545_rev_3:
7454 case e1000_82546_rev_3:
7455 break;
7456 default:
7457 return E1000_SUCCESS;
7458 }
7459
7460 /* Set PHY register 30, page 5, bit 8 to 0 */
7461
7462 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007463 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007464 return ret_val;
7465
7466 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
Auke Kok8fc897b2006-08-28 14:56:16 -07007467 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007468 return ret_val;
7469
7470 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007471 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007472 return ret_val;
7473
7474 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
7475 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007476 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007477 return ret_val;
7478
7479 /* Set PHY register 30, page 4, bit 11 to 1 */
7480
7481 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
Auke Kok8fc897b2006-08-28 14:56:16 -07007482 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007483 return ret_val;
7484
7485 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007486 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007487 return ret_val;
7488
7489 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
7490 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
Auke Kok8fc897b2006-08-28 14:56:16 -07007491 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007492 return ret_val;
7493
7494 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
Auke Kok8fc897b2006-08-28 14:56:16 -07007495 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007496 return ret_val;
7497
7498 return E1000_SUCCESS;
7499}
7500
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007501
7502/*****************************************************************************
7503 * This function reads the cookie from ARC ram.
7504 *
7505 * returns: - E1000_SUCCESS .
7506 ****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07007507static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007508e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
7509{
7510 uint8_t i;
Auke Kok76c224b2006-05-23 13:36:06 -07007511 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007512 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
7513
7514 length = (length >> 2);
7515 offset = (offset >> 2);
7516
7517 for (i = 0; i < length; i++) {
7518 *((uint32_t *) buffer + i) =
7519 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
7520 }
7521 return E1000_SUCCESS;
7522}
7523
7524
7525/*****************************************************************************
7526 * This function checks whether the HOST IF is enabled for command operaton
7527 * and also checks whether the previous command is completed.
7528 * It busy waits in case of previous command is not completed.
7529 *
Auke Kok76c224b2006-05-23 13:36:06 -07007530 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007531 * timeout
7532 * - E1000_SUCCESS for success.
7533 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007534static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007535e1000_mng_enable_host_if(struct e1000_hw * hw)
7536{
7537 uint32_t hicr;
7538 uint8_t i;
7539
7540 /* Check that the host interface is enabled. */
7541 hicr = E1000_READ_REG(hw, HICR);
7542 if ((hicr & E1000_HICR_EN) == 0) {
7543 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
7544 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7545 }
7546 /* check the previous command is completed */
7547 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
7548 hicr = E1000_READ_REG(hw, HICR);
7549 if (!(hicr & E1000_HICR_C))
7550 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007551 mdelay(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007552 }
7553
Auke Kok76c224b2006-05-23 13:36:06 -07007554 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007555 DEBUGOUT("Previous command timeout failed .\n");
7556 return -E1000_ERR_HOST_INTERFACE_COMMAND;
7557 }
7558 return E1000_SUCCESS;
7559}
7560
7561/*****************************************************************************
7562 * This function writes the buffer content at the offset given on the host if.
7563 * It also does alignment considerations to do the writes in most efficient way.
7564 * Also fills up the sum of the buffer in *buffer parameter.
7565 *
7566 * returns - E1000_SUCCESS for success.
7567 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007568static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007569e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
7570 uint16_t length, uint16_t offset, uint8_t *sum)
7571{
7572 uint8_t *tmp;
7573 uint8_t *bufptr = buffer;
Auke Kok8fc897b2006-08-28 14:56:16 -07007574 uint32_t data = 0;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007575 uint16_t remaining, i, j, prev_bytes;
7576
7577 /* sum = only sum of the data and it is not checksum */
7578
7579 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
7580 return -E1000_ERR_PARAM;
7581 }
7582
7583 tmp = (uint8_t *)&data;
7584 prev_bytes = offset & 0x3;
7585 offset &= 0xFFFC;
7586 offset >>= 2;
7587
7588 if (prev_bytes) {
7589 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
7590 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
7591 *(tmp + j) = *bufptr++;
7592 *sum += *(tmp + j);
7593 }
7594 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
7595 length -= j - prev_bytes;
7596 offset++;
7597 }
7598
7599 remaining = length & 0x3;
7600 length -= remaining;
7601
7602 /* Calculate length in DWORDs */
7603 length >>= 2;
7604
7605 /* The device driver writes the relevant command block into the
7606 * ram area. */
7607 for (i = 0; i < length; i++) {
7608 for (j = 0; j < sizeof(uint32_t); j++) {
7609 *(tmp + j) = *bufptr++;
7610 *sum += *(tmp + j);
7611 }
7612
7613 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7614 }
7615 if (remaining) {
7616 for (j = 0; j < sizeof(uint32_t); j++) {
7617 if (j < remaining)
7618 *(tmp + j) = *bufptr++;
7619 else
7620 *(tmp + j) = 0;
7621
7622 *sum += *(tmp + j);
7623 }
7624 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
7625 }
7626
7627 return E1000_SUCCESS;
7628}
7629
7630
7631/*****************************************************************************
7632 * This function writes the command header after does the checksum calculation.
7633 *
7634 * returns - E1000_SUCCESS for success.
7635 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007636static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007637e1000_mng_write_cmd_header(struct e1000_hw * hw,
7638 struct e1000_host_mng_command_header * hdr)
7639{
7640 uint16_t i;
7641 uint8_t sum;
7642 uint8_t *buffer;
7643
7644 /* Write the whole command header structure which includes sum of
7645 * the buffer */
7646
7647 uint16_t length = sizeof(struct e1000_host_mng_command_header);
7648
7649 sum = hdr->checksum;
7650 hdr->checksum = 0;
7651
7652 buffer = (uint8_t *) hdr;
7653 i = length;
Auke Kok8fc897b2006-08-28 14:56:16 -07007654 while (i--)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007655 sum += buffer[i];
7656
7657 hdr->checksum = 0 - sum;
7658
7659 length >>= 2;
7660 /* The device driver writes the relevant command block into the ram area. */
Auke Kok4ca213a2006-06-27 09:07:08 -07007661 for (i = 0; i < length; i++) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007662 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
Auke Kok4ca213a2006-06-27 09:07:08 -07007663 E1000_WRITE_FLUSH(hw);
7664 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007665
7666 return E1000_SUCCESS;
7667}
7668
7669
7670/*****************************************************************************
7671 * This function indicates to ARC that a new command is pending which completes
7672 * one write operation by the driver.
7673 *
7674 * returns - E1000_SUCCESS for success.
7675 ****************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007676static int32_t
Auke Kok8fc897b2006-08-28 14:56:16 -07007677e1000_mng_write_commit(struct e1000_hw * hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007678{
7679 uint32_t hicr;
7680
7681 hicr = E1000_READ_REG(hw, HICR);
7682 /* Setting this bit tells the ARC that a new command is pending. */
7683 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
7684
7685 return E1000_SUCCESS;
7686}
7687
7688
7689/*****************************************************************************
7690 * This function checks the mode of the firmware.
7691 *
7692 * returns - TRUE when the mode is IAMT or FALSE.
7693 ****************************************************************************/
7694boolean_t
Auke Kokcd94dd02006-06-27 09:08:22 -07007695e1000_check_mng_mode(struct e1000_hw *hw)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007696{
7697 uint32_t fwsm;
7698
7699 fwsm = E1000_READ_REG(hw, FWSM);
7700
Auke Kokcd94dd02006-06-27 09:08:22 -07007701 if (hw->mac_type == e1000_ich8lan) {
7702 if ((fwsm & E1000_FWSM_MODE_MASK) ==
7703 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
7704 return TRUE;
7705 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
7706 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007707 return TRUE;
7708
7709 return FALSE;
7710}
7711
7712
7713/*****************************************************************************
7714 * This function writes the dhcp info .
7715 ****************************************************************************/
7716int32_t
7717e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
Nicholas Nunley35574762006-09-27 12:53:34 -07007718 uint16_t length)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007719{
7720 int32_t ret_val;
7721 struct e1000_host_mng_command_header hdr;
7722
7723 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
7724 hdr.command_length = length;
7725 hdr.reserved1 = 0;
7726 hdr.reserved2 = 0;
7727 hdr.checksum = 0;
7728
7729 ret_val = e1000_mng_enable_host_if(hw);
7730 if (ret_val == E1000_SUCCESS) {
7731 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
7732 &(hdr.checksum));
7733 if (ret_val == E1000_SUCCESS) {
7734 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
7735 if (ret_val == E1000_SUCCESS)
7736 ret_val = e1000_mng_write_commit(hw);
7737 }
7738 }
7739 return ret_val;
7740}
7741
7742
7743/*****************************************************************************
7744 * This function calculates the checksum.
7745 *
7746 * returns - checksum of buffer contents.
7747 ****************************************************************************/
Nicholas Nunley35574762006-09-27 12:53:34 -07007748static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007749e1000_calculate_mng_checksum(char *buffer, uint32_t length)
7750{
7751 uint8_t sum = 0;
7752 uint32_t i;
7753
7754 if (!buffer)
7755 return 0;
7756
7757 for (i=0; i < length; i++)
7758 sum += buffer[i];
7759
7760 return (uint8_t) (0 - sum);
7761}
7762
7763/*****************************************************************************
7764 * This function checks whether tx pkt filtering needs to be enabled or not.
7765 *
7766 * returns - TRUE for packet filtering or FALSE.
7767 ****************************************************************************/
7768boolean_t
7769e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
7770{
7771 /* called in init as well as watchdog timer functions */
7772
7773 int32_t ret_val, checksum;
7774 boolean_t tx_filter = FALSE;
7775 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
7776 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
7777
7778 if (e1000_check_mng_mode(hw)) {
7779 ret_val = e1000_mng_enable_host_if(hw);
7780 if (ret_val == E1000_SUCCESS) {
7781 ret_val = e1000_host_if_read_cookie(hw, buffer);
7782 if (ret_val == E1000_SUCCESS) {
7783 checksum = hdr->checksum;
7784 hdr->checksum = 0;
7785 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
7786 checksum == e1000_calculate_mng_checksum((char *)buffer,
7787 E1000_MNG_DHCP_COOKIE_LENGTH)) {
7788 if (hdr->status &
7789 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
7790 tx_filter = TRUE;
7791 } else
7792 tx_filter = TRUE;
7793 } else
7794 tx_filter = TRUE;
7795 }
7796 }
7797
7798 hw->tx_pkt_filtering = tx_filter;
7799 return tx_filter;
7800}
7801
7802/******************************************************************************
7803 * Verifies the hardware needs to allow ARPs to be processed by the host
7804 *
7805 * hw - Struct containing variables accessed by shared code
7806 *
7807 * returns: - TRUE/FALSE
7808 *
7809 *****************************************************************************/
7810uint32_t
7811e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7812{
7813 uint32_t manc;
7814 uint32_t fwsm, factps;
7815
7816 if (hw->asf_firmware_present) {
7817 manc = E1000_READ_REG(hw, MANC);
7818
7819 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
7820 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
7821 return FALSE;
7822 if (e1000_arc_subsystem_valid(hw) == TRUE) {
7823 fwsm = E1000_READ_REG(hw, FWSM);
7824 factps = E1000_READ_REG(hw, FACTPS);
7825
Jeff Garzik0fccd0e2006-12-15 10:56:10 -05007826 if ((((fwsm & E1000_FWSM_MODE_MASK) >> E1000_FWSM_MODE_SHIFT) ==
7827 e1000_mng_mode_pt) && !(factps & E1000_FACTPS_MNGCG))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007828 return TRUE;
7829 } else
7830 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
7831 return TRUE;
7832 }
7833 return FALSE;
7834}
7835
Linus Torvalds1da177e2005-04-16 15:20:36 -07007836static int32_t
7837e1000_polarity_reversal_workaround(struct e1000_hw *hw)
7838{
7839 int32_t ret_val;
7840 uint16_t mii_status_reg;
7841 uint16_t i;
7842
7843 /* Polarity reversal workaround for forced 10F/10H links. */
7844
7845 /* Disable the transmitter on the PHY */
7846
7847 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007848 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007849 return ret_val;
7850 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
Auke Kok8fc897b2006-08-28 14:56:16 -07007851 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007852 return ret_val;
7853
7854 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007855 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007856 return ret_val;
7857
7858 /* This loop will early-out if the NO link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007859 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007860 /* Read the MII Status Register and wait for Link Status bit
7861 * to be clear.
7862 */
7863
7864 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007865 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007866 return ret_val;
7867
7868 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007869 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007870 return ret_val;
7871
Auke Kok8fc897b2006-08-28 14:56:16 -07007872 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007873 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007874 }
7875
7876 /* Recommended delay time after link has been lost */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007877 mdelay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007878
7879 /* Now we will re-enable th transmitter on the PHY */
7880
7881 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
Auke Kok8fc897b2006-08-28 14:56:16 -07007882 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007883 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007884 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007885 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
Auke Kok8fc897b2006-08-28 14:56:16 -07007886 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007887 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007888 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007889 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
Auke Kok8fc897b2006-08-28 14:56:16 -07007890 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007891 return ret_val;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007892 mdelay(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007893 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007894 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007895 return ret_val;
7896
7897 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
Auke Kok8fc897b2006-08-28 14:56:16 -07007898 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007899 return ret_val;
7900
7901 /* This loop will early-out if the link condition has been met. */
Auke Kok8fc897b2006-08-28 14:56:16 -07007902 for (i = PHY_FORCE_TIME; i > 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007903 /* Read the MII Status Register and wait for Link Status bit
7904 * to be set.
7905 */
7906
7907 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007908 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007909 return ret_val;
7910
7911 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
Auke Kok8fc897b2006-08-28 14:56:16 -07007912 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007913 return ret_val;
7914
Auke Kok8fc897b2006-08-28 14:56:16 -07007915 if (mii_status_reg & MII_SR_LINK_STATUS) break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04007916 mdelay(100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007917 }
7918 return E1000_SUCCESS;
7919}
7920
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007921/***************************************************************************
7922 *
7923 * Disables PCI-Express master access.
7924 *
7925 * hw: Struct containing variables accessed by shared code
7926 *
7927 * returns: - none.
7928 *
7929 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007930static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007931e1000_set_pci_express_master_disable(struct e1000_hw *hw)
7932{
7933 uint32_t ctrl;
7934
7935 DEBUGFUNC("e1000_set_pci_express_master_disable");
7936
7937 if (hw->bus_type != e1000_bus_type_pci_express)
7938 return;
7939
7940 ctrl = E1000_READ_REG(hw, CTRL);
7941 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
7942 E1000_WRITE_REG(hw, CTRL, ctrl);
7943}
7944
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007945/*******************************************************************************
7946 *
7947 * Disables PCI-Express master access and verifies there are no pending requests
7948 *
7949 * hw: Struct containing variables accessed by shared code
7950 *
7951 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
7952 * caused the master requests to be disabled.
7953 * E1000_SUCCESS master requests disabled.
7954 *
7955 ******************************************************************************/
7956int32_t
7957e1000_disable_pciex_master(struct e1000_hw *hw)
7958{
7959 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
7960
7961 DEBUGFUNC("e1000_disable_pciex_master");
7962
7963 if (hw->bus_type != e1000_bus_type_pci_express)
7964 return E1000_SUCCESS;
7965
7966 e1000_set_pci_express_master_disable(hw);
7967
Auke Kok8fc897b2006-08-28 14:56:16 -07007968 while (timeout) {
7969 if (!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007970 break;
7971 else
7972 udelay(100);
7973 timeout--;
7974 }
7975
Auke Kok8fc897b2006-08-28 14:56:16 -07007976 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007977 DEBUGOUT("Master requests are pending.\n");
7978 return -E1000_ERR_MASTER_REQUESTS_PENDING;
7979 }
7980
7981 return E1000_SUCCESS;
7982}
7983
7984/*******************************************************************************
7985 *
7986 * Check for EEPROM Auto Read bit done.
7987 *
7988 * hw: Struct containing variables accessed by shared code
7989 *
7990 * returns: - E1000_ERR_RESET if fail to reset MAC
7991 * E1000_SUCCESS at any other case.
7992 *
7993 ******************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01007994static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07007995e1000_get_auto_rd_done(struct e1000_hw *hw)
7996{
7997 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
7998
7999 DEBUGFUNC("e1000_get_auto_rd_done");
8000
8001 switch (hw->mac_type) {
8002 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008003 msleep(5);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008004 break;
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008005 case e1000_82571:
8006 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008007 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008008 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07008009 case e1000_ich8lan:
8010 while (timeout) {
8011 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD)
8012 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008013 else msleep(1);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008014 timeout--;
8015 }
8016
Auke Kok8fc897b2006-08-28 14:56:16 -07008017 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008018 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
8019 return -E1000_ERR_RESET;
8020 }
8021 break;
8022 }
8023
Jeff Kirsherfd803242005-12-13 00:06:22 -05008024 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
8025 * Need to wait for PHY configuration completion before accessing NVM
8026 * and PHY. */
8027 if (hw->mac_type == e1000_82573)
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008028 msleep(25);
Jeff Kirsherfd803242005-12-13 00:06:22 -05008029
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008030 return E1000_SUCCESS;
8031}
8032
8033/***************************************************************************
8034 * Checks if the PHY configuration is done
8035 *
8036 * hw: Struct containing variables accessed by shared code
8037 *
8038 * returns: - E1000_ERR_RESET if fail to reset MAC
8039 * E1000_SUCCESS at any other case.
8040 *
8041 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008042static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008043e1000_get_phy_cfg_done(struct e1000_hw *hw)
8044{
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008045 int32_t timeout = PHY_CFG_TIMEOUT;
8046 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
8047
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008048 DEBUGFUNC("e1000_get_phy_cfg_done");
8049
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008050 switch (hw->mac_type) {
8051 default:
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008052 mdelay(10);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008053 break;
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008054 case e1000_80003es2lan:
8055 /* Separate *_CFG_DONE_* bit for each port */
8056 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
8057 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
8058 /* Fall Through */
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008059 case e1000_82571:
8060 case e1000_82572:
8061 while (timeout) {
8062 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
8063 break;
8064 else
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008065 msleep(1);
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008066 timeout--;
8067 }
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008068 if (!timeout) {
8069 DEBUGOUT("MNG configuration cycle has not completed.\n");
8070 return -E1000_ERR_RESET;
8071 }
8072 break;
8073 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008074
8075 return E1000_SUCCESS;
8076}
8077
8078/***************************************************************************
8079 *
8080 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
8081 * adapter or Eeprom access.
8082 *
8083 * hw: Struct containing variables accessed by shared code
8084 *
8085 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
8086 * E1000_SUCCESS at any other case.
8087 *
8088 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008089static int32_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008090e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
8091{
8092 int32_t timeout;
8093 uint32_t swsm;
8094
8095 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
8096
Auke Kok8fc897b2006-08-28 14:56:16 -07008097 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008098 return E1000_SUCCESS;
8099
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008100 if (hw->mac_type == e1000_80003es2lan) {
8101 /* Get the SW semaphore. */
8102 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
8103 return -E1000_ERR_EEPROM;
8104 }
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008105
8106 /* Get the FW semaphore. */
8107 timeout = hw->eeprom.word_size + 1;
Auke Kok8fc897b2006-08-28 14:56:16 -07008108 while (timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008109 swsm = E1000_READ_REG(hw, SWSM);
8110 swsm |= E1000_SWSM_SWESMBI;
8111 E1000_WRITE_REG(hw, SWSM, swsm);
8112 /* if we managed to set the bit we got the semaphore. */
8113 swsm = E1000_READ_REG(hw, SWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008114 if (swsm & E1000_SWSM_SWESMBI)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008115 break;
8116
8117 udelay(50);
8118 timeout--;
8119 }
8120
Auke Kok8fc897b2006-08-28 14:56:16 -07008121 if (!timeout) {
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008122 /* Release semaphores */
8123 e1000_put_hw_eeprom_semaphore(hw);
8124 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
8125 return -E1000_ERR_EEPROM;
8126 }
8127
8128 return E1000_SUCCESS;
8129}
8130
8131/***************************************************************************
8132 * This function clears HW semaphore bits.
8133 *
8134 * hw: Struct containing variables accessed by shared code
8135 *
8136 * returns: - None.
8137 *
8138 ***************************************************************************/
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008139static void
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008140e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
8141{
8142 uint32_t swsm;
8143
8144 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
8145
Auke Kok8fc897b2006-08-28 14:56:16 -07008146 if (!hw->eeprom_semaphore_present)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008147 return;
8148
8149 swsm = E1000_READ_REG(hw, SWSM);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008150 if (hw->mac_type == e1000_80003es2lan) {
8151 /* Release both semaphores. */
8152 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
8153 } else
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008154 swsm &= ~(E1000_SWSM_SWESMBI);
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008155 E1000_WRITE_REG(hw, SWSM, swsm);
8156}
8157
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008158/***************************************************************************
8159 *
8160 * Obtaining software semaphore bit (SMBI) before resetting PHY.
8161 *
8162 * hw: Struct containing variables accessed by shared code
8163 *
8164 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
8165 * E1000_SUCCESS at any other case.
8166 *
8167 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008168static int32_t
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008169e1000_get_software_semaphore(struct e1000_hw *hw)
8170{
8171 int32_t timeout = hw->eeprom.word_size + 1;
8172 uint32_t swsm;
8173
8174 DEBUGFUNC("e1000_get_software_semaphore");
8175
Nicholas Nunley35574762006-09-27 12:53:34 -07008176 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008177 return E1000_SUCCESS;
Nicholas Nunley35574762006-09-27 12:53:34 -07008178 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008179
Auke Kok8fc897b2006-08-28 14:56:16 -07008180 while (timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008181 swsm = E1000_READ_REG(hw, SWSM);
8182 /* If SMBI bit cleared, it is now set and we hold the semaphore */
Auke Kok8fc897b2006-08-28 14:56:16 -07008183 if (!(swsm & E1000_SWSM_SMBI))
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008184 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008185 mdelay(1);
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008186 timeout--;
8187 }
8188
Auke Kok8fc897b2006-08-28 14:56:16 -07008189 if (!timeout) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008190 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
8191 return -E1000_ERR_RESET;
8192 }
8193
8194 return E1000_SUCCESS;
8195}
8196
8197/***************************************************************************
8198 *
8199 * Release semaphore bit (SMBI).
8200 *
8201 * hw: Struct containing variables accessed by shared code
8202 *
8203 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008204static void
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008205e1000_release_software_semaphore(struct e1000_hw *hw)
8206{
8207 uint32_t swsm;
8208
8209 DEBUGFUNC("e1000_release_software_semaphore");
8210
Nicholas Nunley35574762006-09-27 12:53:34 -07008211 if (hw->mac_type != e1000_80003es2lan) {
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008212 return;
Nicholas Nunley35574762006-09-27 12:53:34 -07008213 }
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008214
8215 swsm = E1000_READ_REG(hw, SWSM);
8216 /* Release the SW semaphores.*/
8217 swsm &= ~E1000_SWSM_SMBI;
8218 E1000_WRITE_REG(hw, SWSM, swsm);
8219}
8220
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008221/******************************************************************************
8222 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
8223 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
8224 * the caller to figure out how to deal with it.
8225 *
8226 * hw - Struct containing variables accessed by shared code
8227 *
8228 * returns: - E1000_BLK_PHY_RESET
8229 * E1000_SUCCESS
8230 *
8231 *****************************************************************************/
8232int32_t
8233e1000_check_phy_reset_block(struct e1000_hw *hw)
8234{
8235 uint32_t manc = 0;
Auke Kokcd94dd02006-06-27 09:08:22 -07008236 uint32_t fwsm = 0;
8237
8238 if (hw->mac_type == e1000_ich8lan) {
8239 fwsm = E1000_READ_REG(hw, FWSM);
8240 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
8241 : E1000_BLK_PHY_RESET;
8242 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08008243
8244 if (hw->mac_type > e1000_82547_rev_2)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008245 manc = E1000_READ_REG(hw, MANC);
8246 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
Nicholas Nunley35574762006-09-27 12:53:34 -07008247 E1000_BLK_PHY_RESET : E1000_SUCCESS;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008248}
8249
Adrian Bunk3ad2cc62005-10-30 16:53:34 +01008250static uint8_t
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008251e1000_arc_subsystem_valid(struct e1000_hw *hw)
8252{
8253 uint32_t fwsm;
8254
8255 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
8256 * may not be provided a DMA clock when no manageability features are
8257 * enabled. We do not want to perform any reads/writes to these registers
8258 * if this is the case. We read FWSM to determine the manageability mode.
8259 */
8260 switch (hw->mac_type) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04008261 case e1000_82571:
8262 case e1000_82572:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008263 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08008264 case e1000_80003es2lan:
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008265 fwsm = E1000_READ_REG(hw, FWSM);
Auke Kok8fc897b2006-08-28 14:56:16 -07008266 if ((fwsm & E1000_FWSM_MODE_MASK) != 0)
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008267 return TRUE;
8268 break;
Auke Kokcd94dd02006-06-27 09:08:22 -07008269 case e1000_ich8lan:
8270 return TRUE;
Malli Chilakala2d7edb92005-04-28 19:43:52 -07008271 default:
8272 break;
8273 }
8274 return FALSE;
8275}
8276
8277
Auke Kokd37ea5d2006-06-27 09:08:17 -07008278/******************************************************************************
8279 * Configure PCI-Ex no-snoop
8280 *
8281 * hw - Struct containing variables accessed by shared code.
8282 * no_snoop - Bitmap of no-snoop events.
8283 *
8284 * returns: E1000_SUCCESS
8285 *
8286 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008287static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008288e1000_set_pci_ex_no_snoop(struct e1000_hw *hw, uint32_t no_snoop)
8289{
8290 uint32_t gcr_reg = 0;
8291
8292 DEBUGFUNC("e1000_set_pci_ex_no_snoop");
8293
8294 if (hw->bus_type == e1000_bus_type_unknown)
8295 e1000_get_bus_info(hw);
8296
8297 if (hw->bus_type != e1000_bus_type_pci_express)
8298 return E1000_SUCCESS;
8299
8300 if (no_snoop) {
8301 gcr_reg = E1000_READ_REG(hw, GCR);
8302 gcr_reg &= ~(PCI_EX_NO_SNOOP_ALL);
8303 gcr_reg |= no_snoop;
8304 E1000_WRITE_REG(hw, GCR, gcr_reg);
8305 }
8306 if (hw->mac_type == e1000_ich8lan) {
8307 uint32_t ctrl_ext;
8308
8309 E1000_WRITE_REG(hw, GCR, PCI_EX_82566_SNOOP_ALL);
8310
8311 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
8312 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
8313 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
8314 }
8315
8316 return E1000_SUCCESS;
8317}
8318
8319/***************************************************************************
8320 *
8321 * Get software semaphore FLAG bit (SWFLAG).
8322 * SWFLAG is used to synchronize the access to all shared resource between
8323 * SW, FW and HW.
8324 *
8325 * hw: Struct containing variables accessed by shared code
8326 *
8327 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008328static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008329e1000_get_software_flag(struct e1000_hw *hw)
8330{
8331 int32_t timeout = PHY_CFG_TIMEOUT;
8332 uint32_t extcnf_ctrl;
8333
8334 DEBUGFUNC("e1000_get_software_flag");
8335
8336 if (hw->mac_type == e1000_ich8lan) {
8337 while (timeout) {
8338 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8339 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
8340 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8341
8342 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
8343 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
8344 break;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04008345 mdelay(1);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008346 timeout--;
8347 }
8348
8349 if (!timeout) {
8350 DEBUGOUT("FW or HW locks the resource too long.\n");
8351 return -E1000_ERR_CONFIG;
8352 }
8353 }
8354
8355 return E1000_SUCCESS;
8356}
8357
8358/***************************************************************************
8359 *
8360 * Release software semaphore FLAG bit (SWFLAG).
8361 * SWFLAG is used to synchronize the access to all shared resource between
8362 * SW, FW and HW.
8363 *
8364 * hw: Struct containing variables accessed by shared code
8365 *
8366 ***************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008367static void
Auke Kokd37ea5d2006-06-27 09:08:17 -07008368e1000_release_software_flag(struct e1000_hw *hw)
8369{
8370 uint32_t extcnf_ctrl;
8371
8372 DEBUGFUNC("e1000_release_software_flag");
8373
8374 if (hw->mac_type == e1000_ich8lan) {
8375 extcnf_ctrl= E1000_READ_REG(hw, EXTCNF_CTRL);
8376 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
8377 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
8378 }
8379
8380 return;
8381}
8382
Auke Kokd37ea5d2006-06-27 09:08:17 -07008383/******************************************************************************
8384 * Reads a 16 bit word or words from the EEPROM using the ICH8's flash access
8385 * register.
8386 *
8387 * hw - Struct containing variables accessed by shared code
8388 * offset - offset of word in the EEPROM to read
8389 * data - word read from the EEPROM
8390 * words - number of words to read
8391 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008392static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008393e1000_read_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8394 uint16_t *data)
8395{
8396 int32_t error = E1000_SUCCESS;
8397 uint32_t flash_bank = 0;
8398 uint32_t act_offset = 0;
8399 uint32_t bank_offset = 0;
8400 uint16_t word = 0;
8401 uint16_t i = 0;
8402
8403 /* We need to know which is the valid flash bank. In the event
8404 * that we didn't allocate eeprom_shadow_ram, we may not be
8405 * managing flash_bank. So it cannot be trusted and needs
8406 * to be updated with each read.
8407 */
8408 /* Value of bit 22 corresponds to the flash bank we're on. */
8409 flash_bank = (E1000_READ_REG(hw, EECD) & E1000_EECD_SEC1VAL) ? 1 : 0;
8410
8411 /* Adjust offset appropriately if we're on bank 1 - adjust for word size */
8412 bank_offset = flash_bank * (hw->flash_bank_size * 2);
8413
8414 error = e1000_get_software_flag(hw);
8415 if (error != E1000_SUCCESS)
8416 return error;
8417
8418 for (i = 0; i < words; i++) {
8419 if (hw->eeprom_shadow_ram != NULL &&
8420 hw->eeprom_shadow_ram[offset+i].modified == TRUE) {
8421 data[i] = hw->eeprom_shadow_ram[offset+i].eeprom_word;
8422 } else {
8423 /* The NVM part needs a byte offset, hence * 2 */
8424 act_offset = bank_offset + ((offset + i) * 2);
8425 error = e1000_read_ich8_word(hw, act_offset, &word);
8426 if (error != E1000_SUCCESS)
8427 break;
8428 data[i] = word;
8429 }
8430 }
8431
8432 e1000_release_software_flag(hw);
8433
8434 return error;
8435}
8436
8437/******************************************************************************
8438 * Writes a 16 bit word or words to the EEPROM using the ICH8's flash access
8439 * register. Actually, writes are written to the shadow ram cache in the hw
8440 * structure hw->e1000_shadow_ram. e1000_commit_shadow_ram flushes this to
8441 * the NVM, which occurs when the NVM checksum is updated.
8442 *
8443 * hw - Struct containing variables accessed by shared code
8444 * offset - offset of word in the EEPROM to write
8445 * words - number of words to write
8446 * data - words to write to the EEPROM
8447 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008448static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008449e1000_write_eeprom_ich8(struct e1000_hw *hw, uint16_t offset, uint16_t words,
8450 uint16_t *data)
8451{
8452 uint32_t i = 0;
8453 int32_t error = E1000_SUCCESS;
8454
8455 error = e1000_get_software_flag(hw);
8456 if (error != E1000_SUCCESS)
8457 return error;
8458
8459 /* A driver can write to the NVM only if it has eeprom_shadow_ram
8460 * allocated. Subsequent reads to the modified words are read from
8461 * this cached structure as well. Writes will only go into this
8462 * cached structure unless it's followed by a call to
8463 * e1000_update_eeprom_checksum() where it will commit the changes
8464 * and clear the "modified" field.
8465 */
8466 if (hw->eeprom_shadow_ram != NULL) {
8467 for (i = 0; i < words; i++) {
8468 if ((offset + i) < E1000_SHADOW_RAM_WORDS) {
8469 hw->eeprom_shadow_ram[offset+i].modified = TRUE;
8470 hw->eeprom_shadow_ram[offset+i].eeprom_word = data[i];
8471 } else {
8472 error = -E1000_ERR_EEPROM;
8473 break;
8474 }
8475 }
8476 } else {
8477 /* Drivers have the option to not allocate eeprom_shadow_ram as long
8478 * as they don't perform any NVM writes. An attempt in doing so
8479 * will result in this error.
8480 */
8481 error = -E1000_ERR_EEPROM;
8482 }
8483
8484 e1000_release_software_flag(hw);
8485
8486 return error;
8487}
8488
8489/******************************************************************************
8490 * This function does initial flash setup so that a new read/write/erase cycle
8491 * can be started.
8492 *
8493 * hw - The pointer to the hw structure
8494 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008495static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008496e1000_ich8_cycle_init(struct e1000_hw *hw)
8497{
8498 union ich8_hws_flash_status hsfsts;
8499 int32_t error = E1000_ERR_EEPROM;
8500 int32_t i = 0;
8501
8502 DEBUGFUNC("e1000_ich8_cycle_init");
8503
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008504 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008505
8506 /* May be check the Flash Des Valid bit in Hw status */
8507 if (hsfsts.hsf_status.fldesvalid == 0) {
8508 DEBUGOUT("Flash descriptor invalid. SW Sequencing must be used.");
8509 return error;
8510 }
8511
8512 /* Clear FCERR in Hw status by writing 1 */
8513 /* Clear DAEL in Hw status by writing a 1 */
8514 hsfsts.hsf_status.flcerr = 1;
8515 hsfsts.hsf_status.dael = 1;
8516
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008517 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008518
8519 /* Either we should have a hardware SPI cycle in progress bit to check
8520 * against, in order to start a new cycle or FDONE bit should be changed
8521 * in the hardware so that it is 1 after harware reset, which can then be
8522 * used as an indication whether a cycle is in progress or has been
8523 * completed .. we should also have some software semaphore mechanism to
8524 * guard FDONE or the cycle in progress bit so that two threads access to
8525 * those bits can be sequentiallized or a way so that 2 threads dont
8526 * start the cycle at the same time */
8527
8528 if (hsfsts.hsf_status.flcinprog == 0) {
8529 /* There is no cycle running at present, so we can start a cycle */
8530 /* Begin by setting Flash Cycle Done. */
8531 hsfsts.hsf_status.flcdone = 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008532 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008533 error = E1000_SUCCESS;
8534 } else {
8535 /* otherwise poll for sometime so the current cycle has a chance
8536 * to end before giving up. */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008537 for (i = 0; i < ICH_FLASH_COMMAND_TIMEOUT; i++) {
8538 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008539 if (hsfsts.hsf_status.flcinprog == 0) {
8540 error = E1000_SUCCESS;
8541 break;
8542 }
8543 udelay(1);
8544 }
8545 if (error == E1000_SUCCESS) {
8546 /* Successful in waiting for previous cycle to timeout,
8547 * now set the Flash Cycle Done. */
8548 hsfsts.hsf_status.flcdone = 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008549 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008550 } else {
8551 DEBUGOUT("Flash controller busy, cannot get access");
8552 }
8553 }
8554 return error;
8555}
8556
8557/******************************************************************************
8558 * This function starts a flash cycle and waits for its completion
8559 *
8560 * hw - The pointer to the hw structure
8561 ****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008562static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008563e1000_ich8_flash_cycle(struct e1000_hw *hw, uint32_t timeout)
8564{
8565 union ich8_hws_flash_ctrl hsflctl;
8566 union ich8_hws_flash_status hsfsts;
8567 int32_t error = E1000_ERR_EEPROM;
8568 uint32_t i = 0;
8569
8570 /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008571 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008572 hsflctl.hsf_ctrl.flcgo = 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008573 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008574
8575 /* wait till FDONE bit is set to 1 */
8576 do {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008577 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008578 if (hsfsts.hsf_status.flcdone == 1)
8579 break;
8580 udelay(1);
8581 i++;
8582 } while (i < timeout);
8583 if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0) {
8584 error = E1000_SUCCESS;
8585 }
8586 return error;
8587}
8588
8589/******************************************************************************
8590 * Reads a byte or word from the NVM using the ICH8 flash access registers.
8591 *
8592 * hw - The pointer to the hw structure
8593 * index - The index of the byte or word to read.
8594 * size - Size of data to read, 1=byte 2=word
8595 * data - Pointer to the word to store the value read.
8596 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008597static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008598e1000_read_ich8_data(struct e1000_hw *hw, uint32_t index,
8599 uint32_t size, uint16_t* data)
8600{
8601 union ich8_hws_flash_status hsfsts;
8602 union ich8_hws_flash_ctrl hsflctl;
8603 uint32_t flash_linear_address;
8604 uint32_t flash_data = 0;
8605 int32_t error = -E1000_ERR_EEPROM;
8606 int32_t count = 0;
8607
8608 DEBUGFUNC("e1000_read_ich8_data");
8609
Stephen Hemmingerabec42a2007-10-29 10:46:19 -07008610 if (size < 1 || size > 2 || data == NULL ||
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008611 index > ICH_FLASH_LINEAR_ADDR_MASK)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008612 return error;
8613
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008614 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
Auke Kokd37ea5d2006-06-27 09:08:17 -07008615 hw->flash_base_addr;
8616
8617 do {
8618 udelay(1);
8619 /* Steps */
8620 error = e1000_ich8_cycle_init(hw);
8621 if (error != E1000_SUCCESS)
8622 break;
8623
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008624 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008625 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8626 hsflctl.hsf_ctrl.fldbcount = size - 1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008627 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
8628 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008629
8630 /* Write the last 24 bits of index into Flash Linear address field in
8631 * Flash Address */
8632 /* TODO: TBD maybe check the index against the size of flash */
8633
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008634 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008635
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008636 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008637
8638 /* Check if FCERR is set to 1, if set to 1, clear it and try the whole
8639 * sequence a few more times, else read in (shift in) the Flash Data0,
8640 * the order is least significant byte first msb to lsb */
8641 if (error == E1000_SUCCESS) {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008642 flash_data = E1000_READ_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008643 if (size == 1) {
8644 *data = (uint8_t)(flash_data & 0x000000FF);
8645 } else if (size == 2) {
8646 *data = (uint16_t)(flash_data & 0x0000FFFF);
8647 }
8648 break;
8649 } else {
8650 /* If we've gotten here, then things are probably completely hosed,
8651 * but if the error condition is detected, it won't hurt to give
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008652 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008653 */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008654 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008655 if (hsfsts.hsf_status.flcerr == 1) {
8656 /* Repeat for some time before giving up. */
8657 continue;
8658 } else if (hsfsts.hsf_status.flcdone == 0) {
8659 DEBUGOUT("Timeout error - flash cycle did not complete.");
8660 break;
8661 }
8662 }
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008663 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008664
8665 return error;
8666}
8667
8668/******************************************************************************
8669 * Writes One /two bytes to the NVM using the ICH8 flash access registers.
8670 *
8671 * hw - The pointer to the hw structure
8672 * index - The index of the byte/word to read.
8673 * size - Size of data to read, 1=byte 2=word
8674 * data - The byte(s) to write to the NVM.
8675 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008676static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008677e1000_write_ich8_data(struct e1000_hw *hw, uint32_t index, uint32_t size,
8678 uint16_t data)
8679{
8680 union ich8_hws_flash_status hsfsts;
8681 union ich8_hws_flash_ctrl hsflctl;
8682 uint32_t flash_linear_address;
8683 uint32_t flash_data = 0;
8684 int32_t error = -E1000_ERR_EEPROM;
8685 int32_t count = 0;
8686
8687 DEBUGFUNC("e1000_write_ich8_data");
8688
8689 if (size < 1 || size > 2 || data > size * 0xff ||
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008690 index > ICH_FLASH_LINEAR_ADDR_MASK)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008691 return error;
8692
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008693 flash_linear_address = (ICH_FLASH_LINEAR_ADDR_MASK & index) +
Auke Kokd37ea5d2006-06-27 09:08:17 -07008694 hw->flash_base_addr;
8695
8696 do {
8697 udelay(1);
8698 /* Steps */
8699 error = e1000_ich8_cycle_init(hw);
8700 if (error != E1000_SUCCESS)
8701 break;
8702
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008703 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008704 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
8705 hsflctl.hsf_ctrl.fldbcount = size -1;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008706 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
8707 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008708
8709 /* Write the last 24 bits of index into Flash Linear address field in
8710 * Flash Address */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008711 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008712
8713 if (size == 1)
8714 flash_data = (uint32_t)data & 0x00FF;
8715 else
8716 flash_data = (uint32_t)data;
8717
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008718 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008719
8720 /* check if FCERR is set to 1 , if set to 1, clear it and try the whole
8721 * sequence a few more times else done */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008722 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_COMMAND_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008723 if (error == E1000_SUCCESS) {
8724 break;
8725 } else {
8726 /* If we're here, then things are most likely completely hosed,
8727 * but if the error condition is detected, it won't hurt to give
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008728 * it another try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008729 */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008730 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008731 if (hsfsts.hsf_status.flcerr == 1) {
8732 /* Repeat for some time before giving up. */
8733 continue;
8734 } else if (hsfsts.hsf_status.flcdone == 0) {
8735 DEBUGOUT("Timeout error - flash cycle did not complete.");
8736 break;
8737 }
8738 }
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008739 } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008740
8741 return error;
8742}
8743
8744/******************************************************************************
8745 * Reads a single byte from the NVM using the ICH8 flash access registers.
8746 *
8747 * hw - pointer to e1000_hw structure
8748 * index - The index of the byte to read.
8749 * data - Pointer to a byte to store the value read.
8750 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008751static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008752e1000_read_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t* data)
8753{
8754 int32_t status = E1000_SUCCESS;
8755 uint16_t word = 0;
8756
8757 status = e1000_read_ich8_data(hw, index, 1, &word);
8758 if (status == E1000_SUCCESS) {
8759 *data = (uint8_t)word;
8760 }
8761
8762 return status;
8763}
8764
8765/******************************************************************************
8766 * Writes a single byte to the NVM using the ICH8 flash access registers.
8767 * Performs verification by reading back the value and then going through
8768 * a retry algorithm before giving up.
8769 *
8770 * hw - pointer to e1000_hw structure
8771 * index - The index of the byte to write.
8772 * byte - The byte to write to the NVM.
8773 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008774static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008775e1000_verify_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t byte)
8776{
8777 int32_t error = E1000_SUCCESS;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008778 int32_t program_retries = 0;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008779
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008780 DEBUGOUT2("Byte := %2.2X Offset := %d\n", byte, index);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008781
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008782 error = e1000_write_ich8_byte(hw, index, byte);
8783
8784 if (error != E1000_SUCCESS) {
8785 for (program_retries = 0; program_retries < 100; program_retries++) {
8786 DEBUGOUT2("Retrying \t Byte := %2.2X Offset := %d\n", byte, index);
8787 error = e1000_write_ich8_byte(hw, index, byte);
8788 udelay(100);
8789 if (error == E1000_SUCCESS)
8790 break;
8791 }
Auke Kokd37ea5d2006-06-27 09:08:17 -07008792 }
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008793
Auke Kokd37ea5d2006-06-27 09:08:17 -07008794 if (program_retries == 100)
8795 error = E1000_ERR_EEPROM;
8796
8797 return error;
8798}
8799
8800/******************************************************************************
8801 * Writes a single byte to the NVM using the ICH8 flash access registers.
8802 *
8803 * hw - pointer to e1000_hw structure
8804 * index - The index of the byte to read.
8805 * data - The byte to write to the NVM.
8806 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008807static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008808e1000_write_ich8_byte(struct e1000_hw *hw, uint32_t index, uint8_t data)
8809{
8810 int32_t status = E1000_SUCCESS;
8811 uint16_t word = (uint16_t)data;
8812
8813 status = e1000_write_ich8_data(hw, index, 1, word);
8814
8815 return status;
8816}
8817
8818/******************************************************************************
8819 * Reads a word from the NVM using the ICH8 flash access registers.
8820 *
8821 * hw - pointer to e1000_hw structure
8822 * index - The starting byte index of the word to read.
8823 * data - Pointer to a word to store the value read.
8824 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008825static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008826e1000_read_ich8_word(struct e1000_hw *hw, uint32_t index, uint16_t *data)
8827{
8828 int32_t status = E1000_SUCCESS;
8829 status = e1000_read_ich8_data(hw, index, 2, data);
8830 return status;
8831}
8832
8833/******************************************************************************
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008834 * Erases the bank specified. Each bank may be a 4, 8 or 64k block. Banks are 0
8835 * based.
Auke Kokd37ea5d2006-06-27 09:08:17 -07008836 *
8837 * hw - pointer to e1000_hw structure
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008838 * bank - 0 for first bank, 1 for second bank
8839 *
8840 * Note that this function may actually erase as much as 8 or 64 KBytes. The
8841 * amount of NVM used in each bank is a *minimum* of 4 KBytes, but in fact the
8842 * bank size may be 4, 8 or 64 KBytes
Auke Kokd37ea5d2006-06-27 09:08:17 -07008843 *****************************************************************************/
Stephen Hemmingerabec42a2007-10-29 10:46:19 -07008844static int32_t
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008845e1000_erase_ich8_4k_segment(struct e1000_hw *hw, uint32_t bank)
Auke Kokd37ea5d2006-06-27 09:08:17 -07008846{
8847 union ich8_hws_flash_status hsfsts;
8848 union ich8_hws_flash_ctrl hsflctl;
8849 uint32_t flash_linear_address;
8850 int32_t count = 0;
8851 int32_t error = E1000_ERR_EEPROM;
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008852 int32_t iteration;
8853 int32_t sub_sector_size = 0;
8854 int32_t bank_size;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008855 int32_t j = 0;
8856 int32_t error_flag = 0;
8857
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008858 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008859
8860 /* Determine HW Sector size: Read BERASE bits of Hw flash Status register */
8861 /* 00: The Hw sector is 256 bytes, hence we need to erase 16
8862 * consecutive sectors. The start index for the nth Hw sector can be
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008863 * calculated as bank * 4096 + n * 256
Auke Kokd37ea5d2006-06-27 09:08:17 -07008864 * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
8865 * The start index for the nth Hw sector can be calculated
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008866 * as bank * 4096
8867 * 10: The HW sector is 8K bytes
8868 * 11: The Hw sector size is 64K bytes */
Auke Kokd37ea5d2006-06-27 09:08:17 -07008869 if (hsfsts.hsf_status.berasesz == 0x0) {
8870 /* Hw sector size 256 */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008871 sub_sector_size = ICH_FLASH_SEG_SIZE_256;
8872 bank_size = ICH_FLASH_SECTOR_SIZE;
8873 iteration = ICH_FLASH_SECTOR_SIZE / ICH_FLASH_SEG_SIZE_256;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008874 } else if (hsfsts.hsf_status.berasesz == 0x1) {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008875 bank_size = ICH_FLASH_SEG_SIZE_4K;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008876 iteration = 1;
8877 } else if (hsfsts.hsf_status.berasesz == 0x3) {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008878 bank_size = ICH_FLASH_SEG_SIZE_64K;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008879 iteration = 1;
8880 } else {
8881 return error;
8882 }
8883
8884 for (j = 0; j < iteration ; j++) {
8885 do {
8886 count++;
8887 /* Steps */
8888 error = e1000_ich8_cycle_init(hw);
8889 if (error != E1000_SUCCESS) {
8890 error_flag = 1;
8891 break;
8892 }
8893
8894 /* Write a value 11 (block Erase) in Flash Cycle field in Hw flash
8895 * Control */
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008896 hsflctl.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
8897 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
8898 E1000_WRITE_ICH_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008899
8900 /* Write the last 24 bits of an index within the block into Flash
8901 * Linear address field in Flash Address. This probably needs to
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008902 * be calculated here based off the on-chip erase sector size and
8903 * the software bank size (4, 8 or 64 KBytes) */
8904 flash_linear_address = bank * bank_size + j * sub_sector_size;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008905 flash_linear_address += hw->flash_base_addr;
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008906 flash_linear_address &= ICH_FLASH_LINEAR_ADDR_MASK;
Auke Kokd37ea5d2006-06-27 09:08:17 -07008907
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008908 E1000_WRITE_ICH_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_address);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008909
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008910 error = e1000_ich8_flash_cycle(hw, ICH_FLASH_ERASE_TIMEOUT);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008911 /* Check if FCERR is set to 1. If 1, clear it and try the whole
8912 * sequence a few more times else Done */
8913 if (error == E1000_SUCCESS) {
8914 break;
8915 } else {
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008916 hsfsts.regval = E1000_READ_ICH_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008917 if (hsfsts.hsf_status.flcerr == 1) {
8918 /* repeat for some time before giving up */
8919 continue;
8920 } else if (hsfsts.hsf_status.flcdone == 0) {
8921 error_flag = 1;
8922 break;
8923 }
8924 }
Jeff Kirsher2df7d592006-11-01 08:48:02 -08008925 } while ((count < ICH_FLASH_CYCLE_REPEAT_COUNT) && !error_flag);
Auke Kokd37ea5d2006-06-27 09:08:17 -07008926 if (error_flag == 1)
8927 break;
8928 }
8929 if (error_flag != 1)
8930 error = E1000_SUCCESS;
8931 return error;
8932}
8933
Adrian Bunke4c780b2006-08-14 23:00:10 -07008934static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008935e1000_init_lcd_from_nvm_config_region(struct e1000_hw *hw,
8936 uint32_t cnf_base_addr, uint32_t cnf_size)
8937{
8938 uint32_t ret_val = E1000_SUCCESS;
8939 uint16_t word_addr, reg_data, reg_addr;
8940 uint16_t i;
8941
8942 /* cnf_base_addr is in DWORD */
8943 word_addr = (uint16_t)(cnf_base_addr << 1);
8944
8945 /* cnf_size is returned in size of dwords */
8946 for (i = 0; i < cnf_size; i++) {
8947 ret_val = e1000_read_eeprom(hw, (word_addr + i*2), 1, &reg_data);
8948 if (ret_val)
8949 return ret_val;
8950
8951 ret_val = e1000_read_eeprom(hw, (word_addr + i*2 + 1), 1, &reg_addr);
8952 if (ret_val)
8953 return ret_val;
8954
8955 ret_val = e1000_get_software_flag(hw);
8956 if (ret_val != E1000_SUCCESS)
8957 return ret_val;
8958
8959 ret_val = e1000_write_phy_reg_ex(hw, (uint32_t)reg_addr, reg_data);
8960
8961 e1000_release_software_flag(hw);
8962 }
8963
8964 return ret_val;
8965}
8966
8967
Jeff Kirsher2a88c172006-09-27 12:54:05 -07008968/******************************************************************************
8969 * This function initializes the PHY from the NVM on ICH8 platforms. This
8970 * is needed due to an issue where the NVM configuration is not properly
8971 * autoloaded after power transitions. Therefore, after each PHY reset, we
8972 * will load the configuration data out of the NVM manually.
8973 *
8974 * hw: Struct containing variables accessed by shared code
8975 *****************************************************************************/
Adrian Bunke4c780b2006-08-14 23:00:10 -07008976static int32_t
Auke Kokd37ea5d2006-06-27 09:08:17 -07008977e1000_init_lcd_from_nvm(struct e1000_hw *hw)
8978{
8979 uint32_t reg_data, cnf_base_addr, cnf_size, ret_val, loop;
8980
8981 if (hw->phy_type != e1000_phy_igp_3)
8982 return E1000_SUCCESS;
8983
8984 /* Check if SW needs configure the PHY */
8985 reg_data = E1000_READ_REG(hw, FEXTNVM);
8986 if (!(reg_data & FEXTNVM_SW_CONFIG))
8987 return E1000_SUCCESS;
8988
8989 /* Wait for basic configuration completes before proceeding*/
8990 loop = 0;
8991 do {
8992 reg_data = E1000_READ_REG(hw, STATUS) & E1000_STATUS_LAN_INIT_DONE;
8993 udelay(100);
8994 loop++;
8995 } while ((!reg_data) && (loop < 50));
8996
8997 /* Clear the Init Done bit for the next init event */
8998 reg_data = E1000_READ_REG(hw, STATUS);
8999 reg_data &= ~E1000_STATUS_LAN_INIT_DONE;
9000 E1000_WRITE_REG(hw, STATUS, reg_data);
9001
9002 /* Make sure HW does not configure LCD from PHY extended configuration
9003 before SW configuration */
9004 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9005 if ((reg_data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE) == 0x0000) {
9006 reg_data = E1000_READ_REG(hw, EXTCNF_SIZE);
9007 cnf_size = reg_data & E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH;
9008 cnf_size >>= 16;
9009 if (cnf_size) {
9010 reg_data = E1000_READ_REG(hw, EXTCNF_CTRL);
9011 cnf_base_addr = reg_data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER;
9012 /* cnf_base_addr is in DWORD */
9013 cnf_base_addr >>= 16;
9014
9015 /* Configure LCD from extended configuration region. */
9016 ret_val = e1000_init_lcd_from_nvm_config_region(hw, cnf_base_addr,
9017 cnf_size);
9018 if (ret_val)
9019 return ret_val;
9020 }
9021 }
9022
9023 return E1000_SUCCESS;
9024}
9025