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 /******************************************************************************
116 * Raises the EEPROM's clock input.
118 * hw - Struct containing variables accessed by shared code
119 * eecd - EECD's current value
120 *****************************************************************************/
122 e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
124 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
125 * wait 50 microseconds.
127 *eecd = *eecd | E1000_EECD_SK;
128 E1000_WRITE_REG(hw, EECD, *eecd);
129 E1000_WRITE_FLUSH(hw);
133 /******************************************************************************
134 * Lowers the EEPROM's clock input.
136 * hw - Struct containing variables accessed by shared code
137 * eecd - EECD's current value
138 *****************************************************************************/
140 e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
142 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
143 * wait 50 microseconds.
145 *eecd = *eecd & ~E1000_EECD_SK;
146 E1000_WRITE_REG(hw, EECD, *eecd);
147 E1000_WRITE_FLUSH(hw);
151 /******************************************************************************
152 * Shift data bits out to the EEPROM.
154 * hw - Struct containing variables accessed by shared code
155 * data - data to send to the EEPROM
156 * count - number of bits to shift out
157 *****************************************************************************/
159 e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count)
164 /* We need to shift "count" bits out to the EEPROM. So, value in the
165 * "data" parameter will be shifted out to the EEPROM one bit at a time.
166 * In order to do this, "data" must be broken down into bits.
168 mask = 0x01 << (count - 1);
169 eecd = E1000_READ_REG(hw, EECD);
170 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
172 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
173 * and then raising and then lowering the clock (the SK bit controls
174 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
175 * by setting "DI" to "0" and then raising and then lowering the clock.
177 eecd &= ~E1000_EECD_DI;
180 eecd |= E1000_EECD_DI;
182 E1000_WRITE_REG(hw, EECD, eecd);
183 E1000_WRITE_FLUSH(hw);
187 e1000_raise_ee_clk(hw, &eecd);
188 e1000_lower_ee_clk(hw, &eecd);
194 /* We leave the "DI" bit set to "0" when we leave this routine. */
195 eecd &= ~E1000_EECD_DI;
196 E1000_WRITE_REG(hw, EECD, eecd);
199 /******************************************************************************
200 * Shift data bits in from the EEPROM
202 * hw - Struct containing variables accessed by shared code
203 *****************************************************************************/
205 e1000_shift_in_ee_bits(struct e1000_hw *hw)
211 /* In order to read a register from the EEPROM, we need to shift 16 bits
212 * in from the EEPROM. Bits are "shifted in" by raising the clock input to
213 * the EEPROM (setting the SK bit), and then reading the value of the "DO"
214 * bit. During this "shifting in" process the "DI" bit should always be
218 eecd = E1000_READ_REG(hw, EECD);
220 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
223 for (i = 0; i < 16; i++) {
225 e1000_raise_ee_clk(hw, &eecd);
227 eecd = E1000_READ_REG(hw, EECD);
229 eecd &= ~(E1000_EECD_DI);
230 if (eecd & E1000_EECD_DO)
233 e1000_lower_ee_clk(hw, &eecd);
239 /******************************************************************************
240 * Prepares EEPROM for access
242 * hw - Struct containing variables accessed by shared code
244 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
245 * function should be called before issuing a command to the EEPROM.
246 *****************************************************************************/
248 e1000_setup_eeprom(struct e1000_hw *hw)
252 eecd = E1000_READ_REG(hw, EECD);
254 /* Clear SK and DI */
255 eecd &= ~(E1000_EECD_SK | E1000_EECD_DI);
256 E1000_WRITE_REG(hw, EECD, eecd);
259 eecd |= E1000_EECD_CS;
260 E1000_WRITE_REG(hw, EECD, eecd);
263 /******************************************************************************
264 * Returns EEPROM to a "standby" state
266 * hw - Struct containing variables accessed by shared code
267 *****************************************************************************/
269 e1000_standby_eeprom(struct e1000_hw *hw)
273 eecd = E1000_READ_REG(hw, EECD);
276 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
277 E1000_WRITE_REG(hw, EECD, eecd);
278 E1000_WRITE_FLUSH(hw);
282 eecd |= E1000_EECD_SK;
283 E1000_WRITE_REG(hw, EECD, eecd);
284 E1000_WRITE_FLUSH(hw);
288 eecd |= E1000_EECD_CS;
289 E1000_WRITE_REG(hw, EECD, eecd);
290 E1000_WRITE_FLUSH(hw);
294 eecd &= ~E1000_EECD_SK;
295 E1000_WRITE_REG(hw, EECD, eecd);
296 E1000_WRITE_FLUSH(hw);
300 /******************************************************************************
301 * Reads a 16 bit word from the EEPROM.
303 * hw - Struct containing variables accessed by shared code
304 * offset - offset of word in the EEPROM to read
305 * data - word read from the EEPROM
306 *****************************************************************************/
308 e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset, uint16_t * data)
312 int large_eeprom = FALSE;
314 /* Request EEPROM Access */
315 if (hw->mac_type > e1000_82544) {
316 eecd = E1000_READ_REG(hw, EECD);
317 if (eecd & E1000_EECD_SIZE)
319 eecd |= E1000_EECD_REQ;
320 E1000_WRITE_REG(hw, EECD, eecd);
321 eecd = E1000_READ_REG(hw, EECD);
322 while ((!(eecd & E1000_EECD_GNT)) && (i < 100)) {
325 eecd = E1000_READ_REG(hw, EECD);
327 if (!(eecd & E1000_EECD_GNT)) {
328 eecd &= ~E1000_EECD_REQ;
329 E1000_WRITE_REG(hw, EECD, eecd);
330 DEBUGOUT("Could not acquire EEPROM grant\n");
331 return -E1000_ERR_EEPROM;
335 /* Prepare the EEPROM for reading */
336 e1000_setup_eeprom(hw);
338 /* Send the READ command (opcode + addr) */
339 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE, 3);
340 e1000_shift_out_ee_bits(hw, offset, (large_eeprom) ? 8 : 6);
343 *data = e1000_shift_in_ee_bits(hw);
345 /* End this read operation */
346 e1000_standby_eeprom(hw);
348 /* Stop requesting EEPROM access */
349 if (hw->mac_type > e1000_82544) {
350 eecd = E1000_READ_REG(hw, EECD);
351 eecd &= ~E1000_EECD_REQ;
352 E1000_WRITE_REG(hw, EECD, eecd);
360 e1000_eeprom_cleanup(struct e1000_hw *hw)
364 eecd = E1000_READ_REG(hw, EECD);
365 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
366 E1000_WRITE_REG(hw, EECD, eecd);
367 e1000_raise_ee_clk(hw, &eecd);
368 e1000_lower_ee_clk(hw, &eecd);
372 e1000_wait_eeprom_done(struct e1000_hw *hw)
377 e1000_standby_eeprom(hw);
378 for (i = 0; i < 200; i++) {
379 eecd = E1000_READ_REG(hw, EECD);
380 if (eecd & E1000_EECD_DO)
388 e1000_write_eeprom(struct e1000_hw *hw, uint16_t Reg, uint16_t Data)
391 int large_eeprom = FALSE;
394 /* Request EEPROM Access */
395 if (hw->mac_type > e1000_82544) {
396 eecd = E1000_READ_REG(hw, EECD);
397 if (eecd & E1000_EECD_SIZE)
399 eecd |= E1000_EECD_REQ;
400 E1000_WRITE_REG(hw, EECD, eecd);
401 eecd = E1000_READ_REG(hw, EECD);
402 while ((!(eecd & E1000_EECD_GNT)) && (i < 100)) {
405 eecd = E1000_READ_REG(hw, EECD);
407 if (!(eecd & E1000_EECD_GNT)) {
408 eecd &= ~E1000_EECD_REQ;
409 E1000_WRITE_REG(hw, EECD, eecd);
410 DEBUGOUT("Could not acquire EEPROM grant\n");
414 e1000_setup_eeprom(hw);
415 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE, 5);
416 e1000_shift_out_ee_bits(hw, Reg, (large_eeprom) ? 6 : 4);
417 e1000_standby_eeprom(hw);
418 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE, 3);
419 e1000_shift_out_ee_bits(hw, Reg, (large_eeprom) ? 8 : 6);
420 e1000_shift_out_ee_bits(hw, Data, 16);
421 if (!e1000_wait_eeprom_done(hw)) {
424 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE, 5);
425 e1000_shift_out_ee_bits(hw, Reg, (large_eeprom) ? 6 : 4);
426 e1000_eeprom_cleanup(hw);
428 /* Stop requesting EEPROM access */
429 if (hw->mac_type > e1000_82544) {
430 eecd = E1000_READ_REG(hw, EECD);
431 eecd &= ~E1000_EECD_REQ;
432 E1000_WRITE_REG(hw, EECD, eecd);
435 eecd = E1000_READ_REG(hw, EECD);
436 while (((eecd & E1000_EECD_GNT)) && (i < 500)) {
439 eecd = E1000_READ_REG(hw, EECD);
441 if ((eecd & E1000_EECD_GNT)) {
442 DEBUGOUT("Could not release EEPROM grant\n");
448 /******************************************************************************
449 * Verifies that the EEPROM has a valid checksum
451 * hw - Struct containing variables accessed by shared code
453 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
454 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
456 *****************************************************************************/
458 e1000_validate_eeprom_checksum(struct eth_device *nic)
460 struct e1000_hw *hw = nic->priv;
461 uint16_t checksum = 0;
462 uint16_t i, eeprom_data;
466 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
467 if (e1000_read_eeprom(hw, i, &eeprom_data) < 0) {
468 DEBUGOUT("EEPROM Read Error\n");
469 return -E1000_ERR_EEPROM;
471 checksum += eeprom_data;
474 if (checksum == (uint16_t) EEPROM_SUM) {
477 DEBUGOUT("EEPROM Checksum Invalid\n");
478 return -E1000_ERR_EEPROM;
482 /******************************************************************************
483 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
484 * second function of dual function devices
486 * nic - Struct containing variables accessed by shared code
487 *****************************************************************************/
489 e1000_read_mac_addr(struct eth_device *nic)
491 struct e1000_hw *hw = nic->priv;
493 uint16_t eeprom_data;
498 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
500 if (e1000_read_eeprom(hw, offset, &eeprom_data) < 0) {
501 DEBUGOUT("EEPROM Read Error\n");
502 return -E1000_ERR_EEPROM;
504 nic->enetaddr[i] = eeprom_data & 0xff;
505 nic->enetaddr[i + 1] = (eeprom_data >> 8) & 0xff;
507 if ((hw->mac_type == e1000_82546) &&
508 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
509 /* Invert the last bit if this is the second device */
510 nic->enetaddr[5] += 1;
515 /******************************************************************************
516 * Initializes receive address filters.
518 * hw - Struct containing variables accessed by shared code
520 * Places the MAC address in receive address register 0 and clears the rest
521 * of the receive addresss registers. Clears the multicast table. Assumes
522 * the receiver is in reset when the routine is called.
523 *****************************************************************************/
525 e1000_init_rx_addrs(struct eth_device *nic)
527 struct e1000_hw *hw = nic->priv;
534 /* Setup the receive address. */
535 DEBUGOUT("Programming MAC Address into RAR[0]\n");
536 addr_low = (nic->enetaddr[0] |
537 (nic->enetaddr[1] << 8) |
538 (nic->enetaddr[2] << 16) | (nic->enetaddr[3] << 24));
540 addr_high = (nic->enetaddr[4] | (nic->enetaddr[5] << 8) | E1000_RAH_AV);
542 E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
543 E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
545 /* Zero out the other 15 receive addresses. */
546 DEBUGOUT("Clearing RAR[1-15]\n");
547 for (i = 1; i < E1000_RAR_ENTRIES; i++) {
548 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
549 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
553 /******************************************************************************
554 * Clears the VLAN filer table
556 * hw - Struct containing variables accessed by shared code
557 *****************************************************************************/
559 e1000_clear_vfta(struct e1000_hw *hw)
563 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
564 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
567 /******************************************************************************
568 * Set the mac type member in the hw struct.
570 * hw - Struct containing variables accessed by shared code
571 *****************************************************************************/
573 e1000_set_mac_type(struct e1000_hw *hw)
577 switch (hw->device_id) {
578 case E1000_DEV_ID_82542:
579 switch (hw->revision_id) {
580 case E1000_82542_2_0_REV_ID:
581 hw->mac_type = e1000_82542_rev2_0;
583 case E1000_82542_2_1_REV_ID:
584 hw->mac_type = e1000_82542_rev2_1;
587 /* Invalid 82542 revision ID */
588 return -E1000_ERR_MAC_TYPE;
591 case E1000_DEV_ID_82543GC_FIBER:
592 case E1000_DEV_ID_82543GC_COPPER:
593 hw->mac_type = e1000_82543;
595 case E1000_DEV_ID_82544EI_COPPER:
596 case E1000_DEV_ID_82544EI_FIBER:
597 case E1000_DEV_ID_82544GC_COPPER:
598 case E1000_DEV_ID_82544GC_LOM:
599 hw->mac_type = e1000_82544;
601 case E1000_DEV_ID_82540EM:
602 case E1000_DEV_ID_82540EM_LOM:
603 hw->mac_type = e1000_82540;
605 case E1000_DEV_ID_82545EM_COPPER:
606 case E1000_DEV_ID_82545EM_FIBER:
607 hw->mac_type = e1000_82545;
609 case E1000_DEV_ID_82546EB_COPPER:
610 case E1000_DEV_ID_82546EB_FIBER:
611 hw->mac_type = e1000_82546;
614 /* Should never have loaded on this device */
615 return -E1000_ERR_MAC_TYPE;
617 return E1000_SUCCESS;
620 /******************************************************************************
621 * Reset the transmit and receive units; mask and clear all interrupts.
623 * hw - Struct containing variables accessed by shared code
624 *****************************************************************************/
626 e1000_reset_hw(struct e1000_hw *hw)
635 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
636 if (hw->mac_type == e1000_82542_rev2_0) {
637 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
638 pci_write_config_word(hw->pdev, PCI_COMMAND,
640 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
643 /* Clear interrupt mask to stop board from generating interrupts */
644 DEBUGOUT("Masking off all interrupts\n");
645 E1000_WRITE_REG(hw, IMC, 0xffffffff);
647 /* Disable the Transmit and Receive units. Then delay to allow
648 * any pending transactions to complete before we hit the MAC with
651 E1000_WRITE_REG(hw, RCTL, 0);
652 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
653 E1000_WRITE_FLUSH(hw);
655 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
656 hw->tbi_compatibility_on = FALSE;
658 /* Delay to allow any outstanding PCI transactions to complete before
659 * resetting the device
663 /* Issue a global reset to the MAC. This will reset the chip's
664 * transmit, receive, DMA, and link units. It will not effect
665 * the current PCI configuration. The global reset bit is self-
666 * clearing, and should clear within a microsecond.
668 DEBUGOUT("Issuing a global reset to MAC\n");
669 ctrl = E1000_READ_REG(hw, CTRL);
672 if (hw->mac_type > e1000_82543)
673 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
676 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
678 /* Force a reload from the EEPROM if necessary */
679 if (hw->mac_type < e1000_82540) {
680 /* Wait for reset to complete */
682 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
683 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
684 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
685 E1000_WRITE_FLUSH(hw);
686 /* Wait for EEPROM reload */
689 /* Wait for EEPROM reload (it happens automatically) */
691 /* Dissable HW ARPs on ASF enabled adapters */
692 manc = E1000_READ_REG(hw, MANC);
693 manc &= ~(E1000_MANC_ARP_EN);
694 E1000_WRITE_REG(hw, MANC, manc);
697 /* Clear interrupt mask to stop board from generating interrupts */
698 DEBUGOUT("Masking off all interrupts\n");
699 E1000_WRITE_REG(hw, IMC, 0xffffffff);
701 /* Clear any pending interrupt events. */
702 icr = E1000_READ_REG(hw, ICR);
704 /* If MWI was previously enabled, reenable it. */
705 if (hw->mac_type == e1000_82542_rev2_0) {
706 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
710 /******************************************************************************
711 * Performs basic configuration of the adapter.
713 * hw - Struct containing variables accessed by shared code
715 * Assumes that the controller has previously been reset and is in a
716 * post-reset uninitialized state. Initializes the receive address registers,
717 * multicast table, and VLAN filter table. Calls routines to setup link
718 * configuration and flow control settings. Clears all on-chip counters. Leaves
719 * the transmit and receive units disabled and uninitialized.
720 *****************************************************************************/
722 e1000_init_hw(struct eth_device *nic)
724 struct e1000_hw *hw = nic->priv;
725 uint32_t ctrl, status;
728 uint16_t pcix_cmd_word;
729 uint16_t pcix_stat_hi_word;
732 e1000_bus_type bus_type = e1000_bus_type_unknown;
736 /* Initialize Identification LED */
737 ret_val = e1000_id_led_init(hw);
739 DEBUGOUT("Error Initializing Identification LED\n");
743 /* Set the Media Type and exit with error if it is not valid. */
744 if (hw->mac_type != e1000_82543) {
745 /* tbi_compatibility is only valid on 82543 */
746 hw->tbi_compatibility_en = FALSE;
749 if (hw->mac_type >= e1000_82543) {
750 status = E1000_READ_REG(hw, STATUS);
751 if (status & E1000_STATUS_TBIMODE) {
752 hw->media_type = e1000_media_type_fiber;
753 /* tbi_compatibility not valid on fiber */
754 hw->tbi_compatibility_en = FALSE;
756 hw->media_type = e1000_media_type_copper;
759 /* This is an 82542 (fiber only) */
760 hw->media_type = e1000_media_type_fiber;
763 /* Disabling VLAN filtering. */
764 DEBUGOUT("Initializing the IEEE VLAN\n");
765 E1000_WRITE_REG(hw, VET, 0);
767 e1000_clear_vfta(hw);
769 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
770 if (hw->mac_type == e1000_82542_rev2_0) {
771 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
772 pci_write_config_word(hw->pdev, PCI_COMMAND,
774 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
775 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
776 E1000_WRITE_FLUSH(hw);
780 /* Setup the receive address. This involves initializing all of the Receive
781 * Address Registers (RARs 0 - 15).
783 e1000_init_rx_addrs(nic);
785 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
786 if (hw->mac_type == e1000_82542_rev2_0) {
787 E1000_WRITE_REG(hw, RCTL, 0);
788 E1000_WRITE_FLUSH(hw);
790 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
793 /* Zero out the Multicast HASH table */
794 DEBUGOUT("Zeroing the MTA\n");
795 for (i = 0; i < E1000_MC_TBL_SIZE; i++)
796 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
799 /* Set the PCI priority bit correctly in the CTRL register. This
800 * determines if the adapter gives priority to receives, or if it
801 * gives equal priority to transmits and receives.
803 if (hw->dma_fairness) {
804 ctrl = E1000_READ_REG(hw, CTRL);
805 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
808 if (hw->mac_type >= e1000_82543) {
809 status = E1000_READ_REG(hw, STATUS);
810 bus_type = (status & E1000_STATUS_PCIX_MODE) ?
811 e1000_bus_type_pcix : e1000_bus_type_pci;
813 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
814 if (bus_type == e1000_bus_type_pcix) {
815 pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
817 pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI,
820 (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
821 PCIX_COMMAND_MMRBC_SHIFT;
823 (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
824 PCIX_STATUS_HI_MMRBC_SHIFT;
825 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
826 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
827 if (cmd_mmrbc > stat_mmrbc) {
828 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
829 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
830 pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
835 /* Call a subroutine to configure the link and setup flow control. */
836 ret_val = e1000_setup_link(nic);
838 /* Set the transmit descriptor write-back policy */
839 if (hw->mac_type > e1000_82544) {
840 ctrl = E1000_READ_REG(hw, TXDCTL);
842 (ctrl & ~E1000_TXDCTL_WTHRESH) |
843 E1000_TXDCTL_FULL_TX_DESC_WB;
844 E1000_WRITE_REG(hw, TXDCTL, ctrl);
847 /* Clear all of the statistics registers (clear on read). It is
848 * important that we do this after we have tried to establish link
849 * because the symbol error count will increment wildly if there
852 e1000_clear_hw_cntrs(hw);
858 /******************************************************************************
859 * Configures flow control and link settings.
861 * hw - Struct containing variables accessed by shared code
863 * Determines which flow control settings to use. Calls the apropriate media-
864 * specific link configuration function. Configures the flow control settings.
865 * Assuming the adapter has a valid link partner, a valid link should be
866 * established. Assumes the hardware has previously been reset and the
867 * transmitter and receiver are not enabled.
868 *****************************************************************************/
870 e1000_setup_link(struct eth_device *nic)
872 struct e1000_hw *hw = nic->priv;
875 uint16_t eeprom_data;
879 /* Read and store word 0x0F of the EEPROM. This word contains bits
880 * that determine the hardware's default PAUSE (flow control) mode,
881 * a bit that determines whether the HW defaults to enabling or
882 * disabling auto-negotiation, and the direction of the
883 * SW defined pins. If there is no SW over-ride of the flow
884 * control setting, then the variable hw->fc will
885 * be initialized based on a value in the EEPROM.
887 if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, &eeprom_data) < 0) {
888 DEBUGOUT("EEPROM Read Error\n");
889 return -E1000_ERR_EEPROM;
892 if (hw->fc == e1000_fc_default) {
893 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
894 hw->fc = e1000_fc_none;
895 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
896 EEPROM_WORD0F_ASM_DIR)
897 hw->fc = e1000_fc_tx_pause;
899 hw->fc = e1000_fc_full;
902 /* We want to save off the original Flow Control configuration just
903 * in case we get disconnected and then reconnected into a different
904 * hub or switch with different Flow Control capabilities.
906 if (hw->mac_type == e1000_82542_rev2_0)
907 hw->fc &= (~e1000_fc_tx_pause);
909 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
910 hw->fc &= (~e1000_fc_rx_pause);
912 hw->original_fc = hw->fc;
914 DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc);
916 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
917 * polarity value for the SW controlled pins, and setup the
918 * Extended Device Control reg with that info.
919 * This is needed because one of the SW controlled pins is used for
920 * signal detection. So this should be done before e1000_setup_pcs_link()
921 * or e1000_phy_setup() is called.
923 if (hw->mac_type == e1000_82543) {
924 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
926 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
929 /* Call the necessary subroutine to configure the link. */
930 ret_val = (hw->media_type == e1000_media_type_fiber) ?
931 e1000_setup_fiber_link(nic) : e1000_setup_copper_link(nic);
936 /* Initialize the flow control address, type, and PAUSE timer
937 * registers to their default values. This is done even if flow
938 * control is disabled, because it does not hurt anything to
939 * initialize these registers.
942 ("Initializing the Flow Control address, type and timer regs\n");
944 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
945 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
946 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
947 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
949 /* Set the flow control receive threshold registers. Normally,
950 * these registers will be set to a default threshold that may be
951 * adjusted later by the driver's runtime code. However, if the
952 * ability to transmit pause frames in not enabled, then these
953 * registers will be set to 0.
955 if (!(hw->fc & e1000_fc_tx_pause)) {
956 E1000_WRITE_REG(hw, FCRTL, 0);
957 E1000_WRITE_REG(hw, FCRTH, 0);
959 /* We need to set up the Receive Threshold high and low water marks
960 * as well as (optionally) enabling the transmission of XON frames.
962 if (hw->fc_send_xon) {
963 E1000_WRITE_REG(hw, FCRTL,
964 (hw->fc_low_water | E1000_FCRTL_XONE));
965 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
967 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
968 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
974 /******************************************************************************
975 * Sets up link for a fiber based adapter
977 * hw - Struct containing variables accessed by shared code
979 * Manipulates Physical Coding Sublayer functions in order to configure
980 * link. Assumes the hardware has been previously reset and the transmitter
981 * and receiver are not enabled.
982 *****************************************************************************/
984 e1000_setup_fiber_link(struct eth_device *nic)
986 struct e1000_hw *hw = nic->priv;
995 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
996 * set when the optics detect a signal. On older adapters, it will be
997 * cleared when there is a signal
999 ctrl = E1000_READ_REG(hw, CTRL);
1000 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
1001 signal = E1000_CTRL_SWDPIN1;
1005 printf("signal for %s is %x (ctrl %08x)!!!!\n", nic->name, signal,
1007 /* Take the link out of reset */
1008 ctrl &= ~(E1000_CTRL_LRST);
1010 e1000_config_collision_dist(hw);
1012 /* Check for a software override of the flow control settings, and setup
1013 * the device accordingly. If auto-negotiation is enabled, then software
1014 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1015 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1016 * auto-negotiation is disabled, then software will have to manually
1017 * configure the two flow control enable bits in the CTRL register.
1019 * The possible values of the "fc" parameter are:
1020 * 0: Flow control is completely disabled
1021 * 1: Rx flow control is enabled (we can receive pause frames, but
1022 * not send pause frames).
1023 * 2: Tx flow control is enabled (we can send pause frames but we do
1024 * not support receiving pause frames).
1025 * 3: Both Rx and TX flow control (symmetric) are enabled.
1029 /* Flow control is completely disabled by a software over-ride. */
1030 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1032 case e1000_fc_rx_pause:
1033 /* RX Flow control is enabled and TX Flow control is disabled by a
1034 * software over-ride. Since there really isn't a way to advertise
1035 * that we are capable of RX Pause ONLY, we will advertise that we
1036 * support both symmetric and asymmetric RX PAUSE. Later, we will
1037 * disable the adapter's ability to send PAUSE frames.
1039 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1041 case e1000_fc_tx_pause:
1042 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1043 * software over-ride.
1045 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1048 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1049 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1052 DEBUGOUT("Flow control param set incorrectly\n");
1053 return -E1000_ERR_CONFIG;
1057 /* Since auto-negotiation is enabled, take the link out of reset (the link
1058 * will be in reset, because we previously reset the chip). This will
1059 * restart auto-negotiation. If auto-neogtiation is successful then the
1060 * link-up status bit will be set and the flow control enable bits (RFCE
1061 * and TFCE) will be set according to their negotiated value.
1063 DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw);
1065 E1000_WRITE_REG(hw, TXCW, txcw);
1066 E1000_WRITE_REG(hw, CTRL, ctrl);
1067 E1000_WRITE_FLUSH(hw);
1072 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1073 * indication in the Device Status Register. Time-out if a link isn't
1074 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1075 * less than 500 milliseconds even if the other end is doing it in SW).
1077 if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1078 DEBUGOUT("Looking for Link\n");
1079 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1081 status = E1000_READ_REG(hw, STATUS);
1082 if (status & E1000_STATUS_LU)
1085 if (i == (LINK_UP_TIMEOUT / 10)) {
1086 /* AutoNeg failed to achieve a link, so we'll call
1087 * e1000_check_for_link. This routine will force the link up if we
1088 * detect a signal. This will allow us to communicate with
1089 * non-autonegotiating link partners.
1091 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1092 hw->autoneg_failed = 1;
1093 ret_val = e1000_check_for_link(nic);
1095 DEBUGOUT("Error while checking for link\n");
1098 hw->autoneg_failed = 0;
1100 hw->autoneg_failed = 0;
1101 DEBUGOUT("Valid Link Found\n");
1104 DEBUGOUT("No Signal Detected\n");
1105 return -E1000_ERR_NOLINK;
1110 /******************************************************************************
1111 * Detects which PHY is present and the speed and duplex
1113 * hw - Struct containing variables accessed by shared code
1114 ******************************************************************************/
1116 e1000_setup_copper_link(struct eth_device *nic)
1118 struct e1000_hw *hw = nic->priv;
1126 ctrl = E1000_READ_REG(hw, CTRL);
1127 /* With 82543, we need to force speed and duplex on the MAC equal to what
1128 * the PHY speed and duplex configuration is. In addition, we need to
1129 * perform a hardware reset on the PHY to take it out of reset.
1131 if (hw->mac_type > e1000_82543) {
1132 ctrl |= E1000_CTRL_SLU;
1133 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1134 E1000_WRITE_REG(hw, CTRL, ctrl);
1137 (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1138 E1000_WRITE_REG(hw, CTRL, ctrl);
1139 e1000_phy_hw_reset(hw);
1142 /* Make sure we have a valid PHY */
1143 ret_val = e1000_detect_gig_phy(hw);
1145 DEBUGOUT("Error, did not detect valid phy.\n");
1148 DEBUGOUT("Phy ID = %x \n", hw->phy_id);
1150 /* Enable CRS on TX. This must be set for half-duplex operation. */
1151 if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data) < 0) {
1152 DEBUGOUT("PHY Read Error\n");
1153 return -E1000_ERR_PHY;
1155 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1159 * MDI/MDI-X = 0 (default)
1160 * 0 - Auto for all speeds
1163 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1165 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1168 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1171 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1174 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1178 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1182 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1187 * disable_polarity_correction = 0 (default)
1188 * Automatic Correction for Reversed Cable Polarity
1192 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1193 if (hw->disable_polarity_correction == 1)
1194 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1196 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1198 if (e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data) < 0) {
1199 DEBUGOUT("PHY Write Error\n");
1200 return -E1000_ERR_PHY;
1203 /* Force TX_CLK in the Extended PHY Specific Control Register
1206 if (e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data) < 0) {
1207 DEBUGOUT("PHY Read Error\n");
1208 return -E1000_ERR_PHY;
1210 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1211 /* Configure Master and Slave downshift values */
1212 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1213 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1214 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1215 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1216 if (e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data) < 0) {
1217 DEBUGOUT("PHY Write Error\n");
1218 return -E1000_ERR_PHY;
1221 /* SW Reset the PHY so all changes take effect */
1222 ret_val = e1000_phy_reset(hw);
1224 DEBUGOUT("Error Resetting the PHY\n");
1229 * autoneg = 1 (default)
1230 * PHY will advertise value(s) parsed from
1231 * autoneg_advertised and fc
1233 * PHY will be set to 10H, 10F, 100H, or 100F
1234 * depending on value parsed from forced_speed_duplex.
1237 /* Is autoneg enabled? This is enabled by default or by software override.
1238 * If so, call e1000_phy_setup_autoneg routine to parse the
1239 * autoneg_advertised and fc options. If autoneg is NOT enabled, then the
1240 * user should have provided a speed/duplex override. If so, then call
1241 * e1000_phy_force_speed_duplex to parse and set this up.
1243 /* Perform some bounds checking on the hw->autoneg_advertised
1244 * parameter. If this variable is zero, then set it to the default.
1246 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1248 /* If autoneg_advertised is zero, we assume it was not defaulted
1249 * by the calling code so we set to advertise full capability.
1251 if (hw->autoneg_advertised == 0)
1252 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1254 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1255 ret_val = e1000_phy_setup_autoneg(hw);
1257 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1260 DEBUGOUT("Restarting Auto-Neg\n");
1262 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1263 * the Auto Neg Restart bit in the PHY control register.
1265 if (e1000_read_phy_reg(hw, PHY_CTRL, &phy_data) < 0) {
1266 DEBUGOUT("PHY Read Error\n");
1267 return -E1000_ERR_PHY;
1269 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1270 if (e1000_write_phy_reg(hw, PHY_CTRL, phy_data) < 0) {
1271 DEBUGOUT("PHY Write Error\n");
1272 return -E1000_ERR_PHY;
1275 /* Does the user want to wait for Auto-Neg to complete here, or
1276 * check at a later time (for example, callback routine).
1278 if (hw->wait_autoneg_complete) {
1279 ret_val = e1000_wait_autoneg(hw);
1282 ("Error while waiting for autoneg to complete\n");
1287 /* If we do not wait for autonegtation to complete I
1288 * do not see a valid link status.
1290 ret_val = e1000_wait_autoneg(hw);
1292 DEBUGOUT("Error while waiting for autoneg to complete\n");
1297 /* Check link status. Wait up to 100 microseconds for link to become
1300 for (i = 0; i < 10; i++) {
1301 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1302 DEBUGOUT("PHY Read Error\n");
1303 return -E1000_ERR_PHY;
1305 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1306 DEBUGOUT("PHY Read Error\n");
1307 return -E1000_ERR_PHY;
1309 if (phy_data & MII_SR_LINK_STATUS) {
1310 /* We have link, so we need to finish the config process:
1311 * 1) Set up the MAC to the current PHY speed/duplex
1312 * if we are on 82543. If we
1313 * are on newer silicon, we only need to configure
1314 * collision distance in the Transmit Control Register.
1315 * 2) Set up flow control on the MAC to that established with
1318 if (hw->mac_type >= e1000_82544) {
1319 e1000_config_collision_dist(hw);
1321 ret_val = e1000_config_mac_to_phy(hw);
1324 ("Error configuring MAC to PHY settings\n");
1328 ret_val = e1000_config_fc_after_link_up(hw);
1330 DEBUGOUT("Error Configuring Flow Control\n");
1333 DEBUGOUT("Valid link established!!!\n");
1339 DEBUGOUT("Unable to establish link!!!\n");
1340 return -E1000_ERR_NOLINK;
1343 /******************************************************************************
1344 * Configures PHY autoneg and flow control advertisement settings
1346 * hw - Struct containing variables accessed by shared code
1347 ******************************************************************************/
1349 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1351 uint16_t mii_autoneg_adv_reg;
1352 uint16_t mii_1000t_ctrl_reg;
1356 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1357 if (e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg) < 0) {
1358 DEBUGOUT("PHY Read Error\n");
1359 return -E1000_ERR_PHY;
1362 /* Read the MII 1000Base-T Control Register (Address 9). */
1363 if (e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg) < 0) {
1364 DEBUGOUT("PHY Read Error\n");
1365 return -E1000_ERR_PHY;
1368 /* Need to parse both autoneg_advertised and fc and set up
1369 * the appropriate PHY registers. First we will parse for
1370 * autoneg_advertised software override. Since we can advertise
1371 * a plethora of combinations, we need to check each bit
1375 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1376 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1377 * the 1000Base-T Control Register (Address 9).
1379 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1380 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1382 DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised);
1384 /* Do we want to advertise 10 Mb Half Duplex? */
1385 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
1386 DEBUGOUT("Advertise 10mb Half duplex\n");
1387 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1390 /* Do we want to advertise 10 Mb Full Duplex? */
1391 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
1392 DEBUGOUT("Advertise 10mb Full duplex\n");
1393 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1396 /* Do we want to advertise 100 Mb Half Duplex? */
1397 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
1398 DEBUGOUT("Advertise 100mb Half duplex\n");
1399 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1402 /* Do we want to advertise 100 Mb Full Duplex? */
1403 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
1404 DEBUGOUT("Advertise 100mb Full duplex\n");
1405 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1408 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1409 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1411 ("Advertise 1000mb Half duplex requested, request denied!\n");
1414 /* Do we want to advertise 1000 Mb Full Duplex? */
1415 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1416 DEBUGOUT("Advertise 1000mb Full duplex\n");
1417 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1420 /* Check for a software override of the flow control settings, and
1421 * setup the PHY advertisement registers accordingly. If
1422 * auto-negotiation is enabled, then software will have to set the
1423 * "PAUSE" bits to the correct value in the Auto-Negotiation
1424 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1426 * The possible values of the "fc" parameter are:
1427 * 0: Flow control is completely disabled
1428 * 1: Rx flow control is enabled (we can receive pause frames
1429 * but not send pause frames).
1430 * 2: Tx flow control is enabled (we can send pause frames
1431 * but we do not support receiving pause frames).
1432 * 3: Both Rx and TX flow control (symmetric) are enabled.
1433 * other: No software override. The flow control configuration
1434 * in the EEPROM is used.
1437 case e1000_fc_none: /* 0 */
1438 /* Flow control (RX & TX) is completely disabled by a
1439 * software over-ride.
1441 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1443 case e1000_fc_rx_pause: /* 1 */
1444 /* RX Flow control is enabled, and TX Flow control is
1445 * disabled, by a software over-ride.
1447 /* Since there really isn't a way to advertise that we are
1448 * capable of RX Pause ONLY, we will advertise that we
1449 * support both symmetric and asymmetric RX PAUSE. Later
1450 * (in e1000_config_fc_after_link_up) we will disable the
1451 *hw's ability to send PAUSE frames.
1453 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1455 case e1000_fc_tx_pause: /* 2 */
1456 /* TX Flow control is enabled, and RX Flow control is
1457 * disabled, by a software over-ride.
1459 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1460 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1462 case e1000_fc_full: /* 3 */
1463 /* Flow control (both RX and TX) is enabled by a software
1466 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1469 DEBUGOUT("Flow control param set incorrectly\n");
1470 return -E1000_ERR_CONFIG;
1473 if (e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg) < 0) {
1474 DEBUGOUT("PHY Write Error\n");
1475 return -E1000_ERR_PHY;
1478 DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1480 if (e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg) < 0) {
1481 DEBUGOUT("PHY Write Error\n");
1482 return -E1000_ERR_PHY;
1487 /******************************************************************************
1488 * Sets the collision distance in the Transmit Control register
1490 * hw - Struct containing variables accessed by shared code
1492 * Link should have been established previously. Reads the speed and duplex
1493 * information from the Device Status register.
1494 ******************************************************************************/
1496 e1000_config_collision_dist(struct e1000_hw *hw)
1500 tctl = E1000_READ_REG(hw, TCTL);
1502 tctl &= ~E1000_TCTL_COLD;
1503 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
1505 E1000_WRITE_REG(hw, TCTL, tctl);
1506 E1000_WRITE_FLUSH(hw);
1509 /******************************************************************************
1510 * Sets MAC speed and duplex settings to reflect the those in the PHY
1512 * hw - Struct containing variables accessed by shared code
1513 * mii_reg - data to write to the MII control register
1515 * The contents of the PHY register containing the needed information need to
1517 ******************************************************************************/
1519 e1000_config_mac_to_phy(struct e1000_hw *hw)
1526 /* Read the Device Control Register and set the bits to Force Speed
1529 ctrl = E1000_READ_REG(hw, CTRL);
1530 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1531 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1533 /* Set up duplex in the Device Control and Transmit Control
1534 * registers depending on negotiated values.
1536 if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
1537 DEBUGOUT("PHY Read Error\n");
1538 return -E1000_ERR_PHY;
1540 if (phy_data & M88E1000_PSSR_DPLX)
1541 ctrl |= E1000_CTRL_FD;
1543 ctrl &= ~E1000_CTRL_FD;
1545 e1000_config_collision_dist(hw);
1547 /* Set up speed in the Device Control register depending on
1548 * negotiated values.
1550 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1551 ctrl |= E1000_CTRL_SPD_1000;
1552 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1553 ctrl |= E1000_CTRL_SPD_100;
1554 /* Write the configured values back to the Device Control Reg. */
1555 E1000_WRITE_REG(hw, CTRL, ctrl);
1559 /******************************************************************************
1560 * Forces the MAC's flow control settings.
1562 * hw - Struct containing variables accessed by shared code
1564 * Sets the TFCE and RFCE bits in the device control register to reflect
1565 * the adapter settings. TFCE and RFCE need to be explicitly set by
1566 * software when a Copper PHY is used because autonegotiation is managed
1567 * by the PHY rather than the MAC. Software must also configure these
1568 * bits when link is forced on a fiber connection.
1569 *****************************************************************************/
1571 e1000_force_mac_fc(struct e1000_hw *hw)
1577 /* Get the current configuration of the Device Control Register */
1578 ctrl = E1000_READ_REG(hw, CTRL);
1580 /* Because we didn't get link via the internal auto-negotiation
1581 * mechanism (we either forced link or we got link via PHY
1582 * auto-neg), we have to manually enable/disable transmit an
1583 * receive flow control.
1585 * The "Case" statement below enables/disable flow control
1586 * according to the "hw->fc" parameter.
1588 * The possible values of the "fc" parameter are:
1589 * 0: Flow control is completely disabled
1590 * 1: Rx flow control is enabled (we can receive pause
1591 * frames but not send pause frames).
1592 * 2: Tx flow control is enabled (we can send pause frames
1593 * frames but we do not receive pause frames).
1594 * 3: Both Rx and TX flow control (symmetric) is enabled.
1595 * other: No other values should be possible at this point.
1600 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1602 case e1000_fc_rx_pause:
1603 ctrl &= (~E1000_CTRL_TFCE);
1604 ctrl |= E1000_CTRL_RFCE;
1606 case e1000_fc_tx_pause:
1607 ctrl &= (~E1000_CTRL_RFCE);
1608 ctrl |= E1000_CTRL_TFCE;
1611 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1614 DEBUGOUT("Flow control param set incorrectly\n");
1615 return -E1000_ERR_CONFIG;
1618 /* Disable TX Flow Control for 82542 (rev 2.0) */
1619 if (hw->mac_type == e1000_82542_rev2_0)
1620 ctrl &= (~E1000_CTRL_TFCE);
1622 E1000_WRITE_REG(hw, CTRL, ctrl);
1626 /******************************************************************************
1627 * Configures flow control settings after link is established
1629 * hw - Struct containing variables accessed by shared code
1631 * Should be called immediately after a valid link has been established.
1632 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1633 * and autonegotiation is enabled, the MAC flow control settings will be set
1634 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1635 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1636 *****************************************************************************/
1638 e1000_config_fc_after_link_up(struct e1000_hw *hw)
1641 uint16_t mii_status_reg;
1642 uint16_t mii_nway_adv_reg;
1643 uint16_t mii_nway_lp_ability_reg;
1649 /* Check for the case where we have fiber media and auto-neg failed
1650 * so we had to force link. In this case, we need to force the
1651 * configuration of the MAC to match the "fc" parameter.
1653 if ((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) {
1654 ret_val = e1000_force_mac_fc(hw);
1656 DEBUGOUT("Error forcing flow control settings\n");
1661 /* Check for the case where we have copper media and auto-neg is
1662 * enabled. In this case, we need to check and see if Auto-Neg
1663 * has completed, and if so, how the PHY and link partner has
1664 * flow control configured.
1666 if (hw->media_type == e1000_media_type_copper) {
1667 /* Read the MII Status Register and check to see if AutoNeg
1668 * has completed. We read this twice because this reg has
1669 * some "sticky" (latched) bits.
1671 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
1672 DEBUGOUT("PHY Read Error \n");
1673 return -E1000_ERR_PHY;
1675 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
1676 DEBUGOUT("PHY Read Error \n");
1677 return -E1000_ERR_PHY;
1680 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
1681 /* The AutoNeg process has completed, so we now need to
1682 * read both the Auto Negotiation Advertisement Register
1683 * (Address 4) and the Auto_Negotiation Base Page Ability
1684 * Register (Address 5) to determine how flow control was
1687 if (e1000_read_phy_reg
1688 (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
1689 DEBUGOUT("PHY Read Error\n");
1690 return -E1000_ERR_PHY;
1692 if (e1000_read_phy_reg
1693 (hw, PHY_LP_ABILITY,
1694 &mii_nway_lp_ability_reg) < 0) {
1695 DEBUGOUT("PHY Read Error\n");
1696 return -E1000_ERR_PHY;
1699 /* Two bits in the Auto Negotiation Advertisement Register
1700 * (Address 4) and two bits in the Auto Negotiation Base
1701 * Page Ability Register (Address 5) determine flow control
1702 * for both the PHY and the link partner. The following
1703 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
1704 * 1999, describes these PAUSE resolution bits and how flow
1705 * control is determined based upon these settings.
1706 * NOTE: DC = Don't Care
1708 * LOCAL DEVICE | LINK PARTNER
1709 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
1710 *-------|---------|-------|---------|--------------------
1711 * 0 | 0 | DC | DC | e1000_fc_none
1712 * 0 | 1 | 0 | DC | e1000_fc_none
1713 * 0 | 1 | 1 | 0 | e1000_fc_none
1714 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1715 * 1 | 0 | 0 | DC | e1000_fc_none
1716 * 1 | DC | 1 | DC | e1000_fc_full
1717 * 1 | 1 | 0 | 0 | e1000_fc_none
1718 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1721 /* Are both PAUSE bits set to 1? If so, this implies
1722 * Symmetric Flow Control is enabled at both ends. The
1723 * ASM_DIR bits are irrelevant per the spec.
1725 * For Symmetric Flow Control:
1727 * LOCAL DEVICE | LINK PARTNER
1728 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1729 *-------|---------|-------|---------|--------------------
1730 * 1 | DC | 1 | DC | e1000_fc_full
1733 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1734 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
1735 /* Now we need to check if the user selected RX ONLY
1736 * of pause frames. In this case, we had to advertise
1737 * FULL flow control because we could not advertise RX
1738 * ONLY. Hence, we must now check to see if we need to
1739 * turn OFF the TRANSMISSION of PAUSE frames.
1741 if (hw->original_fc == e1000_fc_full) {
1742 hw->fc = e1000_fc_full;
1743 DEBUGOUT("Flow Control = FULL.\r\n");
1745 hw->fc = e1000_fc_rx_pause;
1747 ("Flow Control = RX PAUSE frames only.\r\n");
1750 /* For receiving PAUSE frames ONLY.
1752 * LOCAL DEVICE | LINK PARTNER
1753 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1754 *-------|---------|-------|---------|--------------------
1755 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1758 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1759 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1760 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1761 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
1763 hw->fc = e1000_fc_tx_pause;
1765 ("Flow Control = TX PAUSE frames only.\r\n");
1767 /* For transmitting PAUSE frames ONLY.
1769 * LOCAL DEVICE | LINK PARTNER
1770 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1771 *-------|---------|-------|---------|--------------------
1772 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1775 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1776 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1777 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1778 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
1780 hw->fc = e1000_fc_rx_pause;
1782 ("Flow Control = RX PAUSE frames only.\r\n");
1784 /* Per the IEEE spec, at this point flow control should be
1785 * disabled. However, we want to consider that we could
1786 * be connected to a legacy switch that doesn't advertise
1787 * desired flow control, but can be forced on the link
1788 * partner. So if we advertised no flow control, that is
1789 * what we will resolve to. If we advertised some kind of
1790 * receive capability (Rx Pause Only or Full Flow Control)
1791 * and the link partner advertised none, we will configure
1792 * ourselves to enable Rx Flow Control only. We can do
1793 * this safely for two reasons: If the link partner really
1794 * didn't want flow control enabled, and we enable Rx, no
1795 * harm done since we won't be receiving any PAUSE frames
1796 * anyway. If the intent on the link partner was to have
1797 * flow control enabled, then by us enabling RX only, we
1798 * can at least receive pause frames and process them.
1799 * This is a good idea because in most cases, since we are
1800 * predominantly a server NIC, more times than not we will
1801 * be asked to delay transmission of packets than asking
1802 * our link partner to pause transmission of frames.
1804 else if (hw->original_fc == e1000_fc_none ||
1805 hw->original_fc == e1000_fc_tx_pause) {
1806 hw->fc = e1000_fc_none;
1807 DEBUGOUT("Flow Control = NONE.\r\n");
1809 hw->fc = e1000_fc_rx_pause;
1811 ("Flow Control = RX PAUSE frames only.\r\n");
1814 /* Now we need to do one last check... If we auto-
1815 * negotiated to HALF DUPLEX, flow control should not be
1816 * enabled per IEEE 802.3 spec.
1818 e1000_get_speed_and_duplex(hw, &speed, &duplex);
1820 if (duplex == HALF_DUPLEX)
1821 hw->fc = e1000_fc_none;
1823 /* Now we call a subroutine to actually force the MAC
1824 * controller to use the correct flow control settings.
1826 ret_val = e1000_force_mac_fc(hw);
1829 ("Error forcing flow control settings\n");
1834 ("Copper PHY and Auto Neg has not completed.\r\n");
1840 /******************************************************************************
1841 * Checks to see if the link status of the hardware has changed.
1843 * hw - Struct containing variables accessed by shared code
1845 * Called by any function that needs to check the link status of the adapter.
1846 *****************************************************************************/
1848 e1000_check_for_link(struct eth_device *nic)
1850 struct e1000_hw *hw = nic->priv;
1858 uint16_t lp_capability;
1862 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
1863 * set when the optics detect a signal. On older adapters, it will be
1864 * cleared when there is a signal
1866 ctrl = E1000_READ_REG(hw, CTRL);
1867 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
1868 signal = E1000_CTRL_SWDPIN1;
1872 status = E1000_READ_REG(hw, STATUS);
1873 rxcw = E1000_READ_REG(hw, RXCW);
1874 DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw);
1876 /* If we have a copper PHY then we only want to go out to the PHY
1877 * registers to see if Auto-Neg has completed and/or if our link
1878 * status has changed. The get_link_status flag will be set if we
1879 * receive a Link Status Change interrupt or we have Rx Sequence
1882 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
1883 /* First we want to see if the MII Status Register reports
1884 * link. If so, then we want to get the current speed/duplex
1886 * Read the register twice since the link bit is sticky.
1888 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1889 DEBUGOUT("PHY Read Error\n");
1890 return -E1000_ERR_PHY;
1892 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1893 DEBUGOUT("PHY Read Error\n");
1894 return -E1000_ERR_PHY;
1897 if (phy_data & MII_SR_LINK_STATUS) {
1898 hw->get_link_status = FALSE;
1900 /* No link detected */
1901 return -E1000_ERR_NOLINK;
1904 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
1905 * have Si on board that is 82544 or newer, Auto
1906 * Speed Detection takes care of MAC speed/duplex
1907 * configuration. So we only need to configure Collision
1908 * Distance in the MAC. Otherwise, we need to force
1909 * speed/duplex on the MAC to the current PHY speed/duplex
1912 if (hw->mac_type >= e1000_82544)
1913 e1000_config_collision_dist(hw);
1915 ret_val = e1000_config_mac_to_phy(hw);
1918 ("Error configuring MAC to PHY settings\n");
1923 /* Configure Flow Control now that Auto-Neg has completed. First, we
1924 * need to restore the desired flow control settings because we may
1925 * have had to re-autoneg with a different link partner.
1927 ret_val = e1000_config_fc_after_link_up(hw);
1929 DEBUGOUT("Error configuring flow control\n");
1933 /* At this point we know that we are on copper and we have
1934 * auto-negotiated link. These are conditions for checking the link
1935 * parter capability register. We use the link partner capability to
1936 * determine if TBI Compatibility needs to be turned on or off. If
1937 * the link partner advertises any speed in addition to Gigabit, then
1938 * we assume that they are GMII-based, and TBI compatibility is not
1939 * needed. If no other speeds are advertised, we assume the link
1940 * partner is TBI-based, and we turn on TBI Compatibility.
1942 if (hw->tbi_compatibility_en) {
1943 if (e1000_read_phy_reg
1944 (hw, PHY_LP_ABILITY, &lp_capability) < 0) {
1945 DEBUGOUT("PHY Read Error\n");
1946 return -E1000_ERR_PHY;
1948 if (lp_capability & (NWAY_LPAR_10T_HD_CAPS |
1949 NWAY_LPAR_10T_FD_CAPS |
1950 NWAY_LPAR_100TX_HD_CAPS |
1951 NWAY_LPAR_100TX_FD_CAPS |
1952 NWAY_LPAR_100T4_CAPS)) {
1953 /* If our link partner advertises anything in addition to
1954 * gigabit, we do not need to enable TBI compatibility.
1956 if (hw->tbi_compatibility_on) {
1957 /* If we previously were in the mode, turn it off. */
1958 rctl = E1000_READ_REG(hw, RCTL);
1959 rctl &= ~E1000_RCTL_SBP;
1960 E1000_WRITE_REG(hw, RCTL, rctl);
1961 hw->tbi_compatibility_on = FALSE;
1964 /* If TBI compatibility is was previously off, turn it on. For
1965 * compatibility with a TBI link partner, we will store bad
1966 * packets. Some frames have an additional byte on the end and
1967 * will look like CRC errors to to the hardware.
1969 if (!hw->tbi_compatibility_on) {
1970 hw->tbi_compatibility_on = TRUE;
1971 rctl = E1000_READ_REG(hw, RCTL);
1972 rctl |= E1000_RCTL_SBP;
1973 E1000_WRITE_REG(hw, RCTL, rctl);
1978 /* If we don't have link (auto-negotiation failed or link partner cannot
1979 * auto-negotiate), the cable is plugged in (we have signal), and our
1980 * link partner is not trying to auto-negotiate with us (we are receiving
1981 * idles or data), we need to force link up. We also need to give
1982 * auto-negotiation time to complete, in case the cable was just plugged
1983 * in. The autoneg_failed flag does this.
1985 else if ((hw->media_type == e1000_media_type_fiber) &&
1986 (!(status & E1000_STATUS_LU)) &&
1987 ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
1988 (!(rxcw & E1000_RXCW_C))) {
1989 if (hw->autoneg_failed == 0) {
1990 hw->autoneg_failed = 1;
1993 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
1995 /* Disable auto-negotiation in the TXCW register */
1996 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
1998 /* Force link-up and also force full-duplex. */
1999 ctrl = E1000_READ_REG(hw, CTRL);
2000 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2001 E1000_WRITE_REG(hw, CTRL, ctrl);
2003 /* Configure Flow Control after forcing link up. */
2004 ret_val = e1000_config_fc_after_link_up(hw);
2006 DEBUGOUT("Error configuring flow control\n");
2010 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2011 * auto-negotiation in the TXCW register and disable forced link in the
2012 * Device Control register in an attempt to auto-negotiate with our link
2015 else if ((hw->media_type == e1000_media_type_fiber) &&
2016 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2018 ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2019 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2020 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2025 /******************************************************************************
2026 * Detects the current speed and duplex settings of the hardware.
2028 * hw - Struct containing variables accessed by shared code
2029 * speed - Speed of the connection
2030 * duplex - Duplex setting of the connection
2031 *****************************************************************************/
2033 e1000_get_speed_and_duplex(struct e1000_hw *hw,
2034 uint16_t * speed, uint16_t * duplex)
2040 if (hw->mac_type >= e1000_82543) {
2041 status = E1000_READ_REG(hw, STATUS);
2042 if (status & E1000_STATUS_SPEED_1000) {
2043 *speed = SPEED_1000;
2044 DEBUGOUT("1000 Mbs, ");
2045 } else if (status & E1000_STATUS_SPEED_100) {
2047 DEBUGOUT("100 Mbs, ");
2050 DEBUGOUT("10 Mbs, ");
2053 if (status & E1000_STATUS_FD) {
2054 *duplex = FULL_DUPLEX;
2055 DEBUGOUT("Full Duplex\r\n");
2057 *duplex = HALF_DUPLEX;
2058 DEBUGOUT(" Half Duplex\r\n");
2061 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2062 *speed = SPEED_1000;
2063 *duplex = FULL_DUPLEX;
2067 /******************************************************************************
2068 * Blocks until autoneg completes or times out (~4.5 seconds)
2070 * hw - Struct containing variables accessed by shared code
2071 ******************************************************************************/
2073 e1000_wait_autoneg(struct e1000_hw *hw)
2079 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2081 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2082 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2083 /* Read the MII Status Register and wait for Auto-Neg
2084 * Complete bit to be set.
2086 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
2087 DEBUGOUT("PHY Read Error\n");
2088 return -E1000_ERR_PHY;
2090 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
2091 DEBUGOUT("PHY Read Error\n");
2092 return -E1000_ERR_PHY;
2094 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
2095 DEBUGOUT("Auto-Neg complete.\n");
2100 DEBUGOUT("Auto-Neg timedout.\n");
2101 return -E1000_ERR_TIMEOUT;
2104 /******************************************************************************
2105 * Raises the Management Data Clock
2107 * hw - Struct containing variables accessed by shared code
2108 * ctrl - Device control register's current value
2109 ******************************************************************************/
2111 e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
2113 /* Raise the clock input to the Management Data Clock (by setting the MDC
2114 * bit), and then delay 2 microseconds.
2116 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2117 E1000_WRITE_FLUSH(hw);
2121 /******************************************************************************
2122 * Lowers the Management Data Clock
2124 * hw - Struct containing variables accessed by shared code
2125 * ctrl - Device control register's current value
2126 ******************************************************************************/
2128 e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
2130 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2131 * bit), and then delay 2 microseconds.
2133 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2134 E1000_WRITE_FLUSH(hw);
2138 /******************************************************************************
2139 * Shifts data bits out to the PHY
2141 * hw - Struct containing variables accessed by shared code
2142 * data - Data to send out to the PHY
2143 * count - Number of bits to shift out
2145 * Bits are shifted out in MSB to LSB order.
2146 ******************************************************************************/
2148 e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count)
2153 /* We need to shift "count" number of bits out to the PHY. So, the value
2154 * in the "data" parameter will be shifted out to the PHY one bit at a
2155 * time. In order to do this, "data" must be broken down into bits.
2158 mask <<= (count - 1);
2160 ctrl = E1000_READ_REG(hw, CTRL);
2162 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2163 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2166 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2167 * then raising and lowering the Management Data Clock. A "0" is
2168 * shifted out to the PHY by setting the MDIO bit to "0" and then
2169 * raising and lowering the clock.
2172 ctrl |= E1000_CTRL_MDIO;
2174 ctrl &= ~E1000_CTRL_MDIO;
2176 E1000_WRITE_REG(hw, CTRL, ctrl);
2177 E1000_WRITE_FLUSH(hw);
2181 e1000_raise_mdi_clk(hw, &ctrl);
2182 e1000_lower_mdi_clk(hw, &ctrl);
2188 /******************************************************************************
2189 * Shifts data bits in from the PHY
2191 * hw - Struct containing variables accessed by shared code
2193 * Bits are shifted in in MSB to LSB order.
2194 ******************************************************************************/
2196 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2202 /* In order to read a register from the PHY, we need to shift in a total
2203 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2204 * to avoid contention on the MDIO pin when a read operation is performed.
2205 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2206 * by raising the input to the Management Data Clock (setting the MDC bit),
2207 * and then reading the value of the MDIO bit.
2209 ctrl = E1000_READ_REG(hw, CTRL);
2211 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2212 ctrl &= ~E1000_CTRL_MDIO_DIR;
2213 ctrl &= ~E1000_CTRL_MDIO;
2215 E1000_WRITE_REG(hw, CTRL, ctrl);
2216 E1000_WRITE_FLUSH(hw);
2218 /* Raise and Lower the clock before reading in the data. This accounts for
2219 * the turnaround bits. The first clock occurred when we clocked out the
2220 * last bit of the Register Address.
2222 e1000_raise_mdi_clk(hw, &ctrl);
2223 e1000_lower_mdi_clk(hw, &ctrl);
2225 for (data = 0, i = 0; i < 16; i++) {
2227 e1000_raise_mdi_clk(hw, &ctrl);
2228 ctrl = E1000_READ_REG(hw, CTRL);
2229 /* Check to see if we shifted in a "1". */
2230 if (ctrl & E1000_CTRL_MDIO)
2232 e1000_lower_mdi_clk(hw, &ctrl);
2235 e1000_raise_mdi_clk(hw, &ctrl);
2236 e1000_lower_mdi_clk(hw, &ctrl);
2241 /*****************************************************************************
2242 * Reads the value from a PHY register
2244 * hw - Struct containing variables accessed by shared code
2245 * reg_addr - address of the PHY register to read
2246 ******************************************************************************/
2248 e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data)
2252 const uint32_t phy_addr = 1;
2254 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2255 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
2256 return -E1000_ERR_PARAM;
2259 if (hw->mac_type > e1000_82543) {
2260 /* Set up Op-code, Phy Address, and register address in the MDI
2261 * Control register. The MAC will take care of interfacing with the
2262 * PHY to retrieve the desired data.
2264 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2265 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2266 (E1000_MDIC_OP_READ));
2268 E1000_WRITE_REG(hw, MDIC, mdic);
2270 /* Poll the ready bit to see if the MDI read completed */
2271 for (i = 0; i < 64; i++) {
2273 mdic = E1000_READ_REG(hw, MDIC);
2274 if (mdic & E1000_MDIC_READY)
2277 if (!(mdic & E1000_MDIC_READY)) {
2278 DEBUGOUT("MDI Read did not complete\n");
2279 return -E1000_ERR_PHY;
2281 if (mdic & E1000_MDIC_ERROR) {
2282 DEBUGOUT("MDI Error\n");
2283 return -E1000_ERR_PHY;
2285 *phy_data = (uint16_t) mdic;
2287 /* We must first send a preamble through the MDIO pin to signal the
2288 * beginning of an MII instruction. This is done by sending 32
2289 * consecutive "1" bits.
2291 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2293 /* Now combine the next few fields that are required for a read
2294 * operation. We use this method instead of calling the
2295 * e1000_shift_out_mdi_bits routine five different times. The format of
2296 * a MII read instruction consists of a shift out of 14 bits and is
2297 * defined as follows:
2298 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2299 * followed by a shift in of 18 bits. This first two bits shifted in
2300 * are TurnAround bits used to avoid contention on the MDIO pin when a
2301 * READ operation is performed. These two bits are thrown away
2302 * followed by a shift in of 16 bits which contains the desired data.
2304 mdic = ((reg_addr) | (phy_addr << 5) |
2305 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2307 e1000_shift_out_mdi_bits(hw, mdic, 14);
2309 /* Now that we've shifted out the read command to the MII, we need to
2310 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2313 *phy_data = e1000_shift_in_mdi_bits(hw);
2318 /******************************************************************************
2319 * Writes a value to a PHY register
2321 * hw - Struct containing variables accessed by shared code
2322 * reg_addr - address of the PHY register to write
2323 * data - data to write to the PHY
2324 ******************************************************************************/
2326 e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data)
2330 const uint32_t phy_addr = 1;
2332 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2333 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
2334 return -E1000_ERR_PARAM;
2337 if (hw->mac_type > e1000_82543) {
2338 /* Set up Op-code, Phy Address, register address, and data intended
2339 * for the PHY register in the MDI Control register. The MAC will take
2340 * care of interfacing with the PHY to send the desired data.
2342 mdic = (((uint32_t) phy_data) |
2343 (reg_addr << E1000_MDIC_REG_SHIFT) |
2344 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2345 (E1000_MDIC_OP_WRITE));
2347 E1000_WRITE_REG(hw, MDIC, mdic);
2349 /* Poll the ready bit to see if the MDI read completed */
2350 for (i = 0; i < 64; i++) {
2352 mdic = E1000_READ_REG(hw, MDIC);
2353 if (mdic & E1000_MDIC_READY)
2356 if (!(mdic & E1000_MDIC_READY)) {
2357 DEBUGOUT("MDI Write did not complete\n");
2358 return -E1000_ERR_PHY;
2361 /* We'll need to use the SW defined pins to shift the write command
2362 * out to the PHY. We first send a preamble to the PHY to signal the
2363 * beginning of the MII instruction. This is done by sending 32
2364 * consecutive "1" bits.
2366 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2368 /* Now combine the remaining required fields that will indicate a
2369 * write operation. We use this method instead of calling the
2370 * e1000_shift_out_mdi_bits routine for each field in the command. The
2371 * format of a MII write instruction is as follows:
2372 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2374 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2375 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2377 mdic |= (uint32_t) phy_data;
2379 e1000_shift_out_mdi_bits(hw, mdic, 32);
2384 /******************************************************************************
2385 * Returns the PHY to the power-on reset state
2387 * hw - Struct containing variables accessed by shared code
2388 ******************************************************************************/
2390 e1000_phy_hw_reset(struct e1000_hw *hw)
2397 DEBUGOUT("Resetting Phy...\n");
2399 if (hw->mac_type > e1000_82543) {
2400 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2401 * bit. Then, take it out of reset.
2403 ctrl = E1000_READ_REG(hw, CTRL);
2404 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
2405 E1000_WRITE_FLUSH(hw);
2407 E1000_WRITE_REG(hw, CTRL, ctrl);
2408 E1000_WRITE_FLUSH(hw);
2410 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2411 * bit to put the PHY into reset. Then, take it out of reset.
2413 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2414 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2415 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2416 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2417 E1000_WRITE_FLUSH(hw);
2419 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2420 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2421 E1000_WRITE_FLUSH(hw);
2426 /******************************************************************************
2429 * hw - Struct containing variables accessed by shared code
2431 * Sets bit 15 of the MII Control regiser
2432 ******************************************************************************/
2434 e1000_phy_reset(struct e1000_hw *hw)
2440 if (e1000_read_phy_reg(hw, PHY_CTRL, &phy_data) < 0) {
2441 DEBUGOUT("PHY Read Error\n");
2442 return -E1000_ERR_PHY;
2444 phy_data |= MII_CR_RESET;
2445 if (e1000_write_phy_reg(hw, PHY_CTRL, phy_data) < 0) {
2446 DEBUGOUT("PHY Write Error\n");
2447 return -E1000_ERR_PHY;
2453 /******************************************************************************
2454 * Probes the expected PHY address for known PHY IDs
2456 * hw - Struct containing variables accessed by shared code
2457 ******************************************************************************/
2459 e1000_detect_gig_phy(struct e1000_hw *hw)
2461 uint16_t phy_id_high, phy_id_low;
2466 /* Read the PHY ID Registers to identify which PHY is onboard. */
2467 if (e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high) < 0) {
2468 DEBUGOUT("PHY Read Error\n");
2469 return -E1000_ERR_PHY;
2471 hw->phy_id = (uint32_t) (phy_id_high << 16);
2473 if (e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low) < 0) {
2474 DEBUGOUT("PHY Read Error\n");
2475 return -E1000_ERR_PHY;
2477 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
2479 switch (hw->mac_type) {
2481 if (hw->phy_id == M88E1000_E_PHY_ID)
2485 if (hw->phy_id == M88E1000_I_PHY_ID)
2491 if (hw->phy_id == M88E1011_I_PHY_ID)
2495 DEBUGOUT("Invalid MAC type %d\n", hw->mac_type);
2496 return -E1000_ERR_CONFIG;
2499 DEBUGOUT("PHY ID 0x%X detected\n", hw->phy_id);
2502 DEBUGOUT("Invalid PHY ID 0x%X\n", hw->phy_id);
2503 return -E1000_ERR_PHY;
2507 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
2509 * e1000_sw_init initializes the Adapter private data structure.
2510 * Fields are initialized based on PCI device information and
2511 * OS network device settings (MTU size).
2515 e1000_sw_init(struct eth_device *nic, int cardnum)
2517 struct e1000_hw *hw = (typeof(hw)) nic->priv;
2520 /* PCI config space info */
2521 pci_read_config_word(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
2522 pci_read_config_word(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
2523 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
2524 &hw->subsystem_vendor_id);
2525 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
2527 pci_read_config_byte(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
2528 pci_read_config_word(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
2530 /* identify the MAC */
2531 result = e1000_set_mac_type(hw);
2533 E1000_ERR("Unknown MAC Type\n");
2537 /* lan a vs. lan b settings */
2538 if (hw->mac_type == e1000_82546)
2539 /*this also works w/ multiple 82546 cards */
2540 /*but not if they're intermingled /w other e1000s */
2541 hw->lan_loc = (cardnum % 2) ? e1000_lan_b : e1000_lan_a;
2543 hw->lan_loc = e1000_lan_a;
2545 /* flow control settings */
2546 hw->fc_high_water = E1000_FC_HIGH_THRESH;
2547 hw->fc_low_water = E1000_FC_LOW_THRESH;
2548 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
2549 hw->fc_send_xon = 1;
2551 /* Media type - copper or fiber */
2553 if (hw->mac_type >= e1000_82543) {
2554 uint32_t status = E1000_READ_REG(hw, STATUS);
2556 if (status & E1000_STATUS_TBIMODE) {
2557 DEBUGOUT("fiber interface\n");
2558 hw->media_type = e1000_media_type_fiber;
2560 DEBUGOUT("copper interface\n");
2561 hw->media_type = e1000_media_type_copper;
2564 hw->media_type = e1000_media_type_fiber;
2567 if (hw->mac_type < e1000_82543)
2568 hw->report_tx_early = 0;
2570 hw->report_tx_early = 1;
2572 hw->tbi_compatibility_en = TRUE;
2574 hw->wait_autoneg_complete = FALSE;
2575 hw->adaptive_ifs = TRUE;
2577 /* Copper options */
2578 if (hw->media_type == e1000_media_type_copper) {
2579 hw->mdix = AUTO_ALL_MODES;
2580 hw->disable_polarity_correction = FALSE;
2583 return E1000_SUCCESS;
2587 fill_rx(struct e1000_hw *hw)
2589 struct e1000_rx_desc *rd;
2592 rd = rx_base + rx_tail;
2593 rx_tail = (rx_tail + 1) % 8;
2595 rd->buffer_addr = cpu_to_le64((u32) & packet);
2596 E1000_WRITE_REG(hw, RDT, rx_tail);
2600 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
2601 * @adapter: board private structure
2603 * Configure the Tx unit of the MAC after a reset.
2607 e1000_configure_tx(struct e1000_hw *hw)
2613 ptr = (u32) tx_pool;
2615 ptr = (ptr + 0x10) & (~0xf);
2617 tx_base = (typeof(tx_base)) ptr;
2619 E1000_WRITE_REG(hw, TDBAL, (u32) tx_base);
2620 E1000_WRITE_REG(hw, TDBAH, 0);
2622 E1000_WRITE_REG(hw, TDLEN, 128);
2624 /* Setup the HW Tx Head and Tail descriptor pointers */
2625 E1000_WRITE_REG(hw, TDH, 0);
2626 E1000_WRITE_REG(hw, TDT, 0);
2629 /* Set the default values for the Tx Inter Packet Gap timer */
2630 switch (hw->mac_type) {
2631 case e1000_82542_rev2_0:
2632 case e1000_82542_rev2_1:
2633 tipg = DEFAULT_82542_TIPG_IPGT;
2634 tipg |= DEFAULT_82542_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
2635 tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
2638 if (hw->media_type == e1000_media_type_fiber)
2639 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
2641 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
2642 tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
2643 tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
2645 E1000_WRITE_REG(hw, TIPG, tipg);
2647 /* Set the Tx Interrupt Delay register */
2648 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
2649 if (hw->mac_type >= e1000_82540)
2650 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
2652 /* Program the Transmit Control Register */
2653 tctl = E1000_READ_REG(hw, TCTL);
2654 tctl &= ~E1000_TCTL_CT;
2655 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
2656 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
2657 E1000_WRITE_REG(hw, TCTL, tctl);
2659 e1000_config_collision_dist(hw);
2661 /* Setup Transmit Descriptor Settings for this adapter */
2662 adapter->txd_cmd = E1000_TXD_CMD_IFCS | E1000_TXD_CMD_IDE;
2664 if (adapter->hw.report_tx_early == 1)
2665 adapter->txd_cmd |= E1000_TXD_CMD_RS;
2667 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
2672 * e1000_setup_rctl - configure the receive control register
2673 * @adapter: Board private structure
2676 e1000_setup_rctl(struct e1000_hw *hw)
2680 rctl = E1000_READ_REG(hw, RCTL);
2682 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
2684 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF; /* |
2685 (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */
2687 if (hw->tbi_compatibility_on == 1)
2688 rctl |= E1000_RCTL_SBP;
2690 rctl &= ~E1000_RCTL_SBP;
2692 rctl &= ~(E1000_RCTL_SZ_4096);
2694 switch (adapter->rx_buffer_len) {
2695 case E1000_RXBUFFER_2048:
2698 rctl |= E1000_RCTL_SZ_2048;
2699 rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
2702 case E1000_RXBUFFER_4096:
2703 rctl |= E1000_RCTL_SZ_4096 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
2705 case E1000_RXBUFFER_8192:
2706 rctl |= E1000_RCTL_SZ_8192 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
2708 case E1000_RXBUFFER_16384:
2709 rctl |= E1000_RCTL_SZ_16384 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
2713 E1000_WRITE_REG(hw, RCTL, rctl);
2717 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
2718 * @adapter: board private structure
2720 * Configure the Rx unit of the MAC after a reset.
2723 e1000_configure_rx(struct e1000_hw *hw)
2728 unsigned long rxcsum;
2731 /* make sure receives are disabled while setting up the descriptors */
2732 rctl = E1000_READ_REG(hw, RCTL);
2733 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
2735 /* set the Receive Delay Timer Register */
2737 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
2739 if (hw->mac_type >= e1000_82540) {
2741 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
2743 /* Set the interrupt throttling rate. Value is calculated
2744 * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */
2745 #define MAX_INTS_PER_SEC 8000
2746 #define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
2747 E1000_WRITE_REG(hw, ITR, DEFAULT_ITR);
2750 /* Setup the Base and Length of the Rx Descriptor Ring */
2751 ptr = (u32) rx_pool;
2753 ptr = (ptr + 0x10) & (~0xf);
2754 rx_base = (typeof(rx_base)) ptr;
2755 E1000_WRITE_REG(hw, RDBAL, (u32) rx_base);
2756 E1000_WRITE_REG(hw, RDBAH, 0);
2758 E1000_WRITE_REG(hw, RDLEN, 128);
2760 /* Setup the HW Rx Head and Tail Descriptor Pointers */
2761 E1000_WRITE_REG(hw, RDH, 0);
2762 E1000_WRITE_REG(hw, RDT, 0);
2764 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
2765 if ((adapter->hw.mac_type >= e1000_82543) && (adapter->rx_csum == TRUE)) {
2766 rxcsum = E1000_READ_REG(hw, RXCSUM);
2767 rxcsum |= E1000_RXCSUM_TUOFL;
2768 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
2771 /* Enable Receives */
2773 E1000_WRITE_REG(hw, RCTL, rctl);
2777 /**************************************************************************
2778 POLL - Wait for a frame
2779 ***************************************************************************/
2781 e1000_poll(struct eth_device *nic)
2783 struct e1000_hw *hw = nic->priv;
2784 struct e1000_rx_desc *rd;
2785 /* return true if there's an ethernet packet ready to read */
2786 rd = rx_base + rx_last;
2787 if (!(le32_to_cpu(rd->status)) & E1000_RXD_STAT_DD)
2789 /*DEBUGOUT("recv: packet len=%d \n", rd->length); */
2790 NetReceive(packet, le32_to_cpu(rd->length));
2795 /**************************************************************************
2796 TRANSMIT - Transmit a frame
2797 ***************************************************************************/
2799 e1000_transmit(struct eth_device *nic, volatile void *packet, int length)
2801 struct e1000_hw *hw = nic->priv;
2802 struct e1000_tx_desc *txp;
2805 txp = tx_base + tx_tail;
2806 tx_tail = (tx_tail + 1) % 8;
2808 txp->buffer_addr = cpu_to_le64(virt_to_bus(packet));
2809 txp->lower.data = cpu_to_le32(E1000_TXD_CMD_RPS | E1000_TXD_CMD_EOP |
2810 E1000_TXD_CMD_IFCS | length);
2811 txp->upper.data = 0;
2812 E1000_WRITE_REG(hw, TDT, tx_tail);
2814 while (!(le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD)) {
2815 if (i++ > TOUT_LOOP) {
2816 DEBUGOUT("e1000: tx timeout\n");
2819 udelay(10); /* give the nic a chance to write to the register */
2826 e1000_reset(struct eth_device *nic)
2828 struct e1000_hw *hw = nic->priv;
2831 if (hw->mac_type >= e1000_82544) {
2832 E1000_WRITE_REG(hw, WUC, 0);
2834 return e1000_init_hw(nic);
2837 /**************************************************************************
2838 DISABLE - Turn off ethernet interface
2839 ***************************************************************************/
2841 e1000_disable(struct eth_device *nic)
2843 struct e1000_hw *hw = nic->priv;
2845 /* Turn off the ethernet interface */
2846 E1000_WRITE_REG(hw, RCTL, 0);
2847 E1000_WRITE_REG(hw, TCTL, 0);
2849 /* Clear the transmit ring */
2850 E1000_WRITE_REG(hw, TDH, 0);
2851 E1000_WRITE_REG(hw, TDT, 0);
2853 /* Clear the receive ring */
2854 E1000_WRITE_REG(hw, RDH, 0);
2855 E1000_WRITE_REG(hw, RDT, 0);
2857 /* put the card in its initial state */
2859 E1000_WRITE_REG(hw, CTRL, E1000_CTRL_RST);
2865 /**************************************************************************
2866 INIT - set up ethernet interface(s)
2867 ***************************************************************************/
2869 e1000_init(struct eth_device *nic, bd_t * bis)
2871 struct e1000_hw *hw = nic->priv;
2874 ret_val = e1000_reset(nic);
2876 if ((ret_val == -E1000_ERR_NOLINK) ||
2877 (ret_val == -E1000_ERR_TIMEOUT)) {
2878 E1000_ERR("Valid Link not detected\n");
2880 E1000_ERR("Hardware Initialization Failed\n");
2884 e1000_configure_tx(hw);
2885 e1000_setup_rctl(hw);
2886 e1000_configure_rx(hw);
2890 /**************************************************************************
2891 PROBE - Look for an adapter, this routine's visible to the outside
2892 You should omit the last argument struct pci_device * for a non-PCI NIC
2893 ***************************************************************************/
2895 e1000_initialize(bd_t * bis)
2898 int card_number = 0;
2899 struct eth_device *nic = NULL;
2900 struct e1000_hw *hw = NULL;
2905 while (1) { /* Find PCI device(s) */
2906 if ((devno = pci_find_devices(supported, idx++)) < 0) {
2910 pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &iobase);
2911 iobase &= ~0xf; /* Mask the bits that say "this is an io addr" */
2912 DEBUGOUT("e1000#%d: iobase 0x%08x\n", card_number, iobase);
2914 pci_write_config_dword(devno, PCI_COMMAND,
2915 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
2916 /* Check if I/O accesses and Bus Mastering are enabled. */
2917 pci_read_config_dword(devno, PCI_COMMAND, &PciCommandWord);
2918 if (!(PciCommandWord & PCI_COMMAND_MEMORY)) {
2919 printf("Error: Can not enable MEM access.\n");
2921 } else if (!(PciCommandWord & PCI_COMMAND_MASTER)) {
2922 printf("Error: Can not enable Bus Mastering.\n");
2926 nic = (struct eth_device *) malloc(sizeof (*nic));
2927 hw = (struct e1000_hw *) malloc(sizeof (*hw));
2930 nic->iobase = bus_to_phys(devno, iobase);
2932 sprintf(nic->name, "e1000#%d", card_number);
2934 /* Are these variables needed? */
2936 hw->fc = e1000_fc_none;
2937 hw->original_fc = e1000_fc_none;
2939 hw->fc = e1000_fc_default;
2940 hw->original_fc = e1000_fc_default;
2942 hw->autoneg_failed = 0;
2943 hw->get_link_status = TRUE;
2944 hw->hw_addr = (typeof(hw->hw_addr)) iobase;
2945 hw->mac_type = e1000_undefined;
2947 /* MAC and Phy settings */
2948 if (e1000_sw_init(nic, card_number) < 0) {
2953 if (e1000_validate_eeprom_checksum(nic) < 0) {
2954 printf("The EEPROM Checksum Is Not Valid\n");
2959 e1000_read_mac_addr(nic);
2961 E1000_WRITE_REG(hw, PBA, E1000_DEFAULT_PBA);
2963 printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n",
2964 nic->enetaddr[0], nic->enetaddr[1], nic->enetaddr[2],
2965 nic->enetaddr[3], nic->enetaddr[4], nic->enetaddr[5]);
2967 nic->init = e1000_init;
2968 nic->recv = e1000_poll;
2969 nic->send = e1000_transmit;
2970 nic->halt = e1000_disable;