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>
44 * Copyright 2011 Freescale Semiconductor, Inc.
49 #define TOUT_LOOP 100000
51 #define virt_to_bus(devno, v) pci_virt_to_mem(devno, (void *) (v))
52 #define bus_to_phys(devno, a) pci_mem_to_phys(devno, a)
54 #define E1000_DEFAULT_PCI_PBA 0x00000030
55 #define E1000_DEFAULT_PCIE_PBA 0x000a0026
57 /* NIC specific static variables go here */
59 static char tx_pool[128 + 16];
60 static char rx_pool[128 + 16];
61 static char packet[2096];
63 static struct e1000_tx_desc *tx_base;
64 static struct e1000_rx_desc *rx_base;
67 static int rx_tail, rx_last;
69 static struct pci_device_id e1000_supported[] = {
70 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82542},
71 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_FIBER},
72 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_COPPER},
73 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_COPPER},
74 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_FIBER},
75 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_COPPER},
76 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_LOM},
77 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM},
78 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_COPPER},
79 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545GM_COPPER},
80 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_COPPER},
81 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_FIBER},
82 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_FIBER},
83 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_COPPER},
84 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM_LOM},
85 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541ER},
86 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541GI_LF},
88 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_COPPER},
89 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_FIBER },
90 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES },
91 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER},
92 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571PT_QUAD_COPPER},
93 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_FIBER},
94 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER_LOWPROFILE},
95 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_DUAL},
96 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_QUAD},
97 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_COPPER},
98 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_FIBER},
99 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_SERDES},
100 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI},
101 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E},
102 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E_IAMT},
103 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573L},
104 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82574L},
105 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_QUAD_COPPER_KSP3},
106 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_DPT},
107 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_DPT},
108 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_SPT},
109 {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_SPT},
113 /* Function forward declarations */
114 static int e1000_setup_link(struct eth_device *nic);
115 static int e1000_setup_fiber_link(struct eth_device *nic);
116 static int e1000_setup_copper_link(struct eth_device *nic);
117 static int e1000_phy_setup_autoneg(struct e1000_hw *hw);
118 static void e1000_config_collision_dist(struct e1000_hw *hw);
119 static int e1000_config_mac_to_phy(struct e1000_hw *hw);
120 static int e1000_config_fc_after_link_up(struct e1000_hw *hw);
121 static int e1000_check_for_link(struct eth_device *nic);
122 static int e1000_wait_autoneg(struct e1000_hw *hw);
123 static int e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t * speed,
125 static int e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
126 uint16_t * phy_data);
127 static int e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
129 static int32_t e1000_phy_hw_reset(struct e1000_hw *hw);
130 static int e1000_phy_reset(struct e1000_hw *hw);
131 static int e1000_detect_gig_phy(struct e1000_hw *hw);
132 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
133 static void e1000_set_media_type(struct e1000_hw *hw);
135 static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
136 static int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
138 static int32_t e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
141 /******************************************************************************
142 * Raises the EEPROM's clock input.
144 * hw - Struct containing variables accessed by shared code
145 * eecd - EECD's current value
146 *****************************************************************************/
147 void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
149 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
150 * wait 50 microseconds.
152 *eecd = *eecd | E1000_EECD_SK;
153 E1000_WRITE_REG(hw, EECD, *eecd);
154 E1000_WRITE_FLUSH(hw);
158 /******************************************************************************
159 * Lowers the EEPROM's clock input.
161 * hw - Struct containing variables accessed by shared code
162 * eecd - EECD's current value
163 *****************************************************************************/
164 void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
166 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
167 * wait 50 microseconds.
169 *eecd = *eecd & ~E1000_EECD_SK;
170 E1000_WRITE_REG(hw, EECD, *eecd);
171 E1000_WRITE_FLUSH(hw);
175 /******************************************************************************
176 * Shift data bits out to the EEPROM.
178 * hw - Struct containing variables accessed by shared code
179 * data - data to send to the EEPROM
180 * count - number of bits to shift out
181 *****************************************************************************/
183 e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count)
188 /* We need to shift "count" bits out to the EEPROM. So, value in the
189 * "data" parameter will be shifted out to the EEPROM one bit at a time.
190 * In order to do this, "data" must be broken down into bits.
192 mask = 0x01 << (count - 1);
193 eecd = E1000_READ_REG(hw, EECD);
194 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
196 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
197 * and then raising and then lowering the clock (the SK bit controls
198 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
199 * by setting "DI" to "0" and then raising and then lowering the clock.
201 eecd &= ~E1000_EECD_DI;
204 eecd |= E1000_EECD_DI;
206 E1000_WRITE_REG(hw, EECD, eecd);
207 E1000_WRITE_FLUSH(hw);
211 e1000_raise_ee_clk(hw, &eecd);
212 e1000_lower_ee_clk(hw, &eecd);
218 /* We leave the "DI" bit set to "0" when we leave this routine. */
219 eecd &= ~E1000_EECD_DI;
220 E1000_WRITE_REG(hw, EECD, eecd);
223 /******************************************************************************
224 * Shift data bits in from the EEPROM
226 * hw - Struct containing variables accessed by shared code
227 *****************************************************************************/
229 e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count)
235 /* In order to read a register from the EEPROM, we need to shift 'count'
236 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
237 * input to the EEPROM (setting the SK bit), and then reading the
238 * value of the "DO" bit. During this "shifting in" process the
239 * "DI" bit should always be clear.
242 eecd = E1000_READ_REG(hw, EECD);
244 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
247 for (i = 0; i < count; i++) {
249 e1000_raise_ee_clk(hw, &eecd);
251 eecd = E1000_READ_REG(hw, EECD);
253 eecd &= ~(E1000_EECD_DI);
254 if (eecd & E1000_EECD_DO)
257 e1000_lower_ee_clk(hw, &eecd);
263 /******************************************************************************
264 * Returns EEPROM to a "standby" state
266 * hw - Struct containing variables accessed by shared code
267 *****************************************************************************/
268 void e1000_standby_eeprom(struct e1000_hw *hw)
270 struct e1000_eeprom_info *eeprom = &hw->eeprom;
273 eecd = E1000_READ_REG(hw, EECD);
275 if (eeprom->type == e1000_eeprom_microwire) {
276 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
277 E1000_WRITE_REG(hw, EECD, eecd);
278 E1000_WRITE_FLUSH(hw);
279 udelay(eeprom->delay_usec);
282 eecd |= E1000_EECD_SK;
283 E1000_WRITE_REG(hw, EECD, eecd);
284 E1000_WRITE_FLUSH(hw);
285 udelay(eeprom->delay_usec);
288 eecd |= E1000_EECD_CS;
289 E1000_WRITE_REG(hw, EECD, eecd);
290 E1000_WRITE_FLUSH(hw);
291 udelay(eeprom->delay_usec);
294 eecd &= ~E1000_EECD_SK;
295 E1000_WRITE_REG(hw, EECD, eecd);
296 E1000_WRITE_FLUSH(hw);
297 udelay(eeprom->delay_usec);
298 } else if (eeprom->type == e1000_eeprom_spi) {
299 /* Toggle CS to flush commands */
300 eecd |= E1000_EECD_CS;
301 E1000_WRITE_REG(hw, EECD, eecd);
302 E1000_WRITE_FLUSH(hw);
303 udelay(eeprom->delay_usec);
304 eecd &= ~E1000_EECD_CS;
305 E1000_WRITE_REG(hw, EECD, eecd);
306 E1000_WRITE_FLUSH(hw);
307 udelay(eeprom->delay_usec);
311 /***************************************************************************
312 * Description: Determines if the onboard NVM is FLASH or EEPROM.
314 * hw - Struct containing variables accessed by shared code
315 ****************************************************************************/
316 static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
322 if (hw->mac_type == e1000_ich8lan)
325 if (hw->mac_type == e1000_82573 || hw->mac_type == e1000_82574) {
326 eecd = E1000_READ_REG(hw, EECD);
328 /* Isolate bits 15 & 16 */
329 eecd = ((eecd >> 15) & 0x03);
331 /* If both bits are set, device is Flash type */
338 /******************************************************************************
339 * Prepares EEPROM for access
341 * hw - Struct containing variables accessed by shared code
343 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
344 * function should be called before issuing a command to the EEPROM.
345 *****************************************************************************/
346 int32_t e1000_acquire_eeprom(struct e1000_hw *hw)
348 struct e1000_eeprom_info *eeprom = &hw->eeprom;
349 uint32_t eecd, i = 0;
353 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
354 return -E1000_ERR_SWFW_SYNC;
355 eecd = E1000_READ_REG(hw, EECD);
357 if (hw->mac_type != e1000_82573 || hw->mac_type != e1000_82574) {
358 /* Request EEPROM Access */
359 if (hw->mac_type > e1000_82544) {
360 eecd |= E1000_EECD_REQ;
361 E1000_WRITE_REG(hw, EECD, eecd);
362 eecd = E1000_READ_REG(hw, EECD);
363 while ((!(eecd & E1000_EECD_GNT)) &&
364 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
367 eecd = E1000_READ_REG(hw, EECD);
369 if (!(eecd & E1000_EECD_GNT)) {
370 eecd &= ~E1000_EECD_REQ;
371 E1000_WRITE_REG(hw, EECD, eecd);
372 DEBUGOUT("Could not acquire EEPROM grant\n");
373 return -E1000_ERR_EEPROM;
378 /* Setup EEPROM for Read/Write */
380 if (eeprom->type == e1000_eeprom_microwire) {
381 /* Clear SK and DI */
382 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
383 E1000_WRITE_REG(hw, EECD, eecd);
386 eecd |= E1000_EECD_CS;
387 E1000_WRITE_REG(hw, EECD, eecd);
388 } else if (eeprom->type == e1000_eeprom_spi) {
389 /* Clear SK and CS */
390 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
391 E1000_WRITE_REG(hw, EECD, eecd);
395 return E1000_SUCCESS;
398 /******************************************************************************
399 * Sets up eeprom variables in the hw struct. Must be called after mac_type
400 * is configured. Additionally, if this is ICH8, the flash controller GbE
401 * registers must be mapped, or this will crash.
403 * hw - Struct containing variables accessed by shared code
404 *****************************************************************************/
405 static int32_t e1000_init_eeprom_params(struct e1000_hw *hw)
407 struct e1000_eeprom_info *eeprom = &hw->eeprom;
408 uint32_t eecd = E1000_READ_REG(hw, EECD);
409 int32_t ret_val = E1000_SUCCESS;
410 uint16_t eeprom_size;
414 switch (hw->mac_type) {
415 case e1000_82542_rev2_0:
416 case e1000_82542_rev2_1:
419 eeprom->type = e1000_eeprom_microwire;
420 eeprom->word_size = 64;
421 eeprom->opcode_bits = 3;
422 eeprom->address_bits = 6;
423 eeprom->delay_usec = 50;
424 eeprom->use_eerd = false;
425 eeprom->use_eewr = false;
429 case e1000_82545_rev_3:
431 case e1000_82546_rev_3:
432 eeprom->type = e1000_eeprom_microwire;
433 eeprom->opcode_bits = 3;
434 eeprom->delay_usec = 50;
435 if (eecd & E1000_EECD_SIZE) {
436 eeprom->word_size = 256;
437 eeprom->address_bits = 8;
439 eeprom->word_size = 64;
440 eeprom->address_bits = 6;
442 eeprom->use_eerd = false;
443 eeprom->use_eewr = false;
446 case e1000_82541_rev_2:
448 case e1000_82547_rev_2:
449 if (eecd & E1000_EECD_TYPE) {
450 eeprom->type = e1000_eeprom_spi;
451 eeprom->opcode_bits = 8;
452 eeprom->delay_usec = 1;
453 if (eecd & E1000_EECD_ADDR_BITS) {
454 eeprom->page_size = 32;
455 eeprom->address_bits = 16;
457 eeprom->page_size = 8;
458 eeprom->address_bits = 8;
461 eeprom->type = e1000_eeprom_microwire;
462 eeprom->opcode_bits = 3;
463 eeprom->delay_usec = 50;
464 if (eecd & E1000_EECD_ADDR_BITS) {
465 eeprom->word_size = 256;
466 eeprom->address_bits = 8;
468 eeprom->word_size = 64;
469 eeprom->address_bits = 6;
472 eeprom->use_eerd = false;
473 eeprom->use_eewr = false;
477 eeprom->type = e1000_eeprom_spi;
478 eeprom->opcode_bits = 8;
479 eeprom->delay_usec = 1;
480 if (eecd & E1000_EECD_ADDR_BITS) {
481 eeprom->page_size = 32;
482 eeprom->address_bits = 16;
484 eeprom->page_size = 8;
485 eeprom->address_bits = 8;
487 eeprom->use_eerd = false;
488 eeprom->use_eewr = false;
492 eeprom->type = e1000_eeprom_spi;
493 eeprom->opcode_bits = 8;
494 eeprom->delay_usec = 1;
495 if (eecd & E1000_EECD_ADDR_BITS) {
496 eeprom->page_size = 32;
497 eeprom->address_bits = 16;
499 eeprom->page_size = 8;
500 eeprom->address_bits = 8;
502 eeprom->use_eerd = true;
503 eeprom->use_eewr = true;
504 if (e1000_is_onboard_nvm_eeprom(hw) == false) {
505 eeprom->type = e1000_eeprom_flash;
506 eeprom->word_size = 2048;
508 /* Ensure that the Autonomous FLASH update bit is cleared due to
509 * Flash update issue on parts which use a FLASH for NVM. */
510 eecd &= ~E1000_EECD_AUPDEN;
511 E1000_WRITE_REG(hw, EECD, eecd);
514 case e1000_80003es2lan:
515 eeprom->type = e1000_eeprom_spi;
516 eeprom->opcode_bits = 8;
517 eeprom->delay_usec = 1;
518 if (eecd & E1000_EECD_ADDR_BITS) {
519 eeprom->page_size = 32;
520 eeprom->address_bits = 16;
522 eeprom->page_size = 8;
523 eeprom->address_bits = 8;
525 eeprom->use_eerd = true;
526 eeprom->use_eewr = false;
529 /* ich8lan does not support currently. if needed, please
530 * add corresponding code and functions.
537 eeprom->type = e1000_eeprom_ich8;
538 eeprom->use_eerd = false;
539 eeprom->use_eewr = false;
540 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
541 uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw,
543 /* Zero the shadow RAM structure. But don't load it from NVM
544 * so as to save time for driver init */
545 if (hw->eeprom_shadow_ram != NULL) {
546 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
547 hw->eeprom_shadow_ram[i].modified = false;
548 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
552 hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) *
553 ICH_FLASH_SECTOR_SIZE;
555 hw->flash_bank_size = ((flash_size >> 16)
556 & ICH_GFPREG_BASE_MASK) + 1;
557 hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK);
559 hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE;
561 hw->flash_bank_size /= 2 * sizeof(uint16_t);
569 if (eeprom->type == e1000_eeprom_spi) {
570 /* eeprom_size will be an enum [0..8] that maps
571 * to eeprom sizes 128B to
572 * 32KB (incremented by powers of 2).
574 if (hw->mac_type <= e1000_82547_rev_2) {
575 /* Set to default value for initial eeprom read. */
576 eeprom->word_size = 64;
577 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1,
581 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK)
582 >> EEPROM_SIZE_SHIFT;
583 /* 256B eeprom size was not supported in earlier
584 * hardware, so we bump eeprom_size up one to
585 * ensure that "1" (which maps to 256B) is never
586 * the result used in the shifting logic below. */
590 eeprom_size = (uint16_t)((eecd &
591 E1000_EECD_SIZE_EX_MASK) >>
592 E1000_EECD_SIZE_EX_SHIFT);
595 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
600 /******************************************************************************
601 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
603 * hw - Struct containing variables accessed by shared code
604 *****************************************************************************/
606 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
608 uint32_t attempts = 100000;
610 int32_t done = E1000_ERR_EEPROM;
612 for (i = 0; i < attempts; i++) {
613 if (eerd == E1000_EEPROM_POLL_READ)
614 reg = E1000_READ_REG(hw, EERD);
616 reg = E1000_READ_REG(hw, EEWR);
618 if (reg & E1000_EEPROM_RW_REG_DONE) {
619 done = E1000_SUCCESS;
628 /******************************************************************************
629 * Reads a 16 bit word from the EEPROM using the EERD register.
631 * hw - Struct containing variables accessed by shared code
632 * offset - offset of word in the EEPROM to read
633 * data - word read from the EEPROM
634 * words - number of words to read
635 *****************************************************************************/
637 e1000_read_eeprom_eerd(struct e1000_hw *hw,
642 uint32_t i, eerd = 0;
645 for (i = 0; i < words; i++) {
646 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
647 E1000_EEPROM_RW_REG_START;
649 E1000_WRITE_REG(hw, EERD, eerd);
650 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
654 data[i] = (E1000_READ_REG(hw, EERD) >>
655 E1000_EEPROM_RW_REG_DATA);
662 void e1000_release_eeprom(struct e1000_hw *hw)
668 eecd = E1000_READ_REG(hw, EECD);
670 if (hw->eeprom.type == e1000_eeprom_spi) {
671 eecd |= E1000_EECD_CS; /* Pull CS high */
672 eecd &= ~E1000_EECD_SK; /* Lower SCK */
674 E1000_WRITE_REG(hw, EECD, eecd);
676 udelay(hw->eeprom.delay_usec);
677 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
680 /* CS on Microwire is active-high */
681 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
683 E1000_WRITE_REG(hw, EECD, eecd);
685 /* Rising edge of clock */
686 eecd |= E1000_EECD_SK;
687 E1000_WRITE_REG(hw, EECD, eecd);
688 E1000_WRITE_FLUSH(hw);
689 udelay(hw->eeprom.delay_usec);
691 /* Falling edge of clock */
692 eecd &= ~E1000_EECD_SK;
693 E1000_WRITE_REG(hw, EECD, eecd);
694 E1000_WRITE_FLUSH(hw);
695 udelay(hw->eeprom.delay_usec);
698 /* Stop requesting EEPROM access */
699 if (hw->mac_type > e1000_82544) {
700 eecd &= ~E1000_EECD_REQ;
701 E1000_WRITE_REG(hw, EECD, eecd);
704 /******************************************************************************
705 * Reads a 16 bit word from the EEPROM.
707 * hw - Struct containing variables accessed by shared code
708 *****************************************************************************/
710 e1000_spi_eeprom_ready(struct e1000_hw *hw)
712 uint16_t retry_count = 0;
713 uint8_t spi_stat_reg;
717 /* Read "Status Register" repeatedly until the LSB is cleared. The
718 * EEPROM will signal that the command has been completed by clearing
719 * bit 0 of the internal status register. If it's not cleared within
720 * 5 milliseconds, then error out.
724 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
725 hw->eeprom.opcode_bits);
726 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
727 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
733 e1000_standby_eeprom(hw);
734 } while (retry_count < EEPROM_MAX_RETRY_SPI);
736 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
737 * only 0-5mSec on 5V devices)
739 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
740 DEBUGOUT("SPI EEPROM Status error\n");
741 return -E1000_ERR_EEPROM;
744 return E1000_SUCCESS;
747 /******************************************************************************
748 * Reads a 16 bit word from the EEPROM.
750 * hw - Struct containing variables accessed by shared code
751 * offset - offset of word in the EEPROM to read
752 * data - word read from the EEPROM
753 *****************************************************************************/
755 e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
756 uint16_t words, uint16_t *data)
758 struct e1000_eeprom_info *eeprom = &hw->eeprom;
763 /* If eeprom is not yet detected, do so now */
764 if (eeprom->word_size == 0)
765 e1000_init_eeprom_params(hw);
767 /* A check for invalid values: offset too large, too many words,
768 * and not enough words.
770 if ((offset >= eeprom->word_size) ||
771 (words > eeprom->word_size - offset) ||
773 DEBUGOUT("\"words\" parameter out of bounds."
774 "Words = %d, size = %d\n", offset, eeprom->word_size);
775 return -E1000_ERR_EEPROM;
778 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
779 * directly. In this case, we need to acquire the EEPROM so that
780 * FW or other port software does not interrupt.
782 if (e1000_is_onboard_nvm_eeprom(hw) == true &&
783 hw->eeprom.use_eerd == false) {
785 /* Prepare the EEPROM for bit-bang reading */
786 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
787 return -E1000_ERR_EEPROM;
790 /* Eerd register EEPROM access requires no eeprom aquire/release */
791 if (eeprom->use_eerd == true)
792 return e1000_read_eeprom_eerd(hw, offset, words, data);
794 /* ich8lan does not support currently. if needed, please
795 * add corresponding code and functions.
798 /* ICH EEPROM access is done via the ICH flash controller */
799 if (eeprom->type == e1000_eeprom_ich8)
800 return e1000_read_eeprom_ich8(hw, offset, words, data);
802 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
803 * acquired the EEPROM at this point, so any returns should relase it */
804 if (eeprom->type == e1000_eeprom_spi) {
806 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
808 if (e1000_spi_eeprom_ready(hw)) {
809 e1000_release_eeprom(hw);
810 return -E1000_ERR_EEPROM;
813 e1000_standby_eeprom(hw);
815 /* Some SPI eeproms use the 8th address bit embedded in
817 if ((eeprom->address_bits == 8) && (offset >= 128))
818 read_opcode |= EEPROM_A8_OPCODE_SPI;
820 /* Send the READ command (opcode + addr) */
821 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
822 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2),
823 eeprom->address_bits);
825 /* Read the data. The address of the eeprom internally
826 * increments with each byte (spi) being read, saving on the
827 * overhead of eeprom setup and tear-down. The address
828 * counter will roll over if reading beyond the size of
829 * the eeprom, thus allowing the entire memory to be read
830 * starting from any offset. */
831 for (i = 0; i < words; i++) {
832 word_in = e1000_shift_in_ee_bits(hw, 16);
833 data[i] = (word_in >> 8) | (word_in << 8);
835 } else if (eeprom->type == e1000_eeprom_microwire) {
836 for (i = 0; i < words; i++) {
837 /* Send the READ command (opcode + addr) */
838 e1000_shift_out_ee_bits(hw,
839 EEPROM_READ_OPCODE_MICROWIRE,
840 eeprom->opcode_bits);
841 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
842 eeprom->address_bits);
844 /* Read the data. For microwire, each word requires
845 * the overhead of eeprom setup and tear-down. */
846 data[i] = e1000_shift_in_ee_bits(hw, 16);
847 e1000_standby_eeprom(hw);
851 /* End this read operation */
852 e1000_release_eeprom(hw);
854 return E1000_SUCCESS;
857 /******************************************************************************
858 * Verifies that the EEPROM has a valid checksum
860 * hw - Struct containing variables accessed by shared code
862 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
863 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
865 *****************************************************************************/
866 static int e1000_validate_eeprom_checksum(struct e1000_hw *hw)
868 uint16_t i, checksum, checksum_reg, *buf;
872 /* Allocate a temporary buffer */
873 buf = malloc(sizeof(buf[0]) * (EEPROM_CHECKSUM_REG + 1));
875 E1000_ERR(hw->nic, "Unable to allocate EEPROM buffer!\n");
876 return -E1000_ERR_EEPROM;
879 /* Read the EEPROM */
880 if (e1000_read_eeprom(hw, 0, EEPROM_CHECKSUM_REG + 1, buf) < 0) {
881 E1000_ERR(hw->nic, "Unable to read EEPROM!\n");
882 return -E1000_ERR_EEPROM;
885 /* Compute the checksum */
887 for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
889 checksum = ((uint16_t)EEPROM_SUM) - checksum;
890 checksum_reg = buf[i];
893 if (checksum == checksum_reg)
896 /* Hrm, verification failed, print an error */
897 E1000_ERR(hw->nic, "EEPROM checksum is incorrect!\n");
898 E1000_ERR(hw->nic, " ...register was 0x%04hx, calculated 0x%04hx\n",
899 checksum_reg, checksum);
901 return -E1000_ERR_EEPROM;
904 /*****************************************************************************
905 * Set PHY to class A mode
906 * Assumes the following operations will follow to enable the new class mode.
907 * 1. Do a PHY soft reset
908 * 2. Restart auto-negotiation or force link.
910 * hw - Struct containing variables accessed by shared code
911 ****************************************************************************/
913 e1000_set_phy_mode(struct e1000_hw *hw)
916 uint16_t eeprom_data;
920 if ((hw->mac_type == e1000_82545_rev_3) &&
921 (hw->media_type == e1000_media_type_copper)) {
922 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD,
927 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
928 (eeprom_data & EEPROM_PHY_CLASS_A)) {
929 ret_val = e1000_write_phy_reg(hw,
930 M88E1000_PHY_PAGE_SELECT, 0x000B);
933 ret_val = e1000_write_phy_reg(hw,
934 M88E1000_PHY_GEN_CONTROL, 0x8104);
938 hw->phy_reset_disable = false;
942 return E1000_SUCCESS;
945 /***************************************************************************
947 * Obtaining software semaphore bit (SMBI) before resetting PHY.
949 * hw: Struct containing variables accessed by shared code
951 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
952 * E1000_SUCCESS at any other case.
954 ***************************************************************************/
956 e1000_get_software_semaphore(struct e1000_hw *hw)
958 int32_t timeout = hw->eeprom.word_size + 1;
963 if (hw->mac_type != e1000_80003es2lan)
964 return E1000_SUCCESS;
967 swsm = E1000_READ_REG(hw, SWSM);
968 /* If SMBI bit cleared, it is now set and we hold
970 if (!(swsm & E1000_SWSM_SMBI))
977 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
978 return -E1000_ERR_RESET;
981 return E1000_SUCCESS;
984 /***************************************************************************
985 * This function clears HW semaphore bits.
987 * hw: Struct containing variables accessed by shared code
991 ***************************************************************************/
993 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
999 if (!hw->eeprom_semaphore_present)
1002 swsm = E1000_READ_REG(hw, SWSM);
1003 if (hw->mac_type == e1000_80003es2lan) {
1004 /* Release both semaphores. */
1005 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1007 swsm &= ~(E1000_SWSM_SWESMBI);
1008 E1000_WRITE_REG(hw, SWSM, swsm);
1011 /***************************************************************************
1013 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
1014 * adapter or Eeprom access.
1016 * hw: Struct containing variables accessed by shared code
1018 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
1019 * E1000_SUCCESS at any other case.
1021 ***************************************************************************/
1023 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
1030 if (!hw->eeprom_semaphore_present)
1031 return E1000_SUCCESS;
1033 if (hw->mac_type == e1000_80003es2lan) {
1034 /* Get the SW semaphore. */
1035 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
1036 return -E1000_ERR_EEPROM;
1039 /* Get the FW semaphore. */
1040 timeout = hw->eeprom.word_size + 1;
1042 swsm = E1000_READ_REG(hw, SWSM);
1043 swsm |= E1000_SWSM_SWESMBI;
1044 E1000_WRITE_REG(hw, SWSM, swsm);
1045 /* if we managed to set the bit we got the semaphore. */
1046 swsm = E1000_READ_REG(hw, SWSM);
1047 if (swsm & E1000_SWSM_SWESMBI)
1055 /* Release semaphores */
1056 e1000_put_hw_eeprom_semaphore(hw);
1057 DEBUGOUT("Driver can't access the Eeprom - "
1058 "SWESMBI bit is set.\n");
1059 return -E1000_ERR_EEPROM;
1062 return E1000_SUCCESS;
1066 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
1068 uint32_t swfw_sync = 0;
1069 uint32_t swmask = mask;
1070 uint32_t fwmask = mask << 16;
1071 int32_t timeout = 200;
1075 if (e1000_get_hw_eeprom_semaphore(hw))
1076 return -E1000_ERR_SWFW_SYNC;
1078 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
1079 if (!(swfw_sync & (fwmask | swmask)))
1082 /* firmware currently using resource (fwmask) */
1083 /* or other software thread currently using resource (swmask) */
1084 e1000_put_hw_eeprom_semaphore(hw);
1090 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
1091 return -E1000_ERR_SWFW_SYNC;
1094 swfw_sync |= swmask;
1095 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
1097 e1000_put_hw_eeprom_semaphore(hw);
1098 return E1000_SUCCESS;
1101 static bool e1000_is_second_port(struct e1000_hw *hw)
1103 switch (hw->mac_type) {
1104 case e1000_80003es2lan:
1107 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
1115 /******************************************************************************
1116 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
1117 * second function of dual function devices
1119 * nic - Struct containing variables accessed by shared code
1120 *****************************************************************************/
1122 e1000_read_mac_addr(struct eth_device *nic)
1124 struct e1000_hw *hw = nic->priv;
1126 uint16_t eeprom_data;
1131 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
1133 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
1134 DEBUGOUT("EEPROM Read Error\n");
1135 return -E1000_ERR_EEPROM;
1137 nic->enetaddr[i] = eeprom_data & 0xff;
1138 nic->enetaddr[i + 1] = (eeprom_data >> 8) & 0xff;
1141 /* Invert the last bit if this is the second device */
1142 if (e1000_is_second_port(hw))
1143 nic->enetaddr[5] ^= 1;
1145 #ifdef CONFIG_E1000_FALLBACK_MAC
1146 if (!is_valid_ether_addr(nic->enetaddr)) {
1147 unsigned char fb_mac[NODE_ADDRESS_SIZE] = CONFIG_E1000_FALLBACK_MAC;
1149 memcpy (nic->enetaddr, fb_mac, NODE_ADDRESS_SIZE);
1155 /******************************************************************************
1156 * Initializes receive address filters.
1158 * hw - Struct containing variables accessed by shared code
1160 * Places the MAC address in receive address register 0 and clears the rest
1161 * of the receive addresss registers. Clears the multicast table. Assumes
1162 * the receiver is in reset when the routine is called.
1163 *****************************************************************************/
1165 e1000_init_rx_addrs(struct eth_device *nic)
1167 struct e1000_hw *hw = nic->priv;
1174 /* Setup the receive address. */
1175 DEBUGOUT("Programming MAC Address into RAR[0]\n");
1176 addr_low = (nic->enetaddr[0] |
1177 (nic->enetaddr[1] << 8) |
1178 (nic->enetaddr[2] << 16) | (nic->enetaddr[3] << 24));
1180 addr_high = (nic->enetaddr[4] | (nic->enetaddr[5] << 8) | E1000_RAH_AV);
1182 E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
1183 E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
1185 /* Zero out the other 15 receive addresses. */
1186 DEBUGOUT("Clearing RAR[1-15]\n");
1187 for (i = 1; i < E1000_RAR_ENTRIES; i++) {
1188 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
1189 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
1193 /******************************************************************************
1194 * Clears the VLAN filer table
1196 * hw - Struct containing variables accessed by shared code
1197 *****************************************************************************/
1199 e1000_clear_vfta(struct e1000_hw *hw)
1203 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
1204 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
1207 /******************************************************************************
1208 * Set the mac type member in the hw struct.
1210 * hw - Struct containing variables accessed by shared code
1211 *****************************************************************************/
1213 e1000_set_mac_type(struct e1000_hw *hw)
1217 switch (hw->device_id) {
1218 case E1000_DEV_ID_82542:
1219 switch (hw->revision_id) {
1220 case E1000_82542_2_0_REV_ID:
1221 hw->mac_type = e1000_82542_rev2_0;
1223 case E1000_82542_2_1_REV_ID:
1224 hw->mac_type = e1000_82542_rev2_1;
1227 /* Invalid 82542 revision ID */
1228 return -E1000_ERR_MAC_TYPE;
1231 case E1000_DEV_ID_82543GC_FIBER:
1232 case E1000_DEV_ID_82543GC_COPPER:
1233 hw->mac_type = e1000_82543;
1235 case E1000_DEV_ID_82544EI_COPPER:
1236 case E1000_DEV_ID_82544EI_FIBER:
1237 case E1000_DEV_ID_82544GC_COPPER:
1238 case E1000_DEV_ID_82544GC_LOM:
1239 hw->mac_type = e1000_82544;
1241 case E1000_DEV_ID_82540EM:
1242 case E1000_DEV_ID_82540EM_LOM:
1243 case E1000_DEV_ID_82540EP:
1244 case E1000_DEV_ID_82540EP_LOM:
1245 case E1000_DEV_ID_82540EP_LP:
1246 hw->mac_type = e1000_82540;
1248 case E1000_DEV_ID_82545EM_COPPER:
1249 case E1000_DEV_ID_82545EM_FIBER:
1250 hw->mac_type = e1000_82545;
1252 case E1000_DEV_ID_82545GM_COPPER:
1253 case E1000_DEV_ID_82545GM_FIBER:
1254 case E1000_DEV_ID_82545GM_SERDES:
1255 hw->mac_type = e1000_82545_rev_3;
1257 case E1000_DEV_ID_82546EB_COPPER:
1258 case E1000_DEV_ID_82546EB_FIBER:
1259 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1260 hw->mac_type = e1000_82546;
1262 case E1000_DEV_ID_82546GB_COPPER:
1263 case E1000_DEV_ID_82546GB_FIBER:
1264 case E1000_DEV_ID_82546GB_SERDES:
1265 case E1000_DEV_ID_82546GB_PCIE:
1266 case E1000_DEV_ID_82546GB_QUAD_COPPER:
1267 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1268 hw->mac_type = e1000_82546_rev_3;
1270 case E1000_DEV_ID_82541EI:
1271 case E1000_DEV_ID_82541EI_MOBILE:
1272 case E1000_DEV_ID_82541ER_LOM:
1273 hw->mac_type = e1000_82541;
1275 case E1000_DEV_ID_82541ER:
1276 case E1000_DEV_ID_82541GI:
1277 case E1000_DEV_ID_82541GI_LF:
1278 case E1000_DEV_ID_82541GI_MOBILE:
1279 hw->mac_type = e1000_82541_rev_2;
1281 case E1000_DEV_ID_82547EI:
1282 case E1000_DEV_ID_82547EI_MOBILE:
1283 hw->mac_type = e1000_82547;
1285 case E1000_DEV_ID_82547GI:
1286 hw->mac_type = e1000_82547_rev_2;
1288 case E1000_DEV_ID_82571EB_COPPER:
1289 case E1000_DEV_ID_82571EB_FIBER:
1290 case E1000_DEV_ID_82571EB_SERDES:
1291 case E1000_DEV_ID_82571EB_SERDES_DUAL:
1292 case E1000_DEV_ID_82571EB_SERDES_QUAD:
1293 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1294 case E1000_DEV_ID_82571PT_QUAD_COPPER:
1295 case E1000_DEV_ID_82571EB_QUAD_FIBER:
1296 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1297 hw->mac_type = e1000_82571;
1299 case E1000_DEV_ID_82572EI_COPPER:
1300 case E1000_DEV_ID_82572EI_FIBER:
1301 case E1000_DEV_ID_82572EI_SERDES:
1302 case E1000_DEV_ID_82572EI:
1303 hw->mac_type = e1000_82572;
1305 case E1000_DEV_ID_82573E:
1306 case E1000_DEV_ID_82573E_IAMT:
1307 case E1000_DEV_ID_82573L:
1308 hw->mac_type = e1000_82573;
1310 case E1000_DEV_ID_82574L:
1311 hw->mac_type = e1000_82574;
1313 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
1314 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
1315 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
1316 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
1317 hw->mac_type = e1000_80003es2lan;
1319 case E1000_DEV_ID_ICH8_IGP_M_AMT:
1320 case E1000_DEV_ID_ICH8_IGP_AMT:
1321 case E1000_DEV_ID_ICH8_IGP_C:
1322 case E1000_DEV_ID_ICH8_IFE:
1323 case E1000_DEV_ID_ICH8_IFE_GT:
1324 case E1000_DEV_ID_ICH8_IFE_G:
1325 case E1000_DEV_ID_ICH8_IGP_M:
1326 hw->mac_type = e1000_ich8lan;
1329 /* Should never have loaded on this device */
1330 return -E1000_ERR_MAC_TYPE;
1332 return E1000_SUCCESS;
1335 /******************************************************************************
1336 * Reset the transmit and receive units; mask and clear all interrupts.
1338 * hw - Struct containing variables accessed by shared code
1339 *****************************************************************************/
1341 e1000_reset_hw(struct e1000_hw *hw)
1350 /* get the correct pba value for both PCI and PCIe*/
1351 if (hw->mac_type < e1000_82571)
1352 pba = E1000_DEFAULT_PCI_PBA;
1354 pba = E1000_DEFAULT_PCIE_PBA;
1356 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
1357 if (hw->mac_type == e1000_82542_rev2_0) {
1358 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1359 pci_write_config_word(hw->pdev, PCI_COMMAND,
1360 hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1363 /* Clear interrupt mask to stop board from generating interrupts */
1364 DEBUGOUT("Masking off all interrupts\n");
1365 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1367 /* Disable the Transmit and Receive units. Then delay to allow
1368 * any pending transactions to complete before we hit the MAC with
1371 E1000_WRITE_REG(hw, RCTL, 0);
1372 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
1373 E1000_WRITE_FLUSH(hw);
1375 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
1376 hw->tbi_compatibility_on = false;
1378 /* Delay to allow any outstanding PCI transactions to complete before
1379 * resetting the device
1383 /* Issue a global reset to the MAC. This will reset the chip's
1384 * transmit, receive, DMA, and link units. It will not effect
1385 * the current PCI configuration. The global reset bit is self-
1386 * clearing, and should clear within a microsecond.
1388 DEBUGOUT("Issuing a global reset to MAC\n");
1389 ctrl = E1000_READ_REG(hw, CTRL);
1391 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
1393 /* Force a reload from the EEPROM if necessary */
1394 if (hw->mac_type < e1000_82540) {
1395 /* Wait for reset to complete */
1397 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1398 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1399 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1400 E1000_WRITE_FLUSH(hw);
1401 /* Wait for EEPROM reload */
1404 /* Wait for EEPROM reload (it happens automatically) */
1406 /* Dissable HW ARPs on ASF enabled adapters */
1407 manc = E1000_READ_REG(hw, MANC);
1408 manc &= ~(E1000_MANC_ARP_EN);
1409 E1000_WRITE_REG(hw, MANC, manc);
1412 /* Clear interrupt mask to stop board from generating interrupts */
1413 DEBUGOUT("Masking off all interrupts\n");
1414 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1416 /* Clear any pending interrupt events. */
1417 E1000_READ_REG(hw, ICR);
1419 /* If MWI was previously enabled, reenable it. */
1420 if (hw->mac_type == e1000_82542_rev2_0) {
1421 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1423 E1000_WRITE_REG(hw, PBA, pba);
1426 /******************************************************************************
1428 * Initialize a number of hardware-dependent bits
1430 * hw: Struct containing variables accessed by shared code
1432 * This function contains hardware limitation workarounds for PCI-E adapters
1434 *****************************************************************************/
1436 e1000_initialize_hardware_bits(struct e1000_hw *hw)
1438 if ((hw->mac_type >= e1000_82571) &&
1439 (!hw->initialize_hw_bits_disable)) {
1440 /* Settings common to all PCI-express silicon */
1441 uint32_t reg_ctrl, reg_ctrl_ext;
1442 uint32_t reg_tarc0, reg_tarc1;
1444 uint32_t reg_txdctl, reg_txdctl1;
1446 /* link autonegotiation/sync workarounds */
1447 reg_tarc0 = E1000_READ_REG(hw, TARC0);
1448 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
1450 /* Enable not-done TX descriptor counting */
1451 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
1452 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
1453 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
1455 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
1456 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
1457 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
1459 switch (hw->mac_type) {
1462 /* Clear PHY TX compatible mode bits */
1463 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1464 reg_tarc1 &= ~((1 << 30)|(1 << 29));
1466 /* link autonegotiation/sync workarounds */
1467 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
1469 /* TX ring control fixes */
1470 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
1472 /* Multiple read bit is reversed polarity */
1473 reg_tctl = E1000_READ_REG(hw, TCTL);
1474 if (reg_tctl & E1000_TCTL_MULR)
1475 reg_tarc1 &= ~(1 << 28);
1477 reg_tarc1 |= (1 << 28);
1479 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1483 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1484 reg_ctrl_ext &= ~(1 << 23);
1485 reg_ctrl_ext |= (1 << 22);
1487 /* TX byte count fix */
1488 reg_ctrl = E1000_READ_REG(hw, CTRL);
1489 reg_ctrl &= ~(1 << 29);
1491 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1492 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
1494 case e1000_80003es2lan:
1495 /* improve small packet performace for fiber/serdes */
1496 if ((hw->media_type == e1000_media_type_fiber)
1497 || (hw->media_type ==
1498 e1000_media_type_internal_serdes)) {
1499 reg_tarc0 &= ~(1 << 20);
1502 /* Multiple read bit is reversed polarity */
1503 reg_tctl = E1000_READ_REG(hw, TCTL);
1504 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1505 if (reg_tctl & E1000_TCTL_MULR)
1506 reg_tarc1 &= ~(1 << 28);
1508 reg_tarc1 |= (1 << 28);
1510 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1513 /* Reduce concurrent DMA requests to 3 from 4 */
1514 if ((hw->revision_id < 3) ||
1515 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1516 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
1517 reg_tarc0 |= ((1 << 29)|(1 << 28));
1519 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1520 reg_ctrl_ext |= (1 << 22);
1521 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1523 /* workaround TX hang with TSO=on */
1524 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
1526 /* Multiple read bit is reversed polarity */
1527 reg_tctl = E1000_READ_REG(hw, TCTL);
1528 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1529 if (reg_tctl & E1000_TCTL_MULR)
1530 reg_tarc1 &= ~(1 << 28);
1532 reg_tarc1 |= (1 << 28);
1534 /* workaround TX hang with TSO=on */
1535 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
1537 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1543 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
1547 /******************************************************************************
1548 * Performs basic configuration of the adapter.
1550 * hw - Struct containing variables accessed by shared code
1552 * Assumes that the controller has previously been reset and is in a
1553 * post-reset uninitialized state. Initializes the receive address registers,
1554 * multicast table, and VLAN filter table. Calls routines to setup link
1555 * configuration and flow control settings. Clears all on-chip counters. Leaves
1556 * the transmit and receive units disabled and uninitialized.
1557 *****************************************************************************/
1559 e1000_init_hw(struct eth_device *nic)
1561 struct e1000_hw *hw = nic->priv;
1565 uint16_t pcix_cmd_word;
1566 uint16_t pcix_stat_hi_word;
1568 uint16_t stat_mmrbc;
1573 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
1574 if ((hw->mac_type == e1000_ich8lan) &&
1575 ((hw->revision_id < 3) ||
1576 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1577 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
1578 reg_data = E1000_READ_REG(hw, STATUS);
1579 reg_data &= ~0x80000000;
1580 E1000_WRITE_REG(hw, STATUS, reg_data);
1582 /* Do not need initialize Identification LED */
1584 /* Set the media type and TBI compatibility */
1585 e1000_set_media_type(hw);
1587 /* Must be called after e1000_set_media_type
1588 * because media_type is used */
1589 e1000_initialize_hardware_bits(hw);
1591 /* Disabling VLAN filtering. */
1592 DEBUGOUT("Initializing the IEEE VLAN\n");
1593 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
1594 if (hw->mac_type != e1000_ich8lan) {
1595 if (hw->mac_type < e1000_82545_rev_3)
1596 E1000_WRITE_REG(hw, VET, 0);
1597 e1000_clear_vfta(hw);
1600 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
1601 if (hw->mac_type == e1000_82542_rev2_0) {
1602 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1603 pci_write_config_word(hw->pdev, PCI_COMMAND,
1605 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1606 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
1607 E1000_WRITE_FLUSH(hw);
1611 /* Setup the receive address. This involves initializing all of the Receive
1612 * Address Registers (RARs 0 - 15).
1614 e1000_init_rx_addrs(nic);
1616 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
1617 if (hw->mac_type == e1000_82542_rev2_0) {
1618 E1000_WRITE_REG(hw, RCTL, 0);
1619 E1000_WRITE_FLUSH(hw);
1621 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1624 /* Zero out the Multicast HASH table */
1625 DEBUGOUT("Zeroing the MTA\n");
1626 mta_size = E1000_MC_TBL_SIZE;
1627 if (hw->mac_type == e1000_ich8lan)
1628 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
1629 for (i = 0; i < mta_size; i++) {
1630 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
1631 /* use write flush to prevent Memory Write Block (MWB) from
1632 * occuring when accessing our register space */
1633 E1000_WRITE_FLUSH(hw);
1636 /* Set the PCI priority bit correctly in the CTRL register. This
1637 * determines if the adapter gives priority to receives, or if it
1638 * gives equal priority to transmits and receives. Valid only on
1639 * 82542 and 82543 silicon.
1641 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
1642 ctrl = E1000_READ_REG(hw, CTRL);
1643 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
1646 switch (hw->mac_type) {
1647 case e1000_82545_rev_3:
1648 case e1000_82546_rev_3:
1651 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
1652 if (hw->bus_type == e1000_bus_type_pcix) {
1653 pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
1655 pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI,
1656 &pcix_stat_hi_word);
1658 (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
1659 PCIX_COMMAND_MMRBC_SHIFT;
1661 (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
1662 PCIX_STATUS_HI_MMRBC_SHIFT;
1663 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
1664 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
1665 if (cmd_mmrbc > stat_mmrbc) {
1666 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
1667 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
1668 pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
1675 /* More time needed for PHY to initialize */
1676 if (hw->mac_type == e1000_ich8lan)
1679 /* Call a subroutine to configure the link and setup flow control. */
1680 ret_val = e1000_setup_link(nic);
1682 /* Set the transmit descriptor write-back policy */
1683 if (hw->mac_type > e1000_82544) {
1684 ctrl = E1000_READ_REG(hw, TXDCTL);
1686 (ctrl & ~E1000_TXDCTL_WTHRESH) |
1687 E1000_TXDCTL_FULL_TX_DESC_WB;
1688 E1000_WRITE_REG(hw, TXDCTL, ctrl);
1691 /* Set the receive descriptor write back policy */
1693 if (hw->mac_type >= e1000_82571) {
1694 ctrl = E1000_READ_REG(hw, RXDCTL);
1696 (ctrl & ~E1000_RXDCTL_WTHRESH) |
1697 E1000_RXDCTL_FULL_RX_DESC_WB;
1698 E1000_WRITE_REG(hw, RXDCTL, ctrl);
1701 switch (hw->mac_type) {
1704 case e1000_80003es2lan:
1705 /* Enable retransmit on late collisions */
1706 reg_data = E1000_READ_REG(hw, TCTL);
1707 reg_data |= E1000_TCTL_RTLC;
1708 E1000_WRITE_REG(hw, TCTL, reg_data);
1710 /* Configure Gigabit Carry Extend Padding */
1711 reg_data = E1000_READ_REG(hw, TCTL_EXT);
1712 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
1713 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
1714 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1716 /* Configure Transmit Inter-Packet Gap */
1717 reg_data = E1000_READ_REG(hw, TIPG);
1718 reg_data &= ~E1000_TIPG_IPGT_MASK;
1719 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1720 E1000_WRITE_REG(hw, TIPG, reg_data);
1722 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1723 reg_data &= ~0x00100000;
1724 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1729 ctrl = E1000_READ_REG(hw, TXDCTL1);
1730 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH)
1731 | E1000_TXDCTL_FULL_TX_DESC_WB;
1732 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1736 reg_data = E1000_READ_REG(hw, GCR);
1737 reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1738 E1000_WRITE_REG(hw, GCR, reg_data);
1742 /* Clear all of the statistics registers (clear on read). It is
1743 * important that we do this after we have tried to establish link
1744 * because the symbol error count will increment wildly if there
1747 e1000_clear_hw_cntrs(hw);
1749 /* ICH8 No-snoop bits are opposite polarity.
1750 * Set to snoop by default after reset. */
1751 if (hw->mac_type == e1000_ich8lan)
1752 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1755 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1756 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1757 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1758 /* Relaxed ordering must be disabled to avoid a parity
1759 * error crash in a PCI slot. */
1760 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1761 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1767 /******************************************************************************
1768 * Configures flow control and link settings.
1770 * hw - Struct containing variables accessed by shared code
1772 * Determines which flow control settings to use. Calls the apropriate media-
1773 * specific link configuration function. Configures the flow control settings.
1774 * Assuming the adapter has a valid link partner, a valid link should be
1775 * established. Assumes the hardware has previously been reset and the
1776 * transmitter and receiver are not enabled.
1777 *****************************************************************************/
1779 e1000_setup_link(struct eth_device *nic)
1781 struct e1000_hw *hw = nic->priv;
1784 uint16_t eeprom_data;
1788 /* In the case of the phy reset being blocked, we already have a link.
1789 * We do not have to set it up again. */
1790 if (e1000_check_phy_reset_block(hw))
1791 return E1000_SUCCESS;
1793 /* Read and store word 0x0F of the EEPROM. This word contains bits
1794 * that determine the hardware's default PAUSE (flow control) mode,
1795 * a bit that determines whether the HW defaults to enabling or
1796 * disabling auto-negotiation, and the direction of the
1797 * SW defined pins. If there is no SW over-ride of the flow
1798 * control setting, then the variable hw->fc will
1799 * be initialized based on a value in the EEPROM.
1801 if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1,
1802 &eeprom_data) < 0) {
1803 DEBUGOUT("EEPROM Read Error\n");
1804 return -E1000_ERR_EEPROM;
1807 if (hw->fc == e1000_fc_default) {
1808 switch (hw->mac_type) {
1812 hw->fc = e1000_fc_full;
1815 ret_val = e1000_read_eeprom(hw,
1816 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1818 DEBUGOUT("EEPROM Read Error\n");
1819 return -E1000_ERR_EEPROM;
1821 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1822 hw->fc = e1000_fc_none;
1823 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1824 EEPROM_WORD0F_ASM_DIR)
1825 hw->fc = e1000_fc_tx_pause;
1827 hw->fc = e1000_fc_full;
1832 /* We want to save off the original Flow Control configuration just
1833 * in case we get disconnected and then reconnected into a different
1834 * hub or switch with different Flow Control capabilities.
1836 if (hw->mac_type == e1000_82542_rev2_0)
1837 hw->fc &= (~e1000_fc_tx_pause);
1839 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
1840 hw->fc &= (~e1000_fc_rx_pause);
1842 hw->original_fc = hw->fc;
1844 DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc);
1846 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1847 * polarity value for the SW controlled pins, and setup the
1848 * Extended Device Control reg with that info.
1849 * This is needed because one of the SW controlled pins is used for
1850 * signal detection. So this should be done before e1000_setup_pcs_link()
1851 * or e1000_phy_setup() is called.
1853 if (hw->mac_type == e1000_82543) {
1854 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1856 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1859 /* Call the necessary subroutine to configure the link. */
1860 ret_val = (hw->media_type == e1000_media_type_fiber) ?
1861 e1000_setup_fiber_link(nic) : e1000_setup_copper_link(nic);
1866 /* Initialize the flow control address, type, and PAUSE timer
1867 * registers to their default values. This is done even if flow
1868 * control is disabled, because it does not hurt anything to
1869 * initialize these registers.
1871 DEBUGOUT("Initializing the Flow Control address, type"
1872 "and timer regs\n");
1874 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1875 if (hw->mac_type != e1000_ich8lan) {
1876 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1877 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1878 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1881 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1883 /* Set the flow control receive threshold registers. Normally,
1884 * these registers will be set to a default threshold that may be
1885 * adjusted later by the driver's runtime code. However, if the
1886 * ability to transmit pause frames in not enabled, then these
1887 * registers will be set to 0.
1889 if (!(hw->fc & e1000_fc_tx_pause)) {
1890 E1000_WRITE_REG(hw, FCRTL, 0);
1891 E1000_WRITE_REG(hw, FCRTH, 0);
1893 /* We need to set up the Receive Threshold high and low water marks
1894 * as well as (optionally) enabling the transmission of XON frames.
1896 if (hw->fc_send_xon) {
1897 E1000_WRITE_REG(hw, FCRTL,
1898 (hw->fc_low_water | E1000_FCRTL_XONE));
1899 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1901 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1902 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1908 /******************************************************************************
1909 * Sets up link for a fiber based adapter
1911 * hw - Struct containing variables accessed by shared code
1913 * Manipulates Physical Coding Sublayer functions in order to configure
1914 * link. Assumes the hardware has been previously reset and the transmitter
1915 * and receiver are not enabled.
1916 *****************************************************************************/
1918 e1000_setup_fiber_link(struct eth_device *nic)
1920 struct e1000_hw *hw = nic->priv;
1929 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
1930 * set when the optics detect a signal. On older adapters, it will be
1931 * cleared when there is a signal
1933 ctrl = E1000_READ_REG(hw, CTRL);
1934 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
1935 signal = E1000_CTRL_SWDPIN1;
1939 printf("signal for %s is %x (ctrl %08x)!!!!\n", nic->name, signal,
1941 /* Take the link out of reset */
1942 ctrl &= ~(E1000_CTRL_LRST);
1944 e1000_config_collision_dist(hw);
1946 /* Check for a software override of the flow control settings, and setup
1947 * the device accordingly. If auto-negotiation is enabled, then software
1948 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
1949 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
1950 * auto-negotiation is disabled, then software will have to manually
1951 * configure the two flow control enable bits in the CTRL register.
1953 * The possible values of the "fc" parameter are:
1954 * 0: Flow control is completely disabled
1955 * 1: Rx flow control is enabled (we can receive pause frames, but
1956 * not send pause frames).
1957 * 2: Tx flow control is enabled (we can send pause frames but we do
1958 * not support receiving pause frames).
1959 * 3: Both Rx and TX flow control (symmetric) are enabled.
1963 /* Flow control is completely disabled by a software over-ride. */
1964 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1966 case e1000_fc_rx_pause:
1967 /* RX Flow control is enabled and TX Flow control is disabled by a
1968 * software over-ride. Since there really isn't a way to advertise
1969 * that we are capable of RX Pause ONLY, we will advertise that we
1970 * support both symmetric and asymmetric RX PAUSE. Later, we will
1971 * disable the adapter's ability to send PAUSE frames.
1973 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1975 case e1000_fc_tx_pause:
1976 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1977 * software over-ride.
1979 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1982 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1983 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1986 DEBUGOUT("Flow control param set incorrectly\n");
1987 return -E1000_ERR_CONFIG;
1991 /* Since auto-negotiation is enabled, take the link out of reset (the link
1992 * will be in reset, because we previously reset the chip). This will
1993 * restart auto-negotiation. If auto-neogtiation is successful then the
1994 * link-up status bit will be set and the flow control enable bits (RFCE
1995 * and TFCE) will be set according to their negotiated value.
1997 DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw);
1999 E1000_WRITE_REG(hw, TXCW, txcw);
2000 E1000_WRITE_REG(hw, CTRL, ctrl);
2001 E1000_WRITE_FLUSH(hw);
2006 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
2007 * indication in the Device Status Register. Time-out if a link isn't
2008 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
2009 * less than 500 milliseconds even if the other end is doing it in SW).
2011 if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
2012 DEBUGOUT("Looking for Link\n");
2013 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
2015 status = E1000_READ_REG(hw, STATUS);
2016 if (status & E1000_STATUS_LU)
2019 if (i == (LINK_UP_TIMEOUT / 10)) {
2020 /* AutoNeg failed to achieve a link, so we'll call
2021 * e1000_check_for_link. This routine will force the link up if we
2022 * detect a signal. This will allow us to communicate with
2023 * non-autonegotiating link partners.
2025 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
2026 hw->autoneg_failed = 1;
2027 ret_val = e1000_check_for_link(nic);
2029 DEBUGOUT("Error while checking for link\n");
2032 hw->autoneg_failed = 0;
2034 hw->autoneg_failed = 0;
2035 DEBUGOUT("Valid Link Found\n");
2038 DEBUGOUT("No Signal Detected\n");
2039 return -E1000_ERR_NOLINK;
2044 /******************************************************************************
2045 * Make sure we have a valid PHY and change PHY mode before link setup.
2047 * hw - Struct containing variables accessed by shared code
2048 ******************************************************************************/
2050 e1000_copper_link_preconfig(struct e1000_hw *hw)
2058 ctrl = E1000_READ_REG(hw, CTRL);
2059 /* With 82543, we need to force speed and duplex on the MAC equal to what
2060 * the PHY speed and duplex configuration is. In addition, we need to
2061 * perform a hardware reset on the PHY to take it out of reset.
2063 if (hw->mac_type > e1000_82543) {
2064 ctrl |= E1000_CTRL_SLU;
2065 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2066 E1000_WRITE_REG(hw, CTRL, ctrl);
2068 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX
2070 E1000_WRITE_REG(hw, CTRL, ctrl);
2071 ret_val = e1000_phy_hw_reset(hw);
2076 /* Make sure we have a valid PHY */
2077 ret_val = e1000_detect_gig_phy(hw);
2079 DEBUGOUT("Error, did not detect valid phy.\n");
2082 DEBUGOUT("Phy ID = %x \n", hw->phy_id);
2084 /* Set PHY to class A mode (if necessary) */
2085 ret_val = e1000_set_phy_mode(hw);
2088 if ((hw->mac_type == e1000_82545_rev_3) ||
2089 (hw->mac_type == e1000_82546_rev_3)) {
2090 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2092 phy_data |= 0x00000008;
2093 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2097 if (hw->mac_type <= e1000_82543 ||
2098 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
2099 hw->mac_type == e1000_82541_rev_2
2100 || hw->mac_type == e1000_82547_rev_2)
2101 hw->phy_reset_disable = false;
2103 return E1000_SUCCESS;
2106 /*****************************************************************************
2108 * This function sets the lplu state according to the active flag. When
2109 * activating lplu this function also disables smart speed and vise versa.
2110 * lplu will not be activated unless the device autonegotiation advertisment
2111 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2112 * hw: Struct containing variables accessed by shared code
2113 * active - true to enable lplu false to disable lplu.
2115 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2116 * E1000_SUCCESS at any other case.
2118 ****************************************************************************/
2121 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
2123 uint32_t phy_ctrl = 0;
2128 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
2129 && hw->phy_type != e1000_phy_igp_3)
2130 return E1000_SUCCESS;
2132 /* During driver activity LPLU should not be used or it will attain link
2133 * from the lowest speeds starting from 10Mbps. The capability is used
2134 * for Dx transitions and states */
2135 if (hw->mac_type == e1000_82541_rev_2
2136 || hw->mac_type == e1000_82547_rev_2) {
2137 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
2141 } else if (hw->mac_type == e1000_ich8lan) {
2142 /* MAC writes into PHY register based on the state transition
2143 * and start auto-negotiation. SW driver can overwrite the
2144 * settings in CSR PHY power control E1000_PHY_CTRL register. */
2145 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
2147 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2154 if (hw->mac_type == e1000_82541_rev_2 ||
2155 hw->mac_type == e1000_82547_rev_2) {
2156 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
2157 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
2162 if (hw->mac_type == e1000_ich8lan) {
2163 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2164 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2166 phy_data &= ~IGP02E1000_PM_D3_LPLU;
2167 ret_val = e1000_write_phy_reg(hw,
2168 IGP02E1000_PHY_POWER_MGMT, phy_data);
2174 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2175 * Dx states where the power conservation is most important. During
2176 * driver activity we should enable SmartSpeed, so performance is
2178 if (hw->smart_speed == e1000_smart_speed_on) {
2179 ret_val = e1000_read_phy_reg(hw,
2180 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2184 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2185 ret_val = e1000_write_phy_reg(hw,
2186 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2189 } else if (hw->smart_speed == e1000_smart_speed_off) {
2190 ret_val = e1000_read_phy_reg(hw,
2191 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2195 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2196 ret_val = e1000_write_phy_reg(hw,
2197 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2202 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
2203 || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) ||
2204 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
2206 if (hw->mac_type == e1000_82541_rev_2 ||
2207 hw->mac_type == e1000_82547_rev_2) {
2208 phy_data |= IGP01E1000_GMII_FLEX_SPD;
2209 ret_val = e1000_write_phy_reg(hw,
2210 IGP01E1000_GMII_FIFO, phy_data);
2214 if (hw->mac_type == e1000_ich8lan) {
2215 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2216 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2218 phy_data |= IGP02E1000_PM_D3_LPLU;
2219 ret_val = e1000_write_phy_reg(hw,
2220 IGP02E1000_PHY_POWER_MGMT, phy_data);
2226 /* When LPLU is enabled we should disable SmartSpeed */
2227 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2232 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2233 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2238 return E1000_SUCCESS;
2241 /*****************************************************************************
2243 * This function sets the lplu d0 state according to the active flag. When
2244 * activating lplu this function also disables smart speed and vise versa.
2245 * lplu will not be activated unless the device autonegotiation advertisment
2246 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2247 * hw: Struct containing variables accessed by shared code
2248 * active - true to enable lplu false to disable lplu.
2250 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2251 * E1000_SUCCESS at any other case.
2253 ****************************************************************************/
2256 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
2258 uint32_t phy_ctrl = 0;
2263 if (hw->mac_type <= e1000_82547_rev_2)
2264 return E1000_SUCCESS;
2266 if (hw->mac_type == e1000_ich8lan) {
2267 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
2269 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2276 if (hw->mac_type == e1000_ich8lan) {
2277 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2278 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2280 phy_data &= ~IGP02E1000_PM_D0_LPLU;
2281 ret_val = e1000_write_phy_reg(hw,
2282 IGP02E1000_PHY_POWER_MGMT, phy_data);
2287 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2288 * Dx states where the power conservation is most important. During
2289 * driver activity we should enable SmartSpeed, so performance is
2291 if (hw->smart_speed == e1000_smart_speed_on) {
2292 ret_val = e1000_read_phy_reg(hw,
2293 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2297 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2298 ret_val = e1000_write_phy_reg(hw,
2299 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2302 } else if (hw->smart_speed == e1000_smart_speed_off) {
2303 ret_val = e1000_read_phy_reg(hw,
2304 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2308 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2309 ret_val = e1000_write_phy_reg(hw,
2310 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2318 if (hw->mac_type == e1000_ich8lan) {
2319 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2320 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2322 phy_data |= IGP02E1000_PM_D0_LPLU;
2323 ret_val = e1000_write_phy_reg(hw,
2324 IGP02E1000_PHY_POWER_MGMT, phy_data);
2329 /* When LPLU is enabled we should disable SmartSpeed */
2330 ret_val = e1000_read_phy_reg(hw,
2331 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2335 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2336 ret_val = e1000_write_phy_reg(hw,
2337 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2342 return E1000_SUCCESS;
2345 /********************************************************************
2346 * Copper link setup for e1000_phy_igp series.
2348 * hw - Struct containing variables accessed by shared code
2349 *********************************************************************/
2351 e1000_copper_link_igp_setup(struct e1000_hw *hw)
2359 if (hw->phy_reset_disable)
2360 return E1000_SUCCESS;
2362 ret_val = e1000_phy_reset(hw);
2364 DEBUGOUT("Error Resetting the PHY\n");
2368 /* Wait 15ms for MAC to configure PHY from eeprom settings */
2370 if (hw->mac_type != e1000_ich8lan) {
2371 /* Configure activity LED after PHY reset */
2372 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2373 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2374 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2375 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2378 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
2379 if (hw->phy_type == e1000_phy_igp) {
2380 /* disable lplu d3 during driver init */
2381 ret_val = e1000_set_d3_lplu_state(hw, false);
2383 DEBUGOUT("Error Disabling LPLU D3\n");
2388 /* disable lplu d0 during driver init */
2389 ret_val = e1000_set_d0_lplu_state(hw, false);
2391 DEBUGOUT("Error Disabling LPLU D0\n");
2394 /* Configure mdi-mdix settings */
2395 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2399 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2400 hw->dsp_config_state = e1000_dsp_config_disabled;
2401 /* Force MDI for earlier revs of the IGP PHY */
2402 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX
2403 | IGP01E1000_PSCR_FORCE_MDI_MDIX);
2407 hw->dsp_config_state = e1000_dsp_config_enabled;
2408 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2412 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2415 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
2419 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
2423 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2427 /* set auto-master slave resolution settings */
2429 e1000_ms_type phy_ms_setting = hw->master_slave;
2431 if (hw->ffe_config_state == e1000_ffe_config_active)
2432 hw->ffe_config_state = e1000_ffe_config_enabled;
2434 if (hw->dsp_config_state == e1000_dsp_config_activated)
2435 hw->dsp_config_state = e1000_dsp_config_enabled;
2437 /* when autonegotiation advertisment is only 1000Mbps then we
2438 * should disable SmartSpeed and enable Auto MasterSlave
2439 * resolution as hardware default. */
2440 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
2441 /* Disable SmartSpeed */
2442 ret_val = e1000_read_phy_reg(hw,
2443 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2446 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2447 ret_val = e1000_write_phy_reg(hw,
2448 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2451 /* Set auto Master/Slave resolution process */
2452 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
2456 phy_data &= ~CR_1000T_MS_ENABLE;
2457 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
2463 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
2467 /* load defaults for future use */
2468 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
2469 ((phy_data & CR_1000T_MS_VALUE) ?
2470 e1000_ms_force_master :
2471 e1000_ms_force_slave) :
2474 switch (phy_ms_setting) {
2475 case e1000_ms_force_master:
2476 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
2478 case e1000_ms_force_slave:
2479 phy_data |= CR_1000T_MS_ENABLE;
2480 phy_data &= ~(CR_1000T_MS_VALUE);
2483 phy_data &= ~CR_1000T_MS_ENABLE;
2487 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
2492 return E1000_SUCCESS;
2495 /*****************************************************************************
2496 * This function checks the mode of the firmware.
2498 * returns - true when the mode is IAMT or false.
2499 ****************************************************************************/
2501 e1000_check_mng_mode(struct e1000_hw *hw)
2506 fwsm = E1000_READ_REG(hw, FWSM);
2508 if (hw->mac_type == e1000_ich8lan) {
2509 if ((fwsm & E1000_FWSM_MODE_MASK) ==
2510 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
2512 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
2513 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
2520 e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data)
2522 uint16_t swfw = E1000_SWFW_PHY0_SM;
2526 if (e1000_is_second_port(hw))
2527 swfw = E1000_SWFW_PHY1_SM;
2529 if (e1000_swfw_sync_acquire(hw, swfw))
2530 return -E1000_ERR_SWFW_SYNC;
2532 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT)
2533 & E1000_KUMCTRLSTA_OFFSET) | data;
2534 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2537 return E1000_SUCCESS;
2541 e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data)
2543 uint16_t swfw = E1000_SWFW_PHY0_SM;
2547 if (e1000_is_second_port(hw))
2548 swfw = E1000_SWFW_PHY1_SM;
2550 if (e1000_swfw_sync_acquire(hw, swfw))
2551 return -E1000_ERR_SWFW_SYNC;
2553 /* Write register address */
2554 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
2555 E1000_KUMCTRLSTA_OFFSET) | E1000_KUMCTRLSTA_REN;
2556 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2559 /* Read the data returned */
2560 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
2561 *data = (uint16_t)reg_val;
2563 return E1000_SUCCESS;
2566 /********************************************************************
2567 * Copper link setup for e1000_phy_gg82563 series.
2569 * hw - Struct containing variables accessed by shared code
2570 *********************************************************************/
2572 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
2580 if (!hw->phy_reset_disable) {
2581 /* Enable CRS on TX for half-duplex operation. */
2582 ret_val = e1000_read_phy_reg(hw,
2583 GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2587 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2588 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
2589 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
2591 ret_val = e1000_write_phy_reg(hw,
2592 GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2597 * MDI/MDI-X = 0 (default)
2598 * 0 - Auto for all speeds
2601 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
2603 ret_val = e1000_read_phy_reg(hw,
2604 GG82563_PHY_SPEC_CTRL, &phy_data);
2608 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
2612 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
2615 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
2619 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
2624 * disable_polarity_correction = 0 (default)
2625 * Automatic Correction for Reversed Cable Polarity
2629 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
2630 ret_val = e1000_write_phy_reg(hw,
2631 GG82563_PHY_SPEC_CTRL, phy_data);
2636 /* SW Reset the PHY so all changes take effect */
2637 ret_val = e1000_phy_reset(hw);
2639 DEBUGOUT("Error Resetting the PHY\n");
2642 } /* phy_reset_disable */
2644 if (hw->mac_type == e1000_80003es2lan) {
2645 /* Bypass RX and TX FIFO's */
2646 ret_val = e1000_write_kmrn_reg(hw,
2647 E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
2648 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS
2649 | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
2653 ret_val = e1000_read_phy_reg(hw,
2654 GG82563_PHY_SPEC_CTRL_2, &phy_data);
2658 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
2659 ret_val = e1000_write_phy_reg(hw,
2660 GG82563_PHY_SPEC_CTRL_2, phy_data);
2665 reg_data = E1000_READ_REG(hw, CTRL_EXT);
2666 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
2667 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
2669 ret_val = e1000_read_phy_reg(hw,
2670 GG82563_PHY_PWR_MGMT_CTRL, &phy_data);
2674 /* Do not init these registers when the HW is in IAMT mode, since the
2675 * firmware will have already initialized them. We only initialize
2676 * them if the HW is not in IAMT mode.
2678 if (e1000_check_mng_mode(hw) == false) {
2679 /* Enable Electrical Idle on the PHY */
2680 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
2681 ret_val = e1000_write_phy_reg(hw,
2682 GG82563_PHY_PWR_MGMT_CTRL, phy_data);
2686 ret_val = e1000_read_phy_reg(hw,
2687 GG82563_PHY_KMRN_MODE_CTRL, &phy_data);
2691 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2692 ret_val = e1000_write_phy_reg(hw,
2693 GG82563_PHY_KMRN_MODE_CTRL, phy_data);
2699 /* Workaround: Disable padding in Kumeran interface in the MAC
2700 * and in the PHY to avoid CRC errors.
2702 ret_val = e1000_read_phy_reg(hw,
2703 GG82563_PHY_INBAND_CTRL, &phy_data);
2706 phy_data |= GG82563_ICR_DIS_PADDING;
2707 ret_val = e1000_write_phy_reg(hw,
2708 GG82563_PHY_INBAND_CTRL, phy_data);
2712 return E1000_SUCCESS;
2715 /********************************************************************
2716 * Copper link setup for e1000_phy_m88 series.
2718 * hw - Struct containing variables accessed by shared code
2719 *********************************************************************/
2721 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
2728 if (hw->phy_reset_disable)
2729 return E1000_SUCCESS;
2731 /* Enable CRS on TX. This must be set for half-duplex operation. */
2732 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2736 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2739 * MDI/MDI-X = 0 (default)
2740 * 0 - Auto for all speeds
2743 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
2745 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2749 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
2752 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
2755 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
2759 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
2764 * disable_polarity_correction = 0 (default)
2765 * Automatic Correction for Reversed Cable Polarity
2769 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
2770 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2774 if (hw->phy_revision < M88E1011_I_REV_4) {
2775 /* Force TX_CLK in the Extended PHY Specific Control Register
2778 ret_val = e1000_read_phy_reg(hw,
2779 M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2783 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2785 if ((hw->phy_revision == E1000_REVISION_2) &&
2786 (hw->phy_id == M88E1111_I_PHY_ID)) {
2787 /* Vidalia Phy, set the downshift counter to 5x */
2788 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
2789 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
2790 ret_val = e1000_write_phy_reg(hw,
2791 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2795 /* Configure Master and Slave downshift values */
2796 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK
2797 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
2798 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X
2799 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
2800 ret_val = e1000_write_phy_reg(hw,
2801 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2807 /* SW Reset the PHY so all changes take effect */
2808 ret_val = e1000_phy_reset(hw);
2810 DEBUGOUT("Error Resetting the PHY\n");
2814 return E1000_SUCCESS;
2817 /********************************************************************
2818 * Setup auto-negotiation and flow control advertisements,
2819 * and then perform auto-negotiation.
2821 * hw - Struct containing variables accessed by shared code
2822 *********************************************************************/
2824 e1000_copper_link_autoneg(struct e1000_hw *hw)
2831 /* Perform some bounds checking on the hw->autoneg_advertised
2832 * parameter. If this variable is zero, then set it to the default.
2834 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
2836 /* If autoneg_advertised is zero, we assume it was not defaulted
2837 * by the calling code so we set to advertise full capability.
2839 if (hw->autoneg_advertised == 0)
2840 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
2842 /* IFE phy only supports 10/100 */
2843 if (hw->phy_type == e1000_phy_ife)
2844 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
2846 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
2847 ret_val = e1000_phy_setup_autoneg(hw);
2849 DEBUGOUT("Error Setting up Auto-Negotiation\n");
2852 DEBUGOUT("Restarting Auto-Neg\n");
2854 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
2855 * the Auto Neg Restart bit in the PHY control register.
2857 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2861 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
2862 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
2866 /* Does the user want to wait for Auto-Neg to complete here, or
2867 * check at a later time (for example, callback routine).
2869 /* If we do not wait for autonegtation to complete I
2870 * do not see a valid link status.
2871 * wait_autoneg_complete = 1 .
2873 if (hw->wait_autoneg_complete) {
2874 ret_val = e1000_wait_autoneg(hw);
2876 DEBUGOUT("Error while waiting for autoneg"
2882 hw->get_link_status = true;
2884 return E1000_SUCCESS;
2887 /******************************************************************************
2888 * Config the MAC and the PHY after link is up.
2889 * 1) Set up the MAC to the current PHY speed/duplex
2890 * if we are on 82543. If we
2891 * are on newer silicon, we only need to configure
2892 * collision distance in the Transmit Control Register.
2893 * 2) Set up flow control on the MAC to that established with
2895 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
2897 * hw - Struct containing variables accessed by shared code
2898 ******************************************************************************/
2900 e1000_copper_link_postconfig(struct e1000_hw *hw)
2905 if (hw->mac_type >= e1000_82544) {
2906 e1000_config_collision_dist(hw);
2908 ret_val = e1000_config_mac_to_phy(hw);
2910 DEBUGOUT("Error configuring MAC to PHY settings\n");
2914 ret_val = e1000_config_fc_after_link_up(hw);
2916 DEBUGOUT("Error Configuring Flow Control\n");
2919 return E1000_SUCCESS;
2922 /******************************************************************************
2923 * Detects which PHY is present and setup the speed and duplex
2925 * hw - Struct containing variables accessed by shared code
2926 ******************************************************************************/
2928 e1000_setup_copper_link(struct eth_device *nic)
2930 struct e1000_hw *hw = nic->priv;
2938 switch (hw->mac_type) {
2939 case e1000_80003es2lan:
2941 /* Set the mac to wait the maximum time between each
2942 * iteration and increase the max iterations when
2943 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
2944 ret_val = e1000_write_kmrn_reg(hw,
2945 GG82563_REG(0x34, 4), 0xFFFF);
2948 ret_val = e1000_read_kmrn_reg(hw,
2949 GG82563_REG(0x34, 9), ®_data);
2953 ret_val = e1000_write_kmrn_reg(hw,
2954 GG82563_REG(0x34, 9), reg_data);
2961 /* Check if it is a valid PHY and set PHY mode if necessary. */
2962 ret_val = e1000_copper_link_preconfig(hw);
2965 switch (hw->mac_type) {
2966 case e1000_80003es2lan:
2967 /* Kumeran registers are written-only */
2969 E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
2970 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
2971 ret_val = e1000_write_kmrn_reg(hw,
2972 E1000_KUMCTRLSTA_OFFSET_INB_CTRL, reg_data);
2980 if (hw->phy_type == e1000_phy_igp ||
2981 hw->phy_type == e1000_phy_igp_3 ||
2982 hw->phy_type == e1000_phy_igp_2) {
2983 ret_val = e1000_copper_link_igp_setup(hw);
2986 } else if (hw->phy_type == e1000_phy_m88) {
2987 ret_val = e1000_copper_link_mgp_setup(hw);
2990 } else if (hw->phy_type == e1000_phy_gg82563) {
2991 ret_val = e1000_copper_link_ggp_setup(hw);
2997 /* Setup autoneg and flow control advertisement
2998 * and perform autonegotiation */
2999 ret_val = e1000_copper_link_autoneg(hw);
3003 /* Check link status. Wait up to 100 microseconds for link to become
3006 for (i = 0; i < 10; i++) {
3007 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3010 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3014 if (phy_data & MII_SR_LINK_STATUS) {
3015 /* Config the MAC and PHY after link is up */
3016 ret_val = e1000_copper_link_postconfig(hw);
3020 DEBUGOUT("Valid link established!!!\n");
3021 return E1000_SUCCESS;
3026 DEBUGOUT("Unable to establish link!!!\n");
3027 return E1000_SUCCESS;
3030 /******************************************************************************
3031 * Configures PHY autoneg and flow control advertisement settings
3033 * hw - Struct containing variables accessed by shared code
3034 ******************************************************************************/
3036 e1000_phy_setup_autoneg(struct e1000_hw *hw)
3039 uint16_t mii_autoneg_adv_reg;
3040 uint16_t mii_1000t_ctrl_reg;
3044 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
3045 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
3049 if (hw->phy_type != e1000_phy_ife) {
3050 /* Read the MII 1000Base-T Control Register (Address 9). */
3051 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
3052 &mii_1000t_ctrl_reg);
3056 mii_1000t_ctrl_reg = 0;
3058 /* Need to parse both autoneg_advertised and fc and set up
3059 * the appropriate PHY registers. First we will parse for
3060 * autoneg_advertised software override. Since we can advertise
3061 * a plethora of combinations, we need to check each bit
3065 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
3066 * Advertisement Register (Address 4) and the 1000 mb speed bits in
3067 * the 1000Base-T Control Register (Address 9).
3069 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
3070 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
3072 DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised);
3074 /* Do we want to advertise 10 Mb Half Duplex? */
3075 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
3076 DEBUGOUT("Advertise 10mb Half duplex\n");
3077 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
3080 /* Do we want to advertise 10 Mb Full Duplex? */
3081 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
3082 DEBUGOUT("Advertise 10mb Full duplex\n");
3083 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
3086 /* Do we want to advertise 100 Mb Half Duplex? */
3087 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
3088 DEBUGOUT("Advertise 100mb Half duplex\n");
3089 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
3092 /* Do we want to advertise 100 Mb Full Duplex? */
3093 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
3094 DEBUGOUT("Advertise 100mb Full duplex\n");
3095 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
3098 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
3099 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
3101 ("Advertise 1000mb Half duplex requested, request denied!\n");
3104 /* Do we want to advertise 1000 Mb Full Duplex? */
3105 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
3106 DEBUGOUT("Advertise 1000mb Full duplex\n");
3107 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
3110 /* Check for a software override of the flow control settings, and
3111 * setup the PHY advertisement registers accordingly. If
3112 * auto-negotiation is enabled, then software will have to set the
3113 * "PAUSE" bits to the correct value in the Auto-Negotiation
3114 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
3116 * The possible values of the "fc" parameter are:
3117 * 0: Flow control is completely disabled
3118 * 1: Rx flow control is enabled (we can receive pause frames
3119 * but not send pause frames).
3120 * 2: Tx flow control is enabled (we can send pause frames
3121 * but we do not support receiving pause frames).
3122 * 3: Both Rx and TX flow control (symmetric) are enabled.
3123 * other: No software override. The flow control configuration
3124 * in the EEPROM is used.
3127 case e1000_fc_none: /* 0 */
3128 /* Flow control (RX & TX) is completely disabled by a
3129 * software over-ride.
3131 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3133 case e1000_fc_rx_pause: /* 1 */
3134 /* RX Flow control is enabled, and TX Flow control is
3135 * disabled, by a software over-ride.
3137 /* Since there really isn't a way to advertise that we are
3138 * capable of RX Pause ONLY, we will advertise that we
3139 * support both symmetric and asymmetric RX PAUSE. Later
3140 * (in e1000_config_fc_after_link_up) we will disable the
3141 *hw's ability to send PAUSE frames.
3143 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3145 case e1000_fc_tx_pause: /* 2 */
3146 /* TX Flow control is enabled, and RX Flow control is
3147 * disabled, by a software over-ride.
3149 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
3150 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
3152 case e1000_fc_full: /* 3 */
3153 /* Flow control (both RX and TX) is enabled by a software
3156 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3159 DEBUGOUT("Flow control param set incorrectly\n");
3160 return -E1000_ERR_CONFIG;
3163 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
3167 DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
3169 if (hw->phy_type != e1000_phy_ife) {
3170 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
3171 mii_1000t_ctrl_reg);
3176 return E1000_SUCCESS;
3179 /******************************************************************************
3180 * Sets the collision distance in the Transmit Control register
3182 * hw - Struct containing variables accessed by shared code
3184 * Link should have been established previously. Reads the speed and duplex
3185 * information from the Device Status register.
3186 ******************************************************************************/
3188 e1000_config_collision_dist(struct e1000_hw *hw)
3190 uint32_t tctl, coll_dist;
3194 if (hw->mac_type < e1000_82543)
3195 coll_dist = E1000_COLLISION_DISTANCE_82542;
3197 coll_dist = E1000_COLLISION_DISTANCE;
3199 tctl = E1000_READ_REG(hw, TCTL);
3201 tctl &= ~E1000_TCTL_COLD;
3202 tctl |= coll_dist << E1000_COLD_SHIFT;
3204 E1000_WRITE_REG(hw, TCTL, tctl);
3205 E1000_WRITE_FLUSH(hw);
3208 /******************************************************************************
3209 * Sets MAC speed and duplex settings to reflect the those in the PHY
3211 * hw - Struct containing variables accessed by shared code
3212 * mii_reg - data to write to the MII control register
3214 * The contents of the PHY register containing the needed information need to
3216 ******************************************************************************/
3218 e1000_config_mac_to_phy(struct e1000_hw *hw)
3225 /* Read the Device Control Register and set the bits to Force Speed
3228 ctrl = E1000_READ_REG(hw, CTRL);
3229 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3230 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
3232 /* Set up duplex in the Device Control and Transmit Control
3233 * registers depending on negotiated values.
3235 if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
3236 DEBUGOUT("PHY Read Error\n");
3237 return -E1000_ERR_PHY;
3239 if (phy_data & M88E1000_PSSR_DPLX)
3240 ctrl |= E1000_CTRL_FD;
3242 ctrl &= ~E1000_CTRL_FD;
3244 e1000_config_collision_dist(hw);
3246 /* Set up speed in the Device Control register depending on
3247 * negotiated values.
3249 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
3250 ctrl |= E1000_CTRL_SPD_1000;
3251 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
3252 ctrl |= E1000_CTRL_SPD_100;
3253 /* Write the configured values back to the Device Control Reg. */
3254 E1000_WRITE_REG(hw, CTRL, ctrl);
3258 /******************************************************************************
3259 * Forces the MAC's flow control settings.
3261 * hw - Struct containing variables accessed by shared code
3263 * Sets the TFCE and RFCE bits in the device control register to reflect
3264 * the adapter settings. TFCE and RFCE need to be explicitly set by
3265 * software when a Copper PHY is used because autonegotiation is managed
3266 * by the PHY rather than the MAC. Software must also configure these
3267 * bits when link is forced on a fiber connection.
3268 *****************************************************************************/
3270 e1000_force_mac_fc(struct e1000_hw *hw)
3276 /* Get the current configuration of the Device Control Register */
3277 ctrl = E1000_READ_REG(hw, CTRL);
3279 /* Because we didn't get link via the internal auto-negotiation
3280 * mechanism (we either forced link or we got link via PHY
3281 * auto-neg), we have to manually enable/disable transmit an
3282 * receive flow control.
3284 * The "Case" statement below enables/disable flow control
3285 * according to the "hw->fc" parameter.
3287 * The possible values of the "fc" parameter are:
3288 * 0: Flow control is completely disabled
3289 * 1: Rx flow control is enabled (we can receive pause
3290 * frames but not send pause frames).
3291 * 2: Tx flow control is enabled (we can send pause frames
3292 * frames but we do not receive pause frames).
3293 * 3: Both Rx and TX flow control (symmetric) is enabled.
3294 * other: No other values should be possible at this point.
3299 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
3301 case e1000_fc_rx_pause:
3302 ctrl &= (~E1000_CTRL_TFCE);
3303 ctrl |= E1000_CTRL_RFCE;
3305 case e1000_fc_tx_pause:
3306 ctrl &= (~E1000_CTRL_RFCE);
3307 ctrl |= E1000_CTRL_TFCE;
3310 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
3313 DEBUGOUT("Flow control param set incorrectly\n");
3314 return -E1000_ERR_CONFIG;
3317 /* Disable TX Flow Control for 82542 (rev 2.0) */
3318 if (hw->mac_type == e1000_82542_rev2_0)
3319 ctrl &= (~E1000_CTRL_TFCE);
3321 E1000_WRITE_REG(hw, CTRL, ctrl);
3325 /******************************************************************************
3326 * Configures flow control settings after link is established
3328 * hw - Struct containing variables accessed by shared code
3330 * Should be called immediately after a valid link has been established.
3331 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
3332 * and autonegotiation is enabled, the MAC flow control settings will be set
3333 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
3334 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
3335 *****************************************************************************/
3337 e1000_config_fc_after_link_up(struct e1000_hw *hw)
3340 uint16_t mii_status_reg;
3341 uint16_t mii_nway_adv_reg;
3342 uint16_t mii_nway_lp_ability_reg;
3348 /* Check for the case where we have fiber media and auto-neg failed
3349 * so we had to force link. In this case, we need to force the
3350 * configuration of the MAC to match the "fc" parameter.
3352 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
3353 || ((hw->media_type == e1000_media_type_internal_serdes)
3354 && (hw->autoneg_failed))
3355 || ((hw->media_type == e1000_media_type_copper)
3356 && (!hw->autoneg))) {
3357 ret_val = e1000_force_mac_fc(hw);
3359 DEBUGOUT("Error forcing flow control settings\n");
3364 /* Check for the case where we have copper media and auto-neg is
3365 * enabled. In this case, we need to check and see if Auto-Neg
3366 * has completed, and if so, how the PHY and link partner has
3367 * flow control configured.
3369 if (hw->media_type == e1000_media_type_copper) {
3370 /* Read the MII Status Register and check to see if AutoNeg
3371 * has completed. We read this twice because this reg has
3372 * some "sticky" (latched) bits.
3374 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3375 DEBUGOUT("PHY Read Error \n");
3376 return -E1000_ERR_PHY;
3378 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3379 DEBUGOUT("PHY Read Error \n");
3380 return -E1000_ERR_PHY;
3383 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
3384 /* The AutoNeg process has completed, so we now need to
3385 * read both the Auto Negotiation Advertisement Register
3386 * (Address 4) and the Auto_Negotiation Base Page Ability
3387 * Register (Address 5) to determine how flow control was
3390 if (e1000_read_phy_reg
3391 (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
3392 DEBUGOUT("PHY Read Error\n");
3393 return -E1000_ERR_PHY;
3395 if (e1000_read_phy_reg
3396 (hw, PHY_LP_ABILITY,
3397 &mii_nway_lp_ability_reg) < 0) {
3398 DEBUGOUT("PHY Read Error\n");
3399 return -E1000_ERR_PHY;
3402 /* Two bits in the Auto Negotiation Advertisement Register
3403 * (Address 4) and two bits in the Auto Negotiation Base
3404 * Page Ability Register (Address 5) determine flow control
3405 * for both the PHY and the link partner. The following
3406 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
3407 * 1999, describes these PAUSE resolution bits and how flow
3408 * control is determined based upon these settings.
3409 * NOTE: DC = Don't Care
3411 * LOCAL DEVICE | LINK PARTNER
3412 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
3413 *-------|---------|-------|---------|--------------------
3414 * 0 | 0 | DC | DC | e1000_fc_none
3415 * 0 | 1 | 0 | DC | e1000_fc_none
3416 * 0 | 1 | 1 | 0 | e1000_fc_none
3417 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
3418 * 1 | 0 | 0 | DC | e1000_fc_none
3419 * 1 | DC | 1 | DC | e1000_fc_full
3420 * 1 | 1 | 0 | 0 | e1000_fc_none
3421 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
3424 /* Are both PAUSE bits set to 1? If so, this implies
3425 * Symmetric Flow Control is enabled at both ends. The
3426 * ASM_DIR bits are irrelevant per the spec.
3428 * For Symmetric Flow Control:
3430 * LOCAL DEVICE | LINK PARTNER
3431 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3432 *-------|---------|-------|---------|--------------------
3433 * 1 | DC | 1 | DC | e1000_fc_full
3436 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3437 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
3438 /* Now we need to check if the user selected RX ONLY
3439 * of pause frames. In this case, we had to advertise
3440 * FULL flow control because we could not advertise RX
3441 * ONLY. Hence, we must now check to see if we need to
3442 * turn OFF the TRANSMISSION of PAUSE frames.
3444 if (hw->original_fc == e1000_fc_full) {
3445 hw->fc = e1000_fc_full;
3446 DEBUGOUT("Flow Control = FULL.\r\n");
3448 hw->fc = e1000_fc_rx_pause;
3450 ("Flow Control = RX PAUSE frames only.\r\n");
3453 /* For receiving PAUSE frames ONLY.
3455 * LOCAL DEVICE | LINK PARTNER
3456 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3457 *-------|---------|-------|---------|--------------------
3458 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
3461 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3462 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3463 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3464 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3466 hw->fc = e1000_fc_tx_pause;
3468 ("Flow Control = TX PAUSE frames only.\r\n");
3470 /* For transmitting PAUSE frames ONLY.
3472 * LOCAL DEVICE | LINK PARTNER
3473 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3474 *-------|---------|-------|---------|--------------------
3475 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
3478 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3479 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3480 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3481 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3483 hw->fc = e1000_fc_rx_pause;
3485 ("Flow Control = RX PAUSE frames only.\r\n");
3487 /* Per the IEEE spec, at this point flow control should be
3488 * disabled. However, we want to consider that we could
3489 * be connected to a legacy switch that doesn't advertise
3490 * desired flow control, but can be forced on the link
3491 * partner. So if we advertised no flow control, that is
3492 * what we will resolve to. If we advertised some kind of
3493 * receive capability (Rx Pause Only or Full Flow Control)
3494 * and the link partner advertised none, we will configure
3495 * ourselves to enable Rx Flow Control only. We can do
3496 * this safely for two reasons: If the link partner really
3497 * didn't want flow control enabled, and we enable Rx, no
3498 * harm done since we won't be receiving any PAUSE frames
3499 * anyway. If the intent on the link partner was to have
3500 * flow control enabled, then by us enabling RX only, we
3501 * can at least receive pause frames and process them.
3502 * This is a good idea because in most cases, since we are
3503 * predominantly a server NIC, more times than not we will
3504 * be asked to delay transmission of packets than asking
3505 * our link partner to pause transmission of frames.
3507 else if (hw->original_fc == e1000_fc_none ||
3508 hw->original_fc == e1000_fc_tx_pause) {
3509 hw->fc = e1000_fc_none;
3510 DEBUGOUT("Flow Control = NONE.\r\n");
3512 hw->fc = e1000_fc_rx_pause;
3514 ("Flow Control = RX PAUSE frames only.\r\n");
3517 /* Now we need to do one last check... If we auto-
3518 * negotiated to HALF DUPLEX, flow control should not be
3519 * enabled per IEEE 802.3 spec.
3521 e1000_get_speed_and_duplex(hw, &speed, &duplex);
3523 if (duplex == HALF_DUPLEX)
3524 hw->fc = e1000_fc_none;
3526 /* Now we call a subroutine to actually force the MAC
3527 * controller to use the correct flow control settings.
3529 ret_val = e1000_force_mac_fc(hw);
3532 ("Error forcing flow control settings\n");
3537 ("Copper PHY and Auto Neg has not completed.\r\n");
3540 return E1000_SUCCESS;
3543 /******************************************************************************
3544 * Checks to see if the link status of the hardware has changed.
3546 * hw - Struct containing variables accessed by shared code
3548 * Called by any function that needs to check the link status of the adapter.
3549 *****************************************************************************/
3551 e1000_check_for_link(struct eth_device *nic)
3553 struct e1000_hw *hw = nic->priv;
3561 uint16_t lp_capability;
3565 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
3566 * set when the optics detect a signal. On older adapters, it will be
3567 * cleared when there is a signal
3569 ctrl = E1000_READ_REG(hw, CTRL);
3570 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
3571 signal = E1000_CTRL_SWDPIN1;
3575 status = E1000_READ_REG(hw, STATUS);
3576 rxcw = E1000_READ_REG(hw, RXCW);
3577 DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw);
3579 /* If we have a copper PHY then we only want to go out to the PHY
3580 * registers to see if Auto-Neg has completed and/or if our link
3581 * status has changed. The get_link_status flag will be set if we
3582 * receive a Link Status Change interrupt or we have Rx Sequence
3585 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
3586 /* First we want to see if the MII Status Register reports
3587 * link. If so, then we want to get the current speed/duplex
3589 * Read the register twice since the link bit is sticky.
3591 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3592 DEBUGOUT("PHY Read Error\n");
3593 return -E1000_ERR_PHY;
3595 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3596 DEBUGOUT("PHY Read Error\n");
3597 return -E1000_ERR_PHY;
3600 if (phy_data & MII_SR_LINK_STATUS) {
3601 hw->get_link_status = false;
3603 /* No link detected */
3604 return -E1000_ERR_NOLINK;
3607 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
3608 * have Si on board that is 82544 or newer, Auto
3609 * Speed Detection takes care of MAC speed/duplex
3610 * configuration. So we only need to configure Collision
3611 * Distance in the MAC. Otherwise, we need to force
3612 * speed/duplex on the MAC to the current PHY speed/duplex
3615 if (hw->mac_type >= e1000_82544)
3616 e1000_config_collision_dist(hw);
3618 ret_val = e1000_config_mac_to_phy(hw);
3621 ("Error configuring MAC to PHY settings\n");
3626 /* Configure Flow Control now that Auto-Neg has completed. First, we
3627 * need to restore the desired flow control settings because we may
3628 * have had to re-autoneg with a different link partner.
3630 ret_val = e1000_config_fc_after_link_up(hw);
3632 DEBUGOUT("Error configuring flow control\n");
3636 /* At this point we know that we are on copper and we have
3637 * auto-negotiated link. These are conditions for checking the link
3638 * parter capability register. We use the link partner capability to
3639 * determine if TBI Compatibility needs to be turned on or off. If
3640 * the link partner advertises any speed in addition to Gigabit, then
3641 * we assume that they are GMII-based, and TBI compatibility is not
3642 * needed. If no other speeds are advertised, we assume the link
3643 * partner is TBI-based, and we turn on TBI Compatibility.
3645 if (hw->tbi_compatibility_en) {
3646 if (e1000_read_phy_reg
3647 (hw, PHY_LP_ABILITY, &lp_capability) < 0) {
3648 DEBUGOUT("PHY Read Error\n");
3649 return -E1000_ERR_PHY;
3651 if (lp_capability & (NWAY_LPAR_10T_HD_CAPS |
3652 NWAY_LPAR_10T_FD_CAPS |
3653 NWAY_LPAR_100TX_HD_CAPS |
3654 NWAY_LPAR_100TX_FD_CAPS |
3655 NWAY_LPAR_100T4_CAPS)) {
3656 /* If our link partner advertises anything in addition to
3657 * gigabit, we do not need to enable TBI compatibility.
3659 if (hw->tbi_compatibility_on) {
3660 /* If we previously were in the mode, turn it off. */
3661 rctl = E1000_READ_REG(hw, RCTL);
3662 rctl &= ~E1000_RCTL_SBP;
3663 E1000_WRITE_REG(hw, RCTL, rctl);
3664 hw->tbi_compatibility_on = false;
3667 /* If TBI compatibility is was previously off, turn it on. For
3668 * compatibility with a TBI link partner, we will store bad
3669 * packets. Some frames have an additional byte on the end and
3670 * will look like CRC errors to to the hardware.
3672 if (!hw->tbi_compatibility_on) {
3673 hw->tbi_compatibility_on = true;
3674 rctl = E1000_READ_REG(hw, RCTL);
3675 rctl |= E1000_RCTL_SBP;
3676 E1000_WRITE_REG(hw, RCTL, rctl);
3681 /* If we don't have link (auto-negotiation failed or link partner cannot
3682 * auto-negotiate), the cable is plugged in (we have signal), and our
3683 * link partner is not trying to auto-negotiate with us (we are receiving
3684 * idles or data), we need to force link up. We also need to give
3685 * auto-negotiation time to complete, in case the cable was just plugged
3686 * in. The autoneg_failed flag does this.
3688 else if ((hw->media_type == e1000_media_type_fiber) &&
3689 (!(status & E1000_STATUS_LU)) &&
3690 ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
3691 (!(rxcw & E1000_RXCW_C))) {
3692 if (hw->autoneg_failed == 0) {
3693 hw->autoneg_failed = 1;
3696 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
3698 /* Disable auto-negotiation in the TXCW register */
3699 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3701 /* Force link-up and also force full-duplex. */
3702 ctrl = E1000_READ_REG(hw, CTRL);
3703 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3704 E1000_WRITE_REG(hw, CTRL, ctrl);
3706 /* Configure Flow Control after forcing link up. */
3707 ret_val = e1000_config_fc_after_link_up(hw);
3709 DEBUGOUT("Error configuring flow control\n");
3713 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3714 * auto-negotiation in the TXCW register and disable forced link in the
3715 * Device Control register in an attempt to auto-negotiate with our link
3718 else if ((hw->media_type == e1000_media_type_fiber) &&
3719 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
3721 ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
3722 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3723 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3728 /******************************************************************************
3729 * Configure the MAC-to-PHY interface for 10/100Mbps
3731 * hw - Struct containing variables accessed by shared code
3732 ******************************************************************************/
3734 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
3736 int32_t ret_val = E1000_SUCCESS;
3742 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
3743 ret_val = e1000_write_kmrn_reg(hw,
3744 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
3748 /* Configure Transmit Inter-Packet Gap */
3749 tipg = E1000_READ_REG(hw, TIPG);
3750 tipg &= ~E1000_TIPG_IPGT_MASK;
3751 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
3752 E1000_WRITE_REG(hw, TIPG, tipg);
3754 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
3759 if (duplex == HALF_DUPLEX)
3760 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
3762 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
3764 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
3770 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
3772 int32_t ret_val = E1000_SUCCESS;
3778 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
3779 ret_val = e1000_write_kmrn_reg(hw,
3780 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
3784 /* Configure Transmit Inter-Packet Gap */
3785 tipg = E1000_READ_REG(hw, TIPG);
3786 tipg &= ~E1000_TIPG_IPGT_MASK;
3787 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
3788 E1000_WRITE_REG(hw, TIPG, tipg);
3790 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
3795 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
3796 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
3801 /******************************************************************************
3802 * Detects the current speed and duplex settings of the hardware.
3804 * hw - Struct containing variables accessed by shared code
3805 * speed - Speed of the connection
3806 * duplex - Duplex setting of the connection
3807 *****************************************************************************/
3809 e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed,
3818 if (hw->mac_type >= e1000_82543) {
3819 status = E1000_READ_REG(hw, STATUS);
3820 if (status & E1000_STATUS_SPEED_1000) {
3821 *speed = SPEED_1000;
3822 DEBUGOUT("1000 Mbs, ");
3823 } else if (status & E1000_STATUS_SPEED_100) {
3825 DEBUGOUT("100 Mbs, ");
3828 DEBUGOUT("10 Mbs, ");
3831 if (status & E1000_STATUS_FD) {
3832 *duplex = FULL_DUPLEX;
3833 DEBUGOUT("Full Duplex\r\n");
3835 *duplex = HALF_DUPLEX;
3836 DEBUGOUT(" Half Duplex\r\n");
3839 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
3840 *speed = SPEED_1000;
3841 *duplex = FULL_DUPLEX;
3844 /* IGP01 PHY may advertise full duplex operation after speed downgrade
3845 * even if it is operating at half duplex. Here we set the duplex
3846 * settings to match the duplex in the link partner's capabilities.
3848 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
3849 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
3853 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
3854 *duplex = HALF_DUPLEX;
3856 ret_val = e1000_read_phy_reg(hw,
3857 PHY_LP_ABILITY, &phy_data);
3860 if ((*speed == SPEED_100 &&
3861 !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
3862 || (*speed == SPEED_10
3863 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3864 *duplex = HALF_DUPLEX;
3868 if ((hw->mac_type == e1000_80003es2lan) &&
3869 (hw->media_type == e1000_media_type_copper)) {
3870 if (*speed == SPEED_1000)
3871 ret_val = e1000_configure_kmrn_for_1000(hw);
3873 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3877 return E1000_SUCCESS;
3880 /******************************************************************************
3881 * Blocks until autoneg completes or times out (~4.5 seconds)
3883 * hw - Struct containing variables accessed by shared code
3884 ******************************************************************************/
3886 e1000_wait_autoneg(struct e1000_hw *hw)
3892 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3894 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
3895 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
3896 /* Read the MII Status Register and wait for Auto-Neg
3897 * Complete bit to be set.
3899 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3900 DEBUGOUT("PHY Read Error\n");
3901 return -E1000_ERR_PHY;
3903 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3904 DEBUGOUT("PHY Read Error\n");
3905 return -E1000_ERR_PHY;
3907 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
3908 DEBUGOUT("Auto-Neg complete.\n");
3913 DEBUGOUT("Auto-Neg timedout.\n");
3914 return -E1000_ERR_TIMEOUT;
3917 /******************************************************************************
3918 * Raises the Management Data Clock
3920 * hw - Struct containing variables accessed by shared code
3921 * ctrl - Device control register's current value
3922 ******************************************************************************/
3924 e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
3926 /* Raise the clock input to the Management Data Clock (by setting the MDC
3927 * bit), and then delay 2 microseconds.
3929 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
3930 E1000_WRITE_FLUSH(hw);
3934 /******************************************************************************
3935 * Lowers the Management Data Clock
3937 * hw - Struct containing variables accessed by shared code
3938 * ctrl - Device control register's current value
3939 ******************************************************************************/
3941 e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
3943 /* Lower the clock input to the Management Data Clock (by clearing the MDC
3944 * bit), and then delay 2 microseconds.
3946 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
3947 E1000_WRITE_FLUSH(hw);
3951 /******************************************************************************
3952 * Shifts data bits out to the PHY
3954 * hw - Struct containing variables accessed by shared code
3955 * data - Data to send out to the PHY
3956 * count - Number of bits to shift out
3958 * Bits are shifted out in MSB to LSB order.
3959 ******************************************************************************/
3961 e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count)
3966 /* We need to shift "count" number of bits out to the PHY. So, the value
3967 * in the "data" parameter will be shifted out to the PHY one bit at a
3968 * time. In order to do this, "data" must be broken down into bits.
3971 mask <<= (count - 1);
3973 ctrl = E1000_READ_REG(hw, CTRL);
3975 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
3976 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
3979 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
3980 * then raising and lowering the Management Data Clock. A "0" is
3981 * shifted out to the PHY by setting the MDIO bit to "0" and then
3982 * raising and lowering the clock.
3985 ctrl |= E1000_CTRL_MDIO;
3987 ctrl &= ~E1000_CTRL_MDIO;
3989 E1000_WRITE_REG(hw, CTRL, ctrl);
3990 E1000_WRITE_FLUSH(hw);
3994 e1000_raise_mdi_clk(hw, &ctrl);
3995 e1000_lower_mdi_clk(hw, &ctrl);
4001 /******************************************************************************
4002 * Shifts data bits in from the PHY
4004 * hw - Struct containing variables accessed by shared code
4006 * Bits are shifted in in MSB to LSB order.
4007 ******************************************************************************/
4009 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
4015 /* In order to read a register from the PHY, we need to shift in a total
4016 * of 18 bits from the PHY. The first two bit (turnaround) times are used
4017 * to avoid contention on the MDIO pin when a read operation is performed.
4018 * These two bits are ignored by us and thrown away. Bits are "shifted in"
4019 * by raising the input to the Management Data Clock (setting the MDC bit),
4020 * and then reading the value of the MDIO bit.
4022 ctrl = E1000_READ_REG(hw, CTRL);
4024 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
4025 ctrl &= ~E1000_CTRL_MDIO_DIR;
4026 ctrl &= ~E1000_CTRL_MDIO;
4028 E1000_WRITE_REG(hw, CTRL, ctrl);
4029 E1000_WRITE_FLUSH(hw);
4031 /* Raise and Lower the clock before reading in the data. This accounts for
4032 * the turnaround bits. The first clock occurred when we clocked out the
4033 * last bit of the Register Address.
4035 e1000_raise_mdi_clk(hw, &ctrl);
4036 e1000_lower_mdi_clk(hw, &ctrl);
4038 for (data = 0, i = 0; i < 16; i++) {
4040 e1000_raise_mdi_clk(hw, &ctrl);
4041 ctrl = E1000_READ_REG(hw, CTRL);
4042 /* Check to see if we shifted in a "1". */
4043 if (ctrl & E1000_CTRL_MDIO)
4045 e1000_lower_mdi_clk(hw, &ctrl);
4048 e1000_raise_mdi_clk(hw, &ctrl);
4049 e1000_lower_mdi_clk(hw, &ctrl);
4054 /*****************************************************************************
4055 * Reads the value from a PHY register
4057 * hw - Struct containing variables accessed by shared code
4058 * reg_addr - address of the PHY register to read
4059 ******************************************************************************/
4061 e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data)
4065 const uint32_t phy_addr = 1;
4067 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4068 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4069 return -E1000_ERR_PARAM;
4072 if (hw->mac_type > e1000_82543) {
4073 /* Set up Op-code, Phy Address, and register address in the MDI
4074 * Control register. The MAC will take care of interfacing with the
4075 * PHY to retrieve the desired data.
4077 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
4078 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4079 (E1000_MDIC_OP_READ));
4081 E1000_WRITE_REG(hw, MDIC, mdic);
4083 /* Poll the ready bit to see if the MDI read completed */
4084 for (i = 0; i < 64; i++) {
4086 mdic = E1000_READ_REG(hw, MDIC);
4087 if (mdic & E1000_MDIC_READY)
4090 if (!(mdic & E1000_MDIC_READY)) {
4091 DEBUGOUT("MDI Read did not complete\n");
4092 return -E1000_ERR_PHY;
4094 if (mdic & E1000_MDIC_ERROR) {
4095 DEBUGOUT("MDI Error\n");
4096 return -E1000_ERR_PHY;
4098 *phy_data = (uint16_t) mdic;
4100 /* We must first send a preamble through the MDIO pin to signal the
4101 * beginning of an MII instruction. This is done by sending 32
4102 * consecutive "1" bits.
4104 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4106 /* Now combine the next few fields that are required for a read
4107 * operation. We use this method instead of calling the
4108 * e1000_shift_out_mdi_bits routine five different times. The format of
4109 * a MII read instruction consists of a shift out of 14 bits and is
4110 * defined as follows:
4111 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
4112 * followed by a shift in of 18 bits. This first two bits shifted in
4113 * are TurnAround bits used to avoid contention on the MDIO pin when a
4114 * READ operation is performed. These two bits are thrown away
4115 * followed by a shift in of 16 bits which contains the desired data.
4117 mdic = ((reg_addr) | (phy_addr << 5) |
4118 (PHY_OP_READ << 10) | (PHY_SOF << 12));
4120 e1000_shift_out_mdi_bits(hw, mdic, 14);
4122 /* Now that we've shifted out the read command to the MII, we need to
4123 * "shift in" the 16-bit value (18 total bits) of the requested PHY
4126 *phy_data = e1000_shift_in_mdi_bits(hw);
4131 /******************************************************************************
4132 * Writes a value to a PHY register
4134 * hw - Struct containing variables accessed by shared code
4135 * reg_addr - address of the PHY register to write
4136 * data - data to write to the PHY
4137 ******************************************************************************/
4139 e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data)
4143 const uint32_t phy_addr = 1;
4145 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4146 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4147 return -E1000_ERR_PARAM;
4150 if (hw->mac_type > e1000_82543) {
4151 /* Set up Op-code, Phy Address, register address, and data intended
4152 * for the PHY register in the MDI Control register. The MAC will take
4153 * care of interfacing with the PHY to send the desired data.
4155 mdic = (((uint32_t) phy_data) |
4156 (reg_addr << E1000_MDIC_REG_SHIFT) |
4157 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4158 (E1000_MDIC_OP_WRITE));
4160 E1000_WRITE_REG(hw, MDIC, mdic);
4162 /* Poll the ready bit to see if the MDI read completed */
4163 for (i = 0; i < 64; i++) {
4165 mdic = E1000_READ_REG(hw, MDIC);
4166 if (mdic & E1000_MDIC_READY)
4169 if (!(mdic & E1000_MDIC_READY)) {
4170 DEBUGOUT("MDI Write did not complete\n");
4171 return -E1000_ERR_PHY;
4174 /* We'll need to use the SW defined pins to shift the write command
4175 * out to the PHY. We first send a preamble to the PHY to signal the
4176 * beginning of the MII instruction. This is done by sending 32
4177 * consecutive "1" bits.
4179 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4181 /* Now combine the remaining required fields that will indicate a
4182 * write operation. We use this method instead of calling the
4183 * e1000_shift_out_mdi_bits routine for each field in the command. The
4184 * format of a MII write instruction is as follows:
4185 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
4187 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
4188 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
4190 mdic |= (uint32_t) phy_data;
4192 e1000_shift_out_mdi_bits(hw, mdic, 32);
4197 /******************************************************************************
4198 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
4199 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
4200 * the caller to figure out how to deal with it.
4202 * hw - Struct containing variables accessed by shared code
4204 * returns: - E1000_BLK_PHY_RESET
4207 *****************************************************************************/
4209 e1000_check_phy_reset_block(struct e1000_hw *hw)
4214 if (hw->mac_type == e1000_ich8lan) {
4215 fwsm = E1000_READ_REG(hw, FWSM);
4216 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
4217 : E1000_BLK_PHY_RESET;
4220 if (hw->mac_type > e1000_82547_rev_2)
4221 manc = E1000_READ_REG(hw, MANC);
4222 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
4223 E1000_BLK_PHY_RESET : E1000_SUCCESS;
4226 /***************************************************************************
4227 * Checks if the PHY configuration is done
4229 * hw: Struct containing variables accessed by shared code
4231 * returns: - E1000_ERR_RESET if fail to reset MAC
4232 * E1000_SUCCESS at any other case.
4234 ***************************************************************************/
4236 e1000_get_phy_cfg_done(struct e1000_hw *hw)
4238 int32_t timeout = PHY_CFG_TIMEOUT;
4239 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
4243 switch (hw->mac_type) {
4248 case e1000_80003es2lan:
4249 /* Separate *_CFG_DONE_* bit for each port */
4250 if (e1000_is_second_port(hw))
4251 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
4257 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
4264 DEBUGOUT("MNG configuration cycle has not "
4266 return -E1000_ERR_RESET;
4271 return E1000_SUCCESS;
4274 /******************************************************************************
4275 * Returns the PHY to the power-on reset state
4277 * hw - Struct containing variables accessed by shared code
4278 ******************************************************************************/
4280 e1000_phy_hw_reset(struct e1000_hw *hw)
4282 uint16_t swfw = E1000_SWFW_PHY0_SM;
4283 uint32_t ctrl, ctrl_ext;
4289 /* In the case of the phy reset being blocked, it's not an error, we
4290 * simply return success without performing the reset. */
4291 ret_val = e1000_check_phy_reset_block(hw);
4293 return E1000_SUCCESS;
4295 DEBUGOUT("Resetting Phy...\n");
4297 if (hw->mac_type > e1000_82543) {
4298 if (e1000_is_second_port(hw))
4299 swfw = E1000_SWFW_PHY1_SM;
4301 if (e1000_swfw_sync_acquire(hw, swfw)) {
4302 DEBUGOUT("Unable to acquire swfw sync\n");
4303 return -E1000_ERR_SWFW_SYNC;
4306 /* Read the device control register and assert the E1000_CTRL_PHY_RST
4307 * bit. Then, take it out of reset.
4309 ctrl = E1000_READ_REG(hw, CTRL);
4310 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
4311 E1000_WRITE_FLUSH(hw);
4313 if (hw->mac_type < e1000_82571)
4318 E1000_WRITE_REG(hw, CTRL, ctrl);
4319 E1000_WRITE_FLUSH(hw);
4321 if (hw->mac_type >= e1000_82571)
4325 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
4326 * bit to put the PHY into reset. Then, take it out of reset.
4328 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
4329 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
4330 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
4331 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4332 E1000_WRITE_FLUSH(hw);
4334 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
4335 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4336 E1000_WRITE_FLUSH(hw);
4340 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
4341 /* Configure activity LED after PHY reset */
4342 led_ctrl = E1000_READ_REG(hw, LEDCTL);
4343 led_ctrl &= IGP_ACTIVITY_LED_MASK;
4344 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
4345 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
4348 /* Wait for FW to finish PHY configuration. */
4349 ret_val = e1000_get_phy_cfg_done(hw);
4350 if (ret_val != E1000_SUCCESS)
4356 /******************************************************************************
4357 * IGP phy init script - initializes the GbE PHY
4359 * hw - Struct containing variables accessed by shared code
4360 *****************************************************************************/
4362 e1000_phy_init_script(struct e1000_hw *hw)
4365 uint16_t phy_saved_data;
4368 if (hw->phy_init_script) {
4371 /* Save off the current value of register 0x2F5B to be
4372 * restored at the end of this routine. */
4373 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
4375 /* Disabled the PHY transmitter */
4376 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
4380 e1000_write_phy_reg(hw, 0x0000, 0x0140);
4384 switch (hw->mac_type) {
4387 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
4389 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
4391 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
4393 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
4395 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
4397 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
4399 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
4401 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
4403 e1000_write_phy_reg(hw, 0x2010, 0x0008);
4406 case e1000_82541_rev_2:
4407 case e1000_82547_rev_2:
4408 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
4414 e1000_write_phy_reg(hw, 0x0000, 0x3300);
4418 /* Now enable the transmitter */
4420 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
4422 if (hw->mac_type == e1000_82547) {
4423 uint16_t fused, fine, coarse;
4425 /* Move to analog registers page */
4426 e1000_read_phy_reg(hw,
4427 IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
4429 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
4430 e1000_read_phy_reg(hw,
4431 IGP01E1000_ANALOG_FUSE_STATUS, &fused);
4433 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
4435 & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
4438 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
4440 IGP01E1000_ANALOG_FUSE_COARSE_10;
4441 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
4443 == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
4444 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
4447 & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
4449 & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
4451 & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
4453 e1000_write_phy_reg(hw,
4454 IGP01E1000_ANALOG_FUSE_CONTROL, fused);
4455 e1000_write_phy_reg(hw,
4456 IGP01E1000_ANALOG_FUSE_BYPASS,
4457 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
4463 /******************************************************************************
4466 * hw - Struct containing variables accessed by shared code
4468 * Sets bit 15 of the MII Control register
4469 ******************************************************************************/
4471 e1000_phy_reset(struct e1000_hw *hw)
4478 /* In the case of the phy reset being blocked, it's not an error, we
4479 * simply return success without performing the reset. */
4480 ret_val = e1000_check_phy_reset_block(hw);
4482 return E1000_SUCCESS;
4484 switch (hw->phy_type) {
4486 case e1000_phy_igp_2:
4487 case e1000_phy_igp_3:
4489 ret_val = e1000_phy_hw_reset(hw);
4494 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
4498 phy_data |= MII_CR_RESET;
4499 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
4507 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
4508 e1000_phy_init_script(hw);
4510 return E1000_SUCCESS;
4513 static int e1000_set_phy_type (struct e1000_hw *hw)
4517 if (hw->mac_type == e1000_undefined)
4518 return -E1000_ERR_PHY_TYPE;
4520 switch (hw->phy_id) {
4521 case M88E1000_E_PHY_ID:
4522 case M88E1000_I_PHY_ID:
4523 case M88E1011_I_PHY_ID:
4524 case M88E1111_I_PHY_ID:
4525 hw->phy_type = e1000_phy_m88;
4527 case IGP01E1000_I_PHY_ID:
4528 if (hw->mac_type == e1000_82541 ||
4529 hw->mac_type == e1000_82541_rev_2 ||
4530 hw->mac_type == e1000_82547 ||
4531 hw->mac_type == e1000_82547_rev_2) {
4532 hw->phy_type = e1000_phy_igp;
4533 hw->phy_type = e1000_phy_igp;
4536 case IGP03E1000_E_PHY_ID:
4537 hw->phy_type = e1000_phy_igp_3;
4540 case IFE_PLUS_E_PHY_ID:
4541 case IFE_C_E_PHY_ID:
4542 hw->phy_type = e1000_phy_ife;
4544 case GG82563_E_PHY_ID:
4545 if (hw->mac_type == e1000_80003es2lan) {
4546 hw->phy_type = e1000_phy_gg82563;
4549 case BME1000_E_PHY_ID:
4550 hw->phy_type = e1000_phy_bm;
4554 /* Should never have loaded on this device */
4555 hw->phy_type = e1000_phy_undefined;
4556 return -E1000_ERR_PHY_TYPE;
4559 return E1000_SUCCESS;
4562 /******************************************************************************
4563 * Probes the expected PHY address for known PHY IDs
4565 * hw - Struct containing variables accessed by shared code
4566 ******************************************************************************/
4568 e1000_detect_gig_phy(struct e1000_hw *hw)
4570 int32_t phy_init_status, ret_val;
4571 uint16_t phy_id_high, phy_id_low;
4576 /* The 82571 firmware may still be configuring the PHY. In this
4577 * case, we cannot access the PHY until the configuration is done. So
4578 * we explicitly set the PHY values. */
4579 if (hw->mac_type == e1000_82571 ||
4580 hw->mac_type == e1000_82572) {
4581 hw->phy_id = IGP01E1000_I_PHY_ID;
4582 hw->phy_type = e1000_phy_igp_2;
4583 return E1000_SUCCESS;
4586 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a
4587 * work- around that forces PHY page 0 to be set or the reads fail.
4588 * The rest of the code in this routine uses e1000_read_phy_reg to
4589 * read the PHY ID. So for ESB-2 we need to have this set so our
4590 * reads won't fail. If the attached PHY is not a e1000_phy_gg82563,
4591 * the routines below will figure this out as well. */
4592 if (hw->mac_type == e1000_80003es2lan)
4593 hw->phy_type = e1000_phy_gg82563;
4595 /* Read the PHY ID Registers to identify which PHY is onboard. */
4596 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
4600 hw->phy_id = (uint32_t) (phy_id_high << 16);
4602 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
4606 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4607 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4609 switch (hw->mac_type) {
4611 if (hw->phy_id == M88E1000_E_PHY_ID)
4615 if (hw->phy_id == M88E1000_I_PHY_ID)
4620 case e1000_82545_rev_3:
4622 case e1000_82546_rev_3:
4623 if (hw->phy_id == M88E1011_I_PHY_ID)
4627 case e1000_82541_rev_2:
4629 case e1000_82547_rev_2:
4630 if(hw->phy_id == IGP01E1000_I_PHY_ID)
4635 if (hw->phy_id == M88E1111_I_PHY_ID)
4639 if (hw->phy_id == BME1000_E_PHY_ID)
4642 case e1000_80003es2lan:
4643 if (hw->phy_id == GG82563_E_PHY_ID)
4647 if (hw->phy_id == IGP03E1000_E_PHY_ID)
4649 if (hw->phy_id == IFE_E_PHY_ID)
4651 if (hw->phy_id == IFE_PLUS_E_PHY_ID)
4653 if (hw->phy_id == IFE_C_E_PHY_ID)
4657 DEBUGOUT("Invalid MAC type %d\n", hw->mac_type);
4658 return -E1000_ERR_CONFIG;
4661 phy_init_status = e1000_set_phy_type(hw);
4663 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4664 DEBUGOUT("PHY ID 0x%X detected\n", hw->phy_id);
4667 DEBUGOUT("Invalid PHY ID 0x%X\n", hw->phy_id);
4668 return -E1000_ERR_PHY;
4671 /*****************************************************************************
4672 * Set media type and TBI compatibility.
4674 * hw - Struct containing variables accessed by shared code
4675 * **************************************************************************/
4677 e1000_set_media_type(struct e1000_hw *hw)
4683 if (hw->mac_type != e1000_82543) {
4684 /* tbi_compatibility is only valid on 82543 */
4685 hw->tbi_compatibility_en = false;
4688 switch (hw->device_id) {
4689 case E1000_DEV_ID_82545GM_SERDES:
4690 case E1000_DEV_ID_82546GB_SERDES:
4691 case E1000_DEV_ID_82571EB_SERDES:
4692 case E1000_DEV_ID_82571EB_SERDES_DUAL:
4693 case E1000_DEV_ID_82571EB_SERDES_QUAD:
4694 case E1000_DEV_ID_82572EI_SERDES:
4695 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
4696 hw->media_type = e1000_media_type_internal_serdes;
4699 switch (hw->mac_type) {
4700 case e1000_82542_rev2_0:
4701 case e1000_82542_rev2_1:
4702 hw->media_type = e1000_media_type_fiber;
4707 /* The STATUS_TBIMODE bit is reserved or reused
4708 * for the this device.
4710 hw->media_type = e1000_media_type_copper;
4713 status = E1000_READ_REG(hw, STATUS);
4714 if (status & E1000_STATUS_TBIMODE) {
4715 hw->media_type = e1000_media_type_fiber;
4716 /* tbi_compatibility not valid on fiber */
4717 hw->tbi_compatibility_en = false;
4719 hw->media_type = e1000_media_type_copper;
4727 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4729 * e1000_sw_init initializes the Adapter private data structure.
4730 * Fields are initialized based on PCI device information and
4731 * OS network device settings (MTU size).
4735 e1000_sw_init(struct eth_device *nic)
4737 struct e1000_hw *hw = (typeof(hw)) nic->priv;
4740 /* PCI config space info */
4741 pci_read_config_word(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
4742 pci_read_config_word(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
4743 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
4744 &hw->subsystem_vendor_id);
4745 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
4747 pci_read_config_byte(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
4748 pci_read_config_word(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
4750 /* identify the MAC */
4751 result = e1000_set_mac_type(hw);
4753 E1000_ERR(hw->nic, "Unknown MAC Type\n");
4757 switch (hw->mac_type) {
4762 case e1000_82541_rev_2:
4763 case e1000_82547_rev_2:
4764 hw->phy_init_script = 1;
4768 /* flow control settings */
4769 hw->fc_high_water = E1000_FC_HIGH_THRESH;
4770 hw->fc_low_water = E1000_FC_LOW_THRESH;
4771 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
4772 hw->fc_send_xon = 1;
4774 /* Media type - copper or fiber */
4775 e1000_set_media_type(hw);
4777 if (hw->mac_type >= e1000_82543) {
4778 uint32_t status = E1000_READ_REG(hw, STATUS);
4780 if (status & E1000_STATUS_TBIMODE) {
4781 DEBUGOUT("fiber interface\n");
4782 hw->media_type = e1000_media_type_fiber;
4784 DEBUGOUT("copper interface\n");
4785 hw->media_type = e1000_media_type_copper;
4788 hw->media_type = e1000_media_type_fiber;
4791 hw->tbi_compatibility_en = true;
4792 hw->wait_autoneg_complete = true;
4793 if (hw->mac_type < e1000_82543)
4794 hw->report_tx_early = 0;
4796 hw->report_tx_early = 1;
4798 return E1000_SUCCESS;
4802 fill_rx(struct e1000_hw *hw)
4804 struct e1000_rx_desc *rd;
4807 rd = rx_base + rx_tail;
4808 rx_tail = (rx_tail + 1) % 8;
4810 rd->buffer_addr = cpu_to_le64((u32) & packet);
4811 E1000_WRITE_REG(hw, RDT, rx_tail);
4815 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
4816 * @adapter: board private structure
4818 * Configure the Tx unit of the MAC after a reset.
4822 e1000_configure_tx(struct e1000_hw *hw)
4826 unsigned long tipg, tarc;
4827 uint32_t ipgr1, ipgr2;
4829 ptr = (u32) tx_pool;
4831 ptr = (ptr + 0x10) & (~0xf);
4833 tx_base = (typeof(tx_base)) ptr;
4835 E1000_WRITE_REG(hw, TDBAL, (u32) tx_base);
4836 E1000_WRITE_REG(hw, TDBAH, 0);
4838 E1000_WRITE_REG(hw, TDLEN, 128);
4840 /* Setup the HW Tx Head and Tail descriptor pointers */
4841 E1000_WRITE_REG(hw, TDH, 0);
4842 E1000_WRITE_REG(hw, TDT, 0);
4845 /* Set the default values for the Tx Inter Packet Gap timer */
4846 if (hw->mac_type <= e1000_82547_rev_2 &&
4847 (hw->media_type == e1000_media_type_fiber ||
4848 hw->media_type == e1000_media_type_internal_serdes))
4849 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
4851 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
4853 /* Set the default values for the Tx Inter Packet Gap timer */
4854 switch (hw->mac_type) {
4855 case e1000_82542_rev2_0:
4856 case e1000_82542_rev2_1:
4857 tipg = DEFAULT_82542_TIPG_IPGT;
4858 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
4859 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
4861 case e1000_80003es2lan:
4862 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
4863 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
4866 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
4867 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
4870 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
4871 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
4872 E1000_WRITE_REG(hw, TIPG, tipg);
4873 /* Program the Transmit Control Register */
4874 tctl = E1000_READ_REG(hw, TCTL);
4875 tctl &= ~E1000_TCTL_CT;
4876 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
4877 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
4879 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
4880 tarc = E1000_READ_REG(hw, TARC0);
4881 /* set the speed mode bit, we'll clear it if we're not at
4882 * gigabit link later */
4883 /* git bit can be set to 1*/
4884 } else if (hw->mac_type == e1000_80003es2lan) {
4885 tarc = E1000_READ_REG(hw, TARC0);
4887 E1000_WRITE_REG(hw, TARC0, tarc);
4888 tarc = E1000_READ_REG(hw, TARC1);
4890 E1000_WRITE_REG(hw, TARC1, tarc);
4894 e1000_config_collision_dist(hw);
4895 /* Setup Transmit Descriptor Settings for eop descriptor */
4896 hw->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
4898 /* Need to set up RS bit */
4899 if (hw->mac_type < e1000_82543)
4900 hw->txd_cmd |= E1000_TXD_CMD_RPS;
4902 hw->txd_cmd |= E1000_TXD_CMD_RS;
4903 E1000_WRITE_REG(hw, TCTL, tctl);
4907 * e1000_setup_rctl - configure the receive control register
4908 * @adapter: Board private structure
4911 e1000_setup_rctl(struct e1000_hw *hw)
4915 rctl = E1000_READ_REG(hw, RCTL);
4917 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
4919 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO
4920 | E1000_RCTL_RDMTS_HALF; /* |
4921 (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */
4923 if (hw->tbi_compatibility_on == 1)
4924 rctl |= E1000_RCTL_SBP;
4926 rctl &= ~E1000_RCTL_SBP;
4928 rctl &= ~(E1000_RCTL_SZ_4096);
4929 rctl |= E1000_RCTL_SZ_2048;
4930 rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
4931 E1000_WRITE_REG(hw, RCTL, rctl);
4935 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
4936 * @adapter: board private structure
4938 * Configure the Rx unit of the MAC after a reset.
4941 e1000_configure_rx(struct e1000_hw *hw)
4944 unsigned long rctl, ctrl_ext;
4946 /* make sure receives are disabled while setting up the descriptors */
4947 rctl = E1000_READ_REG(hw, RCTL);
4948 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
4949 if (hw->mac_type >= e1000_82540) {
4950 /* Set the interrupt throttling rate. Value is calculated
4951 * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */
4952 #define MAX_INTS_PER_SEC 8000
4953 #define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
4954 E1000_WRITE_REG(hw, ITR, DEFAULT_ITR);
4957 if (hw->mac_type >= e1000_82571) {
4958 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
4959 /* Reset delay timers after every interrupt */
4960 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
4961 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4962 E1000_WRITE_FLUSH(hw);
4964 /* Setup the Base and Length of the Rx Descriptor Ring */
4965 ptr = (u32) rx_pool;
4967 ptr = (ptr + 0x10) & (~0xf);
4968 rx_base = (typeof(rx_base)) ptr;
4969 E1000_WRITE_REG(hw, RDBAL, (u32) rx_base);
4970 E1000_WRITE_REG(hw, RDBAH, 0);
4972 E1000_WRITE_REG(hw, RDLEN, 128);
4974 /* Setup the HW Rx Head and Tail Descriptor Pointers */
4975 E1000_WRITE_REG(hw, RDH, 0);
4976 E1000_WRITE_REG(hw, RDT, 0);
4977 /* Enable Receives */
4979 E1000_WRITE_REG(hw, RCTL, rctl);
4983 /**************************************************************************
4984 POLL - Wait for a frame
4985 ***************************************************************************/
4987 e1000_poll(struct eth_device *nic)
4989 struct e1000_hw *hw = nic->priv;
4990 struct e1000_rx_desc *rd;
4991 /* return true if there's an ethernet packet ready to read */
4992 rd = rx_base + rx_last;
4993 if (!(le32_to_cpu(rd->status)) & E1000_RXD_STAT_DD)
4995 /*DEBUGOUT("recv: packet len=%d \n", rd->length); */
4996 NetReceive((uchar *)packet, le32_to_cpu(rd->length));
5001 /**************************************************************************
5002 TRANSMIT - Transmit a frame
5003 ***************************************************************************/
5004 static int e1000_transmit(struct eth_device *nic, void *packet, int length)
5006 void *nv_packet = (void *)packet;
5007 struct e1000_hw *hw = nic->priv;
5008 struct e1000_tx_desc *txp;
5011 txp = tx_base + tx_tail;
5012 tx_tail = (tx_tail + 1) % 8;
5014 txp->buffer_addr = cpu_to_le64(virt_to_bus(hw->pdev, nv_packet));
5015 txp->lower.data = cpu_to_le32(hw->txd_cmd | length);
5016 txp->upper.data = 0;
5017 E1000_WRITE_REG(hw, TDT, tx_tail);
5019 E1000_WRITE_FLUSH(hw);
5020 while (!(le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD)) {
5021 if (i++ > TOUT_LOOP) {
5022 DEBUGOUT("e1000: tx timeout\n");
5025 udelay(10); /* give the nic a chance to write to the register */
5032 e1000_reset(struct eth_device *nic)
5034 struct e1000_hw *hw = nic->priv;
5037 if (hw->mac_type >= e1000_82544) {
5038 E1000_WRITE_REG(hw, WUC, 0);
5040 return e1000_init_hw(nic);
5043 /**************************************************************************
5044 DISABLE - Turn off ethernet interface
5045 ***************************************************************************/
5047 e1000_disable(struct eth_device *nic)
5049 struct e1000_hw *hw = nic->priv;
5051 /* Turn off the ethernet interface */
5052 E1000_WRITE_REG(hw, RCTL, 0);
5053 E1000_WRITE_REG(hw, TCTL, 0);
5055 /* Clear the transmit ring */
5056 E1000_WRITE_REG(hw, TDH, 0);
5057 E1000_WRITE_REG(hw, TDT, 0);
5059 /* Clear the receive ring */
5060 E1000_WRITE_REG(hw, RDH, 0);
5061 E1000_WRITE_REG(hw, RDT, 0);
5063 /* put the card in its initial state */
5065 E1000_WRITE_REG(hw, CTRL, E1000_CTRL_RST);
5071 /**************************************************************************
5072 INIT - set up ethernet interface(s)
5073 ***************************************************************************/
5075 e1000_init(struct eth_device *nic, bd_t * bis)
5077 struct e1000_hw *hw = nic->priv;
5080 ret_val = e1000_reset(nic);
5082 if ((ret_val == -E1000_ERR_NOLINK) ||
5083 (ret_val == -E1000_ERR_TIMEOUT)) {
5084 E1000_ERR(hw->nic, "Valid Link not detected\n");
5086 E1000_ERR(hw->nic, "Hardware Initialization Failed\n");
5090 e1000_configure_tx(hw);
5091 e1000_setup_rctl(hw);
5092 e1000_configure_rx(hw);
5096 /******************************************************************************
5097 * Gets the current PCI bus type of hardware
5099 * hw - Struct containing variables accessed by shared code
5100 *****************************************************************************/
5101 void e1000_get_bus_type(struct e1000_hw *hw)
5105 switch (hw->mac_type) {
5106 case e1000_82542_rev2_0:
5107 case e1000_82542_rev2_1:
5108 hw->bus_type = e1000_bus_type_pci;
5114 case e1000_80003es2lan:
5115 hw->bus_type = e1000_bus_type_pci_express;
5118 hw->bus_type = e1000_bus_type_pci_express;
5121 status = E1000_READ_REG(hw, STATUS);
5122 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5123 e1000_bus_type_pcix : e1000_bus_type_pci;
5128 /* A list of all registered e1000 devices */
5129 static LIST_HEAD(e1000_hw_list);
5131 /**************************************************************************
5132 PROBE - Look for an adapter, this routine's visible to the outside
5133 You should omit the last argument struct pci_device * for a non-PCI NIC
5134 ***************************************************************************/
5136 e1000_initialize(bd_t * bis)
5143 /* Find and probe all the matching PCI devices */
5144 for (i = 0; (devno = pci_find_devices(e1000_supported, i)) >= 0; i++) {
5148 * These will never get freed due to errors, this allows us to
5149 * perform SPI EEPROM programming from U-boot, for example.
5151 struct eth_device *nic = malloc(sizeof(*nic));
5152 struct e1000_hw *hw = malloc(sizeof(*hw));
5154 printf("e1000#%u: Out of Memory!\n", i);
5160 /* Make sure all of the fields are initially zeroed */
5161 memset(nic, 0, sizeof(*nic));
5162 memset(hw, 0, sizeof(*hw));
5164 /* Assign the passed-in values */
5170 /* Generate a card name */
5171 sprintf(nic->name, "e1000#%u", hw->cardnum);
5173 /* Print a debug message with the IO base address */
5174 pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &val);
5175 E1000_DBG(nic, "iobase 0x%08x\n", val & 0xfffffff0);
5177 /* Try to enable I/O accesses and bus-mastering */
5178 val = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
5179 pci_write_config_dword(devno, PCI_COMMAND, val);
5181 /* Make sure it worked */
5182 pci_read_config_dword(devno, PCI_COMMAND, &val);
5183 if (!(val & PCI_COMMAND_MEMORY)) {
5184 E1000_ERR(nic, "Can't enable I/O memory\n");
5187 if (!(val & PCI_COMMAND_MASTER)) {
5188 E1000_ERR(nic, "Can't enable bus-mastering\n");
5192 /* Are these variables needed? */
5193 hw->fc = e1000_fc_default;
5194 hw->original_fc = e1000_fc_default;
5195 hw->autoneg_failed = 0;
5197 hw->get_link_status = true;
5198 hw->hw_addr = pci_map_bar(devno, PCI_BASE_ADDRESS_0,
5200 hw->mac_type = e1000_undefined;
5202 /* MAC and Phy settings */
5203 if (e1000_sw_init(nic) < 0) {
5204 E1000_ERR(nic, "Software init failed\n");
5207 if (e1000_check_phy_reset_block(hw))
5208 E1000_ERR(nic, "PHY Reset is blocked!\n");
5210 /* Basic init was OK, reset the hardware and allow SPI access */
5212 list_add_tail(&hw->list_node, &e1000_hw_list);
5214 /* Validate the EEPROM and get chipset information */
5215 #if !defined(CONFIG_MVBC_1G)
5216 if (e1000_init_eeprom_params(hw)) {
5217 E1000_ERR(nic, "EEPROM is invalid!\n");
5220 if (e1000_validate_eeprom_checksum(hw))
5223 e1000_read_mac_addr(nic);
5224 e1000_get_bus_type(hw);
5226 printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n ",
5227 nic->enetaddr[0], nic->enetaddr[1], nic->enetaddr[2],
5228 nic->enetaddr[3], nic->enetaddr[4], nic->enetaddr[5]);
5230 /* Set up the function pointers and register the device */
5231 nic->init = e1000_init;
5232 nic->recv = e1000_poll;
5233 nic->send = e1000_transmit;
5234 nic->halt = e1000_disable;
5241 struct e1000_hw *e1000_find_card(unsigned int cardnum)
5243 struct e1000_hw *hw;
5245 list_for_each_entry(hw, &e1000_hw_list, list_node)
5246 if (hw->cardnum == cardnum)
5252 #ifdef CONFIG_CMD_E1000
5253 static int do_e1000(cmd_tbl_t *cmdtp, int flag,
5254 int argc, char * const argv[])
5256 struct e1000_hw *hw;
5263 /* Make sure we can find the requested e1000 card */
5264 hw = e1000_find_card(simple_strtoul(argv[1], NULL, 10));
5266 printf("e1000: ERROR: No such device: e1000#%s\n", argv[1]);
5270 if (!strcmp(argv[2], "print-mac-address")) {
5271 unsigned char *mac = hw->nic->enetaddr;
5272 printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
5273 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
5277 #ifdef CONFIG_E1000_SPI
5278 /* Handle the "SPI" subcommand */
5279 if (!strcmp(argv[2], "spi"))
5280 return do_e1000_spi(cmdtp, hw, argc - 3, argv + 3);
5288 e1000, 7, 0, do_e1000,
5289 "Intel e1000 controller management",
5290 /* */"<card#> print-mac-address\n"
5291 #ifdef CONFIG_E1000_SPI
5292 "e1000 <card#> spi show [<offset> [<length>]]\n"
5293 "e1000 <card#> spi dump <addr> <offset> <length>\n"
5294 "e1000 <card#> spi program <addr> <offset> <length>\n"
5295 "e1000 <card#> spi checksum [update]\n"
5297 " - Manage the Intel E1000 PCI device"
5299 #endif /* not CONFIG_CMD_E1000 */