1 /**************************************************************************
2 Intel 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 #define TOUT_LOOP 100000
50 #define virt_to_bus(x) ((unsigned long)x)
51 #define bus_to_phys(devno, a) pci_mem_to_phys(devno, a)
52 #define mdelay(n) udelay((n)*1000)
54 #define E1000_DEFAULT_PBA 0x00000030
56 /* NIC specific static variables go here */
58 static char tx_pool[128 + 16];
59 static char rx_pool[128 + 16];
60 static char packet[2096];
62 static struct e1000_tx_desc *tx_base;
63 static struct e1000_rx_desc *rx_base;
66 static int rx_tail, rx_last;
68 static struct pci_device_id supported[] = {
69 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82542},
70 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_FIBER},
71 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_COPPER},
72 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_COPPER},
73 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_FIBER},
74 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_COPPER},
75 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_LOM},
76 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM},
77 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_COPPER},
78 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545GM_COPPER},
79 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_COPPER},
80 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_FIBER},
81 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_FIBER},
82 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM_LOM},
83 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541ER},
84 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541GI_LF},
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;
515 #ifdef CONFIG_E1000_FALLBACK_MAC
516 if ( *(u32*)(nic->enetaddr) == 0 || *(u32*)(nic->enetaddr) == ~0 ) {
517 unsigned char fb_mac[NODE_ADDRESS_SIZE] = CONFIG_E1000_FALLBACK_MAC;
519 memcpy (nic->enetaddr, fb_mac, NODE_ADDRESS_SIZE);
524 * The AP1000's e1000 has no eeprom; the MAC address is stored in the
525 * environment variables. Currently this does not support the addition
526 * of a PMC e1000 card, which is certainly a possibility, so this should
527 * be updated to properly use the env variable only for the onboard e1000
535 s = getenv ("ethaddr");
537 return -E1000_ERR_EEPROM;
539 for(ii = 0; ii < 6; ii++) {
540 nic->enetaddr[ii] = s ? simple_strtoul (s, &e, 16) : 0;
542 s = (*e) ? e + 1 : e;
550 /******************************************************************************
551 * Initializes receive address filters.
553 * hw - Struct containing variables accessed by shared code
555 * Places the MAC address in receive address register 0 and clears the rest
556 * of the receive addresss registers. Clears the multicast table. Assumes
557 * the receiver is in reset when the routine is called.
558 *****************************************************************************/
560 e1000_init_rx_addrs(struct eth_device *nic)
562 struct e1000_hw *hw = nic->priv;
569 /* Setup the receive address. */
570 DEBUGOUT("Programming MAC Address into RAR[0]\n");
571 addr_low = (nic->enetaddr[0] |
572 (nic->enetaddr[1] << 8) |
573 (nic->enetaddr[2] << 16) | (nic->enetaddr[3] << 24));
575 addr_high = (nic->enetaddr[4] | (nic->enetaddr[5] << 8) | E1000_RAH_AV);
577 E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
578 E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
580 /* Zero out the other 15 receive addresses. */
581 DEBUGOUT("Clearing RAR[1-15]\n");
582 for (i = 1; i < E1000_RAR_ENTRIES; i++) {
583 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
584 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
588 /******************************************************************************
589 * Clears the VLAN filer table
591 * hw - Struct containing variables accessed by shared code
592 *****************************************************************************/
594 e1000_clear_vfta(struct e1000_hw *hw)
598 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
599 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
602 /******************************************************************************
603 * Set the mac type member in the hw struct.
605 * hw - Struct containing variables accessed by shared code
606 *****************************************************************************/
608 e1000_set_mac_type(struct e1000_hw *hw)
612 switch (hw->device_id) {
613 case E1000_DEV_ID_82542:
614 switch (hw->revision_id) {
615 case E1000_82542_2_0_REV_ID:
616 hw->mac_type = e1000_82542_rev2_0;
618 case E1000_82542_2_1_REV_ID:
619 hw->mac_type = e1000_82542_rev2_1;
622 /* Invalid 82542 revision ID */
623 return -E1000_ERR_MAC_TYPE;
626 case E1000_DEV_ID_82543GC_FIBER:
627 case E1000_DEV_ID_82543GC_COPPER:
628 hw->mac_type = e1000_82543;
630 case E1000_DEV_ID_82544EI_COPPER:
631 case E1000_DEV_ID_82544EI_FIBER:
632 case E1000_DEV_ID_82544GC_COPPER:
633 case E1000_DEV_ID_82544GC_LOM:
634 hw->mac_type = e1000_82544;
636 case E1000_DEV_ID_82540EM:
637 case E1000_DEV_ID_82540EM_LOM:
638 hw->mac_type = e1000_82540;
640 case E1000_DEV_ID_82545EM_COPPER:
641 case E1000_DEV_ID_82545GM_COPPER:
642 case E1000_DEV_ID_82545EM_FIBER:
643 hw->mac_type = e1000_82545;
645 case E1000_DEV_ID_82546EB_COPPER:
646 case E1000_DEV_ID_82546EB_FIBER:
647 hw->mac_type = e1000_82546;
649 case E1000_DEV_ID_82541ER:
650 case E1000_DEV_ID_82541GI_LF:
651 hw->mac_type = e1000_82541_rev_2;
654 /* Should never have loaded on this device */
655 return -E1000_ERR_MAC_TYPE;
657 return E1000_SUCCESS;
660 /******************************************************************************
661 * Reset the transmit and receive units; mask and clear all interrupts.
663 * hw - Struct containing variables accessed by shared code
664 *****************************************************************************/
666 e1000_reset_hw(struct e1000_hw *hw)
675 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
676 if (hw->mac_type == e1000_82542_rev2_0) {
677 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
678 pci_write_config_word(hw->pdev, PCI_COMMAND,
680 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
683 /* Clear interrupt mask to stop board from generating interrupts */
684 DEBUGOUT("Masking off all interrupts\n");
685 E1000_WRITE_REG(hw, IMC, 0xffffffff);
687 /* Disable the Transmit and Receive units. Then delay to allow
688 * any pending transactions to complete before we hit the MAC with
691 E1000_WRITE_REG(hw, RCTL, 0);
692 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
693 E1000_WRITE_FLUSH(hw);
695 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
696 hw->tbi_compatibility_on = FALSE;
698 /* Delay to allow any outstanding PCI transactions to complete before
699 * resetting the device
703 /* Issue a global reset to the MAC. This will reset the chip's
704 * transmit, receive, DMA, and link units. It will not effect
705 * the current PCI configuration. The global reset bit is self-
706 * clearing, and should clear within a microsecond.
708 DEBUGOUT("Issuing a global reset to MAC\n");
709 ctrl = E1000_READ_REG(hw, CTRL);
712 if (hw->mac_type > e1000_82543)
713 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
716 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
718 /* Force a reload from the EEPROM if necessary */
719 if (hw->mac_type < e1000_82540) {
720 /* Wait for reset to complete */
722 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
723 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
724 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
725 E1000_WRITE_FLUSH(hw);
726 /* Wait for EEPROM reload */
729 /* Wait for EEPROM reload (it happens automatically) */
731 /* Dissable HW ARPs on ASF enabled adapters */
732 manc = E1000_READ_REG(hw, MANC);
733 manc &= ~(E1000_MANC_ARP_EN);
734 E1000_WRITE_REG(hw, MANC, manc);
737 /* Clear interrupt mask to stop board from generating interrupts */
738 DEBUGOUT("Masking off all interrupts\n");
739 E1000_WRITE_REG(hw, IMC, 0xffffffff);
741 /* Clear any pending interrupt events. */
742 icr = E1000_READ_REG(hw, ICR);
744 /* If MWI was previously enabled, reenable it. */
745 if (hw->mac_type == e1000_82542_rev2_0) {
746 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
750 /******************************************************************************
751 * Performs basic configuration of the adapter.
753 * hw - Struct containing variables accessed by shared code
755 * Assumes that the controller has previously been reset and is in a
756 * post-reset uninitialized state. Initializes the receive address registers,
757 * multicast table, and VLAN filter table. Calls routines to setup link
758 * configuration and flow control settings. Clears all on-chip counters. Leaves
759 * the transmit and receive units disabled and uninitialized.
760 *****************************************************************************/
762 e1000_init_hw(struct eth_device *nic)
764 struct e1000_hw *hw = nic->priv;
765 uint32_t ctrl, status;
768 uint16_t pcix_cmd_word;
769 uint16_t pcix_stat_hi_word;
772 e1000_bus_type bus_type = e1000_bus_type_unknown;
776 /* Initialize Identification LED */
777 ret_val = e1000_id_led_init(hw);
779 DEBUGOUT("Error Initializing Identification LED\n");
783 /* Set the Media Type and exit with error if it is not valid. */
784 if (hw->mac_type != e1000_82543) {
785 /* tbi_compatibility is only valid on 82543 */
786 hw->tbi_compatibility_en = FALSE;
789 if (hw->mac_type >= e1000_82543) {
790 status = E1000_READ_REG(hw, STATUS);
791 if (status & E1000_STATUS_TBIMODE) {
792 hw->media_type = e1000_media_type_fiber;
793 /* tbi_compatibility not valid on fiber */
794 hw->tbi_compatibility_en = FALSE;
796 hw->media_type = e1000_media_type_copper;
799 /* This is an 82542 (fiber only) */
800 hw->media_type = e1000_media_type_fiber;
803 /* Disabling VLAN filtering. */
804 DEBUGOUT("Initializing the IEEE VLAN\n");
805 E1000_WRITE_REG(hw, VET, 0);
807 e1000_clear_vfta(hw);
809 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
810 if (hw->mac_type == e1000_82542_rev2_0) {
811 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
812 pci_write_config_word(hw->pdev, PCI_COMMAND,
814 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
815 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
816 E1000_WRITE_FLUSH(hw);
820 /* Setup the receive address. This involves initializing all of the Receive
821 * Address Registers (RARs 0 - 15).
823 e1000_init_rx_addrs(nic);
825 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
826 if (hw->mac_type == e1000_82542_rev2_0) {
827 E1000_WRITE_REG(hw, RCTL, 0);
828 E1000_WRITE_FLUSH(hw);
830 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
833 /* Zero out the Multicast HASH table */
834 DEBUGOUT("Zeroing the MTA\n");
835 for (i = 0; i < E1000_MC_TBL_SIZE; i++)
836 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
839 /* Set the PCI priority bit correctly in the CTRL register. This
840 * determines if the adapter gives priority to receives, or if it
841 * gives equal priority to transmits and receives.
843 if (hw->dma_fairness) {
844 ctrl = E1000_READ_REG(hw, CTRL);
845 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
848 if (hw->mac_type >= e1000_82543) {
849 status = E1000_READ_REG(hw, STATUS);
850 bus_type = (status & E1000_STATUS_PCIX_MODE) ?
851 e1000_bus_type_pcix : e1000_bus_type_pci;
853 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
854 if (bus_type == e1000_bus_type_pcix) {
855 pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
857 pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI,
860 (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
861 PCIX_COMMAND_MMRBC_SHIFT;
863 (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
864 PCIX_STATUS_HI_MMRBC_SHIFT;
865 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
866 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
867 if (cmd_mmrbc > stat_mmrbc) {
868 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
869 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
870 pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
875 /* Call a subroutine to configure the link and setup flow control. */
876 ret_val = e1000_setup_link(nic);
878 /* Set the transmit descriptor write-back policy */
879 if (hw->mac_type > e1000_82544) {
880 ctrl = E1000_READ_REG(hw, TXDCTL);
882 (ctrl & ~E1000_TXDCTL_WTHRESH) |
883 E1000_TXDCTL_FULL_TX_DESC_WB;
884 E1000_WRITE_REG(hw, TXDCTL, ctrl);
887 /* Clear all of the statistics registers (clear on read). It is
888 * important that we do this after we have tried to establish link
889 * because the symbol error count will increment wildly if there
892 e1000_clear_hw_cntrs(hw);
898 /******************************************************************************
899 * Configures flow control and link settings.
901 * hw - Struct containing variables accessed by shared code
903 * Determines which flow control settings to use. Calls the apropriate media-
904 * specific link configuration function. Configures the flow control settings.
905 * Assuming the adapter has a valid link partner, a valid link should be
906 * established. Assumes the hardware has previously been reset and the
907 * transmitter and receiver are not enabled.
908 *****************************************************************************/
910 e1000_setup_link(struct eth_device *nic)
912 struct e1000_hw *hw = nic->priv;
915 uint16_t eeprom_data;
919 #ifndef CONFIG_AP1000
920 /* Read and store word 0x0F of the EEPROM. This word contains bits
921 * that determine the hardware's default PAUSE (flow control) mode,
922 * a bit that determines whether the HW defaults to enabling or
923 * disabling auto-negotiation, and the direction of the
924 * SW defined pins. If there is no SW over-ride of the flow
925 * control setting, then the variable hw->fc will
926 * be initialized based on a value in the EEPROM.
928 if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, &eeprom_data) < 0) {
929 DEBUGOUT("EEPROM Read Error\n");
930 return -E1000_ERR_EEPROM;
933 /* we have to hardcode the proper value for our hardware. */
934 /* this value is for the 82540EM pci card used for prototyping, and it works. */
935 eeprom_data = 0xb220;
938 if (hw->fc == e1000_fc_default) {
939 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
940 hw->fc = e1000_fc_none;
941 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
942 EEPROM_WORD0F_ASM_DIR)
943 hw->fc = e1000_fc_tx_pause;
945 hw->fc = e1000_fc_full;
948 /* We want to save off the original Flow Control configuration just
949 * in case we get disconnected and then reconnected into a different
950 * hub or switch with different Flow Control capabilities.
952 if (hw->mac_type == e1000_82542_rev2_0)
953 hw->fc &= (~e1000_fc_tx_pause);
955 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
956 hw->fc &= (~e1000_fc_rx_pause);
958 hw->original_fc = hw->fc;
960 DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc);
962 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
963 * polarity value for the SW controlled pins, and setup the
964 * Extended Device Control reg with that info.
965 * This is needed because one of the SW controlled pins is used for
966 * signal detection. So this should be done before e1000_setup_pcs_link()
967 * or e1000_phy_setup() is called.
969 if (hw->mac_type == e1000_82543) {
970 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
972 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
975 /* Call the necessary subroutine to configure the link. */
976 ret_val = (hw->media_type == e1000_media_type_fiber) ?
977 e1000_setup_fiber_link(nic) : e1000_setup_copper_link(nic);
982 /* Initialize the flow control address, type, and PAUSE timer
983 * registers to their default values. This is done even if flow
984 * control is disabled, because it does not hurt anything to
985 * initialize these registers.
988 ("Initializing the Flow Control address, type and timer regs\n");
990 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
991 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
992 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
993 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
995 /* Set the flow control receive threshold registers. Normally,
996 * these registers will be set to a default threshold that may be
997 * adjusted later by the driver's runtime code. However, if the
998 * ability to transmit pause frames in not enabled, then these
999 * registers will be set to 0.
1001 if (!(hw->fc & e1000_fc_tx_pause)) {
1002 E1000_WRITE_REG(hw, FCRTL, 0);
1003 E1000_WRITE_REG(hw, FCRTH, 0);
1005 /* We need to set up the Receive Threshold high and low water marks
1006 * as well as (optionally) enabling the transmission of XON frames.
1008 if (hw->fc_send_xon) {
1009 E1000_WRITE_REG(hw, FCRTL,
1010 (hw->fc_low_water | E1000_FCRTL_XONE));
1011 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1013 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1014 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1020 /******************************************************************************
1021 * Sets up link for a fiber based adapter
1023 * hw - Struct containing variables accessed by shared code
1025 * Manipulates Physical Coding Sublayer functions in order to configure
1026 * link. Assumes the hardware has been previously reset and the transmitter
1027 * and receiver are not enabled.
1028 *****************************************************************************/
1030 e1000_setup_fiber_link(struct eth_device *nic)
1032 struct e1000_hw *hw = nic->priv;
1041 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
1042 * set when the optics detect a signal. On older adapters, it will be
1043 * cleared when there is a signal
1045 ctrl = E1000_READ_REG(hw, CTRL);
1046 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
1047 signal = E1000_CTRL_SWDPIN1;
1051 printf("signal for %s is %x (ctrl %08x)!!!!\n", nic->name, signal,
1053 /* Take the link out of reset */
1054 ctrl &= ~(E1000_CTRL_LRST);
1056 e1000_config_collision_dist(hw);
1058 /* Check for a software override of the flow control settings, and setup
1059 * the device accordingly. If auto-negotiation is enabled, then software
1060 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1061 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1062 * auto-negotiation is disabled, then software will have to manually
1063 * configure the two flow control enable bits in the CTRL register.
1065 * The possible values of the "fc" parameter are:
1066 * 0: Flow control is completely disabled
1067 * 1: Rx flow control is enabled (we can receive pause frames, but
1068 * not send pause frames).
1069 * 2: Tx flow control is enabled (we can send pause frames but we do
1070 * not support receiving pause frames).
1071 * 3: Both Rx and TX flow control (symmetric) are enabled.
1075 /* Flow control is completely disabled by a software over-ride. */
1076 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1078 case e1000_fc_rx_pause:
1079 /* RX Flow control is enabled and TX Flow control is disabled by a
1080 * software over-ride. Since there really isn't a way to advertise
1081 * that we are capable of RX Pause ONLY, we will advertise that we
1082 * support both symmetric and asymmetric RX PAUSE. Later, we will
1083 * disable the adapter's ability to send PAUSE frames.
1085 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1087 case e1000_fc_tx_pause:
1088 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1089 * software over-ride.
1091 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1094 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1095 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1098 DEBUGOUT("Flow control param set incorrectly\n");
1099 return -E1000_ERR_CONFIG;
1103 /* Since auto-negotiation is enabled, take the link out of reset (the link
1104 * will be in reset, because we previously reset the chip). This will
1105 * restart auto-negotiation. If auto-neogtiation is successful then the
1106 * link-up status bit will be set and the flow control enable bits (RFCE
1107 * and TFCE) will be set according to their negotiated value.
1109 DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw);
1111 E1000_WRITE_REG(hw, TXCW, txcw);
1112 E1000_WRITE_REG(hw, CTRL, ctrl);
1113 E1000_WRITE_FLUSH(hw);
1118 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1119 * indication in the Device Status Register. Time-out if a link isn't
1120 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1121 * less than 500 milliseconds even if the other end is doing it in SW).
1123 if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1124 DEBUGOUT("Looking for Link\n");
1125 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1127 status = E1000_READ_REG(hw, STATUS);
1128 if (status & E1000_STATUS_LU)
1131 if (i == (LINK_UP_TIMEOUT / 10)) {
1132 /* AutoNeg failed to achieve a link, so we'll call
1133 * e1000_check_for_link. This routine will force the link up if we
1134 * detect a signal. This will allow us to communicate with
1135 * non-autonegotiating link partners.
1137 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1138 hw->autoneg_failed = 1;
1139 ret_val = e1000_check_for_link(nic);
1141 DEBUGOUT("Error while checking for link\n");
1144 hw->autoneg_failed = 0;
1146 hw->autoneg_failed = 0;
1147 DEBUGOUT("Valid Link Found\n");
1150 DEBUGOUT("No Signal Detected\n");
1151 return -E1000_ERR_NOLINK;
1156 /******************************************************************************
1157 * Detects which PHY is present and the speed and duplex
1159 * hw - Struct containing variables accessed by shared code
1160 ******************************************************************************/
1162 e1000_setup_copper_link(struct eth_device *nic)
1164 struct e1000_hw *hw = nic->priv;
1172 ctrl = E1000_READ_REG(hw, CTRL);
1173 /* With 82543, we need to force speed and duplex on the MAC equal to what
1174 * the PHY speed and duplex configuration is. In addition, we need to
1175 * perform a hardware reset on the PHY to take it out of reset.
1177 if (hw->mac_type > e1000_82543) {
1178 ctrl |= E1000_CTRL_SLU;
1179 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1180 E1000_WRITE_REG(hw, CTRL, ctrl);
1183 (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1184 E1000_WRITE_REG(hw, CTRL, ctrl);
1185 e1000_phy_hw_reset(hw);
1188 /* Make sure we have a valid PHY */
1189 ret_val = e1000_detect_gig_phy(hw);
1191 DEBUGOUT("Error, did not detect valid phy.\n");
1194 DEBUGOUT("Phy ID = %x \n", hw->phy_id);
1196 /* Enable CRS on TX. This must be set for half-duplex operation. */
1197 if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data) < 0) {
1198 DEBUGOUT("PHY Read Error\n");
1199 return -E1000_ERR_PHY;
1201 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1205 * MDI/MDI-X = 0 (default)
1206 * 0 - Auto for all speeds
1209 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1211 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1214 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1217 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1220 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1224 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1228 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1233 * disable_polarity_correction = 0 (default)
1234 * Automatic Correction for Reversed Cable Polarity
1238 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1239 if (hw->disable_polarity_correction == 1)
1240 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1242 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1244 if (e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data) < 0) {
1245 DEBUGOUT("PHY Write Error\n");
1246 return -E1000_ERR_PHY;
1249 /* Force TX_CLK in the Extended PHY Specific Control Register
1252 if (e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data) < 0) {
1253 DEBUGOUT("PHY Read Error\n");
1254 return -E1000_ERR_PHY;
1256 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1257 /* Configure Master and Slave downshift values */
1258 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1259 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1260 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1261 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1262 if (e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data) < 0) {
1263 DEBUGOUT("PHY Write Error\n");
1264 return -E1000_ERR_PHY;
1267 /* SW Reset the PHY so all changes take effect */
1268 ret_val = e1000_phy_reset(hw);
1270 DEBUGOUT("Error Resetting the PHY\n");
1275 * autoneg = 1 (default)
1276 * PHY will advertise value(s) parsed from
1277 * autoneg_advertised and fc
1279 * PHY will be set to 10H, 10F, 100H, or 100F
1280 * depending on value parsed from forced_speed_duplex.
1283 /* Is autoneg enabled? This is enabled by default or by software override.
1284 * If so, call e1000_phy_setup_autoneg routine to parse the
1285 * autoneg_advertised and fc options. If autoneg is NOT enabled, then the
1286 * user should have provided a speed/duplex override. If so, then call
1287 * e1000_phy_force_speed_duplex to parse and set this up.
1289 /* Perform some bounds checking on the hw->autoneg_advertised
1290 * parameter. If this variable is zero, then set it to the default.
1292 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1294 /* If autoneg_advertised is zero, we assume it was not defaulted
1295 * by the calling code so we set to advertise full capability.
1297 if (hw->autoneg_advertised == 0)
1298 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1300 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1301 ret_val = e1000_phy_setup_autoneg(hw);
1303 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1306 DEBUGOUT("Restarting Auto-Neg\n");
1308 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1309 * the Auto Neg Restart bit in the PHY control register.
1311 if (e1000_read_phy_reg(hw, PHY_CTRL, &phy_data) < 0) {
1312 DEBUGOUT("PHY Read Error\n");
1313 return -E1000_ERR_PHY;
1315 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1316 if (e1000_write_phy_reg(hw, PHY_CTRL, phy_data) < 0) {
1317 DEBUGOUT("PHY Write Error\n");
1318 return -E1000_ERR_PHY;
1321 /* Does the user want to wait for Auto-Neg to complete here, or
1322 * check at a later time (for example, callback routine).
1324 if (hw->wait_autoneg_complete) {
1325 ret_val = e1000_wait_autoneg(hw);
1328 ("Error while waiting for autoneg to complete\n");
1333 /* If we do not wait for autonegtation to complete I
1334 * do not see a valid link status.
1336 ret_val = e1000_wait_autoneg(hw);
1338 DEBUGOUT("Error while waiting for autoneg to complete\n");
1343 /* Check link status. Wait up to 100 microseconds for link to become
1346 for (i = 0; i < 10; i++) {
1347 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1348 DEBUGOUT("PHY Read Error\n");
1349 return -E1000_ERR_PHY;
1351 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1352 DEBUGOUT("PHY Read Error\n");
1353 return -E1000_ERR_PHY;
1355 if (phy_data & MII_SR_LINK_STATUS) {
1356 /* We have link, so we need to finish the config process:
1357 * 1) Set up the MAC to the current PHY speed/duplex
1358 * if we are on 82543. If we
1359 * are on newer silicon, we only need to configure
1360 * collision distance in the Transmit Control Register.
1361 * 2) Set up flow control on the MAC to that established with
1364 if (hw->mac_type >= e1000_82544) {
1365 e1000_config_collision_dist(hw);
1367 ret_val = e1000_config_mac_to_phy(hw);
1370 ("Error configuring MAC to PHY settings\n");
1374 ret_val = e1000_config_fc_after_link_up(hw);
1376 DEBUGOUT("Error Configuring Flow Control\n");
1379 DEBUGOUT("Valid link established!!!\n");
1385 DEBUGOUT("Unable to establish link!!!\n");
1386 return -E1000_ERR_NOLINK;
1389 /******************************************************************************
1390 * Configures PHY autoneg and flow control advertisement settings
1392 * hw - Struct containing variables accessed by shared code
1393 ******************************************************************************/
1395 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1397 uint16_t mii_autoneg_adv_reg;
1398 uint16_t mii_1000t_ctrl_reg;
1402 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1403 if (e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg) < 0) {
1404 DEBUGOUT("PHY Read Error\n");
1405 return -E1000_ERR_PHY;
1408 /* Read the MII 1000Base-T Control Register (Address 9). */
1409 if (e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg) < 0) {
1410 DEBUGOUT("PHY Read Error\n");
1411 return -E1000_ERR_PHY;
1414 /* Need to parse both autoneg_advertised and fc and set up
1415 * the appropriate PHY registers. First we will parse for
1416 * autoneg_advertised software override. Since we can advertise
1417 * a plethora of combinations, we need to check each bit
1421 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1422 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1423 * the 1000Base-T Control Register (Address 9).
1425 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1426 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1428 DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised);
1430 /* Do we want to advertise 10 Mb Half Duplex? */
1431 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
1432 DEBUGOUT("Advertise 10mb Half duplex\n");
1433 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1436 /* Do we want to advertise 10 Mb Full Duplex? */
1437 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
1438 DEBUGOUT("Advertise 10mb Full duplex\n");
1439 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1442 /* Do we want to advertise 100 Mb Half Duplex? */
1443 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
1444 DEBUGOUT("Advertise 100mb Half duplex\n");
1445 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1448 /* Do we want to advertise 100 Mb Full Duplex? */
1449 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
1450 DEBUGOUT("Advertise 100mb Full duplex\n");
1451 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1454 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1455 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1457 ("Advertise 1000mb Half duplex requested, request denied!\n");
1460 /* Do we want to advertise 1000 Mb Full Duplex? */
1461 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1462 DEBUGOUT("Advertise 1000mb Full duplex\n");
1463 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1466 /* Check for a software override of the flow control settings, and
1467 * setup the PHY advertisement registers accordingly. If
1468 * auto-negotiation is enabled, then software will have to set the
1469 * "PAUSE" bits to the correct value in the Auto-Negotiation
1470 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1472 * The possible values of the "fc" parameter are:
1473 * 0: Flow control is completely disabled
1474 * 1: Rx flow control is enabled (we can receive pause frames
1475 * but not send pause frames).
1476 * 2: Tx flow control is enabled (we can send pause frames
1477 * but we do not support receiving pause frames).
1478 * 3: Both Rx and TX flow control (symmetric) are enabled.
1479 * other: No software override. The flow control configuration
1480 * in the EEPROM is used.
1483 case e1000_fc_none: /* 0 */
1484 /* Flow control (RX & TX) is completely disabled by a
1485 * software over-ride.
1487 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1489 case e1000_fc_rx_pause: /* 1 */
1490 /* RX Flow control is enabled, and TX Flow control is
1491 * disabled, by a software over-ride.
1493 /* Since there really isn't a way to advertise that we are
1494 * capable of RX Pause ONLY, we will advertise that we
1495 * support both symmetric and asymmetric RX PAUSE. Later
1496 * (in e1000_config_fc_after_link_up) we will disable the
1497 *hw's ability to send PAUSE frames.
1499 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1501 case e1000_fc_tx_pause: /* 2 */
1502 /* TX Flow control is enabled, and RX Flow control is
1503 * disabled, by a software over-ride.
1505 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1506 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1508 case e1000_fc_full: /* 3 */
1509 /* Flow control (both RX and TX) is enabled by a software
1512 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1515 DEBUGOUT("Flow control param set incorrectly\n");
1516 return -E1000_ERR_CONFIG;
1519 if (e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg) < 0) {
1520 DEBUGOUT("PHY Write Error\n");
1521 return -E1000_ERR_PHY;
1524 DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1526 if (e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg) < 0) {
1527 DEBUGOUT("PHY Write Error\n");
1528 return -E1000_ERR_PHY;
1533 /******************************************************************************
1534 * Sets the collision distance in the Transmit Control register
1536 * hw - Struct containing variables accessed by shared code
1538 * Link should have been established previously. Reads the speed and duplex
1539 * information from the Device Status register.
1540 ******************************************************************************/
1542 e1000_config_collision_dist(struct e1000_hw *hw)
1546 tctl = E1000_READ_REG(hw, TCTL);
1548 tctl &= ~E1000_TCTL_COLD;
1549 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
1551 E1000_WRITE_REG(hw, TCTL, tctl);
1552 E1000_WRITE_FLUSH(hw);
1555 /******************************************************************************
1556 * Sets MAC speed and duplex settings to reflect the those in the PHY
1558 * hw - Struct containing variables accessed by shared code
1559 * mii_reg - data to write to the MII control register
1561 * The contents of the PHY register containing the needed information need to
1563 ******************************************************************************/
1565 e1000_config_mac_to_phy(struct e1000_hw *hw)
1572 /* Read the Device Control Register and set the bits to Force Speed
1575 ctrl = E1000_READ_REG(hw, CTRL);
1576 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1577 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1579 /* Set up duplex in the Device Control and Transmit Control
1580 * registers depending on negotiated values.
1582 if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
1583 DEBUGOUT("PHY Read Error\n");
1584 return -E1000_ERR_PHY;
1586 if (phy_data & M88E1000_PSSR_DPLX)
1587 ctrl |= E1000_CTRL_FD;
1589 ctrl &= ~E1000_CTRL_FD;
1591 e1000_config_collision_dist(hw);
1593 /* Set up speed in the Device Control register depending on
1594 * negotiated values.
1596 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1597 ctrl |= E1000_CTRL_SPD_1000;
1598 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1599 ctrl |= E1000_CTRL_SPD_100;
1600 /* Write the configured values back to the Device Control Reg. */
1601 E1000_WRITE_REG(hw, CTRL, ctrl);
1605 /******************************************************************************
1606 * Forces the MAC's flow control settings.
1608 * hw - Struct containing variables accessed by shared code
1610 * Sets the TFCE and RFCE bits in the device control register to reflect
1611 * the adapter settings. TFCE and RFCE need to be explicitly set by
1612 * software when a Copper PHY is used because autonegotiation is managed
1613 * by the PHY rather than the MAC. Software must also configure these
1614 * bits when link is forced on a fiber connection.
1615 *****************************************************************************/
1617 e1000_force_mac_fc(struct e1000_hw *hw)
1623 /* Get the current configuration of the Device Control Register */
1624 ctrl = E1000_READ_REG(hw, CTRL);
1626 /* Because we didn't get link via the internal auto-negotiation
1627 * mechanism (we either forced link or we got link via PHY
1628 * auto-neg), we have to manually enable/disable transmit an
1629 * receive flow control.
1631 * The "Case" statement below enables/disable flow control
1632 * according to the "hw->fc" parameter.
1634 * The possible values of the "fc" parameter are:
1635 * 0: Flow control is completely disabled
1636 * 1: Rx flow control is enabled (we can receive pause
1637 * frames but not send pause frames).
1638 * 2: Tx flow control is enabled (we can send pause frames
1639 * frames but we do not receive pause frames).
1640 * 3: Both Rx and TX flow control (symmetric) is enabled.
1641 * other: No other values should be possible at this point.
1646 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1648 case e1000_fc_rx_pause:
1649 ctrl &= (~E1000_CTRL_TFCE);
1650 ctrl |= E1000_CTRL_RFCE;
1652 case e1000_fc_tx_pause:
1653 ctrl &= (~E1000_CTRL_RFCE);
1654 ctrl |= E1000_CTRL_TFCE;
1657 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1660 DEBUGOUT("Flow control param set incorrectly\n");
1661 return -E1000_ERR_CONFIG;
1664 /* Disable TX Flow Control for 82542 (rev 2.0) */
1665 if (hw->mac_type == e1000_82542_rev2_0)
1666 ctrl &= (~E1000_CTRL_TFCE);
1668 E1000_WRITE_REG(hw, CTRL, ctrl);
1672 /******************************************************************************
1673 * Configures flow control settings after link is established
1675 * hw - Struct containing variables accessed by shared code
1677 * Should be called immediately after a valid link has been established.
1678 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1679 * and autonegotiation is enabled, the MAC flow control settings will be set
1680 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1681 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1682 *****************************************************************************/
1684 e1000_config_fc_after_link_up(struct e1000_hw *hw)
1687 uint16_t mii_status_reg;
1688 uint16_t mii_nway_adv_reg;
1689 uint16_t mii_nway_lp_ability_reg;
1695 /* Check for the case where we have fiber media and auto-neg failed
1696 * so we had to force link. In this case, we need to force the
1697 * configuration of the MAC to match the "fc" parameter.
1699 if ((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) {
1700 ret_val = e1000_force_mac_fc(hw);
1702 DEBUGOUT("Error forcing flow control settings\n");
1707 /* Check for the case where we have copper media and auto-neg is
1708 * enabled. In this case, we need to check and see if Auto-Neg
1709 * has completed, and if so, how the PHY and link partner has
1710 * flow control configured.
1712 if (hw->media_type == e1000_media_type_copper) {
1713 /* Read the MII Status Register and check to see if AutoNeg
1714 * has completed. We read this twice because this reg has
1715 * some "sticky" (latched) bits.
1717 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
1718 DEBUGOUT("PHY Read Error \n");
1719 return -E1000_ERR_PHY;
1721 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
1722 DEBUGOUT("PHY Read Error \n");
1723 return -E1000_ERR_PHY;
1726 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
1727 /* The AutoNeg process has completed, so we now need to
1728 * read both the Auto Negotiation Advertisement Register
1729 * (Address 4) and the Auto_Negotiation Base Page Ability
1730 * Register (Address 5) to determine how flow control was
1733 if (e1000_read_phy_reg
1734 (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
1735 DEBUGOUT("PHY Read Error\n");
1736 return -E1000_ERR_PHY;
1738 if (e1000_read_phy_reg
1739 (hw, PHY_LP_ABILITY,
1740 &mii_nway_lp_ability_reg) < 0) {
1741 DEBUGOUT("PHY Read Error\n");
1742 return -E1000_ERR_PHY;
1745 /* Two bits in the Auto Negotiation Advertisement Register
1746 * (Address 4) and two bits in the Auto Negotiation Base
1747 * Page Ability Register (Address 5) determine flow control
1748 * for both the PHY and the link partner. The following
1749 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
1750 * 1999, describes these PAUSE resolution bits and how flow
1751 * control is determined based upon these settings.
1752 * NOTE: DC = Don't Care
1754 * LOCAL DEVICE | LINK PARTNER
1755 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
1756 *-------|---------|-------|---------|--------------------
1757 * 0 | 0 | DC | DC | e1000_fc_none
1758 * 0 | 1 | 0 | DC | e1000_fc_none
1759 * 0 | 1 | 1 | 0 | e1000_fc_none
1760 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1761 * 1 | 0 | 0 | DC | e1000_fc_none
1762 * 1 | DC | 1 | DC | e1000_fc_full
1763 * 1 | 1 | 0 | 0 | e1000_fc_none
1764 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1767 /* Are both PAUSE bits set to 1? If so, this implies
1768 * Symmetric Flow Control is enabled at both ends. The
1769 * ASM_DIR bits are irrelevant per the spec.
1771 * For Symmetric Flow Control:
1773 * LOCAL DEVICE | LINK PARTNER
1774 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1775 *-------|---------|-------|---------|--------------------
1776 * 1 | DC | 1 | DC | e1000_fc_full
1779 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1780 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
1781 /* Now we need to check if the user selected RX ONLY
1782 * of pause frames. In this case, we had to advertise
1783 * FULL flow control because we could not advertise RX
1784 * ONLY. Hence, we must now check to see if we need to
1785 * turn OFF the TRANSMISSION of PAUSE frames.
1787 if (hw->original_fc == e1000_fc_full) {
1788 hw->fc = e1000_fc_full;
1789 DEBUGOUT("Flow Control = FULL.\r\n");
1791 hw->fc = e1000_fc_rx_pause;
1793 ("Flow Control = RX PAUSE frames only.\r\n");
1796 /* For receiving PAUSE frames ONLY.
1798 * LOCAL DEVICE | LINK PARTNER
1799 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1800 *-------|---------|-------|---------|--------------------
1801 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1804 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1805 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1806 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1807 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
1809 hw->fc = e1000_fc_tx_pause;
1811 ("Flow Control = TX PAUSE frames only.\r\n");
1813 /* For transmitting PAUSE frames ONLY.
1815 * LOCAL DEVICE | LINK PARTNER
1816 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1817 *-------|---------|-------|---------|--------------------
1818 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1821 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1822 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1823 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1824 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
1826 hw->fc = e1000_fc_rx_pause;
1828 ("Flow Control = RX PAUSE frames only.\r\n");
1830 /* Per the IEEE spec, at this point flow control should be
1831 * disabled. However, we want to consider that we could
1832 * be connected to a legacy switch that doesn't advertise
1833 * desired flow control, but can be forced on the link
1834 * partner. So if we advertised no flow control, that is
1835 * what we will resolve to. If we advertised some kind of
1836 * receive capability (Rx Pause Only or Full Flow Control)
1837 * and the link partner advertised none, we will configure
1838 * ourselves to enable Rx Flow Control only. We can do
1839 * this safely for two reasons: If the link partner really
1840 * didn't want flow control enabled, and we enable Rx, no
1841 * harm done since we won't be receiving any PAUSE frames
1842 * anyway. If the intent on the link partner was to have
1843 * flow control enabled, then by us enabling RX only, we
1844 * can at least receive pause frames and process them.
1845 * This is a good idea because in most cases, since we are
1846 * predominantly a server NIC, more times than not we will
1847 * be asked to delay transmission of packets than asking
1848 * our link partner to pause transmission of frames.
1850 else if (hw->original_fc == e1000_fc_none ||
1851 hw->original_fc == e1000_fc_tx_pause) {
1852 hw->fc = e1000_fc_none;
1853 DEBUGOUT("Flow Control = NONE.\r\n");
1855 hw->fc = e1000_fc_rx_pause;
1857 ("Flow Control = RX PAUSE frames only.\r\n");
1860 /* Now we need to do one last check... If we auto-
1861 * negotiated to HALF DUPLEX, flow control should not be
1862 * enabled per IEEE 802.3 spec.
1864 e1000_get_speed_and_duplex(hw, &speed, &duplex);
1866 if (duplex == HALF_DUPLEX)
1867 hw->fc = e1000_fc_none;
1869 /* Now we call a subroutine to actually force the MAC
1870 * controller to use the correct flow control settings.
1872 ret_val = e1000_force_mac_fc(hw);
1875 ("Error forcing flow control settings\n");
1880 ("Copper PHY and Auto Neg has not completed.\r\n");
1886 /******************************************************************************
1887 * Checks to see if the link status of the hardware has changed.
1889 * hw - Struct containing variables accessed by shared code
1891 * Called by any function that needs to check the link status of the adapter.
1892 *****************************************************************************/
1894 e1000_check_for_link(struct eth_device *nic)
1896 struct e1000_hw *hw = nic->priv;
1904 uint16_t lp_capability;
1908 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
1909 * set when the optics detect a signal. On older adapters, it will be
1910 * cleared when there is a signal
1912 ctrl = E1000_READ_REG(hw, CTRL);
1913 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
1914 signal = E1000_CTRL_SWDPIN1;
1918 status = E1000_READ_REG(hw, STATUS);
1919 rxcw = E1000_READ_REG(hw, RXCW);
1920 DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw);
1922 /* If we have a copper PHY then we only want to go out to the PHY
1923 * registers to see if Auto-Neg has completed and/or if our link
1924 * status has changed. The get_link_status flag will be set if we
1925 * receive a Link Status Change interrupt or we have Rx Sequence
1928 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
1929 /* First we want to see if the MII Status Register reports
1930 * link. If so, then we want to get the current speed/duplex
1932 * Read the register twice since the link bit is sticky.
1934 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1935 DEBUGOUT("PHY Read Error\n");
1936 return -E1000_ERR_PHY;
1938 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1939 DEBUGOUT("PHY Read Error\n");
1940 return -E1000_ERR_PHY;
1943 if (phy_data & MII_SR_LINK_STATUS) {
1944 hw->get_link_status = FALSE;
1946 /* No link detected */
1947 return -E1000_ERR_NOLINK;
1950 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
1951 * have Si on board that is 82544 or newer, Auto
1952 * Speed Detection takes care of MAC speed/duplex
1953 * configuration. So we only need to configure Collision
1954 * Distance in the MAC. Otherwise, we need to force
1955 * speed/duplex on the MAC to the current PHY speed/duplex
1958 if (hw->mac_type >= e1000_82544)
1959 e1000_config_collision_dist(hw);
1961 ret_val = e1000_config_mac_to_phy(hw);
1964 ("Error configuring MAC to PHY settings\n");
1969 /* Configure Flow Control now that Auto-Neg has completed. First, we
1970 * need to restore the desired flow control settings because we may
1971 * have had to re-autoneg with a different link partner.
1973 ret_val = e1000_config_fc_after_link_up(hw);
1975 DEBUGOUT("Error configuring flow control\n");
1979 /* At this point we know that we are on copper and we have
1980 * auto-negotiated link. These are conditions for checking the link
1981 * parter capability register. We use the link partner capability to
1982 * determine if TBI Compatibility needs to be turned on or off. If
1983 * the link partner advertises any speed in addition to Gigabit, then
1984 * we assume that they are GMII-based, and TBI compatibility is not
1985 * needed. If no other speeds are advertised, we assume the link
1986 * partner is TBI-based, and we turn on TBI Compatibility.
1988 if (hw->tbi_compatibility_en) {
1989 if (e1000_read_phy_reg
1990 (hw, PHY_LP_ABILITY, &lp_capability) < 0) {
1991 DEBUGOUT("PHY Read Error\n");
1992 return -E1000_ERR_PHY;
1994 if (lp_capability & (NWAY_LPAR_10T_HD_CAPS |
1995 NWAY_LPAR_10T_FD_CAPS |
1996 NWAY_LPAR_100TX_HD_CAPS |
1997 NWAY_LPAR_100TX_FD_CAPS |
1998 NWAY_LPAR_100T4_CAPS)) {
1999 /* If our link partner advertises anything in addition to
2000 * gigabit, we do not need to enable TBI compatibility.
2002 if (hw->tbi_compatibility_on) {
2003 /* If we previously were in the mode, turn it off. */
2004 rctl = E1000_READ_REG(hw, RCTL);
2005 rctl &= ~E1000_RCTL_SBP;
2006 E1000_WRITE_REG(hw, RCTL, rctl);
2007 hw->tbi_compatibility_on = FALSE;
2010 /* If TBI compatibility is was previously off, turn it on. For
2011 * compatibility with a TBI link partner, we will store bad
2012 * packets. Some frames have an additional byte on the end and
2013 * will look like CRC errors to to the hardware.
2015 if (!hw->tbi_compatibility_on) {
2016 hw->tbi_compatibility_on = TRUE;
2017 rctl = E1000_READ_REG(hw, RCTL);
2018 rctl |= E1000_RCTL_SBP;
2019 E1000_WRITE_REG(hw, RCTL, rctl);
2024 /* If we don't have link (auto-negotiation failed or link partner cannot
2025 * auto-negotiate), the cable is plugged in (we have signal), and our
2026 * link partner is not trying to auto-negotiate with us (we are receiving
2027 * idles or data), we need to force link up. We also need to give
2028 * auto-negotiation time to complete, in case the cable was just plugged
2029 * in. The autoneg_failed flag does this.
2031 else if ((hw->media_type == e1000_media_type_fiber) &&
2032 (!(status & E1000_STATUS_LU)) &&
2033 ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
2034 (!(rxcw & E1000_RXCW_C))) {
2035 if (hw->autoneg_failed == 0) {
2036 hw->autoneg_failed = 1;
2039 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
2041 /* Disable auto-negotiation in the TXCW register */
2042 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2044 /* Force link-up and also force full-duplex. */
2045 ctrl = E1000_READ_REG(hw, CTRL);
2046 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2047 E1000_WRITE_REG(hw, CTRL, ctrl);
2049 /* Configure Flow Control after forcing link up. */
2050 ret_val = e1000_config_fc_after_link_up(hw);
2052 DEBUGOUT("Error configuring flow control\n");
2056 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2057 * auto-negotiation in the TXCW register and disable forced link in the
2058 * Device Control register in an attempt to auto-negotiate with our link
2061 else if ((hw->media_type == e1000_media_type_fiber) &&
2062 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2064 ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2065 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2066 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2071 /******************************************************************************
2072 * Detects the current speed and duplex settings of the hardware.
2074 * hw - Struct containing variables accessed by shared code
2075 * speed - Speed of the connection
2076 * duplex - Duplex setting of the connection
2077 *****************************************************************************/
2079 e1000_get_speed_and_duplex(struct e1000_hw *hw,
2080 uint16_t * speed, uint16_t * duplex)
2086 if (hw->mac_type >= e1000_82543) {
2087 status = E1000_READ_REG(hw, STATUS);
2088 if (status & E1000_STATUS_SPEED_1000) {
2089 *speed = SPEED_1000;
2090 DEBUGOUT("1000 Mbs, ");
2091 } else if (status & E1000_STATUS_SPEED_100) {
2093 DEBUGOUT("100 Mbs, ");
2096 DEBUGOUT("10 Mbs, ");
2099 if (status & E1000_STATUS_FD) {
2100 *duplex = FULL_DUPLEX;
2101 DEBUGOUT("Full Duplex\r\n");
2103 *duplex = HALF_DUPLEX;
2104 DEBUGOUT(" Half Duplex\r\n");
2107 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2108 *speed = SPEED_1000;
2109 *duplex = FULL_DUPLEX;
2113 /******************************************************************************
2114 * Blocks until autoneg completes or times out (~4.5 seconds)
2116 * hw - Struct containing variables accessed by shared code
2117 ******************************************************************************/
2119 e1000_wait_autoneg(struct e1000_hw *hw)
2125 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2127 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2128 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2129 /* Read the MII Status Register and wait for Auto-Neg
2130 * Complete bit to be set.
2132 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
2133 DEBUGOUT("PHY Read Error\n");
2134 return -E1000_ERR_PHY;
2136 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
2137 DEBUGOUT("PHY Read Error\n");
2138 return -E1000_ERR_PHY;
2140 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
2141 DEBUGOUT("Auto-Neg complete.\n");
2146 DEBUGOUT("Auto-Neg timedout.\n");
2147 return -E1000_ERR_TIMEOUT;
2150 /******************************************************************************
2151 * Raises the Management Data Clock
2153 * hw - Struct containing variables accessed by shared code
2154 * ctrl - Device control register's current value
2155 ******************************************************************************/
2157 e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
2159 /* Raise the clock input to the Management Data Clock (by setting the MDC
2160 * bit), and then delay 2 microseconds.
2162 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2163 E1000_WRITE_FLUSH(hw);
2167 /******************************************************************************
2168 * Lowers the Management Data Clock
2170 * hw - Struct containing variables accessed by shared code
2171 * ctrl - Device control register's current value
2172 ******************************************************************************/
2174 e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
2176 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2177 * bit), and then delay 2 microseconds.
2179 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2180 E1000_WRITE_FLUSH(hw);
2184 /******************************************************************************
2185 * Shifts data bits out to the PHY
2187 * hw - Struct containing variables accessed by shared code
2188 * data - Data to send out to the PHY
2189 * count - Number of bits to shift out
2191 * Bits are shifted out in MSB to LSB order.
2192 ******************************************************************************/
2194 e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count)
2199 /* We need to shift "count" number of bits out to the PHY. So, the value
2200 * in the "data" parameter will be shifted out to the PHY one bit at a
2201 * time. In order to do this, "data" must be broken down into bits.
2204 mask <<= (count - 1);
2206 ctrl = E1000_READ_REG(hw, CTRL);
2208 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2209 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2212 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2213 * then raising and lowering the Management Data Clock. A "0" is
2214 * shifted out to the PHY by setting the MDIO bit to "0" and then
2215 * raising and lowering the clock.
2218 ctrl |= E1000_CTRL_MDIO;
2220 ctrl &= ~E1000_CTRL_MDIO;
2222 E1000_WRITE_REG(hw, CTRL, ctrl);
2223 E1000_WRITE_FLUSH(hw);
2227 e1000_raise_mdi_clk(hw, &ctrl);
2228 e1000_lower_mdi_clk(hw, &ctrl);
2234 /******************************************************************************
2235 * Shifts data bits in from the PHY
2237 * hw - Struct containing variables accessed by shared code
2239 * Bits are shifted in in MSB to LSB order.
2240 ******************************************************************************/
2242 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2248 /* In order to read a register from the PHY, we need to shift in a total
2249 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2250 * to avoid contention on the MDIO pin when a read operation is performed.
2251 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2252 * by raising the input to the Management Data Clock (setting the MDC bit),
2253 * and then reading the value of the MDIO bit.
2255 ctrl = E1000_READ_REG(hw, CTRL);
2257 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2258 ctrl &= ~E1000_CTRL_MDIO_DIR;
2259 ctrl &= ~E1000_CTRL_MDIO;
2261 E1000_WRITE_REG(hw, CTRL, ctrl);
2262 E1000_WRITE_FLUSH(hw);
2264 /* Raise and Lower the clock before reading in the data. This accounts for
2265 * the turnaround bits. The first clock occurred when we clocked out the
2266 * last bit of the Register Address.
2268 e1000_raise_mdi_clk(hw, &ctrl);
2269 e1000_lower_mdi_clk(hw, &ctrl);
2271 for (data = 0, i = 0; i < 16; i++) {
2273 e1000_raise_mdi_clk(hw, &ctrl);
2274 ctrl = E1000_READ_REG(hw, CTRL);
2275 /* Check to see if we shifted in a "1". */
2276 if (ctrl & E1000_CTRL_MDIO)
2278 e1000_lower_mdi_clk(hw, &ctrl);
2281 e1000_raise_mdi_clk(hw, &ctrl);
2282 e1000_lower_mdi_clk(hw, &ctrl);
2287 /*****************************************************************************
2288 * Reads the value from a PHY register
2290 * hw - Struct containing variables accessed by shared code
2291 * reg_addr - address of the PHY register to read
2292 ******************************************************************************/
2294 e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data)
2298 const uint32_t phy_addr = 1;
2300 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2301 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
2302 return -E1000_ERR_PARAM;
2305 if (hw->mac_type > e1000_82543) {
2306 /* Set up Op-code, Phy Address, and register address in the MDI
2307 * Control register. The MAC will take care of interfacing with the
2308 * PHY to retrieve the desired data.
2310 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2311 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2312 (E1000_MDIC_OP_READ));
2314 E1000_WRITE_REG(hw, MDIC, mdic);
2316 /* Poll the ready bit to see if the MDI read completed */
2317 for (i = 0; i < 64; i++) {
2319 mdic = E1000_READ_REG(hw, MDIC);
2320 if (mdic & E1000_MDIC_READY)
2323 if (!(mdic & E1000_MDIC_READY)) {
2324 DEBUGOUT("MDI Read did not complete\n");
2325 return -E1000_ERR_PHY;
2327 if (mdic & E1000_MDIC_ERROR) {
2328 DEBUGOUT("MDI Error\n");
2329 return -E1000_ERR_PHY;
2331 *phy_data = (uint16_t) mdic;
2333 /* We must first send a preamble through the MDIO pin to signal the
2334 * beginning of an MII instruction. This is done by sending 32
2335 * consecutive "1" bits.
2337 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2339 /* Now combine the next few fields that are required for a read
2340 * operation. We use this method instead of calling the
2341 * e1000_shift_out_mdi_bits routine five different times. The format of
2342 * a MII read instruction consists of a shift out of 14 bits and is
2343 * defined as follows:
2344 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2345 * followed by a shift in of 18 bits. This first two bits shifted in
2346 * are TurnAround bits used to avoid contention on the MDIO pin when a
2347 * READ operation is performed. These two bits are thrown away
2348 * followed by a shift in of 16 bits which contains the desired data.
2350 mdic = ((reg_addr) | (phy_addr << 5) |
2351 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2353 e1000_shift_out_mdi_bits(hw, mdic, 14);
2355 /* Now that we've shifted out the read command to the MII, we need to
2356 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2359 *phy_data = e1000_shift_in_mdi_bits(hw);
2364 /******************************************************************************
2365 * Writes a value to a PHY register
2367 * hw - Struct containing variables accessed by shared code
2368 * reg_addr - address of the PHY register to write
2369 * data - data to write to the PHY
2370 ******************************************************************************/
2372 e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data)
2376 const uint32_t phy_addr = 1;
2378 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2379 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
2380 return -E1000_ERR_PARAM;
2383 if (hw->mac_type > e1000_82543) {
2384 /* Set up Op-code, Phy Address, register address, and data intended
2385 * for the PHY register in the MDI Control register. The MAC will take
2386 * care of interfacing with the PHY to send the desired data.
2388 mdic = (((uint32_t) phy_data) |
2389 (reg_addr << E1000_MDIC_REG_SHIFT) |
2390 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2391 (E1000_MDIC_OP_WRITE));
2393 E1000_WRITE_REG(hw, MDIC, mdic);
2395 /* Poll the ready bit to see if the MDI read completed */
2396 for (i = 0; i < 64; i++) {
2398 mdic = E1000_READ_REG(hw, MDIC);
2399 if (mdic & E1000_MDIC_READY)
2402 if (!(mdic & E1000_MDIC_READY)) {
2403 DEBUGOUT("MDI Write did not complete\n");
2404 return -E1000_ERR_PHY;
2407 /* We'll need to use the SW defined pins to shift the write command
2408 * out to the PHY. We first send a preamble to the PHY to signal the
2409 * beginning of the MII instruction. This is done by sending 32
2410 * consecutive "1" bits.
2412 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2414 /* Now combine the remaining required fields that will indicate a
2415 * write operation. We use this method instead of calling the
2416 * e1000_shift_out_mdi_bits routine for each field in the command. The
2417 * format of a MII write instruction is as follows:
2418 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2420 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2421 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2423 mdic |= (uint32_t) phy_data;
2425 e1000_shift_out_mdi_bits(hw, mdic, 32);
2430 /******************************************************************************
2431 * Returns the PHY to the power-on reset state
2433 * hw - Struct containing variables accessed by shared code
2434 ******************************************************************************/
2436 e1000_phy_hw_reset(struct e1000_hw *hw)
2443 DEBUGOUT("Resetting Phy...\n");
2445 if (hw->mac_type > e1000_82543) {
2446 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2447 * bit. Then, take it out of reset.
2449 ctrl = E1000_READ_REG(hw, CTRL);
2450 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
2451 E1000_WRITE_FLUSH(hw);
2453 E1000_WRITE_REG(hw, CTRL, ctrl);
2454 E1000_WRITE_FLUSH(hw);
2456 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2457 * bit to put the PHY into reset. Then, take it out of reset.
2459 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2460 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2461 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2462 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2463 E1000_WRITE_FLUSH(hw);
2465 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2466 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2467 E1000_WRITE_FLUSH(hw);
2472 /******************************************************************************
2475 * hw - Struct containing variables accessed by shared code
2477 * Sets bit 15 of the MII Control regiser
2478 ******************************************************************************/
2480 e1000_phy_reset(struct e1000_hw *hw)
2486 if (e1000_read_phy_reg(hw, PHY_CTRL, &phy_data) < 0) {
2487 DEBUGOUT("PHY Read Error\n");
2488 return -E1000_ERR_PHY;
2490 phy_data |= MII_CR_RESET;
2491 if (e1000_write_phy_reg(hw, PHY_CTRL, phy_data) < 0) {
2492 DEBUGOUT("PHY Write Error\n");
2493 return -E1000_ERR_PHY;
2499 static int e1000_set_phy_type (struct e1000_hw *hw)
2503 if (hw->mac_type == e1000_undefined)
2504 return -E1000_ERR_PHY_TYPE;
2506 switch (hw->phy_id) {
2507 case M88E1000_E_PHY_ID:
2508 case M88E1000_I_PHY_ID:
2509 case M88E1011_I_PHY_ID:
2510 hw->phy_type = e1000_phy_m88;
2512 case IGP01E1000_I_PHY_ID:
2513 if (hw->mac_type == e1000_82541 ||
2514 hw->mac_type == e1000_82541_rev_2) {
2515 hw->phy_type = e1000_phy_igp;
2520 /* Should never have loaded on this device */
2521 hw->phy_type = e1000_phy_undefined;
2522 return -E1000_ERR_PHY_TYPE;
2525 return E1000_SUCCESS;
2528 /******************************************************************************
2529 * Probes the expected PHY address for known PHY IDs
2531 * hw - Struct containing variables accessed by shared code
2532 ******************************************************************************/
2534 e1000_detect_gig_phy(struct e1000_hw *hw)
2536 int32_t phy_init_status;
2537 uint16_t phy_id_high, phy_id_low;
2542 /* Read the PHY ID Registers to identify which PHY is onboard. */
2543 if (e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high) < 0) {
2544 DEBUGOUT("PHY Read Error\n");
2545 return -E1000_ERR_PHY;
2547 hw->phy_id = (uint32_t) (phy_id_high << 16);
2549 if (e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low) < 0) {
2550 DEBUGOUT("PHY Read Error\n");
2551 return -E1000_ERR_PHY;
2553 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
2555 switch (hw->mac_type) {
2557 if (hw->phy_id == M88E1000_E_PHY_ID)
2561 if (hw->phy_id == M88E1000_I_PHY_ID)
2567 if (hw->phy_id == M88E1011_I_PHY_ID)
2570 case e1000_82541_rev_2:
2571 if(hw->phy_id == IGP01E1000_I_PHY_ID)
2576 DEBUGOUT("Invalid MAC type %d\n", hw->mac_type);
2577 return -E1000_ERR_CONFIG;
2580 phy_init_status = e1000_set_phy_type(hw);
2582 if ((match) && (phy_init_status == E1000_SUCCESS)) {
2583 DEBUGOUT("PHY ID 0x%X detected\n", hw->phy_id);
2586 DEBUGOUT("Invalid PHY ID 0x%X\n", hw->phy_id);
2587 return -E1000_ERR_PHY;
2591 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2593 * e1000_sw_init initializes the Adapter private data structure.
2594 * Fields are initialized based on PCI device information and
2595 * OS network device settings (MTU size).
2599 e1000_sw_init(struct eth_device *nic, int cardnum)
2601 struct e1000_hw *hw = (typeof(hw)) nic->priv;
2604 /* PCI config space info */
2605 pci_read_config_word(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
2606 pci_read_config_word(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
2607 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
2608 &hw->subsystem_vendor_id);
2609 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
2611 pci_read_config_byte(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
2612 pci_read_config_word(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
2614 /* identify the MAC */
2615 result = e1000_set_mac_type(hw);
2617 E1000_ERR("Unknown MAC Type\n");
2621 /* lan a vs. lan b settings */
2622 if (hw->mac_type == e1000_82546)
2623 /*this also works w/ multiple 82546 cards */
2624 /*but not if they're intermingled /w other e1000s */
2625 hw->lan_loc = (cardnum % 2) ? e1000_lan_b : e1000_lan_a;
2627 hw->lan_loc = e1000_lan_a;
2629 /* flow control settings */
2630 hw->fc_high_water = E1000_FC_HIGH_THRESH;
2631 hw->fc_low_water = E1000_FC_LOW_THRESH;
2632 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
2633 hw->fc_send_xon = 1;
2635 /* Media type - copper or fiber */
2637 if (hw->mac_type >= e1000_82543) {
2638 uint32_t status = E1000_READ_REG(hw, STATUS);
2640 if (status & E1000_STATUS_TBIMODE) {
2641 DEBUGOUT("fiber interface\n");
2642 hw->media_type = e1000_media_type_fiber;
2644 DEBUGOUT("copper interface\n");
2645 hw->media_type = e1000_media_type_copper;
2648 hw->media_type = e1000_media_type_fiber;
2651 if (hw->mac_type < e1000_82543)
2652 hw->report_tx_early = 0;
2654 hw->report_tx_early = 1;
2656 hw->tbi_compatibility_en = TRUE;
2658 hw->wait_autoneg_complete = FALSE;
2659 hw->adaptive_ifs = TRUE;
2661 /* Copper options */
2662 if (hw->media_type == e1000_media_type_copper) {
2663 hw->mdix = AUTO_ALL_MODES;
2664 hw->disable_polarity_correction = FALSE;
2667 return E1000_SUCCESS;
2671 fill_rx(struct e1000_hw *hw)
2673 struct e1000_rx_desc *rd;
2676 rd = rx_base + rx_tail;
2677 rx_tail = (rx_tail + 1) % 8;
2679 rd->buffer_addr = cpu_to_le64((u32) & packet);
2680 E1000_WRITE_REG(hw, RDT, rx_tail);
2684 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
2685 * @adapter: board private structure
2687 * Configure the Tx unit of the MAC after a reset.
2691 e1000_configure_tx(struct e1000_hw *hw)
2697 ptr = (u32) tx_pool;
2699 ptr = (ptr + 0x10) & (~0xf);
2701 tx_base = (typeof(tx_base)) ptr;
2703 E1000_WRITE_REG(hw, TDBAL, (u32) tx_base);
2704 E1000_WRITE_REG(hw, TDBAH, 0);
2706 E1000_WRITE_REG(hw, TDLEN, 128);
2708 /* Setup the HW Tx Head and Tail descriptor pointers */
2709 E1000_WRITE_REG(hw, TDH, 0);
2710 E1000_WRITE_REG(hw, TDT, 0);
2713 /* Set the default values for the Tx Inter Packet Gap timer */
2714 switch (hw->mac_type) {
2715 case e1000_82542_rev2_0:
2716 case e1000_82542_rev2_1:
2717 tipg = DEFAULT_82542_TIPG_IPGT;
2718 tipg |= DEFAULT_82542_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
2719 tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
2722 if (hw->media_type == e1000_media_type_fiber)
2723 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
2725 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
2726 tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
2727 tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
2729 E1000_WRITE_REG(hw, TIPG, tipg);
2731 /* Set the Tx Interrupt Delay register */
2732 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
2733 if (hw->mac_type >= e1000_82540)
2734 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
2736 /* Program the Transmit Control Register */
2737 tctl = E1000_READ_REG(hw, TCTL);
2738 tctl &= ~E1000_TCTL_CT;
2739 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
2740 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2741 E1000_WRITE_REG(hw, TCTL, tctl);
2743 e1000_config_collision_dist(hw);
2745 /* Setup Transmit Descriptor Settings for this adapter */
2746 adapter->txd_cmd = E1000_TXD_CMD_IFCS | E1000_TXD_CMD_IDE;
2748 if (adapter->hw.report_tx_early == 1)
2749 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2751 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
2756 * e1000_setup_rctl - configure the receive control register
2757 * @adapter: Board private structure
2760 e1000_setup_rctl(struct e1000_hw *hw)
2764 rctl = E1000_READ_REG(hw, RCTL);
2766 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2768 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF; /* |
2769 (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */
2771 if (hw->tbi_compatibility_on == 1)
2772 rctl |= E1000_RCTL_SBP;
2774 rctl &= ~E1000_RCTL_SBP;
2776 rctl &= ~(E1000_RCTL_SZ_4096);
2778 switch (adapter->rx_buffer_len) {
2779 case E1000_RXBUFFER_2048:
2782 rctl |= E1000_RCTL_SZ_2048;
2783 rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
2786 case E1000_RXBUFFER_4096:
2787 rctl |= E1000_RCTL_SZ_4096 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
2789 case E1000_RXBUFFER_8192:
2790 rctl |= E1000_RCTL_SZ_8192 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
2792 case E1000_RXBUFFER_16384:
2793 rctl |= E1000_RCTL_SZ_16384 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
2797 E1000_WRITE_REG(hw, RCTL, rctl);
2801 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
2802 * @adapter: board private structure
2804 * Configure the Rx unit of the MAC after a reset.
2807 e1000_configure_rx(struct e1000_hw *hw)
2812 unsigned long rxcsum;
2815 /* make sure receives are disabled while setting up the descriptors */
2816 rctl = E1000_READ_REG(hw, RCTL);
2817 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
2819 /* set the Receive Delay Timer Register */
2821 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
2823 if (hw->mac_type >= e1000_82540) {
2825 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
2827 /* Set the interrupt throttling rate. Value is calculated
2828 * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */
2829 #define MAX_INTS_PER_SEC 8000
2830 #define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
2831 E1000_WRITE_REG(hw, ITR, DEFAULT_ITR);
2834 /* Setup the Base and Length of the Rx Descriptor Ring */
2835 ptr = (u32) rx_pool;
2837 ptr = (ptr + 0x10) & (~0xf);
2838 rx_base = (typeof(rx_base)) ptr;
2839 E1000_WRITE_REG(hw, RDBAL, (u32) rx_base);
2840 E1000_WRITE_REG(hw, RDBAH, 0);
2842 E1000_WRITE_REG(hw, RDLEN, 128);
2844 /* Setup the HW Rx Head and Tail Descriptor Pointers */
2845 E1000_WRITE_REG(hw, RDH, 0);
2846 E1000_WRITE_REG(hw, RDT, 0);
2848 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
2849 if ((adapter->hw.mac_type >= e1000_82543) && (adapter->rx_csum == TRUE)) {
2850 rxcsum = E1000_READ_REG(hw, RXCSUM);
2851 rxcsum |= E1000_RXCSUM_TUOFL;
2852 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
2855 /* Enable Receives */
2857 E1000_WRITE_REG(hw, RCTL, rctl);
2861 /**************************************************************************
2862 POLL - Wait for a frame
2863 ***************************************************************************/
2865 e1000_poll(struct eth_device *nic)
2867 struct e1000_hw *hw = nic->priv;
2868 struct e1000_rx_desc *rd;
2869 /* return true if there's an ethernet packet ready to read */
2870 rd = rx_base + rx_last;
2871 if (!(le32_to_cpu(rd->status)) & E1000_RXD_STAT_DD)
2873 /*DEBUGOUT("recv: packet len=%d \n", rd->length); */
2874 NetReceive((uchar *)packet, le32_to_cpu(rd->length));
2879 /**************************************************************************
2880 TRANSMIT - Transmit a frame
2881 ***************************************************************************/
2883 e1000_transmit(struct eth_device *nic, volatile void *packet, int length)
2885 struct e1000_hw *hw = nic->priv;
2886 struct e1000_tx_desc *txp;
2889 txp = tx_base + tx_tail;
2890 tx_tail = (tx_tail + 1) % 8;
2892 txp->buffer_addr = cpu_to_le64(virt_to_bus(packet));
2893 txp->lower.data = cpu_to_le32(E1000_TXD_CMD_RPS | E1000_TXD_CMD_EOP |
2894 E1000_TXD_CMD_IFCS | length);
2895 txp->upper.data = 0;
2896 E1000_WRITE_REG(hw, TDT, tx_tail);
2898 while (!(le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD)) {
2899 if (i++ > TOUT_LOOP) {
2900 DEBUGOUT("e1000: tx timeout\n");
2903 udelay(10); /* give the nic a chance to write to the register */
2910 e1000_reset(struct eth_device *nic)
2912 struct e1000_hw *hw = nic->priv;
2915 if (hw->mac_type >= e1000_82544) {
2916 E1000_WRITE_REG(hw, WUC, 0);
2918 return e1000_init_hw(nic);
2921 /**************************************************************************
2922 DISABLE - Turn off ethernet interface
2923 ***************************************************************************/
2925 e1000_disable(struct eth_device *nic)
2927 struct e1000_hw *hw = nic->priv;
2929 /* Turn off the ethernet interface */
2930 E1000_WRITE_REG(hw, RCTL, 0);
2931 E1000_WRITE_REG(hw, TCTL, 0);
2933 /* Clear the transmit ring */
2934 E1000_WRITE_REG(hw, TDH, 0);
2935 E1000_WRITE_REG(hw, TDT, 0);
2937 /* Clear the receive ring */
2938 E1000_WRITE_REG(hw, RDH, 0);
2939 E1000_WRITE_REG(hw, RDT, 0);
2941 /* put the card in its initial state */
2943 E1000_WRITE_REG(hw, CTRL, E1000_CTRL_RST);
2949 /**************************************************************************
2950 INIT - set up ethernet interface(s)
2951 ***************************************************************************/
2953 e1000_init(struct eth_device *nic, bd_t * bis)
2955 struct e1000_hw *hw = nic->priv;
2958 ret_val = e1000_reset(nic);
2960 if ((ret_val == -E1000_ERR_NOLINK) ||
2961 (ret_val == -E1000_ERR_TIMEOUT)) {
2962 E1000_ERR("Valid Link not detected\n");
2964 E1000_ERR("Hardware Initialization Failed\n");
2968 e1000_configure_tx(hw);
2969 e1000_setup_rctl(hw);
2970 e1000_configure_rx(hw);
2974 /**************************************************************************
2975 PROBE - Look for an adapter, this routine's visible to the outside
2976 You should omit the last argument struct pci_device * for a non-PCI NIC
2977 ***************************************************************************/
2979 e1000_initialize(bd_t * bis)
2982 int card_number = 0;
2983 struct eth_device *nic = NULL;
2984 struct e1000_hw *hw = NULL;
2989 while (1) { /* Find PCI device(s) */
2990 if ((devno = pci_find_devices(supported, idx++)) < 0) {
2994 pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &iobase);
2995 iobase &= ~0xf; /* Mask the bits that say "this is an io addr" */
2996 DEBUGOUT("e1000#%d: iobase 0x%08x\n", card_number, iobase);
2998 pci_write_config_dword(devno, PCI_COMMAND,
2999 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
3000 /* Check if I/O accesses and Bus Mastering are enabled. */
3001 pci_read_config_dword(devno, PCI_COMMAND, &PciCommandWord);
3002 if (!(PciCommandWord & PCI_COMMAND_MEMORY)) {
3003 printf("Error: Can not enable MEM access.\n");
3005 } else if (!(PciCommandWord & PCI_COMMAND_MASTER)) {
3006 printf("Error: Can not enable Bus Mastering.\n");
3010 nic = (struct eth_device *) malloc(sizeof (*nic));
3011 hw = (struct e1000_hw *) malloc(sizeof (*hw));
3014 nic->iobase = bus_to_phys(devno, iobase);
3016 sprintf(nic->name, "e1000#%d", card_number);
3018 /* Are these variables needed? */
3020 hw->fc = e1000_fc_none;
3021 hw->original_fc = e1000_fc_none;
3023 hw->fc = e1000_fc_default;
3024 hw->original_fc = e1000_fc_default;
3026 hw->autoneg_failed = 0;
3027 hw->get_link_status = TRUE;
3028 hw->hw_addr = (typeof(hw->hw_addr)) iobase;
3029 hw->mac_type = e1000_undefined;
3031 /* MAC and Phy settings */
3032 if (e1000_sw_init(nic, card_number) < 0) {
3037 #if !(defined(CONFIG_AP1000) || defined(CONFIG_MVBC_1G))
3038 if (e1000_validate_eeprom_checksum(nic) < 0) {
3039 printf("The EEPROM Checksum Is Not Valid\n");
3045 e1000_read_mac_addr(nic);
3047 E1000_WRITE_REG(hw, PBA, E1000_DEFAULT_PBA);
3049 printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n",
3050 nic->enetaddr[0], nic->enetaddr[1], nic->enetaddr[2],
3051 nic->enetaddr[3], nic->enetaddr[4], nic->enetaddr[5]);
3053 nic->init = e1000_init;
3054 nic->recv = e1000_poll;
3055 nic->send = e1000_transmit;
3056 nic->halt = e1000_disable;