1 /**************************************************************************
2 Inter Pro 1000 for ppcboot/das-u-boot
3 Drivers are port from Intel's Linux driver e1000-4.3.15
4 and from Etherboot pro 1000 driver by mrakes at vivato dot net
5 tested on both gig copper and gig fiber boards
6 ***************************************************************************/
7 /*******************************************************************************
10 Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by the Free
14 Software Foundation; either version 2 of the License, or (at your option)
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc., 59
24 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 The full GNU General Public License is included in this distribution in the
30 Linux NICS <linux.nics@intel.com>
31 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 *******************************************************************************/
35 * Copyright (C) Archway Digital Solutions.
37 * written by Chrsitopher Li <cli at arcyway dot com> or <chrisl at gnuchina dot org>
40 * Copyright (C) Linux Networx.
41 * Massive upgrade to work with the new intel gigabit NICs.
42 * <ebiederman at lnxi dot com>
47 #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI) && \
50 #define TOUT_LOOP 100000
53 #define virt_to_bus(x) ((unsigned long)x)
54 #define bus_to_phys(devno, a) pci_mem_to_phys(devno, a)
55 #define mdelay(n) udelay((n)*1000)
57 #define E1000_DEFAULT_PBA 0x00000030
59 /* NIC specific static variables go here */
61 static char tx_pool
[128 + 16];
62 static char rx_pool
[128 + 16];
63 static char packet
[2096];
65 static struct e1000_tx_desc
*tx_base
;
66 static struct e1000_rx_desc
*rx_base
;
69 static int rx_tail
, rx_last
;
71 static struct pci_device_id supported
[] = {
72 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82542
},
73 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82543GC_FIBER
},
74 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82543GC_COPPER
},
75 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82544EI_COPPER
},
76 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82544EI_FIBER
},
77 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82544GC_COPPER
},
78 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82544GC_LOM
},
79 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82540EM
},
80 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82545EM_COPPER
},
81 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82546EB_COPPER
},
82 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82545EM_FIBER
},
83 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82546EB_FIBER
},
84 {PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82540EM_LOM
},
87 /* Function forward declarations */
88 static int e1000_setup_link(struct eth_device
*nic
);
89 static int e1000_setup_fiber_link(struct eth_device
*nic
);
90 static int e1000_setup_copper_link(struct eth_device
*nic
);
91 static int e1000_phy_setup_autoneg(struct e1000_hw
*hw
);
92 static void e1000_config_collision_dist(struct e1000_hw
*hw
);
93 static int e1000_config_mac_to_phy(struct e1000_hw
*hw
);
94 static int e1000_config_fc_after_link_up(struct e1000_hw
*hw
);
95 static int e1000_check_for_link(struct eth_device
*nic
);
96 static int e1000_wait_autoneg(struct e1000_hw
*hw
);
97 static void e1000_get_speed_and_duplex(struct e1000_hw
*hw
, uint16_t * speed
,
99 static int e1000_read_phy_reg(struct e1000_hw
*hw
, uint32_t reg_addr
,
100 uint16_t * phy_data
);
101 static int e1000_write_phy_reg(struct e1000_hw
*hw
, uint32_t reg_addr
,
103 static void e1000_phy_hw_reset(struct e1000_hw
*hw
);
104 static int e1000_phy_reset(struct e1000_hw
*hw
);
105 static int e1000_detect_gig_phy(struct e1000_hw
*hw
);
107 #define E1000_WRITE_REG(a, reg, value) (writel((value), ((a)->hw_addr + E1000_##reg)))
108 #define E1000_READ_REG(a, reg) (readl((a)->hw_addr + E1000_##reg))
109 #define E1000_WRITE_REG_ARRAY(a, reg, offset, value) (\
110 writel((value), ((a)->hw_addr + E1000_##reg + ((offset) << 2))))
111 #define E1000_READ_REG_ARRAY(a, reg, offset) ( \
112 readl((a)->hw_addr + E1000_##reg + ((offset) << 2)))
113 #define E1000_WRITE_FLUSH(a) {uint32_t x; x = E1000_READ_REG(a, STATUS);}
115 #ifndef CONFIG_AP1000 /* remove for warnings */
116 /******************************************************************************
117 * Raises the EEPROM's clock input.
119 * hw - Struct containing variables accessed by shared code
120 * eecd - EECD's current value
121 *****************************************************************************/
123 e1000_raise_ee_clk(struct e1000_hw
*hw
, uint32_t * eecd
)
125 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
126 * wait 50 microseconds.
128 *eecd
= *eecd
| E1000_EECD_SK
;
129 E1000_WRITE_REG(hw
, EECD
, *eecd
);
130 E1000_WRITE_FLUSH(hw
);
134 /******************************************************************************
135 * Lowers the EEPROM's clock input.
137 * hw - Struct containing variables accessed by shared code
138 * eecd - EECD's current value
139 *****************************************************************************/
141 e1000_lower_ee_clk(struct e1000_hw
*hw
, uint32_t * eecd
)
143 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
144 * wait 50 microseconds.
146 *eecd
= *eecd
& ~E1000_EECD_SK
;
147 E1000_WRITE_REG(hw
, EECD
, *eecd
);
148 E1000_WRITE_FLUSH(hw
);
152 /******************************************************************************
153 * Shift data bits out to the EEPROM.
155 * hw - Struct containing variables accessed by shared code
156 * data - data to send to the EEPROM
157 * count - number of bits to shift out
158 *****************************************************************************/
160 e1000_shift_out_ee_bits(struct e1000_hw
*hw
, uint16_t data
, uint16_t count
)
165 /* We need to shift "count" bits out to the EEPROM. So, value in the
166 * "data" parameter will be shifted out to the EEPROM one bit at a time.
167 * In order to do this, "data" must be broken down into bits.
169 mask
= 0x01 << (count
- 1);
170 eecd
= E1000_READ_REG(hw
, EECD
);
171 eecd
&= ~(E1000_EECD_DO
| E1000_EECD_DI
);
173 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
174 * and then raising and then lowering the clock (the SK bit controls
175 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
176 * by setting "DI" to "0" and then raising and then lowering the clock.
178 eecd
&= ~E1000_EECD_DI
;
181 eecd
|= E1000_EECD_DI
;
183 E1000_WRITE_REG(hw
, EECD
, eecd
);
184 E1000_WRITE_FLUSH(hw
);
188 e1000_raise_ee_clk(hw
, &eecd
);
189 e1000_lower_ee_clk(hw
, &eecd
);
195 /* We leave the "DI" bit set to "0" when we leave this routine. */
196 eecd
&= ~E1000_EECD_DI
;
197 E1000_WRITE_REG(hw
, EECD
, eecd
);
200 /******************************************************************************
201 * Shift data bits in from the EEPROM
203 * hw - Struct containing variables accessed by shared code
204 *****************************************************************************/
206 e1000_shift_in_ee_bits(struct e1000_hw
*hw
)
212 /* In order to read a register from the EEPROM, we need to shift 16 bits
213 * in from the EEPROM. Bits are "shifted in" by raising the clock input to
214 * the EEPROM (setting the SK bit), and then reading the value of the "DO"
215 * bit. During this "shifting in" process the "DI" bit should always be
219 eecd
= E1000_READ_REG(hw
, EECD
);
221 eecd
&= ~(E1000_EECD_DO
| E1000_EECD_DI
);
224 for (i
= 0; i
< 16; i
++) {
226 e1000_raise_ee_clk(hw
, &eecd
);
228 eecd
= E1000_READ_REG(hw
, EECD
);
230 eecd
&= ~(E1000_EECD_DI
);
231 if (eecd
& E1000_EECD_DO
)
234 e1000_lower_ee_clk(hw
, &eecd
);
240 /******************************************************************************
241 * Prepares EEPROM for access
243 * hw - Struct containing variables accessed by shared code
245 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
246 * function should be called before issuing a command to the EEPROM.
247 *****************************************************************************/
249 e1000_setup_eeprom(struct e1000_hw
*hw
)
253 eecd
= E1000_READ_REG(hw
, EECD
);
255 /* Clear SK and DI */
256 eecd
&= ~(E1000_EECD_SK
| E1000_EECD_DI
);
257 E1000_WRITE_REG(hw
, EECD
, eecd
);
260 eecd
|= E1000_EECD_CS
;
261 E1000_WRITE_REG(hw
, EECD
, eecd
);
264 /******************************************************************************
265 * Returns EEPROM to a "standby" state
267 * hw - Struct containing variables accessed by shared code
268 *****************************************************************************/
270 e1000_standby_eeprom(struct e1000_hw
*hw
)
274 eecd
= E1000_READ_REG(hw
, EECD
);
277 eecd
&= ~(E1000_EECD_CS
| E1000_EECD_SK
);
278 E1000_WRITE_REG(hw
, EECD
, eecd
);
279 E1000_WRITE_FLUSH(hw
);
283 eecd
|= E1000_EECD_SK
;
284 E1000_WRITE_REG(hw
, EECD
, eecd
);
285 E1000_WRITE_FLUSH(hw
);
289 eecd
|= E1000_EECD_CS
;
290 E1000_WRITE_REG(hw
, EECD
, eecd
);
291 E1000_WRITE_FLUSH(hw
);
295 eecd
&= ~E1000_EECD_SK
;
296 E1000_WRITE_REG(hw
, EECD
, eecd
);
297 E1000_WRITE_FLUSH(hw
);
301 /******************************************************************************
302 * Reads a 16 bit word from the EEPROM.
304 * hw - Struct containing variables accessed by shared code
305 * offset - offset of word in the EEPROM to read
306 * data - word read from the EEPROM
307 *****************************************************************************/
309 e1000_read_eeprom(struct e1000_hw
*hw
, uint16_t offset
, uint16_t * data
)
313 int large_eeprom
= FALSE
;
315 /* Request EEPROM Access */
316 if (hw
->mac_type
> e1000_82544
) {
317 eecd
= E1000_READ_REG(hw
, EECD
);
318 if (eecd
& E1000_EECD_SIZE
)
320 eecd
|= E1000_EECD_REQ
;
321 E1000_WRITE_REG(hw
, EECD
, eecd
);
322 eecd
= E1000_READ_REG(hw
, EECD
);
323 while ((!(eecd
& E1000_EECD_GNT
)) && (i
< 100)) {
326 eecd
= E1000_READ_REG(hw
, EECD
);
328 if (!(eecd
& E1000_EECD_GNT
)) {
329 eecd
&= ~E1000_EECD_REQ
;
330 E1000_WRITE_REG(hw
, EECD
, eecd
);
331 DEBUGOUT("Could not acquire EEPROM grant\n");
332 return -E1000_ERR_EEPROM
;
336 /* Prepare the EEPROM for reading */
337 e1000_setup_eeprom(hw
);
339 /* Send the READ command (opcode + addr) */
340 e1000_shift_out_ee_bits(hw
, EEPROM_READ_OPCODE
, 3);
341 e1000_shift_out_ee_bits(hw
, offset
, (large_eeprom
) ? 8 : 6);
344 *data
= e1000_shift_in_ee_bits(hw
);
346 /* End this read operation */
347 e1000_standby_eeprom(hw
);
349 /* Stop requesting EEPROM access */
350 if (hw
->mac_type
> e1000_82544
) {
351 eecd
= E1000_READ_REG(hw
, EECD
);
352 eecd
&= ~E1000_EECD_REQ
;
353 E1000_WRITE_REG(hw
, EECD
, eecd
);
361 e1000_eeprom_cleanup(struct e1000_hw
*hw
)
365 eecd
= E1000_READ_REG(hw
, EECD
);
366 eecd
&= ~(E1000_EECD_CS
| E1000_EECD_DI
);
367 E1000_WRITE_REG(hw
, EECD
, eecd
);
368 e1000_raise_ee_clk(hw
, &eecd
);
369 e1000_lower_ee_clk(hw
, &eecd
);
373 e1000_wait_eeprom_done(struct e1000_hw
*hw
)
378 e1000_standby_eeprom(hw
);
379 for (i
= 0; i
< 200; i
++) {
380 eecd
= E1000_READ_REG(hw
, EECD
);
381 if (eecd
& E1000_EECD_DO
)
389 e1000_write_eeprom(struct e1000_hw
*hw
, uint16_t Reg
, uint16_t Data
)
392 int large_eeprom
= FALSE
;
395 /* Request EEPROM Access */
396 if (hw
->mac_type
> e1000_82544
) {
397 eecd
= E1000_READ_REG(hw
, EECD
);
398 if (eecd
& E1000_EECD_SIZE
)
400 eecd
|= E1000_EECD_REQ
;
401 E1000_WRITE_REG(hw
, EECD
, eecd
);
402 eecd
= E1000_READ_REG(hw
, EECD
);
403 while ((!(eecd
& E1000_EECD_GNT
)) && (i
< 100)) {
406 eecd
= E1000_READ_REG(hw
, EECD
);
408 if (!(eecd
& E1000_EECD_GNT
)) {
409 eecd
&= ~E1000_EECD_REQ
;
410 E1000_WRITE_REG(hw
, EECD
, eecd
);
411 DEBUGOUT("Could not acquire EEPROM grant\n");
415 e1000_setup_eeprom(hw
);
416 e1000_shift_out_ee_bits(hw
, EEPROM_EWEN_OPCODE
, 5);
417 e1000_shift_out_ee_bits(hw
, Reg
, (large_eeprom
) ? 6 : 4);
418 e1000_standby_eeprom(hw
);
419 e1000_shift_out_ee_bits(hw
, EEPROM_WRITE_OPCODE
, 3);
420 e1000_shift_out_ee_bits(hw
, Reg
, (large_eeprom
) ? 8 : 6);
421 e1000_shift_out_ee_bits(hw
, Data
, 16);
422 if (!e1000_wait_eeprom_done(hw
)) {
425 e1000_shift_out_ee_bits(hw
, EEPROM_EWDS_OPCODE
, 5);
426 e1000_shift_out_ee_bits(hw
, Reg
, (large_eeprom
) ? 6 : 4);
427 e1000_eeprom_cleanup(hw
);
429 /* Stop requesting EEPROM access */
430 if (hw
->mac_type
> e1000_82544
) {
431 eecd
= E1000_READ_REG(hw
, EECD
);
432 eecd
&= ~E1000_EECD_REQ
;
433 E1000_WRITE_REG(hw
, EECD
, eecd
);
436 eecd
= E1000_READ_REG(hw
, EECD
);
437 while (((eecd
& E1000_EECD_GNT
)) && (i
< 500)) {
440 eecd
= E1000_READ_REG(hw
, EECD
);
442 if ((eecd
& E1000_EECD_GNT
)) {
443 DEBUGOUT("Could not release EEPROM grant\n");
449 /******************************************************************************
450 * Verifies that the EEPROM has a valid checksum
452 * hw - Struct containing variables accessed by shared code
454 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
455 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
457 *****************************************************************************/
459 e1000_validate_eeprom_checksum(struct eth_device
*nic
)
461 struct e1000_hw
*hw
= nic
->priv
;
462 uint16_t checksum
= 0;
463 uint16_t i
, eeprom_data
;
467 for (i
= 0; i
< (EEPROM_CHECKSUM_REG
+ 1); i
++) {
468 if (e1000_read_eeprom(hw
, i
, &eeprom_data
) < 0) {
469 DEBUGOUT("EEPROM Read Error\n");
470 return -E1000_ERR_EEPROM
;
472 checksum
+= eeprom_data
;
475 if (checksum
== (uint16_t) EEPROM_SUM
) {
478 DEBUGOUT("EEPROM Checksum Invalid\n");
479 return -E1000_ERR_EEPROM
;
482 #endif /* #ifndef CONFIG_AP1000 */
484 /******************************************************************************
485 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
486 * second function of dual function devices
488 * nic - Struct containing variables accessed by shared code
489 *****************************************************************************/
491 e1000_read_mac_addr(struct eth_device
*nic
)
493 #ifndef CONFIG_AP1000
494 struct e1000_hw
*hw
= nic
->priv
;
496 uint16_t eeprom_data
;
501 for (i
= 0; i
< NODE_ADDRESS_SIZE
; i
+= 2) {
503 if (e1000_read_eeprom(hw
, offset
, &eeprom_data
) < 0) {
504 DEBUGOUT("EEPROM Read Error\n");
505 return -E1000_ERR_EEPROM
;
507 nic
->enetaddr
[i
] = eeprom_data
& 0xff;
508 nic
->enetaddr
[i
+ 1] = (eeprom_data
>> 8) & 0xff;
510 if ((hw
->mac_type
== e1000_82546
) &&
511 (E1000_READ_REG(hw
, STATUS
) & E1000_STATUS_FUNC_1
)) {
512 /* Invert the last bit if this is the second device */
513 nic
->enetaddr
[5] += 1;
517 * The AP1000's e1000 has no eeprom; the MAC address is stored in the
518 * environment variables. Currently this does not support the addition
519 * of a PMC e1000 card, which is certainly a possibility, so this should
520 * be updated to properly use the env variable only for the onboard e1000
528 s
= getenv ("ethaddr");
530 return -E1000_ERR_EEPROM
;
533 for(ii
= 0; ii
< 6; ii
++) {
534 nic
->enetaddr
[ii
] = s
? simple_strtoul (s
, &e
, 16) : 0;
536 s
= (*e
) ? e
+ 1 : e
;
544 /******************************************************************************
545 * Initializes receive address filters.
547 * hw - Struct containing variables accessed by shared code
549 * Places the MAC address in receive address register 0 and clears the rest
550 * of the receive addresss registers. Clears the multicast table. Assumes
551 * the receiver is in reset when the routine is called.
552 *****************************************************************************/
554 e1000_init_rx_addrs(struct eth_device
*nic
)
556 struct e1000_hw
*hw
= nic
->priv
;
563 /* Setup the receive address. */
564 DEBUGOUT("Programming MAC Address into RAR[0]\n");
565 addr_low
= (nic
->enetaddr
[0] |
566 (nic
->enetaddr
[1] << 8) |
567 (nic
->enetaddr
[2] << 16) | (nic
->enetaddr
[3] << 24));
569 addr_high
= (nic
->enetaddr
[4] | (nic
->enetaddr
[5] << 8) | E1000_RAH_AV
);
571 E1000_WRITE_REG_ARRAY(hw
, RA
, 0, addr_low
);
572 E1000_WRITE_REG_ARRAY(hw
, RA
, 1, addr_high
);
574 /* Zero out the other 15 receive addresses. */
575 DEBUGOUT("Clearing RAR[1-15]\n");
576 for (i
= 1; i
< E1000_RAR_ENTRIES
; i
++) {
577 E1000_WRITE_REG_ARRAY(hw
, RA
, (i
<< 1), 0);
578 E1000_WRITE_REG_ARRAY(hw
, RA
, ((i
<< 1) + 1), 0);
582 /******************************************************************************
583 * Clears the VLAN filer table
585 * hw - Struct containing variables accessed by shared code
586 *****************************************************************************/
588 e1000_clear_vfta(struct e1000_hw
*hw
)
592 for (offset
= 0; offset
< E1000_VLAN_FILTER_TBL_SIZE
; offset
++)
593 E1000_WRITE_REG_ARRAY(hw
, VFTA
, offset
, 0);
596 /******************************************************************************
597 * Set the mac type member in the hw struct.
599 * hw - Struct containing variables accessed by shared code
600 *****************************************************************************/
602 e1000_set_mac_type(struct e1000_hw
*hw
)
606 switch (hw
->device_id
) {
607 case E1000_DEV_ID_82542
:
608 switch (hw
->revision_id
) {
609 case E1000_82542_2_0_REV_ID
:
610 hw
->mac_type
= e1000_82542_rev2_0
;
612 case E1000_82542_2_1_REV_ID
:
613 hw
->mac_type
= e1000_82542_rev2_1
;
616 /* Invalid 82542 revision ID */
617 return -E1000_ERR_MAC_TYPE
;
620 case E1000_DEV_ID_82543GC_FIBER
:
621 case E1000_DEV_ID_82543GC_COPPER
:
622 hw
->mac_type
= e1000_82543
;
624 case E1000_DEV_ID_82544EI_COPPER
:
625 case E1000_DEV_ID_82544EI_FIBER
:
626 case E1000_DEV_ID_82544GC_COPPER
:
627 case E1000_DEV_ID_82544GC_LOM
:
628 hw
->mac_type
= e1000_82544
;
630 case E1000_DEV_ID_82540EM
:
631 case E1000_DEV_ID_82540EM_LOM
:
632 hw
->mac_type
= e1000_82540
;
634 case E1000_DEV_ID_82545EM_COPPER
:
635 case E1000_DEV_ID_82545EM_FIBER
:
636 hw
->mac_type
= e1000_82545
;
638 case E1000_DEV_ID_82546EB_COPPER
:
639 case E1000_DEV_ID_82546EB_FIBER
:
640 hw
->mac_type
= e1000_82546
;
643 /* Should never have loaded on this device */
644 return -E1000_ERR_MAC_TYPE
;
646 return E1000_SUCCESS
;
649 /******************************************************************************
650 * Reset the transmit and receive units; mask and clear all interrupts.
652 * hw - Struct containing variables accessed by shared code
653 *****************************************************************************/
655 e1000_reset_hw(struct e1000_hw
*hw
)
664 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
665 if (hw
->mac_type
== e1000_82542_rev2_0
) {
666 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
667 pci_write_config_word(hw
->pdev
, PCI_COMMAND
,
669 pci_cmd_word
& ~PCI_COMMAND_INVALIDATE
);
672 /* Clear interrupt mask to stop board from generating interrupts */
673 DEBUGOUT("Masking off all interrupts\n");
674 E1000_WRITE_REG(hw
, IMC
, 0xffffffff);
676 /* Disable the Transmit and Receive units. Then delay to allow
677 * any pending transactions to complete before we hit the MAC with
680 E1000_WRITE_REG(hw
, RCTL
, 0);
681 E1000_WRITE_REG(hw
, TCTL
, E1000_TCTL_PSP
);
682 E1000_WRITE_FLUSH(hw
);
684 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
685 hw
->tbi_compatibility_on
= FALSE
;
687 /* Delay to allow any outstanding PCI transactions to complete before
688 * resetting the device
692 /* Issue a global reset to the MAC. This will reset the chip's
693 * transmit, receive, DMA, and link units. It will not effect
694 * the current PCI configuration. The global reset bit is self-
695 * clearing, and should clear within a microsecond.
697 DEBUGOUT("Issuing a global reset to MAC\n");
698 ctrl
= E1000_READ_REG(hw
, CTRL
);
701 if (hw
->mac_type
> e1000_82543
)
702 E1000_WRITE_REG_IO(hw
, CTRL
, (ctrl
| E1000_CTRL_RST
));
705 E1000_WRITE_REG(hw
, CTRL
, (ctrl
| E1000_CTRL_RST
));
707 /* Force a reload from the EEPROM if necessary */
708 if (hw
->mac_type
< e1000_82540
) {
709 /* Wait for reset to complete */
711 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
712 ctrl_ext
|= E1000_CTRL_EXT_EE_RST
;
713 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
714 E1000_WRITE_FLUSH(hw
);
715 /* Wait for EEPROM reload */
718 /* Wait for EEPROM reload (it happens automatically) */
720 /* Dissable HW ARPs on ASF enabled adapters */
721 manc
= E1000_READ_REG(hw
, MANC
);
722 manc
&= ~(E1000_MANC_ARP_EN
);
723 E1000_WRITE_REG(hw
, MANC
, manc
);
726 /* Clear interrupt mask to stop board from generating interrupts */
727 DEBUGOUT("Masking off all interrupts\n");
728 E1000_WRITE_REG(hw
, IMC
, 0xffffffff);
730 /* Clear any pending interrupt events. */
731 icr
= E1000_READ_REG(hw
, ICR
);
733 /* If MWI was previously enabled, reenable it. */
734 if (hw
->mac_type
== e1000_82542_rev2_0
) {
735 pci_write_config_word(hw
->pdev
, PCI_COMMAND
, hw
->pci_cmd_word
);
739 /******************************************************************************
740 * Performs basic configuration of the adapter.
742 * hw - Struct containing variables accessed by shared code
744 * Assumes that the controller has previously been reset and is in a
745 * post-reset uninitialized state. Initializes the receive address registers,
746 * multicast table, and VLAN filter table. Calls routines to setup link
747 * configuration and flow control settings. Clears all on-chip counters. Leaves
748 * the transmit and receive units disabled and uninitialized.
749 *****************************************************************************/
751 e1000_init_hw(struct eth_device
*nic
)
753 struct e1000_hw
*hw
= nic
->priv
;
754 uint32_t ctrl
, status
;
757 uint16_t pcix_cmd_word
;
758 uint16_t pcix_stat_hi_word
;
761 e1000_bus_type bus_type
= e1000_bus_type_unknown
;
765 /* Initialize Identification LED */
766 ret_val
= e1000_id_led_init(hw
);
768 DEBUGOUT("Error Initializing Identification LED\n");
772 /* Set the Media Type and exit with error if it is not valid. */
773 if (hw
->mac_type
!= e1000_82543
) {
774 /* tbi_compatibility is only valid on 82543 */
775 hw
->tbi_compatibility_en
= FALSE
;
778 if (hw
->mac_type
>= e1000_82543
) {
779 status
= E1000_READ_REG(hw
, STATUS
);
780 if (status
& E1000_STATUS_TBIMODE
) {
781 hw
->media_type
= e1000_media_type_fiber
;
782 /* tbi_compatibility not valid on fiber */
783 hw
->tbi_compatibility_en
= FALSE
;
785 hw
->media_type
= e1000_media_type_copper
;
788 /* This is an 82542 (fiber only) */
789 hw
->media_type
= e1000_media_type_fiber
;
792 /* Disabling VLAN filtering. */
793 DEBUGOUT("Initializing the IEEE VLAN\n");
794 E1000_WRITE_REG(hw
, VET
, 0);
796 e1000_clear_vfta(hw
);
798 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
799 if (hw
->mac_type
== e1000_82542_rev2_0
) {
800 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
801 pci_write_config_word(hw
->pdev
, PCI_COMMAND
,
803 pci_cmd_word
& ~PCI_COMMAND_INVALIDATE
);
804 E1000_WRITE_REG(hw
, RCTL
, E1000_RCTL_RST
);
805 E1000_WRITE_FLUSH(hw
);
809 /* Setup the receive address. This involves initializing all of the Receive
810 * Address Registers (RARs 0 - 15).
812 e1000_init_rx_addrs(nic
);
814 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
815 if (hw
->mac_type
== e1000_82542_rev2_0
) {
816 E1000_WRITE_REG(hw
, RCTL
, 0);
817 E1000_WRITE_FLUSH(hw
);
819 pci_write_config_word(hw
->pdev
, PCI_COMMAND
, hw
->pci_cmd_word
);
822 /* Zero out the Multicast HASH table */
823 DEBUGOUT("Zeroing the MTA\n");
824 for (i
= 0; i
< E1000_MC_TBL_SIZE
; i
++)
825 E1000_WRITE_REG_ARRAY(hw
, MTA
, i
, 0);
828 /* Set the PCI priority bit correctly in the CTRL register. This
829 * determines if the adapter gives priority to receives, or if it
830 * gives equal priority to transmits and receives.
832 if (hw
->dma_fairness
) {
833 ctrl
= E1000_READ_REG(hw
, CTRL
);
834 E1000_WRITE_REG(hw
, CTRL
, ctrl
| E1000_CTRL_PRIOR
);
837 if (hw
->mac_type
>= e1000_82543
) {
838 status
= E1000_READ_REG(hw
, STATUS
);
839 bus_type
= (status
& E1000_STATUS_PCIX_MODE
) ?
840 e1000_bus_type_pcix
: e1000_bus_type_pci
;
842 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
843 if (bus_type
== e1000_bus_type_pcix
) {
844 pci_read_config_word(hw
->pdev
, PCIX_COMMAND_REGISTER
,
846 pci_read_config_word(hw
->pdev
, PCIX_STATUS_REGISTER_HI
,
849 (pcix_cmd_word
& PCIX_COMMAND_MMRBC_MASK
) >>
850 PCIX_COMMAND_MMRBC_SHIFT
;
852 (pcix_stat_hi_word
& PCIX_STATUS_HI_MMRBC_MASK
) >>
853 PCIX_STATUS_HI_MMRBC_SHIFT
;
854 if (stat_mmrbc
== PCIX_STATUS_HI_MMRBC_4K
)
855 stat_mmrbc
= PCIX_STATUS_HI_MMRBC_2K
;
856 if (cmd_mmrbc
> stat_mmrbc
) {
857 pcix_cmd_word
&= ~PCIX_COMMAND_MMRBC_MASK
;
858 pcix_cmd_word
|= stat_mmrbc
<< PCIX_COMMAND_MMRBC_SHIFT
;
859 pci_write_config_word(hw
->pdev
, PCIX_COMMAND_REGISTER
,
864 /* Call a subroutine to configure the link and setup flow control. */
865 ret_val
= e1000_setup_link(nic
);
867 /* Set the transmit descriptor write-back policy */
868 if (hw
->mac_type
> e1000_82544
) {
869 ctrl
= E1000_READ_REG(hw
, TXDCTL
);
871 (ctrl
& ~E1000_TXDCTL_WTHRESH
) |
872 E1000_TXDCTL_FULL_TX_DESC_WB
;
873 E1000_WRITE_REG(hw
, TXDCTL
, ctrl
);
876 /* Clear all of the statistics registers (clear on read). It is
877 * important that we do this after we have tried to establish link
878 * because the symbol error count will increment wildly if there
881 e1000_clear_hw_cntrs(hw
);
887 /******************************************************************************
888 * Configures flow control and link settings.
890 * hw - Struct containing variables accessed by shared code
892 * Determines which flow control settings to use. Calls the apropriate media-
893 * specific link configuration function. Configures the flow control settings.
894 * Assuming the adapter has a valid link partner, a valid link should be
895 * established. Assumes the hardware has previously been reset and the
896 * transmitter and receiver are not enabled.
897 *****************************************************************************/
899 e1000_setup_link(struct eth_device
*nic
)
901 struct e1000_hw
*hw
= nic
->priv
;
904 uint16_t eeprom_data
;
908 #ifndef CONFIG_AP1000
909 /* Read and store word 0x0F of the EEPROM. This word contains bits
910 * that determine the hardware's default PAUSE (flow control) mode,
911 * a bit that determines whether the HW defaults to enabling or
912 * disabling auto-negotiation, and the direction of the
913 * SW defined pins. If there is no SW over-ride of the flow
914 * control setting, then the variable hw->fc will
915 * be initialized based on a value in the EEPROM.
917 if (e1000_read_eeprom(hw
, EEPROM_INIT_CONTROL2_REG
, &eeprom_data
) < 0) {
918 DEBUGOUT("EEPROM Read Error\n");
919 return -E1000_ERR_EEPROM
;
922 /* we have to hardcode the proper value for our hardware. */
923 /* this value is for the 82540EM pci card used for prototyping, and it works. */
924 eeprom_data
= 0xb220;
927 if (hw
->fc
== e1000_fc_default
) {
928 if ((eeprom_data
& EEPROM_WORD0F_PAUSE_MASK
) == 0)
929 hw
->fc
= e1000_fc_none
;
930 else if ((eeprom_data
& EEPROM_WORD0F_PAUSE_MASK
) ==
931 EEPROM_WORD0F_ASM_DIR
)
932 hw
->fc
= e1000_fc_tx_pause
;
934 hw
->fc
= e1000_fc_full
;
937 /* We want to save off the original Flow Control configuration just
938 * in case we get disconnected and then reconnected into a different
939 * hub or switch with different Flow Control capabilities.
941 if (hw
->mac_type
== e1000_82542_rev2_0
)
942 hw
->fc
&= (~e1000_fc_tx_pause
);
944 if ((hw
->mac_type
< e1000_82543
) && (hw
->report_tx_early
== 1))
945 hw
->fc
&= (~e1000_fc_rx_pause
);
947 hw
->original_fc
= hw
->fc
;
949 DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw
->fc
);
951 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
952 * polarity value for the SW controlled pins, and setup the
953 * Extended Device Control reg with that info.
954 * This is needed because one of the SW controlled pins is used for
955 * signal detection. So this should be done before e1000_setup_pcs_link()
956 * or e1000_phy_setup() is called.
958 if (hw
->mac_type
== e1000_82543
) {
959 ctrl_ext
= ((eeprom_data
& EEPROM_WORD0F_SWPDIO_EXT
) <<
961 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
964 /* Call the necessary subroutine to configure the link. */
965 ret_val
= (hw
->media_type
== e1000_media_type_fiber
) ?
966 e1000_setup_fiber_link(nic
) : e1000_setup_copper_link(nic
);
971 /* Initialize the flow control address, type, and PAUSE timer
972 * registers to their default values. This is done even if flow
973 * control is disabled, because it does not hurt anything to
974 * initialize these registers.
977 ("Initializing the Flow Control address, type and timer regs\n");
979 E1000_WRITE_REG(hw
, FCAL
, FLOW_CONTROL_ADDRESS_LOW
);
980 E1000_WRITE_REG(hw
, FCAH
, FLOW_CONTROL_ADDRESS_HIGH
);
981 E1000_WRITE_REG(hw
, FCT
, FLOW_CONTROL_TYPE
);
982 E1000_WRITE_REG(hw
, FCTTV
, hw
->fc_pause_time
);
984 /* Set the flow control receive threshold registers. Normally,
985 * these registers will be set to a default threshold that may be
986 * adjusted later by the driver's runtime code. However, if the
987 * ability to transmit pause frames in not enabled, then these
988 * registers will be set to 0.
990 if (!(hw
->fc
& e1000_fc_tx_pause
)) {
991 E1000_WRITE_REG(hw
, FCRTL
, 0);
992 E1000_WRITE_REG(hw
, FCRTH
, 0);
994 /* We need to set up the Receive Threshold high and low water marks
995 * as well as (optionally) enabling the transmission of XON frames.
997 if (hw
->fc_send_xon
) {
998 E1000_WRITE_REG(hw
, FCRTL
,
999 (hw
->fc_low_water
| E1000_FCRTL_XONE
));
1000 E1000_WRITE_REG(hw
, FCRTH
, hw
->fc_high_water
);
1002 E1000_WRITE_REG(hw
, FCRTL
, hw
->fc_low_water
);
1003 E1000_WRITE_REG(hw
, FCRTH
, hw
->fc_high_water
);
1009 /******************************************************************************
1010 * Sets up link for a fiber based adapter
1012 * hw - Struct containing variables accessed by shared code
1014 * Manipulates Physical Coding Sublayer functions in order to configure
1015 * link. Assumes the hardware has been previously reset and the transmitter
1016 * and receiver are not enabled.
1017 *****************************************************************************/
1019 e1000_setup_fiber_link(struct eth_device
*nic
)
1021 struct e1000_hw
*hw
= nic
->priv
;
1030 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
1031 * set when the optics detect a signal. On older adapters, it will be
1032 * cleared when there is a signal
1034 ctrl
= E1000_READ_REG(hw
, CTRL
);
1035 if ((hw
->mac_type
> e1000_82544
) && !(ctrl
& E1000_CTRL_ILOS
))
1036 signal
= E1000_CTRL_SWDPIN1
;
1040 printf("signal for %s is %x (ctrl %08x)!!!!\n", nic
->name
, signal
,
1042 /* Take the link out of reset */
1043 ctrl
&= ~(E1000_CTRL_LRST
);
1045 e1000_config_collision_dist(hw
);
1047 /* Check for a software override of the flow control settings, and setup
1048 * the device accordingly. If auto-negotiation is enabled, then software
1049 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1050 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1051 * auto-negotiation is disabled, then software will have to manually
1052 * configure the two flow control enable bits in the CTRL register.
1054 * The possible values of the "fc" parameter are:
1055 * 0: Flow control is completely disabled
1056 * 1: Rx flow control is enabled (we can receive pause frames, but
1057 * not send pause frames).
1058 * 2: Tx flow control is enabled (we can send pause frames but we do
1059 * not support receiving pause frames).
1060 * 3: Both Rx and TX flow control (symmetric) are enabled.
1064 /* Flow control is completely disabled by a software over-ride. */
1065 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
);
1067 case e1000_fc_rx_pause
:
1068 /* RX Flow control is enabled and TX Flow control is disabled by a
1069 * software over-ride. Since there really isn't a way to advertise
1070 * that we are capable of RX Pause ONLY, we will advertise that we
1071 * support both symmetric and asymmetric RX PAUSE. Later, we will
1072 * disable the adapter's ability to send PAUSE frames.
1074 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
| E1000_TXCW_PAUSE_MASK
);
1076 case e1000_fc_tx_pause
:
1077 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1078 * software over-ride.
1080 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
| E1000_TXCW_ASM_DIR
);
1083 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1084 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
| E1000_TXCW_PAUSE_MASK
);
1087 DEBUGOUT("Flow control param set incorrectly\n");
1088 return -E1000_ERR_CONFIG
;
1092 /* Since auto-negotiation is enabled, take the link out of reset (the link
1093 * will be in reset, because we previously reset the chip). This will
1094 * restart auto-negotiation. If auto-neogtiation is successful then the
1095 * link-up status bit will be set and the flow control enable bits (RFCE
1096 * and TFCE) will be set according to their negotiated value.
1098 DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw
);
1100 E1000_WRITE_REG(hw
, TXCW
, txcw
);
1101 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
1102 E1000_WRITE_FLUSH(hw
);
1107 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1108 * indication in the Device Status Register. Time-out if a link isn't
1109 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1110 * less than 500 milliseconds even if the other end is doing it in SW).
1112 if ((E1000_READ_REG(hw
, CTRL
) & E1000_CTRL_SWDPIN1
) == signal
) {
1113 DEBUGOUT("Looking for Link\n");
1114 for (i
= 0; i
< (LINK_UP_TIMEOUT
/ 10); i
++) {
1116 status
= E1000_READ_REG(hw
, STATUS
);
1117 if (status
& E1000_STATUS_LU
)
1120 if (i
== (LINK_UP_TIMEOUT
/ 10)) {
1121 /* AutoNeg failed to achieve a link, so we'll call
1122 * e1000_check_for_link. This routine will force the link up if we
1123 * detect a signal. This will allow us to communicate with
1124 * non-autonegotiating link partners.
1126 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1127 hw
->autoneg_failed
= 1;
1128 ret_val
= e1000_check_for_link(nic
);
1130 DEBUGOUT("Error while checking for link\n");
1133 hw
->autoneg_failed
= 0;
1135 hw
->autoneg_failed
= 0;
1136 DEBUGOUT("Valid Link Found\n");
1139 DEBUGOUT("No Signal Detected\n");
1140 return -E1000_ERR_NOLINK
;
1145 /******************************************************************************
1146 * Detects which PHY is present and the speed and duplex
1148 * hw - Struct containing variables accessed by shared code
1149 ******************************************************************************/
1151 e1000_setup_copper_link(struct eth_device
*nic
)
1153 struct e1000_hw
*hw
= nic
->priv
;
1161 ctrl
= E1000_READ_REG(hw
, CTRL
);
1162 /* With 82543, we need to force speed and duplex on the MAC equal to what
1163 * the PHY speed and duplex configuration is. In addition, we need to
1164 * perform a hardware reset on the PHY to take it out of reset.
1166 if (hw
->mac_type
> e1000_82543
) {
1167 ctrl
|= E1000_CTRL_SLU
;
1168 ctrl
&= ~(E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
);
1169 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
1172 (E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
| E1000_CTRL_SLU
);
1173 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
1174 e1000_phy_hw_reset(hw
);
1177 /* Make sure we have a valid PHY */
1178 ret_val
= e1000_detect_gig_phy(hw
);
1180 DEBUGOUT("Error, did not detect valid phy.\n");
1183 DEBUGOUT("Phy ID = %x \n", hw
->phy_id
);
1185 /* Enable CRS on TX. This must be set for half-duplex operation. */
1186 if (e1000_read_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
, &phy_data
) < 0) {
1187 DEBUGOUT("PHY Read Error\n");
1188 return -E1000_ERR_PHY
;
1190 phy_data
|= M88E1000_PSCR_ASSERT_CRS_ON_TX
;
1194 * MDI/MDI-X = 0 (default)
1195 * 0 - Auto for all speeds
1198 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1200 phy_data
&= ~M88E1000_PSCR_AUTO_X_MODE
;
1203 phy_data
|= M88E1000_PSCR_MDI_MANUAL_MODE
;
1206 phy_data
|= M88E1000_PSCR_MDIX_MANUAL_MODE
;
1209 phy_data
|= M88E1000_PSCR_AUTO_X_1000T
;
1213 phy_data
|= M88E1000_PSCR_AUTO_X_MODE
;
1217 phy_data
|= M88E1000_PSCR_AUTO_X_MODE
;
1222 * disable_polarity_correction = 0 (default)
1223 * Automatic Correction for Reversed Cable Polarity
1227 phy_data
&= ~M88E1000_PSCR_POLARITY_REVERSAL
;
1228 if (hw
->disable_polarity_correction
== 1)
1229 phy_data
|= M88E1000_PSCR_POLARITY_REVERSAL
;
1231 phy_data
&= ~M88E1000_PSCR_POLARITY_REVERSAL
;
1233 if (e1000_write_phy_reg(hw
, M88E1000_PHY_SPEC_CTRL
, phy_data
) < 0) {
1234 DEBUGOUT("PHY Write Error\n");
1235 return -E1000_ERR_PHY
;
1238 /* Force TX_CLK in the Extended PHY Specific Control Register
1241 if (e1000_read_phy_reg(hw
, M88E1000_EXT_PHY_SPEC_CTRL
, &phy_data
) < 0) {
1242 DEBUGOUT("PHY Read Error\n");
1243 return -E1000_ERR_PHY
;
1245 phy_data
|= M88E1000_EPSCR_TX_CLK_25
;
1246 /* Configure Master and Slave downshift values */
1247 phy_data
&= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK
|
1248 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK
);
1249 phy_data
|= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X
|
1250 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X
);
1251 if (e1000_write_phy_reg(hw
, M88E1000_EXT_PHY_SPEC_CTRL
, phy_data
) < 0) {
1252 DEBUGOUT("PHY Write Error\n");
1253 return -E1000_ERR_PHY
;
1256 /* SW Reset the PHY so all changes take effect */
1257 ret_val
= e1000_phy_reset(hw
);
1259 DEBUGOUT("Error Resetting the PHY\n");
1264 * autoneg = 1 (default)
1265 * PHY will advertise value(s) parsed from
1266 * autoneg_advertised and fc
1268 * PHY will be set to 10H, 10F, 100H, or 100F
1269 * depending on value parsed from forced_speed_duplex.
1272 /* Is autoneg enabled? This is enabled by default or by software override.
1273 * If so, call e1000_phy_setup_autoneg routine to parse the
1274 * autoneg_advertised and fc options. If autoneg is NOT enabled, then the
1275 * user should have provided a speed/duplex override. If so, then call
1276 * e1000_phy_force_speed_duplex to parse and set this up.
1278 /* Perform some bounds checking on the hw->autoneg_advertised
1279 * parameter. If this variable is zero, then set it to the default.
1281 hw
->autoneg_advertised
&= AUTONEG_ADVERTISE_SPEED_DEFAULT
;
1283 /* If autoneg_advertised is zero, we assume it was not defaulted
1284 * by the calling code so we set to advertise full capability.
1286 if (hw
->autoneg_advertised
== 0)
1287 hw
->autoneg_advertised
= AUTONEG_ADVERTISE_SPEED_DEFAULT
;
1289 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1290 ret_val
= e1000_phy_setup_autoneg(hw
);
1292 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1295 DEBUGOUT("Restarting Auto-Neg\n");
1297 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1298 * the Auto Neg Restart bit in the PHY control register.
1300 if (e1000_read_phy_reg(hw
, PHY_CTRL
, &phy_data
) < 0) {
1301 DEBUGOUT("PHY Read Error\n");
1302 return -E1000_ERR_PHY
;
1304 phy_data
|= (MII_CR_AUTO_NEG_EN
| MII_CR_RESTART_AUTO_NEG
);
1305 if (e1000_write_phy_reg(hw
, PHY_CTRL
, phy_data
) < 0) {
1306 DEBUGOUT("PHY Write Error\n");
1307 return -E1000_ERR_PHY
;
1310 /* Does the user want to wait for Auto-Neg to complete here, or
1311 * check at a later time (for example, callback routine).
1313 if (hw
->wait_autoneg_complete
) {
1314 ret_val
= e1000_wait_autoneg(hw
);
1317 ("Error while waiting for autoneg to complete\n");
1322 /* If we do not wait for autonegtation to complete I
1323 * do not see a valid link status.
1325 ret_val
= e1000_wait_autoneg(hw
);
1327 DEBUGOUT("Error while waiting for autoneg to complete\n");
1332 /* Check link status. Wait up to 100 microseconds for link to become
1335 for (i
= 0; i
< 10; i
++) {
1336 if (e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
) < 0) {
1337 DEBUGOUT("PHY Read Error\n");
1338 return -E1000_ERR_PHY
;
1340 if (e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
) < 0) {
1341 DEBUGOUT("PHY Read Error\n");
1342 return -E1000_ERR_PHY
;
1344 if (phy_data
& MII_SR_LINK_STATUS
) {
1345 /* We have link, so we need to finish the config process:
1346 * 1) Set up the MAC to the current PHY speed/duplex
1347 * if we are on 82543. If we
1348 * are on newer silicon, we only need to configure
1349 * collision distance in the Transmit Control Register.
1350 * 2) Set up flow control on the MAC to that established with
1353 if (hw
->mac_type
>= e1000_82544
) {
1354 e1000_config_collision_dist(hw
);
1356 ret_val
= e1000_config_mac_to_phy(hw
);
1359 ("Error configuring MAC to PHY settings\n");
1363 ret_val
= e1000_config_fc_after_link_up(hw
);
1365 DEBUGOUT("Error Configuring Flow Control\n");
1368 DEBUGOUT("Valid link established!!!\n");
1374 DEBUGOUT("Unable to establish link!!!\n");
1375 return -E1000_ERR_NOLINK
;
1378 /******************************************************************************
1379 * Configures PHY autoneg and flow control advertisement settings
1381 * hw - Struct containing variables accessed by shared code
1382 ******************************************************************************/
1384 e1000_phy_setup_autoneg(struct e1000_hw
*hw
)
1386 uint16_t mii_autoneg_adv_reg
;
1387 uint16_t mii_1000t_ctrl_reg
;
1391 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1392 if (e1000_read_phy_reg(hw
, PHY_AUTONEG_ADV
, &mii_autoneg_adv_reg
) < 0) {
1393 DEBUGOUT("PHY Read Error\n");
1394 return -E1000_ERR_PHY
;
1397 /* Read the MII 1000Base-T Control Register (Address 9). */
1398 if (e1000_read_phy_reg(hw
, PHY_1000T_CTRL
, &mii_1000t_ctrl_reg
) < 0) {
1399 DEBUGOUT("PHY Read Error\n");
1400 return -E1000_ERR_PHY
;
1403 /* Need to parse both autoneg_advertised and fc and set up
1404 * the appropriate PHY registers. First we will parse for
1405 * autoneg_advertised software override. Since we can advertise
1406 * a plethora of combinations, we need to check each bit
1410 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1411 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1412 * the 1000Base-T Control Register (Address 9).
1414 mii_autoneg_adv_reg
&= ~REG4_SPEED_MASK
;
1415 mii_1000t_ctrl_reg
&= ~REG9_SPEED_MASK
;
1417 DEBUGOUT("autoneg_advertised %x\n", hw
->autoneg_advertised
);
1419 /* Do we want to advertise 10 Mb Half Duplex? */
1420 if (hw
->autoneg_advertised
& ADVERTISE_10_HALF
) {
1421 DEBUGOUT("Advertise 10mb Half duplex\n");
1422 mii_autoneg_adv_reg
|= NWAY_AR_10T_HD_CAPS
;
1425 /* Do we want to advertise 10 Mb Full Duplex? */
1426 if (hw
->autoneg_advertised
& ADVERTISE_10_FULL
) {
1427 DEBUGOUT("Advertise 10mb Full duplex\n");
1428 mii_autoneg_adv_reg
|= NWAY_AR_10T_FD_CAPS
;
1431 /* Do we want to advertise 100 Mb Half Duplex? */
1432 if (hw
->autoneg_advertised
& ADVERTISE_100_HALF
) {
1433 DEBUGOUT("Advertise 100mb Half duplex\n");
1434 mii_autoneg_adv_reg
|= NWAY_AR_100TX_HD_CAPS
;
1437 /* Do we want to advertise 100 Mb Full Duplex? */
1438 if (hw
->autoneg_advertised
& ADVERTISE_100_FULL
) {
1439 DEBUGOUT("Advertise 100mb Full duplex\n");
1440 mii_autoneg_adv_reg
|= NWAY_AR_100TX_FD_CAPS
;
1443 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1444 if (hw
->autoneg_advertised
& ADVERTISE_1000_HALF
) {
1446 ("Advertise 1000mb Half duplex requested, request denied!\n");
1449 /* Do we want to advertise 1000 Mb Full Duplex? */
1450 if (hw
->autoneg_advertised
& ADVERTISE_1000_FULL
) {
1451 DEBUGOUT("Advertise 1000mb Full duplex\n");
1452 mii_1000t_ctrl_reg
|= CR_1000T_FD_CAPS
;
1455 /* Check for a software override of the flow control settings, and
1456 * setup the PHY advertisement registers accordingly. If
1457 * auto-negotiation is enabled, then software will have to set the
1458 * "PAUSE" bits to the correct value in the Auto-Negotiation
1459 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1461 * The possible values of the "fc" parameter are:
1462 * 0: Flow control is completely disabled
1463 * 1: Rx flow control is enabled (we can receive pause frames
1464 * but not send pause frames).
1465 * 2: Tx flow control is enabled (we can send pause frames
1466 * but we do not support receiving pause frames).
1467 * 3: Both Rx and TX flow control (symmetric) are enabled.
1468 * other: No software override. The flow control configuration
1469 * in the EEPROM is used.
1472 case e1000_fc_none
: /* 0 */
1473 /* Flow control (RX & TX) is completely disabled by a
1474 * software over-ride.
1476 mii_autoneg_adv_reg
&= ~(NWAY_AR_ASM_DIR
| NWAY_AR_PAUSE
);
1478 case e1000_fc_rx_pause
: /* 1 */
1479 /* RX Flow control is enabled, and TX Flow control is
1480 * disabled, by a software over-ride.
1482 /* Since there really isn't a way to advertise that we are
1483 * capable of RX Pause ONLY, we will advertise that we
1484 * support both symmetric and asymmetric RX PAUSE. Later
1485 * (in e1000_config_fc_after_link_up) we will disable the
1486 *hw's ability to send PAUSE frames.
1488 mii_autoneg_adv_reg
|= (NWAY_AR_ASM_DIR
| NWAY_AR_PAUSE
);
1490 case e1000_fc_tx_pause
: /* 2 */
1491 /* TX Flow control is enabled, and RX Flow control is
1492 * disabled, by a software over-ride.
1494 mii_autoneg_adv_reg
|= NWAY_AR_ASM_DIR
;
1495 mii_autoneg_adv_reg
&= ~NWAY_AR_PAUSE
;
1497 case e1000_fc_full
: /* 3 */
1498 /* Flow control (both RX and TX) is enabled by a software
1501 mii_autoneg_adv_reg
|= (NWAY_AR_ASM_DIR
| NWAY_AR_PAUSE
);
1504 DEBUGOUT("Flow control param set incorrectly\n");
1505 return -E1000_ERR_CONFIG
;
1508 if (e1000_write_phy_reg(hw
, PHY_AUTONEG_ADV
, mii_autoneg_adv_reg
) < 0) {
1509 DEBUGOUT("PHY Write Error\n");
1510 return -E1000_ERR_PHY
;
1513 DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg
);
1515 if (e1000_write_phy_reg(hw
, PHY_1000T_CTRL
, mii_1000t_ctrl_reg
) < 0) {
1516 DEBUGOUT("PHY Write Error\n");
1517 return -E1000_ERR_PHY
;
1522 /******************************************************************************
1523 * Sets the collision distance in the Transmit Control register
1525 * hw - Struct containing variables accessed by shared code
1527 * Link should have been established previously. Reads the speed and duplex
1528 * information from the Device Status register.
1529 ******************************************************************************/
1531 e1000_config_collision_dist(struct e1000_hw
*hw
)
1535 tctl
= E1000_READ_REG(hw
, TCTL
);
1537 tctl
&= ~E1000_TCTL_COLD
;
1538 tctl
|= E1000_COLLISION_DISTANCE
<< E1000_COLD_SHIFT
;
1540 E1000_WRITE_REG(hw
, TCTL
, tctl
);
1541 E1000_WRITE_FLUSH(hw
);
1544 /******************************************************************************
1545 * Sets MAC speed and duplex settings to reflect the those in the PHY
1547 * hw - Struct containing variables accessed by shared code
1548 * mii_reg - data to write to the MII control register
1550 * The contents of the PHY register containing the needed information need to
1552 ******************************************************************************/
1554 e1000_config_mac_to_phy(struct e1000_hw
*hw
)
1561 /* Read the Device Control Register and set the bits to Force Speed
1564 ctrl
= E1000_READ_REG(hw
, CTRL
);
1565 ctrl
|= (E1000_CTRL_FRCSPD
| E1000_CTRL_FRCDPX
);
1566 ctrl
&= ~(E1000_CTRL_SPD_SEL
| E1000_CTRL_ILOS
);
1568 /* Set up duplex in the Device Control and Transmit Control
1569 * registers depending on negotiated values.
1571 if (e1000_read_phy_reg(hw
, M88E1000_PHY_SPEC_STATUS
, &phy_data
) < 0) {
1572 DEBUGOUT("PHY Read Error\n");
1573 return -E1000_ERR_PHY
;
1575 if (phy_data
& M88E1000_PSSR_DPLX
)
1576 ctrl
|= E1000_CTRL_FD
;
1578 ctrl
&= ~E1000_CTRL_FD
;
1580 e1000_config_collision_dist(hw
);
1582 /* Set up speed in the Device Control register depending on
1583 * negotiated values.
1585 if ((phy_data
& M88E1000_PSSR_SPEED
) == M88E1000_PSSR_1000MBS
)
1586 ctrl
|= E1000_CTRL_SPD_1000
;
1587 else if ((phy_data
& M88E1000_PSSR_SPEED
) == M88E1000_PSSR_100MBS
)
1588 ctrl
|= E1000_CTRL_SPD_100
;
1589 /* Write the configured values back to the Device Control Reg. */
1590 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
1594 /******************************************************************************
1595 * Forces the MAC's flow control settings.
1597 * hw - Struct containing variables accessed by shared code
1599 * Sets the TFCE and RFCE bits in the device control register to reflect
1600 * the adapter settings. TFCE and RFCE need to be explicitly set by
1601 * software when a Copper PHY is used because autonegotiation is managed
1602 * by the PHY rather than the MAC. Software must also configure these
1603 * bits when link is forced on a fiber connection.
1604 *****************************************************************************/
1606 e1000_force_mac_fc(struct e1000_hw
*hw
)
1612 /* Get the current configuration of the Device Control Register */
1613 ctrl
= E1000_READ_REG(hw
, CTRL
);
1615 /* Because we didn't get link via the internal auto-negotiation
1616 * mechanism (we either forced link or we got link via PHY
1617 * auto-neg), we have to manually enable/disable transmit an
1618 * receive flow control.
1620 * The "Case" statement below enables/disable flow control
1621 * according to the "hw->fc" parameter.
1623 * The possible values of the "fc" parameter are:
1624 * 0: Flow control is completely disabled
1625 * 1: Rx flow control is enabled (we can receive pause
1626 * frames but not send pause frames).
1627 * 2: Tx flow control is enabled (we can send pause frames
1628 * frames but we do not receive pause frames).
1629 * 3: Both Rx and TX flow control (symmetric) is enabled.
1630 * other: No other values should be possible at this point.
1635 ctrl
&= (~(E1000_CTRL_TFCE
| E1000_CTRL_RFCE
));
1637 case e1000_fc_rx_pause
:
1638 ctrl
&= (~E1000_CTRL_TFCE
);
1639 ctrl
|= E1000_CTRL_RFCE
;
1641 case e1000_fc_tx_pause
:
1642 ctrl
&= (~E1000_CTRL_RFCE
);
1643 ctrl
|= E1000_CTRL_TFCE
;
1646 ctrl
|= (E1000_CTRL_TFCE
| E1000_CTRL_RFCE
);
1649 DEBUGOUT("Flow control param set incorrectly\n");
1650 return -E1000_ERR_CONFIG
;
1653 /* Disable TX Flow Control for 82542 (rev 2.0) */
1654 if (hw
->mac_type
== e1000_82542_rev2_0
)
1655 ctrl
&= (~E1000_CTRL_TFCE
);
1657 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
1661 /******************************************************************************
1662 * Configures flow control settings after link is established
1664 * hw - Struct containing variables accessed by shared code
1666 * Should be called immediately after a valid link has been established.
1667 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1668 * and autonegotiation is enabled, the MAC flow control settings will be set
1669 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1670 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1671 *****************************************************************************/
1673 e1000_config_fc_after_link_up(struct e1000_hw
*hw
)
1676 uint16_t mii_status_reg
;
1677 uint16_t mii_nway_adv_reg
;
1678 uint16_t mii_nway_lp_ability_reg
;
1684 /* Check for the case where we have fiber media and auto-neg failed
1685 * so we had to force link. In this case, we need to force the
1686 * configuration of the MAC to match the "fc" parameter.
1688 if ((hw
->media_type
== e1000_media_type_fiber
) && (hw
->autoneg_failed
)) {
1689 ret_val
= e1000_force_mac_fc(hw
);
1691 DEBUGOUT("Error forcing flow control settings\n");
1696 /* Check for the case where we have copper media and auto-neg is
1697 * enabled. In this case, we need to check and see if Auto-Neg
1698 * has completed, and if so, how the PHY and link partner has
1699 * flow control configured.
1701 if (hw
->media_type
== e1000_media_type_copper
) {
1702 /* Read the MII Status Register and check to see if AutoNeg
1703 * has completed. We read this twice because this reg has
1704 * some "sticky" (latched) bits.
1706 if (e1000_read_phy_reg(hw
, PHY_STATUS
, &mii_status_reg
) < 0) {
1707 DEBUGOUT("PHY Read Error \n");
1708 return -E1000_ERR_PHY
;
1710 if (e1000_read_phy_reg(hw
, PHY_STATUS
, &mii_status_reg
) < 0) {
1711 DEBUGOUT("PHY Read Error \n");
1712 return -E1000_ERR_PHY
;
1715 if (mii_status_reg
& MII_SR_AUTONEG_COMPLETE
) {
1716 /* The AutoNeg process has completed, so we now need to
1717 * read both the Auto Negotiation Advertisement Register
1718 * (Address 4) and the Auto_Negotiation Base Page Ability
1719 * Register (Address 5) to determine how flow control was
1722 if (e1000_read_phy_reg
1723 (hw
, PHY_AUTONEG_ADV
, &mii_nway_adv_reg
) < 0) {
1724 DEBUGOUT("PHY Read Error\n");
1725 return -E1000_ERR_PHY
;
1727 if (e1000_read_phy_reg
1728 (hw
, PHY_LP_ABILITY
,
1729 &mii_nway_lp_ability_reg
) < 0) {
1730 DEBUGOUT("PHY Read Error\n");
1731 return -E1000_ERR_PHY
;
1734 /* Two bits in the Auto Negotiation Advertisement Register
1735 * (Address 4) and two bits in the Auto Negotiation Base
1736 * Page Ability Register (Address 5) determine flow control
1737 * for both the PHY and the link partner. The following
1738 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
1739 * 1999, describes these PAUSE resolution bits and how flow
1740 * control is determined based upon these settings.
1741 * NOTE: DC = Don't Care
1743 * LOCAL DEVICE | LINK PARTNER
1744 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
1745 *-------|---------|-------|---------|--------------------
1746 * 0 | 0 | DC | DC | e1000_fc_none
1747 * 0 | 1 | 0 | DC | e1000_fc_none
1748 * 0 | 1 | 1 | 0 | e1000_fc_none
1749 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1750 * 1 | 0 | 0 | DC | e1000_fc_none
1751 * 1 | DC | 1 | DC | e1000_fc_full
1752 * 1 | 1 | 0 | 0 | e1000_fc_none
1753 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1756 /* Are both PAUSE bits set to 1? If so, this implies
1757 * Symmetric Flow Control is enabled at both ends. The
1758 * ASM_DIR bits are irrelevant per the spec.
1760 * For Symmetric Flow Control:
1762 * LOCAL DEVICE | LINK PARTNER
1763 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1764 *-------|---------|-------|---------|--------------------
1765 * 1 | DC | 1 | DC | e1000_fc_full
1768 if ((mii_nway_adv_reg
& NWAY_AR_PAUSE
) &&
1769 (mii_nway_lp_ability_reg
& NWAY_LPAR_PAUSE
)) {
1770 /* Now we need to check if the user selected RX ONLY
1771 * of pause frames. In this case, we had to advertise
1772 * FULL flow control because we could not advertise RX
1773 * ONLY. Hence, we must now check to see if we need to
1774 * turn OFF the TRANSMISSION of PAUSE frames.
1776 if (hw
->original_fc
== e1000_fc_full
) {
1777 hw
->fc
= e1000_fc_full
;
1778 DEBUGOUT("Flow Control = FULL.\r\n");
1780 hw
->fc
= e1000_fc_rx_pause
;
1782 ("Flow Control = RX PAUSE frames only.\r\n");
1785 /* For receiving PAUSE frames ONLY.
1787 * LOCAL DEVICE | LINK PARTNER
1788 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1789 *-------|---------|-------|---------|--------------------
1790 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1793 else if (!(mii_nway_adv_reg
& NWAY_AR_PAUSE
) &&
1794 (mii_nway_adv_reg
& NWAY_AR_ASM_DIR
) &&
1795 (mii_nway_lp_ability_reg
& NWAY_LPAR_PAUSE
) &&
1796 (mii_nway_lp_ability_reg
& NWAY_LPAR_ASM_DIR
))
1798 hw
->fc
= e1000_fc_tx_pause
;
1800 ("Flow Control = TX PAUSE frames only.\r\n");
1802 /* For transmitting PAUSE frames ONLY.
1804 * LOCAL DEVICE | LINK PARTNER
1805 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1806 *-------|---------|-------|---------|--------------------
1807 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1810 else if ((mii_nway_adv_reg
& NWAY_AR_PAUSE
) &&
1811 (mii_nway_adv_reg
& NWAY_AR_ASM_DIR
) &&
1812 !(mii_nway_lp_ability_reg
& NWAY_LPAR_PAUSE
) &&
1813 (mii_nway_lp_ability_reg
& NWAY_LPAR_ASM_DIR
))
1815 hw
->fc
= e1000_fc_rx_pause
;
1817 ("Flow Control = RX PAUSE frames only.\r\n");
1819 /* Per the IEEE spec, at this point flow control should be
1820 * disabled. However, we want to consider that we could
1821 * be connected to a legacy switch that doesn't advertise
1822 * desired flow control, but can be forced on the link
1823 * partner. So if we advertised no flow control, that is
1824 * what we will resolve to. If we advertised some kind of
1825 * receive capability (Rx Pause Only or Full Flow Control)
1826 * and the link partner advertised none, we will configure
1827 * ourselves to enable Rx Flow Control only. We can do
1828 * this safely for two reasons: If the link partner really
1829 * didn't want flow control enabled, and we enable Rx, no
1830 * harm done since we won't be receiving any PAUSE frames
1831 * anyway. If the intent on the link partner was to have
1832 * flow control enabled, then by us enabling RX only, we
1833 * can at least receive pause frames and process them.
1834 * This is a good idea because in most cases, since we are
1835 * predominantly a server NIC, more times than not we will
1836 * be asked to delay transmission of packets than asking
1837 * our link partner to pause transmission of frames.
1839 else if (hw
->original_fc
== e1000_fc_none
||
1840 hw
->original_fc
== e1000_fc_tx_pause
) {
1841 hw
->fc
= e1000_fc_none
;
1842 DEBUGOUT("Flow Control = NONE.\r\n");
1844 hw
->fc
= e1000_fc_rx_pause
;
1846 ("Flow Control = RX PAUSE frames only.\r\n");
1849 /* Now we need to do one last check... If we auto-
1850 * negotiated to HALF DUPLEX, flow control should not be
1851 * enabled per IEEE 802.3 spec.
1853 e1000_get_speed_and_duplex(hw
, &speed
, &duplex
);
1855 if (duplex
== HALF_DUPLEX
)
1856 hw
->fc
= e1000_fc_none
;
1858 /* Now we call a subroutine to actually force the MAC
1859 * controller to use the correct flow control settings.
1861 ret_val
= e1000_force_mac_fc(hw
);
1864 ("Error forcing flow control settings\n");
1869 ("Copper PHY and Auto Neg has not completed.\r\n");
1875 /******************************************************************************
1876 * Checks to see if the link status of the hardware has changed.
1878 * hw - Struct containing variables accessed by shared code
1880 * Called by any function that needs to check the link status of the adapter.
1881 *****************************************************************************/
1883 e1000_check_for_link(struct eth_device
*nic
)
1885 struct e1000_hw
*hw
= nic
->priv
;
1893 uint16_t lp_capability
;
1897 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
1898 * set when the optics detect a signal. On older adapters, it will be
1899 * cleared when there is a signal
1901 ctrl
= E1000_READ_REG(hw
, CTRL
);
1902 if ((hw
->mac_type
> e1000_82544
) && !(ctrl
& E1000_CTRL_ILOS
))
1903 signal
= E1000_CTRL_SWDPIN1
;
1907 status
= E1000_READ_REG(hw
, STATUS
);
1908 rxcw
= E1000_READ_REG(hw
, RXCW
);
1909 DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl
, status
, rxcw
);
1911 /* If we have a copper PHY then we only want to go out to the PHY
1912 * registers to see if Auto-Neg has completed and/or if our link
1913 * status has changed. The get_link_status flag will be set if we
1914 * receive a Link Status Change interrupt or we have Rx Sequence
1917 if ((hw
->media_type
== e1000_media_type_copper
) && hw
->get_link_status
) {
1918 /* First we want to see if the MII Status Register reports
1919 * link. If so, then we want to get the current speed/duplex
1921 * Read the register twice since the link bit is sticky.
1923 if (e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
) < 0) {
1924 DEBUGOUT("PHY Read Error\n");
1925 return -E1000_ERR_PHY
;
1927 if (e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
) < 0) {
1928 DEBUGOUT("PHY Read Error\n");
1929 return -E1000_ERR_PHY
;
1932 if (phy_data
& MII_SR_LINK_STATUS
) {
1933 hw
->get_link_status
= FALSE
;
1935 /* No link detected */
1936 return -E1000_ERR_NOLINK
;
1939 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
1940 * have Si on board that is 82544 or newer, Auto
1941 * Speed Detection takes care of MAC speed/duplex
1942 * configuration. So we only need to configure Collision
1943 * Distance in the MAC. Otherwise, we need to force
1944 * speed/duplex on the MAC to the current PHY speed/duplex
1947 if (hw
->mac_type
>= e1000_82544
)
1948 e1000_config_collision_dist(hw
);
1950 ret_val
= e1000_config_mac_to_phy(hw
);
1953 ("Error configuring MAC to PHY settings\n");
1958 /* Configure Flow Control now that Auto-Neg has completed. First, we
1959 * need to restore the desired flow control settings because we may
1960 * have had to re-autoneg with a different link partner.
1962 ret_val
= e1000_config_fc_after_link_up(hw
);
1964 DEBUGOUT("Error configuring flow control\n");
1968 /* At this point we know that we are on copper and we have
1969 * auto-negotiated link. These are conditions for checking the link
1970 * parter capability register. We use the link partner capability to
1971 * determine if TBI Compatibility needs to be turned on or off. If
1972 * the link partner advertises any speed in addition to Gigabit, then
1973 * we assume that they are GMII-based, and TBI compatibility is not
1974 * needed. If no other speeds are advertised, we assume the link
1975 * partner is TBI-based, and we turn on TBI Compatibility.
1977 if (hw
->tbi_compatibility_en
) {
1978 if (e1000_read_phy_reg
1979 (hw
, PHY_LP_ABILITY
, &lp_capability
) < 0) {
1980 DEBUGOUT("PHY Read Error\n");
1981 return -E1000_ERR_PHY
;
1983 if (lp_capability
& (NWAY_LPAR_10T_HD_CAPS
|
1984 NWAY_LPAR_10T_FD_CAPS
|
1985 NWAY_LPAR_100TX_HD_CAPS
|
1986 NWAY_LPAR_100TX_FD_CAPS
|
1987 NWAY_LPAR_100T4_CAPS
)) {
1988 /* If our link partner advertises anything in addition to
1989 * gigabit, we do not need to enable TBI compatibility.
1991 if (hw
->tbi_compatibility_on
) {
1992 /* If we previously were in the mode, turn it off. */
1993 rctl
= E1000_READ_REG(hw
, RCTL
);
1994 rctl
&= ~E1000_RCTL_SBP
;
1995 E1000_WRITE_REG(hw
, RCTL
, rctl
);
1996 hw
->tbi_compatibility_on
= FALSE
;
1999 /* If TBI compatibility is was previously off, turn it on. For
2000 * compatibility with a TBI link partner, we will store bad
2001 * packets. Some frames have an additional byte on the end and
2002 * will look like CRC errors to to the hardware.
2004 if (!hw
->tbi_compatibility_on
) {
2005 hw
->tbi_compatibility_on
= TRUE
;
2006 rctl
= E1000_READ_REG(hw
, RCTL
);
2007 rctl
|= E1000_RCTL_SBP
;
2008 E1000_WRITE_REG(hw
, RCTL
, rctl
);
2013 /* If we don't have link (auto-negotiation failed or link partner cannot
2014 * auto-negotiate), the cable is plugged in (we have signal), and our
2015 * link partner is not trying to auto-negotiate with us (we are receiving
2016 * idles or data), we need to force link up. We also need to give
2017 * auto-negotiation time to complete, in case the cable was just plugged
2018 * in. The autoneg_failed flag does this.
2020 else if ((hw
->media_type
== e1000_media_type_fiber
) &&
2021 (!(status
& E1000_STATUS_LU
)) &&
2022 ((ctrl
& E1000_CTRL_SWDPIN1
) == signal
) &&
2023 (!(rxcw
& E1000_RXCW_C
))) {
2024 if (hw
->autoneg_failed
== 0) {
2025 hw
->autoneg_failed
= 1;
2028 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
2030 /* Disable auto-negotiation in the TXCW register */
2031 E1000_WRITE_REG(hw
, TXCW
, (hw
->txcw
& ~E1000_TXCW_ANE
));
2033 /* Force link-up and also force full-duplex. */
2034 ctrl
= E1000_READ_REG(hw
, CTRL
);
2035 ctrl
|= (E1000_CTRL_SLU
| E1000_CTRL_FD
);
2036 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
2038 /* Configure Flow Control after forcing link up. */
2039 ret_val
= e1000_config_fc_after_link_up(hw
);
2041 DEBUGOUT("Error configuring flow control\n");
2045 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2046 * auto-negotiation in the TXCW register and disable forced link in the
2047 * Device Control register in an attempt to auto-negotiate with our link
2050 else if ((hw
->media_type
== e1000_media_type_fiber
) &&
2051 (ctrl
& E1000_CTRL_SLU
) && (rxcw
& E1000_RXCW_C
)) {
2053 ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2054 E1000_WRITE_REG(hw
, TXCW
, hw
->txcw
);
2055 E1000_WRITE_REG(hw
, CTRL
, (ctrl
& ~E1000_CTRL_SLU
));
2060 /******************************************************************************
2061 * Detects the current speed and duplex settings of the hardware.
2063 * hw - Struct containing variables accessed by shared code
2064 * speed - Speed of the connection
2065 * duplex - Duplex setting of the connection
2066 *****************************************************************************/
2068 e1000_get_speed_and_duplex(struct e1000_hw
*hw
,
2069 uint16_t * speed
, uint16_t * duplex
)
2075 if (hw
->mac_type
>= e1000_82543
) {
2076 status
= E1000_READ_REG(hw
, STATUS
);
2077 if (status
& E1000_STATUS_SPEED_1000
) {
2078 *speed
= SPEED_1000
;
2079 DEBUGOUT("1000 Mbs, ");
2080 } else if (status
& E1000_STATUS_SPEED_100
) {
2082 DEBUGOUT("100 Mbs, ");
2085 DEBUGOUT("10 Mbs, ");
2088 if (status
& E1000_STATUS_FD
) {
2089 *duplex
= FULL_DUPLEX
;
2090 DEBUGOUT("Full Duplex\r\n");
2092 *duplex
= HALF_DUPLEX
;
2093 DEBUGOUT(" Half Duplex\r\n");
2096 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2097 *speed
= SPEED_1000
;
2098 *duplex
= FULL_DUPLEX
;
2102 /******************************************************************************
2103 * Blocks until autoneg completes or times out (~4.5 seconds)
2105 * hw - Struct containing variables accessed by shared code
2106 ******************************************************************************/
2108 e1000_wait_autoneg(struct e1000_hw
*hw
)
2114 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2116 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2117 for (i
= PHY_AUTO_NEG_TIME
; i
> 0; i
--) {
2118 /* Read the MII Status Register and wait for Auto-Neg
2119 * Complete bit to be set.
2121 if (e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
) < 0) {
2122 DEBUGOUT("PHY Read Error\n");
2123 return -E1000_ERR_PHY
;
2125 if (e1000_read_phy_reg(hw
, PHY_STATUS
, &phy_data
) < 0) {
2126 DEBUGOUT("PHY Read Error\n");
2127 return -E1000_ERR_PHY
;
2129 if (phy_data
& MII_SR_AUTONEG_COMPLETE
) {
2130 DEBUGOUT("Auto-Neg complete.\n");
2135 DEBUGOUT("Auto-Neg timedout.\n");
2136 return -E1000_ERR_TIMEOUT
;
2139 /******************************************************************************
2140 * Raises the Management Data Clock
2142 * hw - Struct containing variables accessed by shared code
2143 * ctrl - Device control register's current value
2144 ******************************************************************************/
2146 e1000_raise_mdi_clk(struct e1000_hw
*hw
, uint32_t * ctrl
)
2148 /* Raise the clock input to the Management Data Clock (by setting the MDC
2149 * bit), and then delay 2 microseconds.
2151 E1000_WRITE_REG(hw
, CTRL
, (*ctrl
| E1000_CTRL_MDC
));
2152 E1000_WRITE_FLUSH(hw
);
2156 /******************************************************************************
2157 * Lowers the Management Data Clock
2159 * hw - Struct containing variables accessed by shared code
2160 * ctrl - Device control register's current value
2161 ******************************************************************************/
2163 e1000_lower_mdi_clk(struct e1000_hw
*hw
, uint32_t * ctrl
)
2165 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2166 * bit), and then delay 2 microseconds.
2168 E1000_WRITE_REG(hw
, CTRL
, (*ctrl
& ~E1000_CTRL_MDC
));
2169 E1000_WRITE_FLUSH(hw
);
2173 /******************************************************************************
2174 * Shifts data bits out to the PHY
2176 * hw - Struct containing variables accessed by shared code
2177 * data - Data to send out to the PHY
2178 * count - Number of bits to shift out
2180 * Bits are shifted out in MSB to LSB order.
2181 ******************************************************************************/
2183 e1000_shift_out_mdi_bits(struct e1000_hw
*hw
, uint32_t data
, uint16_t count
)
2188 /* We need to shift "count" number of bits out to the PHY. So, the value
2189 * in the "data" parameter will be shifted out to the PHY one bit at a
2190 * time. In order to do this, "data" must be broken down into bits.
2193 mask
<<= (count
- 1);
2195 ctrl
= E1000_READ_REG(hw
, CTRL
);
2197 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2198 ctrl
|= (E1000_CTRL_MDIO_DIR
| E1000_CTRL_MDC_DIR
);
2201 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2202 * then raising and lowering the Management Data Clock. A "0" is
2203 * shifted out to the PHY by setting the MDIO bit to "0" and then
2204 * raising and lowering the clock.
2207 ctrl
|= E1000_CTRL_MDIO
;
2209 ctrl
&= ~E1000_CTRL_MDIO
;
2211 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
2212 E1000_WRITE_FLUSH(hw
);
2216 e1000_raise_mdi_clk(hw
, &ctrl
);
2217 e1000_lower_mdi_clk(hw
, &ctrl
);
2223 /******************************************************************************
2224 * Shifts data bits in from the PHY
2226 * hw - Struct containing variables accessed by shared code
2228 * Bits are shifted in in MSB to LSB order.
2229 ******************************************************************************/
2231 e1000_shift_in_mdi_bits(struct e1000_hw
*hw
)
2237 /* In order to read a register from the PHY, we need to shift in a total
2238 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2239 * to avoid contention on the MDIO pin when a read operation is performed.
2240 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2241 * by raising the input to the Management Data Clock (setting the MDC bit),
2242 * and then reading the value of the MDIO bit.
2244 ctrl
= E1000_READ_REG(hw
, CTRL
);
2246 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2247 ctrl
&= ~E1000_CTRL_MDIO_DIR
;
2248 ctrl
&= ~E1000_CTRL_MDIO
;
2250 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
2251 E1000_WRITE_FLUSH(hw
);
2253 /* Raise and Lower the clock before reading in the data. This accounts for
2254 * the turnaround bits. The first clock occurred when we clocked out the
2255 * last bit of the Register Address.
2257 e1000_raise_mdi_clk(hw
, &ctrl
);
2258 e1000_lower_mdi_clk(hw
, &ctrl
);
2260 for (data
= 0, i
= 0; i
< 16; i
++) {
2262 e1000_raise_mdi_clk(hw
, &ctrl
);
2263 ctrl
= E1000_READ_REG(hw
, CTRL
);
2264 /* Check to see if we shifted in a "1". */
2265 if (ctrl
& E1000_CTRL_MDIO
)
2267 e1000_lower_mdi_clk(hw
, &ctrl
);
2270 e1000_raise_mdi_clk(hw
, &ctrl
);
2271 e1000_lower_mdi_clk(hw
, &ctrl
);
2276 /*****************************************************************************
2277 * Reads the value from a PHY register
2279 * hw - Struct containing variables accessed by shared code
2280 * reg_addr - address of the PHY register to read
2281 ******************************************************************************/
2283 e1000_read_phy_reg(struct e1000_hw
*hw
, uint32_t reg_addr
, uint16_t * phy_data
)
2287 const uint32_t phy_addr
= 1;
2289 if (reg_addr
> MAX_PHY_REG_ADDRESS
) {
2290 DEBUGOUT("PHY Address %d is out of range\n", reg_addr
);
2291 return -E1000_ERR_PARAM
;
2294 if (hw
->mac_type
> e1000_82543
) {
2295 /* Set up Op-code, Phy Address, and register address in the MDI
2296 * Control register. The MAC will take care of interfacing with the
2297 * PHY to retrieve the desired data.
2299 mdic
= ((reg_addr
<< E1000_MDIC_REG_SHIFT
) |
2300 (phy_addr
<< E1000_MDIC_PHY_SHIFT
) |
2301 (E1000_MDIC_OP_READ
));
2303 E1000_WRITE_REG(hw
, MDIC
, mdic
);
2305 /* Poll the ready bit to see if the MDI read completed */
2306 for (i
= 0; i
< 64; i
++) {
2308 mdic
= E1000_READ_REG(hw
, MDIC
);
2309 if (mdic
& E1000_MDIC_READY
)
2312 if (!(mdic
& E1000_MDIC_READY
)) {
2313 DEBUGOUT("MDI Read did not complete\n");
2314 return -E1000_ERR_PHY
;
2316 if (mdic
& E1000_MDIC_ERROR
) {
2317 DEBUGOUT("MDI Error\n");
2318 return -E1000_ERR_PHY
;
2320 *phy_data
= (uint16_t) mdic
;
2322 /* We must first send a preamble through the MDIO pin to signal the
2323 * beginning of an MII instruction. This is done by sending 32
2324 * consecutive "1" bits.
2326 e1000_shift_out_mdi_bits(hw
, PHY_PREAMBLE
, PHY_PREAMBLE_SIZE
);
2328 /* Now combine the next few fields that are required for a read
2329 * operation. We use this method instead of calling the
2330 * e1000_shift_out_mdi_bits routine five different times. The format of
2331 * a MII read instruction consists of a shift out of 14 bits and is
2332 * defined as follows:
2333 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2334 * followed by a shift in of 18 bits. This first two bits shifted in
2335 * are TurnAround bits used to avoid contention on the MDIO pin when a
2336 * READ operation is performed. These two bits are thrown away
2337 * followed by a shift in of 16 bits which contains the desired data.
2339 mdic
= ((reg_addr
) | (phy_addr
<< 5) |
2340 (PHY_OP_READ
<< 10) | (PHY_SOF
<< 12));
2342 e1000_shift_out_mdi_bits(hw
, mdic
, 14);
2344 /* Now that we've shifted out the read command to the MII, we need to
2345 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2348 *phy_data
= e1000_shift_in_mdi_bits(hw
);
2353 /******************************************************************************
2354 * Writes a value to a PHY register
2356 * hw - Struct containing variables accessed by shared code
2357 * reg_addr - address of the PHY register to write
2358 * data - data to write to the PHY
2359 ******************************************************************************/
2361 e1000_write_phy_reg(struct e1000_hw
*hw
, uint32_t reg_addr
, uint16_t phy_data
)
2365 const uint32_t phy_addr
= 1;
2367 if (reg_addr
> MAX_PHY_REG_ADDRESS
) {
2368 DEBUGOUT("PHY Address %d is out of range\n", reg_addr
);
2369 return -E1000_ERR_PARAM
;
2372 if (hw
->mac_type
> e1000_82543
) {
2373 /* Set up Op-code, Phy Address, register address, and data intended
2374 * for the PHY register in the MDI Control register. The MAC will take
2375 * care of interfacing with the PHY to send the desired data.
2377 mdic
= (((uint32_t) phy_data
) |
2378 (reg_addr
<< E1000_MDIC_REG_SHIFT
) |
2379 (phy_addr
<< E1000_MDIC_PHY_SHIFT
) |
2380 (E1000_MDIC_OP_WRITE
));
2382 E1000_WRITE_REG(hw
, MDIC
, mdic
);
2384 /* Poll the ready bit to see if the MDI read completed */
2385 for (i
= 0; i
< 64; i
++) {
2387 mdic
= E1000_READ_REG(hw
, MDIC
);
2388 if (mdic
& E1000_MDIC_READY
)
2391 if (!(mdic
& E1000_MDIC_READY
)) {
2392 DEBUGOUT("MDI Write did not complete\n");
2393 return -E1000_ERR_PHY
;
2396 /* We'll need to use the SW defined pins to shift the write command
2397 * out to the PHY. We first send a preamble to the PHY to signal the
2398 * beginning of the MII instruction. This is done by sending 32
2399 * consecutive "1" bits.
2401 e1000_shift_out_mdi_bits(hw
, PHY_PREAMBLE
, PHY_PREAMBLE_SIZE
);
2403 /* Now combine the remaining required fields that will indicate a
2404 * write operation. We use this method instead of calling the
2405 * e1000_shift_out_mdi_bits routine for each field in the command. The
2406 * format of a MII write instruction is as follows:
2407 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2409 mdic
= ((PHY_TURNAROUND
) | (reg_addr
<< 2) | (phy_addr
<< 7) |
2410 (PHY_OP_WRITE
<< 12) | (PHY_SOF
<< 14));
2412 mdic
|= (uint32_t) phy_data
;
2414 e1000_shift_out_mdi_bits(hw
, mdic
, 32);
2419 /******************************************************************************
2420 * Returns the PHY to the power-on reset state
2422 * hw - Struct containing variables accessed by shared code
2423 ******************************************************************************/
2425 e1000_phy_hw_reset(struct e1000_hw
*hw
)
2432 DEBUGOUT("Resetting Phy...\n");
2434 if (hw
->mac_type
> e1000_82543
) {
2435 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2436 * bit. Then, take it out of reset.
2438 ctrl
= E1000_READ_REG(hw
, CTRL
);
2439 E1000_WRITE_REG(hw
, CTRL
, ctrl
| E1000_CTRL_PHY_RST
);
2440 E1000_WRITE_FLUSH(hw
);
2442 E1000_WRITE_REG(hw
, CTRL
, ctrl
);
2443 E1000_WRITE_FLUSH(hw
);
2445 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2446 * bit to put the PHY into reset. Then, take it out of reset.
2448 ctrl_ext
= E1000_READ_REG(hw
, CTRL_EXT
);
2449 ctrl_ext
|= E1000_CTRL_EXT_SDP4_DIR
;
2450 ctrl_ext
&= ~E1000_CTRL_EXT_SDP4_DATA
;
2451 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
2452 E1000_WRITE_FLUSH(hw
);
2454 ctrl_ext
|= E1000_CTRL_EXT_SDP4_DATA
;
2455 E1000_WRITE_REG(hw
, CTRL_EXT
, ctrl_ext
);
2456 E1000_WRITE_FLUSH(hw
);
2461 /******************************************************************************
2464 * hw - Struct containing variables accessed by shared code
2466 * Sets bit 15 of the MII Control regiser
2467 ******************************************************************************/
2469 e1000_phy_reset(struct e1000_hw
*hw
)
2475 if (e1000_read_phy_reg(hw
, PHY_CTRL
, &phy_data
) < 0) {
2476 DEBUGOUT("PHY Read Error\n");
2477 return -E1000_ERR_PHY
;
2479 phy_data
|= MII_CR_RESET
;
2480 if (e1000_write_phy_reg(hw
, PHY_CTRL
, phy_data
) < 0) {
2481 DEBUGOUT("PHY Write Error\n");
2482 return -E1000_ERR_PHY
;
2488 /******************************************************************************
2489 * Probes the expected PHY address for known PHY IDs
2491 * hw - Struct containing variables accessed by shared code
2492 ******************************************************************************/
2494 e1000_detect_gig_phy(struct e1000_hw
*hw
)
2496 uint16_t phy_id_high
, phy_id_low
;
2501 /* Read the PHY ID Registers to identify which PHY is onboard. */
2502 if (e1000_read_phy_reg(hw
, PHY_ID1
, &phy_id_high
) < 0) {
2503 DEBUGOUT("PHY Read Error\n");
2504 return -E1000_ERR_PHY
;
2506 hw
->phy_id
= (uint32_t) (phy_id_high
<< 16);
2508 if (e1000_read_phy_reg(hw
, PHY_ID2
, &phy_id_low
) < 0) {
2509 DEBUGOUT("PHY Read Error\n");
2510 return -E1000_ERR_PHY
;
2512 hw
->phy_id
|= (uint32_t) (phy_id_low
& PHY_REVISION_MASK
);
2514 switch (hw
->mac_type
) {
2516 if (hw
->phy_id
== M88E1000_E_PHY_ID
)
2520 if (hw
->phy_id
== M88E1000_I_PHY_ID
)
2526 if (hw
->phy_id
== M88E1011_I_PHY_ID
)
2530 DEBUGOUT("Invalid MAC type %d\n", hw
->mac_type
);
2531 return -E1000_ERR_CONFIG
;
2534 DEBUGOUT("PHY ID 0x%X detected\n", hw
->phy_id
);
2537 DEBUGOUT("Invalid PHY ID 0x%X\n", hw
->phy_id
);
2538 return -E1000_ERR_PHY
;
2542 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2544 * e1000_sw_init initializes the Adapter private data structure.
2545 * Fields are initialized based on PCI device information and
2546 * OS network device settings (MTU size).
2550 e1000_sw_init(struct eth_device
*nic
, int cardnum
)
2552 struct e1000_hw
*hw
= (typeof(hw
)) nic
->priv
;
2555 /* PCI config space info */
2556 pci_read_config_word(hw
->pdev
, PCI_VENDOR_ID
, &hw
->vendor_id
);
2557 pci_read_config_word(hw
->pdev
, PCI_DEVICE_ID
, &hw
->device_id
);
2558 pci_read_config_word(hw
->pdev
, PCI_SUBSYSTEM_VENDOR_ID
,
2559 &hw
->subsystem_vendor_id
);
2560 pci_read_config_word(hw
->pdev
, PCI_SUBSYSTEM_ID
, &hw
->subsystem_id
);
2562 pci_read_config_byte(hw
->pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
2563 pci_read_config_word(hw
->pdev
, PCI_COMMAND
, &hw
->pci_cmd_word
);
2565 /* identify the MAC */
2566 result
= e1000_set_mac_type(hw
);
2568 E1000_ERR("Unknown MAC Type\n");
2572 /* lan a vs. lan b settings */
2573 if (hw
->mac_type
== e1000_82546
)
2574 /*this also works w/ multiple 82546 cards */
2575 /*but not if they're intermingled /w other e1000s */
2576 hw
->lan_loc
= (cardnum
% 2) ? e1000_lan_b
: e1000_lan_a
;
2578 hw
->lan_loc
= e1000_lan_a
;
2580 /* flow control settings */
2581 hw
->fc_high_water
= E1000_FC_HIGH_THRESH
;
2582 hw
->fc_low_water
= E1000_FC_LOW_THRESH
;
2583 hw
->fc_pause_time
= E1000_FC_PAUSE_TIME
;
2584 hw
->fc_send_xon
= 1;
2586 /* Media type - copper or fiber */
2588 if (hw
->mac_type
>= e1000_82543
) {
2589 uint32_t status
= E1000_READ_REG(hw
, STATUS
);
2591 if (status
& E1000_STATUS_TBIMODE
) {
2592 DEBUGOUT("fiber interface\n");
2593 hw
->media_type
= e1000_media_type_fiber
;
2595 DEBUGOUT("copper interface\n");
2596 hw
->media_type
= e1000_media_type_copper
;
2599 hw
->media_type
= e1000_media_type_fiber
;
2602 if (hw
->mac_type
< e1000_82543
)
2603 hw
->report_tx_early
= 0;
2605 hw
->report_tx_early
= 1;
2607 hw
->tbi_compatibility_en
= TRUE
;
2609 hw
->wait_autoneg_complete
= FALSE
;
2610 hw
->adaptive_ifs
= TRUE
;
2612 /* Copper options */
2613 if (hw
->media_type
== e1000_media_type_copper
) {
2614 hw
->mdix
= AUTO_ALL_MODES
;
2615 hw
->disable_polarity_correction
= FALSE
;
2618 return E1000_SUCCESS
;
2622 fill_rx(struct e1000_hw
*hw
)
2624 struct e1000_rx_desc
*rd
;
2627 rd
= rx_base
+ rx_tail
;
2628 rx_tail
= (rx_tail
+ 1) % 8;
2630 rd
->buffer_addr
= cpu_to_le64((u32
) & packet
);
2631 E1000_WRITE_REG(hw
, RDT
, rx_tail
);
2635 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
2636 * @adapter: board private structure
2638 * Configure the Tx unit of the MAC after a reset.
2642 e1000_configure_tx(struct e1000_hw
*hw
)
2648 ptr
= (u32
) tx_pool
;
2650 ptr
= (ptr
+ 0x10) & (~0xf);
2652 tx_base
= (typeof(tx_base
)) ptr
;
2654 E1000_WRITE_REG(hw
, TDBAL
, (u32
) tx_base
);
2655 E1000_WRITE_REG(hw
, TDBAH
, 0);
2657 E1000_WRITE_REG(hw
, TDLEN
, 128);
2659 /* Setup the HW Tx Head and Tail descriptor pointers */
2660 E1000_WRITE_REG(hw
, TDH
, 0);
2661 E1000_WRITE_REG(hw
, TDT
, 0);
2664 /* Set the default values for the Tx Inter Packet Gap timer */
2665 switch (hw
->mac_type
) {
2666 case e1000_82542_rev2_0
:
2667 case e1000_82542_rev2_1
:
2668 tipg
= DEFAULT_82542_TIPG_IPGT
;
2669 tipg
|= DEFAULT_82542_TIPG_IPGR1
<< E1000_TIPG_IPGR1_SHIFT
;
2670 tipg
|= DEFAULT_82542_TIPG_IPGR2
<< E1000_TIPG_IPGR2_SHIFT
;
2673 if (hw
->media_type
== e1000_media_type_fiber
)
2674 tipg
= DEFAULT_82543_TIPG_IPGT_FIBER
;
2676 tipg
= DEFAULT_82543_TIPG_IPGT_COPPER
;
2677 tipg
|= DEFAULT_82543_TIPG_IPGR1
<< E1000_TIPG_IPGR1_SHIFT
;
2678 tipg
|= DEFAULT_82543_TIPG_IPGR2
<< E1000_TIPG_IPGR2_SHIFT
;
2680 E1000_WRITE_REG(hw
, TIPG
, tipg
);
2682 /* Set the Tx Interrupt Delay register */
2683 E1000_WRITE_REG(hw
, TIDV
, adapter
->tx_int_delay
);
2684 if (hw
->mac_type
>= e1000_82540
)
2685 E1000_WRITE_REG(hw
, TADV
, adapter
->tx_abs_int_delay
);
2687 /* Program the Transmit Control Register */
2688 tctl
= E1000_READ_REG(hw
, TCTL
);
2689 tctl
&= ~E1000_TCTL_CT
;
2690 tctl
|= E1000_TCTL_EN
| E1000_TCTL_PSP
|
2691 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
2692 E1000_WRITE_REG(hw
, TCTL
, tctl
);
2694 e1000_config_collision_dist(hw
);
2696 /* Setup Transmit Descriptor Settings for this adapter */
2697 adapter
->txd_cmd
= E1000_TXD_CMD_IFCS
| E1000_TXD_CMD_IDE
;
2699 if (adapter
->hw
.report_tx_early
== 1)
2700 adapter
->txd_cmd
|= E1000_TXD_CMD_RS
;
2702 adapter
->txd_cmd
|= E1000_TXD_CMD_RPS
;
2707 * e1000_setup_rctl - configure the receive control register
2708 * @adapter: Board private structure
2711 e1000_setup_rctl(struct e1000_hw
*hw
)
2715 rctl
= E1000_READ_REG(hw
, RCTL
);
2717 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
2719 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
| E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
; /* |
2720 (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */
2722 if (hw
->tbi_compatibility_on
== 1)
2723 rctl
|= E1000_RCTL_SBP
;
2725 rctl
&= ~E1000_RCTL_SBP
;
2727 rctl
&= ~(E1000_RCTL_SZ_4096
);
2729 switch (adapter
->rx_buffer_len
) {
2730 case E1000_RXBUFFER_2048
:
2733 rctl
|= E1000_RCTL_SZ_2048
;
2734 rctl
&= ~(E1000_RCTL_BSEX
| E1000_RCTL_LPE
);
2737 case E1000_RXBUFFER_4096
:
2738 rctl
|= E1000_RCTL_SZ_4096
| E1000_RCTL_BSEX
| E1000_RCTL_LPE
;
2740 case E1000_RXBUFFER_8192
:
2741 rctl
|= E1000_RCTL_SZ_8192
| E1000_RCTL_BSEX
| E1000_RCTL_LPE
;
2743 case E1000_RXBUFFER_16384
:
2744 rctl
|= E1000_RCTL_SZ_16384
| E1000_RCTL_BSEX
| E1000_RCTL_LPE
;
2748 E1000_WRITE_REG(hw
, RCTL
, rctl
);
2752 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
2753 * @adapter: board private structure
2755 * Configure the Rx unit of the MAC after a reset.
2758 e1000_configure_rx(struct e1000_hw
*hw
)
2763 unsigned long rxcsum
;
2766 /* make sure receives are disabled while setting up the descriptors */
2767 rctl
= E1000_READ_REG(hw
, RCTL
);
2768 E1000_WRITE_REG(hw
, RCTL
, rctl
& ~E1000_RCTL_EN
);
2770 /* set the Receive Delay Timer Register */
2772 E1000_WRITE_REG(hw
, RDTR
, adapter
->rx_int_delay
);
2774 if (hw
->mac_type
>= e1000_82540
) {
2776 E1000_WRITE_REG(hw
, RADV
, adapter
->rx_abs_int_delay
);
2778 /* Set the interrupt throttling rate. Value is calculated
2779 * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */
2780 #define MAX_INTS_PER_SEC 8000
2781 #define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
2782 E1000_WRITE_REG(hw
, ITR
, DEFAULT_ITR
);
2785 /* Setup the Base and Length of the Rx Descriptor Ring */
2786 ptr
= (u32
) rx_pool
;
2788 ptr
= (ptr
+ 0x10) & (~0xf);
2789 rx_base
= (typeof(rx_base
)) ptr
;
2790 E1000_WRITE_REG(hw
, RDBAL
, (u32
) rx_base
);
2791 E1000_WRITE_REG(hw
, RDBAH
, 0);
2793 E1000_WRITE_REG(hw
, RDLEN
, 128);
2795 /* Setup the HW Rx Head and Tail Descriptor Pointers */
2796 E1000_WRITE_REG(hw
, RDH
, 0);
2797 E1000_WRITE_REG(hw
, RDT
, 0);
2799 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
2800 if ((adapter
->hw
.mac_type
>= e1000_82543
) && (adapter
->rx_csum
== TRUE
)) {
2801 rxcsum
= E1000_READ_REG(hw
, RXCSUM
);
2802 rxcsum
|= E1000_RXCSUM_TUOFL
;
2803 E1000_WRITE_REG(hw
, RXCSUM
, rxcsum
);
2806 /* Enable Receives */
2808 E1000_WRITE_REG(hw
, RCTL
, rctl
);
2812 /**************************************************************************
2813 POLL - Wait for a frame
2814 ***************************************************************************/
2816 e1000_poll(struct eth_device
*nic
)
2818 struct e1000_hw
*hw
= nic
->priv
;
2819 struct e1000_rx_desc
*rd
;
2820 /* return true if there's an ethernet packet ready to read */
2821 rd
= rx_base
+ rx_last
;
2822 if (!(le32_to_cpu(rd
->status
)) & E1000_RXD_STAT_DD
)
2824 /*DEBUGOUT("recv: packet len=%d \n", rd->length); */
2825 NetReceive((uchar
*)packet
, le32_to_cpu(rd
->length
));
2830 /**************************************************************************
2831 TRANSMIT - Transmit a frame
2832 ***************************************************************************/
2834 e1000_transmit(struct eth_device
*nic
, volatile void *packet
, int length
)
2836 struct e1000_hw
*hw
= nic
->priv
;
2837 struct e1000_tx_desc
*txp
;
2840 txp
= tx_base
+ tx_tail
;
2841 tx_tail
= (tx_tail
+ 1) % 8;
2843 txp
->buffer_addr
= cpu_to_le64(virt_to_bus(packet
));
2844 txp
->lower
.data
= cpu_to_le32(E1000_TXD_CMD_RPS
| E1000_TXD_CMD_EOP
|
2845 E1000_TXD_CMD_IFCS
| length
);
2846 txp
->upper
.data
= 0;
2847 E1000_WRITE_REG(hw
, TDT
, tx_tail
);
2849 while (!(le32_to_cpu(txp
->upper
.data
) & E1000_TXD_STAT_DD
)) {
2850 if (i
++ > TOUT_LOOP
) {
2851 DEBUGOUT("e1000: tx timeout\n");
2854 udelay(10); /* give the nic a chance to write to the register */
2861 e1000_reset(struct eth_device
*nic
)
2863 struct e1000_hw
*hw
= nic
->priv
;
2866 if (hw
->mac_type
>= e1000_82544
) {
2867 E1000_WRITE_REG(hw
, WUC
, 0);
2869 return e1000_init_hw(nic
);
2872 /**************************************************************************
2873 DISABLE - Turn off ethernet interface
2874 ***************************************************************************/
2876 e1000_disable(struct eth_device
*nic
)
2878 struct e1000_hw
*hw
= nic
->priv
;
2880 /* Turn off the ethernet interface */
2881 E1000_WRITE_REG(hw
, RCTL
, 0);
2882 E1000_WRITE_REG(hw
, TCTL
, 0);
2884 /* Clear the transmit ring */
2885 E1000_WRITE_REG(hw
, TDH
, 0);
2886 E1000_WRITE_REG(hw
, TDT
, 0);
2888 /* Clear the receive ring */
2889 E1000_WRITE_REG(hw
, RDH
, 0);
2890 E1000_WRITE_REG(hw
, RDT
, 0);
2892 /* put the card in its initial state */
2894 E1000_WRITE_REG(hw
, CTRL
, E1000_CTRL_RST
);
2900 /**************************************************************************
2901 INIT - set up ethernet interface(s)
2902 ***************************************************************************/
2904 e1000_init(struct eth_device
*nic
, bd_t
* bis
)
2906 struct e1000_hw
*hw
= nic
->priv
;
2909 ret_val
= e1000_reset(nic
);
2911 if ((ret_val
== -E1000_ERR_NOLINK
) ||
2912 (ret_val
== -E1000_ERR_TIMEOUT
)) {
2913 E1000_ERR("Valid Link not detected\n");
2915 E1000_ERR("Hardware Initialization Failed\n");
2919 e1000_configure_tx(hw
);
2920 e1000_setup_rctl(hw
);
2921 e1000_configure_rx(hw
);
2925 /**************************************************************************
2926 PROBE - Look for an adapter, this routine's visible to the outside
2927 You should omit the last argument struct pci_device * for a non-PCI NIC
2928 ***************************************************************************/
2930 e1000_initialize(bd_t
* bis
)
2933 int card_number
= 0;
2934 struct eth_device
*nic
= NULL
;
2935 struct e1000_hw
*hw
= NULL
;
2940 while (1) { /* Find PCI device(s) */
2941 if ((devno
= pci_find_devices(supported
, idx
++)) < 0) {
2945 pci_read_config_dword(devno
, PCI_BASE_ADDRESS_0
, &iobase
);
2946 iobase
&= ~0xf; /* Mask the bits that say "this is an io addr" */
2947 DEBUGOUT("e1000#%d: iobase 0x%08x\n", card_number
, iobase
);
2949 pci_write_config_dword(devno
, PCI_COMMAND
,
2950 PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
);
2951 /* Check if I/O accesses and Bus Mastering are enabled. */
2952 pci_read_config_dword(devno
, PCI_COMMAND
, &PciCommandWord
);
2953 if (!(PciCommandWord
& PCI_COMMAND_MEMORY
)) {
2954 printf("Error: Can not enable MEM access.\n");
2956 } else if (!(PciCommandWord
& PCI_COMMAND_MASTER
)) {
2957 printf("Error: Can not enable Bus Mastering.\n");
2961 nic
= (struct eth_device
*) malloc(sizeof (*nic
));
2962 hw
= (struct e1000_hw
*) malloc(sizeof (*hw
));
2965 nic
->iobase
= bus_to_phys(devno
, iobase
);
2967 sprintf(nic
->name
, "e1000#%d", card_number
);
2969 /* Are these variables needed? */
2971 hw
->fc
= e1000_fc_none
;
2972 hw
->original_fc
= e1000_fc_none
;
2974 hw
->fc
= e1000_fc_default
;
2975 hw
->original_fc
= e1000_fc_default
;
2977 hw
->autoneg_failed
= 0;
2978 hw
->get_link_status
= TRUE
;
2979 hw
->hw_addr
= (typeof(hw
->hw_addr
)) iobase
;
2980 hw
->mac_type
= e1000_undefined
;
2982 /* MAC and Phy settings */
2983 if (e1000_sw_init(nic
, card_number
) < 0) {
2988 #ifndef CONFIG_AP1000
2989 if (e1000_validate_eeprom_checksum(nic
) < 0) {
2990 printf("The EEPROM Checksum Is Not Valid\n");
2996 e1000_read_mac_addr(nic
);
2998 E1000_WRITE_REG(hw
, PBA
, E1000_DEFAULT_PBA
);
3000 printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n",
3001 nic
->enetaddr
[0], nic
->enetaddr
[1], nic
->enetaddr
[2],
3002 nic
->enetaddr
[3], nic
->enetaddr
[4], nic
->enetaddr
[5]);
3004 nic
->init
= e1000_init
;
3005 nic
->recv
= e1000_poll
;
3006 nic
->send
= e1000_transmit
;
3007 nic
->halt
= e1000_disable
;