initial commit with v2.6.32.60
[linux-2.6.32.60-moxart.git] / drivers / net / e1000 / e1000_hw.c
blob0d82be08ed2890896f88fb275ef8d828e2ab2ba8
1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
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.
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
13 more details.
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
29 /* e1000_hw.c
30 * Shared functions for accessing and configuring the MAC
33 #include "e1000_hw.h"
35 static s32 e1000_check_downshift(struct e1000_hw *hw);
36 static s32 e1000_check_polarity(struct e1000_hw *hw,
37 e1000_rev_polarity *polarity);
38 static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
39 static void e1000_clear_vfta(struct e1000_hw *hw);
40 static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
41 bool link_up);
42 static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw);
43 static s32 e1000_detect_gig_phy(struct e1000_hw *hw);
44 static s32 e1000_get_auto_rd_done(struct e1000_hw *hw);
45 static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
46 u16 *max_length);
47 static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw);
48 static s32 e1000_id_led_init(struct e1000_hw *hw);
49 static void e1000_init_rx_addrs(struct e1000_hw *hw);
50 static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
51 struct e1000_phy_info *phy_info);
52 static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
53 struct e1000_phy_info *phy_info);
54 static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active);
55 static s32 e1000_wait_autoneg(struct e1000_hw *hw);
56 static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value);
57 static s32 e1000_set_phy_type(struct e1000_hw *hw);
58 static void e1000_phy_init_script(struct e1000_hw *hw);
59 static s32 e1000_setup_copper_link(struct e1000_hw *hw);
60 static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
61 static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
62 static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
63 static s32 e1000_config_mac_to_phy(struct e1000_hw *hw);
64 static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
65 static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
66 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count);
67 static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw);
68 static s32 e1000_phy_reset_dsp(struct e1000_hw *hw);
69 static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset,
70 u16 words, u16 *data);
71 static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
72 u16 words, u16 *data);
73 static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw);
74 static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd);
75 static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd);
76 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count);
77 static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
78 u16 phy_data);
79 static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
80 u16 *phy_data);
81 static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count);
82 static s32 e1000_acquire_eeprom(struct e1000_hw *hw);
83 static void e1000_release_eeprom(struct e1000_hw *hw);
84 static void e1000_standby_eeprom(struct e1000_hw *hw);
85 static s32 e1000_set_vco_speed(struct e1000_hw *hw);
86 static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw);
87 static s32 e1000_set_phy_mode(struct e1000_hw *hw);
88 static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
89 u16 *data);
90 static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
91 u16 *data);
93 /* IGP cable length table */
94 static const
95 u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = {
96 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
97 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
98 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
99 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
100 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
101 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100,
102 100,
103 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
104 110, 110,
105 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120,
106 120, 120
109 static DEFINE_SPINLOCK(e1000_eeprom_lock);
112 * e1000_set_phy_type - Set the phy type member in the hw struct.
113 * @hw: Struct containing variables accessed by shared code
115 static s32 e1000_set_phy_type(struct e1000_hw *hw)
117 DEBUGFUNC("e1000_set_phy_type");
119 if (hw->mac_type == e1000_undefined)
120 return -E1000_ERR_PHY_TYPE;
122 switch (hw->phy_id) {
123 case M88E1000_E_PHY_ID:
124 case M88E1000_I_PHY_ID:
125 case M88E1011_I_PHY_ID:
126 case M88E1111_I_PHY_ID:
127 hw->phy_type = e1000_phy_m88;
128 break;
129 case IGP01E1000_I_PHY_ID:
130 if (hw->mac_type == e1000_82541 ||
131 hw->mac_type == e1000_82541_rev_2 ||
132 hw->mac_type == e1000_82547 ||
133 hw->mac_type == e1000_82547_rev_2) {
134 hw->phy_type = e1000_phy_igp;
135 break;
137 default:
138 /* Should never have loaded on this device */
139 hw->phy_type = e1000_phy_undefined;
140 return -E1000_ERR_PHY_TYPE;
143 return E1000_SUCCESS;
147 * e1000_phy_init_script - IGP phy init script - initializes the GbE PHY
148 * @hw: Struct containing variables accessed by shared code
150 static void e1000_phy_init_script(struct e1000_hw *hw)
152 u32 ret_val;
153 u16 phy_saved_data;
155 DEBUGFUNC("e1000_phy_init_script");
157 if (hw->phy_init_script) {
158 msleep(20);
160 /* Save off the current value of register 0x2F5B to be restored at
161 * the end of this routine. */
162 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
164 /* Disabled the PHY transmitter */
165 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
166 msleep(20);
168 e1000_write_phy_reg(hw, 0x0000, 0x0140);
169 msleep(5);
171 switch (hw->mac_type) {
172 case e1000_82541:
173 case e1000_82547:
174 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
175 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
176 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
177 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
178 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
179 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
180 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
181 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
182 e1000_write_phy_reg(hw, 0x2010, 0x0008);
183 break;
185 case e1000_82541_rev_2:
186 case e1000_82547_rev_2:
187 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
188 break;
189 default:
190 break;
193 e1000_write_phy_reg(hw, 0x0000, 0x3300);
194 msleep(20);
196 /* Now enable the transmitter */
197 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
199 if (hw->mac_type == e1000_82547) {
200 u16 fused, fine, coarse;
202 /* Move to analog registers page */
203 e1000_read_phy_reg(hw,
204 IGP01E1000_ANALOG_SPARE_FUSE_STATUS,
205 &fused);
207 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
208 e1000_read_phy_reg(hw,
209 IGP01E1000_ANALOG_FUSE_STATUS,
210 &fused);
212 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
213 coarse =
214 fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
216 if (coarse >
217 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
218 coarse -=
219 IGP01E1000_ANALOG_FUSE_COARSE_10;
220 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
221 } else if (coarse ==
222 IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
223 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
225 fused =
226 (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
227 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
228 (coarse &
229 IGP01E1000_ANALOG_FUSE_COARSE_MASK);
231 e1000_write_phy_reg(hw,
232 IGP01E1000_ANALOG_FUSE_CONTROL,
233 fused);
234 e1000_write_phy_reg(hw,
235 IGP01E1000_ANALOG_FUSE_BYPASS,
236 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
243 * e1000_set_mac_type - Set the mac type member in the hw struct.
244 * @hw: Struct containing variables accessed by shared code
246 s32 e1000_set_mac_type(struct e1000_hw *hw)
248 DEBUGFUNC("e1000_set_mac_type");
250 switch (hw->device_id) {
251 case E1000_DEV_ID_82542:
252 switch (hw->revision_id) {
253 case E1000_82542_2_0_REV_ID:
254 hw->mac_type = e1000_82542_rev2_0;
255 break;
256 case E1000_82542_2_1_REV_ID:
257 hw->mac_type = e1000_82542_rev2_1;
258 break;
259 default:
260 /* Invalid 82542 revision ID */
261 return -E1000_ERR_MAC_TYPE;
263 break;
264 case E1000_DEV_ID_82543GC_FIBER:
265 case E1000_DEV_ID_82543GC_COPPER:
266 hw->mac_type = e1000_82543;
267 break;
268 case E1000_DEV_ID_82544EI_COPPER:
269 case E1000_DEV_ID_82544EI_FIBER:
270 case E1000_DEV_ID_82544GC_COPPER:
271 case E1000_DEV_ID_82544GC_LOM:
272 hw->mac_type = e1000_82544;
273 break;
274 case E1000_DEV_ID_82540EM:
275 case E1000_DEV_ID_82540EM_LOM:
276 case E1000_DEV_ID_82540EP:
277 case E1000_DEV_ID_82540EP_LOM:
278 case E1000_DEV_ID_82540EP_LP:
279 hw->mac_type = e1000_82540;
280 break;
281 case E1000_DEV_ID_82545EM_COPPER:
282 case E1000_DEV_ID_82545EM_FIBER:
283 hw->mac_type = e1000_82545;
284 break;
285 case E1000_DEV_ID_82545GM_COPPER:
286 case E1000_DEV_ID_82545GM_FIBER:
287 case E1000_DEV_ID_82545GM_SERDES:
288 hw->mac_type = e1000_82545_rev_3;
289 break;
290 case E1000_DEV_ID_82546EB_COPPER:
291 case E1000_DEV_ID_82546EB_FIBER:
292 case E1000_DEV_ID_82546EB_QUAD_COPPER:
293 hw->mac_type = e1000_82546;
294 break;
295 case E1000_DEV_ID_82546GB_COPPER:
296 case E1000_DEV_ID_82546GB_FIBER:
297 case E1000_DEV_ID_82546GB_SERDES:
298 case E1000_DEV_ID_82546GB_PCIE:
299 case E1000_DEV_ID_82546GB_QUAD_COPPER:
300 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
301 hw->mac_type = e1000_82546_rev_3;
302 break;
303 case E1000_DEV_ID_82541EI:
304 case E1000_DEV_ID_82541EI_MOBILE:
305 case E1000_DEV_ID_82541ER_LOM:
306 hw->mac_type = e1000_82541;
307 break;
308 case E1000_DEV_ID_82541ER:
309 case E1000_DEV_ID_82541GI:
310 case E1000_DEV_ID_82541GI_LF:
311 case E1000_DEV_ID_82541GI_MOBILE:
312 hw->mac_type = e1000_82541_rev_2;
313 break;
314 case E1000_DEV_ID_82547EI:
315 case E1000_DEV_ID_82547EI_MOBILE:
316 hw->mac_type = e1000_82547;
317 break;
318 case E1000_DEV_ID_82547GI:
319 hw->mac_type = e1000_82547_rev_2;
320 break;
321 default:
322 /* Should never have loaded on this device */
323 return -E1000_ERR_MAC_TYPE;
326 switch (hw->mac_type) {
327 case e1000_82541:
328 case e1000_82547:
329 case e1000_82541_rev_2:
330 case e1000_82547_rev_2:
331 hw->asf_firmware_present = true;
332 break;
333 default:
334 break;
337 /* The 82543 chip does not count tx_carrier_errors properly in
338 * FD mode
340 if (hw->mac_type == e1000_82543)
341 hw->bad_tx_carr_stats_fd = true;
343 if (hw->mac_type > e1000_82544)
344 hw->has_smbus = true;
346 return E1000_SUCCESS;
350 * e1000_set_media_type - Set media type and TBI compatibility.
351 * @hw: Struct containing variables accessed by shared code
353 void e1000_set_media_type(struct e1000_hw *hw)
355 u32 status;
357 DEBUGFUNC("e1000_set_media_type");
359 if (hw->mac_type != e1000_82543) {
360 /* tbi_compatibility is only valid on 82543 */
361 hw->tbi_compatibility_en = false;
364 switch (hw->device_id) {
365 case E1000_DEV_ID_82545GM_SERDES:
366 case E1000_DEV_ID_82546GB_SERDES:
367 hw->media_type = e1000_media_type_internal_serdes;
368 break;
369 default:
370 switch (hw->mac_type) {
371 case e1000_82542_rev2_0:
372 case e1000_82542_rev2_1:
373 hw->media_type = e1000_media_type_fiber;
374 break;
375 default:
376 status = er32(STATUS);
377 if (status & E1000_STATUS_TBIMODE) {
378 hw->media_type = e1000_media_type_fiber;
379 /* tbi_compatibility not valid on fiber */
380 hw->tbi_compatibility_en = false;
381 } else {
382 hw->media_type = e1000_media_type_copper;
384 break;
390 * e1000_reset_hw: reset the hardware completely
391 * @hw: Struct containing variables accessed by shared code
393 * Reset the transmit and receive units; mask and clear all interrupts.
395 s32 e1000_reset_hw(struct e1000_hw *hw)
397 u32 ctrl;
398 u32 ctrl_ext;
399 u32 icr;
400 u32 manc;
401 u32 led_ctrl;
402 s32 ret_val;
404 DEBUGFUNC("e1000_reset_hw");
406 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
407 if (hw->mac_type == e1000_82542_rev2_0) {
408 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
409 e1000_pci_clear_mwi(hw);
412 /* Clear interrupt mask to stop board from generating interrupts */
413 DEBUGOUT("Masking off all interrupts\n");
414 ew32(IMC, 0xffffffff);
416 /* Disable the Transmit and Receive units. Then delay to allow
417 * any pending transactions to complete before we hit the MAC with
418 * the global reset.
420 ew32(RCTL, 0);
421 ew32(TCTL, E1000_TCTL_PSP);
422 E1000_WRITE_FLUSH();
424 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
425 hw->tbi_compatibility_on = false;
427 /* Delay to allow any outstanding PCI transactions to complete before
428 * resetting the device
430 msleep(10);
432 ctrl = er32(CTRL);
434 /* Must reset the PHY before resetting the MAC */
435 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
436 ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST));
437 msleep(5);
440 /* Issue a global reset to the MAC. This will reset the chip's
441 * transmit, receive, DMA, and link units. It will not effect
442 * the current PCI configuration. The global reset bit is self-
443 * clearing, and should clear within a microsecond.
445 DEBUGOUT("Issuing a global reset to MAC\n");
447 switch (hw->mac_type) {
448 case e1000_82544:
449 case e1000_82540:
450 case e1000_82545:
451 case e1000_82546:
452 case e1000_82541:
453 case e1000_82541_rev_2:
454 /* These controllers can't ack the 64-bit write when issuing the
455 * reset, so use IO-mapping as a workaround to issue the reset */
456 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
457 break;
458 case e1000_82545_rev_3:
459 case e1000_82546_rev_3:
460 /* Reset is performed on a shadow of the control register */
461 ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST));
462 break;
463 default:
464 ew32(CTRL, (ctrl | E1000_CTRL_RST));
465 break;
468 /* After MAC reset, force reload of EEPROM to restore power-on settings to
469 * device. Later controllers reload the EEPROM automatically, so just wait
470 * for reload to complete.
472 switch (hw->mac_type) {
473 case e1000_82542_rev2_0:
474 case e1000_82542_rev2_1:
475 case e1000_82543:
476 case e1000_82544:
477 /* Wait for reset to complete */
478 udelay(10);
479 ctrl_ext = er32(CTRL_EXT);
480 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
481 ew32(CTRL_EXT, ctrl_ext);
482 E1000_WRITE_FLUSH();
483 /* Wait for EEPROM reload */
484 msleep(2);
485 break;
486 case e1000_82541:
487 case e1000_82541_rev_2:
488 case e1000_82547:
489 case e1000_82547_rev_2:
490 /* Wait for EEPROM reload */
491 msleep(20);
492 break;
493 default:
494 /* Auto read done will delay 5ms or poll based on mac type */
495 ret_val = e1000_get_auto_rd_done(hw);
496 if (ret_val)
497 return ret_val;
498 break;
501 /* Disable HW ARPs on ASF enabled adapters */
502 if (hw->mac_type >= e1000_82540) {
503 manc = er32(MANC);
504 manc &= ~(E1000_MANC_ARP_EN);
505 ew32(MANC, manc);
508 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
509 e1000_phy_init_script(hw);
511 /* Configure activity LED after PHY reset */
512 led_ctrl = er32(LEDCTL);
513 led_ctrl &= IGP_ACTIVITY_LED_MASK;
514 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
515 ew32(LEDCTL, led_ctrl);
518 /* Clear interrupt mask to stop board from generating interrupts */
519 DEBUGOUT("Masking off all interrupts\n");
520 ew32(IMC, 0xffffffff);
522 /* Clear any pending interrupt events. */
523 icr = er32(ICR);
525 /* If MWI was previously enabled, reenable it. */
526 if (hw->mac_type == e1000_82542_rev2_0) {
527 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
528 e1000_pci_set_mwi(hw);
531 return E1000_SUCCESS;
535 * e1000_init_hw: Performs basic configuration of the adapter.
536 * @hw: Struct containing variables accessed by shared code
538 * Assumes that the controller has previously been reset and is in a
539 * post-reset uninitialized state. Initializes the receive address registers,
540 * multicast table, and VLAN filter table. Calls routines to setup link
541 * configuration and flow control settings. Clears all on-chip counters. Leaves
542 * the transmit and receive units disabled and uninitialized.
544 s32 e1000_init_hw(struct e1000_hw *hw)
546 u32 ctrl;
547 u32 i;
548 s32 ret_val;
549 u32 mta_size;
550 u32 ctrl_ext;
552 DEBUGFUNC("e1000_init_hw");
554 /* Initialize Identification LED */
555 ret_val = e1000_id_led_init(hw);
556 if (ret_val) {
557 DEBUGOUT("Error Initializing Identification LED\n");
558 return ret_val;
561 /* Set the media type and TBI compatibility */
562 e1000_set_media_type(hw);
564 /* Disabling VLAN filtering. */
565 DEBUGOUT("Initializing the IEEE VLAN\n");
566 if (hw->mac_type < e1000_82545_rev_3)
567 ew32(VET, 0);
568 e1000_clear_vfta(hw);
570 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
571 if (hw->mac_type == e1000_82542_rev2_0) {
572 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
573 e1000_pci_clear_mwi(hw);
574 ew32(RCTL, E1000_RCTL_RST);
575 E1000_WRITE_FLUSH();
576 msleep(5);
579 /* Setup the receive address. This involves initializing all of the Receive
580 * Address Registers (RARs 0 - 15).
582 e1000_init_rx_addrs(hw);
584 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
585 if (hw->mac_type == e1000_82542_rev2_0) {
586 ew32(RCTL, 0);
587 E1000_WRITE_FLUSH();
588 msleep(1);
589 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
590 e1000_pci_set_mwi(hw);
593 /* Zero out the Multicast HASH table */
594 DEBUGOUT("Zeroing the MTA\n");
595 mta_size = E1000_MC_TBL_SIZE;
596 for (i = 0; i < mta_size; i++) {
597 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
598 /* use write flush to prevent Memory Write Block (MWB) from
599 * occurring when accessing our register space */
600 E1000_WRITE_FLUSH();
603 /* Set the PCI priority bit correctly in the CTRL register. This
604 * determines if the adapter gives priority to receives, or if it
605 * gives equal priority to transmits and receives. Valid only on
606 * 82542 and 82543 silicon.
608 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
609 ctrl = er32(CTRL);
610 ew32(CTRL, ctrl | E1000_CTRL_PRIOR);
613 switch (hw->mac_type) {
614 case e1000_82545_rev_3:
615 case e1000_82546_rev_3:
616 break;
617 default:
618 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
619 if (hw->bus_type == e1000_bus_type_pcix
620 && e1000_pcix_get_mmrbc(hw) > 2048)
621 e1000_pcix_set_mmrbc(hw, 2048);
622 break;
625 /* Call a subroutine to configure the link and setup flow control. */
626 ret_val = e1000_setup_link(hw);
628 /* Set the transmit descriptor write-back policy */
629 if (hw->mac_type > e1000_82544) {
630 ctrl = er32(TXDCTL);
631 ctrl =
632 (ctrl & ~E1000_TXDCTL_WTHRESH) |
633 E1000_TXDCTL_FULL_TX_DESC_WB;
634 ew32(TXDCTL, ctrl);
637 /* Clear all of the statistics registers (clear on read). It is
638 * important that we do this after we have tried to establish link
639 * because the symbol error count will increment wildly if there
640 * is no link.
642 e1000_clear_hw_cntrs(hw);
644 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
645 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
646 ctrl_ext = er32(CTRL_EXT);
647 /* Relaxed ordering must be disabled to avoid a parity
648 * error crash in a PCI slot. */
649 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
650 ew32(CTRL_EXT, ctrl_ext);
653 return ret_val;
657 * e1000_adjust_serdes_amplitude - Adjust SERDES output amplitude based on EEPROM setting.
658 * @hw: Struct containing variables accessed by shared code.
660 static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
662 u16 eeprom_data;
663 s32 ret_val;
665 DEBUGFUNC("e1000_adjust_serdes_amplitude");
667 if (hw->media_type != e1000_media_type_internal_serdes)
668 return E1000_SUCCESS;
670 switch (hw->mac_type) {
671 case e1000_82545_rev_3:
672 case e1000_82546_rev_3:
673 break;
674 default:
675 return E1000_SUCCESS;
678 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1,
679 &eeprom_data);
680 if (ret_val) {
681 return ret_val;
684 if (eeprom_data != EEPROM_RESERVED_WORD) {
685 /* Adjust SERDES output amplitude only. */
686 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
687 ret_val =
688 e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
689 if (ret_val)
690 return ret_val;
693 return E1000_SUCCESS;
697 * e1000_setup_link - Configures flow control and link settings.
698 * @hw: Struct containing variables accessed by shared code
700 * Determines which flow control settings to use. Calls the appropriate media-
701 * specific link configuration function. Configures the flow control settings.
702 * Assuming the adapter has a valid link partner, a valid link should be
703 * established. Assumes the hardware has previously been reset and the
704 * transmitter and receiver are not enabled.
706 s32 e1000_setup_link(struct e1000_hw *hw)
708 u32 ctrl_ext;
709 s32 ret_val;
710 u16 eeprom_data;
712 DEBUGFUNC("e1000_setup_link");
714 /* Read and store word 0x0F of the EEPROM. This word contains bits
715 * that determine the hardware's default PAUSE (flow control) mode,
716 * a bit that determines whether the HW defaults to enabling or
717 * disabling auto-negotiation, and the direction of the
718 * SW defined pins. If there is no SW over-ride of the flow
719 * control setting, then the variable hw->fc will
720 * be initialized based on a value in the EEPROM.
722 if (hw->fc == E1000_FC_DEFAULT) {
723 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
724 1, &eeprom_data);
725 if (ret_val) {
726 DEBUGOUT("EEPROM Read Error\n");
727 return -E1000_ERR_EEPROM;
729 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
730 hw->fc = E1000_FC_NONE;
731 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
732 EEPROM_WORD0F_ASM_DIR)
733 hw->fc = E1000_FC_TX_PAUSE;
734 else
735 hw->fc = E1000_FC_FULL;
738 /* We want to save off the original Flow Control configuration just
739 * in case we get disconnected and then reconnected into a different
740 * hub or switch with different Flow Control capabilities.
742 if (hw->mac_type == e1000_82542_rev2_0)
743 hw->fc &= (~E1000_FC_TX_PAUSE);
745 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
746 hw->fc &= (~E1000_FC_RX_PAUSE);
748 hw->original_fc = hw->fc;
750 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
752 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
753 * polarity value for the SW controlled pins, and setup the
754 * Extended Device Control reg with that info.
755 * This is needed because one of the SW controlled pins is used for
756 * signal detection. So this should be done before e1000_setup_pcs_link()
757 * or e1000_phy_setup() is called.
759 if (hw->mac_type == e1000_82543) {
760 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
761 1, &eeprom_data);
762 if (ret_val) {
763 DEBUGOUT("EEPROM Read Error\n");
764 return -E1000_ERR_EEPROM;
766 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
767 SWDPIO__EXT_SHIFT);
768 ew32(CTRL_EXT, ctrl_ext);
771 /* Call the necessary subroutine to configure the link. */
772 ret_val = (hw->media_type == e1000_media_type_copper) ?
773 e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw);
775 /* Initialize the flow control address, type, and PAUSE timer
776 * registers to their default values. This is done even if flow
777 * control is disabled, because it does not hurt anything to
778 * initialize these registers.
780 DEBUGOUT
781 ("Initializing the Flow Control address, type and timer regs\n");
783 ew32(FCT, FLOW_CONTROL_TYPE);
784 ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
785 ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
787 ew32(FCTTV, hw->fc_pause_time);
789 /* Set the flow control receive threshold registers. Normally,
790 * these registers will be set to a default threshold that may be
791 * adjusted later by the driver's runtime code. However, if the
792 * ability to transmit pause frames in not enabled, then these
793 * registers will be set to 0.
795 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
796 ew32(FCRTL, 0);
797 ew32(FCRTH, 0);
798 } else {
799 /* We need to set up the Receive Threshold high and low water marks
800 * as well as (optionally) enabling the transmission of XON frames.
802 if (hw->fc_send_xon) {
803 ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
804 ew32(FCRTH, hw->fc_high_water);
805 } else {
806 ew32(FCRTL, hw->fc_low_water);
807 ew32(FCRTH, hw->fc_high_water);
810 return ret_val;
814 * e1000_setup_fiber_serdes_link - prepare fiber or serdes link
815 * @hw: Struct containing variables accessed by shared code
817 * Manipulates Physical Coding Sublayer functions in order to configure
818 * link. Assumes the hardware has been previously reset and the transmitter
819 * and receiver are not enabled.
821 static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
823 u32 ctrl;
824 u32 status;
825 u32 txcw = 0;
826 u32 i;
827 u32 signal = 0;
828 s32 ret_val;
830 DEBUGFUNC("e1000_setup_fiber_serdes_link");
832 /* On adapters with a MAC newer than 82544, SWDP 1 will be
833 * set when the optics detect a signal. On older adapters, it will be
834 * cleared when there is a signal. This applies to fiber media only.
835 * If we're on serdes media, adjust the output amplitude to value
836 * set in the EEPROM.
838 ctrl = er32(CTRL);
839 if (hw->media_type == e1000_media_type_fiber)
840 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
842 ret_val = e1000_adjust_serdes_amplitude(hw);
843 if (ret_val)
844 return ret_val;
846 /* Take the link out of reset */
847 ctrl &= ~(E1000_CTRL_LRST);
849 /* Adjust VCO speed to improve BER performance */
850 ret_val = e1000_set_vco_speed(hw);
851 if (ret_val)
852 return ret_val;
854 e1000_config_collision_dist(hw);
856 /* Check for a software override of the flow control settings, and setup
857 * the device accordingly. If auto-negotiation is enabled, then software
858 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
859 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
860 * auto-negotiation is disabled, then software will have to manually
861 * configure the two flow control enable bits in the CTRL register.
863 * The possible values of the "fc" parameter are:
864 * 0: Flow control is completely disabled
865 * 1: Rx flow control is enabled (we can receive pause frames, but
866 * not send pause frames).
867 * 2: Tx flow control is enabled (we can send pause frames but we do
868 * not support receiving pause frames).
869 * 3: Both Rx and TX flow control (symmetric) are enabled.
871 switch (hw->fc) {
872 case E1000_FC_NONE:
873 /* Flow control is completely disabled by a software over-ride. */
874 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
875 break;
876 case E1000_FC_RX_PAUSE:
877 /* RX Flow control is enabled and TX Flow control is disabled by a
878 * software over-ride. Since there really isn't a way to advertise
879 * that we are capable of RX Pause ONLY, we will advertise that we
880 * support both symmetric and asymmetric RX PAUSE. Later, we will
881 * disable the adapter's ability to send PAUSE frames.
883 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
884 break;
885 case E1000_FC_TX_PAUSE:
886 /* TX Flow control is enabled, and RX Flow control is disabled, by a
887 * software over-ride.
889 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
890 break;
891 case E1000_FC_FULL:
892 /* Flow control (both RX and TX) is enabled by a software over-ride. */
893 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
894 break;
895 default:
896 DEBUGOUT("Flow control param set incorrectly\n");
897 return -E1000_ERR_CONFIG;
898 break;
901 /* Since auto-negotiation is enabled, take the link out of reset (the link
902 * will be in reset, because we previously reset the chip). This will
903 * restart auto-negotiation. If auto-negotiation is successful then the
904 * link-up status bit will be set and the flow control enable bits (RFCE
905 * and TFCE) will be set according to their negotiated value.
907 DEBUGOUT("Auto-negotiation enabled\n");
909 ew32(TXCW, txcw);
910 ew32(CTRL, ctrl);
911 E1000_WRITE_FLUSH();
913 hw->txcw = txcw;
914 msleep(1);
916 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
917 * indication in the Device Status Register. Time-out if a link isn't
918 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
919 * less than 500 milliseconds even if the other end is doing it in SW).
920 * For internal serdes, we just assume a signal is present, then poll.
922 if (hw->media_type == e1000_media_type_internal_serdes ||
923 (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) {
924 DEBUGOUT("Looking for Link\n");
925 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
926 msleep(10);
927 status = er32(STATUS);
928 if (status & E1000_STATUS_LU)
929 break;
931 if (i == (LINK_UP_TIMEOUT / 10)) {
932 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
933 hw->autoneg_failed = 1;
934 /* AutoNeg failed to achieve a link, so we'll call
935 * e1000_check_for_link. This routine will force the link up if
936 * we detect a signal. This will allow us to communicate with
937 * non-autonegotiating link partners.
939 ret_val = e1000_check_for_link(hw);
940 if (ret_val) {
941 DEBUGOUT("Error while checking for link\n");
942 return ret_val;
944 hw->autoneg_failed = 0;
945 } else {
946 hw->autoneg_failed = 0;
947 DEBUGOUT("Valid Link Found\n");
949 } else {
950 DEBUGOUT("No Signal Detected\n");
952 return E1000_SUCCESS;
956 * e1000_copper_link_preconfig - early configuration for copper
957 * @hw: Struct containing variables accessed by shared code
959 * Make sure we have a valid PHY and change PHY mode before link setup.
961 static s32 e1000_copper_link_preconfig(struct e1000_hw *hw)
963 u32 ctrl;
964 s32 ret_val;
965 u16 phy_data;
967 DEBUGFUNC("e1000_copper_link_preconfig");
969 ctrl = er32(CTRL);
970 /* With 82543, we need to force speed and duplex on the MAC equal to what
971 * the PHY speed and duplex configuration is. In addition, we need to
972 * perform a hardware reset on the PHY to take it out of reset.
974 if (hw->mac_type > e1000_82543) {
975 ctrl |= E1000_CTRL_SLU;
976 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
977 ew32(CTRL, ctrl);
978 } else {
979 ctrl |=
980 (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
981 ew32(CTRL, ctrl);
982 ret_val = e1000_phy_hw_reset(hw);
983 if (ret_val)
984 return ret_val;
987 /* Make sure we have a valid PHY */
988 ret_val = e1000_detect_gig_phy(hw);
989 if (ret_val) {
990 DEBUGOUT("Error, did not detect valid phy.\n");
991 return ret_val;
993 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
995 /* Set PHY to class A mode (if necessary) */
996 ret_val = e1000_set_phy_mode(hw);
997 if (ret_val)
998 return ret_val;
1000 if ((hw->mac_type == e1000_82545_rev_3) ||
1001 (hw->mac_type == e1000_82546_rev_3)) {
1002 ret_val =
1003 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1004 phy_data |= 0x00000008;
1005 ret_val =
1006 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1009 if (hw->mac_type <= e1000_82543 ||
1010 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1011 hw->mac_type == e1000_82541_rev_2
1012 || hw->mac_type == e1000_82547_rev_2)
1013 hw->phy_reset_disable = false;
1015 return E1000_SUCCESS;
1019 * e1000_copper_link_igp_setup - Copper link setup for e1000_phy_igp series.
1020 * @hw: Struct containing variables accessed by shared code
1022 static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1024 u32 led_ctrl;
1025 s32 ret_val;
1026 u16 phy_data;
1028 DEBUGFUNC("e1000_copper_link_igp_setup");
1030 if (hw->phy_reset_disable)
1031 return E1000_SUCCESS;
1033 ret_val = e1000_phy_reset(hw);
1034 if (ret_val) {
1035 DEBUGOUT("Error Resetting the PHY\n");
1036 return ret_val;
1039 /* Wait 15ms for MAC to configure PHY from eeprom settings */
1040 msleep(15);
1041 /* Configure activity LED after PHY reset */
1042 led_ctrl = er32(LEDCTL);
1043 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1044 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1045 ew32(LEDCTL, led_ctrl);
1047 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1048 if (hw->phy_type == e1000_phy_igp) {
1049 /* disable lplu d3 during driver init */
1050 ret_val = e1000_set_d3_lplu_state(hw, false);
1051 if (ret_val) {
1052 DEBUGOUT("Error Disabling LPLU D3\n");
1053 return ret_val;
1057 /* Configure mdi-mdix settings */
1058 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1059 if (ret_val)
1060 return ret_val;
1062 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1063 hw->dsp_config_state = e1000_dsp_config_disabled;
1064 /* Force MDI for earlier revs of the IGP PHY */
1065 phy_data &=
1066 ~(IGP01E1000_PSCR_AUTO_MDIX |
1067 IGP01E1000_PSCR_FORCE_MDI_MDIX);
1068 hw->mdix = 1;
1070 } else {
1071 hw->dsp_config_state = e1000_dsp_config_enabled;
1072 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1074 switch (hw->mdix) {
1075 case 1:
1076 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1077 break;
1078 case 2:
1079 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1080 break;
1081 case 0:
1082 default:
1083 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1084 break;
1087 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1088 if (ret_val)
1089 return ret_val;
1091 /* set auto-master slave resolution settings */
1092 if (hw->autoneg) {
1093 e1000_ms_type phy_ms_setting = hw->master_slave;
1095 if (hw->ffe_config_state == e1000_ffe_config_active)
1096 hw->ffe_config_state = e1000_ffe_config_enabled;
1098 if (hw->dsp_config_state == e1000_dsp_config_activated)
1099 hw->dsp_config_state = e1000_dsp_config_enabled;
1101 /* when autonegotiation advertisement is only 1000Mbps then we
1102 * should disable SmartSpeed and enable Auto MasterSlave
1103 * resolution as hardware default. */
1104 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1105 /* Disable SmartSpeed */
1106 ret_val =
1107 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1108 &phy_data);
1109 if (ret_val)
1110 return ret_val;
1111 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1112 ret_val =
1113 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1114 phy_data);
1115 if (ret_val)
1116 return ret_val;
1117 /* Set auto Master/Slave resolution process */
1118 ret_val =
1119 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1120 if (ret_val)
1121 return ret_val;
1122 phy_data &= ~CR_1000T_MS_ENABLE;
1123 ret_val =
1124 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1125 if (ret_val)
1126 return ret_val;
1129 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1130 if (ret_val)
1131 return ret_val;
1133 /* load defaults for future use */
1134 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1135 ((phy_data & CR_1000T_MS_VALUE) ?
1136 e1000_ms_force_master :
1137 e1000_ms_force_slave) : e1000_ms_auto;
1139 switch (phy_ms_setting) {
1140 case e1000_ms_force_master:
1141 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1142 break;
1143 case e1000_ms_force_slave:
1144 phy_data |= CR_1000T_MS_ENABLE;
1145 phy_data &= ~(CR_1000T_MS_VALUE);
1146 break;
1147 case e1000_ms_auto:
1148 phy_data &= ~CR_1000T_MS_ENABLE;
1149 default:
1150 break;
1152 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1153 if (ret_val)
1154 return ret_val;
1157 return E1000_SUCCESS;
1161 * e1000_copper_link_mgp_setup - Copper link setup for e1000_phy_m88 series.
1162 * @hw: Struct containing variables accessed by shared code
1164 static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1166 s32 ret_val;
1167 u16 phy_data;
1169 DEBUGFUNC("e1000_copper_link_mgp_setup");
1171 if (hw->phy_reset_disable)
1172 return E1000_SUCCESS;
1174 /* Enable CRS on TX. This must be set for half-duplex operation. */
1175 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1176 if (ret_val)
1177 return ret_val;
1179 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1181 /* Options:
1182 * MDI/MDI-X = 0 (default)
1183 * 0 - Auto for all speeds
1184 * 1 - MDI mode
1185 * 2 - MDI-X mode
1186 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1188 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1190 switch (hw->mdix) {
1191 case 1:
1192 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1193 break;
1194 case 2:
1195 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1196 break;
1197 case 3:
1198 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1199 break;
1200 case 0:
1201 default:
1202 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1203 break;
1206 /* Options:
1207 * disable_polarity_correction = 0 (default)
1208 * Automatic Correction for Reversed Cable Polarity
1209 * 0 - Disabled
1210 * 1 - Enabled
1212 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1213 if (hw->disable_polarity_correction == 1)
1214 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1215 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1216 if (ret_val)
1217 return ret_val;
1219 if (hw->phy_revision < M88E1011_I_REV_4) {
1220 /* Force TX_CLK in the Extended PHY Specific Control Register
1221 * to 25MHz clock.
1223 ret_val =
1224 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1225 &phy_data);
1226 if (ret_val)
1227 return ret_val;
1229 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1231 if ((hw->phy_revision == E1000_REVISION_2) &&
1232 (hw->phy_id == M88E1111_I_PHY_ID)) {
1233 /* Vidalia Phy, set the downshift counter to 5x */
1234 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1235 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1236 ret_val = e1000_write_phy_reg(hw,
1237 M88E1000_EXT_PHY_SPEC_CTRL,
1238 phy_data);
1239 if (ret_val)
1240 return ret_val;
1241 } else {
1242 /* Configure Master and Slave downshift values */
1243 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1244 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1245 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1246 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1247 ret_val = e1000_write_phy_reg(hw,
1248 M88E1000_EXT_PHY_SPEC_CTRL,
1249 phy_data);
1250 if (ret_val)
1251 return ret_val;
1255 /* SW Reset the PHY so all changes take effect */
1256 ret_val = e1000_phy_reset(hw);
1257 if (ret_val) {
1258 DEBUGOUT("Error Resetting the PHY\n");
1259 return ret_val;
1262 return E1000_SUCCESS;
1266 * e1000_copper_link_autoneg - setup auto-neg
1267 * @hw: Struct containing variables accessed by shared code
1269 * Setup auto-negotiation and flow control advertisements,
1270 * and then perform auto-negotiation.
1272 static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1274 s32 ret_val;
1275 u16 phy_data;
1277 DEBUGFUNC("e1000_copper_link_autoneg");
1279 /* Perform some bounds checking on the hw->autoneg_advertised
1280 * parameter. If this variable is zero, then set it to the default.
1282 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1284 /* If autoneg_advertised is zero, we assume it was not defaulted
1285 * by the calling code so we set to advertise full capability.
1287 if (hw->autoneg_advertised == 0)
1288 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1290 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1291 ret_val = e1000_phy_setup_autoneg(hw);
1292 if (ret_val) {
1293 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1294 return ret_val;
1296 DEBUGOUT("Restarting Auto-Neg\n");
1298 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1299 * the Auto Neg Restart bit in the PHY control register.
1301 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1302 if (ret_val)
1303 return ret_val;
1305 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1306 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1307 if (ret_val)
1308 return ret_val;
1310 /* Does the user want to wait for Auto-Neg to complete here, or
1311 * check at a later time (for example, callback routine).
1313 if (hw->wait_autoneg_complete) {
1314 ret_val = e1000_wait_autoneg(hw);
1315 if (ret_val) {
1316 DEBUGOUT
1317 ("Error while waiting for autoneg to complete\n");
1318 return ret_val;
1322 hw->get_link_status = true;
1324 return E1000_SUCCESS;
1328 * e1000_copper_link_postconfig - post link setup
1329 * @hw: Struct containing variables accessed by shared code
1331 * Config the MAC and the PHY after link is up.
1332 * 1) Set up the MAC to the current PHY speed/duplex
1333 * if we are on 82543. If we
1334 * are on newer silicon, we only need to configure
1335 * collision distance in the Transmit Control Register.
1336 * 2) Set up flow control on the MAC to that established with
1337 * the link partner.
1338 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1340 static s32 e1000_copper_link_postconfig(struct e1000_hw *hw)
1342 s32 ret_val;
1343 DEBUGFUNC("e1000_copper_link_postconfig");
1345 if (hw->mac_type >= e1000_82544) {
1346 e1000_config_collision_dist(hw);
1347 } else {
1348 ret_val = e1000_config_mac_to_phy(hw);
1349 if (ret_val) {
1350 DEBUGOUT("Error configuring MAC to PHY settings\n");
1351 return ret_val;
1354 ret_val = e1000_config_fc_after_link_up(hw);
1355 if (ret_val) {
1356 DEBUGOUT("Error Configuring Flow Control\n");
1357 return ret_val;
1360 /* Config DSP to improve Giga link quality */
1361 if (hw->phy_type == e1000_phy_igp) {
1362 ret_val = e1000_config_dsp_after_link_change(hw, true);
1363 if (ret_val) {
1364 DEBUGOUT("Error Configuring DSP after link up\n");
1365 return ret_val;
1369 return E1000_SUCCESS;
1373 * e1000_setup_copper_link - phy/speed/duplex setting
1374 * @hw: Struct containing variables accessed by shared code
1376 * Detects which PHY is present and sets up the speed and duplex
1378 static s32 e1000_setup_copper_link(struct e1000_hw *hw)
1380 s32 ret_val;
1381 u16 i;
1382 u16 phy_data;
1384 DEBUGFUNC("e1000_setup_copper_link");
1386 /* Check if it is a valid PHY and set PHY mode if necessary. */
1387 ret_val = e1000_copper_link_preconfig(hw);
1388 if (ret_val)
1389 return ret_val;
1391 if (hw->phy_type == e1000_phy_igp) {
1392 ret_val = e1000_copper_link_igp_setup(hw);
1393 if (ret_val)
1394 return ret_val;
1395 } else if (hw->phy_type == e1000_phy_m88) {
1396 ret_val = e1000_copper_link_mgp_setup(hw);
1397 if (ret_val)
1398 return ret_val;
1401 if (hw->autoneg) {
1402 /* Setup autoneg and flow control advertisement
1403 * and perform autonegotiation */
1404 ret_val = e1000_copper_link_autoneg(hw);
1405 if (ret_val)
1406 return ret_val;
1407 } else {
1408 /* PHY will be set to 10H, 10F, 100H,or 100F
1409 * depending on value from forced_speed_duplex. */
1410 DEBUGOUT("Forcing speed and duplex\n");
1411 ret_val = e1000_phy_force_speed_duplex(hw);
1412 if (ret_val) {
1413 DEBUGOUT("Error Forcing Speed and Duplex\n");
1414 return ret_val;
1418 /* Check link status. Wait up to 100 microseconds for link to become
1419 * valid.
1421 for (i = 0; i < 10; i++) {
1422 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1423 if (ret_val)
1424 return ret_val;
1425 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1426 if (ret_val)
1427 return ret_val;
1429 if (phy_data & MII_SR_LINK_STATUS) {
1430 /* Config the MAC and PHY after link is up */
1431 ret_val = e1000_copper_link_postconfig(hw);
1432 if (ret_val)
1433 return ret_val;
1435 DEBUGOUT("Valid link established!!!\n");
1436 return E1000_SUCCESS;
1438 udelay(10);
1441 DEBUGOUT("Unable to establish link!!!\n");
1442 return E1000_SUCCESS;
1446 * e1000_phy_setup_autoneg - phy settings
1447 * @hw: Struct containing variables accessed by shared code
1449 * Configures PHY autoneg and flow control advertisement settings
1451 s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1453 s32 ret_val;
1454 u16 mii_autoneg_adv_reg;
1455 u16 mii_1000t_ctrl_reg;
1457 DEBUGFUNC("e1000_phy_setup_autoneg");
1459 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1460 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1461 if (ret_val)
1462 return ret_val;
1464 /* Read the MII 1000Base-T Control Register (Address 9). */
1465 ret_val =
1466 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1467 if (ret_val)
1468 return ret_val;
1470 /* Need to parse both autoneg_advertised and fc and set up
1471 * the appropriate PHY registers. First we will parse for
1472 * autoneg_advertised software override. Since we can advertise
1473 * a plethora of combinations, we need to check each bit
1474 * individually.
1477 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1478 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1479 * the 1000Base-T Control Register (Address 9).
1481 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1482 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1484 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1486 /* Do we want to advertise 10 Mb Half Duplex? */
1487 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
1488 DEBUGOUT("Advertise 10mb Half duplex\n");
1489 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1492 /* Do we want to advertise 10 Mb Full Duplex? */
1493 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
1494 DEBUGOUT("Advertise 10mb Full duplex\n");
1495 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1498 /* Do we want to advertise 100 Mb Half Duplex? */
1499 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
1500 DEBUGOUT("Advertise 100mb Half duplex\n");
1501 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1504 /* Do we want to advertise 100 Mb Full Duplex? */
1505 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
1506 DEBUGOUT("Advertise 100mb Full duplex\n");
1507 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1510 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1511 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1512 DEBUGOUT
1513 ("Advertise 1000mb Half duplex requested, request denied!\n");
1516 /* Do we want to advertise 1000 Mb Full Duplex? */
1517 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1518 DEBUGOUT("Advertise 1000mb Full duplex\n");
1519 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1522 /* Check for a software override of the flow control settings, and
1523 * setup the PHY advertisement registers accordingly. If
1524 * auto-negotiation is enabled, then software will have to set the
1525 * "PAUSE" bits to the correct value in the Auto-Negotiation
1526 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1528 * The possible values of the "fc" parameter are:
1529 * 0: Flow control is completely disabled
1530 * 1: Rx flow control is enabled (we can receive pause frames
1531 * but not send pause frames).
1532 * 2: Tx flow control is enabled (we can send pause frames
1533 * but we do not support receiving pause frames).
1534 * 3: Both Rx and TX flow control (symmetric) are enabled.
1535 * other: No software override. The flow control configuration
1536 * in the EEPROM is used.
1538 switch (hw->fc) {
1539 case E1000_FC_NONE: /* 0 */
1540 /* Flow control (RX & TX) is completely disabled by a
1541 * software over-ride.
1543 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1544 break;
1545 case E1000_FC_RX_PAUSE: /* 1 */
1546 /* RX Flow control is enabled, and TX Flow control is
1547 * disabled, by a software over-ride.
1549 /* Since there really isn't a way to advertise that we are
1550 * capable of RX Pause ONLY, we will advertise that we
1551 * support both symmetric and asymmetric RX PAUSE. Later
1552 * (in e1000_config_fc_after_link_up) we will disable the
1553 *hw's ability to send PAUSE frames.
1555 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1556 break;
1557 case E1000_FC_TX_PAUSE: /* 2 */
1558 /* TX Flow control is enabled, and RX Flow control is
1559 * disabled, by a software over-ride.
1561 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1562 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1563 break;
1564 case E1000_FC_FULL: /* 3 */
1565 /* Flow control (both RX and TX) is enabled by a software
1566 * over-ride.
1568 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1569 break;
1570 default:
1571 DEBUGOUT("Flow control param set incorrectly\n");
1572 return -E1000_ERR_CONFIG;
1575 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1576 if (ret_val)
1577 return ret_val;
1579 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1581 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1582 if (ret_val)
1583 return ret_val;
1585 return E1000_SUCCESS;
1589 * e1000_phy_force_speed_duplex - force link settings
1590 * @hw: Struct containing variables accessed by shared code
1592 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1594 static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1596 u32 ctrl;
1597 s32 ret_val;
1598 u16 mii_ctrl_reg;
1599 u16 mii_status_reg;
1600 u16 phy_data;
1601 u16 i;
1603 DEBUGFUNC("e1000_phy_force_speed_duplex");
1605 /* Turn off Flow control if we are forcing speed and duplex. */
1606 hw->fc = E1000_FC_NONE;
1608 DEBUGOUT1("hw->fc = %d\n", hw->fc);
1610 /* Read the Device Control Register. */
1611 ctrl = er32(CTRL);
1613 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1614 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1615 ctrl &= ~(DEVICE_SPEED_MASK);
1617 /* Clear the Auto Speed Detect Enable bit. */
1618 ctrl &= ~E1000_CTRL_ASDE;
1620 /* Read the MII Control Register. */
1621 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1622 if (ret_val)
1623 return ret_val;
1625 /* We need to disable autoneg in order to force link and duplex. */
1627 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1629 /* Are we forcing Full or Half Duplex? */
1630 if (hw->forced_speed_duplex == e1000_100_full ||
1631 hw->forced_speed_duplex == e1000_10_full) {
1632 /* We want to force full duplex so we SET the full duplex bits in the
1633 * Device and MII Control Registers.
1635 ctrl |= E1000_CTRL_FD;
1636 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1637 DEBUGOUT("Full Duplex\n");
1638 } else {
1639 /* We want to force half duplex so we CLEAR the full duplex bits in
1640 * the Device and MII Control Registers.
1642 ctrl &= ~E1000_CTRL_FD;
1643 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1644 DEBUGOUT("Half Duplex\n");
1647 /* Are we forcing 100Mbps??? */
1648 if (hw->forced_speed_duplex == e1000_100_full ||
1649 hw->forced_speed_duplex == e1000_100_half) {
1650 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1651 ctrl |= E1000_CTRL_SPD_100;
1652 mii_ctrl_reg |= MII_CR_SPEED_100;
1653 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1654 DEBUGOUT("Forcing 100mb ");
1655 } else {
1656 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1657 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1658 mii_ctrl_reg |= MII_CR_SPEED_10;
1659 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1660 DEBUGOUT("Forcing 10mb ");
1663 e1000_config_collision_dist(hw);
1665 /* Write the configured values back to the Device Control Reg. */
1666 ew32(CTRL, ctrl);
1668 if (hw->phy_type == e1000_phy_m88) {
1669 ret_val =
1670 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1671 if (ret_val)
1672 return ret_val;
1674 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1675 * forced whenever speed are duplex are forced.
1677 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1678 ret_val =
1679 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1680 if (ret_val)
1681 return ret_val;
1683 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1685 /* Need to reset the PHY or these changes will be ignored */
1686 mii_ctrl_reg |= MII_CR_RESET;
1688 /* Disable MDI-X support for 10/100 */
1689 } else {
1690 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1691 * forced whenever speed or duplex are forced.
1693 ret_val =
1694 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1695 if (ret_val)
1696 return ret_val;
1698 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1699 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1701 ret_val =
1702 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1703 if (ret_val)
1704 return ret_val;
1707 /* Write back the modified PHY MII control register. */
1708 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1709 if (ret_val)
1710 return ret_val;
1712 udelay(1);
1714 /* The wait_autoneg_complete flag may be a little misleading here.
1715 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1716 * But we do want to delay for a period while forcing only so we
1717 * don't generate false No Link messages. So we will wait here
1718 * only if the user has set wait_autoneg_complete to 1, which is
1719 * the default.
1721 if (hw->wait_autoneg_complete) {
1722 /* We will wait for autoneg to complete. */
1723 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1724 mii_status_reg = 0;
1726 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1727 for (i = PHY_FORCE_TIME; i > 0; i--) {
1728 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1729 * to be set.
1731 ret_val =
1732 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1733 if (ret_val)
1734 return ret_val;
1736 ret_val =
1737 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1738 if (ret_val)
1739 return ret_val;
1741 if (mii_status_reg & MII_SR_LINK_STATUS)
1742 break;
1743 msleep(100);
1745 if ((i == 0) && (hw->phy_type == e1000_phy_m88)) {
1746 /* We didn't get link. Reset the DSP and wait again for link. */
1747 ret_val = e1000_phy_reset_dsp(hw);
1748 if (ret_val) {
1749 DEBUGOUT("Error Resetting PHY DSP\n");
1750 return ret_val;
1753 /* This loop will early-out if the link condition has been met. */
1754 for (i = PHY_FORCE_TIME; i > 0; i--) {
1755 if (mii_status_reg & MII_SR_LINK_STATUS)
1756 break;
1757 msleep(100);
1758 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1759 * to be set.
1761 ret_val =
1762 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1763 if (ret_val)
1764 return ret_val;
1766 ret_val =
1767 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1768 if (ret_val)
1769 return ret_val;
1773 if (hw->phy_type == e1000_phy_m88) {
1774 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1775 * Extended PHY Specific Control Register to 25MHz clock. This value
1776 * defaults back to a 2.5MHz clock when the PHY is reset.
1778 ret_val =
1779 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1780 &phy_data);
1781 if (ret_val)
1782 return ret_val;
1784 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1785 ret_val =
1786 e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1787 phy_data);
1788 if (ret_val)
1789 return ret_val;
1791 /* In addition, because of the s/w reset above, we need to enable CRS on
1792 * TX. This must be set for both full and half duplex operation.
1794 ret_val =
1795 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1796 if (ret_val)
1797 return ret_val;
1799 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1800 ret_val =
1801 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1802 if (ret_val)
1803 return ret_val;
1805 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543)
1806 && (!hw->autoneg)
1807 && (hw->forced_speed_duplex == e1000_10_full
1808 || hw->forced_speed_duplex == e1000_10_half)) {
1809 ret_val = e1000_polarity_reversal_workaround(hw);
1810 if (ret_val)
1811 return ret_val;
1814 return E1000_SUCCESS;
1818 * e1000_config_collision_dist - set collision distance register
1819 * @hw: Struct containing variables accessed by shared code
1821 * Sets the collision distance in the Transmit Control register.
1822 * Link should have been established previously. Reads the speed and duplex
1823 * information from the Device Status register.
1825 void e1000_config_collision_dist(struct e1000_hw *hw)
1827 u32 tctl, coll_dist;
1829 DEBUGFUNC("e1000_config_collision_dist");
1831 if (hw->mac_type < e1000_82543)
1832 coll_dist = E1000_COLLISION_DISTANCE_82542;
1833 else
1834 coll_dist = E1000_COLLISION_DISTANCE;
1836 tctl = er32(TCTL);
1838 tctl &= ~E1000_TCTL_COLD;
1839 tctl |= coll_dist << E1000_COLD_SHIFT;
1841 ew32(TCTL, tctl);
1842 E1000_WRITE_FLUSH();
1846 * e1000_config_mac_to_phy - sync phy and mac settings
1847 * @hw: Struct containing variables accessed by shared code
1848 * @mii_reg: data to write to the MII control register
1850 * Sets MAC speed and duplex settings to reflect the those in the PHY
1851 * The contents of the PHY register containing the needed information need to
1852 * be passed in.
1854 static s32 e1000_config_mac_to_phy(struct e1000_hw *hw)
1856 u32 ctrl;
1857 s32 ret_val;
1858 u16 phy_data;
1860 DEBUGFUNC("e1000_config_mac_to_phy");
1862 /* 82544 or newer MAC, Auto Speed Detection takes care of
1863 * MAC speed/duplex configuration.*/
1864 if (hw->mac_type >= e1000_82544)
1865 return E1000_SUCCESS;
1867 /* Read the Device Control Register and set the bits to Force Speed
1868 * and Duplex.
1870 ctrl = er32(CTRL);
1871 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1872 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1874 /* Set up duplex in the Device Control and Transmit Control
1875 * registers depending on negotiated values.
1877 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1878 if (ret_val)
1879 return ret_val;
1881 if (phy_data & M88E1000_PSSR_DPLX)
1882 ctrl |= E1000_CTRL_FD;
1883 else
1884 ctrl &= ~E1000_CTRL_FD;
1886 e1000_config_collision_dist(hw);
1888 /* Set up speed in the Device Control register depending on
1889 * negotiated values.
1891 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1892 ctrl |= E1000_CTRL_SPD_1000;
1893 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1894 ctrl |= E1000_CTRL_SPD_100;
1896 /* Write the configured values back to the Device Control Reg. */
1897 ew32(CTRL, ctrl);
1898 return E1000_SUCCESS;
1902 * e1000_force_mac_fc - force flow control settings
1903 * @hw: Struct containing variables accessed by shared code
1905 * Forces the MAC's flow control settings.
1906 * Sets the TFCE and RFCE bits in the device control register to reflect
1907 * the adapter settings. TFCE and RFCE need to be explicitly set by
1908 * software when a Copper PHY is used because autonegotiation is managed
1909 * by the PHY rather than the MAC. Software must also configure these
1910 * bits when link is forced on a fiber connection.
1912 s32 e1000_force_mac_fc(struct e1000_hw *hw)
1914 u32 ctrl;
1916 DEBUGFUNC("e1000_force_mac_fc");
1918 /* Get the current configuration of the Device Control Register */
1919 ctrl = er32(CTRL);
1921 /* Because we didn't get link via the internal auto-negotiation
1922 * mechanism (we either forced link or we got link via PHY
1923 * auto-neg), we have to manually enable/disable transmit an
1924 * receive flow control.
1926 * The "Case" statement below enables/disable flow control
1927 * according to the "hw->fc" parameter.
1929 * The possible values of the "fc" parameter are:
1930 * 0: Flow control is completely disabled
1931 * 1: Rx flow control is enabled (we can receive pause
1932 * frames but not send pause frames).
1933 * 2: Tx flow control is enabled (we can send pause frames
1934 * frames but we do not receive pause frames).
1935 * 3: Both Rx and TX flow control (symmetric) is enabled.
1936 * other: No other values should be possible at this point.
1939 switch (hw->fc) {
1940 case E1000_FC_NONE:
1941 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1942 break;
1943 case E1000_FC_RX_PAUSE:
1944 ctrl &= (~E1000_CTRL_TFCE);
1945 ctrl |= E1000_CTRL_RFCE;
1946 break;
1947 case E1000_FC_TX_PAUSE:
1948 ctrl &= (~E1000_CTRL_RFCE);
1949 ctrl |= E1000_CTRL_TFCE;
1950 break;
1951 case E1000_FC_FULL:
1952 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1953 break;
1954 default:
1955 DEBUGOUT("Flow control param set incorrectly\n");
1956 return -E1000_ERR_CONFIG;
1959 /* Disable TX Flow Control for 82542 (rev 2.0) */
1960 if (hw->mac_type == e1000_82542_rev2_0)
1961 ctrl &= (~E1000_CTRL_TFCE);
1963 ew32(CTRL, ctrl);
1964 return E1000_SUCCESS;
1968 * e1000_config_fc_after_link_up - configure flow control after autoneg
1969 * @hw: Struct containing variables accessed by shared code
1971 * Configures flow control settings after link is established
1972 * Should be called immediately after a valid link has been established.
1973 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1974 * and autonegotiation is enabled, the MAC flow control settings will be set
1975 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1976 * and RFCE bits will be automatically set to the negotiated flow control mode.
1978 static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw)
1980 s32 ret_val;
1981 u16 mii_status_reg;
1982 u16 mii_nway_adv_reg;
1983 u16 mii_nway_lp_ability_reg;
1984 u16 speed;
1985 u16 duplex;
1987 DEBUGFUNC("e1000_config_fc_after_link_up");
1989 /* Check for the case where we have fiber media and auto-neg failed
1990 * so we had to force link. In this case, we need to force the
1991 * configuration of the MAC to match the "fc" parameter.
1993 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
1994 || ((hw->media_type == e1000_media_type_internal_serdes)
1995 && (hw->autoneg_failed))
1996 || ((hw->media_type == e1000_media_type_copper)
1997 && (!hw->autoneg))) {
1998 ret_val = e1000_force_mac_fc(hw);
1999 if (ret_val) {
2000 DEBUGOUT("Error forcing flow control settings\n");
2001 return ret_val;
2005 /* Check for the case where we have copper media and auto-neg is
2006 * enabled. In this case, we need to check and see if Auto-Neg
2007 * has completed, and if so, how the PHY and link partner has
2008 * flow control configured.
2010 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2011 /* Read the MII Status Register and check to see if AutoNeg
2012 * has completed. We read this twice because this reg has
2013 * some "sticky" (latched) bits.
2015 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2016 if (ret_val)
2017 return ret_val;
2018 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2019 if (ret_val)
2020 return ret_val;
2022 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2023 /* The AutoNeg process has completed, so we now need to
2024 * read both the Auto Negotiation Advertisement Register
2025 * (Address 4) and the Auto_Negotiation Base Page Ability
2026 * Register (Address 5) to determine how flow control was
2027 * negotiated.
2029 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2030 &mii_nway_adv_reg);
2031 if (ret_val)
2032 return ret_val;
2033 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2034 &mii_nway_lp_ability_reg);
2035 if (ret_val)
2036 return ret_val;
2038 /* Two bits in the Auto Negotiation Advertisement Register
2039 * (Address 4) and two bits in the Auto Negotiation Base
2040 * Page Ability Register (Address 5) determine flow control
2041 * for both the PHY and the link partner. The following
2042 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2043 * 1999, describes these PAUSE resolution bits and how flow
2044 * control is determined based upon these settings.
2045 * NOTE: DC = Don't Care
2047 * LOCAL DEVICE | LINK PARTNER
2048 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2049 *-------|---------|-------|---------|--------------------
2050 * 0 | 0 | DC | DC | E1000_FC_NONE
2051 * 0 | 1 | 0 | DC | E1000_FC_NONE
2052 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2053 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2054 * 1 | 0 | 0 | DC | E1000_FC_NONE
2055 * 1 | DC | 1 | DC | E1000_FC_FULL
2056 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2057 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2060 /* Are both PAUSE bits set to 1? If so, this implies
2061 * Symmetric Flow Control is enabled at both ends. The
2062 * ASM_DIR bits are irrelevant per the spec.
2064 * For Symmetric Flow Control:
2066 * LOCAL DEVICE | LINK PARTNER
2067 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2068 *-------|---------|-------|---------|--------------------
2069 * 1 | DC | 1 | DC | E1000_FC_FULL
2072 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2073 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2074 /* Now we need to check if the user selected RX ONLY
2075 * of pause frames. In this case, we had to advertise
2076 * FULL flow control because we could not advertise RX
2077 * ONLY. Hence, we must now check to see if we need to
2078 * turn OFF the TRANSMISSION of PAUSE frames.
2080 if (hw->original_fc == E1000_FC_FULL) {
2081 hw->fc = E1000_FC_FULL;
2082 DEBUGOUT("Flow Control = FULL.\n");
2083 } else {
2084 hw->fc = E1000_FC_RX_PAUSE;
2085 DEBUGOUT
2086 ("Flow Control = RX PAUSE frames only.\n");
2089 /* For receiving PAUSE frames ONLY.
2091 * LOCAL DEVICE | LINK PARTNER
2092 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2093 *-------|---------|-------|---------|--------------------
2094 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2097 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2098 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2099 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2100 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
2102 hw->fc = E1000_FC_TX_PAUSE;
2103 DEBUGOUT
2104 ("Flow Control = TX PAUSE frames only.\n");
2106 /* For transmitting PAUSE frames ONLY.
2108 * LOCAL DEVICE | LINK PARTNER
2109 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2110 *-------|---------|-------|---------|--------------------
2111 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2114 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2115 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2116 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2117 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
2119 hw->fc = E1000_FC_RX_PAUSE;
2120 DEBUGOUT
2121 ("Flow Control = RX PAUSE frames only.\n");
2123 /* Per the IEEE spec, at this point flow control should be
2124 * disabled. However, we want to consider that we could
2125 * be connected to a legacy switch that doesn't advertise
2126 * desired flow control, but can be forced on the link
2127 * partner. So if we advertised no flow control, that is
2128 * what we will resolve to. If we advertised some kind of
2129 * receive capability (Rx Pause Only or Full Flow Control)
2130 * and the link partner advertised none, we will configure
2131 * ourselves to enable Rx Flow Control only. We can do
2132 * this safely for two reasons: If the link partner really
2133 * didn't want flow control enabled, and we enable Rx, no
2134 * harm done since we won't be receiving any PAUSE frames
2135 * anyway. If the intent on the link partner was to have
2136 * flow control enabled, then by us enabling RX only, we
2137 * can at least receive pause frames and process them.
2138 * This is a good idea because in most cases, since we are
2139 * predominantly a server NIC, more times than not we will
2140 * be asked to delay transmission of packets than asking
2141 * our link partner to pause transmission of frames.
2143 else if ((hw->original_fc == E1000_FC_NONE ||
2144 hw->original_fc == E1000_FC_TX_PAUSE) ||
2145 hw->fc_strict_ieee) {
2146 hw->fc = E1000_FC_NONE;
2147 DEBUGOUT("Flow Control = NONE.\n");
2148 } else {
2149 hw->fc = E1000_FC_RX_PAUSE;
2150 DEBUGOUT
2151 ("Flow Control = RX PAUSE frames only.\n");
2154 /* Now we need to do one last check... If we auto-
2155 * negotiated to HALF DUPLEX, flow control should not be
2156 * enabled per IEEE 802.3 spec.
2158 ret_val =
2159 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2160 if (ret_val) {
2161 DEBUGOUT
2162 ("Error getting link speed and duplex\n");
2163 return ret_val;
2166 if (duplex == HALF_DUPLEX)
2167 hw->fc = E1000_FC_NONE;
2169 /* Now we call a subroutine to actually force the MAC
2170 * controller to use the correct flow control settings.
2172 ret_val = e1000_force_mac_fc(hw);
2173 if (ret_val) {
2174 DEBUGOUT
2175 ("Error forcing flow control settings\n");
2176 return ret_val;
2178 } else {
2179 DEBUGOUT
2180 ("Copper PHY and Auto Neg has not completed.\n");
2183 return E1000_SUCCESS;
2187 * e1000_check_for_serdes_link_generic - Check for link (Serdes)
2188 * @hw: pointer to the HW structure
2190 * Checks for link up on the hardware. If link is not up and we have
2191 * a signal, then we need to force link up.
2193 static s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw)
2195 u32 rxcw;
2196 u32 ctrl;
2197 u32 status;
2198 s32 ret_val = E1000_SUCCESS;
2200 DEBUGFUNC("e1000_check_for_serdes_link_generic");
2202 ctrl = er32(CTRL);
2203 status = er32(STATUS);
2204 rxcw = er32(RXCW);
2207 * If we don't have link (auto-negotiation failed or link partner
2208 * cannot auto-negotiate), and our link partner is not trying to
2209 * auto-negotiate with us (we are receiving idles or data),
2210 * we need to force link up. We also need to give auto-negotiation
2211 * time to complete.
2213 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
2214 if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
2215 if (hw->autoneg_failed == 0) {
2216 hw->autoneg_failed = 1;
2217 goto out;
2219 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
2221 /* Disable auto-negotiation in the TXCW register */
2222 ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2224 /* Force link-up and also force full-duplex. */
2225 ctrl = er32(CTRL);
2226 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2227 ew32(CTRL, ctrl);
2229 /* Configure Flow Control after forcing link up. */
2230 ret_val = e1000_config_fc_after_link_up(hw);
2231 if (ret_val) {
2232 DEBUGOUT("Error configuring flow control\n");
2233 goto out;
2235 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2237 * If we are forcing link and we are receiving /C/ ordered
2238 * sets, re-enable auto-negotiation in the TXCW register
2239 * and disable forced link in the Device Control register
2240 * in an attempt to auto-negotiate with our link partner.
2242 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
2243 ew32(TXCW, hw->txcw);
2244 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
2246 hw->serdes_has_link = true;
2247 } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
2249 * If we force link for non-auto-negotiation switch, check
2250 * link status based on MAC synchronization for internal
2251 * serdes media type.
2253 /* SYNCH bit and IV bit are sticky. */
2254 udelay(10);
2255 rxcw = er32(RXCW);
2256 if (rxcw & E1000_RXCW_SYNCH) {
2257 if (!(rxcw & E1000_RXCW_IV)) {
2258 hw->serdes_has_link = true;
2259 DEBUGOUT("SERDES: Link up - forced.\n");
2261 } else {
2262 hw->serdes_has_link = false;
2263 DEBUGOUT("SERDES: Link down - force failed.\n");
2267 if (E1000_TXCW_ANE & er32(TXCW)) {
2268 status = er32(STATUS);
2269 if (status & E1000_STATUS_LU) {
2270 /* SYNCH bit and IV bit are sticky, so reread rxcw. */
2271 udelay(10);
2272 rxcw = er32(RXCW);
2273 if (rxcw & E1000_RXCW_SYNCH) {
2274 if (!(rxcw & E1000_RXCW_IV)) {
2275 hw->serdes_has_link = true;
2276 DEBUGOUT("SERDES: Link up - autoneg "
2277 "completed successfully.\n");
2278 } else {
2279 hw->serdes_has_link = false;
2280 DEBUGOUT("SERDES: Link down - invalid"
2281 "codewords detected in autoneg.\n");
2283 } else {
2284 hw->serdes_has_link = false;
2285 DEBUGOUT("SERDES: Link down - no sync.\n");
2287 } else {
2288 hw->serdes_has_link = false;
2289 DEBUGOUT("SERDES: Link down - autoneg failed\n");
2293 out:
2294 return ret_val;
2298 * e1000_check_for_link
2299 * @hw: Struct containing variables accessed by shared code
2301 * Checks to see if the link status of the hardware has changed.
2302 * Called by any function that needs to check the link status of the adapter.
2304 s32 e1000_check_for_link(struct e1000_hw *hw)
2306 u32 rxcw = 0;
2307 u32 ctrl;
2308 u32 status;
2309 u32 rctl;
2310 u32 icr;
2311 u32 signal = 0;
2312 s32 ret_val;
2313 u16 phy_data;
2315 DEBUGFUNC("e1000_check_for_link");
2317 ctrl = er32(CTRL);
2318 status = er32(STATUS);
2320 /* On adapters with a MAC newer than 82544, SW Definable pin 1 will be
2321 * set when the optics detect a signal. On older adapters, it will be
2322 * cleared when there is a signal. This applies to fiber media only.
2324 if ((hw->media_type == e1000_media_type_fiber) ||
2325 (hw->media_type == e1000_media_type_internal_serdes)) {
2326 rxcw = er32(RXCW);
2328 if (hw->media_type == e1000_media_type_fiber) {
2329 signal =
2330 (hw->mac_type >
2331 e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2332 if (status & E1000_STATUS_LU)
2333 hw->get_link_status = false;
2337 /* If we have a copper PHY then we only want to go out to the PHY
2338 * registers to see if Auto-Neg has completed and/or if our link
2339 * status has changed. The get_link_status flag will be set if we
2340 * receive a Link Status Change interrupt or we have Rx Sequence
2341 * Errors.
2343 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2344 /* First we want to see if the MII Status Register reports
2345 * link. If so, then we want to get the current speed/duplex
2346 * of the PHY.
2347 * Read the register twice since the link bit is sticky.
2349 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2350 if (ret_val)
2351 return ret_val;
2352 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2353 if (ret_val)
2354 return ret_val;
2356 if (phy_data & MII_SR_LINK_STATUS) {
2357 hw->get_link_status = false;
2358 /* Check if there was DownShift, must be checked immediately after
2359 * link-up */
2360 e1000_check_downshift(hw);
2362 /* If we are on 82544 or 82543 silicon and speed/duplex
2363 * are forced to 10H or 10F, then we will implement the polarity
2364 * reversal workaround. We disable interrupts first, and upon
2365 * returning, place the devices interrupt state to its previous
2366 * value except for the link status change interrupt which will
2367 * happen due to the execution of this workaround.
2370 if ((hw->mac_type == e1000_82544
2371 || hw->mac_type == e1000_82543) && (!hw->autoneg)
2372 && (hw->forced_speed_duplex == e1000_10_full
2373 || hw->forced_speed_duplex == e1000_10_half)) {
2374 ew32(IMC, 0xffffffff);
2375 ret_val =
2376 e1000_polarity_reversal_workaround(hw);
2377 icr = er32(ICR);
2378 ew32(ICS, (icr & ~E1000_ICS_LSC));
2379 ew32(IMS, IMS_ENABLE_MASK);
2382 } else {
2383 /* No link detected */
2384 e1000_config_dsp_after_link_change(hw, false);
2385 return 0;
2388 /* If we are forcing speed/duplex, then we simply return since
2389 * we have already determined whether we have link or not.
2391 if (!hw->autoneg)
2392 return -E1000_ERR_CONFIG;
2394 /* optimize the dsp settings for the igp phy */
2395 e1000_config_dsp_after_link_change(hw, true);
2397 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2398 * have Si on board that is 82544 or newer, Auto
2399 * Speed Detection takes care of MAC speed/duplex
2400 * configuration. So we only need to configure Collision
2401 * Distance in the MAC. Otherwise, we need to force
2402 * speed/duplex on the MAC to the current PHY speed/duplex
2403 * settings.
2405 if (hw->mac_type >= e1000_82544)
2406 e1000_config_collision_dist(hw);
2407 else {
2408 ret_val = e1000_config_mac_to_phy(hw);
2409 if (ret_val) {
2410 DEBUGOUT
2411 ("Error configuring MAC to PHY settings\n");
2412 return ret_val;
2416 /* Configure Flow Control now that Auto-Neg has completed. First, we
2417 * need to restore the desired flow control settings because we may
2418 * have had to re-autoneg with a different link partner.
2420 ret_val = e1000_config_fc_after_link_up(hw);
2421 if (ret_val) {
2422 DEBUGOUT("Error configuring flow control\n");
2423 return ret_val;
2426 /* At this point we know that we are on copper and we have
2427 * auto-negotiated link. These are conditions for checking the link
2428 * partner capability register. We use the link speed to determine if
2429 * TBI compatibility needs to be turned on or off. If the link is not
2430 * at gigabit speed, then TBI compatibility is not needed. If we are
2431 * at gigabit speed, we turn on TBI compatibility.
2433 if (hw->tbi_compatibility_en) {
2434 u16 speed, duplex;
2435 ret_val =
2436 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2437 if (ret_val) {
2438 DEBUGOUT
2439 ("Error getting link speed and duplex\n");
2440 return ret_val;
2442 if (speed != SPEED_1000) {
2443 /* If link speed is not set to gigabit speed, we do not need
2444 * to enable TBI compatibility.
2446 if (hw->tbi_compatibility_on) {
2447 /* If we previously were in the mode, turn it off. */
2448 rctl = er32(RCTL);
2449 rctl &= ~E1000_RCTL_SBP;
2450 ew32(RCTL, rctl);
2451 hw->tbi_compatibility_on = false;
2453 } else {
2454 /* If TBI compatibility is was previously off, turn it on. For
2455 * compatibility with a TBI link partner, we will store bad
2456 * packets. Some frames have an additional byte on the end and
2457 * will look like CRC errors to to the hardware.
2459 if (!hw->tbi_compatibility_on) {
2460 hw->tbi_compatibility_on = true;
2461 rctl = er32(RCTL);
2462 rctl |= E1000_RCTL_SBP;
2463 ew32(RCTL, rctl);
2469 if ((hw->media_type == e1000_media_type_fiber) ||
2470 (hw->media_type == e1000_media_type_internal_serdes))
2471 e1000_check_for_serdes_link_generic(hw);
2473 return E1000_SUCCESS;
2477 * e1000_get_speed_and_duplex
2478 * @hw: Struct containing variables accessed by shared code
2479 * @speed: Speed of the connection
2480 * @duplex: Duplex setting of the connection
2482 * Detects the current speed and duplex settings of the hardware.
2484 s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
2486 u32 status;
2487 s32 ret_val;
2488 u16 phy_data;
2490 DEBUGFUNC("e1000_get_speed_and_duplex");
2492 if (hw->mac_type >= e1000_82543) {
2493 status = er32(STATUS);
2494 if (status & E1000_STATUS_SPEED_1000) {
2495 *speed = SPEED_1000;
2496 DEBUGOUT("1000 Mbs, ");
2497 } else if (status & E1000_STATUS_SPEED_100) {
2498 *speed = SPEED_100;
2499 DEBUGOUT("100 Mbs, ");
2500 } else {
2501 *speed = SPEED_10;
2502 DEBUGOUT("10 Mbs, ");
2505 if (status & E1000_STATUS_FD) {
2506 *duplex = FULL_DUPLEX;
2507 DEBUGOUT("Full Duplex\n");
2508 } else {
2509 *duplex = HALF_DUPLEX;
2510 DEBUGOUT(" Half Duplex\n");
2512 } else {
2513 DEBUGOUT("1000 Mbs, Full Duplex\n");
2514 *speed = SPEED_1000;
2515 *duplex = FULL_DUPLEX;
2518 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2519 * if it is operating at half duplex. Here we set the duplex settings to
2520 * match the duplex in the link partner's capabilities.
2522 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2523 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2524 if (ret_val)
2525 return ret_val;
2527 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2528 *duplex = HALF_DUPLEX;
2529 else {
2530 ret_val =
2531 e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2532 if (ret_val)
2533 return ret_val;
2534 if ((*speed == SPEED_100
2535 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
2536 || (*speed == SPEED_10
2537 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2538 *duplex = HALF_DUPLEX;
2542 return E1000_SUCCESS;
2546 * e1000_wait_autoneg
2547 * @hw: Struct containing variables accessed by shared code
2549 * Blocks until autoneg completes or times out (~4.5 seconds)
2551 static s32 e1000_wait_autoneg(struct e1000_hw *hw)
2553 s32 ret_val;
2554 u16 i;
2555 u16 phy_data;
2557 DEBUGFUNC("e1000_wait_autoneg");
2558 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2560 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2561 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2562 /* Read the MII Status Register and wait for Auto-Neg
2563 * Complete bit to be set.
2565 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2566 if (ret_val)
2567 return ret_val;
2568 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2569 if (ret_val)
2570 return ret_val;
2571 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
2572 return E1000_SUCCESS;
2574 msleep(100);
2576 return E1000_SUCCESS;
2580 * e1000_raise_mdi_clk - Raises the Management Data Clock
2581 * @hw: Struct containing variables accessed by shared code
2582 * @ctrl: Device control register's current value
2584 static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
2586 /* Raise the clock input to the Management Data Clock (by setting the MDC
2587 * bit), and then delay 10 microseconds.
2589 ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
2590 E1000_WRITE_FLUSH();
2591 udelay(10);
2595 * e1000_lower_mdi_clk - Lowers the Management Data Clock
2596 * @hw: Struct containing variables accessed by shared code
2597 * @ctrl: Device control register's current value
2599 static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
2601 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2602 * bit), and then delay 10 microseconds.
2604 ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
2605 E1000_WRITE_FLUSH();
2606 udelay(10);
2610 * e1000_shift_out_mdi_bits - Shifts data bits out to the PHY
2611 * @hw: Struct containing variables accessed by shared code
2612 * @data: Data to send out to the PHY
2613 * @count: Number of bits to shift out
2615 * Bits are shifted out in MSB to LSB order.
2617 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count)
2619 u32 ctrl;
2620 u32 mask;
2622 /* We need to shift "count" number of bits out to the PHY. So, the value
2623 * in the "data" parameter will be shifted out to the PHY one bit at a
2624 * time. In order to do this, "data" must be broken down into bits.
2626 mask = 0x01;
2627 mask <<= (count - 1);
2629 ctrl = er32(CTRL);
2631 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2632 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2634 while (mask) {
2635 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2636 * then raising and lowering the Management Data Clock. A "0" is
2637 * shifted out to the PHY by setting the MDIO bit to "0" and then
2638 * raising and lowering the clock.
2640 if (data & mask)
2641 ctrl |= E1000_CTRL_MDIO;
2642 else
2643 ctrl &= ~E1000_CTRL_MDIO;
2645 ew32(CTRL, ctrl);
2646 E1000_WRITE_FLUSH();
2648 udelay(10);
2650 e1000_raise_mdi_clk(hw, &ctrl);
2651 e1000_lower_mdi_clk(hw, &ctrl);
2653 mask = mask >> 1;
2658 * e1000_shift_in_mdi_bits - Shifts data bits in from the PHY
2659 * @hw: Struct containing variables accessed by shared code
2661 * Bits are shifted in in MSB to LSB order.
2663 static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2665 u32 ctrl;
2666 u16 data = 0;
2667 u8 i;
2669 /* In order to read a register from the PHY, we need to shift in a total
2670 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2671 * to avoid contention on the MDIO pin when a read operation is performed.
2672 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2673 * by raising the input to the Management Data Clock (setting the MDC bit),
2674 * and then reading the value of the MDIO bit.
2676 ctrl = er32(CTRL);
2678 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2679 ctrl &= ~E1000_CTRL_MDIO_DIR;
2680 ctrl &= ~E1000_CTRL_MDIO;
2682 ew32(CTRL, ctrl);
2683 E1000_WRITE_FLUSH();
2685 /* Raise and Lower the clock before reading in the data. This accounts for
2686 * the turnaround bits. The first clock occurred when we clocked out the
2687 * last bit of the Register Address.
2689 e1000_raise_mdi_clk(hw, &ctrl);
2690 e1000_lower_mdi_clk(hw, &ctrl);
2692 for (data = 0, i = 0; i < 16; i++) {
2693 data = data << 1;
2694 e1000_raise_mdi_clk(hw, &ctrl);
2695 ctrl = er32(CTRL);
2696 /* Check to see if we shifted in a "1". */
2697 if (ctrl & E1000_CTRL_MDIO)
2698 data |= 1;
2699 e1000_lower_mdi_clk(hw, &ctrl);
2702 e1000_raise_mdi_clk(hw, &ctrl);
2703 e1000_lower_mdi_clk(hw, &ctrl);
2705 return data;
2710 * e1000_read_phy_reg - read a phy register
2711 * @hw: Struct containing variables accessed by shared code
2712 * @reg_addr: address of the PHY register to read
2714 * Reads the value from a PHY register, if the value is on a specific non zero
2715 * page, sets the page first.
2717 s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
2719 u32 ret_val;
2721 DEBUGFUNC("e1000_read_phy_reg");
2723 if ((hw->phy_type == e1000_phy_igp) &&
2724 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2725 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2726 (u16) reg_addr);
2727 if (ret_val)
2728 return ret_val;
2731 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2732 phy_data);
2734 return ret_val;
2737 static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2738 u16 *phy_data)
2740 u32 i;
2741 u32 mdic = 0;
2742 const u32 phy_addr = 1;
2744 DEBUGFUNC("e1000_read_phy_reg_ex");
2746 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2747 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2748 return -E1000_ERR_PARAM;
2751 if (hw->mac_type > e1000_82543) {
2752 /* Set up Op-code, Phy Address, and register address in the MDI
2753 * Control register. The MAC will take care of interfacing with the
2754 * PHY to retrieve the desired data.
2756 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2757 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2758 (E1000_MDIC_OP_READ));
2760 ew32(MDIC, mdic);
2762 /* Poll the ready bit to see if the MDI read completed */
2763 for (i = 0; i < 64; i++) {
2764 udelay(50);
2765 mdic = er32(MDIC);
2766 if (mdic & E1000_MDIC_READY)
2767 break;
2769 if (!(mdic & E1000_MDIC_READY)) {
2770 DEBUGOUT("MDI Read did not complete\n");
2771 return -E1000_ERR_PHY;
2773 if (mdic & E1000_MDIC_ERROR) {
2774 DEBUGOUT("MDI Error\n");
2775 return -E1000_ERR_PHY;
2777 *phy_data = (u16) mdic;
2778 } else {
2779 /* We must first send a preamble through the MDIO pin to signal the
2780 * beginning of an MII instruction. This is done by sending 32
2781 * consecutive "1" bits.
2783 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2785 /* Now combine the next few fields that are required for a read
2786 * operation. We use this method instead of calling the
2787 * e1000_shift_out_mdi_bits routine five different times. The format of
2788 * a MII read instruction consists of a shift out of 14 bits and is
2789 * defined as follows:
2790 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2791 * followed by a shift in of 18 bits. This first two bits shifted in
2792 * are TurnAround bits used to avoid contention on the MDIO pin when a
2793 * READ operation is performed. These two bits are thrown away
2794 * followed by a shift in of 16 bits which contains the desired data.
2796 mdic = ((reg_addr) | (phy_addr << 5) |
2797 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2799 e1000_shift_out_mdi_bits(hw, mdic, 14);
2801 /* Now that we've shifted out the read command to the MII, we need to
2802 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2803 * register address.
2805 *phy_data = e1000_shift_in_mdi_bits(hw);
2807 return E1000_SUCCESS;
2811 * e1000_write_phy_reg - write a phy register
2813 * @hw: Struct containing variables accessed by shared code
2814 * @reg_addr: address of the PHY register to write
2815 * @data: data to write to the PHY
2817 * Writes a value to a PHY register
2819 s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
2821 u32 ret_val;
2823 DEBUGFUNC("e1000_write_phy_reg");
2825 if ((hw->phy_type == e1000_phy_igp) &&
2826 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2827 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2828 (u16) reg_addr);
2829 if (ret_val)
2830 return ret_val;
2833 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2834 phy_data);
2836 return ret_val;
2839 static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2840 u16 phy_data)
2842 u32 i;
2843 u32 mdic = 0;
2844 const u32 phy_addr = 1;
2846 DEBUGFUNC("e1000_write_phy_reg_ex");
2848 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2849 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2850 return -E1000_ERR_PARAM;
2853 if (hw->mac_type > e1000_82543) {
2854 /* Set up Op-code, Phy Address, register address, and data intended
2855 * for the PHY register in the MDI Control register. The MAC will take
2856 * care of interfacing with the PHY to send the desired data.
2858 mdic = (((u32) phy_data) |
2859 (reg_addr << E1000_MDIC_REG_SHIFT) |
2860 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2861 (E1000_MDIC_OP_WRITE));
2863 ew32(MDIC, mdic);
2865 /* Poll the ready bit to see if the MDI read completed */
2866 for (i = 0; i < 641; i++) {
2867 udelay(5);
2868 mdic = er32(MDIC);
2869 if (mdic & E1000_MDIC_READY)
2870 break;
2872 if (!(mdic & E1000_MDIC_READY)) {
2873 DEBUGOUT("MDI Write did not complete\n");
2874 return -E1000_ERR_PHY;
2876 } else {
2877 /* We'll need to use the SW defined pins to shift the write command
2878 * out to the PHY. We first send a preamble to the PHY to signal the
2879 * beginning of the MII instruction. This is done by sending 32
2880 * consecutive "1" bits.
2882 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2884 /* Now combine the remaining required fields that will indicate a
2885 * write operation. We use this method instead of calling the
2886 * e1000_shift_out_mdi_bits routine for each field in the command. The
2887 * format of a MII write instruction is as follows:
2888 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2890 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2891 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2892 mdic <<= 16;
2893 mdic |= (u32) phy_data;
2895 e1000_shift_out_mdi_bits(hw, mdic, 32);
2898 return E1000_SUCCESS;
2902 * e1000_phy_hw_reset - reset the phy, hardware style
2903 * @hw: Struct containing variables accessed by shared code
2905 * Returns the PHY to the power-on reset state
2907 s32 e1000_phy_hw_reset(struct e1000_hw *hw)
2909 u32 ctrl, ctrl_ext;
2910 u32 led_ctrl;
2911 s32 ret_val;
2913 DEBUGFUNC("e1000_phy_hw_reset");
2915 DEBUGOUT("Resetting Phy...\n");
2917 if (hw->mac_type > e1000_82543) {
2918 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2919 * bit. Then, take it out of reset.
2920 * For e1000 hardware, we delay for 10ms between the assert
2921 * and deassert.
2923 ctrl = er32(CTRL);
2924 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2925 E1000_WRITE_FLUSH();
2927 msleep(10);
2929 ew32(CTRL, ctrl);
2930 E1000_WRITE_FLUSH();
2932 } else {
2933 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2934 * bit to put the PHY into reset. Then, take it out of reset.
2936 ctrl_ext = er32(CTRL_EXT);
2937 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2938 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2939 ew32(CTRL_EXT, ctrl_ext);
2940 E1000_WRITE_FLUSH();
2941 msleep(10);
2942 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2943 ew32(CTRL_EXT, ctrl_ext);
2944 E1000_WRITE_FLUSH();
2946 udelay(150);
2948 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2949 /* Configure activity LED after PHY reset */
2950 led_ctrl = er32(LEDCTL);
2951 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2952 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2953 ew32(LEDCTL, led_ctrl);
2956 /* Wait for FW to finish PHY configuration. */
2957 ret_val = e1000_get_phy_cfg_done(hw);
2958 if (ret_val != E1000_SUCCESS)
2959 return ret_val;
2961 return ret_val;
2965 * e1000_phy_reset - reset the phy to commit settings
2966 * @hw: Struct containing variables accessed by shared code
2968 * Resets the PHY
2969 * Sets bit 15 of the MII Control register
2971 s32 e1000_phy_reset(struct e1000_hw *hw)
2973 s32 ret_val;
2974 u16 phy_data;
2976 DEBUGFUNC("e1000_phy_reset");
2978 switch (hw->phy_type) {
2979 case e1000_phy_igp:
2980 ret_val = e1000_phy_hw_reset(hw);
2981 if (ret_val)
2982 return ret_val;
2983 break;
2984 default:
2985 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2986 if (ret_val)
2987 return ret_val;
2989 phy_data |= MII_CR_RESET;
2990 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
2991 if (ret_val)
2992 return ret_val;
2994 udelay(1);
2995 break;
2998 if (hw->phy_type == e1000_phy_igp)
2999 e1000_phy_init_script(hw);
3001 return E1000_SUCCESS;
3005 * e1000_detect_gig_phy - check the phy type
3006 * @hw: Struct containing variables accessed by shared code
3008 * Probes the expected PHY address for known PHY IDs
3010 static s32 e1000_detect_gig_phy(struct e1000_hw *hw)
3012 s32 phy_init_status, ret_val;
3013 u16 phy_id_high, phy_id_low;
3014 bool match = false;
3016 DEBUGFUNC("e1000_detect_gig_phy");
3018 if (hw->phy_id != 0)
3019 return E1000_SUCCESS;
3021 /* Read the PHY ID Registers to identify which PHY is onboard. */
3022 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3023 if (ret_val)
3024 return ret_val;
3026 hw->phy_id = (u32) (phy_id_high << 16);
3027 udelay(20);
3028 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3029 if (ret_val)
3030 return ret_val;
3032 hw->phy_id |= (u32) (phy_id_low & PHY_REVISION_MASK);
3033 hw->phy_revision = (u32) phy_id_low & ~PHY_REVISION_MASK;
3035 switch (hw->mac_type) {
3036 case e1000_82543:
3037 if (hw->phy_id == M88E1000_E_PHY_ID)
3038 match = true;
3039 break;
3040 case e1000_82544:
3041 if (hw->phy_id == M88E1000_I_PHY_ID)
3042 match = true;
3043 break;
3044 case e1000_82540:
3045 case e1000_82545:
3046 case e1000_82545_rev_3:
3047 case e1000_82546:
3048 case e1000_82546_rev_3:
3049 if (hw->phy_id == M88E1011_I_PHY_ID)
3050 match = true;
3051 break;
3052 case e1000_82541:
3053 case e1000_82541_rev_2:
3054 case e1000_82547:
3055 case e1000_82547_rev_2:
3056 if (hw->phy_id == IGP01E1000_I_PHY_ID)
3057 match = true;
3058 break;
3059 default:
3060 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3061 return -E1000_ERR_CONFIG;
3063 phy_init_status = e1000_set_phy_type(hw);
3065 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3066 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3067 return E1000_SUCCESS;
3069 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3070 return -E1000_ERR_PHY;
3074 * e1000_phy_reset_dsp - reset DSP
3075 * @hw: Struct containing variables accessed by shared code
3077 * Resets the PHY's DSP
3079 static s32 e1000_phy_reset_dsp(struct e1000_hw *hw)
3081 s32 ret_val;
3082 DEBUGFUNC("e1000_phy_reset_dsp");
3084 do {
3085 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3086 if (ret_val)
3087 break;
3088 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3089 if (ret_val)
3090 break;
3091 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3092 if (ret_val)
3093 break;
3094 ret_val = E1000_SUCCESS;
3095 } while (0);
3097 return ret_val;
3101 * e1000_phy_igp_get_info - get igp specific registers
3102 * @hw: Struct containing variables accessed by shared code
3103 * @phy_info: PHY information structure
3105 * Get PHY information from various PHY registers for igp PHY only.
3107 static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
3108 struct e1000_phy_info *phy_info)
3110 s32 ret_val;
3111 u16 phy_data, min_length, max_length, average;
3112 e1000_rev_polarity polarity;
3114 DEBUGFUNC("e1000_phy_igp_get_info");
3116 /* The downshift status is checked only once, after link is established,
3117 * and it stored in the hw->speed_downgraded parameter. */
3118 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
3120 /* IGP01E1000 does not need to support it. */
3121 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3123 /* IGP01E1000 always correct polarity reversal */
3124 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3126 /* Check polarity status */
3127 ret_val = e1000_check_polarity(hw, &polarity);
3128 if (ret_val)
3129 return ret_val;
3131 phy_info->cable_polarity = polarity;
3133 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3134 if (ret_val)
3135 return ret_val;
3137 phy_info->mdix_mode =
3138 (e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >>
3139 IGP01E1000_PSSR_MDIX_SHIFT);
3141 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3142 IGP01E1000_PSSR_SPEED_1000MBPS) {
3143 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3144 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3145 if (ret_val)
3146 return ret_val;
3148 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3149 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3150 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3151 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3152 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3153 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3155 /* Get cable length */
3156 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3157 if (ret_val)
3158 return ret_val;
3160 /* Translate to old method */
3161 average = (max_length + min_length) / 2;
3163 if (average <= e1000_igp_cable_length_50)
3164 phy_info->cable_length = e1000_cable_length_50;
3165 else if (average <= e1000_igp_cable_length_80)
3166 phy_info->cable_length = e1000_cable_length_50_80;
3167 else if (average <= e1000_igp_cable_length_110)
3168 phy_info->cable_length = e1000_cable_length_80_110;
3169 else if (average <= e1000_igp_cable_length_140)
3170 phy_info->cable_length = e1000_cable_length_110_140;
3171 else
3172 phy_info->cable_length = e1000_cable_length_140;
3175 return E1000_SUCCESS;
3179 * e1000_phy_m88_get_info - get m88 specific registers
3180 * @hw: Struct containing variables accessed by shared code
3181 * @phy_info: PHY information structure
3183 * Get PHY information from various PHY registers for m88 PHY only.
3185 static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
3186 struct e1000_phy_info *phy_info)
3188 s32 ret_val;
3189 u16 phy_data;
3190 e1000_rev_polarity polarity;
3192 DEBUGFUNC("e1000_phy_m88_get_info");
3194 /* The downshift status is checked only once, after link is established,
3195 * and it stored in the hw->speed_downgraded parameter. */
3196 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
3198 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3199 if (ret_val)
3200 return ret_val;
3202 phy_info->extended_10bt_distance =
3203 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3204 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
3205 e1000_10bt_ext_dist_enable_lower :
3206 e1000_10bt_ext_dist_enable_normal;
3208 phy_info->polarity_correction =
3209 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3210 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
3211 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
3213 /* Check polarity status */
3214 ret_val = e1000_check_polarity(hw, &polarity);
3215 if (ret_val)
3216 return ret_val;
3217 phy_info->cable_polarity = polarity;
3219 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3220 if (ret_val)
3221 return ret_val;
3223 phy_info->mdix_mode =
3224 (e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >>
3225 M88E1000_PSSR_MDIX_SHIFT);
3227 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3228 /* Cable Length Estimation and Local/Remote Receiver Information
3229 * are only valid at 1000 Mbps.
3231 phy_info->cable_length =
3232 (e1000_cable_length) ((phy_data &
3233 M88E1000_PSSR_CABLE_LENGTH) >>
3234 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3236 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3237 if (ret_val)
3238 return ret_val;
3240 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3241 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3242 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3243 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3244 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3245 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3249 return E1000_SUCCESS;
3253 * e1000_phy_get_info - request phy info
3254 * @hw: Struct containing variables accessed by shared code
3255 * @phy_info: PHY information structure
3257 * Get PHY information from various PHY registers
3259 s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info)
3261 s32 ret_val;
3262 u16 phy_data;
3264 DEBUGFUNC("e1000_phy_get_info");
3266 phy_info->cable_length = e1000_cable_length_undefined;
3267 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3268 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3269 phy_info->downshift = e1000_downshift_undefined;
3270 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3271 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3272 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3273 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3275 if (hw->media_type != e1000_media_type_copper) {
3276 DEBUGOUT("PHY info is only valid for copper media\n");
3277 return -E1000_ERR_CONFIG;
3280 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3281 if (ret_val)
3282 return ret_val;
3284 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3285 if (ret_val)
3286 return ret_val;
3288 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3289 DEBUGOUT("PHY info is only valid if link is up\n");
3290 return -E1000_ERR_CONFIG;
3293 if (hw->phy_type == e1000_phy_igp)
3294 return e1000_phy_igp_get_info(hw, phy_info);
3295 else
3296 return e1000_phy_m88_get_info(hw, phy_info);
3299 s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
3301 DEBUGFUNC("e1000_validate_mdi_settings");
3303 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3304 DEBUGOUT("Invalid MDI setting detected\n");
3305 hw->mdix = 1;
3306 return -E1000_ERR_CONFIG;
3308 return E1000_SUCCESS;
3312 * e1000_init_eeprom_params - initialize sw eeprom vars
3313 * @hw: Struct containing variables accessed by shared code
3315 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3316 * is configured.
3318 s32 e1000_init_eeprom_params(struct e1000_hw *hw)
3320 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3321 u32 eecd = er32(EECD);
3322 s32 ret_val = E1000_SUCCESS;
3323 u16 eeprom_size;
3325 DEBUGFUNC("e1000_init_eeprom_params");
3327 switch (hw->mac_type) {
3328 case e1000_82542_rev2_0:
3329 case e1000_82542_rev2_1:
3330 case e1000_82543:
3331 case e1000_82544:
3332 eeprom->type = e1000_eeprom_microwire;
3333 eeprom->word_size = 64;
3334 eeprom->opcode_bits = 3;
3335 eeprom->address_bits = 6;
3336 eeprom->delay_usec = 50;
3337 break;
3338 case e1000_82540:
3339 case e1000_82545:
3340 case e1000_82545_rev_3:
3341 case e1000_82546:
3342 case e1000_82546_rev_3:
3343 eeprom->type = e1000_eeprom_microwire;
3344 eeprom->opcode_bits = 3;
3345 eeprom->delay_usec = 50;
3346 if (eecd & E1000_EECD_SIZE) {
3347 eeprom->word_size = 256;
3348 eeprom->address_bits = 8;
3349 } else {
3350 eeprom->word_size = 64;
3351 eeprom->address_bits = 6;
3353 break;
3354 case e1000_82541:
3355 case e1000_82541_rev_2:
3356 case e1000_82547:
3357 case e1000_82547_rev_2:
3358 if (eecd & E1000_EECD_TYPE) {
3359 eeprom->type = e1000_eeprom_spi;
3360 eeprom->opcode_bits = 8;
3361 eeprom->delay_usec = 1;
3362 if (eecd & E1000_EECD_ADDR_BITS) {
3363 eeprom->page_size = 32;
3364 eeprom->address_bits = 16;
3365 } else {
3366 eeprom->page_size = 8;
3367 eeprom->address_bits = 8;
3369 } else {
3370 eeprom->type = e1000_eeprom_microwire;
3371 eeprom->opcode_bits = 3;
3372 eeprom->delay_usec = 50;
3373 if (eecd & E1000_EECD_ADDR_BITS) {
3374 eeprom->word_size = 256;
3375 eeprom->address_bits = 8;
3376 } else {
3377 eeprom->word_size = 64;
3378 eeprom->address_bits = 6;
3381 break;
3382 default:
3383 break;
3386 if (eeprom->type == e1000_eeprom_spi) {
3387 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
3388 * 32KB (incremented by powers of 2).
3390 /* Set to default value for initial eeprom read. */
3391 eeprom->word_size = 64;
3392 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3393 if (ret_val)
3394 return ret_val;
3395 eeprom_size =
3396 (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3397 /* 256B eeprom size was not supported in earlier hardware, so we
3398 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
3399 * is never the result used in the shifting logic below. */
3400 if (eeprom_size)
3401 eeprom_size++;
3403 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
3405 return ret_val;
3409 * e1000_raise_ee_clk - Raises the EEPROM's clock input.
3410 * @hw: Struct containing variables accessed by shared code
3411 * @eecd: EECD's current value
3413 static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd)
3415 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3416 * wait <delay> microseconds.
3418 *eecd = *eecd | E1000_EECD_SK;
3419 ew32(EECD, *eecd);
3420 E1000_WRITE_FLUSH();
3421 udelay(hw->eeprom.delay_usec);
3425 * e1000_lower_ee_clk - Lowers the EEPROM's clock input.
3426 * @hw: Struct containing variables accessed by shared code
3427 * @eecd: EECD's current value
3429 static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd)
3431 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3432 * wait 50 microseconds.
3434 *eecd = *eecd & ~E1000_EECD_SK;
3435 ew32(EECD, *eecd);
3436 E1000_WRITE_FLUSH();
3437 udelay(hw->eeprom.delay_usec);
3441 * e1000_shift_out_ee_bits - Shift data bits out to the EEPROM.
3442 * @hw: Struct containing variables accessed by shared code
3443 * @data: data to send to the EEPROM
3444 * @count: number of bits to shift out
3446 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count)
3448 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3449 u32 eecd;
3450 u32 mask;
3452 /* We need to shift "count" bits out to the EEPROM. So, value in the
3453 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3454 * In order to do this, "data" must be broken down into bits.
3456 mask = 0x01 << (count - 1);
3457 eecd = er32(EECD);
3458 if (eeprom->type == e1000_eeprom_microwire) {
3459 eecd &= ~E1000_EECD_DO;
3460 } else if (eeprom->type == e1000_eeprom_spi) {
3461 eecd |= E1000_EECD_DO;
3463 do {
3464 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3465 * and then raising and then lowering the clock (the SK bit controls
3466 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3467 * by setting "DI" to "0" and then raising and then lowering the clock.
3469 eecd &= ~E1000_EECD_DI;
3471 if (data & mask)
3472 eecd |= E1000_EECD_DI;
3474 ew32(EECD, eecd);
3475 E1000_WRITE_FLUSH();
3477 udelay(eeprom->delay_usec);
3479 e1000_raise_ee_clk(hw, &eecd);
3480 e1000_lower_ee_clk(hw, &eecd);
3482 mask = mask >> 1;
3484 } while (mask);
3486 /* We leave the "DI" bit set to "0" when we leave this routine. */
3487 eecd &= ~E1000_EECD_DI;
3488 ew32(EECD, eecd);
3492 * e1000_shift_in_ee_bits - Shift data bits in from the EEPROM
3493 * @hw: Struct containing variables accessed by shared code
3494 * @count: number of bits to shift in
3496 static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count)
3498 u32 eecd;
3499 u32 i;
3500 u16 data;
3502 /* In order to read a register from the EEPROM, we need to shift 'count'
3503 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3504 * input to the EEPROM (setting the SK bit), and then reading the value of
3505 * the "DO" bit. During this "shifting in" process the "DI" bit should
3506 * always be clear.
3509 eecd = er32(EECD);
3511 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3512 data = 0;
3514 for (i = 0; i < count; i++) {
3515 data = data << 1;
3516 e1000_raise_ee_clk(hw, &eecd);
3518 eecd = er32(EECD);
3520 eecd &= ~(E1000_EECD_DI);
3521 if (eecd & E1000_EECD_DO)
3522 data |= 1;
3524 e1000_lower_ee_clk(hw, &eecd);
3527 return data;
3531 * e1000_acquire_eeprom - Prepares EEPROM for access
3532 * @hw: Struct containing variables accessed by shared code
3534 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3535 * function should be called before issuing a command to the EEPROM.
3537 static s32 e1000_acquire_eeprom(struct e1000_hw *hw)
3539 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3540 u32 eecd, i = 0;
3542 DEBUGFUNC("e1000_acquire_eeprom");
3544 eecd = er32(EECD);
3546 /* Request EEPROM Access */
3547 if (hw->mac_type > e1000_82544) {
3548 eecd |= E1000_EECD_REQ;
3549 ew32(EECD, eecd);
3550 eecd = er32(EECD);
3551 while ((!(eecd & E1000_EECD_GNT)) &&
3552 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3553 i++;
3554 udelay(5);
3555 eecd = er32(EECD);
3557 if (!(eecd & E1000_EECD_GNT)) {
3558 eecd &= ~E1000_EECD_REQ;
3559 ew32(EECD, eecd);
3560 DEBUGOUT("Could not acquire EEPROM grant\n");
3561 return -E1000_ERR_EEPROM;
3565 /* Setup EEPROM for Read/Write */
3567 if (eeprom->type == e1000_eeprom_microwire) {
3568 /* Clear SK and DI */
3569 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3570 ew32(EECD, eecd);
3572 /* Set CS */
3573 eecd |= E1000_EECD_CS;
3574 ew32(EECD, eecd);
3575 } else if (eeprom->type == e1000_eeprom_spi) {
3576 /* Clear SK and CS */
3577 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3578 ew32(EECD, eecd);
3579 udelay(1);
3582 return E1000_SUCCESS;
3586 * e1000_standby_eeprom - Returns EEPROM to a "standby" state
3587 * @hw: Struct containing variables accessed by shared code
3589 static void e1000_standby_eeprom(struct e1000_hw *hw)
3591 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3592 u32 eecd;
3594 eecd = er32(EECD);
3596 if (eeprom->type == e1000_eeprom_microwire) {
3597 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3598 ew32(EECD, eecd);
3599 E1000_WRITE_FLUSH();
3600 udelay(eeprom->delay_usec);
3602 /* Clock high */
3603 eecd |= E1000_EECD_SK;
3604 ew32(EECD, eecd);
3605 E1000_WRITE_FLUSH();
3606 udelay(eeprom->delay_usec);
3608 /* Select EEPROM */
3609 eecd |= E1000_EECD_CS;
3610 ew32(EECD, eecd);
3611 E1000_WRITE_FLUSH();
3612 udelay(eeprom->delay_usec);
3614 /* Clock low */
3615 eecd &= ~E1000_EECD_SK;
3616 ew32(EECD, eecd);
3617 E1000_WRITE_FLUSH();
3618 udelay(eeprom->delay_usec);
3619 } else if (eeprom->type == e1000_eeprom_spi) {
3620 /* Toggle CS to flush commands */
3621 eecd |= E1000_EECD_CS;
3622 ew32(EECD, eecd);
3623 E1000_WRITE_FLUSH();
3624 udelay(eeprom->delay_usec);
3625 eecd &= ~E1000_EECD_CS;
3626 ew32(EECD, eecd);
3627 E1000_WRITE_FLUSH();
3628 udelay(eeprom->delay_usec);
3633 * e1000_release_eeprom - drop chip select
3634 * @hw: Struct containing variables accessed by shared code
3636 * Terminates a command by inverting the EEPROM's chip select pin
3638 static void e1000_release_eeprom(struct e1000_hw *hw)
3640 u32 eecd;
3642 DEBUGFUNC("e1000_release_eeprom");
3644 eecd = er32(EECD);
3646 if (hw->eeprom.type == e1000_eeprom_spi) {
3647 eecd |= E1000_EECD_CS; /* Pull CS high */
3648 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3650 ew32(EECD, eecd);
3652 udelay(hw->eeprom.delay_usec);
3653 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
3654 /* cleanup eeprom */
3656 /* CS on Microwire is active-high */
3657 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3659 ew32(EECD, eecd);
3661 /* Rising edge of clock */
3662 eecd |= E1000_EECD_SK;
3663 ew32(EECD, eecd);
3664 E1000_WRITE_FLUSH();
3665 udelay(hw->eeprom.delay_usec);
3667 /* Falling edge of clock */
3668 eecd &= ~E1000_EECD_SK;
3669 ew32(EECD, eecd);
3670 E1000_WRITE_FLUSH();
3671 udelay(hw->eeprom.delay_usec);
3674 /* Stop requesting EEPROM access */
3675 if (hw->mac_type > e1000_82544) {
3676 eecd &= ~E1000_EECD_REQ;
3677 ew32(EECD, eecd);
3682 * e1000_spi_eeprom_ready - Reads a 16 bit word from the EEPROM.
3683 * @hw: Struct containing variables accessed by shared code
3685 static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw)
3687 u16 retry_count = 0;
3688 u8 spi_stat_reg;
3690 DEBUGFUNC("e1000_spi_eeprom_ready");
3692 /* Read "Status Register" repeatedly until the LSB is cleared. The
3693 * EEPROM will signal that the command has been completed by clearing
3694 * bit 0 of the internal status register. If it's not cleared within
3695 * 5 milliseconds, then error out.
3697 retry_count = 0;
3698 do {
3699 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3700 hw->eeprom.opcode_bits);
3701 spi_stat_reg = (u8) e1000_shift_in_ee_bits(hw, 8);
3702 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3703 break;
3705 udelay(5);
3706 retry_count += 5;
3708 e1000_standby_eeprom(hw);
3709 } while (retry_count < EEPROM_MAX_RETRY_SPI);
3711 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3712 * only 0-5mSec on 5V devices)
3714 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
3715 DEBUGOUT("SPI EEPROM Status error\n");
3716 return -E1000_ERR_EEPROM;
3719 return E1000_SUCCESS;
3723 * e1000_read_eeprom - Reads a 16 bit word from the EEPROM.
3724 * @hw: Struct containing variables accessed by shared code
3725 * @offset: offset of word in the EEPROM to read
3726 * @data: word read from the EEPROM
3727 * @words: number of words to read
3729 s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3731 s32 ret;
3732 spin_lock(&e1000_eeprom_lock);
3733 ret = e1000_do_read_eeprom(hw, offset, words, data);
3734 spin_unlock(&e1000_eeprom_lock);
3735 return ret;
3738 static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
3739 u16 *data)
3741 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3742 u32 i = 0;
3744 DEBUGFUNC("e1000_read_eeprom");
3746 /* If eeprom is not yet detected, do so now */
3747 if (eeprom->word_size == 0)
3748 e1000_init_eeprom_params(hw);
3750 /* A check for invalid values: offset too large, too many words, and not
3751 * enough words.
3753 if ((offset >= eeprom->word_size)
3754 || (words > eeprom->word_size - offset) || (words == 0)) {
3755 DEBUGOUT2
3756 ("\"words\" parameter out of bounds. Words = %d, size = %d\n",
3757 offset, eeprom->word_size);
3758 return -E1000_ERR_EEPROM;
3761 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
3762 * directly. In this case, we need to acquire the EEPROM so that
3763 * FW or other port software does not interrupt.
3765 /* Prepare the EEPROM for bit-bang reading */
3766 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3767 return -E1000_ERR_EEPROM;
3769 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
3770 * acquired the EEPROM at this point, so any returns should release it */
3771 if (eeprom->type == e1000_eeprom_spi) {
3772 u16 word_in;
3773 u8 read_opcode = EEPROM_READ_OPCODE_SPI;
3775 if (e1000_spi_eeprom_ready(hw)) {
3776 e1000_release_eeprom(hw);
3777 return -E1000_ERR_EEPROM;
3780 e1000_standby_eeprom(hw);
3782 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3783 if ((eeprom->address_bits == 8) && (offset >= 128))
3784 read_opcode |= EEPROM_A8_OPCODE_SPI;
3786 /* Send the READ command (opcode + addr) */
3787 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3788 e1000_shift_out_ee_bits(hw, (u16) (offset * 2),
3789 eeprom->address_bits);
3791 /* Read the data. The address of the eeprom internally increments with
3792 * each byte (spi) being read, saving on the overhead of eeprom setup
3793 * and tear-down. The address counter will roll over if reading beyond
3794 * the size of the eeprom, thus allowing the entire memory to be read
3795 * starting from any offset. */
3796 for (i = 0; i < words; i++) {
3797 word_in = e1000_shift_in_ee_bits(hw, 16);
3798 data[i] = (word_in >> 8) | (word_in << 8);
3800 } else if (eeprom->type == e1000_eeprom_microwire) {
3801 for (i = 0; i < words; i++) {
3802 /* Send the READ command (opcode + addr) */
3803 e1000_shift_out_ee_bits(hw,
3804 EEPROM_READ_OPCODE_MICROWIRE,
3805 eeprom->opcode_bits);
3806 e1000_shift_out_ee_bits(hw, (u16) (offset + i),
3807 eeprom->address_bits);
3809 /* Read the data. For microwire, each word requires the overhead
3810 * of eeprom setup and tear-down. */
3811 data[i] = e1000_shift_in_ee_bits(hw, 16);
3812 e1000_standby_eeprom(hw);
3816 /* End this read operation */
3817 e1000_release_eeprom(hw);
3819 return E1000_SUCCESS;
3823 * e1000_validate_eeprom_checksum - Verifies that the EEPROM has a valid checksum
3824 * @hw: Struct containing variables accessed by shared code
3826 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3827 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3828 * valid.
3830 s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
3832 u16 checksum = 0;
3833 u16 i, eeprom_data;
3835 DEBUGFUNC("e1000_validate_eeprom_checksum");
3837 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3838 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3839 DEBUGOUT("EEPROM Read Error\n");
3840 return -E1000_ERR_EEPROM;
3842 checksum += eeprom_data;
3845 #ifdef CONFIG_PARISC
3846 /* This is a signature and not a checksum on HP c8000 */
3847 if ((hw->subsystem_vendor_id == 0x103C) && (eeprom_data == 0x16d6))
3848 return E1000_SUCCESS;
3850 #endif
3851 if (checksum == (u16) EEPROM_SUM)
3852 return E1000_SUCCESS;
3853 else {
3854 DEBUGOUT("EEPROM Checksum Invalid\n");
3855 return -E1000_ERR_EEPROM;
3860 * e1000_update_eeprom_checksum - Calculates/writes the EEPROM checksum
3861 * @hw: Struct containing variables accessed by shared code
3863 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
3864 * Writes the difference to word offset 63 of the EEPROM.
3866 s32 e1000_update_eeprom_checksum(struct e1000_hw *hw)
3868 u16 checksum = 0;
3869 u16 i, eeprom_data;
3871 DEBUGFUNC("e1000_update_eeprom_checksum");
3873 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
3874 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3875 DEBUGOUT("EEPROM Read Error\n");
3876 return -E1000_ERR_EEPROM;
3878 checksum += eeprom_data;
3880 checksum = (u16) EEPROM_SUM - checksum;
3881 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
3882 DEBUGOUT("EEPROM Write Error\n");
3883 return -E1000_ERR_EEPROM;
3885 return E1000_SUCCESS;
3889 * e1000_write_eeprom - write words to the different EEPROM types.
3890 * @hw: Struct containing variables accessed by shared code
3891 * @offset: offset within the EEPROM to be written to
3892 * @words: number of words to write
3893 * @data: 16 bit word to be written to the EEPROM
3895 * If e1000_update_eeprom_checksum is not called after this function, the
3896 * EEPROM will most likely contain an invalid checksum.
3898 s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3900 s32 ret;
3901 spin_lock(&e1000_eeprom_lock);
3902 ret = e1000_do_write_eeprom(hw, offset, words, data);
3903 spin_unlock(&e1000_eeprom_lock);
3904 return ret;
3907 static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
3908 u16 *data)
3910 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3911 s32 status = 0;
3913 DEBUGFUNC("e1000_write_eeprom");
3915 /* If eeprom is not yet detected, do so now */
3916 if (eeprom->word_size == 0)
3917 e1000_init_eeprom_params(hw);
3919 /* A check for invalid values: offset too large, too many words, and not
3920 * enough words.
3922 if ((offset >= eeprom->word_size)
3923 || (words > eeprom->word_size - offset) || (words == 0)) {
3924 DEBUGOUT("\"words\" parameter out of bounds\n");
3925 return -E1000_ERR_EEPROM;
3928 /* Prepare the EEPROM for writing */
3929 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3930 return -E1000_ERR_EEPROM;
3932 if (eeprom->type == e1000_eeprom_microwire) {
3933 status = e1000_write_eeprom_microwire(hw, offset, words, data);
3934 } else {
3935 status = e1000_write_eeprom_spi(hw, offset, words, data);
3936 msleep(10);
3939 /* Done with writing */
3940 e1000_release_eeprom(hw);
3942 return status;
3946 * e1000_write_eeprom_spi - Writes a 16 bit word to a given offset in an SPI EEPROM.
3947 * @hw: Struct containing variables accessed by shared code
3948 * @offset: offset within the EEPROM to be written to
3949 * @words: number of words to write
3950 * @data: pointer to array of 8 bit words to be written to the EEPROM
3952 static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words,
3953 u16 *data)
3955 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3956 u16 widx = 0;
3958 DEBUGFUNC("e1000_write_eeprom_spi");
3960 while (widx < words) {
3961 u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
3963 if (e1000_spi_eeprom_ready(hw))
3964 return -E1000_ERR_EEPROM;
3966 e1000_standby_eeprom(hw);
3968 /* Send the WRITE ENABLE command (8 bit opcode ) */
3969 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
3970 eeprom->opcode_bits);
3972 e1000_standby_eeprom(hw);
3974 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3975 if ((eeprom->address_bits == 8) && (offset >= 128))
3976 write_opcode |= EEPROM_A8_OPCODE_SPI;
3978 /* Send the Write command (8-bit opcode + addr) */
3979 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
3981 e1000_shift_out_ee_bits(hw, (u16) ((offset + widx) * 2),
3982 eeprom->address_bits);
3984 /* Send the data */
3986 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
3987 while (widx < words) {
3988 u16 word_out = data[widx];
3989 word_out = (word_out >> 8) | (word_out << 8);
3990 e1000_shift_out_ee_bits(hw, word_out, 16);
3991 widx++;
3993 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
3994 * operation, while the smaller eeproms are capable of an 8-byte
3995 * PAGE WRITE operation. Break the inner loop to pass new address
3997 if ((((offset + widx) * 2) % eeprom->page_size) == 0) {
3998 e1000_standby_eeprom(hw);
3999 break;
4004 return E1000_SUCCESS;
4008 * e1000_write_eeprom_microwire - Writes a 16 bit word to a given offset in a Microwire EEPROM.
4009 * @hw: Struct containing variables accessed by shared code
4010 * @offset: offset within the EEPROM to be written to
4011 * @words: number of words to write
4012 * @data: pointer to array of 8 bit words to be written to the EEPROM
4014 static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
4015 u16 words, u16 *data)
4017 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4018 u32 eecd;
4019 u16 words_written = 0;
4020 u16 i = 0;
4022 DEBUGFUNC("e1000_write_eeprom_microwire");
4024 /* Send the write enable command to the EEPROM (3-bit opcode plus
4025 * 6/8-bit dummy address beginning with 11). It's less work to include
4026 * the 11 of the dummy address as part of the opcode than it is to shift
4027 * it over the correct number of bits for the address. This puts the
4028 * EEPROM into write/erase mode.
4030 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4031 (u16) (eeprom->opcode_bits + 2));
4033 e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
4035 /* Prepare the EEPROM */
4036 e1000_standby_eeprom(hw);
4038 while (words_written < words) {
4039 /* Send the Write command (3-bit opcode + addr) */
4040 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4041 eeprom->opcode_bits);
4043 e1000_shift_out_ee_bits(hw, (u16) (offset + words_written),
4044 eeprom->address_bits);
4046 /* Send the data */
4047 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4049 /* Toggle the CS line. This in effect tells the EEPROM to execute
4050 * the previous command.
4052 e1000_standby_eeprom(hw);
4054 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4055 * signal that the command has been completed by raising the DO signal.
4056 * If DO does not go high in 10 milliseconds, then error out.
4058 for (i = 0; i < 200; i++) {
4059 eecd = er32(EECD);
4060 if (eecd & E1000_EECD_DO)
4061 break;
4062 udelay(50);
4064 if (i == 200) {
4065 DEBUGOUT("EEPROM Write did not complete\n");
4066 return -E1000_ERR_EEPROM;
4069 /* Recover from write */
4070 e1000_standby_eeprom(hw);
4072 words_written++;
4075 /* Send the write disable command to the EEPROM (3-bit opcode plus
4076 * 6/8-bit dummy address beginning with 10). It's less work to include
4077 * the 10 of the dummy address as part of the opcode than it is to shift
4078 * it over the correct number of bits for the address. This takes the
4079 * EEPROM out of write/erase mode.
4081 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4082 (u16) (eeprom->opcode_bits + 2));
4084 e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
4086 return E1000_SUCCESS;
4090 * e1000_read_mac_addr - read the adapters MAC from eeprom
4091 * @hw: Struct containing variables accessed by shared code
4093 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4094 * second function of dual function devices
4096 s32 e1000_read_mac_addr(struct e1000_hw *hw)
4098 u16 offset;
4099 u16 eeprom_data, i;
4101 DEBUGFUNC("e1000_read_mac_addr");
4103 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
4104 offset = i >> 1;
4105 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
4106 DEBUGOUT("EEPROM Read Error\n");
4107 return -E1000_ERR_EEPROM;
4109 hw->perm_mac_addr[i] = (u8) (eeprom_data & 0x00FF);
4110 hw->perm_mac_addr[i + 1] = (u8) (eeprom_data >> 8);
4113 switch (hw->mac_type) {
4114 default:
4115 break;
4116 case e1000_82546:
4117 case e1000_82546_rev_3:
4118 if (er32(STATUS) & E1000_STATUS_FUNC_1)
4119 hw->perm_mac_addr[5] ^= 0x01;
4120 break;
4123 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
4124 hw->mac_addr[i] = hw->perm_mac_addr[i];
4125 return E1000_SUCCESS;
4129 * e1000_init_rx_addrs - Initializes receive address filters.
4130 * @hw: Struct containing variables accessed by shared code
4132 * Places the MAC address in receive address register 0 and clears the rest
4133 * of the receive address registers. Clears the multicast table. Assumes
4134 * the receiver is in reset when the routine is called.
4136 static void e1000_init_rx_addrs(struct e1000_hw *hw)
4138 u32 i;
4139 u32 rar_num;
4141 DEBUGFUNC("e1000_init_rx_addrs");
4143 /* Setup the receive address. */
4144 DEBUGOUT("Programming MAC Address into RAR[0]\n");
4146 e1000_rar_set(hw, hw->mac_addr, 0);
4148 rar_num = E1000_RAR_ENTRIES;
4150 /* Zero out the other 15 receive addresses. */
4151 DEBUGOUT("Clearing RAR[1-15]\n");
4152 for (i = 1; i < rar_num; i++) {
4153 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4154 E1000_WRITE_FLUSH();
4155 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4156 E1000_WRITE_FLUSH();
4161 * e1000_hash_mc_addr - Hashes an address to determine its location in the multicast table
4162 * @hw: Struct containing variables accessed by shared code
4163 * @mc_addr: the multicast address to hash
4165 u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
4167 u32 hash_value = 0;
4169 /* The portion of the address that is used for the hash table is
4170 * determined by the mc_filter_type setting.
4172 switch (hw->mc_filter_type) {
4173 /* [0] [1] [2] [3] [4] [5]
4174 * 01 AA 00 12 34 56
4175 * LSB MSB
4177 case 0:
4178 /* [47:36] i.e. 0x563 for above example address */
4179 hash_value = ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4));
4180 break;
4181 case 1:
4182 /* [46:35] i.e. 0xAC6 for above example address */
4183 hash_value = ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5));
4184 break;
4185 case 2:
4186 /* [45:34] i.e. 0x5D8 for above example address */
4187 hash_value = ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6));
4188 break;
4189 case 3:
4190 /* [43:32] i.e. 0x634 for above example address */
4191 hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8));
4192 break;
4195 hash_value &= 0xFFF;
4196 return hash_value;
4200 * e1000_rar_set - Puts an ethernet address into a receive address register.
4201 * @hw: Struct containing variables accessed by shared code
4202 * @addr: Address to put into receive address register
4203 * @index: Receive address register to write
4205 void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
4207 u32 rar_low, rar_high;
4209 /* HW expects these in little endian so we reverse the byte order
4210 * from network order (big endian) to little endian
4212 rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
4213 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
4214 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
4216 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
4217 * unit hang.
4219 * Description:
4220 * If there are any Rx frames queued up or otherwise present in the HW
4221 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
4222 * hang. To work around this issue, we have to disable receives and
4223 * flush out all Rx frames before we enable RSS. To do so, we modify we
4224 * redirect all Rx traffic to manageability and then reset the HW.
4225 * This flushes away Rx frames, and (since the redirections to
4226 * manageability persists across resets) keeps new ones from coming in
4227 * while we work. Then, we clear the Address Valid AV bit for all MAC
4228 * addresses and undo the re-direction to manageability.
4229 * Now, frames are coming in again, but the MAC won't accept them, so
4230 * far so good. We now proceed to initialize RSS (if necessary) and
4231 * configure the Rx unit. Last, we re-enable the AV bits and continue
4232 * on our merry way.
4234 switch (hw->mac_type) {
4235 default:
4236 /* Indicate to hardware the Address is Valid. */
4237 rar_high |= E1000_RAH_AV;
4238 break;
4241 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4242 E1000_WRITE_FLUSH();
4243 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4244 E1000_WRITE_FLUSH();
4248 * e1000_write_vfta - Writes a value to the specified offset in the VLAN filter table.
4249 * @hw: Struct containing variables accessed by shared code
4250 * @offset: Offset in VLAN filer table to write
4251 * @value: Value to write into VLAN filter table
4253 void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
4255 u32 temp;
4257 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4258 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4259 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4260 E1000_WRITE_FLUSH();
4261 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4262 E1000_WRITE_FLUSH();
4263 } else {
4264 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4265 E1000_WRITE_FLUSH();
4270 * e1000_clear_vfta - Clears the VLAN filer table
4271 * @hw: Struct containing variables accessed by shared code
4273 static void e1000_clear_vfta(struct e1000_hw *hw)
4275 u32 offset;
4276 u32 vfta_value = 0;
4277 u32 vfta_offset = 0;
4278 u32 vfta_bit_in_reg = 0;
4280 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4281 /* If the offset we want to clear is the same offset of the
4282 * manageability VLAN ID, then clear all bits except that of the
4283 * manageability unit */
4284 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4285 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
4286 E1000_WRITE_FLUSH();
4290 static s32 e1000_id_led_init(struct e1000_hw *hw)
4292 u32 ledctl;
4293 const u32 ledctl_mask = 0x000000FF;
4294 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4295 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4296 u16 eeprom_data, i, temp;
4297 const u16 led_mask = 0x0F;
4299 DEBUGFUNC("e1000_id_led_init");
4301 if (hw->mac_type < e1000_82540) {
4302 /* Nothing to do */
4303 return E1000_SUCCESS;
4306 ledctl = er32(LEDCTL);
4307 hw->ledctl_default = ledctl;
4308 hw->ledctl_mode1 = hw->ledctl_default;
4309 hw->ledctl_mode2 = hw->ledctl_default;
4311 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4312 DEBUGOUT("EEPROM Read Error\n");
4313 return -E1000_ERR_EEPROM;
4316 if ((eeprom_data == ID_LED_RESERVED_0000) ||
4317 (eeprom_data == ID_LED_RESERVED_FFFF)) {
4318 eeprom_data = ID_LED_DEFAULT;
4321 for (i = 0; i < 4; i++) {
4322 temp = (eeprom_data >> (i << 2)) & led_mask;
4323 switch (temp) {
4324 case ID_LED_ON1_DEF2:
4325 case ID_LED_ON1_ON2:
4326 case ID_LED_ON1_OFF2:
4327 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4328 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4329 break;
4330 case ID_LED_OFF1_DEF2:
4331 case ID_LED_OFF1_ON2:
4332 case ID_LED_OFF1_OFF2:
4333 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4334 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4335 break;
4336 default:
4337 /* Do nothing */
4338 break;
4340 switch (temp) {
4341 case ID_LED_DEF1_ON2:
4342 case ID_LED_ON1_ON2:
4343 case ID_LED_OFF1_ON2:
4344 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4345 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4346 break;
4347 case ID_LED_DEF1_OFF2:
4348 case ID_LED_ON1_OFF2:
4349 case ID_LED_OFF1_OFF2:
4350 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4351 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4352 break;
4353 default:
4354 /* Do nothing */
4355 break;
4358 return E1000_SUCCESS;
4362 * e1000_setup_led
4363 * @hw: Struct containing variables accessed by shared code
4365 * Prepares SW controlable LED for use and saves the current state of the LED.
4367 s32 e1000_setup_led(struct e1000_hw *hw)
4369 u32 ledctl;
4370 s32 ret_val = E1000_SUCCESS;
4372 DEBUGFUNC("e1000_setup_led");
4374 switch (hw->mac_type) {
4375 case e1000_82542_rev2_0:
4376 case e1000_82542_rev2_1:
4377 case e1000_82543:
4378 case e1000_82544:
4379 /* No setup necessary */
4380 break;
4381 case e1000_82541:
4382 case e1000_82547:
4383 case e1000_82541_rev_2:
4384 case e1000_82547_rev_2:
4385 /* Turn off PHY Smart Power Down (if enabled) */
4386 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4387 &hw->phy_spd_default);
4388 if (ret_val)
4389 return ret_val;
4390 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4391 (u16) (hw->phy_spd_default &
4392 ~IGP01E1000_GMII_SPD));
4393 if (ret_val)
4394 return ret_val;
4395 /* Fall Through */
4396 default:
4397 if (hw->media_type == e1000_media_type_fiber) {
4398 ledctl = er32(LEDCTL);
4399 /* Save current LEDCTL settings */
4400 hw->ledctl_default = ledctl;
4401 /* Turn off LED0 */
4402 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4403 E1000_LEDCTL_LED0_BLINK |
4404 E1000_LEDCTL_LED0_MODE_MASK);
4405 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4406 E1000_LEDCTL_LED0_MODE_SHIFT);
4407 ew32(LEDCTL, ledctl);
4408 } else if (hw->media_type == e1000_media_type_copper)
4409 ew32(LEDCTL, hw->ledctl_mode1);
4410 break;
4413 return E1000_SUCCESS;
4417 * e1000_cleanup_led - Restores the saved state of the SW controlable LED.
4418 * @hw: Struct containing variables accessed by shared code
4420 s32 e1000_cleanup_led(struct e1000_hw *hw)
4422 s32 ret_val = E1000_SUCCESS;
4424 DEBUGFUNC("e1000_cleanup_led");
4426 switch (hw->mac_type) {
4427 case e1000_82542_rev2_0:
4428 case e1000_82542_rev2_1:
4429 case e1000_82543:
4430 case e1000_82544:
4431 /* No cleanup necessary */
4432 break;
4433 case e1000_82541:
4434 case e1000_82547:
4435 case e1000_82541_rev_2:
4436 case e1000_82547_rev_2:
4437 /* Turn on PHY Smart Power Down (if previously enabled) */
4438 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4439 hw->phy_spd_default);
4440 if (ret_val)
4441 return ret_val;
4442 /* Fall Through */
4443 default:
4444 /* Restore LEDCTL settings */
4445 ew32(LEDCTL, hw->ledctl_default);
4446 break;
4449 return E1000_SUCCESS;
4453 * e1000_led_on - Turns on the software controllable LED
4454 * @hw: Struct containing variables accessed by shared code
4456 s32 e1000_led_on(struct e1000_hw *hw)
4458 u32 ctrl = er32(CTRL);
4460 DEBUGFUNC("e1000_led_on");
4462 switch (hw->mac_type) {
4463 case e1000_82542_rev2_0:
4464 case e1000_82542_rev2_1:
4465 case e1000_82543:
4466 /* Set SW Defineable Pin 0 to turn on the LED */
4467 ctrl |= E1000_CTRL_SWDPIN0;
4468 ctrl |= E1000_CTRL_SWDPIO0;
4469 break;
4470 case e1000_82544:
4471 if (hw->media_type == e1000_media_type_fiber) {
4472 /* Set SW Defineable Pin 0 to turn on the LED */
4473 ctrl |= E1000_CTRL_SWDPIN0;
4474 ctrl |= E1000_CTRL_SWDPIO0;
4475 } else {
4476 /* Clear SW Defineable Pin 0 to turn on the LED */
4477 ctrl &= ~E1000_CTRL_SWDPIN0;
4478 ctrl |= E1000_CTRL_SWDPIO0;
4480 break;
4481 default:
4482 if (hw->media_type == e1000_media_type_fiber) {
4483 /* Clear SW Defineable Pin 0 to turn on the LED */
4484 ctrl &= ~E1000_CTRL_SWDPIN0;
4485 ctrl |= E1000_CTRL_SWDPIO0;
4486 } else if (hw->media_type == e1000_media_type_copper) {
4487 ew32(LEDCTL, hw->ledctl_mode2);
4488 return E1000_SUCCESS;
4490 break;
4493 ew32(CTRL, ctrl);
4495 return E1000_SUCCESS;
4499 * e1000_led_off - Turns off the software controllable LED
4500 * @hw: Struct containing variables accessed by shared code
4502 s32 e1000_led_off(struct e1000_hw *hw)
4504 u32 ctrl = er32(CTRL);
4506 DEBUGFUNC("e1000_led_off");
4508 switch (hw->mac_type) {
4509 case e1000_82542_rev2_0:
4510 case e1000_82542_rev2_1:
4511 case e1000_82543:
4512 /* Clear SW Defineable Pin 0 to turn off the LED */
4513 ctrl &= ~E1000_CTRL_SWDPIN0;
4514 ctrl |= E1000_CTRL_SWDPIO0;
4515 break;
4516 case e1000_82544:
4517 if (hw->media_type == e1000_media_type_fiber) {
4518 /* Clear SW Defineable Pin 0 to turn off the LED */
4519 ctrl &= ~E1000_CTRL_SWDPIN0;
4520 ctrl |= E1000_CTRL_SWDPIO0;
4521 } else {
4522 /* Set SW Defineable Pin 0 to turn off the LED */
4523 ctrl |= E1000_CTRL_SWDPIN0;
4524 ctrl |= E1000_CTRL_SWDPIO0;
4526 break;
4527 default:
4528 if (hw->media_type == e1000_media_type_fiber) {
4529 /* Set SW Defineable Pin 0 to turn off the LED */
4530 ctrl |= E1000_CTRL_SWDPIN0;
4531 ctrl |= E1000_CTRL_SWDPIO0;
4532 } else if (hw->media_type == e1000_media_type_copper) {
4533 ew32(LEDCTL, hw->ledctl_mode1);
4534 return E1000_SUCCESS;
4536 break;
4539 ew32(CTRL, ctrl);
4541 return E1000_SUCCESS;
4545 * e1000_clear_hw_cntrs - Clears all hardware statistics counters.
4546 * @hw: Struct containing variables accessed by shared code
4548 static void e1000_clear_hw_cntrs(struct e1000_hw *hw)
4550 volatile u32 temp;
4552 temp = er32(CRCERRS);
4553 temp = er32(SYMERRS);
4554 temp = er32(MPC);
4555 temp = er32(SCC);
4556 temp = er32(ECOL);
4557 temp = er32(MCC);
4558 temp = er32(LATECOL);
4559 temp = er32(COLC);
4560 temp = er32(DC);
4561 temp = er32(SEC);
4562 temp = er32(RLEC);
4563 temp = er32(XONRXC);
4564 temp = er32(XONTXC);
4565 temp = er32(XOFFRXC);
4566 temp = er32(XOFFTXC);
4567 temp = er32(FCRUC);
4569 temp = er32(PRC64);
4570 temp = er32(PRC127);
4571 temp = er32(PRC255);
4572 temp = er32(PRC511);
4573 temp = er32(PRC1023);
4574 temp = er32(PRC1522);
4576 temp = er32(GPRC);
4577 temp = er32(BPRC);
4578 temp = er32(MPRC);
4579 temp = er32(GPTC);
4580 temp = er32(GORCL);
4581 temp = er32(GORCH);
4582 temp = er32(GOTCL);
4583 temp = er32(GOTCH);
4584 temp = er32(RNBC);
4585 temp = er32(RUC);
4586 temp = er32(RFC);
4587 temp = er32(ROC);
4588 temp = er32(RJC);
4589 temp = er32(TORL);
4590 temp = er32(TORH);
4591 temp = er32(TOTL);
4592 temp = er32(TOTH);
4593 temp = er32(TPR);
4594 temp = er32(TPT);
4596 temp = er32(PTC64);
4597 temp = er32(PTC127);
4598 temp = er32(PTC255);
4599 temp = er32(PTC511);
4600 temp = er32(PTC1023);
4601 temp = er32(PTC1522);
4603 temp = er32(MPTC);
4604 temp = er32(BPTC);
4606 if (hw->mac_type < e1000_82543)
4607 return;
4609 temp = er32(ALGNERRC);
4610 temp = er32(RXERRC);
4611 temp = er32(TNCRS);
4612 temp = er32(CEXTERR);
4613 temp = er32(TSCTC);
4614 temp = er32(TSCTFC);
4616 if (hw->mac_type <= e1000_82544)
4617 return;
4619 temp = er32(MGTPRC);
4620 temp = er32(MGTPDC);
4621 temp = er32(MGTPTC);
4625 * e1000_reset_adaptive - Resets Adaptive IFS to its default state.
4626 * @hw: Struct containing variables accessed by shared code
4628 * Call this after e1000_init_hw. You may override the IFS defaults by setting
4629 * hw->ifs_params_forced to true. However, you must initialize hw->
4630 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4631 * before calling this function.
4633 void e1000_reset_adaptive(struct e1000_hw *hw)
4635 DEBUGFUNC("e1000_reset_adaptive");
4637 if (hw->adaptive_ifs) {
4638 if (!hw->ifs_params_forced) {
4639 hw->current_ifs_val = 0;
4640 hw->ifs_min_val = IFS_MIN;
4641 hw->ifs_max_val = IFS_MAX;
4642 hw->ifs_step_size = IFS_STEP;
4643 hw->ifs_ratio = IFS_RATIO;
4645 hw->in_ifs_mode = false;
4646 ew32(AIT, 0);
4647 } else {
4648 DEBUGOUT("Not in Adaptive IFS mode!\n");
4653 * e1000_update_adaptive - update adaptive IFS
4654 * @hw: Struct containing variables accessed by shared code
4655 * @tx_packets: Number of transmits since last callback
4656 * @total_collisions: Number of collisions since last callback
4658 * Called during the callback/watchdog routine to update IFS value based on
4659 * the ratio of transmits to collisions.
4661 void e1000_update_adaptive(struct e1000_hw *hw)
4663 DEBUGFUNC("e1000_update_adaptive");
4665 if (hw->adaptive_ifs) {
4666 if ((hw->collision_delta *hw->ifs_ratio) > hw->tx_packet_delta) {
4667 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
4668 hw->in_ifs_mode = true;
4669 if (hw->current_ifs_val < hw->ifs_max_val) {
4670 if (hw->current_ifs_val == 0)
4671 hw->current_ifs_val =
4672 hw->ifs_min_val;
4673 else
4674 hw->current_ifs_val +=
4675 hw->ifs_step_size;
4676 ew32(AIT, hw->current_ifs_val);
4679 } else {
4680 if (hw->in_ifs_mode
4681 && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
4682 hw->current_ifs_val = 0;
4683 hw->in_ifs_mode = false;
4684 ew32(AIT, 0);
4687 } else {
4688 DEBUGOUT("Not in Adaptive IFS mode!\n");
4693 * e1000_tbi_adjust_stats
4694 * @hw: Struct containing variables accessed by shared code
4695 * @frame_len: The length of the frame in question
4696 * @mac_addr: The Ethernet destination address of the frame in question
4698 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4700 void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats,
4701 u32 frame_len, u8 *mac_addr)
4703 u64 carry_bit;
4705 /* First adjust the frame length. */
4706 frame_len--;
4707 /* We need to adjust the statistics counters, since the hardware
4708 * counters overcount this packet as a CRC error and undercount
4709 * the packet as a good packet
4711 /* This packet should not be counted as a CRC error. */
4712 stats->crcerrs--;
4713 /* This packet does count as a Good Packet Received. */
4714 stats->gprc++;
4716 /* Adjust the Good Octets received counters */
4717 carry_bit = 0x80000000 & stats->gorcl;
4718 stats->gorcl += frame_len;
4719 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4720 * Received Count) was one before the addition,
4721 * AND it is zero after, then we lost the carry out,
4722 * need to add one to Gorch (Good Octets Received Count High).
4723 * This could be simplified if all environments supported
4724 * 64-bit integers.
4726 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
4727 stats->gorch++;
4728 /* Is this a broadcast or multicast? Check broadcast first,
4729 * since the test for a multicast frame will test positive on
4730 * a broadcast frame.
4732 if ((mac_addr[0] == (u8) 0xff) && (mac_addr[1] == (u8) 0xff))
4733 /* Broadcast packet */
4734 stats->bprc++;
4735 else if (*mac_addr & 0x01)
4736 /* Multicast packet */
4737 stats->mprc++;
4739 if (frame_len == hw->max_frame_size) {
4740 /* In this case, the hardware has overcounted the number of
4741 * oversize frames.
4743 if (stats->roc > 0)
4744 stats->roc--;
4747 /* Adjust the bin counters when the extra byte put the frame in the
4748 * wrong bin. Remember that the frame_len was adjusted above.
4750 if (frame_len == 64) {
4751 stats->prc64++;
4752 stats->prc127--;
4753 } else if (frame_len == 127) {
4754 stats->prc127++;
4755 stats->prc255--;
4756 } else if (frame_len == 255) {
4757 stats->prc255++;
4758 stats->prc511--;
4759 } else if (frame_len == 511) {
4760 stats->prc511++;
4761 stats->prc1023--;
4762 } else if (frame_len == 1023) {
4763 stats->prc1023++;
4764 stats->prc1522--;
4765 } else if (frame_len == 1522) {
4766 stats->prc1522++;
4771 * e1000_get_bus_info
4772 * @hw: Struct containing variables accessed by shared code
4774 * Gets the current PCI bus type, speed, and width of the hardware
4776 void e1000_get_bus_info(struct e1000_hw *hw)
4778 u32 status;
4780 switch (hw->mac_type) {
4781 case e1000_82542_rev2_0:
4782 case e1000_82542_rev2_1:
4783 hw->bus_type = e1000_bus_type_pci;
4784 hw->bus_speed = e1000_bus_speed_unknown;
4785 hw->bus_width = e1000_bus_width_unknown;
4786 break;
4787 default:
4788 status = er32(STATUS);
4789 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4790 e1000_bus_type_pcix : e1000_bus_type_pci;
4792 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
4793 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4794 e1000_bus_speed_66 : e1000_bus_speed_120;
4795 } else if (hw->bus_type == e1000_bus_type_pci) {
4796 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4797 e1000_bus_speed_66 : e1000_bus_speed_33;
4798 } else {
4799 switch (status & E1000_STATUS_PCIX_SPEED) {
4800 case E1000_STATUS_PCIX_SPEED_66:
4801 hw->bus_speed = e1000_bus_speed_66;
4802 break;
4803 case E1000_STATUS_PCIX_SPEED_100:
4804 hw->bus_speed = e1000_bus_speed_100;
4805 break;
4806 case E1000_STATUS_PCIX_SPEED_133:
4807 hw->bus_speed = e1000_bus_speed_133;
4808 break;
4809 default:
4810 hw->bus_speed = e1000_bus_speed_reserved;
4811 break;
4814 hw->bus_width = (status & E1000_STATUS_BUS64) ?
4815 e1000_bus_width_64 : e1000_bus_width_32;
4816 break;
4821 * e1000_write_reg_io
4822 * @hw: Struct containing variables accessed by shared code
4823 * @offset: offset to write to
4824 * @value: value to write
4826 * Writes a value to one of the devices registers using port I/O (as opposed to
4827 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4829 static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value)
4831 unsigned long io_addr = hw->io_base;
4832 unsigned long io_data = hw->io_base + 4;
4834 e1000_io_write(hw, io_addr, offset);
4835 e1000_io_write(hw, io_data, value);
4839 * e1000_get_cable_length - Estimates the cable length.
4840 * @hw: Struct containing variables accessed by shared code
4841 * @min_length: The estimated minimum length
4842 * @max_length: The estimated maximum length
4844 * returns: - E1000_ERR_XXX
4845 * E1000_SUCCESS
4847 * This function always returns a ranged length (minimum & maximum).
4848 * So for M88 phy's, this function interprets the one value returned from the
4849 * register to the minimum and maximum range.
4850 * For IGP phy's, the function calculates the range by the AGC registers.
4852 static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
4853 u16 *max_length)
4855 s32 ret_val;
4856 u16 agc_value = 0;
4857 u16 i, phy_data;
4858 u16 cable_length;
4860 DEBUGFUNC("e1000_get_cable_length");
4862 *min_length = *max_length = 0;
4864 /* Use old method for Phy older than IGP */
4865 if (hw->phy_type == e1000_phy_m88) {
4867 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4868 &phy_data);
4869 if (ret_val)
4870 return ret_val;
4871 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4872 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
4874 /* Convert the enum value to ranged values */
4875 switch (cable_length) {
4876 case e1000_cable_length_50:
4877 *min_length = 0;
4878 *max_length = e1000_igp_cable_length_50;
4879 break;
4880 case e1000_cable_length_50_80:
4881 *min_length = e1000_igp_cable_length_50;
4882 *max_length = e1000_igp_cable_length_80;
4883 break;
4884 case e1000_cable_length_80_110:
4885 *min_length = e1000_igp_cable_length_80;
4886 *max_length = e1000_igp_cable_length_110;
4887 break;
4888 case e1000_cable_length_110_140:
4889 *min_length = e1000_igp_cable_length_110;
4890 *max_length = e1000_igp_cable_length_140;
4891 break;
4892 case e1000_cable_length_140:
4893 *min_length = e1000_igp_cable_length_140;
4894 *max_length = e1000_igp_cable_length_170;
4895 break;
4896 default:
4897 return -E1000_ERR_PHY;
4898 break;
4900 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
4901 u16 cur_agc_value;
4902 u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
4903 u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
4904 { IGP01E1000_PHY_AGC_A,
4905 IGP01E1000_PHY_AGC_B,
4906 IGP01E1000_PHY_AGC_C,
4907 IGP01E1000_PHY_AGC_D
4909 /* Read the AGC registers for all channels */
4910 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4912 ret_val =
4913 e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
4914 if (ret_val)
4915 return ret_val;
4917 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
4919 /* Value bound check. */
4920 if ((cur_agc_value >=
4921 IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1)
4922 || (cur_agc_value == 0))
4923 return -E1000_ERR_PHY;
4925 agc_value += cur_agc_value;
4927 /* Update minimal AGC value. */
4928 if (min_agc_value > cur_agc_value)
4929 min_agc_value = cur_agc_value;
4932 /* Remove the minimal AGC result for length < 50m */
4933 if (agc_value <
4934 IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
4935 agc_value -= min_agc_value;
4937 /* Get the average length of the remaining 3 channels */
4938 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
4939 } else {
4940 /* Get the average length of all the 4 channels. */
4941 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
4944 /* Set the range of the calculated length. */
4945 *min_length = ((e1000_igp_cable_length_table[agc_value] -
4946 IGP01E1000_AGC_RANGE) > 0) ?
4947 (e1000_igp_cable_length_table[agc_value] -
4948 IGP01E1000_AGC_RANGE) : 0;
4949 *max_length = e1000_igp_cable_length_table[agc_value] +
4950 IGP01E1000_AGC_RANGE;
4953 return E1000_SUCCESS;
4957 * e1000_check_polarity - Check the cable polarity
4958 * @hw: Struct containing variables accessed by shared code
4959 * @polarity: output parameter : 0 - Polarity is not reversed
4960 * 1 - Polarity is reversed.
4962 * returns: - E1000_ERR_XXX
4963 * E1000_SUCCESS
4965 * For phy's older than IGP, this function simply reads the polarity bit in the
4966 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
4967 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
4968 * return 0. If the link speed is 1000 Mbps the polarity status is in the
4969 * IGP01E1000_PHY_PCS_INIT_REG.
4971 static s32 e1000_check_polarity(struct e1000_hw *hw,
4972 e1000_rev_polarity *polarity)
4974 s32 ret_val;
4975 u16 phy_data;
4977 DEBUGFUNC("e1000_check_polarity");
4979 if (hw->phy_type == e1000_phy_m88) {
4980 /* return the Polarity bit in the Status register. */
4981 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4982 &phy_data);
4983 if (ret_val)
4984 return ret_val;
4985 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
4986 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
4987 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
4989 } else if (hw->phy_type == e1000_phy_igp) {
4990 /* Read the Status register to check the speed */
4991 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
4992 &phy_data);
4993 if (ret_val)
4994 return ret_val;
4996 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
4997 * find the polarity status */
4998 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
4999 IGP01E1000_PSSR_SPEED_1000MBPS) {
5001 /* Read the GIG initialization PCS register (0x00B4) */
5002 ret_val =
5003 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
5004 &phy_data);
5005 if (ret_val)
5006 return ret_val;
5008 /* Check the polarity bits */
5009 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
5010 e1000_rev_polarity_reversed :
5011 e1000_rev_polarity_normal;
5012 } else {
5013 /* For 10 Mbps, read the polarity bit in the status register. (for
5014 * 100 Mbps this bit is always 0) */
5015 *polarity =
5016 (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
5017 e1000_rev_polarity_reversed :
5018 e1000_rev_polarity_normal;
5021 return E1000_SUCCESS;
5025 * e1000_check_downshift - Check if Downshift occurred
5026 * @hw: Struct containing variables accessed by shared code
5027 * @downshift: output parameter : 0 - No Downshift occurred.
5028 * 1 - Downshift occurred.
5030 * returns: - E1000_ERR_XXX
5031 * E1000_SUCCESS
5033 * For phy's older than IGP, this function reads the Downshift bit in the Phy
5034 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5035 * Link Health register. In IGP this bit is latched high, so the driver must
5036 * read it immediately after link is established.
5038 static s32 e1000_check_downshift(struct e1000_hw *hw)
5040 s32 ret_val;
5041 u16 phy_data;
5043 DEBUGFUNC("e1000_check_downshift");
5045 if (hw->phy_type == e1000_phy_igp) {
5046 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5047 &phy_data);
5048 if (ret_val)
5049 return ret_val;
5051 hw->speed_downgraded =
5052 (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
5053 } else if (hw->phy_type == e1000_phy_m88) {
5054 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5055 &phy_data);
5056 if (ret_val)
5057 return ret_val;
5059 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5060 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5063 return E1000_SUCCESS;
5067 * e1000_config_dsp_after_link_change
5068 * @hw: Struct containing variables accessed by shared code
5069 * @link_up: was link up at the time this was called
5071 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5072 * E1000_SUCCESS at any other case.
5074 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5075 * gigabit link is achieved to improve link quality.
5078 static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up)
5080 s32 ret_val;
5081 u16 phy_data, phy_saved_data, speed, duplex, i;
5082 u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5083 { IGP01E1000_PHY_AGC_PARAM_A,
5084 IGP01E1000_PHY_AGC_PARAM_B,
5085 IGP01E1000_PHY_AGC_PARAM_C,
5086 IGP01E1000_PHY_AGC_PARAM_D
5088 u16 min_length, max_length;
5090 DEBUGFUNC("e1000_config_dsp_after_link_change");
5092 if (hw->phy_type != e1000_phy_igp)
5093 return E1000_SUCCESS;
5095 if (link_up) {
5096 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
5097 if (ret_val) {
5098 DEBUGOUT("Error getting link speed and duplex\n");
5099 return ret_val;
5102 if (speed == SPEED_1000) {
5104 ret_val =
5105 e1000_get_cable_length(hw, &min_length,
5106 &max_length);
5107 if (ret_val)
5108 return ret_val;
5110 if ((hw->dsp_config_state == e1000_dsp_config_enabled)
5111 && min_length >= e1000_igp_cable_length_50) {
5113 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5114 ret_val =
5115 e1000_read_phy_reg(hw,
5116 dsp_reg_array[i],
5117 &phy_data);
5118 if (ret_val)
5119 return ret_val;
5121 phy_data &=
5122 ~IGP01E1000_PHY_EDAC_MU_INDEX;
5124 ret_val =
5125 e1000_write_phy_reg(hw,
5126 dsp_reg_array
5127 [i], phy_data);
5128 if (ret_val)
5129 return ret_val;
5131 hw->dsp_config_state =
5132 e1000_dsp_config_activated;
5135 if ((hw->ffe_config_state == e1000_ffe_config_enabled)
5136 && (min_length < e1000_igp_cable_length_50)) {
5138 u16 ffe_idle_err_timeout =
5139 FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5140 u32 idle_errs = 0;
5142 /* clear previous idle error counts */
5143 ret_val =
5144 e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5145 &phy_data);
5146 if (ret_val)
5147 return ret_val;
5149 for (i = 0; i < ffe_idle_err_timeout; i++) {
5150 udelay(1000);
5151 ret_val =
5152 e1000_read_phy_reg(hw,
5153 PHY_1000T_STATUS,
5154 &phy_data);
5155 if (ret_val)
5156 return ret_val;
5158 idle_errs +=
5159 (phy_data &
5160 SR_1000T_IDLE_ERROR_CNT);
5161 if (idle_errs >
5162 SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT)
5164 hw->ffe_config_state =
5165 e1000_ffe_config_active;
5167 ret_val =
5168 e1000_write_phy_reg(hw,
5169 IGP01E1000_PHY_DSP_FFE,
5170 IGP01E1000_PHY_DSP_FFE_CM_CP);
5171 if (ret_val)
5172 return ret_val;
5173 break;
5176 if (idle_errs)
5177 ffe_idle_err_timeout =
5178 FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5182 } else {
5183 if (hw->dsp_config_state == e1000_dsp_config_activated) {
5184 /* Save off the current value of register 0x2F5B to be restored at
5185 * the end of the routines. */
5186 ret_val =
5187 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5189 if (ret_val)
5190 return ret_val;
5192 /* Disable the PHY transmitter */
5193 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5195 if (ret_val)
5196 return ret_val;
5198 mdelay(20);
5200 ret_val = e1000_write_phy_reg(hw, 0x0000,
5201 IGP01E1000_IEEE_FORCE_GIGA);
5202 if (ret_val)
5203 return ret_val;
5204 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5205 ret_val =
5206 e1000_read_phy_reg(hw, dsp_reg_array[i],
5207 &phy_data);
5208 if (ret_val)
5209 return ret_val;
5211 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5212 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
5214 ret_val =
5215 e1000_write_phy_reg(hw, dsp_reg_array[i],
5216 phy_data);
5217 if (ret_val)
5218 return ret_val;
5221 ret_val = e1000_write_phy_reg(hw, 0x0000,
5222 IGP01E1000_IEEE_RESTART_AUTONEG);
5223 if (ret_val)
5224 return ret_val;
5226 mdelay(20);
5228 /* Now enable the transmitter */
5229 ret_val =
5230 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5232 if (ret_val)
5233 return ret_val;
5235 hw->dsp_config_state = e1000_dsp_config_enabled;
5238 if (hw->ffe_config_state == e1000_ffe_config_active) {
5239 /* Save off the current value of register 0x2F5B to be restored at
5240 * the end of the routines. */
5241 ret_val =
5242 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5244 if (ret_val)
5245 return ret_val;
5247 /* Disable the PHY transmitter */
5248 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5250 if (ret_val)
5251 return ret_val;
5253 mdelay(20);
5255 ret_val = e1000_write_phy_reg(hw, 0x0000,
5256 IGP01E1000_IEEE_FORCE_GIGA);
5257 if (ret_val)
5258 return ret_val;
5259 ret_val =
5260 e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5261 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5262 if (ret_val)
5263 return ret_val;
5265 ret_val = e1000_write_phy_reg(hw, 0x0000,
5266 IGP01E1000_IEEE_RESTART_AUTONEG);
5267 if (ret_val)
5268 return ret_val;
5270 mdelay(20);
5272 /* Now enable the transmitter */
5273 ret_val =
5274 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5276 if (ret_val)
5277 return ret_val;
5279 hw->ffe_config_state = e1000_ffe_config_enabled;
5282 return E1000_SUCCESS;
5286 * e1000_set_phy_mode - Set PHY to class A mode
5287 * @hw: Struct containing variables accessed by shared code
5289 * Assumes the following operations will follow to enable the new class mode.
5290 * 1. Do a PHY soft reset
5291 * 2. Restart auto-negotiation or force link.
5293 static s32 e1000_set_phy_mode(struct e1000_hw *hw)
5295 s32 ret_val;
5296 u16 eeprom_data;
5298 DEBUGFUNC("e1000_set_phy_mode");
5300 if ((hw->mac_type == e1000_82545_rev_3) &&
5301 (hw->media_type == e1000_media_type_copper)) {
5302 ret_val =
5303 e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1,
5304 &eeprom_data);
5305 if (ret_val) {
5306 return ret_val;
5309 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
5310 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5311 ret_val =
5312 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT,
5313 0x000B);
5314 if (ret_val)
5315 return ret_val;
5316 ret_val =
5317 e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL,
5318 0x8104);
5319 if (ret_val)
5320 return ret_val;
5322 hw->phy_reset_disable = false;
5326 return E1000_SUCCESS;
5330 * e1000_set_d3_lplu_state - set d3 link power state
5331 * @hw: Struct containing variables accessed by shared code
5332 * @active: true to enable lplu false to disable lplu.
5334 * This function sets the lplu state according to the active flag. When
5335 * activating lplu this function also disables smart speed and vise versa.
5336 * lplu will not be activated unless the device autonegotiation advertisement
5337 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5339 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5340 * E1000_SUCCESS at any other case.
5342 static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
5344 s32 ret_val;
5345 u16 phy_data;
5346 DEBUGFUNC("e1000_set_d3_lplu_state");
5348 if (hw->phy_type != e1000_phy_igp)
5349 return E1000_SUCCESS;
5351 /* During driver activity LPLU should not be used or it will attain link
5352 * from the lowest speeds starting from 10Mbps. The capability is used for
5353 * Dx transitions and states */
5354 if (hw->mac_type == e1000_82541_rev_2
5355 || hw->mac_type == e1000_82547_rev_2) {
5356 ret_val =
5357 e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5358 if (ret_val)
5359 return ret_val;
5362 if (!active) {
5363 if (hw->mac_type == e1000_82541_rev_2 ||
5364 hw->mac_type == e1000_82547_rev_2) {
5365 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5366 ret_val =
5367 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5368 phy_data);
5369 if (ret_val)
5370 return ret_val;
5373 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5374 * Dx states where the power conservation is most important. During
5375 * driver activity we should enable SmartSpeed, so performance is
5376 * maintained. */
5377 if (hw->smart_speed == e1000_smart_speed_on) {
5378 ret_val =
5379 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5380 &phy_data);
5381 if (ret_val)
5382 return ret_val;
5384 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5385 ret_val =
5386 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5387 phy_data);
5388 if (ret_val)
5389 return ret_val;
5390 } else if (hw->smart_speed == e1000_smart_speed_off) {
5391 ret_val =
5392 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5393 &phy_data);
5394 if (ret_val)
5395 return ret_val;
5397 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5398 ret_val =
5399 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5400 phy_data);
5401 if (ret_val)
5402 return ret_val;
5404 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
5405 || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL)
5406 || (hw->autoneg_advertised ==
5407 AUTONEG_ADVERTISE_10_100_ALL)) {
5409 if (hw->mac_type == e1000_82541_rev_2 ||
5410 hw->mac_type == e1000_82547_rev_2) {
5411 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5412 ret_val =
5413 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5414 phy_data);
5415 if (ret_val)
5416 return ret_val;
5419 /* When LPLU is enabled we should disable SmartSpeed */
5420 ret_val =
5421 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5422 &phy_data);
5423 if (ret_val)
5424 return ret_val;
5426 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5427 ret_val =
5428 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5429 phy_data);
5430 if (ret_val)
5431 return ret_val;
5434 return E1000_SUCCESS;
5438 * e1000_set_vco_speed
5439 * @hw: Struct containing variables accessed by shared code
5441 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5443 static s32 e1000_set_vco_speed(struct e1000_hw *hw)
5445 s32 ret_val;
5446 u16 default_page = 0;
5447 u16 phy_data;
5449 DEBUGFUNC("e1000_set_vco_speed");
5451 switch (hw->mac_type) {
5452 case e1000_82545_rev_3:
5453 case e1000_82546_rev_3:
5454 break;
5455 default:
5456 return E1000_SUCCESS;
5459 /* Set PHY register 30, page 5, bit 8 to 0 */
5461 ret_val =
5462 e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5463 if (ret_val)
5464 return ret_val;
5466 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5467 if (ret_val)
5468 return ret_val;
5470 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5471 if (ret_val)
5472 return ret_val;
5474 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5475 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5476 if (ret_val)
5477 return ret_val;
5479 /* Set PHY register 30, page 4, bit 11 to 1 */
5481 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5482 if (ret_val)
5483 return ret_val;
5485 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5486 if (ret_val)
5487 return ret_val;
5489 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5490 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5491 if (ret_val)
5492 return ret_val;
5494 ret_val =
5495 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5496 if (ret_val)
5497 return ret_val;
5499 return E1000_SUCCESS;
5504 * e1000_enable_mng_pass_thru - check for bmc pass through
5505 * @hw: Struct containing variables accessed by shared code
5507 * Verifies the hardware needs to allow ARPs to be processed by the host
5508 * returns: - true/false
5510 u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
5512 u32 manc;
5514 if (hw->asf_firmware_present) {
5515 manc = er32(MANC);
5517 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
5518 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
5519 return false;
5520 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
5521 return true;
5523 return false;
5526 static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
5528 s32 ret_val;
5529 u16 mii_status_reg;
5530 u16 i;
5532 /* Polarity reversal workaround for forced 10F/10H links. */
5534 /* Disable the transmitter on the PHY */
5536 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5537 if (ret_val)
5538 return ret_val;
5539 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
5540 if (ret_val)
5541 return ret_val;
5543 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5544 if (ret_val)
5545 return ret_val;
5547 /* This loop will early-out if the NO link condition has been met. */
5548 for (i = PHY_FORCE_TIME; i > 0; i--) {
5549 /* Read the MII Status Register and wait for Link Status bit
5550 * to be clear.
5553 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5554 if (ret_val)
5555 return ret_val;
5557 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5558 if (ret_val)
5559 return ret_val;
5561 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0)
5562 break;
5563 mdelay(100);
5566 /* Recommended delay time after link has been lost */
5567 mdelay(1000);
5569 /* Now we will re-enable th transmitter on the PHY */
5571 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5572 if (ret_val)
5573 return ret_val;
5574 mdelay(50);
5575 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
5576 if (ret_val)
5577 return ret_val;
5578 mdelay(50);
5579 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
5580 if (ret_val)
5581 return ret_val;
5582 mdelay(50);
5583 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
5584 if (ret_val)
5585 return ret_val;
5587 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5588 if (ret_val)
5589 return ret_val;
5591 /* This loop will early-out if the link condition has been met. */
5592 for (i = PHY_FORCE_TIME; i > 0; i--) {
5593 /* Read the MII Status Register and wait for Link Status bit
5594 * to be set.
5597 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5598 if (ret_val)
5599 return ret_val;
5601 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5602 if (ret_val)
5603 return ret_val;
5605 if (mii_status_reg & MII_SR_LINK_STATUS)
5606 break;
5607 mdelay(100);
5609 return E1000_SUCCESS;
5613 * e1000_get_auto_rd_done
5614 * @hw: Struct containing variables accessed by shared code
5616 * Check for EEPROM Auto Read bit done.
5617 * returns: - E1000_ERR_RESET if fail to reset MAC
5618 * E1000_SUCCESS at any other case.
5620 static s32 e1000_get_auto_rd_done(struct e1000_hw *hw)
5622 DEBUGFUNC("e1000_get_auto_rd_done");
5623 msleep(5);
5624 return E1000_SUCCESS;
5628 * e1000_get_phy_cfg_done
5629 * @hw: Struct containing variables accessed by shared code
5631 * Checks if the PHY configuration is done
5632 * returns: - E1000_ERR_RESET if fail to reset MAC
5633 * E1000_SUCCESS at any other case.
5635 static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
5637 DEBUGFUNC("e1000_get_phy_cfg_done");
5638 mdelay(10);
5639 return E1000_SUCCESS;