1 /*******************************************************************************
4 Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 * Shared functions for accessing and configuring the MAC
35 static int32_t e1000_set_phy_type(struct e1000_hw
*hw
);
36 static void e1000_phy_init_script(struct e1000_hw
*hw
);
37 static int32_t e1000_setup_copper_link(struct e1000_hw
*hw
);
38 static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw
*hw
);
39 static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw
*hw
);
40 static int32_t e1000_phy_force_speed_duplex(struct e1000_hw
*hw
);
41 static int32_t e1000_config_mac_to_phy(struct e1000_hw
*hw
);
42 static void e1000_raise_mdi_clk(struct e1000_hw
*hw
, uint32_t *ctrl
);
43 static void e1000_lower_mdi_clk(struct e1000_hw
*hw
, uint32_t *ctrl
);
44 static void e1000_shift_out_mdi_bits(struct e1000_hw
*hw
, uint32_t data
,
46 static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw
*hw
);
47 static int32_t e1000_phy_reset_dsp(struct e1000_hw
*hw
);
48 static int32_t e1000_write_eeprom_spi(struct e1000_hw
*hw
, uint16_t offset
,
49 uint16_t words
, uint16_t *data
);
50 static int32_t e1000_write_eeprom_microwire(struct e1000_hw
*hw
,
51 uint16_t offset
, uint16_t words
,
53 static int32_t e1000_spi_eeprom_ready(struct e1000_hw
*hw
);
54 static void e1000_raise_ee_clk(struct e1000_hw
*hw
, uint32_t *eecd
);
55 static void e1000_lower_ee_clk(struct e1000_hw
*hw
, uint32_t *eecd
);
56 static void e1000_shift_out_ee_bits(struct e1000_hw
*hw
, uint16_t data
,
58 static int32_t e1000_write_phy_reg_ex(struct e1000_hw
*hw
, uint32_t reg_addr
,
60 static int32_t e1000_read_phy_reg_ex(struct e1000_hw
*hw
,uint32_t reg_addr
,
62 static uint16_t e1000_shift_in_ee_bits(struct e1000_hw
*hw
, uint16_t count
);
63 static int32_t e1000_acquire_eeprom(struct e1000_hw
*hw
);
64 static void e1000_release_eeprom(struct e1000_hw
*hw
);
65 static void e1000_standby_eeprom(struct e1000_hw
*hw
);
66 static int32_t e1000_id_led_init(struct e1000_hw
* hw
);
67 static int32_t e1000_set_vco_speed(struct e1000_hw
*hw
);
68 static int32_t e1000_polarity_reversal_workaround(struct e1000_hw
*hw
);
69 static int32_t e1000_set_phy_mode(struct e1000_hw
*hw
);
71 /* IGP cable length table */
73 uint16_t e1000_igp_cable_length_table
[IGP01E1000_AGC_LENGTH_TABLE_SIZE
] =
74 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
75 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
76 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
77 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
78 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
79 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
80 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
81 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
84 /******************************************************************************
85 * Set the phy type member in the hw struct.
87 * hw - Struct containing variables accessed by shared code
88 *****************************************************************************/
90 e1000_set_phy_type(struct e1000_hw
*hw
)
92 DEBUGFUNC("e1000_set_phy_type");
95 case M88E1000_E_PHY_ID
:
96 case M88E1000_I_PHY_ID
:
97 case M88E1011_I_PHY_ID
:
98 hw
->phy_type
= e1000_phy_m88
;
100 case IGP01E1000_I_PHY_ID
:
101 if(hw
->mac_type
== e1000_82541
||
102 hw
->mac_type
== e1000_82541_rev_2
||
103 hw
->mac_type
== e1000_82547
||
104 hw
->mac_type
== e1000_82547_rev_2
) {
105 hw
->phy_type
= e1000_phy_igp
;
110 /* Should never have loaded on this device */
111 hw
->phy_type
= e1000_phy_undefined
;
112 return -E1000_ERR_PHY_TYPE
;
115 return E1000_SUCCESS
;
118 /******************************************************************************
119 * IGP phy init script - initializes the GbE PHY
121 * hw - Struct containing variables accessed by shared code
122 *****************************************************************************/
124 e1000_phy_init_script(struct e1000_hw
*hw
)
127 uint16_t phy_saved_data
;
129 DEBUGFUNC("e1000_phy_init_script");
132 if(hw
->phy_init_script
) {
135 /* Save off the current value of register 0x2F5B to be restored at
136 * the end of this routine. */
137 ret_val
= e1000_read_phy_reg(hw
, 0x2F5B, &phy_saved_data
);
139 /* Disabled the PHY transmitter */
140 e1000_write_phy_reg(hw
, 0x2F5B, 0x0003);
144 e1000_write_phy_reg(hw
,0x0000,0x0140);
148 switch(hw
->mac_type
) {
151 e1000_write_phy_reg(hw
, 0x1F95, 0x0001);
153 e1000_write_phy_reg(hw
, 0x1F71, 0xBD21);
155 e1000_write_phy_reg(hw
, 0x1F79, 0x0018);
157 e1000_write_phy_reg(hw
, 0x1F30, 0x1600);
159 e1000_write_phy_reg(hw
, 0x1F31, 0x0014);
161 e1000_write_phy_reg(hw
, 0x1F32, 0x161C);
163 e1000_write_phy_reg(hw
, 0x1F94, 0x0003);
165 e1000_write_phy_reg(hw
, 0x1F96, 0x003F);
167 e1000_write_phy_reg(hw
, 0x2010, 0x0008);
170 case e1000_82541_rev_2
:
171 case e1000_82547_rev_2
:
172 e1000_write_phy_reg(hw
, 0x1F73, 0x0099);
178 e1000_write_phy_reg(hw
, 0x0000, 0x3300);
182 /* Now enable the transmitter */
183 e1000_write_phy_reg(hw
, 0x2F5B, phy_saved_data
);
185 if(hw
->mac_type
== e1000_82547
) {
186 uint16_t fused
, fine
, coarse
;
188 /* Move to analog registers page */
189 e1000_read_phy_reg(hw
, IGP01E1000_ANALOG_SPARE_FUSE_STATUS
, &fused
);
191 if(!(fused
& IGP01E1000_ANALOG_SPARE_FUSE_ENABLED
)) {
192 e1000_read_phy_reg(hw
, IGP01E1000_ANALOG_FUSE_STATUS
, &fused
);
194 fine
= fused
& IGP01E1000_ANALOG_FUSE_FINE_MASK
;
195 coarse
= fused
& IGP01E1000_ANALOG_FUSE_COARSE_MASK
;
197 if(coarse
> IGP01E1000_ANALOG_FUSE_COARSE_THRESH
) {
198 coarse
-= IGP01E1000_ANALOG_FUSE_COARSE_10
;
199 fine
-= IGP01E1000_ANALOG_FUSE_FINE_1
;
200 } else if(coarse
== IGP01E1000_ANALOG_FUSE_COARSE_THRESH
)
201 fine
-= IGP01E1000_ANALOG_FUSE_FINE_10
;
203 fused
= (fused
& IGP01E1000_ANALOG_FUSE_POLY_MASK
) |
204 (fine
& IGP01E1000_ANALOG_FUSE_FINE_MASK
) |
205 (coarse
& IGP01E1000_ANALOG_FUSE_COARSE_MASK
);
207 e1000_write_phy_reg(hw
, IGP01E1000_ANALOG_FUSE_CONTROL
, fused
);
208 e1000_write_phy_reg(hw
, IGP01E1000_ANALOG_FUSE_BYPASS
,
209 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL
);
215 /******************************************************************************
216 * Set the mac type member in the hw struct.
218 * hw - Struct containing variables accessed by shared code
219 *****************************************************************************/
221 e1000_set_mac_type(struct e1000_hw
*hw
)
223 DEBUGFUNC("e1000_set_mac_type");
225 switch (hw
->device_id
) {
226 case E1000_DEV_ID_82542
:
227 switch (hw
->revision_id
) {
228 case E1000_82542_2_0_REV_ID
:
229 hw
->mac_type
= e1000_82542_rev2_0
;
231 case E1000_82542_2_1_REV_ID
:
232 hw
->mac_type
= e1000_82542_rev2_1
;
235 /* Invalid 82542 revision ID */
236 return -E1000_ERR_MAC_TYPE
;
239 case E1000_DEV_ID_82543GC_FIBER
:
240 case E1000_DEV_ID_82543GC_COPPER
:
241 hw
->mac_type
= e1000_82543
;
243 case E1000_DEV_ID_82544EI_COPPER
:
244 case E1000_DEV_ID_82544EI_FIBER
:
245 case E1000_DEV_ID_82544GC_COPPER
:
246 case E1000_DEV_ID_82544GC_LOM
:
247 hw
->mac_type
= e1000_82544
;
249 case E1000_DEV_ID_82540EM
:
250 case E1000_DEV_ID_82540EM_LOM
:
251 case E1000_DEV_ID_82540EP
:
252 case E1000_DEV_ID_82540EP_LOM
:
253 case E1000_DEV_ID_82540EP_LP
:
254 hw
->mac_type
= e1000_82540
;
256 case E1000_DEV_ID_82545EM_COPPER
:
257 case E1000_DEV_ID_82545EM_FIBER
:
258 hw
->mac_type
= e1000_82545
;
260 case E1000_DEV_ID_82545GM_COPPER
:
261 case E1000_DEV_ID_82545GM_FIBER
:
262 case E1000_DEV_ID_82545GM_SERDES
:
263 hw
->mac_type
= e1000_82545_rev_3
;
265 case E1000_DEV_ID_82546EB_COPPER
:
266 case E1000_DEV_ID_82546EB_FIBER
:
267 case E1000_DEV_ID_82546EB_QUAD_COPPER
:
268 hw
->mac_type
= e1000_82546
;
270 case E1000_DEV_ID_82546GB_COPPER
:
271 case E1000_DEV_ID_82546GB_FIBER
:
272 case E1000_DEV_ID_82546GB_SERDES
:
273 case E1000_DEV_ID_82546GB_PCIE
:
274 hw
->mac_type
= e1000_82546_rev_3
;
276 case E1000_DEV_ID_82541EI
:
277 case E1000_DEV_ID_82541EI_MOBILE
:
278 hw
->mac_type
= e1000_82541
;
280 case E1000_DEV_ID_82541ER
:
281 case E1000_DEV_ID_82541GI
:
282 case E1000_DEV_ID_82541GI_LF
:
283 case E1000_DEV_ID_82541GI_MOBILE
:
284 hw
->mac_type
= e1000_82541_rev_2
;
286 case E1000_DEV_ID_82547EI
:
287 hw
->mac_type
= e1000_82547
;
289 case E1000_DEV_ID_82547GI
:
290 hw
->mac_type
= e1000_82547_rev_2
;
293 /* Should never have loaded on this device */
294 return -E1000_ERR_MAC_TYPE
;
297 switch(hw
->mac_type
) {
300 case e1000_82541_rev_2
:
301 case e1000_82547_rev_2
:
302 hw
->asf_firmware_present
= TRUE
;
308 return E1000_SUCCESS
;
311 /*****************************************************************************
312 * Set media type and TBI compatibility.
314 * hw - Struct containing variables accessed by shared code
315 * **************************************************************************/
317 e1000_set_media_type(struct e1000_hw
*hw
)
321 DEBUGFUNC("e1000_set_media_type");
323 if(hw
->mac_type
!= e1000_82543
) {
324 /* tbi_compatibility is only valid on 82543 */
325 hw
->tbi_compatibility_en
= FALSE
;
328 switch (hw
->device_id
) {
329 case E1000_DEV_ID_82545GM_SERDES
:
330 case E1000_DEV_ID_82546GB_SERDES
:
331 hw
->media_type
= e1000_media_type_internal_serdes
;
334 if(hw
->mac_type
>= e1000_82543
) {
335 status
= E1000_READ_REG(hw
, STATUS
);
336 if(status
& E1000_STATUS_TBIMODE
) {
337 hw
->media_type
= e1000_media_type_fiber
;
338 /* tbi_compatibility not valid on fiber */
339 hw
->tbi_compatibility_en
= FALSE
;
341 hw
->media_type
= e1000_media_type_copper
;
344 /* This is an 82542 (fiber only) */
345 hw
->media_type
= e1000_media_type_fiber
;
350 /******************************************************************************
351 * Reset the transmit and receive units; mask and clear all interrupts.
353 * hw - Struct containing variables accessed by shared code
354 *****************************************************************************/
356 e1000_reset_hw(struct e1000_hw
*hw
)
364 DEBUGFUNC("e1000_reset_hw");
366 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
367 if(hw
->mac_type
== e1000_82542_rev2_0
) {
368 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
369 e1000_pci_clear_mwi(hw
);
372 /* Clear interrupt mask to stop board from generating interrupts */
373 DEBUGOUT("Masking off all interrupts\n");
374 E1000_WRITE_REG(hw
, IMC
, 0xffffffff);
376 /* Disable the Transmit and Receive units. Then delay to allow
377 * any pending transactions to complete before we hit the MAC with
380 E1000_WRITE_REG(hw
, RCTL
, 0);
381 E1000_WRITE_REG(hw
, TCTL
, E1000_TCTL_PSP
);
382 E1000_WRITE_FLUSH(hw
);
384 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
385 hw
->tbi_compatibility_on
= FALSE
;
387 /* Delay to allow any outstanding PCI transactions to complete before
388 * resetting the device
392 ctrl
= E1000_READ_REG(hw
, CTRL
);
394 /* Must reset the PHY before resetting the MAC */
395 if((hw
->mac_type
== e1000_82541
) || (hw
->mac_type
== e1000_82547
)) {
396 E1000_WRITE_REG_IO(hw
, CTRL
, (ctrl
| E1000_CTRL_PHY_RST
));
400 /* Issue a global reset to the MAC. This will reset the chip's
401 * transmit, receive, DMA, and link units. It will not effect
402 * the current PCI configuration. The global reset bit is self-
403 * clearing, and should clear within a microsecond.
405 DEBUGOUT("Issuing a global reset to MAC\n");
407 switch(hw
->mac_type
) {
413 case e1000_82541_rev_2
:
414 /* These controllers can't ack the 64-bit write when issuing the
415 * reset, so use IO-mapping as a workaround to issue the reset */
416 E1000_WRITE_REG_IO(hw
, CTRL
, (ctrl
| E1000_CTRL_RST
));
418 case e1000_82545_rev_3
:
419 case e1000_82546_rev_3
:
420 /* Reset is performed on a shadow of the control register */
421 E1000_WRITE_REG(hw
, CTRL_DUP
, (ctrl
| E1000_CTRL_RST
));
424 E1000_WRITE_REG(hw
, CTRL
, (ctrl
| E1000_CTRL_RST
));
428 /* After MAC reset, force reload of EEPROM to restore power-on settings to
429 * device. Later controllers reload the EEPROM automatically, so just wait
430 * for reload to complete.
432 switch(hw
->mac_type
) {
433 case e1000_82542_rev2_0
:
434 case e1000_82542_rev2_1
:
437 /* Wait for reset to complete */
439 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
440 ctrl_ext
|= E1000_CTRL_EXT_EE_RST
;
441 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
442 E1000_WRITE_FLUSH(hw
);
443 /* Wait for EEPROM reload */
447 case e1000_82541_rev_2
:
449 case e1000_82547_rev_2
:
450 /* Wait for EEPROM reload */
454 /* Wait for EEPROM reload (it happens automatically) */
459 /* Disable HW ARPs on ASF enabled adapters */
460 if(hw
->mac_type
>= e1000_82540
) {
461 manc
= E1000_READ_REG(hw
, MANC
);
462 manc
&= ~(E1000_MANC_ARP_EN
);
463 E1000_WRITE_REG(hw
, MANC
, manc
);
466 if((hw
->mac_type
== e1000_82541
) || (hw
->mac_type
== e1000_82547
)) {
467 e1000_phy_init_script(hw
);
469 /* Configure activity LED after PHY reset */
470 led_ctrl
= E1000_READ_REG(hw
, LEDCTL
);
471 led_ctrl
&= IGP_ACTIVITY_LED_MASK
;
472 led_ctrl
|= (IGP_ACTIVITY_LED_ENABLE
| IGP_LED3_MODE
);
473 E1000_WRITE_REG(hw
, LEDCTL
, led_ctrl
);
476 /* Clear interrupt mask to stop board from generating interrupts */
477 DEBUGOUT("Masking off all interrupts\n");
478 E1000_WRITE_REG(hw
, IMC
, 0xffffffff);
480 /* Clear any pending interrupt events. */
481 icr
= E1000_READ_REG(hw
, ICR
);
483 /* If MWI was previously enabled, reenable it. */
484 if(hw
->mac_type
== e1000_82542_rev2_0
) {
485 if(hw
->pci_cmd_word
& CMD_MEM_WRT_INVALIDATE
)
486 e1000_pci_set_mwi(hw
);
489 return E1000_SUCCESS
;
492 /******************************************************************************
493 * Performs basic configuration of the adapter.
495 * hw - Struct containing variables accessed by shared code
497 * Assumes that the controller has previously been reset and is in a
498 * post-reset uninitialized state. Initializes the receive address registers,
499 * multicast table, and VLAN filter table. Calls routines to setup link
500 * configuration and flow control settings. Clears all on-chip counters. Leaves
501 * the transmit and receive units disabled and uninitialized.
502 *****************************************************************************/
504 e1000_init_hw(struct e1000_hw
*hw
)
509 uint16_t pcix_cmd_word
;
510 uint16_t pcix_stat_hi_word
;
513 DEBUGFUNC("e1000_init_hw");
515 /* Initialize Identification LED */
516 ret_val
= e1000_id_led_init(hw
);
518 DEBUGOUT("Error Initializing Identification LED\n");
522 /* Set the media type and TBI compatibility */
523 e1000_set_media_type(hw
);
525 /* Disabling VLAN filtering. */
526 DEBUGOUT("Initializing the IEEE VLAN\n");
527 E1000_WRITE_REG(hw
, VET
, 0);
529 e1000_clear_vfta(hw
);
531 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
532 if(hw
->mac_type
== e1000_82542_rev2_0
) {
533 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
534 e1000_pci_clear_mwi(hw
);
535 E1000_WRITE_REG(hw
, RCTL
, E1000_RCTL_RST
);
536 E1000_WRITE_FLUSH(hw
);
540 /* Setup the receive address. This involves initializing all of the Receive
541 * Address Registers (RARs 0 - 15).
543 e1000_init_rx_addrs(hw
);
545 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
546 if(hw
->mac_type
== e1000_82542_rev2_0
) {
547 E1000_WRITE_REG(hw
, RCTL
, 0);
548 E1000_WRITE_FLUSH(hw
);
550 if(hw
->pci_cmd_word
& CMD_MEM_WRT_INVALIDATE
)
551 e1000_pci_set_mwi(hw
);
554 /* Zero out the Multicast HASH table */
555 DEBUGOUT("Zeroing the MTA\n");
556 for(i
= 0; i
< E1000_MC_TBL_SIZE
; i
++)
557 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, 0);
559 /* Set the PCI priority bit correctly in the CTRL register. This
560 * determines if the adapter gives priority to receives, or if it
561 * gives equal priority to transmits and receives.
563 if(hw
->dma_fairness
) {
564 ctrl
= E1000_READ_REG(hw
, CTRL
);
565 E1000_WRITE_REG(hw
, CTRL
, ctrl
| E1000_CTRL_PRIOR
);
568 switch(hw
->mac_type
) {
569 case e1000_82545_rev_3
:
570 case e1000_82546_rev_3
:
573 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
574 if(hw
->bus_type
== e1000_bus_type_pcix
) {
575 e1000_read_pci_cfg(hw
, PCIX_COMMAND_REGISTER
, &pcix_cmd_word
);
576 e1000_read_pci_cfg(hw
, PCIX_STATUS_REGISTER_HI
,
578 cmd_mmrbc
= (pcix_cmd_word
& PCIX_COMMAND_MMRBC_MASK
) >>
579 PCIX_COMMAND_MMRBC_SHIFT
;
580 stat_mmrbc
= (pcix_stat_hi_word
& PCIX_STATUS_HI_MMRBC_MASK
) >>
581 PCIX_STATUS_HI_MMRBC_SHIFT
;
582 if(stat_mmrbc
== PCIX_STATUS_HI_MMRBC_4K
)
583 stat_mmrbc
= PCIX_STATUS_HI_MMRBC_2K
;
584 if(cmd_mmrbc
> stat_mmrbc
) {
585 pcix_cmd_word
&= ~PCIX_COMMAND_MMRBC_MASK
;
586 pcix_cmd_word
|= stat_mmrbc
<< PCIX_COMMAND_MMRBC_SHIFT
;
587 e1000_write_pci_cfg(hw
, PCIX_COMMAND_REGISTER
,
594 /* Call a subroutine to configure the link and setup flow control. */
595 ret_val
= e1000_setup_link(hw
);
597 /* Set the transmit descriptor write-back policy */
598 if(hw
->mac_type
> e1000_82544
) {
599 ctrl
= E1000_READ_REG(hw
, TXDCTL
);
600 ctrl
= (ctrl
& ~E1000_TXDCTL_WTHRESH
) | E1000_TXDCTL_FULL_TX_DESC_WB
;
601 E1000_WRITE_REG(hw
, TXDCTL
, ctrl
);
604 /* Clear all of the statistics registers (clear on read). It is
605 * important that we do this after we have tried to establish link
606 * because the symbol error count will increment wildly if there
609 e1000_clear_hw_cntrs(hw
);
614 /******************************************************************************
615 * Adjust SERDES output amplitude based on EEPROM setting.
617 * hw - Struct containing variables accessed by shared code.
618 *****************************************************************************/
620 e1000_adjust_serdes_amplitude(struct e1000_hw
*hw
)
622 uint16_t eeprom_data
;
625 DEBUGFUNC("e1000_adjust_serdes_amplitude");
627 if(hw
->media_type
!= e1000_media_type_internal_serdes
)
628 return E1000_SUCCESS
;
630 switch(hw
->mac_type
) {
631 case e1000_82545_rev_3
:
632 case e1000_82546_rev_3
:
635 return E1000_SUCCESS
;
638 ret_val
= e1000_read_eeprom(hw
, EEPROM_SERDES_AMPLITUDE
, 1, &eeprom_data
);
643 if(eeprom_data
!= EEPROM_RESERVED_WORD
) {
644 /* Adjust SERDES output amplitude only. */
645 eeprom_data
&= EEPROM_SERDES_AMPLITUDE_MASK
;
646 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_EXT_CTRL
, eeprom_data
);
651 return E1000_SUCCESS
;
654 /******************************************************************************
655 * Configures flow control and link settings.
657 * hw - Struct containing variables accessed by shared code
659 * Determines which flow control settings to use. Calls the apropriate media-
660 * specific link configuration function. Configures the flow control settings.
661 * Assuming the adapter has a valid link partner, a valid link should be
662 * established. Assumes the hardware has previously been reset and the
663 * transmitter and receiver are not enabled.
664 *****************************************************************************/
666 e1000_setup_link(struct e1000_hw
*hw
)
670 uint16_t eeprom_data
;
672 DEBUGFUNC("e1000_setup_link");
674 /* Read and store word 0x0F of the EEPROM. This word contains bits
675 * that determine the hardware's default PAUSE (flow control) mode,
676 * a bit that determines whether the HW defaults to enabling or
677 * disabling auto-negotiation, and the direction of the
678 * SW defined pins. If there is no SW over-ride of the flow
679 * control setting, then the variable hw->fc will
680 * be initialized based on a value in the EEPROM.
682 if(e1000_read_eeprom(hw
, EEPROM_INIT_CONTROL2_REG
, 1, &eeprom_data
) < 0) {
683 DEBUGOUT("EEPROM Read Error\n");
684 return -E1000_ERR_EEPROM
;
687 if(hw
->fc
== e1000_fc_default
) {
688 if((eeprom_data
& EEPROM_WORD0F_PAUSE_MASK
) == 0)
689 hw
->fc
= e1000_fc_none
;
690 else if((eeprom_data
& EEPROM_WORD0F_PAUSE_MASK
) ==
691 EEPROM_WORD0F_ASM_DIR
)
692 hw
->fc
= e1000_fc_tx_pause
;
694 hw
->fc
= e1000_fc_full
;
697 /* We want to save off the original Flow Control configuration just
698 * in case we get disconnected and then reconnected into a different
699 * hub or switch with different Flow Control capabilities.
701 if(hw
->mac_type
== e1000_82542_rev2_0
)
702 hw
->fc
&= (~e1000_fc_tx_pause
);
704 if((hw
->mac_type
< e1000_82543
) && (hw
->report_tx_early
== 1))
705 hw
->fc
&= (~e1000_fc_rx_pause
);
707 hw
->original_fc
= hw
->fc
;
709 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw
->fc
);
711 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
712 * polarity value for the SW controlled pins, and setup the
713 * Extended Device Control reg with that info.
714 * This is needed because one of the SW controlled pins is used for
715 * signal detection. So this should be done before e1000_setup_pcs_link()
716 * or e1000_phy_setup() is called.
718 if(hw
->mac_type
== e1000_82543
) {
719 ctrl_ext
= ((eeprom_data
& EEPROM_WORD0F_SWPDIO_EXT
) <<
721 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
724 /* Call the necessary subroutine to configure the link. */
725 ret_val
= (hw
->media_type
== e1000_media_type_copper
) ?
726 e1000_setup_copper_link(hw
) :
727 e1000_setup_fiber_serdes_link(hw
);
729 /* Initialize the flow control address, type, and PAUSE timer
730 * registers to their default values. This is done even if flow
731 * control is disabled, because it does not hurt anything to
732 * initialize these registers.
734 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
736 E1000_WRITE_REG(hw
, FCAL
, FLOW_CONTROL_ADDRESS_LOW
);
737 E1000_WRITE_REG(hw
, FCAH
, FLOW_CONTROL_ADDRESS_HIGH
);
738 E1000_WRITE_REG(hw
, FCT
, FLOW_CONTROL_TYPE
);
739 E1000_WRITE_REG(hw
, FCTTV
, hw
->fc_pause_time
);
741 /* Set the flow control receive threshold registers. Normally,
742 * these registers will be set to a default threshold that may be
743 * adjusted later by the driver's runtime code. However, if the
744 * ability to transmit pause frames in not enabled, then these
745 * registers will be set to 0.
747 if(!(hw
->fc
& e1000_fc_tx_pause
)) {
748 E1000_WRITE_REG(hw
, FCRTL
, 0);
749 E1000_WRITE_REG(hw
, FCRTH
, 0);
751 /* We need to set up the Receive Threshold high and low water marks
752 * as well as (optionally) enabling the transmission of XON frames.
754 if(hw
->fc_send_xon
) {
755 E1000_WRITE_REG(hw
, FCRTL
, (hw
->fc_low_water
| E1000_FCRTL_XONE
));
756 E1000_WRITE_REG(hw
, FCRTH
, hw
->fc_high_water
);
758 E1000_WRITE_REG(hw
, FCRTL
, hw
->fc_low_water
);
759 E1000_WRITE_REG(hw
, FCRTH
, hw
->fc_high_water
);
765 /******************************************************************************
766 * Sets up link for a fiber based or serdes based adapter
768 * hw - Struct containing variables accessed by shared code
770 * Manipulates Physical Coding Sublayer functions in order to configure
771 * link. Assumes the hardware has been previously reset and the transmitter
772 * and receiver are not enabled.
773 *****************************************************************************/
775 e1000_setup_fiber_serdes_link(struct e1000_hw
*hw
)
784 DEBUGFUNC("e1000_setup_fiber_serdes_link");
786 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
787 * set when the optics detect a signal. On older adapters, it will be
788 * cleared when there is a signal. This applies to fiber media only.
789 * If we're on serdes media, adjust the output amplitude to value set in
792 ctrl
= E1000_READ_REG(hw
, CTRL
);
793 if(hw
->media_type
== e1000_media_type_fiber
)
794 signal
= (hw
->mac_type
> e1000_82544
) ? E1000_CTRL_SWDPIN1
: 0;
796 ret_val
= e1000_adjust_serdes_amplitude(hw
);
800 /* Take the link out of reset */
801 ctrl
&= ~(E1000_CTRL_LRST
);
803 /* Adjust VCO speed to improve BER performance */
804 ret_val
= e1000_set_vco_speed(hw
);
808 e1000_config_collision_dist(hw
);
810 /* Check for a software override of the flow control settings, and setup
811 * the device accordingly. If auto-negotiation is enabled, then software
812 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
813 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
814 * auto-negotiation is disabled, then software will have to manually
815 * configure the two flow control enable bits in the CTRL register.
817 * The possible values of the "fc" parameter are:
818 * 0: Flow control is completely disabled
819 * 1: Rx flow control is enabled (we can receive pause frames, but
820 * not send pause frames).
821 * 2: Tx flow control is enabled (we can send pause frames but we do
822 * not support receiving pause frames).
823 * 3: Both Rx and TX flow control (symmetric) are enabled.
827 /* Flow control is completely disabled by a software over-ride. */
828 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
);
830 case e1000_fc_rx_pause
:
831 /* RX Flow control is enabled and TX Flow control is disabled by a
832 * software over-ride. Since there really isn't a way to advertise
833 * that we are capable of RX Pause ONLY, we will advertise that we
834 * support both symmetric and asymmetric RX PAUSE. Later, we will
835 * disable the adapter's ability to send PAUSE frames.
837 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
| E1000_TXCW_PAUSE_MASK
);
839 case e1000_fc_tx_pause
:
840 /* TX Flow control is enabled, and RX Flow control is disabled, by a
841 * software over-ride.
843 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
| E1000_TXCW_ASM_DIR
);
846 /* Flow control (both RX and TX) is enabled by a software over-ride. */
847 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
| E1000_TXCW_PAUSE_MASK
);
850 DEBUGOUT("Flow control param set incorrectly\n");
851 return -E1000_ERR_CONFIG
;
855 /* Since auto-negotiation is enabled, take the link out of reset (the link
856 * will be in reset, because we previously reset the chip). This will
857 * restart auto-negotiation. If auto-neogtiation is successful then the
858 * link-up status bit will be set and the flow control enable bits (RFCE
859 * and TFCE) will be set according to their negotiated value.
861 DEBUGOUT("Auto-negotiation enabled\n");
863 E1000_WRITE_REG(hw
, TXCW
, txcw
);
864 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
865 E1000_WRITE_FLUSH(hw
);
870 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
871 * indication in the Device Status Register. Time-out if a link isn't
872 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
873 * less than 500 milliseconds even if the other end is doing it in SW).
874 * For internal serdes, we just assume a signal is present, then poll.
876 if(hw
->media_type
== e1000_media_type_internal_serdes
||
877 (E1000_READ_REG(hw
, CTRL
) & E1000_CTRL_SWDPIN1
) == signal
) {
878 DEBUGOUT("Looking for Link\n");
879 for(i
= 0; i
< (LINK_UP_TIMEOUT
/ 10); i
++) {
881 status
= E1000_READ_REG(hw
, STATUS
);
882 if(status
& E1000_STATUS_LU
) break;
884 if(i
== (LINK_UP_TIMEOUT
/ 10)) {
885 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
886 hw
->autoneg_failed
= 1;
887 /* AutoNeg failed to achieve a link, so we'll call
888 * e1000_check_for_link. This routine will force the link up if
889 * we detect a signal. This will allow us to communicate with
890 * non-autonegotiating link partners.
892 ret_val
= e1000_check_for_link(hw
);
894 DEBUGOUT("Error while checking for link\n");
897 hw
->autoneg_failed
= 0;
899 hw
->autoneg_failed
= 0;
900 DEBUGOUT("Valid Link Found\n");
903 DEBUGOUT("No Signal Detected\n");
905 return E1000_SUCCESS
;
908 /******************************************************************************
909 * Detects which PHY is present and the speed and duplex
911 * hw - Struct containing variables accessed by shared code
912 ******************************************************************************/
914 e1000_setup_copper_link(struct e1000_hw
*hw
)
922 DEBUGFUNC("e1000_setup_copper_link");
924 ctrl
= E1000_READ_REG(hw
, CTRL
);
925 /* With 82543, we need to force speed and duplex on the MAC equal to what
926 * the PHY speed and duplex configuration is. In addition, we need to
927 * perform a hardware reset on the PHY to take it out of reset.
929 if(hw
->mac_type
> e1000_82543
) {
930 ctrl
|= E1000_CTRL_SLU
;
931 ctrl
&= ~(E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
);
932 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
934 ctrl
|= (E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
| E1000_CTRL_SLU
);
935 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
936 e1000_phy_hw_reset(hw
);
939 /* Make sure we have a valid PHY */
940 ret_val
= e1000_detect_gig_phy(hw
);
942 DEBUGOUT("Error, did not detect valid phy.\n");
945 DEBUGOUT1("Phy ID = %x \n", hw
->phy_id
);
947 /* Set PHY to class A mode (if necessary) */
948 ret_val
= e1000_set_phy_mode(hw
);
952 if((hw
->mac_type
== e1000_82545_rev_3
) ||
953 (hw
->mac_type
== e1000_82546_rev_3
)) {
954 ret_val
= e1000_read_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
955 phy_data
|= 0x00000008;
956 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
, phy_data
);
959 if(hw
->mac_type
<= e1000_82543
||
960 hw
->mac_type
== e1000_82541
|| hw
->mac_type
== e1000_82547
||
961 hw
->mac_type
== e1000_82541_rev_2
|| hw
->mac_type
== e1000_82547_rev_2
)
962 hw
->phy_reset_disable
= FALSE
;
964 if(!hw
->phy_reset_disable
) {
965 if (hw
->phy_type
== e1000_phy_igp
) {
967 ret_val
= e1000_phy_reset(hw
);
969 DEBUGOUT("Error Resetting the PHY\n");
973 /* Wait 10ms for MAC to configure PHY from eeprom settings */
976 /* Configure activity LED after PHY reset */
977 led_ctrl
= E1000_READ_REG(hw
, LEDCTL
);
978 led_ctrl
&= IGP_ACTIVITY_LED_MASK
;
979 led_ctrl
|= (IGP_ACTIVITY_LED_ENABLE
| IGP_LED3_MODE
);
980 E1000_WRITE_REG(hw
, LEDCTL
, led_ctrl
);
982 /* disable lplu d3 during driver init */
983 ret_val
= e1000_set_d3_lplu_state(hw
, FALSE
);
985 DEBUGOUT("Error Disabling LPLU D3\n");
989 /* Configure mdi-mdix settings */
990 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_PHY_PORT_CTRL
,
995 if((hw
->mac_type
== e1000_82541
) || (hw
->mac_type
== e1000_82547
)) {
996 hw
->dsp_config_state
= e1000_dsp_config_disabled
;
997 /* Force MDI for earlier revs of the IGP PHY */
998 phy_data
&= ~(IGP01E1000_PSCR_AUTO_MDIX
|
999 IGP01E1000_PSCR_FORCE_MDI_MDIX
);
1003 hw
->dsp_config_state
= e1000_dsp_config_enabled
;
1004 phy_data
&= ~IGP01E1000_PSCR_AUTO_MDIX
;
1008 phy_data
&= ~IGP01E1000_PSCR_FORCE_MDI_MDIX
;
1011 phy_data
|= IGP01E1000_PSCR_FORCE_MDI_MDIX
;
1015 phy_data
|= IGP01E1000_PSCR_AUTO_MDIX
;
1019 ret_val
= e1000_write_phy_reg(hw
, IGP01E1000_PHY_PORT_CTRL
,
1024 /* set auto-master slave resolution settings */
1026 e1000_ms_type phy_ms_setting
= hw
->master_slave
;
1028 if(hw
->ffe_config_state
== e1000_ffe_config_active
)
1029 hw
->ffe_config_state
= e1000_ffe_config_enabled
;
1031 if(hw
->dsp_config_state
== e1000_dsp_config_activated
)
1032 hw
->dsp_config_state
= e1000_dsp_config_enabled
;
1034 /* when autonegotiation advertisment is only 1000Mbps then we
1035 * should disable SmartSpeed and enable Auto MasterSlave
1036 * resolution as hardware default. */
1037 if(hw
->autoneg_advertised
== ADVERTISE_1000_FULL
) {
1038 /* Disable SmartSpeed */
1039 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_PHY_PORT_CONFIG
,
1043 phy_data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
1044 ret_val
= e1000_write_phy_reg(hw
,
1045 IGP01E1000_PHY_PORT_CONFIG
,
1049 /* Set auto Master/Slave resolution process */
1050 ret_val
= e1000_read_phy_reg(hw
, PHY_1000T_CTRL
, &phy_data
);
1053 phy_data
&= ~CR_1000T_MS_ENABLE
;
1054 ret_val
= e1000_write_phy_reg(hw
, PHY_1000T_CTRL
, phy_data
);
1059 ret_val
= e1000_read_phy_reg(hw
, PHY_1000T_CTRL
, &phy_data
);
1063 /* load defaults for future use */
1064 hw
->original_master_slave
= (phy_data
& CR_1000T_MS_ENABLE
) ?
1065 ((phy_data
& CR_1000T_MS_VALUE
) ?
1066 e1000_ms_force_master
:
1067 e1000_ms_force_slave
) :
1070 switch (phy_ms_setting
) {
1071 case e1000_ms_force_master
:
1072 phy_data
|= (CR_1000T_MS_ENABLE
| CR_1000T_MS_VALUE
);
1074 case e1000_ms_force_slave
:
1075 phy_data
|= CR_1000T_MS_ENABLE
;
1076 phy_data
&= ~(CR_1000T_MS_VALUE
);
1079 phy_data
&= ~CR_1000T_MS_ENABLE
;
1083 ret_val
= e1000_write_phy_reg(hw
, PHY_1000T_CTRL
, phy_data
);
1088 /* Enable CRS on TX. This must be set for half-duplex operation. */
1089 ret_val
= e1000_read_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
,
1094 phy_data
|= M88E1000_PSCR_ASSERT_CRS_ON_TX
;
1097 * MDI/MDI-X = 0 (default)
1098 * 0 - Auto for all speeds
1101 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1103 phy_data
&= ~M88E1000_PSCR_AUTO_X_MODE
;
1107 phy_data
|= M88E1000_PSCR_MDI_MANUAL_MODE
;
1110 phy_data
|= M88E1000_PSCR_MDIX_MANUAL_MODE
;
1113 phy_data
|= M88E1000_PSCR_AUTO_X_1000T
;
1117 phy_data
|= M88E1000_PSCR_AUTO_X_MODE
;
1122 * disable_polarity_correction = 0 (default)
1123 * Automatic Correction for Reversed Cable Polarity
1127 phy_data
&= ~M88E1000_PSCR_POLARITY_REVERSAL
;
1128 if(hw
->disable_polarity_correction
== 1)
1129 phy_data
|= M88E1000_PSCR_POLARITY_REVERSAL
;
1130 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
,
1135 /* Force TX_CLK in the Extended PHY Specific Control Register
1138 ret_val
= e1000_read_phy_reg(hw
, M88E1000_EXT_PHY_SPEC_CTRL
,
1143 phy_data
|= M88E1000_EPSCR_TX_CLK_25
;
1145 if (hw
->phy_revision
< M88E1011_I_REV_4
) {
1146 /* Configure Master and Slave downshift values */
1147 phy_data
&= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK
|
1148 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK
);
1149 phy_data
|= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X
|
1150 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X
);
1151 ret_val
= e1000_write_phy_reg(hw
, M88E1000_EXT_PHY_SPEC_CTRL
,
1157 /* SW Reset the PHY so all changes take effect */
1158 ret_val
= e1000_phy_reset(hw
);
1160 DEBUGOUT("Error Resetting the PHY\n");
1166 * autoneg = 1 (default)
1167 * PHY will advertise value(s) parsed from
1168 * autoneg_advertised and fc
1170 * PHY will be set to 10H, 10F, 100H, or 100F
1171 * depending on value parsed from forced_speed_duplex.
1174 /* Is autoneg enabled? This is enabled by default or by software
1175 * override. If so, call e1000_phy_setup_autoneg routine to parse the
1176 * autoneg_advertised and fc options. If autoneg is NOT enabled, then
1177 * the user should have provided a speed/duplex override. If so, then
1178 * call e1000_phy_force_speed_duplex to parse and set this up.
1181 /* Perform some bounds checking on the hw->autoneg_advertised
1182 * parameter. If this variable is zero, then set it to the default.
1184 hw
->autoneg_advertised
&= AUTONEG_ADVERTISE_SPEED_DEFAULT
;
1186 /* If autoneg_advertised is zero, we assume it was not defaulted
1187 * by the calling code so we set to advertise full capability.
1189 if(hw
->autoneg_advertised
== 0)
1190 hw
->autoneg_advertised
= AUTONEG_ADVERTISE_SPEED_DEFAULT
;
1192 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1193 ret_val
= e1000_phy_setup_autoneg(hw
);
1195 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1198 DEBUGOUT("Restarting Auto-Neg\n");
1200 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1201 * the Auto Neg Restart bit in the PHY control register.
1203 ret_val
= e1000_read_phy_reg(hw
, PHY_CTRL
, &phy_data
);
1207 phy_data
|= (MII_CR_AUTO_NEG_EN
| MII_CR_RESTART_AUTO_NEG
);
1208 ret_val
= e1000_write_phy_reg(hw
, PHY_CTRL
, phy_data
);
1212 /* Does the user want to wait for Auto-Neg to complete here, or
1213 * check at a later time (for example, callback routine).
1215 if(hw
->wait_autoneg_complete
) {
1216 ret_val
= e1000_wait_autoneg(hw
);
1218 DEBUGOUT("Error while waiting for autoneg to complete\n");
1222 hw
->get_link_status
= TRUE
;
1224 DEBUGOUT("Forcing speed and duplex\n");
1225 ret_val
= e1000_phy_force_speed_duplex(hw
);
1227 DEBUGOUT("Error Forcing Speed and Duplex\n");
1231 } /* !hw->phy_reset_disable */
1233 /* Check link status. Wait up to 100 microseconds for link to become
1236 for(i
= 0; i
< 10; i
++) {
1237 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
);
1240 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
);
1244 if(phy_data
& MII_SR_LINK_STATUS
) {
1245 /* We have link, so we need to finish the config process:
1246 * 1) Set up the MAC to the current PHY speed/duplex
1247 * if we are on 82543. If we
1248 * are on newer silicon, we only need to configure
1249 * collision distance in the Transmit Control Register.
1250 * 2) Set up flow control on the MAC to that established with
1253 if(hw
->mac_type
>= e1000_82544
) {
1254 e1000_config_collision_dist(hw
);
1256 ret_val
= e1000_config_mac_to_phy(hw
);
1258 DEBUGOUT("Error configuring MAC to PHY settings\n");
1262 ret_val
= e1000_config_fc_after_link_up(hw
);
1264 DEBUGOUT("Error Configuring Flow Control\n");
1267 DEBUGOUT("Valid link established!!!\n");
1269 if(hw
->phy_type
== e1000_phy_igp
) {
1270 ret_val
= e1000_config_dsp_after_link_change(hw
, TRUE
);
1272 DEBUGOUT("Error Configuring DSP after link up\n");
1276 DEBUGOUT("Valid link established!!!\n");
1277 return E1000_SUCCESS
;
1282 DEBUGOUT("Unable to establish link!!!\n");
1283 return E1000_SUCCESS
;
1286 /******************************************************************************
1287 * Configures PHY autoneg and flow control advertisement settings
1289 * hw - Struct containing variables accessed by shared code
1290 ******************************************************************************/
1292 e1000_phy_setup_autoneg(struct e1000_hw
*hw
)
1295 uint16_t mii_autoneg_adv_reg
;
1296 uint16_t mii_1000t_ctrl_reg
;
1298 DEBUGFUNC("e1000_phy_setup_autoneg");
1300 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1301 ret_val
= e1000_read_phy_reg(hw
, PHY_AUTONEG_ADV
, &mii_autoneg_adv_reg
);
1305 /* Read the MII 1000Base-T Control Register (Address 9). */
1306 ret_val
= e1000_read_phy_reg(hw
, PHY_1000T_CTRL
, &mii_1000t_ctrl_reg
);
1310 /* Need to parse both autoneg_advertised and fc and set up
1311 * the appropriate PHY registers. First we will parse for
1312 * autoneg_advertised software override. Since we can advertise
1313 * a plethora of combinations, we need to check each bit
1317 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1318 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1319 * the 1000Base-T Control Register (Address 9).
1321 mii_autoneg_adv_reg
&= ~REG4_SPEED_MASK
;
1322 mii_1000t_ctrl_reg
&= ~REG9_SPEED_MASK
;
1324 DEBUGOUT1("autoneg_advertised %x\n", hw
->autoneg_advertised
);
1326 /* Do we want to advertise 10 Mb Half Duplex? */
1327 if(hw
->autoneg_advertised
& ADVERTISE_10_HALF
) {
1328 DEBUGOUT("Advertise 10mb Half duplex\n");
1329 mii_autoneg_adv_reg
|= NWAY_AR_10T_HD_CAPS
;
1332 /* Do we want to advertise 10 Mb Full Duplex? */
1333 if(hw
->autoneg_advertised
& ADVERTISE_10_FULL
) {
1334 DEBUGOUT("Advertise 10mb Full duplex\n");
1335 mii_autoneg_adv_reg
|= NWAY_AR_10T_FD_CAPS
;
1338 /* Do we want to advertise 100 Mb Half Duplex? */
1339 if(hw
->autoneg_advertised
& ADVERTISE_100_HALF
) {
1340 DEBUGOUT("Advertise 100mb Half duplex\n");
1341 mii_autoneg_adv_reg
|= NWAY_AR_100TX_HD_CAPS
;
1344 /* Do we want to advertise 100 Mb Full Duplex? */
1345 if(hw
->autoneg_advertised
& ADVERTISE_100_FULL
) {
1346 DEBUGOUT("Advertise 100mb Full duplex\n");
1347 mii_autoneg_adv_reg
|= NWAY_AR_100TX_FD_CAPS
;
1350 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1351 if(hw
->autoneg_advertised
& ADVERTISE_1000_HALF
) {
1352 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1355 /* Do we want to advertise 1000 Mb Full Duplex? */
1356 if(hw
->autoneg_advertised
& ADVERTISE_1000_FULL
) {
1357 DEBUGOUT("Advertise 1000mb Full duplex\n");
1358 mii_1000t_ctrl_reg
|= CR_1000T_FD_CAPS
;
1361 /* Check for a software override of the flow control settings, and
1362 * setup the PHY advertisement registers accordingly. If
1363 * auto-negotiation is enabled, then software will have to set the
1364 * "PAUSE" bits to the correct value in the Auto-Negotiation
1365 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1367 * The possible values of the "fc" parameter are:
1368 * 0: Flow control is completely disabled
1369 * 1: Rx flow control is enabled (we can receive pause frames
1370 * but not send pause frames).
1371 * 2: Tx flow control is enabled (we can send pause frames
1372 * but we do not support receiving pause frames).
1373 * 3: Both Rx and TX flow control (symmetric) are enabled.
1374 * other: No software override. The flow control configuration
1375 * in the EEPROM is used.
1378 case e1000_fc_none
: /* 0 */
1379 /* Flow control (RX & TX) is completely disabled by a
1380 * software over-ride.
1382 mii_autoneg_adv_reg
&= ~(NWAY_AR_ASM_DIR
| NWAY_AR_PAUSE
);
1384 case e1000_fc_rx_pause
: /* 1 */
1385 /* RX Flow control is enabled, and TX Flow control is
1386 * disabled, by a software over-ride.
1388 /* Since there really isn't a way to advertise that we are
1389 * capable of RX Pause ONLY, we will advertise that we
1390 * support both symmetric and asymmetric RX PAUSE. Later
1391 * (in e1000_config_fc_after_link_up) we will disable the
1392 *hw's ability to send PAUSE frames.
1394 mii_autoneg_adv_reg
|= (NWAY_AR_ASM_DIR
| NWAY_AR_PAUSE
);
1396 case e1000_fc_tx_pause
: /* 2 */
1397 /* TX Flow control is enabled, and RX Flow control is
1398 * disabled, by a software over-ride.
1400 mii_autoneg_adv_reg
|= NWAY_AR_ASM_DIR
;
1401 mii_autoneg_adv_reg
&= ~NWAY_AR_PAUSE
;
1403 case e1000_fc_full
: /* 3 */
1404 /* Flow control (both RX and TX) is enabled by a software
1407 mii_autoneg_adv_reg
|= (NWAY_AR_ASM_DIR
| NWAY_AR_PAUSE
);
1410 DEBUGOUT("Flow control param set incorrectly\n");
1411 return -E1000_ERR_CONFIG
;
1414 ret_val
= e1000_write_phy_reg(hw
, PHY_AUTONEG_ADV
, mii_autoneg_adv_reg
);
1418 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg
);
1420 ret_val
= e1000_write_phy_reg(hw
, PHY_1000T_CTRL
, mii_1000t_ctrl_reg
);
1424 return E1000_SUCCESS
;
1427 /******************************************************************************
1428 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1430 * hw - Struct containing variables accessed by shared code
1431 ******************************************************************************/
1433 e1000_phy_force_speed_duplex(struct e1000_hw
*hw
)
1437 uint16_t mii_ctrl_reg
;
1438 uint16_t mii_status_reg
;
1442 DEBUGFUNC("e1000_phy_force_speed_duplex");
1444 /* Turn off Flow control if we are forcing speed and duplex. */
1445 hw
->fc
= e1000_fc_none
;
1447 DEBUGOUT1("hw->fc = %d\n", hw
->fc
);
1449 /* Read the Device Control Register. */
1450 ctrl
= E1000_READ_REG(hw
, CTRL
);
1452 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1453 ctrl
|= (E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
);
1454 ctrl
&= ~(DEVICE_SPEED_MASK
);
1456 /* Clear the Auto Speed Detect Enable bit. */
1457 ctrl
&= ~E1000_CTRL_ASDE
;
1459 /* Read the MII Control Register. */
1460 ret_val
= e1000_read_phy_reg(hw
, PHY_CTRL
, &mii_ctrl_reg
);
1464 /* We need to disable autoneg in order to force link and duplex. */
1466 mii_ctrl_reg
&= ~MII_CR_AUTO_NEG_EN
;
1468 /* Are we forcing Full or Half Duplex? */
1469 if(hw
->forced_speed_duplex
== e1000_100_full
||
1470 hw
->forced_speed_duplex
== e1000_10_full
) {
1471 /* We want to force full duplex so we SET the full duplex bits in the
1472 * Device and MII Control Registers.
1474 ctrl
|= E1000_CTRL_FD
;
1475 mii_ctrl_reg
|= MII_CR_FULL_DUPLEX
;
1476 DEBUGOUT("Full Duplex\n");
1478 /* We want to force half duplex so we CLEAR the full duplex bits in
1479 * the Device and MII Control Registers.
1481 ctrl
&= ~E1000_CTRL_FD
;
1482 mii_ctrl_reg
&= ~MII_CR_FULL_DUPLEX
;
1483 DEBUGOUT("Half Duplex\n");
1486 /* Are we forcing 100Mbps??? */
1487 if(hw
->forced_speed_duplex
== e1000_100_full
||
1488 hw
->forced_speed_duplex
== e1000_100_half
) {
1489 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1490 ctrl
|= E1000_CTRL_SPD_100
;
1491 mii_ctrl_reg
|= MII_CR_SPEED_100
;
1492 mii_ctrl_reg
&= ~(MII_CR_SPEED_1000
| MII_CR_SPEED_10
);
1493 DEBUGOUT("Forcing 100mb ");
1495 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1496 ctrl
&= ~(E1000_CTRL_SPD_1000
| E1000_CTRL_SPD_100
);
1497 mii_ctrl_reg
|= MII_CR_SPEED_10
;
1498 mii_ctrl_reg
&= ~(MII_CR_SPEED_1000
| MII_CR_SPEED_100
);
1499 DEBUGOUT("Forcing 10mb ");
1502 e1000_config_collision_dist(hw
);
1504 /* Write the configured values back to the Device Control Reg. */
1505 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
1507 if (hw
->phy_type
== e1000_phy_m88
) {
1508 ret_val
= e1000_read_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
1512 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1513 * forced whenever speed are duplex are forced.
1515 phy_data
&= ~M88E1000_PSCR_AUTO_X_MODE
;
1516 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
, phy_data
);
1520 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data
);
1522 /* Need to reset the PHY or these changes will be ignored */
1523 mii_ctrl_reg
|= MII_CR_RESET
;
1525 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1526 * forced whenever speed or duplex are forced.
1528 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_PHY_PORT_CTRL
, &phy_data
);
1532 phy_data
&= ~IGP01E1000_PSCR_AUTO_MDIX
;
1533 phy_data
&= ~IGP01E1000_PSCR_FORCE_MDI_MDIX
;
1535 ret_val
= e1000_write_phy_reg(hw
, IGP01E1000_PHY_PORT_CTRL
, phy_data
);
1540 /* Write back the modified PHY MII control register. */
1541 ret_val
= e1000_write_phy_reg(hw
, PHY_CTRL
, mii_ctrl_reg
);
1547 /* The wait_autoneg_complete flag may be a little misleading here.
1548 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1549 * But we do want to delay for a period while forcing only so we
1550 * don't generate false No Link messages. So we will wait here
1551 * only if the user has set wait_autoneg_complete to 1, which is
1554 if(hw
->wait_autoneg_complete
) {
1555 /* We will wait for autoneg to complete. */
1556 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1559 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1560 for(i
= PHY_FORCE_TIME
; i
> 0; i
--) {
1561 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1564 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &mii_status_reg
);
1568 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &mii_status_reg
);
1572 if(mii_status_reg
& MII_SR_LINK_STATUS
) break;
1576 (hw
->phy_type
== e1000_phy_m88
)) {
1577 /* We didn't get link. Reset the DSP and wait again for link. */
1578 ret_val
= e1000_phy_reset_dsp(hw
);
1580 DEBUGOUT("Error Resetting PHY DSP\n");
1584 /* This loop will early-out if the link condition has been met. */
1585 for(i
= PHY_FORCE_TIME
; i
> 0; i
--) {
1586 if(mii_status_reg
& MII_SR_LINK_STATUS
) break;
1588 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1591 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &mii_status_reg
);
1595 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &mii_status_reg
);
1601 if (hw
->phy_type
== e1000_phy_m88
) {
1602 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1603 * Extended PHY Specific Control Register to 25MHz clock. This value
1604 * defaults back to a 2.5MHz clock when the PHY is reset.
1606 ret_val
= e1000_read_phy_reg(hw
, M88E1000_EXT_PHY_SPEC_CTRL
, &phy_data
);
1610 phy_data
|= M88E1000_EPSCR_TX_CLK_25
;
1611 ret_val
= e1000_write_phy_reg(hw
, M88E1000_EXT_PHY_SPEC_CTRL
, phy_data
);
1615 /* In addition, because of the s/w reset above, we need to enable CRS on
1616 * TX. This must be set for both full and half duplex operation.
1618 ret_val
= e1000_read_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
1622 phy_data
|= M88E1000_PSCR_ASSERT_CRS_ON_TX
;
1623 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
, phy_data
);
1627 if((hw
->mac_type
== e1000_82544
|| hw
->mac_type
== e1000_82543
) &&
1629 (hw
->forced_speed_duplex
== e1000_10_full
||
1630 hw
->forced_speed_duplex
== e1000_10_half
)) {
1631 ret_val
= e1000_polarity_reversal_workaround(hw
);
1636 return E1000_SUCCESS
;
1639 /******************************************************************************
1640 * Sets the collision distance in the Transmit Control register
1642 * hw - Struct containing variables accessed by shared code
1644 * Link should have been established previously. Reads the speed and duplex
1645 * information from the Device Status register.
1646 ******************************************************************************/
1648 e1000_config_collision_dist(struct e1000_hw
*hw
)
1652 DEBUGFUNC("e1000_config_collision_dist");
1654 tctl
= E1000_READ_REG(hw
, TCTL
);
1656 tctl
&= ~E1000_TCTL_COLD
;
1657 tctl
|= E1000_COLLISION_DISTANCE
<< E1000_COLD_SHIFT
;
1659 E1000_WRITE_REG(hw
, TCTL
, tctl
);
1660 E1000_WRITE_FLUSH(hw
);
1663 /******************************************************************************
1664 * Sets MAC speed and duplex settings to reflect the those in the PHY
1666 * hw - Struct containing variables accessed by shared code
1667 * mii_reg - data to write to the MII control register
1669 * The contents of the PHY register containing the needed information need to
1671 ******************************************************************************/
1673 e1000_config_mac_to_phy(struct e1000_hw
*hw
)
1679 DEBUGFUNC("e1000_config_mac_to_phy");
1681 /* Read the Device Control Register and set the bits to Force Speed
1684 ctrl
= E1000_READ_REG(hw
, CTRL
);
1685 ctrl
|= (E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
);
1686 ctrl
&= ~(E1000_CTRL_SPD_SEL
| E1000_CTRL_ILOS
);
1688 /* Set up duplex in the Device Control and Transmit Control
1689 * registers depending on negotiated values.
1691 if (hw
->phy_type
== e1000_phy_igp
) {
1692 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_PHY_PORT_STATUS
,
1697 if(phy_data
& IGP01E1000_PSSR_FULL_DUPLEX
) ctrl
|= E1000_CTRL_FD
;
1698 else ctrl
&= ~E1000_CTRL_FD
;
1700 e1000_config_collision_dist(hw
);
1702 /* Set up speed in the Device Control register depending on
1703 * negotiated values.
1705 if((phy_data
& IGP01E1000_PSSR_SPEED_MASK
) ==
1706 IGP01E1000_PSSR_SPEED_1000MBPS
)
1707 ctrl
|= E1000_CTRL_SPD_1000
;
1708 else if((phy_data
& IGP01E1000_PSSR_SPEED_MASK
) ==
1709 IGP01E1000_PSSR_SPEED_100MBPS
)
1710 ctrl
|= E1000_CTRL_SPD_100
;
1712 ret_val
= e1000_read_phy_reg(hw
, M88E1000_PHY_SPEC_STATUS
,
1717 if(phy_data
& M88E1000_PSSR_DPLX
) ctrl
|= E1000_CTRL_FD
;
1718 else ctrl
&= ~E1000_CTRL_FD
;
1720 e1000_config_collision_dist(hw
);
1722 /* Set up speed in the Device Control register depending on
1723 * negotiated values.
1725 if((phy_data
& M88E1000_PSSR_SPEED
) == M88E1000_PSSR_1000MBS
)
1726 ctrl
|= E1000_CTRL_SPD_1000
;
1727 else if((phy_data
& M88E1000_PSSR_SPEED
) == M88E1000_PSSR_100MBS
)
1728 ctrl
|= E1000_CTRL_SPD_100
;
1730 /* Write the configured values back to the Device Control Reg. */
1731 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
1732 return E1000_SUCCESS
;
1735 /******************************************************************************
1736 * Forces the MAC's flow control settings.
1738 * hw - Struct containing variables accessed by shared code
1740 * Sets the TFCE and RFCE bits in the device control register to reflect
1741 * the adapter settings. TFCE and RFCE need to be explicitly set by
1742 * software when a Copper PHY is used because autonegotiation is managed
1743 * by the PHY rather than the MAC. Software must also configure these
1744 * bits when link is forced on a fiber connection.
1745 *****************************************************************************/
1747 e1000_force_mac_fc(struct e1000_hw
*hw
)
1751 DEBUGFUNC("e1000_force_mac_fc");
1753 /* Get the current configuration of the Device Control Register */
1754 ctrl
= E1000_READ_REG(hw
, CTRL
);
1756 /* Because we didn't get link via the internal auto-negotiation
1757 * mechanism (we either forced link or we got link via PHY
1758 * auto-neg), we have to manually enable/disable transmit an
1759 * receive flow control.
1761 * The "Case" statement below enables/disable flow control
1762 * according to the "hw->fc" parameter.
1764 * The possible values of the "fc" parameter are:
1765 * 0: Flow control is completely disabled
1766 * 1: Rx flow control is enabled (we can receive pause
1767 * frames but not send pause frames).
1768 * 2: Tx flow control is enabled (we can send pause frames
1769 * frames but we do not receive pause frames).
1770 * 3: Both Rx and TX flow control (symmetric) is enabled.
1771 * other: No other values should be possible at this point.
1776 ctrl
&= (~(E1000_CTRL_TFCE
| E1000_CTRL_RFCE
));
1778 case e1000_fc_rx_pause
:
1779 ctrl
&= (~E1000_CTRL_TFCE
);
1780 ctrl
|= E1000_CTRL_RFCE
;
1782 case e1000_fc_tx_pause
:
1783 ctrl
&= (~E1000_CTRL_RFCE
);
1784 ctrl
|= E1000_CTRL_TFCE
;
1787 ctrl
|= (E1000_CTRL_TFCE
| E1000_CTRL_RFCE
);
1790 DEBUGOUT("Flow control param set incorrectly\n");
1791 return -E1000_ERR_CONFIG
;
1794 /* Disable TX Flow Control for 82542 (rev 2.0) */
1795 if(hw
->mac_type
== e1000_82542_rev2_0
)
1796 ctrl
&= (~E1000_CTRL_TFCE
);
1798 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
1799 return E1000_SUCCESS
;
1802 /******************************************************************************
1803 * Configures flow control settings after link is established
1805 * hw - Struct containing variables accessed by shared code
1807 * Should be called immediately after a valid link has been established.
1808 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1809 * and autonegotiation is enabled, the MAC flow control settings will be set
1810 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1811 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1812 *****************************************************************************/
1814 e1000_config_fc_after_link_up(struct e1000_hw
*hw
)
1817 uint16_t mii_status_reg
;
1818 uint16_t mii_nway_adv_reg
;
1819 uint16_t mii_nway_lp_ability_reg
;
1823 DEBUGFUNC("e1000_config_fc_after_link_up");
1825 /* Check for the case where we have fiber media and auto-neg failed
1826 * so we had to force link. In this case, we need to force the
1827 * configuration of the MAC to match the "fc" parameter.
1829 if(((hw
->media_type
== e1000_media_type_fiber
) && (hw
->autoneg_failed
)) ||
1830 ((hw
->media_type
== e1000_media_type_internal_serdes
) && (hw
->autoneg_failed
)) ||
1831 ((hw
->media_type
== e1000_media_type_copper
) && (!hw
->autoneg
))) {
1832 ret_val
= e1000_force_mac_fc(hw
);
1834 DEBUGOUT("Error forcing flow control settings\n");
1839 /* Check for the case where we have copper media and auto-neg is
1840 * enabled. In this case, we need to check and see if Auto-Neg
1841 * has completed, and if so, how the PHY and link partner has
1842 * flow control configured.
1844 if((hw
->media_type
== e1000_media_type_copper
) && hw
->autoneg
) {
1845 /* Read the MII Status Register and check to see if AutoNeg
1846 * has completed. We read this twice because this reg has
1847 * some "sticky" (latched) bits.
1849 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &mii_status_reg
);
1852 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &mii_status_reg
);
1856 if(mii_status_reg
& MII_SR_AUTONEG_COMPLETE
) {
1857 /* The AutoNeg process has completed, so we now need to
1858 * read both the Auto Negotiation Advertisement Register
1859 * (Address 4) and the Auto_Negotiation Base Page Ability
1860 * Register (Address 5) to determine how flow control was
1863 ret_val
= e1000_read_phy_reg(hw
, PHY_AUTONEG_ADV
,
1867 ret_val
= e1000_read_phy_reg(hw
, PHY_LP_ABILITY
,
1868 &mii_nway_lp_ability_reg
);
1872 /* Two bits in the Auto Negotiation Advertisement Register
1873 * (Address 4) and two bits in the Auto Negotiation Base
1874 * Page Ability Register (Address 5) determine flow control
1875 * for both the PHY and the link partner. The following
1876 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
1877 * 1999, describes these PAUSE resolution bits and how flow
1878 * control is determined based upon these settings.
1879 * NOTE: DC = Don't Care
1881 * LOCAL DEVICE | LINK PARTNER
1882 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
1883 *-------|---------|-------|---------|--------------------
1884 * 0 | 0 | DC | DC | e1000_fc_none
1885 * 0 | 1 | 0 | DC | e1000_fc_none
1886 * 0 | 1 | 1 | 0 | e1000_fc_none
1887 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1888 * 1 | 0 | 0 | DC | e1000_fc_none
1889 * 1 | DC | 1 | DC | e1000_fc_full
1890 * 1 | 1 | 0 | 0 | e1000_fc_none
1891 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1894 /* Are both PAUSE bits set to 1? If so, this implies
1895 * Symmetric Flow Control is enabled at both ends. The
1896 * ASM_DIR bits are irrelevant per the spec.
1898 * For Symmetric Flow Control:
1900 * LOCAL DEVICE | LINK PARTNER
1901 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1902 *-------|---------|-------|---------|--------------------
1903 * 1 | DC | 1 | DC | e1000_fc_full
1906 if((mii_nway_adv_reg
& NWAY_AR_PAUSE
) &&
1907 (mii_nway_lp_ability_reg
& NWAY_LPAR_PAUSE
)) {
1908 /* Now we need to check if the user selected RX ONLY
1909 * of pause frames. In this case, we had to advertise
1910 * FULL flow control because we could not advertise RX
1911 * ONLY. Hence, we must now check to see if we need to
1912 * turn OFF the TRANSMISSION of PAUSE frames.
1914 if(hw
->original_fc
== e1000_fc_full
) {
1915 hw
->fc
= e1000_fc_full
;
1916 DEBUGOUT("Flow Control = FULL.\r\n");
1918 hw
->fc
= e1000_fc_rx_pause
;
1919 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1922 /* For receiving PAUSE frames ONLY.
1924 * LOCAL DEVICE | LINK PARTNER
1925 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1926 *-------|---------|-------|---------|--------------------
1927 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1930 else if(!(mii_nway_adv_reg
& NWAY_AR_PAUSE
) &&
1931 (mii_nway_adv_reg
& NWAY_AR_ASM_DIR
) &&
1932 (mii_nway_lp_ability_reg
& NWAY_LPAR_PAUSE
) &&
1933 (mii_nway_lp_ability_reg
& NWAY_LPAR_ASM_DIR
)) {
1934 hw
->fc
= e1000_fc_tx_pause
;
1935 DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
1937 /* For transmitting PAUSE frames ONLY.
1939 * LOCAL DEVICE | LINK PARTNER
1940 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1941 *-------|---------|-------|---------|--------------------
1942 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1945 else if((mii_nway_adv_reg
& NWAY_AR_PAUSE
) &&
1946 (mii_nway_adv_reg
& NWAY_AR_ASM_DIR
) &&
1947 !(mii_nway_lp_ability_reg
& NWAY_LPAR_PAUSE
) &&
1948 (mii_nway_lp_ability_reg
& NWAY_LPAR_ASM_DIR
)) {
1949 hw
->fc
= e1000_fc_rx_pause
;
1950 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1952 /* Per the IEEE spec, at this point flow control should be
1953 * disabled. However, we want to consider that we could
1954 * be connected to a legacy switch that doesn't advertise
1955 * desired flow control, but can be forced on the link
1956 * partner. So if we advertised no flow control, that is
1957 * what we will resolve to. If we advertised some kind of
1958 * receive capability (Rx Pause Only or Full Flow Control)
1959 * and the link partner advertised none, we will configure
1960 * ourselves to enable Rx Flow Control only. We can do
1961 * this safely for two reasons: If the link partner really
1962 * didn't want flow control enabled, and we enable Rx, no
1963 * harm done since we won't be receiving any PAUSE frames
1964 * anyway. If the intent on the link partner was to have
1965 * flow control enabled, then by us enabling RX only, we
1966 * can at least receive pause frames and process them.
1967 * This is a good idea because in most cases, since we are
1968 * predominantly a server NIC, more times than not we will
1969 * be asked to delay transmission of packets than asking
1970 * our link partner to pause transmission of frames.
1972 else if((hw
->original_fc
== e1000_fc_none
||
1973 hw
->original_fc
== e1000_fc_tx_pause
) ||
1974 hw
->fc_strict_ieee
) {
1975 hw
->fc
= e1000_fc_none
;
1976 DEBUGOUT("Flow Control = NONE.\r\n");
1978 hw
->fc
= e1000_fc_rx_pause
;
1979 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1982 /* Now we need to do one last check... If we auto-
1983 * negotiated to HALF DUPLEX, flow control should not be
1984 * enabled per IEEE 802.3 spec.
1986 ret_val
= e1000_get_speed_and_duplex(hw
, &speed
, &duplex
);
1988 DEBUGOUT("Error getting link speed and duplex\n");
1992 if(duplex
== HALF_DUPLEX
)
1993 hw
->fc
= e1000_fc_none
;
1995 /* Now we call a subroutine to actually force the MAC
1996 * controller to use the correct flow control settings.
1998 ret_val
= e1000_force_mac_fc(hw
);
2000 DEBUGOUT("Error forcing flow control settings\n");
2004 DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
2007 return E1000_SUCCESS
;
2010 /******************************************************************************
2011 * Checks to see if the link status of the hardware has changed.
2013 * hw - Struct containing variables accessed by shared code
2015 * Called by any function that needs to check the link status of the adapter.
2016 *****************************************************************************/
2018 e1000_check_for_link(struct e1000_hw
*hw
)
2025 uint32_t signal
= 0;
2029 DEBUGFUNC("e1000_check_for_link");
2031 ctrl
= E1000_READ_REG(hw
, CTRL
);
2032 status
= E1000_READ_REG(hw
, STATUS
);
2034 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2035 * set when the optics detect a signal. On older adapters, it will be
2036 * cleared when there is a signal. This applies to fiber media only.
2038 if((hw
->media_type
== e1000_media_type_fiber
) ||
2039 (hw
->media_type
== e1000_media_type_internal_serdes
)) {
2040 rxcw
= E1000_READ_REG(hw
, RXCW
);
2042 if(hw
->media_type
== e1000_media_type_fiber
) {
2043 signal
= (hw
->mac_type
> e1000_82544
) ? E1000_CTRL_SWDPIN1
: 0;
2044 if(status
& E1000_STATUS_LU
)
2045 hw
->get_link_status
= FALSE
;
2049 /* If we have a copper PHY then we only want to go out to the PHY
2050 * registers to see if Auto-Neg has completed and/or if our link
2051 * status has changed. The get_link_status flag will be set if we
2052 * receive a Link Status Change interrupt or we have Rx Sequence
2055 if((hw
->media_type
== e1000_media_type_copper
) && hw
->get_link_status
) {
2056 /* First we want to see if the MII Status Register reports
2057 * link. If so, then we want to get the current speed/duplex
2059 * Read the register twice since the link bit is sticky.
2061 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
);
2064 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
);
2068 if(phy_data
& MII_SR_LINK_STATUS
) {
2069 hw
->get_link_status
= FALSE
;
2070 /* Check if there was DownShift, must be checked immediately after
2072 e1000_check_downshift(hw
);
2074 /* If we are on 82544 or 82543 silicon and speed/duplex
2075 * are forced to 10H or 10F, then we will implement the polarity
2076 * reversal workaround. We disable interrupts first, and upon
2077 * returning, place the devices interrupt state to its previous
2078 * value except for the link status change interrupt which will
2079 * happen due to the execution of this workaround.
2082 if((hw
->mac_type
== e1000_82544
|| hw
->mac_type
== e1000_82543
) &&
2084 (hw
->forced_speed_duplex
== e1000_10_full
||
2085 hw
->forced_speed_duplex
== e1000_10_half
)) {
2086 E1000_WRITE_REG(hw
, IMC
, 0xffffffff);
2087 ret_val
= e1000_polarity_reversal_workaround(hw
);
2088 icr
= E1000_READ_REG(hw
, ICR
);
2089 E1000_WRITE_REG(hw
, ICS
, (icr
& ~E1000_ICS_LSC
));
2090 E1000_WRITE_REG(hw
, IMS
, IMS_ENABLE_MASK
);
2094 /* No link detected */
2095 e1000_config_dsp_after_link_change(hw
, FALSE
);
2099 /* If we are forcing speed/duplex, then we simply return since
2100 * we have already determined whether we have link or not.
2102 if(!hw
->autoneg
) return -E1000_ERR_CONFIG
;
2104 /* optimize the dsp settings for the igp phy */
2105 e1000_config_dsp_after_link_change(hw
, TRUE
);
2107 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2108 * have Si on board that is 82544 or newer, Auto
2109 * Speed Detection takes care of MAC speed/duplex
2110 * configuration. So we only need to configure Collision
2111 * Distance in the MAC. Otherwise, we need to force
2112 * speed/duplex on the MAC to the current PHY speed/duplex
2115 if(hw
->mac_type
>= e1000_82544
)
2116 e1000_config_collision_dist(hw
);
2118 ret_val
= e1000_config_mac_to_phy(hw
);
2120 DEBUGOUT("Error configuring MAC to PHY settings\n");
2125 /* Configure Flow Control now that Auto-Neg has completed. First, we
2126 * need to restore the desired flow control settings because we may
2127 * have had to re-autoneg with a different link partner.
2129 ret_val
= e1000_config_fc_after_link_up(hw
);
2131 DEBUGOUT("Error configuring flow control\n");
2135 /* At this point we know that we are on copper and we have
2136 * auto-negotiated link. These are conditions for checking the link
2137 * partner capability register. We use the link speed to determine if
2138 * TBI compatibility needs to be turned on or off. If the link is not
2139 * at gigabit speed, then TBI compatibility is not needed. If we are
2140 * at gigabit speed, we turn on TBI compatibility.
2142 if(hw
->tbi_compatibility_en
) {
2143 uint16_t speed
, duplex
;
2144 e1000_get_speed_and_duplex(hw
, &speed
, &duplex
);
2145 if(speed
!= SPEED_1000
) {
2146 /* If link speed is not set to gigabit speed, we do not need
2147 * to enable TBI compatibility.
2149 if(hw
->tbi_compatibility_on
) {
2150 /* If we previously were in the mode, turn it off. */
2151 rctl
= E1000_READ_REG(hw
, RCTL
);
2152 rctl
&= ~E1000_RCTL_SBP
;
2153 E1000_WRITE_REG(hw
, RCTL
, rctl
);
2154 hw
->tbi_compatibility_on
= FALSE
;
2157 /* If TBI compatibility is was previously off, turn it on. For
2158 * compatibility with a TBI link partner, we will store bad
2159 * packets. Some frames have an additional byte on the end and
2160 * will look like CRC errors to to the hardware.
2162 if(!hw
->tbi_compatibility_on
) {
2163 hw
->tbi_compatibility_on
= TRUE
;
2164 rctl
= E1000_READ_REG(hw
, RCTL
);
2165 rctl
|= E1000_RCTL_SBP
;
2166 E1000_WRITE_REG(hw
, RCTL
, rctl
);
2171 /* If we don't have link (auto-negotiation failed or link partner cannot
2172 * auto-negotiate), the cable is plugged in (we have signal), and our
2173 * link partner is not trying to auto-negotiate with us (we are receiving
2174 * idles or data), we need to force link up. We also need to give
2175 * auto-negotiation time to complete, in case the cable was just plugged
2176 * in. The autoneg_failed flag does this.
2178 else if((((hw
->media_type
== e1000_media_type_fiber
) &&
2179 ((ctrl
& E1000_CTRL_SWDPIN1
) == signal
)) ||
2180 (hw
->media_type
== e1000_media_type_internal_serdes
)) &&
2181 (!(status
& E1000_STATUS_LU
)) &&
2182 (!(rxcw
& E1000_RXCW_C
))) {
2183 if(hw
->autoneg_failed
== 0) {
2184 hw
->autoneg_failed
= 1;
2187 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
2189 /* Disable auto-negotiation in the TXCW register */
2190 E1000_WRITE_REG(hw
, TXCW
, (hw
->txcw
& ~E1000_TXCW_ANE
));
2192 /* Force link-up and also force full-duplex. */
2193 ctrl
= E1000_READ_REG(hw
, CTRL
);
2194 ctrl
|= (E1000_CTRL_SLU
| E1000_CTRL_FD
);
2195 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
2197 /* Configure Flow Control after forcing link up. */
2198 ret_val
= e1000_config_fc_after_link_up(hw
);
2200 DEBUGOUT("Error configuring flow control\n");
2204 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2205 * auto-negotiation in the TXCW register and disable forced link in the
2206 * Device Control register in an attempt to auto-negotiate with our link
2209 else if(((hw
->media_type
== e1000_media_type_fiber
) ||
2210 (hw
->media_type
== e1000_media_type_internal_serdes
)) &&
2211 (ctrl
& E1000_CTRL_SLU
) && (rxcw
& E1000_RXCW_C
)) {
2212 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2213 E1000_WRITE_REG(hw
, TXCW
, hw
->txcw
);
2214 E1000_WRITE_REG(hw
, CTRL
, (ctrl
& ~E1000_CTRL_SLU
));
2216 hw
->serdes_link_down
= FALSE
;
2218 /* If we force link for non-auto-negotiation switch, check link status
2219 * based on MAC synchronization for internal serdes media type.
2221 else if((hw
->media_type
== e1000_media_type_internal_serdes
) &&
2222 !(E1000_TXCW_ANE
& E1000_READ_REG(hw
, TXCW
))) {
2223 /* SYNCH bit and IV bit are sticky. */
2225 if(E1000_RXCW_SYNCH
& E1000_READ_REG(hw
, RXCW
)) {
2226 if(!(rxcw
& E1000_RXCW_IV
)) {
2227 hw
->serdes_link_down
= FALSE
;
2228 DEBUGOUT("SERDES: Link is up.\n");
2231 hw
->serdes_link_down
= TRUE
;
2232 DEBUGOUT("SERDES: Link is down.\n");
2235 if((hw
->media_type
== e1000_media_type_internal_serdes
) &&
2236 (E1000_TXCW_ANE
& E1000_READ_REG(hw
, TXCW
))) {
2237 hw
->serdes_link_down
= !(E1000_STATUS_LU
& E1000_READ_REG(hw
, STATUS
));
2239 return E1000_SUCCESS
;
2242 /******************************************************************************
2243 * Detects the current speed and duplex settings of the hardware.
2245 * hw - Struct containing variables accessed by shared code
2246 * speed - Speed of the connection
2247 * duplex - Duplex setting of the connection
2248 *****************************************************************************/
2250 e1000_get_speed_and_duplex(struct e1000_hw
*hw
,
2258 DEBUGFUNC("e1000_get_speed_and_duplex");
2260 if(hw
->mac_type
>= e1000_82543
) {
2261 status
= E1000_READ_REG(hw
, STATUS
);
2262 if(status
& E1000_STATUS_SPEED_1000
) {
2263 *speed
= SPEED_1000
;
2264 DEBUGOUT("1000 Mbs, ");
2265 } else if(status
& E1000_STATUS_SPEED_100
) {
2267 DEBUGOUT("100 Mbs, ");
2270 DEBUGOUT("10 Mbs, ");
2273 if(status
& E1000_STATUS_FD
) {
2274 *duplex
= FULL_DUPLEX
;
2275 DEBUGOUT("Full Duplex\r\n");
2277 *duplex
= HALF_DUPLEX
;
2278 DEBUGOUT(" Half Duplex\r\n");
2281 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2282 *speed
= SPEED_1000
;
2283 *duplex
= FULL_DUPLEX
;
2286 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2287 * if it is operating at half duplex. Here we set the duplex settings to
2288 * match the duplex in the link partner's capabilities.
2290 if(hw
->phy_type
== e1000_phy_igp
&& hw
->speed_downgraded
) {
2291 ret_val
= e1000_read_phy_reg(hw
, PHY_AUTONEG_EXP
, &phy_data
);
2295 if(!(phy_data
& NWAY_ER_LP_NWAY_CAPS
))
2296 *duplex
= HALF_DUPLEX
;
2298 ret_val
= e1000_read_phy_reg(hw
, PHY_LP_ABILITY
, &phy_data
);
2301 if((*speed
== SPEED_100
&& !(phy_data
& NWAY_LPAR_100TX_FD_CAPS
)) ||
2302 (*speed
== SPEED_10
&& !(phy_data
& NWAY_LPAR_10T_FD_CAPS
)))
2303 *duplex
= HALF_DUPLEX
;
2307 return E1000_SUCCESS
;
2310 /******************************************************************************
2311 * Blocks until autoneg completes or times out (~4.5 seconds)
2313 * hw - Struct containing variables accessed by shared code
2314 ******************************************************************************/
2316 e1000_wait_autoneg(struct e1000_hw
*hw
)
2322 DEBUGFUNC("e1000_wait_autoneg");
2323 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2325 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2326 for(i
= PHY_AUTO_NEG_TIME
; i
> 0; i
--) {
2327 /* Read the MII Status Register and wait for Auto-Neg
2328 * Complete bit to be set.
2330 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
);
2333 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
);
2336 if(phy_data
& MII_SR_AUTONEG_COMPLETE
) {
2337 return E1000_SUCCESS
;
2341 return E1000_SUCCESS
;
2344 /******************************************************************************
2345 * Raises the Management Data Clock
2347 * hw - Struct containing variables accessed by shared code
2348 * ctrl - Device control register's current value
2349 ******************************************************************************/
2351 e1000_raise_mdi_clk(struct e1000_hw
*hw
,
2354 /* Raise the clock input to the Management Data Clock (by setting the MDC
2355 * bit), and then delay 10 microseconds.
2357 E1000_WRITE_REG(hw
, CTRL
, (*ctrl
| E1000_CTRL_MDC
));
2358 E1000_WRITE_FLUSH(hw
);
2362 /******************************************************************************
2363 * Lowers the Management Data Clock
2365 * hw - Struct containing variables accessed by shared code
2366 * ctrl - Device control register's current value
2367 ******************************************************************************/
2369 e1000_lower_mdi_clk(struct e1000_hw
*hw
,
2372 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2373 * bit), and then delay 10 microseconds.
2375 E1000_WRITE_REG(hw
, CTRL
, (*ctrl
& ~E1000_CTRL_MDC
));
2376 E1000_WRITE_FLUSH(hw
);
2380 /******************************************************************************
2381 * Shifts data bits out to the PHY
2383 * hw - Struct containing variables accessed by shared code
2384 * data - Data to send out to the PHY
2385 * count - Number of bits to shift out
2387 * Bits are shifted out in MSB to LSB order.
2388 ******************************************************************************/
2390 e1000_shift_out_mdi_bits(struct e1000_hw
*hw
,
2397 /* We need to shift "count" number of bits out to the PHY. So, the value
2398 * in the "data" parameter will be shifted out to the PHY one bit at a
2399 * time. In order to do this, "data" must be broken down into bits.
2402 mask
<<= (count
- 1);
2404 ctrl
= E1000_READ_REG(hw
, CTRL
);
2406 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2407 ctrl
|= (E1000_CTRL_MDIO_DIR
| E1000_CTRL_MDC_DIR
);
2410 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2411 * then raising and lowering the Management Data Clock. A "0" is
2412 * shifted out to the PHY by setting the MDIO bit to "0" and then
2413 * raising and lowering the clock.
2415 if(data
& mask
) ctrl
|= E1000_CTRL_MDIO
;
2416 else ctrl
&= ~E1000_CTRL_MDIO
;
2418 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
2419 E1000_WRITE_FLUSH(hw
);
2423 e1000_raise_mdi_clk(hw
, &ctrl
);
2424 e1000_lower_mdi_clk(hw
, &ctrl
);
2430 /******************************************************************************
2431 * Shifts data bits in from the PHY
2433 * hw - Struct containing variables accessed by shared code
2435 * Bits are shifted in in MSB to LSB order.
2436 ******************************************************************************/
2438 e1000_shift_in_mdi_bits(struct e1000_hw
*hw
)
2444 /* In order to read a register from the PHY, we need to shift in a total
2445 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2446 * to avoid contention on the MDIO pin when a read operation is performed.
2447 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2448 * by raising the input to the Management Data Clock (setting the MDC bit),
2449 * and then reading the value of the MDIO bit.
2451 ctrl
= E1000_READ_REG(hw
, CTRL
);
2453 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2454 ctrl
&= ~E1000_CTRL_MDIO_DIR
;
2455 ctrl
&= ~E1000_CTRL_MDIO
;
2457 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
2458 E1000_WRITE_FLUSH(hw
);
2460 /* Raise and Lower the clock before reading in the data. This accounts for
2461 * the turnaround bits. The first clock occurred when we clocked out the
2462 * last bit of the Register Address.
2464 e1000_raise_mdi_clk(hw
, &ctrl
);
2465 e1000_lower_mdi_clk(hw
, &ctrl
);
2467 for(data
= 0, i
= 0; i
< 16; i
++) {
2469 e1000_raise_mdi_clk(hw
, &ctrl
);
2470 ctrl
= E1000_READ_REG(hw
, CTRL
);
2471 /* Check to see if we shifted in a "1". */
2472 if(ctrl
& E1000_CTRL_MDIO
) data
|= 1;
2473 e1000_lower_mdi_clk(hw
, &ctrl
);
2476 e1000_raise_mdi_clk(hw
, &ctrl
);
2477 e1000_lower_mdi_clk(hw
, &ctrl
);
2482 /*****************************************************************************
2483 * Reads the value from a PHY register, if the value is on a specific non zero
2484 * page, sets the page first.
2485 * hw - Struct containing variables accessed by shared code
2486 * reg_addr - address of the PHY register to read
2487 ******************************************************************************/
2489 e1000_read_phy_reg(struct e1000_hw
*hw
,
2495 DEBUGFUNC("e1000_read_phy_reg");
2498 if(hw
->phy_type
== e1000_phy_igp
&&
2499 (reg_addr
> MAX_PHY_MULTI_PAGE_REG
)) {
2500 ret_val
= e1000_write_phy_reg_ex(hw
, IGP01E1000_PHY_PAGE_SELECT
,
2501 (uint16_t)reg_addr
);
2507 ret_val
= e1000_read_phy_reg_ex(hw
, MAX_PHY_REG_ADDRESS
& reg_addr
,
2514 e1000_read_phy_reg_ex(struct e1000_hw
*hw
,
2520 const uint32_t phy_addr
= 1;
2522 DEBUGFUNC("e1000_read_phy_reg_ex");
2524 if(reg_addr
> MAX_PHY_REG_ADDRESS
) {
2525 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr
);
2526 return -E1000_ERR_PARAM
;
2529 if(hw
->mac_type
> e1000_82543
) {
2530 /* Set up Op-code, Phy Address, and register address in the MDI
2531 * Control register. The MAC will take care of interfacing with the
2532 * PHY to retrieve the desired data.
2534 mdic
= ((reg_addr
<< E1000_MDIC_REG_SHIFT
) |
2535 (phy_addr
<< E1000_MDIC_PHY_SHIFT
) |
2536 (E1000_MDIC_OP_READ
));
2538 E1000_WRITE_REG(hw
, MDIC
, mdic
);
2540 /* Poll the ready bit to see if the MDI read completed */
2541 for(i
= 0; i
< 64; i
++) {
2543 mdic
= E1000_READ_REG(hw
, MDIC
);
2544 if(mdic
& E1000_MDIC_READY
) break;
2546 if(!(mdic
& E1000_MDIC_READY
)) {
2547 DEBUGOUT("MDI Read did not complete\n");
2548 return -E1000_ERR_PHY
;
2550 if(mdic
& E1000_MDIC_ERROR
) {
2551 DEBUGOUT("MDI Error\n");
2552 return -E1000_ERR_PHY
;
2554 *phy_data
= (uint16_t) mdic
;
2556 /* We must first send a preamble through the MDIO pin to signal the
2557 * beginning of an MII instruction. This is done by sending 32
2558 * consecutive "1" bits.
2560 e1000_shift_out_mdi_bits(hw
, PHY_PREAMBLE
, PHY_PREAMBLE_SIZE
);
2562 /* Now combine the next few fields that are required for a read
2563 * operation. We use this method instead of calling the
2564 * e1000_shift_out_mdi_bits routine five different times. The format of
2565 * a MII read instruction consists of a shift out of 14 bits and is
2566 * defined as follows:
2567 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2568 * followed by a shift in of 18 bits. This first two bits shifted in
2569 * are TurnAround bits used to avoid contention on the MDIO pin when a
2570 * READ operation is performed. These two bits are thrown away
2571 * followed by a shift in of 16 bits which contains the desired data.
2573 mdic
= ((reg_addr
) | (phy_addr
<< 5) |
2574 (PHY_OP_READ
<< 10) | (PHY_SOF
<< 12));
2576 e1000_shift_out_mdi_bits(hw
, mdic
, 14);
2578 /* Now that we've shifted out the read command to the MII, we need to
2579 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2582 *phy_data
= e1000_shift_in_mdi_bits(hw
);
2584 return E1000_SUCCESS
;
2587 /******************************************************************************
2588 * Writes a value to a PHY register
2590 * hw - Struct containing variables accessed by shared code
2591 * reg_addr - address of the PHY register to write
2592 * data - data to write to the PHY
2593 ******************************************************************************/
2595 e1000_write_phy_reg(struct e1000_hw
*hw
,
2601 DEBUGFUNC("e1000_write_phy_reg");
2604 if(hw
->phy_type
== e1000_phy_igp
&&
2605 (reg_addr
> MAX_PHY_MULTI_PAGE_REG
)) {
2606 ret_val
= e1000_write_phy_reg_ex(hw
, IGP01E1000_PHY_PAGE_SELECT
,
2607 (uint16_t)reg_addr
);
2613 ret_val
= e1000_write_phy_reg_ex(hw
, MAX_PHY_REG_ADDRESS
& reg_addr
,
2620 e1000_write_phy_reg_ex(struct e1000_hw
*hw
,
2626 const uint32_t phy_addr
= 1;
2628 DEBUGFUNC("e1000_write_phy_reg_ex");
2630 if(reg_addr
> MAX_PHY_REG_ADDRESS
) {
2631 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr
);
2632 return -E1000_ERR_PARAM
;
2635 if(hw
->mac_type
> e1000_82543
) {
2636 /* Set up Op-code, Phy Address, register address, and data intended
2637 * for the PHY register in the MDI Control register. The MAC will take
2638 * care of interfacing with the PHY to send the desired data.
2640 mdic
= (((uint32_t) phy_data
) |
2641 (reg_addr
<< E1000_MDIC_REG_SHIFT
) |
2642 (phy_addr
<< E1000_MDIC_PHY_SHIFT
) |
2643 (E1000_MDIC_OP_WRITE
));
2645 E1000_WRITE_REG(hw
, MDIC
, mdic
);
2647 /* Poll the ready bit to see if the MDI read completed */
2648 for(i
= 0; i
< 640; i
++) {
2650 mdic
= E1000_READ_REG(hw
, MDIC
);
2651 if(mdic
& E1000_MDIC_READY
) break;
2653 if(!(mdic
& E1000_MDIC_READY
)) {
2654 DEBUGOUT("MDI Write did not complete\n");
2655 return -E1000_ERR_PHY
;
2658 /* We'll need to use the SW defined pins to shift the write command
2659 * out to the PHY. We first send a preamble to the PHY to signal the
2660 * beginning of the MII instruction. This is done by sending 32
2661 * consecutive "1" bits.
2663 e1000_shift_out_mdi_bits(hw
, PHY_PREAMBLE
, PHY_PREAMBLE_SIZE
);
2665 /* Now combine the remaining required fields that will indicate a
2666 * write operation. We use this method instead of calling the
2667 * e1000_shift_out_mdi_bits routine for each field in the command. The
2668 * format of a MII write instruction is as follows:
2669 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2671 mdic
= ((PHY_TURNAROUND
) | (reg_addr
<< 2) | (phy_addr
<< 7) |
2672 (PHY_OP_WRITE
<< 12) | (PHY_SOF
<< 14));
2674 mdic
|= (uint32_t) phy_data
;
2676 e1000_shift_out_mdi_bits(hw
, mdic
, 32);
2679 return E1000_SUCCESS
;
2682 /******************************************************************************
2683 * Returns the PHY to the power-on reset state
2685 * hw - Struct containing variables accessed by shared code
2686 ******************************************************************************/
2688 e1000_phy_hw_reset(struct e1000_hw
*hw
)
2690 uint32_t ctrl
, ctrl_ext
;
2693 DEBUGFUNC("e1000_phy_hw_reset");
2695 DEBUGOUT("Resetting Phy...\n");
2697 if(hw
->mac_type
> e1000_82543
) {
2698 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2699 * bit. Then, take it out of reset.
2701 ctrl
= E1000_READ_REG(hw
, CTRL
);
2702 E1000_WRITE_REG(hw
, CTRL
, ctrl
| E1000_CTRL_PHY_RST
);
2703 E1000_WRITE_FLUSH(hw
);
2705 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
2706 E1000_WRITE_FLUSH(hw
);
2708 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2709 * bit to put the PHY into reset. Then, take it out of reset.
2711 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
2712 ctrl_ext
|= E1000_CTRL_EXT_SDP4_DIR
;
2713 ctrl_ext
&= ~E1000_CTRL_EXT_SDP4_DATA
;
2714 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
2715 E1000_WRITE_FLUSH(hw
);
2717 ctrl_ext
|= E1000_CTRL_EXT_SDP4_DATA
;
2718 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
2719 E1000_WRITE_FLUSH(hw
);
2723 if((hw
->mac_type
== e1000_82541
) || (hw
->mac_type
== e1000_82547
)) {
2724 /* Configure activity LED after PHY reset */
2725 led_ctrl
= E1000_READ_REG(hw
, LEDCTL
);
2726 led_ctrl
&= IGP_ACTIVITY_LED_MASK
;
2727 led_ctrl
|= (IGP_ACTIVITY_LED_ENABLE
| IGP_LED3_MODE
);
2728 E1000_WRITE_REG(hw
, LEDCTL
, led_ctrl
);
2732 /******************************************************************************
2735 * hw - Struct containing variables accessed by shared code
2737 * Sets bit 15 of the MII Control regiser
2738 ******************************************************************************/
2740 e1000_phy_reset(struct e1000_hw
*hw
)
2745 DEBUGFUNC("e1000_phy_reset");
2747 if(hw
->mac_type
!= e1000_82541_rev_2
) {
2748 ret_val
= e1000_read_phy_reg(hw
, PHY_CTRL
, &phy_data
);
2752 phy_data
|= MII_CR_RESET
;
2753 ret_val
= e1000_write_phy_reg(hw
, PHY_CTRL
, phy_data
);
2758 } else e1000_phy_hw_reset(hw
);
2760 if(hw
->phy_type
== e1000_phy_igp
)
2761 e1000_phy_init_script(hw
);
2763 return E1000_SUCCESS
;
2766 /******************************************************************************
2767 * Probes the expected PHY address for known PHY IDs
2769 * hw - Struct containing variables accessed by shared code
2770 ******************************************************************************/
2772 e1000_detect_gig_phy(struct e1000_hw
*hw
)
2774 int32_t phy_init_status
, ret_val
;
2775 uint16_t phy_id_high
, phy_id_low
;
2776 boolean_t match
= FALSE
;
2778 DEBUGFUNC("e1000_detect_gig_phy");
2780 /* Read the PHY ID Registers to identify which PHY is onboard. */
2781 ret_val
= e1000_read_phy_reg(hw
, PHY_ID1
, &phy_id_high
);
2785 hw
->phy_id
= (uint32_t) (phy_id_high
<< 16);
2787 ret_val
= e1000_read_phy_reg(hw
, PHY_ID2
, &phy_id_low
);
2791 hw
->phy_id
|= (uint32_t) (phy_id_low
& PHY_REVISION_MASK
);
2792 hw
->phy_revision
= (uint32_t) phy_id_low
& ~PHY_REVISION_MASK
;
2794 switch(hw
->mac_type
) {
2796 if(hw
->phy_id
== M88E1000_E_PHY_ID
) match
= TRUE
;
2799 if(hw
->phy_id
== M88E1000_I_PHY_ID
) match
= TRUE
;
2803 case e1000_82545_rev_3
:
2805 case e1000_82546_rev_3
:
2806 if(hw
->phy_id
== M88E1011_I_PHY_ID
) match
= TRUE
;
2809 case e1000_82541_rev_2
:
2811 case e1000_82547_rev_2
:
2812 if(hw
->phy_id
== IGP01E1000_I_PHY_ID
) match
= TRUE
;
2815 DEBUGOUT1("Invalid MAC type %d\n", hw
->mac_type
);
2816 return -E1000_ERR_CONFIG
;
2818 phy_init_status
= e1000_set_phy_type(hw
);
2820 if ((match
) && (phy_init_status
== E1000_SUCCESS
)) {
2821 DEBUGOUT1("PHY ID 0x%X detected\n", hw
->phy_id
);
2822 return E1000_SUCCESS
;
2824 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw
->phy_id
);
2825 return -E1000_ERR_PHY
;
2828 /******************************************************************************
2829 * Resets the PHY's DSP
2831 * hw - Struct containing variables accessed by shared code
2832 ******************************************************************************/
2834 e1000_phy_reset_dsp(struct e1000_hw
*hw
)
2837 DEBUGFUNC("e1000_phy_reset_dsp");
2840 ret_val
= e1000_write_phy_reg(hw
, 29, 0x001d);
2842 ret_val
= e1000_write_phy_reg(hw
, 30, 0x00c1);
2844 ret_val
= e1000_write_phy_reg(hw
, 30, 0x0000);
2846 ret_val
= E1000_SUCCESS
;
2852 /******************************************************************************
2853 * Get PHY information from various PHY registers for igp PHY only.
2855 * hw - Struct containing variables accessed by shared code
2856 * phy_info - PHY information structure
2857 ******************************************************************************/
2859 e1000_phy_igp_get_info(struct e1000_hw
*hw
,
2860 struct e1000_phy_info
*phy_info
)
2863 uint16_t phy_data
, polarity
, min_length
, max_length
, average
;
2865 DEBUGFUNC("e1000_phy_igp_get_info");
2867 /* The downshift status is checked only once, after link is established,
2868 * and it stored in the hw->speed_downgraded parameter. */
2869 phy_info
->downshift
= hw
->speed_downgraded
;
2871 /* IGP01E1000 does not need to support it. */
2872 phy_info
->extended_10bt_distance
= e1000_10bt_ext_dist_enable_normal
;
2874 /* IGP01E1000 always correct polarity reversal */
2875 phy_info
->polarity_correction
= e1000_polarity_reversal_enabled
;
2877 /* Check polarity status */
2878 ret_val
= e1000_check_polarity(hw
, &polarity
);
2882 phy_info
->cable_polarity
= polarity
;
2884 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_PHY_PORT_STATUS
, &phy_data
);
2888 phy_info
->mdix_mode
= (phy_data
& IGP01E1000_PSSR_MDIX
) >>
2889 IGP01E1000_PSSR_MDIX_SHIFT
;
2891 if((phy_data
& IGP01E1000_PSSR_SPEED_MASK
) ==
2892 IGP01E1000_PSSR_SPEED_1000MBPS
) {
2893 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
2894 ret_val
= e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_data
);
2898 phy_info
->local_rx
= (phy_data
& SR_1000T_LOCAL_RX_STATUS
) >>
2899 SR_1000T_LOCAL_RX_STATUS_SHIFT
;
2900 phy_info
->remote_rx
= (phy_data
& SR_1000T_REMOTE_RX_STATUS
) >>
2901 SR_1000T_REMOTE_RX_STATUS_SHIFT
;
2903 /* Get cable length */
2904 ret_val
= e1000_get_cable_length(hw
, &min_length
, &max_length
);
2908 /* transalte to old method */
2909 average
= (max_length
+ min_length
) / 2;
2911 if(average
<= e1000_igp_cable_length_50
)
2912 phy_info
->cable_length
= e1000_cable_length_50
;
2913 else if(average
<= e1000_igp_cable_length_80
)
2914 phy_info
->cable_length
= e1000_cable_length_50_80
;
2915 else if(average
<= e1000_igp_cable_length_110
)
2916 phy_info
->cable_length
= e1000_cable_length_80_110
;
2917 else if(average
<= e1000_igp_cable_length_140
)
2918 phy_info
->cable_length
= e1000_cable_length_110_140
;
2920 phy_info
->cable_length
= e1000_cable_length_140
;
2923 return E1000_SUCCESS
;
2926 /******************************************************************************
2927 * Get PHY information from various PHY registers fot m88 PHY only.
2929 * hw - Struct containing variables accessed by shared code
2930 * phy_info - PHY information structure
2931 ******************************************************************************/
2933 e1000_phy_m88_get_info(struct e1000_hw
*hw
,
2934 struct e1000_phy_info
*phy_info
)
2937 uint16_t phy_data
, polarity
;
2939 DEBUGFUNC("e1000_phy_m88_get_info");
2941 /* The downshift status is checked only once, after link is established,
2942 * and it stored in the hw->speed_downgraded parameter. */
2943 phy_info
->downshift
= hw
->speed_downgraded
;
2945 ret_val
= e1000_read_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
);
2949 phy_info
->extended_10bt_distance
=
2950 (phy_data
& M88E1000_PSCR_10BT_EXT_DIST_ENABLE
) >>
2951 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT
;
2952 phy_info
->polarity_correction
=
2953 (phy_data
& M88E1000_PSCR_POLARITY_REVERSAL
) >>
2954 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT
;
2956 /* Check polarity status */
2957 ret_val
= e1000_check_polarity(hw
, &polarity
);
2960 phy_info
->cable_polarity
= polarity
;
2962 ret_val
= e1000_read_phy_reg(hw
, M88E1000_PHY_SPEC_STATUS
, &phy_data
);
2966 phy_info
->mdix_mode
= (phy_data
& M88E1000_PSSR_MDIX
) >>
2967 M88E1000_PSSR_MDIX_SHIFT
;
2969 if ((phy_data
& M88E1000_PSSR_SPEED
) == M88E1000_PSSR_1000MBS
) {
2970 /* Cable Length Estimation and Local/Remote Receiver Information
2971 * are only valid at 1000 Mbps.
2973 phy_info
->cable_length
= ((phy_data
& M88E1000_PSSR_CABLE_LENGTH
) >>
2974 M88E1000_PSSR_CABLE_LENGTH_SHIFT
);
2976 ret_val
= e1000_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_data
);
2980 phy_info
->local_rx
= (phy_data
& SR_1000T_LOCAL_RX_STATUS
) >>
2981 SR_1000T_LOCAL_RX_STATUS_SHIFT
;
2983 phy_info
->remote_rx
= (phy_data
& SR_1000T_REMOTE_RX_STATUS
) >>
2984 SR_1000T_REMOTE_RX_STATUS_SHIFT
;
2987 return E1000_SUCCESS
;
2990 /******************************************************************************
2991 * Get PHY information from various PHY registers
2993 * hw - Struct containing variables accessed by shared code
2994 * phy_info - PHY information structure
2995 ******************************************************************************/
2997 e1000_phy_get_info(struct e1000_hw
*hw
,
2998 struct e1000_phy_info
*phy_info
)
3003 DEBUGFUNC("e1000_phy_get_info");
3005 phy_info
->cable_length
= e1000_cable_length_undefined
;
3006 phy_info
->extended_10bt_distance
= e1000_10bt_ext_dist_enable_undefined
;
3007 phy_info
->cable_polarity
= e1000_rev_polarity_undefined
;
3008 phy_info
->downshift
= e1000_downshift_undefined
;
3009 phy_info
->polarity_correction
= e1000_polarity_reversal_undefined
;
3010 phy_info
->mdix_mode
= e1000_auto_x_mode_undefined
;
3011 phy_info
->local_rx
= e1000_1000t_rx_status_undefined
;
3012 phy_info
->remote_rx
= e1000_1000t_rx_status_undefined
;
3014 if(hw
->media_type
!= e1000_media_type_copper
) {
3015 DEBUGOUT("PHY info is only valid for copper media\n");
3016 return -E1000_ERR_CONFIG
;
3019 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
);
3023 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
);
3027 if((phy_data
& MII_SR_LINK_STATUS
) != MII_SR_LINK_STATUS
) {
3028 DEBUGOUT("PHY info is only valid if link is up\n");
3029 return -E1000_ERR_CONFIG
;
3032 if(hw
->phy_type
== e1000_phy_igp
)
3033 return e1000_phy_igp_get_info(hw
, phy_info
);
3035 return e1000_phy_m88_get_info(hw
, phy_info
);
3039 e1000_validate_mdi_setting(struct e1000_hw
*hw
)
3041 DEBUGFUNC("e1000_validate_mdi_settings");
3043 if(!hw
->autoneg
&& (hw
->mdix
== 0 || hw
->mdix
== 3)) {
3044 DEBUGOUT("Invalid MDI setting detected\n");
3046 return -E1000_ERR_CONFIG
;
3048 return E1000_SUCCESS
;
3052 /******************************************************************************
3053 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3056 * hw - Struct containing variables accessed by shared code
3057 *****************************************************************************/
3059 e1000_init_eeprom_params(struct e1000_hw
*hw
)
3061 struct e1000_eeprom_info
*eeprom
= &hw
->eeprom
;
3062 uint32_t eecd
= E1000_READ_REG(hw
, EECD
);
3063 uint16_t eeprom_size
;
3065 DEBUGFUNC("e1000_init_eeprom_params");
3067 switch (hw
->mac_type
) {
3068 case e1000_82542_rev2_0
:
3069 case e1000_82542_rev2_1
:
3072 eeprom
->type
= e1000_eeprom_microwire
;
3073 eeprom
->word_size
= 64;
3074 eeprom
->opcode_bits
= 3;
3075 eeprom
->address_bits
= 6;
3076 eeprom
->delay_usec
= 50;
3080 case e1000_82545_rev_3
:
3082 case e1000_82546_rev_3
:
3083 eeprom
->type
= e1000_eeprom_microwire
;
3084 eeprom
->opcode_bits
= 3;
3085 eeprom
->delay_usec
= 50;
3086 if(eecd
& E1000_EECD_SIZE
) {
3087 eeprom
->word_size
= 256;
3088 eeprom
->address_bits
= 8;
3090 eeprom
->word_size
= 64;
3091 eeprom
->address_bits
= 6;
3095 case e1000_82541_rev_2
:
3097 case e1000_82547_rev_2
:
3098 if (eecd
& E1000_EECD_TYPE
) {
3099 eeprom
->type
= e1000_eeprom_spi
;
3100 eeprom
->opcode_bits
= 8;
3101 eeprom
->delay_usec
= 1;
3102 if (eecd
& E1000_EECD_ADDR_BITS
) {
3103 eeprom
->page_size
= 32;
3104 eeprom
->address_bits
= 16;
3106 eeprom
->page_size
= 8;
3107 eeprom
->address_bits
= 8;
3110 eeprom
->type
= e1000_eeprom_microwire
;
3111 eeprom
->opcode_bits
= 3;
3112 eeprom
->delay_usec
= 50;
3113 if (eecd
& E1000_EECD_ADDR_BITS
) {
3114 eeprom
->word_size
= 256;
3115 eeprom
->address_bits
= 8;
3117 eeprom
->word_size
= 64;
3118 eeprom
->address_bits
= 6;
3126 if (eeprom
->type
== e1000_eeprom_spi
) {
3127 eeprom
->word_size
= 64;
3128 if (e1000_read_eeprom(hw
, EEPROM_CFG
, 1, &eeprom_size
) == 0) {
3129 eeprom_size
&= EEPROM_SIZE_MASK
;
3131 switch (eeprom_size
) {
3132 case EEPROM_SIZE_16KB
:
3133 eeprom
->word_size
= 8192;
3135 case EEPROM_SIZE_8KB
:
3136 eeprom
->word_size
= 4096;
3138 case EEPROM_SIZE_4KB
:
3139 eeprom
->word_size
= 2048;
3141 case EEPROM_SIZE_2KB
:
3142 eeprom
->word_size
= 1024;
3144 case EEPROM_SIZE_1KB
:
3145 eeprom
->word_size
= 512;
3147 case EEPROM_SIZE_512B
:
3148 eeprom
->word_size
= 256;
3150 case EEPROM_SIZE_128B
:
3152 eeprom
->word_size
= 64;
3159 /******************************************************************************
3160 * Raises the EEPROM's clock input.
3162 * hw - Struct containing variables accessed by shared code
3163 * eecd - EECD's current value
3164 *****************************************************************************/
3166 e1000_raise_ee_clk(struct e1000_hw
*hw
,
3169 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3170 * wait <delay> microseconds.
3172 *eecd
= *eecd
| E1000_EECD_SK
;
3173 E1000_WRITE_REG(hw
, EECD
, *eecd
);
3174 E1000_WRITE_FLUSH(hw
);
3175 udelay(hw
->eeprom
.delay_usec
);
3178 /******************************************************************************
3179 * Lowers the EEPROM's clock input.
3181 * hw - Struct containing variables accessed by shared code
3182 * eecd - EECD's current value
3183 *****************************************************************************/
3185 e1000_lower_ee_clk(struct e1000_hw
*hw
,
3188 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3189 * wait 50 microseconds.
3191 *eecd
= *eecd
& ~E1000_EECD_SK
;
3192 E1000_WRITE_REG(hw
, EECD
, *eecd
);
3193 E1000_WRITE_FLUSH(hw
);
3194 udelay(hw
->eeprom
.delay_usec
);
3197 /******************************************************************************
3198 * Shift data bits out to the EEPROM.
3200 * hw - Struct containing variables accessed by shared code
3201 * data - data to send to the EEPROM
3202 * count - number of bits to shift out
3203 *****************************************************************************/
3205 e1000_shift_out_ee_bits(struct e1000_hw
*hw
,
3209 struct e1000_eeprom_info
*eeprom
= &hw
->eeprom
;
3213 /* We need to shift "count" bits out to the EEPROM. So, value in the
3214 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3215 * In order to do this, "data" must be broken down into bits.
3217 mask
= 0x01 << (count
- 1);
3218 eecd
= E1000_READ_REG(hw
, EECD
);
3219 if (eeprom
->type
== e1000_eeprom_microwire
) {
3220 eecd
&= ~E1000_EECD_DO
;
3221 } else if (eeprom
->type
== e1000_eeprom_spi
) {
3222 eecd
|= E1000_EECD_DO
;
3225 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3226 * and then raising and then lowering the clock (the SK bit controls
3227 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3228 * by setting "DI" to "0" and then raising and then lowering the clock.
3230 eecd
&= ~E1000_EECD_DI
;
3233 eecd
|= E1000_EECD_DI
;
3235 E1000_WRITE_REG(hw
, EECD
, eecd
);
3236 E1000_WRITE_FLUSH(hw
);
3238 udelay(eeprom
->delay_usec
);
3240 e1000_raise_ee_clk(hw
, &eecd
);
3241 e1000_lower_ee_clk(hw
, &eecd
);
3247 /* We leave the "DI" bit set to "0" when we leave this routine. */
3248 eecd
&= ~E1000_EECD_DI
;
3249 E1000_WRITE_REG(hw
, EECD
, eecd
);
3252 /******************************************************************************
3253 * Shift data bits in from the EEPROM
3255 * hw - Struct containing variables accessed by shared code
3256 *****************************************************************************/
3258 e1000_shift_in_ee_bits(struct e1000_hw
*hw
,
3265 /* In order to read a register from the EEPROM, we need to shift 'count'
3266 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3267 * input to the EEPROM (setting the SK bit), and then reading the value of
3268 * the "DO" bit. During this "shifting in" process the "DI" bit should
3272 eecd
= E1000_READ_REG(hw
, EECD
);
3274 eecd
&= ~(E1000_EECD_DO
| E1000_EECD_DI
);
3277 for(i
= 0; i
< count
; i
++) {
3279 e1000_raise_ee_clk(hw
, &eecd
);
3281 eecd
= E1000_READ_REG(hw
, EECD
);
3283 eecd
&= ~(E1000_EECD_DI
);
3284 if(eecd
& E1000_EECD_DO
)
3287 e1000_lower_ee_clk(hw
, &eecd
);
3293 /******************************************************************************
3294 * Prepares EEPROM for access
3296 * hw - Struct containing variables accessed by shared code
3298 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3299 * function should be called before issuing a command to the EEPROM.
3300 *****************************************************************************/
3302 e1000_acquire_eeprom(struct e1000_hw
*hw
)
3304 struct e1000_eeprom_info
*eeprom
= &hw
->eeprom
;
3307 DEBUGFUNC("e1000_acquire_eeprom");
3309 eecd
= E1000_READ_REG(hw
, EECD
);
3311 /* Request EEPROM Access */
3312 if(hw
->mac_type
> e1000_82544
) {
3313 eecd
|= E1000_EECD_REQ
;
3314 E1000_WRITE_REG(hw
, EECD
, eecd
);
3315 eecd
= E1000_READ_REG(hw
, EECD
);
3316 while((!(eecd
& E1000_EECD_GNT
)) &&
3317 (i
< E1000_EEPROM_GRANT_ATTEMPTS
)) {
3320 eecd
= E1000_READ_REG(hw
, EECD
);
3322 if(!(eecd
& E1000_EECD_GNT
)) {
3323 eecd
&= ~E1000_EECD_REQ
;
3324 E1000_WRITE_REG(hw
, EECD
, eecd
);
3325 DEBUGOUT("Could not acquire EEPROM grant\n");
3326 return -E1000_ERR_EEPROM
;
3330 /* Setup EEPROM for Read/Write */
3332 if (eeprom
->type
== e1000_eeprom_microwire
) {
3333 /* Clear SK and DI */
3334 eecd
&= ~(E1000_EECD_DI
| E1000_EECD_SK
);
3335 E1000_WRITE_REG(hw
, EECD
, eecd
);
3338 eecd
|= E1000_EECD_CS
;
3339 E1000_WRITE_REG(hw
, EECD
, eecd
);
3340 } else if (eeprom
->type
== e1000_eeprom_spi
) {
3341 /* Clear SK and CS */
3342 eecd
&= ~(E1000_EECD_CS
| E1000_EECD_SK
);
3343 E1000_WRITE_REG(hw
, EECD
, eecd
);
3347 return E1000_SUCCESS
;
3350 /******************************************************************************
3351 * Returns EEPROM to a "standby" state
3353 * hw - Struct containing variables accessed by shared code
3354 *****************************************************************************/
3356 e1000_standby_eeprom(struct e1000_hw
*hw
)
3358 struct e1000_eeprom_info
*eeprom
= &hw
->eeprom
;
3361 eecd
= E1000_READ_REG(hw
, EECD
);
3363 if(eeprom
->type
== e1000_eeprom_microwire
) {
3364 eecd
&= ~(E1000_EECD_CS
| E1000_EECD_SK
);
3365 E1000_WRITE_REG(hw
, EECD
, eecd
);
3366 E1000_WRITE_FLUSH(hw
);
3367 udelay(eeprom
->delay_usec
);
3370 eecd
|= E1000_EECD_SK
;
3371 E1000_WRITE_REG(hw
, EECD
, eecd
);
3372 E1000_WRITE_FLUSH(hw
);
3373 udelay(eeprom
->delay_usec
);
3376 eecd
|= E1000_EECD_CS
;
3377 E1000_WRITE_REG(hw
, EECD
, eecd
);
3378 E1000_WRITE_FLUSH(hw
);
3379 udelay(eeprom
->delay_usec
);
3382 eecd
&= ~E1000_EECD_SK
;
3383 E1000_WRITE_REG(hw
, EECD
, eecd
);
3384 E1000_WRITE_FLUSH(hw
);
3385 udelay(eeprom
->delay_usec
);
3386 } else if(eeprom
->type
== e1000_eeprom_spi
) {
3387 /* Toggle CS to flush commands */
3388 eecd
|= E1000_EECD_CS
;
3389 E1000_WRITE_REG(hw
, EECD
, eecd
);
3390 E1000_WRITE_FLUSH(hw
);
3391 udelay(eeprom
->delay_usec
);
3392 eecd
&= ~E1000_EECD_CS
;
3393 E1000_WRITE_REG(hw
, EECD
, eecd
);
3394 E1000_WRITE_FLUSH(hw
);
3395 udelay(eeprom
->delay_usec
);
3399 /******************************************************************************
3400 * Terminates a command by inverting the EEPROM's chip select pin
3402 * hw - Struct containing variables accessed by shared code
3403 *****************************************************************************/
3405 e1000_release_eeprom(struct e1000_hw
*hw
)
3409 DEBUGFUNC("e1000_release_eeprom");
3411 eecd
= E1000_READ_REG(hw
, EECD
);
3413 if (hw
->eeprom
.type
== e1000_eeprom_spi
) {
3414 eecd
|= E1000_EECD_CS
; /* Pull CS high */
3415 eecd
&= ~E1000_EECD_SK
; /* Lower SCK */
3417 E1000_WRITE_REG(hw
, EECD
, eecd
);
3419 udelay(hw
->eeprom
.delay_usec
);
3420 } else if(hw
->eeprom
.type
== e1000_eeprom_microwire
) {
3421 /* cleanup eeprom */
3423 /* CS on Microwire is active-high */
3424 eecd
&= ~(E1000_EECD_CS
| E1000_EECD_DI
);
3426 E1000_WRITE_REG(hw
, EECD
, eecd
);
3428 /* Rising edge of clock */
3429 eecd
|= E1000_EECD_SK
;
3430 E1000_WRITE_REG(hw
, EECD
, eecd
);
3431 E1000_WRITE_FLUSH(hw
);
3432 udelay(hw
->eeprom
.delay_usec
);
3434 /* Falling edge of clock */
3435 eecd
&= ~E1000_EECD_SK
;
3436 E1000_WRITE_REG(hw
, EECD
, eecd
);
3437 E1000_WRITE_FLUSH(hw
);
3438 udelay(hw
->eeprom
.delay_usec
);
3441 /* Stop requesting EEPROM access */
3442 if(hw
->mac_type
> e1000_82544
) {
3443 eecd
&= ~E1000_EECD_REQ
;
3444 E1000_WRITE_REG(hw
, EECD
, eecd
);
3448 /******************************************************************************
3449 * Reads a 16 bit word from the EEPROM.
3451 * hw - Struct containing variables accessed by shared code
3452 *****************************************************************************/
3454 e1000_spi_eeprom_ready(struct e1000_hw
*hw
)
3456 uint16_t retry_count
= 0;
3457 uint8_t spi_stat_reg
;
3459 DEBUGFUNC("e1000_spi_eeprom_ready");
3461 /* Read "Status Register" repeatedly until the LSB is cleared. The
3462 * EEPROM will signal that the command has been completed by clearing
3463 * bit 0 of the internal status register. If it's not cleared within
3464 * 5 milliseconds, then error out.
3468 e1000_shift_out_ee_bits(hw
, EEPROM_RDSR_OPCODE_SPI
,
3469 hw
->eeprom
.opcode_bits
);
3470 spi_stat_reg
= (uint8_t)e1000_shift_in_ee_bits(hw
, 8);
3471 if (!(spi_stat_reg
& EEPROM_STATUS_RDY_SPI
))
3477 e1000_standby_eeprom(hw
);
3478 } while(retry_count
< EEPROM_MAX_RETRY_SPI
);
3480 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3481 * only 0-5mSec on 5V devices)
3483 if(retry_count
>= EEPROM_MAX_RETRY_SPI
) {
3484 DEBUGOUT("SPI EEPROM Status error\n");
3485 return -E1000_ERR_EEPROM
;
3488 return E1000_SUCCESS
;
3491 /******************************************************************************
3492 * Reads a 16 bit word from the EEPROM.
3494 * hw - Struct containing variables accessed by shared code
3495 * offset - offset of word in the EEPROM to read
3496 * data - word read from the EEPROM
3497 * words - number of words to read
3498 *****************************************************************************/
3500 e1000_read_eeprom(struct e1000_hw
*hw
,
3505 struct e1000_eeprom_info
*eeprom
= &hw
->eeprom
;
3508 DEBUGFUNC("e1000_read_eeprom");
3509 /* A check for invalid values: offset too large, too many words, and not
3512 if((offset
>= eeprom
->word_size
) || (words
> eeprom
->word_size
- offset
) ||
3514 DEBUGOUT("\"words\" parameter out of bounds\n");
3515 return -E1000_ERR_EEPROM
;
3518 /* Prepare the EEPROM for reading */
3519 if(e1000_acquire_eeprom(hw
) != E1000_SUCCESS
)
3520 return -E1000_ERR_EEPROM
;
3522 if(eeprom
->type
== e1000_eeprom_spi
) {
3524 uint8_t read_opcode
= EEPROM_READ_OPCODE_SPI
;
3526 if(e1000_spi_eeprom_ready(hw
)) {
3527 e1000_release_eeprom(hw
);
3528 return -E1000_ERR_EEPROM
;
3531 e1000_standby_eeprom(hw
);
3533 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3534 if((eeprom
->address_bits
== 8) && (offset
>= 128))
3535 read_opcode
|= EEPROM_A8_OPCODE_SPI
;
3537 /* Send the READ command (opcode + addr) */
3538 e1000_shift_out_ee_bits(hw
, read_opcode
, eeprom
->opcode_bits
);
3539 e1000_shift_out_ee_bits(hw
, (uint16_t)(offset
*2), eeprom
->address_bits
);
3541 /* Read the data. The address of the eeprom internally increments with
3542 * each byte (spi) being read, saving on the overhead of eeprom setup
3543 * and tear-down. The address counter will roll over if reading beyond
3544 * the size of the eeprom, thus allowing the entire memory to be read
3545 * starting from any offset. */
3546 for (i
= 0; i
< words
; i
++) {
3547 word_in
= e1000_shift_in_ee_bits(hw
, 16);
3548 data
[i
] = (word_in
>> 8) | (word_in
<< 8);
3550 } else if(eeprom
->type
== e1000_eeprom_microwire
) {
3551 for (i
= 0; i
< words
; i
++) {
3552 /* Send the READ command (opcode + addr) */
3553 e1000_shift_out_ee_bits(hw
, EEPROM_READ_OPCODE_MICROWIRE
,
3554 eeprom
->opcode_bits
);
3555 e1000_shift_out_ee_bits(hw
, (uint16_t)(offset
+ i
),
3556 eeprom
->address_bits
);
3558 /* Read the data. For microwire, each word requires the overhead
3559 * of eeprom setup and tear-down. */
3560 data
[i
] = e1000_shift_in_ee_bits(hw
, 16);
3561 e1000_standby_eeprom(hw
);
3565 /* End this read operation */
3566 e1000_release_eeprom(hw
);
3568 return E1000_SUCCESS
;
3571 /******************************************************************************
3572 * Verifies that the EEPROM has a valid checksum
3574 * hw - Struct containing variables accessed by shared code
3576 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3577 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3579 *****************************************************************************/
3581 e1000_validate_eeprom_checksum(struct e1000_hw
*hw
)
3583 uint16_t checksum
= 0;
3584 uint16_t i
, eeprom_data
;
3586 DEBUGFUNC("e1000_validate_eeprom_checksum");
3588 for(i
= 0; i
< (EEPROM_CHECKSUM_REG
+ 1); i
++) {
3589 if(e1000_read_eeprom(hw
, i
, 1, &eeprom_data
) < 0) {
3590 DEBUGOUT("EEPROM Read Error\n");
3591 return -E1000_ERR_EEPROM
;
3593 checksum
+= eeprom_data
;
3596 if(checksum
== (uint16_t) EEPROM_SUM
)
3597 return E1000_SUCCESS
;
3599 DEBUGOUT("EEPROM Checksum Invalid\n");
3600 return -E1000_ERR_EEPROM
;
3604 /******************************************************************************
3605 * Calculates the EEPROM checksum and writes it to the EEPROM
3607 * hw - Struct containing variables accessed by shared code
3609 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
3610 * Writes the difference to word offset 63 of the EEPROM.
3611 *****************************************************************************/
3613 e1000_update_eeprom_checksum(struct e1000_hw
*hw
)
3615 uint16_t checksum
= 0;
3616 uint16_t i
, eeprom_data
;
3618 DEBUGFUNC("e1000_update_eeprom_checksum");
3620 for(i
= 0; i
< EEPROM_CHECKSUM_REG
; i
++) {
3621 if(e1000_read_eeprom(hw
, i
, 1, &eeprom_data
) < 0) {
3622 DEBUGOUT("EEPROM Read Error\n");
3623 return -E1000_ERR_EEPROM
;
3625 checksum
+= eeprom_data
;
3627 checksum
= (uint16_t) EEPROM_SUM
- checksum
;
3628 if(e1000_write_eeprom(hw
, EEPROM_CHECKSUM_REG
, 1, &checksum
) < 0) {
3629 DEBUGOUT("EEPROM Write Error\n");
3630 return -E1000_ERR_EEPROM
;
3632 return E1000_SUCCESS
;
3635 /******************************************************************************
3636 * Parent function for writing words to the different EEPROM types.
3638 * hw - Struct containing variables accessed by shared code
3639 * offset - offset within the EEPROM to be written to
3640 * words - number of words to write
3641 * data - 16 bit word to be written to the EEPROM
3643 * If e1000_update_eeprom_checksum is not called after this function, the
3644 * EEPROM will most likely contain an invalid checksum.
3645 *****************************************************************************/
3647 e1000_write_eeprom(struct e1000_hw
*hw
,
3652 struct e1000_eeprom_info
*eeprom
= &hw
->eeprom
;
3655 DEBUGFUNC("e1000_write_eeprom");
3657 /* A check for invalid values: offset too large, too many words, and not
3660 if((offset
>= eeprom
->word_size
) || (words
> eeprom
->word_size
- offset
) ||
3662 DEBUGOUT("\"words\" parameter out of bounds\n");
3663 return -E1000_ERR_EEPROM
;
3666 /* Prepare the EEPROM for writing */
3667 if (e1000_acquire_eeprom(hw
) != E1000_SUCCESS
)
3668 return -E1000_ERR_EEPROM
;
3670 if(eeprom
->type
== e1000_eeprom_microwire
) {
3671 status
= e1000_write_eeprom_microwire(hw
, offset
, words
, data
);
3673 status
= e1000_write_eeprom_spi(hw
, offset
, words
, data
);
3677 /* Done with writing */
3678 e1000_release_eeprom(hw
);
3683 /******************************************************************************
3684 * Writes a 16 bit word to a given offset in an SPI EEPROM.
3686 * hw - Struct containing variables accessed by shared code
3687 * offset - offset within the EEPROM to be written to
3688 * words - number of words to write
3689 * data - pointer to array of 8 bit words to be written to the EEPROM
3691 *****************************************************************************/
3693 e1000_write_eeprom_spi(struct e1000_hw
*hw
,
3698 struct e1000_eeprom_info
*eeprom
= &hw
->eeprom
;
3701 DEBUGFUNC("e1000_write_eeprom_spi");
3703 while (widx
< words
) {
3704 uint8_t write_opcode
= EEPROM_WRITE_OPCODE_SPI
;
3706 if(e1000_spi_eeprom_ready(hw
)) return -E1000_ERR_EEPROM
;
3708 e1000_standby_eeprom(hw
);
3710 /* Send the WRITE ENABLE command (8 bit opcode ) */
3711 e1000_shift_out_ee_bits(hw
, EEPROM_WREN_OPCODE_SPI
,
3712 eeprom
->opcode_bits
);
3714 e1000_standby_eeprom(hw
);
3716 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3717 if((eeprom
->address_bits
== 8) && (offset
>= 128))
3718 write_opcode
|= EEPROM_A8_OPCODE_SPI
;
3720 /* Send the Write command (8-bit opcode + addr) */
3721 e1000_shift_out_ee_bits(hw
, write_opcode
, eeprom
->opcode_bits
);
3723 e1000_shift_out_ee_bits(hw
, (uint16_t)((offset
+ widx
)*2),
3724 eeprom
->address_bits
);
3728 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
3729 while (widx
< words
) {
3730 uint16_t word_out
= data
[widx
];
3731 word_out
= (word_out
>> 8) | (word_out
<< 8);
3732 e1000_shift_out_ee_bits(hw
, word_out
, 16);
3735 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
3736 * operation, while the smaller eeproms are capable of an 8-byte
3737 * PAGE WRITE operation. Break the inner loop to pass new address
3739 if((((offset
+ widx
)*2) % eeprom
->page_size
) == 0) {
3740 e1000_standby_eeprom(hw
);
3746 return E1000_SUCCESS
;
3749 /******************************************************************************
3750 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
3752 * hw - Struct containing variables accessed by shared code
3753 * offset - offset within the EEPROM to be written to
3754 * words - number of words to write
3755 * data - pointer to array of 16 bit words to be written to the EEPROM
3757 *****************************************************************************/
3759 e1000_write_eeprom_microwire(struct e1000_hw
*hw
,
3764 struct e1000_eeprom_info
*eeprom
= &hw
->eeprom
;
3766 uint16_t words_written
= 0;
3769 DEBUGFUNC("e1000_write_eeprom_microwire");
3771 /* Send the write enable command to the EEPROM (3-bit opcode plus
3772 * 6/8-bit dummy address beginning with 11). It's less work to include
3773 * the 11 of the dummy address as part of the opcode than it is to shift
3774 * it over the correct number of bits for the address. This puts the
3775 * EEPROM into write/erase mode.
3777 e1000_shift_out_ee_bits(hw
, EEPROM_EWEN_OPCODE_MICROWIRE
,
3778 (uint16_t)(eeprom
->opcode_bits
+ 2));
3780 e1000_shift_out_ee_bits(hw
, 0, (uint16_t)(eeprom
->address_bits
- 2));
3782 /* Prepare the EEPROM */
3783 e1000_standby_eeprom(hw
);
3785 while (words_written
< words
) {
3786 /* Send the Write command (3-bit opcode + addr) */
3787 e1000_shift_out_ee_bits(hw
, EEPROM_WRITE_OPCODE_MICROWIRE
,
3788 eeprom
->opcode_bits
);
3790 e1000_shift_out_ee_bits(hw
, (uint16_t)(offset
+ words_written
),
3791 eeprom
->address_bits
);
3794 e1000_shift_out_ee_bits(hw
, data
[words_written
], 16);
3796 /* Toggle the CS line. This in effect tells the EEPROM to execute
3797 * the previous command.
3799 e1000_standby_eeprom(hw
);
3801 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
3802 * signal that the command has been completed by raising the DO signal.
3803 * If DO does not go high in 10 milliseconds, then error out.
3805 for(i
= 0; i
< 200; i
++) {
3806 eecd
= E1000_READ_REG(hw
, EECD
);
3807 if(eecd
& E1000_EECD_DO
) break;
3811 DEBUGOUT("EEPROM Write did not complete\n");
3812 return -E1000_ERR_EEPROM
;
3815 /* Recover from write */
3816 e1000_standby_eeprom(hw
);
3821 /* Send the write disable command to the EEPROM (3-bit opcode plus
3822 * 6/8-bit dummy address beginning with 10). It's less work to include
3823 * the 10 of the dummy address as part of the opcode than it is to shift
3824 * it over the correct number of bits for the address. This takes the
3825 * EEPROM out of write/erase mode.
3827 e1000_shift_out_ee_bits(hw
, EEPROM_EWDS_OPCODE_MICROWIRE
,
3828 (uint16_t)(eeprom
->opcode_bits
+ 2));
3830 e1000_shift_out_ee_bits(hw
, 0, (uint16_t)(eeprom
->address_bits
- 2));
3832 return E1000_SUCCESS
;
3835 /******************************************************************************
3836 * Reads the adapter's part number from the EEPROM
3838 * hw - Struct containing variables accessed by shared code
3839 * part_num - Adapter's part number
3840 *****************************************************************************/
3842 e1000_read_part_num(struct e1000_hw
*hw
,
3845 uint16_t offset
= EEPROM_PBA_BYTE_1
;
3846 uint16_t eeprom_data
;
3848 DEBUGFUNC("e1000_read_part_num");
3850 /* Get word 0 from EEPROM */
3851 if(e1000_read_eeprom(hw
, offset
, 1, &eeprom_data
) < 0) {
3852 DEBUGOUT("EEPROM Read Error\n");
3853 return -E1000_ERR_EEPROM
;
3855 /* Save word 0 in upper half of part_num */
3856 *part_num
= (uint32_t) (eeprom_data
<< 16);
3858 /* Get word 1 from EEPROM */
3859 if(e1000_read_eeprom(hw
, ++offset
, 1, &eeprom_data
) < 0) {
3860 DEBUGOUT("EEPROM Read Error\n");
3861 return -E1000_ERR_EEPROM
;
3863 /* Save word 1 in lower half of part_num */
3864 *part_num
|= eeprom_data
;
3866 return E1000_SUCCESS
;
3869 /******************************************************************************
3870 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
3871 * second function of dual function devices
3873 * hw - Struct containing variables accessed by shared code
3874 *****************************************************************************/
3876 e1000_read_mac_addr(struct e1000_hw
* hw
)
3879 uint16_t eeprom_data
, i
;
3881 DEBUGFUNC("e1000_read_mac_addr");
3883 for(i
= 0; i
< NODE_ADDRESS_SIZE
; i
+= 2) {
3885 if(e1000_read_eeprom(hw
, offset
, 1, &eeprom_data
) < 0) {
3886 DEBUGOUT("EEPROM Read Error\n");
3887 return -E1000_ERR_EEPROM
;
3889 hw
->perm_mac_addr
[i
] = (uint8_t) (eeprom_data
& 0x00FF);
3890 hw
->perm_mac_addr
[i
+1] = (uint8_t) (eeprom_data
>> 8);
3892 if(((hw
->mac_type
== e1000_82546
) || (hw
->mac_type
== e1000_82546_rev_3
)) &&
3893 (E1000_READ_REG(hw
, STATUS
) & E1000_STATUS_FUNC_1
))
3894 hw
->perm_mac_addr
[5] ^= 0x01;
3896 for(i
= 0; i
< NODE_ADDRESS_SIZE
; i
++)
3897 hw
->mac_addr
[i
] = hw
->perm_mac_addr
[i
];
3898 return E1000_SUCCESS
;
3901 /******************************************************************************
3902 * Initializes receive address filters.
3904 * hw - Struct containing variables accessed by shared code
3906 * Places the MAC address in receive address register 0 and clears the rest
3907 * of the receive addresss registers. Clears the multicast table. Assumes
3908 * the receiver is in reset when the routine is called.
3909 *****************************************************************************/
3911 e1000_init_rx_addrs(struct e1000_hw
*hw
)
3915 DEBUGFUNC("e1000_init_rx_addrs");
3917 /* Setup the receive address. */
3918 DEBUGOUT("Programming MAC Address into RAR[0]\n");
3920 e1000_rar_set(hw
, hw
->mac_addr
, 0);
3922 /* Zero out the other 15 receive addresses. */
3923 DEBUGOUT("Clearing RAR[1-15]\n");
3924 for(i
= 1; i
< E1000_RAR_ENTRIES
; i
++) {
3925 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1), 0);
3926 E1000_WRITE_REG_ARRAY(hw
, RA
, ((i
<< 1) + 1), 0);
3930 /******************************************************************************
3931 * Updates the MAC's list of multicast addresses.
3933 * hw - Struct containing variables accessed by shared code
3934 * mc_addr_list - the list of new multicast addresses
3935 * mc_addr_count - number of addresses
3936 * pad - number of bytes between addresses in the list
3937 * rar_used_count - offset where to start adding mc addresses into the RAR's
3939 * The given list replaces any existing list. Clears the last 15 receive
3940 * address registers and the multicast table. Uses receive address registers
3941 * for the first 15 multicast addresses, and hashes the rest into the
3943 *****************************************************************************/
3945 e1000_mc_addr_list_update(struct e1000_hw
*hw
,
3946 uint8_t *mc_addr_list
,
3947 uint32_t mc_addr_count
,
3949 uint32_t rar_used_count
)
3951 uint32_t hash_value
;
3954 DEBUGFUNC("e1000_mc_addr_list_update");
3956 /* Set the new number of MC addresses that we are being requested to use. */
3957 hw
->num_mc_addrs
= mc_addr_count
;
3959 /* Clear RAR[1-15] */
3960 DEBUGOUT(" Clearing RAR[1-15]\n");
3961 for(i
= rar_used_count
; i
< E1000_RAR_ENTRIES
; i
++) {
3962 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1), 0);
3963 E1000_WRITE_REG_ARRAY(hw
, RA
, ((i
<< 1) + 1), 0);
3967 DEBUGOUT(" Clearing MTA\n");
3968 for(i
= 0; i
< E1000_NUM_MTA_REGISTERS
; i
++) {
3969 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, 0);
3972 /* Add the new addresses */
3973 for(i
= 0; i
< mc_addr_count
; i
++) {
3974 DEBUGOUT(" Adding the multicast addresses:\n");
3975 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i
,
3976 mc_addr_list
[i
* (ETH_LENGTH_OF_ADDRESS
+ pad
)],
3977 mc_addr_list
[i
* (ETH_LENGTH_OF_ADDRESS
+ pad
) + 1],
3978 mc_addr_list
[i
* (ETH_LENGTH_OF_ADDRESS
+ pad
) + 2],
3979 mc_addr_list
[i
* (ETH_LENGTH_OF_ADDRESS
+ pad
) + 3],
3980 mc_addr_list
[i
* (ETH_LENGTH_OF_ADDRESS
+ pad
) + 4],
3981 mc_addr_list
[i
* (ETH_LENGTH_OF_ADDRESS
+ pad
) + 5]);
3983 hash_value
= e1000_hash_mc_addr(hw
,
3985 (i
* (ETH_LENGTH_OF_ADDRESS
+ pad
)));
3987 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value
);
3989 /* Place this multicast address in the RAR if there is room, *
3990 * else put it in the MTA
3992 if(rar_used_count
< E1000_RAR_ENTRIES
) {
3994 mc_addr_list
+ (i
* (ETH_LENGTH_OF_ADDRESS
+ pad
)),
3998 e1000_mta_set(hw
, hash_value
);
4001 DEBUGOUT("MC Update Complete\n");
4004 /******************************************************************************
4005 * Hashes an address to determine its location in the multicast table
4007 * hw - Struct containing variables accessed by shared code
4008 * mc_addr - the multicast address to hash
4009 *****************************************************************************/
4011 e1000_hash_mc_addr(struct e1000_hw
*hw
,
4014 uint32_t hash_value
= 0;
4016 /* The portion of the address that is used for the hash table is
4017 * determined by the mc_filter_type setting.
4019 switch (hw
->mc_filter_type
) {
4020 /* [0] [1] [2] [3] [4] [5]
4025 /* [47:36] i.e. 0x563 for above example address */
4026 hash_value
= ((mc_addr
[4] >> 4) | (((uint16_t) mc_addr
[5]) << 4));
4029 /* [46:35] i.e. 0xAC6 for above example address */
4030 hash_value
= ((mc_addr
[4] >> 3) | (((uint16_t) mc_addr
[5]) << 5));
4033 /* [45:34] i.e. 0x5D8 for above example address */
4034 hash_value
= ((mc_addr
[4] >> 2) | (((uint16_t) mc_addr
[5]) << 6));
4037 /* [43:32] i.e. 0x634 for above example address */
4038 hash_value
= ((mc_addr
[4]) | (((uint16_t) mc_addr
[5]) << 8));
4042 hash_value
&= 0xFFF;
4046 /******************************************************************************
4047 * Sets the bit in the multicast table corresponding to the hash value.
4049 * hw - Struct containing variables accessed by shared code
4050 * hash_value - Multicast address hash value
4051 *****************************************************************************/
4053 e1000_mta_set(struct e1000_hw
*hw
,
4054 uint32_t hash_value
)
4056 uint32_t hash_bit
, hash_reg
;
4060 /* The MTA is a register array of 128 32-bit registers.
4061 * It is treated like an array of 4096 bits. We want to set
4062 * bit BitArray[hash_value]. So we figure out what register
4063 * the bit is in, read it, OR in the new bit, then write
4064 * back the new value. The register is determined by the
4065 * upper 7 bits of the hash value and the bit within that
4066 * register are determined by the lower 5 bits of the value.
4068 hash_reg
= (hash_value
>> 5) & 0x7F;
4069 hash_bit
= hash_value
& 0x1F;
4071 mta
= E1000_READ_REG_ARRAY(hw
, MTA
, hash_reg
);
4073 mta
|= (1 << hash_bit
);
4075 /* If we are on an 82544 and we are trying to write an odd offset
4076 * in the MTA, save off the previous entry before writing and
4077 * restore the old value after writing.
4079 if((hw
->mac_type
== e1000_82544
) && ((hash_reg
& 0x1) == 1)) {
4080 temp
= E1000_READ_REG_ARRAY(hw
, MTA
, (hash_reg
- 1));
4081 E1000_WRITE_REG_ARRAY(hw
, MTA
, hash_reg
, mta
);
4082 E1000_WRITE_REG_ARRAY(hw
, MTA
, (hash_reg
- 1), temp
);
4084 E1000_WRITE_REG_ARRAY(hw
, MTA
, hash_reg
, mta
);
4088 /******************************************************************************
4089 * Puts an ethernet address into a receive address register.
4091 * hw - Struct containing variables accessed by shared code
4092 * addr - Address to put into receive address register
4093 * index - Receive address register to write
4094 *****************************************************************************/
4096 e1000_rar_set(struct e1000_hw
*hw
,
4100 uint32_t rar_low
, rar_high
;
4102 /* HW expects these in little endian so we reverse the byte order
4103 * from network order (big endian) to little endian
4105 rar_low
= ((uint32_t) addr
[0] |
4106 ((uint32_t) addr
[1] << 8) |
4107 ((uint32_t) addr
[2] << 16) | ((uint32_t) addr
[3] << 24));
4109 rar_high
= ((uint32_t) addr
[4] | ((uint32_t) addr
[5] << 8) | E1000_RAH_AV
);
4111 E1000_WRITE_REG_ARRAY(hw
, RA
, (index
<< 1), rar_low
);
4112 E1000_WRITE_REG_ARRAY(hw
, RA
, ((index
<< 1) + 1), rar_high
);
4115 /******************************************************************************
4116 * Writes a value to the specified offset in the VLAN filter table.
4118 * hw - Struct containing variables accessed by shared code
4119 * offset - Offset in VLAN filer table to write
4120 * value - Value to write into VLAN filter table
4121 *****************************************************************************/
4123 e1000_write_vfta(struct e1000_hw
*hw
,
4129 if((hw
->mac_type
== e1000_82544
) && ((offset
& 0x1) == 1)) {
4130 temp
= E1000_READ_REG_ARRAY(hw
, VFTA
, (offset
- 1));
4131 E1000_WRITE_REG_ARRAY(hw
, VFTA
, offset
, value
);
4132 E1000_WRITE_REG_ARRAY(hw
, VFTA
, (offset
- 1), temp
);
4134 E1000_WRITE_REG_ARRAY(hw
, VFTA
, offset
, value
);
4138 /******************************************************************************
4139 * Clears the VLAN filer table
4141 * hw - Struct containing variables accessed by shared code
4142 *****************************************************************************/
4144 e1000_clear_vfta(struct e1000_hw
*hw
)
4148 for(offset
= 0; offset
< E1000_VLAN_FILTER_TBL_SIZE
; offset
++)
4149 E1000_WRITE_REG_ARRAY(hw
, VFTA
, offset
, 0);
4153 e1000_id_led_init(struct e1000_hw
* hw
)
4156 const uint32_t ledctl_mask
= 0x000000FF;
4157 const uint32_t ledctl_on
= E1000_LEDCTL_MODE_LED_ON
;
4158 const uint32_t ledctl_off
= E1000_LEDCTL_MODE_LED_OFF
;
4159 uint16_t eeprom_data
, i
, temp
;
4160 const uint16_t led_mask
= 0x0F;
4162 DEBUGFUNC("e1000_id_led_init");
4164 if(hw
->mac_type
< e1000_82540
) {
4166 return E1000_SUCCESS
;
4169 ledctl
= E1000_READ_REG(hw
, LEDCTL
);
4170 hw
->ledctl_default
= ledctl
;
4171 hw
->ledctl_mode1
= hw
->ledctl_default
;
4172 hw
->ledctl_mode2
= hw
->ledctl_default
;
4174 if(e1000_read_eeprom(hw
, EEPROM_ID_LED_SETTINGS
, 1, &eeprom_data
) < 0) {
4175 DEBUGOUT("EEPROM Read Error\n");
4176 return -E1000_ERR_EEPROM
;
4178 if((eeprom_data
== ID_LED_RESERVED_0000
) ||
4179 (eeprom_data
== ID_LED_RESERVED_FFFF
)) eeprom_data
= ID_LED_DEFAULT
;
4180 for(i
= 0; i
< 4; i
++) {
4181 temp
= (eeprom_data
>> (i
<< 2)) & led_mask
;
4183 case ID_LED_ON1_DEF2
:
4184 case ID_LED_ON1_ON2
:
4185 case ID_LED_ON1_OFF2
:
4186 hw
->ledctl_mode1
&= ~(ledctl_mask
<< (i
<< 3));
4187 hw
->ledctl_mode1
|= ledctl_on
<< (i
<< 3);
4189 case ID_LED_OFF1_DEF2
:
4190 case ID_LED_OFF1_ON2
:
4191 case ID_LED_OFF1_OFF2
:
4192 hw
->ledctl_mode1
&= ~(ledctl_mask
<< (i
<< 3));
4193 hw
->ledctl_mode1
|= ledctl_off
<< (i
<< 3);
4200 case ID_LED_DEF1_ON2
:
4201 case ID_LED_ON1_ON2
:
4202 case ID_LED_OFF1_ON2
:
4203 hw
->ledctl_mode2
&= ~(ledctl_mask
<< (i
<< 3));
4204 hw
->ledctl_mode2
|= ledctl_on
<< (i
<< 3);
4206 case ID_LED_DEF1_OFF2
:
4207 case ID_LED_ON1_OFF2
:
4208 case ID_LED_OFF1_OFF2
:
4209 hw
->ledctl_mode2
&= ~(ledctl_mask
<< (i
<< 3));
4210 hw
->ledctl_mode2
|= ledctl_off
<< (i
<< 3);
4217 return E1000_SUCCESS
;
4220 /******************************************************************************
4221 * Prepares SW controlable LED for use and saves the current state of the LED.
4223 * hw - Struct containing variables accessed by shared code
4224 *****************************************************************************/
4226 e1000_setup_led(struct e1000_hw
*hw
)
4229 int32_t ret_val
= E1000_SUCCESS
;
4231 DEBUGFUNC("e1000_setup_led");
4233 switch(hw
->mac_type
) {
4234 case e1000_82542_rev2_0
:
4235 case e1000_82542_rev2_1
:
4238 /* No setup necessary */
4242 case e1000_82541_rev_2
:
4243 case e1000_82547_rev_2
:
4244 /* Turn off PHY Smart Power Down (if enabled) */
4245 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_GMII_FIFO
,
4246 &hw
->phy_spd_default
);
4249 ret_val
= e1000_write_phy_reg(hw
, IGP01E1000_GMII_FIFO
,
4250 (uint16_t)(hw
->phy_spd_default
&
4251 ~IGP01E1000_GMII_SPD
));
4256 if(hw
->media_type
== e1000_media_type_fiber
) {
4257 ledctl
= E1000_READ_REG(hw
, LEDCTL
);
4258 /* Save current LEDCTL settings */
4259 hw
->ledctl_default
= ledctl
;
4261 ledctl
&= ~(E1000_LEDCTL_LED0_IVRT
|
4262 E1000_LEDCTL_LED0_BLINK
|
4263 E1000_LEDCTL_LED0_MODE_MASK
);
4264 ledctl
|= (E1000_LEDCTL_MODE_LED_OFF
<<
4265 E1000_LEDCTL_LED0_MODE_SHIFT
);
4266 E1000_WRITE_REG(hw
, LEDCTL
, ledctl
);
4267 } else if(hw
->media_type
== e1000_media_type_copper
)
4268 E1000_WRITE_REG(hw
, LEDCTL
, hw
->ledctl_mode1
);
4272 return E1000_SUCCESS
;
4275 /******************************************************************************
4276 * Restores the saved state of the SW controlable LED.
4278 * hw - Struct containing variables accessed by shared code
4279 *****************************************************************************/
4281 e1000_cleanup_led(struct e1000_hw
*hw
)
4283 int32_t ret_val
= E1000_SUCCESS
;
4285 DEBUGFUNC("e1000_cleanup_led");
4287 switch(hw
->mac_type
) {
4288 case e1000_82542_rev2_0
:
4289 case e1000_82542_rev2_1
:
4292 /* No cleanup necessary */
4296 case e1000_82541_rev_2
:
4297 case e1000_82547_rev_2
:
4298 /* Turn on PHY Smart Power Down (if previously enabled) */
4299 ret_val
= e1000_write_phy_reg(hw
, IGP01E1000_GMII_FIFO
,
4300 hw
->phy_spd_default
);
4305 /* Restore LEDCTL settings */
4306 E1000_WRITE_REG(hw
, LEDCTL
, hw
->ledctl_default
);
4310 return E1000_SUCCESS
;
4313 /******************************************************************************
4314 * Turns on the software controllable LED
4316 * hw - Struct containing variables accessed by shared code
4317 *****************************************************************************/
4319 e1000_led_on(struct e1000_hw
*hw
)
4321 uint32_t ctrl
= E1000_READ_REG(hw
, CTRL
);
4323 DEBUGFUNC("e1000_led_on");
4325 switch(hw
->mac_type
) {
4326 case e1000_82542_rev2_0
:
4327 case e1000_82542_rev2_1
:
4329 /* Set SW Defineable Pin 0 to turn on the LED */
4330 ctrl
|= E1000_CTRL_SWDPIN0
;
4331 ctrl
|= E1000_CTRL_SWDPIO0
;
4334 if(hw
->media_type
== e1000_media_type_fiber
) {
4335 /* Set SW Defineable Pin 0 to turn on the LED */
4336 ctrl
|= E1000_CTRL_SWDPIN0
;
4337 ctrl
|= E1000_CTRL_SWDPIO0
;
4339 /* Clear SW Defineable Pin 0 to turn on the LED */
4340 ctrl
&= ~E1000_CTRL_SWDPIN0
;
4341 ctrl
|= E1000_CTRL_SWDPIO0
;
4345 if(hw
->media_type
== e1000_media_type_fiber
) {
4346 /* Clear SW Defineable Pin 0 to turn on the LED */
4347 ctrl
&= ~E1000_CTRL_SWDPIN0
;
4348 ctrl
|= E1000_CTRL_SWDPIO0
;
4349 } else if(hw
->media_type
== e1000_media_type_copper
) {
4350 E1000_WRITE_REG(hw
, LEDCTL
, hw
->ledctl_mode2
);
4351 return E1000_SUCCESS
;
4356 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
4358 return E1000_SUCCESS
;
4361 /******************************************************************************
4362 * Turns off the software controllable LED
4364 * hw - Struct containing variables accessed by shared code
4365 *****************************************************************************/
4367 e1000_led_off(struct e1000_hw
*hw
)
4369 uint32_t ctrl
= E1000_READ_REG(hw
, CTRL
);
4371 DEBUGFUNC("e1000_led_off");
4373 switch(hw
->mac_type
) {
4374 case e1000_82542_rev2_0
:
4375 case e1000_82542_rev2_1
:
4377 /* Clear SW Defineable Pin 0 to turn off the LED */
4378 ctrl
&= ~E1000_CTRL_SWDPIN0
;
4379 ctrl
|= E1000_CTRL_SWDPIO0
;
4382 if(hw
->media_type
== e1000_media_type_fiber
) {
4383 /* Clear SW Defineable Pin 0 to turn off the LED */
4384 ctrl
&= ~E1000_CTRL_SWDPIN0
;
4385 ctrl
|= E1000_CTRL_SWDPIO0
;
4387 /* Set SW Defineable Pin 0 to turn off the LED */
4388 ctrl
|= E1000_CTRL_SWDPIN0
;
4389 ctrl
|= E1000_CTRL_SWDPIO0
;
4393 if(hw
->media_type
== e1000_media_type_fiber
) {
4394 /* Set SW Defineable Pin 0 to turn off the LED */
4395 ctrl
|= E1000_CTRL_SWDPIN0
;
4396 ctrl
|= E1000_CTRL_SWDPIO0
;
4397 } else if(hw
->media_type
== e1000_media_type_copper
) {
4398 E1000_WRITE_REG(hw
, LEDCTL
, hw
->ledctl_mode1
);
4399 return E1000_SUCCESS
;
4404 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
4406 return E1000_SUCCESS
;
4409 /******************************************************************************
4410 * Clears all hardware statistics counters.
4412 * hw - Struct containing variables accessed by shared code
4413 *****************************************************************************/
4415 e1000_clear_hw_cntrs(struct e1000_hw
*hw
)
4417 volatile uint32_t temp
;
4419 temp
= E1000_READ_REG(hw
, CRCERRS
);
4420 temp
= E1000_READ_REG(hw
, SYMERRS
);
4421 temp
= E1000_READ_REG(hw
, MPC
);
4422 temp
= E1000_READ_REG(hw
, SCC
);
4423 temp
= E1000_READ_REG(hw
, ECOL
);
4424 temp
= E1000_READ_REG(hw
, MCC
);
4425 temp
= E1000_READ_REG(hw
, LATECOL
);
4426 temp
= E1000_READ_REG(hw
, COLC
);
4427 temp
= E1000_READ_REG(hw
, DC
);
4428 temp
= E1000_READ_REG(hw
, SEC
);
4429 temp
= E1000_READ_REG(hw
, RLEC
);
4430 temp
= E1000_READ_REG(hw
, XONRXC
);
4431 temp
= E1000_READ_REG(hw
, XONTXC
);
4432 temp
= E1000_READ_REG(hw
, XOFFRXC
);
4433 temp
= E1000_READ_REG(hw
, XOFFTXC
);
4434 temp
= E1000_READ_REG(hw
, FCRUC
);
4435 temp
= E1000_READ_REG(hw
, PRC64
);
4436 temp
= E1000_READ_REG(hw
, PRC127
);
4437 temp
= E1000_READ_REG(hw
, PRC255
);
4438 temp
= E1000_READ_REG(hw
, PRC511
);
4439 temp
= E1000_READ_REG(hw
, PRC1023
);
4440 temp
= E1000_READ_REG(hw
, PRC1522
);
4441 temp
= E1000_READ_REG(hw
, GPRC
);
4442 temp
= E1000_READ_REG(hw
, BPRC
);
4443 temp
= E1000_READ_REG(hw
, MPRC
);
4444 temp
= E1000_READ_REG(hw
, GPTC
);
4445 temp
= E1000_READ_REG(hw
, GORCL
);
4446 temp
= E1000_READ_REG(hw
, GORCH
);
4447 temp
= E1000_READ_REG(hw
, GOTCL
);
4448 temp
= E1000_READ_REG(hw
, GOTCH
);
4449 temp
= E1000_READ_REG(hw
, RNBC
);
4450 temp
= E1000_READ_REG(hw
, RUC
);
4451 temp
= E1000_READ_REG(hw
, RFC
);
4452 temp
= E1000_READ_REG(hw
, ROC
);
4453 temp
= E1000_READ_REG(hw
, RJC
);
4454 temp
= E1000_READ_REG(hw
, TORL
);
4455 temp
= E1000_READ_REG(hw
, TORH
);
4456 temp
= E1000_READ_REG(hw
, TOTL
);
4457 temp
= E1000_READ_REG(hw
, TOTH
);
4458 temp
= E1000_READ_REG(hw
, TPR
);
4459 temp
= E1000_READ_REG(hw
, TPT
);
4460 temp
= E1000_READ_REG(hw
, PTC64
);
4461 temp
= E1000_READ_REG(hw
, PTC127
);
4462 temp
= E1000_READ_REG(hw
, PTC255
);
4463 temp
= E1000_READ_REG(hw
, PTC511
);
4464 temp
= E1000_READ_REG(hw
, PTC1023
);
4465 temp
= E1000_READ_REG(hw
, PTC1522
);
4466 temp
= E1000_READ_REG(hw
, MPTC
);
4467 temp
= E1000_READ_REG(hw
, BPTC
);
4469 if(hw
->mac_type
< e1000_82543
) return;
4471 temp
= E1000_READ_REG(hw
, ALGNERRC
);
4472 temp
= E1000_READ_REG(hw
, RXERRC
);
4473 temp
= E1000_READ_REG(hw
, TNCRS
);
4474 temp
= E1000_READ_REG(hw
, CEXTERR
);
4475 temp
= E1000_READ_REG(hw
, TSCTC
);
4476 temp
= E1000_READ_REG(hw
, TSCTFC
);
4478 if(hw
->mac_type
<= e1000_82544
) return;
4480 temp
= E1000_READ_REG(hw
, MGTPRC
);
4481 temp
= E1000_READ_REG(hw
, MGTPDC
);
4482 temp
= E1000_READ_REG(hw
, MGTPTC
);
4485 /******************************************************************************
4486 * Resets Adaptive IFS to its default state.
4488 * hw - Struct containing variables accessed by shared code
4490 * Call this after e1000_init_hw. You may override the IFS defaults by setting
4491 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
4492 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4493 * before calling this function.
4494 *****************************************************************************/
4496 e1000_reset_adaptive(struct e1000_hw
*hw
)
4498 DEBUGFUNC("e1000_reset_adaptive");
4500 if(hw
->adaptive_ifs
) {
4501 if(!hw
->ifs_params_forced
) {
4502 hw
->current_ifs_val
= 0;
4503 hw
->ifs_min_val
= IFS_MIN
;
4504 hw
->ifs_max_val
= IFS_MAX
;
4505 hw
->ifs_step_size
= IFS_STEP
;
4506 hw
->ifs_ratio
= IFS_RATIO
;
4508 hw
->in_ifs_mode
= FALSE
;
4509 E1000_WRITE_REG(hw
, AIT
, 0);
4511 DEBUGOUT("Not in Adaptive IFS mode!\n");
4515 /******************************************************************************
4516 * Called during the callback/watchdog routine to update IFS value based on
4517 * the ratio of transmits to collisions.
4519 * hw - Struct containing variables accessed by shared code
4520 * tx_packets - Number of transmits since last callback
4521 * total_collisions - Number of collisions since last callback
4522 *****************************************************************************/
4524 e1000_update_adaptive(struct e1000_hw
*hw
)
4526 DEBUGFUNC("e1000_update_adaptive");
4528 if(hw
->adaptive_ifs
) {
4529 if((hw
->collision_delta
* hw
->ifs_ratio
) > hw
->tx_packet_delta
) {
4530 if(hw
->tx_packet_delta
> MIN_NUM_XMITS
) {
4531 hw
->in_ifs_mode
= TRUE
;
4532 if(hw
->current_ifs_val
< hw
->ifs_max_val
) {
4533 if(hw
->current_ifs_val
== 0)
4534 hw
->current_ifs_val
= hw
->ifs_min_val
;
4536 hw
->current_ifs_val
+= hw
->ifs_step_size
;
4537 E1000_WRITE_REG(hw
, AIT
, hw
->current_ifs_val
);
4541 if(hw
->in_ifs_mode
&& (hw
->tx_packet_delta
<= MIN_NUM_XMITS
)) {
4542 hw
->current_ifs_val
= 0;
4543 hw
->in_ifs_mode
= FALSE
;
4544 E1000_WRITE_REG(hw
, AIT
, 0);
4548 DEBUGOUT("Not in Adaptive IFS mode!\n");
4552 /******************************************************************************
4553 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4555 * hw - Struct containing variables accessed by shared code
4556 * frame_len - The length of the frame in question
4557 * mac_addr - The Ethernet destination address of the frame in question
4558 *****************************************************************************/
4560 e1000_tbi_adjust_stats(struct e1000_hw
*hw
,
4561 struct e1000_hw_stats
*stats
,
4567 /* First adjust the frame length. */
4569 /* We need to adjust the statistics counters, since the hardware
4570 * counters overcount this packet as a CRC error and undercount
4571 * the packet as a good packet
4573 /* This packet should not be counted as a CRC error. */
4575 /* This packet does count as a Good Packet Received. */
4578 /* Adjust the Good Octets received counters */
4579 carry_bit
= 0x80000000 & stats
->gorcl
;
4580 stats
->gorcl
+= frame_len
;
4581 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4582 * Received Count) was one before the addition,
4583 * AND it is zero after, then we lost the carry out,
4584 * need to add one to Gorch (Good Octets Received Count High).
4585 * This could be simplified if all environments supported
4588 if(carry_bit
&& ((stats
->gorcl
& 0x80000000) == 0))
4590 /* Is this a broadcast or multicast? Check broadcast first,
4591 * since the test for a multicast frame will test positive on
4592 * a broadcast frame.
4594 if((mac_addr
[0] == (uint8_t) 0xff) && (mac_addr
[1] == (uint8_t) 0xff))
4595 /* Broadcast packet */
4597 else if(*mac_addr
& 0x01)
4598 /* Multicast packet */
4601 if(frame_len
== hw
->max_frame_size
) {
4602 /* In this case, the hardware has overcounted the number of
4609 /* Adjust the bin counters when the extra byte put the frame in the
4610 * wrong bin. Remember that the frame_len was adjusted above.
4612 if(frame_len
== 64) {
4615 } else if(frame_len
== 127) {
4618 } else if(frame_len
== 255) {
4621 } else if(frame_len
== 511) {
4624 } else if(frame_len
== 1023) {
4627 } else if(frame_len
== 1522) {
4632 /******************************************************************************
4633 * Gets the current PCI bus type, speed, and width of the hardware
4635 * hw - Struct containing variables accessed by shared code
4636 *****************************************************************************/
4638 e1000_get_bus_info(struct e1000_hw
*hw
)
4642 switch (hw
->mac_type
) {
4643 case e1000_82542_rev2_0
:
4644 case e1000_82542_rev2_1
:
4645 hw
->bus_type
= e1000_bus_type_unknown
;
4646 hw
->bus_speed
= e1000_bus_speed_unknown
;
4647 hw
->bus_width
= e1000_bus_width_unknown
;
4650 status
= E1000_READ_REG(hw
, STATUS
);
4651 hw
->bus_type
= (status
& E1000_STATUS_PCIX_MODE
) ?
4652 e1000_bus_type_pcix
: e1000_bus_type_pci
;
4654 if(hw
->device_id
== E1000_DEV_ID_82546EB_QUAD_COPPER
) {
4655 hw
->bus_speed
= (hw
->bus_type
== e1000_bus_type_pci
) ?
4656 e1000_bus_speed_66
: e1000_bus_speed_120
;
4657 } else if(hw
->bus_type
== e1000_bus_type_pci
) {
4658 hw
->bus_speed
= (status
& E1000_STATUS_PCI66
) ?
4659 e1000_bus_speed_66
: e1000_bus_speed_33
;
4661 switch (status
& E1000_STATUS_PCIX_SPEED
) {
4662 case E1000_STATUS_PCIX_SPEED_66
:
4663 hw
->bus_speed
= e1000_bus_speed_66
;
4665 case E1000_STATUS_PCIX_SPEED_100
:
4666 hw
->bus_speed
= e1000_bus_speed_100
;
4668 case E1000_STATUS_PCIX_SPEED_133
:
4669 hw
->bus_speed
= e1000_bus_speed_133
;
4672 hw
->bus_speed
= e1000_bus_speed_reserved
;
4676 hw
->bus_width
= (status
& E1000_STATUS_BUS64
) ?
4677 e1000_bus_width_64
: e1000_bus_width_32
;
4681 /******************************************************************************
4682 * Reads a value from one of the devices registers using port I/O (as opposed
4683 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4685 * hw - Struct containing variables accessed by shared code
4686 * offset - offset to read from
4687 *****************************************************************************/
4689 e1000_read_reg_io(struct e1000_hw
*hw
,
4692 unsigned long io_addr
= hw
->io_base
;
4693 unsigned long io_data
= hw
->io_base
+ 4;
4695 e1000_io_write(hw
, io_addr
, offset
);
4696 return e1000_io_read(hw
, io_data
);
4699 /******************************************************************************
4700 * Writes a value to one of the devices registers using port I/O (as opposed to
4701 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4703 * hw - Struct containing variables accessed by shared code
4704 * offset - offset to write to
4705 * value - value to write
4706 *****************************************************************************/
4708 e1000_write_reg_io(struct e1000_hw
*hw
,
4712 unsigned long io_addr
= hw
->io_base
;
4713 unsigned long io_data
= hw
->io_base
+ 4;
4715 e1000_io_write(hw
, io_addr
, offset
);
4716 e1000_io_write(hw
, io_data
, value
);
4720 /******************************************************************************
4721 * Estimates the cable length.
4723 * hw - Struct containing variables accessed by shared code
4724 * min_length - The estimated minimum length
4725 * max_length - The estimated maximum length
4727 * returns: - E1000_ERR_XXX
4730 * This function always returns a ranged length (minimum & maximum).
4731 * So for M88 phy's, this function interprets the one value returned from the
4732 * register to the minimum and maximum range.
4733 * For IGP phy's, the function calculates the range by the AGC registers.
4734 *****************************************************************************/
4736 e1000_get_cable_length(struct e1000_hw
*hw
,
4737 uint16_t *min_length
,
4738 uint16_t *max_length
)
4741 uint16_t agc_value
= 0;
4742 uint16_t cur_agc
, min_agc
= IGP01E1000_AGC_LENGTH_TABLE_SIZE
;
4743 uint16_t i
, phy_data
;
4744 uint16_t cable_length
;
4746 DEBUGFUNC("e1000_get_cable_length");
4748 *min_length
= *max_length
= 0;
4750 /* Use old method for Phy older than IGP */
4751 if(hw
->phy_type
== e1000_phy_m88
) {
4752 ret_val
= e1000_read_phy_reg(hw
, M88E1000_PHY_SPEC_STATUS
,
4756 cable_length
= (phy_data
& M88E1000_PSSR_CABLE_LENGTH
) >>
4757 M88E1000_PSSR_CABLE_LENGTH_SHIFT
;
4759 /* Convert the enum value to ranged values */
4760 switch (cable_length
) {
4761 case e1000_cable_length_50
:
4763 *max_length
= e1000_igp_cable_length_50
;
4765 case e1000_cable_length_50_80
:
4766 *min_length
= e1000_igp_cable_length_50
;
4767 *max_length
= e1000_igp_cable_length_80
;
4769 case e1000_cable_length_80_110
:
4770 *min_length
= e1000_igp_cable_length_80
;
4771 *max_length
= e1000_igp_cable_length_110
;
4773 case e1000_cable_length_110_140
:
4774 *min_length
= e1000_igp_cable_length_110
;
4775 *max_length
= e1000_igp_cable_length_140
;
4777 case e1000_cable_length_140
:
4778 *min_length
= e1000_igp_cable_length_140
;
4779 *max_length
= e1000_igp_cable_length_170
;
4782 return -E1000_ERR_PHY
;
4785 } else if(hw
->phy_type
== e1000_phy_igp
) { /* For IGP PHY */
4786 uint16_t agc_reg_array
[IGP01E1000_PHY_CHANNEL_NUM
] =
4787 {IGP01E1000_PHY_AGC_A
,
4788 IGP01E1000_PHY_AGC_B
,
4789 IGP01E1000_PHY_AGC_C
,
4790 IGP01E1000_PHY_AGC_D
};
4791 /* Read the AGC registers for all channels */
4792 for(i
= 0; i
< IGP01E1000_PHY_CHANNEL_NUM
; i
++) {
4794 ret_val
= e1000_read_phy_reg(hw
, agc_reg_array
[i
], &phy_data
);
4798 cur_agc
= phy_data
>> IGP01E1000_AGC_LENGTH_SHIFT
;
4800 /* Array bound check. */
4801 if((cur_agc
>= IGP01E1000_AGC_LENGTH_TABLE_SIZE
- 1) ||
4803 return -E1000_ERR_PHY
;
4805 agc_value
+= cur_agc
;
4807 /* Update minimal AGC value. */
4808 if(min_agc
> cur_agc
)
4812 /* Remove the minimal AGC result for length < 50m */
4813 if(agc_value
< IGP01E1000_PHY_CHANNEL_NUM
* e1000_igp_cable_length_50
) {
4814 agc_value
-= min_agc
;
4816 /* Get the average length of the remaining 3 channels */
4817 agc_value
/= (IGP01E1000_PHY_CHANNEL_NUM
- 1);
4819 /* Get the average length of all the 4 channels. */
4820 agc_value
/= IGP01E1000_PHY_CHANNEL_NUM
;
4823 /* Set the range of the calculated length. */
4824 *min_length
= ((e1000_igp_cable_length_table
[agc_value
] -
4825 IGP01E1000_AGC_RANGE
) > 0) ?
4826 (e1000_igp_cable_length_table
[agc_value
] -
4827 IGP01E1000_AGC_RANGE
) : 0;
4828 *max_length
= e1000_igp_cable_length_table
[agc_value
] +
4829 IGP01E1000_AGC_RANGE
;
4832 return E1000_SUCCESS
;
4835 /******************************************************************************
4836 * Check the cable polarity
4838 * hw - Struct containing variables accessed by shared code
4839 * polarity - output parameter : 0 - Polarity is not reversed
4840 * 1 - Polarity is reversed.
4842 * returns: - E1000_ERR_XXX
4845 * For phy's older then IGP, this function simply reads the polarity bit in the
4846 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
4847 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
4848 * return 0. If the link speed is 1000 Mbps the polarity status is in the
4849 * IGP01E1000_PHY_PCS_INIT_REG.
4850 *****************************************************************************/
4852 e1000_check_polarity(struct e1000_hw
*hw
,
4858 DEBUGFUNC("e1000_check_polarity");
4860 if(hw
->phy_type
== e1000_phy_m88
) {
4861 /* return the Polarity bit in the Status register. */
4862 ret_val
= e1000_read_phy_reg(hw
, M88E1000_PHY_SPEC_STATUS
,
4866 *polarity
= (phy_data
& M88E1000_PSSR_REV_POLARITY
) >>
4867 M88E1000_PSSR_REV_POLARITY_SHIFT
;
4868 } else if(hw
->phy_type
== e1000_phy_igp
) {
4869 /* Read the Status register to check the speed */
4870 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_PHY_PORT_STATUS
,
4875 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
4876 * find the polarity status */
4877 if((phy_data
& IGP01E1000_PSSR_SPEED_MASK
) ==
4878 IGP01E1000_PSSR_SPEED_1000MBPS
) {
4880 /* Read the GIG initialization PCS register (0x00B4) */
4881 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_PHY_PCS_INIT_REG
,
4886 /* Check the polarity bits */
4887 *polarity
= (phy_data
& IGP01E1000_PHY_POLARITY_MASK
) ? 1 : 0;
4889 /* For 10 Mbps, read the polarity bit in the status register. (for
4890 * 100 Mbps this bit is always 0) */
4891 *polarity
= phy_data
& IGP01E1000_PSSR_POLARITY_REVERSED
;
4894 return E1000_SUCCESS
;
4897 /******************************************************************************
4898 * Check if Downshift occured
4900 * hw - Struct containing variables accessed by shared code
4901 * downshift - output parameter : 0 - No Downshift ocured.
4902 * 1 - Downshift ocured.
4904 * returns: - E1000_ERR_XXX
4907 * For phy's older then IGP, this function reads the Downshift bit in the Phy
4908 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
4909 * Link Health register. In IGP this bit is latched high, so the driver must
4910 * read it immediately after link is established.
4911 *****************************************************************************/
4913 e1000_check_downshift(struct e1000_hw
*hw
)
4918 DEBUGFUNC("e1000_check_downshift");
4920 if(hw
->phy_type
== e1000_phy_igp
) {
4921 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_PHY_LINK_HEALTH
,
4926 hw
->speed_downgraded
= (phy_data
& IGP01E1000_PLHR_SS_DOWNGRADE
) ? 1 : 0;
4927 } else if(hw
->phy_type
== e1000_phy_m88
) {
4928 ret_val
= e1000_read_phy_reg(hw
, M88E1000_PHY_SPEC_STATUS
,
4933 hw
->speed_downgraded
= (phy_data
& M88E1000_PSSR_DOWNSHIFT
) >>
4934 M88E1000_PSSR_DOWNSHIFT_SHIFT
;
4936 return E1000_SUCCESS
;
4939 /*****************************************************************************
4941 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
4942 * gigabit link is achieved to improve link quality.
4944 * hw: Struct containing variables accessed by shared code
4946 * returns: - E1000_ERR_PHY if fail to read/write the PHY
4947 * E1000_SUCCESS at any other case.
4949 ****************************************************************************/
4952 e1000_config_dsp_after_link_change(struct e1000_hw
*hw
,
4956 uint16_t phy_data
, phy_saved_data
, speed
, duplex
, i
;
4957 uint16_t dsp_reg_array
[IGP01E1000_PHY_CHANNEL_NUM
] =
4958 {IGP01E1000_PHY_AGC_PARAM_A
,
4959 IGP01E1000_PHY_AGC_PARAM_B
,
4960 IGP01E1000_PHY_AGC_PARAM_C
,
4961 IGP01E1000_PHY_AGC_PARAM_D
};
4962 uint16_t min_length
, max_length
;
4964 DEBUGFUNC("e1000_config_dsp_after_link_change");
4966 if(hw
->phy_type
!= e1000_phy_igp
)
4967 return E1000_SUCCESS
;
4970 ret_val
= e1000_get_speed_and_duplex(hw
, &speed
, &duplex
);
4972 DEBUGOUT("Error getting link speed and duplex\n");
4976 if(speed
== SPEED_1000
) {
4978 e1000_get_cable_length(hw
, &min_length
, &max_length
);
4980 if((hw
->dsp_config_state
== e1000_dsp_config_enabled
) &&
4981 min_length
>= e1000_igp_cable_length_50
) {
4983 for(i
= 0; i
< IGP01E1000_PHY_CHANNEL_NUM
; i
++) {
4984 ret_val
= e1000_read_phy_reg(hw
, dsp_reg_array
[i
],
4989 phy_data
&= ~IGP01E1000_PHY_EDAC_MU_INDEX
;
4991 ret_val
= e1000_write_phy_reg(hw
, dsp_reg_array
[i
],
4996 hw
->dsp_config_state
= e1000_dsp_config_activated
;
4999 if((hw
->ffe_config_state
== e1000_ffe_config_enabled
) &&
5000 (min_length
< e1000_igp_cable_length_50
)) {
5002 uint16_t ffe_idle_err_timeout
= FFE_IDLE_ERR_COUNT_TIMEOUT_20
;
5003 uint32_t idle_errs
= 0;
5005 /* clear previous idle error counts */
5006 ret_val
= e1000_read_phy_reg(hw
, PHY_1000T_STATUS
,
5011 for(i
= 0; i
< ffe_idle_err_timeout
; i
++) {
5013 ret_val
= e1000_read_phy_reg(hw
, PHY_1000T_STATUS
,
5018 idle_errs
+= (phy_data
& SR_1000T_IDLE_ERROR_CNT
);
5019 if(idle_errs
> SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT
) {
5020 hw
->ffe_config_state
= e1000_ffe_config_active
;
5022 ret_val
= e1000_write_phy_reg(hw
,
5023 IGP01E1000_PHY_DSP_FFE
,
5024 IGP01E1000_PHY_DSP_FFE_CM_CP
);
5031 ffe_idle_err_timeout
= FFE_IDLE_ERR_COUNT_TIMEOUT_100
;
5036 if(hw
->dsp_config_state
== e1000_dsp_config_activated
) {
5037 /* Save off the current value of register 0x2F5B to be restored at
5038 * the end of the routines. */
5039 ret_val
= e1000_read_phy_reg(hw
, 0x2F5B, &phy_saved_data
);
5044 /* Disable the PHY transmitter */
5045 ret_val
= e1000_write_phy_reg(hw
, 0x2F5B, 0x0003);
5052 ret_val
= e1000_write_phy_reg(hw
, 0x0000,
5053 IGP01E1000_IEEE_FORCE_GIGA
);
5056 for(i
= 0; i
< IGP01E1000_PHY_CHANNEL_NUM
; i
++) {
5057 ret_val
= e1000_read_phy_reg(hw
, dsp_reg_array
[i
], &phy_data
);
5061 phy_data
&= ~IGP01E1000_PHY_EDAC_MU_INDEX
;
5062 phy_data
|= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS
;
5064 ret_val
= e1000_write_phy_reg(hw
,dsp_reg_array
[i
], phy_data
);
5069 ret_val
= e1000_write_phy_reg(hw
, 0x0000,
5070 IGP01E1000_IEEE_RESTART_AUTONEG
);
5076 /* Now enable the transmitter */
5077 ret_val
= e1000_write_phy_reg(hw
, 0x2F5B, phy_saved_data
);
5082 hw
->dsp_config_state
= e1000_dsp_config_enabled
;
5085 if(hw
->ffe_config_state
== e1000_ffe_config_active
) {
5086 /* Save off the current value of register 0x2F5B to be restored at
5087 * the end of the routines. */
5088 ret_val
= e1000_read_phy_reg(hw
, 0x2F5B, &phy_saved_data
);
5093 /* Disable the PHY transmitter */
5094 ret_val
= e1000_write_phy_reg(hw
, 0x2F5B, 0x0003);
5101 ret_val
= e1000_write_phy_reg(hw
, 0x0000,
5102 IGP01E1000_IEEE_FORCE_GIGA
);
5105 ret_val
= e1000_write_phy_reg(hw
, IGP01E1000_PHY_DSP_FFE
,
5106 IGP01E1000_PHY_DSP_FFE_DEFAULT
);
5110 ret_val
= e1000_write_phy_reg(hw
, 0x0000,
5111 IGP01E1000_IEEE_RESTART_AUTONEG
);
5117 /* Now enable the transmitter */
5118 ret_val
= e1000_write_phy_reg(hw
, 0x2F5B, phy_saved_data
);
5123 hw
->ffe_config_state
= e1000_ffe_config_enabled
;
5126 return E1000_SUCCESS
;
5129 /*****************************************************************************
5130 * Set PHY to class A mode
5131 * Assumes the following operations will follow to enable the new class mode.
5132 * 1. Do a PHY soft reset
5133 * 2. Restart auto-negotiation or force link.
5135 * hw - Struct containing variables accessed by shared code
5136 ****************************************************************************/
5138 e1000_set_phy_mode(struct e1000_hw
*hw
)
5141 uint16_t eeprom_data
;
5143 DEBUGFUNC("e1000_set_phy_mode");
5145 if((hw
->mac_type
== e1000_82545_rev_3
) &&
5146 (hw
->media_type
== e1000_media_type_copper
)) {
5147 ret_val
= e1000_read_eeprom(hw
, EEPROM_PHY_CLASS_WORD
, 1, &eeprom_data
);
5152 if((eeprom_data
!= EEPROM_RESERVED_WORD
) &&
5153 (eeprom_data
& EEPROM_PHY_CLASS_A
)) {
5154 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_PAGE_SELECT
, 0x000B);
5157 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_GEN_CONTROL
, 0x8104);
5161 hw
->phy_reset_disable
= FALSE
;
5165 return E1000_SUCCESS
;
5168 /*****************************************************************************
5170 * This function sets the lplu state according to the active flag. When
5171 * activating lplu this function also disables smart speed and vise versa.
5172 * lplu will not be activated unless the device autonegotiation advertisment
5173 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5174 * hw: Struct containing variables accessed by shared code
5175 * active - true to enable lplu false to disable lplu.
5177 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5178 * E1000_SUCCESS at any other case.
5180 ****************************************************************************/
5183 e1000_set_d3_lplu_state(struct e1000_hw
*hw
,
5188 DEBUGFUNC("e1000_set_d3_lplu_state");
5190 if(!((hw
->mac_type
== e1000_82541_rev_2
) ||
5191 (hw
->mac_type
== e1000_82547_rev_2
)))
5192 return E1000_SUCCESS
;
5194 /* During driver activity LPLU should not be used or it will attain link
5195 * from the lowest speeds starting from 10Mbps. The capability is used for
5196 * Dx transitions and states */
5197 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_GMII_FIFO
, &phy_data
);
5202 phy_data
&= ~IGP01E1000_GMII_FLEX_SPD
;
5203 ret_val
= e1000_write_phy_reg(hw
, IGP01E1000_GMII_FIFO
, phy_data
);
5207 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5208 * Dx states where the power conservation is most important. During
5209 * driver activity we should enable SmartSpeed, so performance is
5211 if (hw
->smart_speed
== e1000_smart_speed_on
) {
5212 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_PHY_PORT_CONFIG
,
5217 phy_data
|= IGP01E1000_PSCFR_SMART_SPEED
;
5218 ret_val
= e1000_write_phy_reg(hw
, IGP01E1000_PHY_PORT_CONFIG
,
5222 } else if (hw
->smart_speed
== e1000_smart_speed_off
) {
5223 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_PHY_PORT_CONFIG
,
5228 phy_data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
5229 ret_val
= e1000_write_phy_reg(hw
, IGP01E1000_PHY_PORT_CONFIG
,
5235 } else if((hw
->autoneg_advertised
== AUTONEG_ADVERTISE_SPEED_DEFAULT
) ||
5236 (hw
->autoneg_advertised
== AUTONEG_ADVERTISE_10_ALL
) ||
5237 (hw
->autoneg_advertised
== AUTONEG_ADVERTISE_10_100_ALL
)) {
5239 phy_data
|= IGP01E1000_GMII_FLEX_SPD
;
5240 ret_val
= e1000_write_phy_reg(hw
, IGP01E1000_GMII_FIFO
, phy_data
);
5244 /* When LPLU is enabled we should disable SmartSpeed */
5245 ret_val
= e1000_read_phy_reg(hw
, IGP01E1000_PHY_PORT_CONFIG
, &phy_data
);
5249 phy_data
&= ~IGP01E1000_PSCFR_SMART_SPEED
;
5250 ret_val
= e1000_write_phy_reg(hw
, IGP01E1000_PHY_PORT_CONFIG
, phy_data
);
5255 return E1000_SUCCESS
;
5258 /******************************************************************************
5259 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5261 * hw - Struct containing variables accessed by shared code
5262 *****************************************************************************/
5264 e1000_set_vco_speed(struct e1000_hw
*hw
)
5267 uint16_t default_page
= 0;
5270 DEBUGFUNC("e1000_set_vco_speed");
5272 switch(hw
->mac_type
) {
5273 case e1000_82545_rev_3
:
5274 case e1000_82546_rev_3
:
5277 return E1000_SUCCESS
;
5280 /* Set PHY register 30, page 5, bit 8 to 0 */
5282 ret_val
= e1000_read_phy_reg(hw
, M88E1000_PHY_PAGE_SELECT
, &default_page
);
5286 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_PAGE_SELECT
, 0x0005);
5290 ret_val
= e1000_read_phy_reg(hw
, M88E1000_PHY_GEN_CONTROL
, &phy_data
);
5294 phy_data
&= ~M88E1000_PHY_VCO_REG_BIT8
;
5295 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_GEN_CONTROL
, phy_data
);
5299 /* Set PHY register 30, page 4, bit 11 to 1 */
5301 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_PAGE_SELECT
, 0x0004);
5305 ret_val
= e1000_read_phy_reg(hw
, M88E1000_PHY_GEN_CONTROL
, &phy_data
);
5309 phy_data
|= M88E1000_PHY_VCO_REG_BIT11
;
5310 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_GEN_CONTROL
, phy_data
);
5314 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_PAGE_SELECT
, default_page
);
5318 return E1000_SUCCESS
;
5322 e1000_polarity_reversal_workaround(struct e1000_hw
*hw
)
5325 uint16_t mii_status_reg
;
5328 /* Polarity reversal workaround for forced 10F/10H links. */
5330 /* Disable the transmitter on the PHY */
5332 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_PAGE_SELECT
, 0x0019);
5335 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_GEN_CONTROL
, 0xFFFF);
5339 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_PAGE_SELECT
, 0x0000);
5343 /* This loop will early-out if the NO link condition has been met. */
5344 for(i
= PHY_FORCE_TIME
; i
> 0; i
--) {
5345 /* Read the MII Status Register and wait for Link Status bit
5349 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &mii_status_reg
);
5353 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &mii_status_reg
);
5357 if((mii_status_reg
& ~MII_SR_LINK_STATUS
) == 0) break;
5358 msec_delay_irq(100);
5361 /* Recommended delay time after link has been lost */
5362 msec_delay_irq(1000);
5364 /* Now we will re-enable th transmitter on the PHY */
5366 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_PAGE_SELECT
, 0x0019);
5370 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_GEN_CONTROL
, 0xFFF0);
5374 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_GEN_CONTROL
, 0xFF00);
5378 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_GEN_CONTROL
, 0x0000);
5382 ret_val
= e1000_write_phy_reg(hw
, M88E1000_PHY_PAGE_SELECT
, 0x0000);
5386 /* This loop will early-out if the link condition has been met. */
5387 for(i
= PHY_FORCE_TIME
; i
> 0; i
--) {
5388 /* Read the MII Status Register and wait for Link Status bit
5392 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &mii_status_reg
);
5396 ret_val
= e1000_read_phy_reg(hw
, PHY_STATUS
, &mii_status_reg
);
5400 if(mii_status_reg
& MII_SR_LINK_STATUS
) break;
5401 msec_delay_irq(100);
5403 return E1000_SUCCESS
;