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 * SPDX-License-Identifier: GPL-2.0+
15 Linux NICS <linux.nics@intel.com>
16 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
18 *******************************************************************************/
20 * Copyright (C) Archway Digital Solutions.
22 * written by Chrsitopher Li <cli at arcyway dot com> or <chrisl at gnuchina dot org>
25 * Copyright (C) Linux Networx.
26 * Massive upgrade to work with the new intel gigabit NICs.
27 * <ebiederman at lnxi dot com>
29 * Copyright 2011 Freescale Semiconductor, Inc.
38 #define TOUT_LOOP 100000
40 #define virt_to_bus(devno, v) pci_virt_to_mem(devno, (void *) (v))
41 #define bus_to_phys(devno, a) pci_mem_to_phys(devno, a)
43 #define E1000_DEFAULT_PCI_PBA 0x00000030
44 #define E1000_DEFAULT_PCIE_PBA 0x000a0026
46 /* NIC specific static variables go here */
48 /* Intel i210 needs the DMA descriptor rings aligned to 128b */
49 #define E1000_BUFFER_ALIGN 128
52 * TODO(sjg@chromium.org): Even with driver model we share these buffers.
53 * Concurrent receiving on multiple active Ethernet devices will not work.
54 * Normally U-Boot does not support this anyway. To fix it in this driver,
55 * move these buffers and the tx/rx pointers to struct e1000_hw.
57 DEFINE_ALIGN_BUFFER(struct e1000_tx_desc, tx_base, 16, E1000_BUFFER_ALIGN);
58 DEFINE_ALIGN_BUFFER(struct e1000_rx_desc, rx_base, 16, E1000_BUFFER_ALIGN);
59 DEFINE_ALIGN_BUFFER(unsigned char, packet, 4096, E1000_BUFFER_ALIGN);
62 static int rx_tail, rx_last;
64 static int num_cards; /* Number of E1000 devices seen so far */
67 static struct pci_device_id e1000_supported[] = {
68 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82542) },
69 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_FIBER) },
70 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_COPPER) },
71 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_COPPER) },
72 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_FIBER) },
73 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_COPPER) },
74 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_LOM) },
75 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM) },
76 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_COPPER) },
77 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545GM_COPPER) },
78 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_COPPER) },
79 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_FIBER) },
80 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_FIBER) },
81 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_COPPER) },
82 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM_LOM) },
83 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541ER) },
84 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541GI_LF) },
86 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_COPPER) },
87 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_FIBER) },
88 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES) },
89 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER) },
90 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571PT_QUAD_COPPER) },
91 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_FIBER) },
92 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER_LOWPROFILE) },
93 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_DUAL) },
94 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_QUAD) },
95 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_COPPER) },
96 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_FIBER) },
97 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_SERDES) },
98 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI) },
99 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E) },
100 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E_IAMT) },
101 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573L) },
102 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82574L) },
103 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_QUAD_COPPER_KSP3) },
104 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_DPT) },
105 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_DPT) },
106 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_SPT) },
107 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_SPT) },
108 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED) },
109 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED) },
110 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER) },
111 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_COPPER) },
112 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS) },
113 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES) },
114 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS) },
115 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_1000BASEKX) },
120 /* Function forward declarations */
121 static int e1000_setup_link(struct e1000_hw *hw);
122 static int e1000_setup_fiber_link(struct e1000_hw *hw);
123 static int e1000_setup_copper_link(struct e1000_hw *hw);
124 static int e1000_phy_setup_autoneg(struct e1000_hw *hw);
125 static void e1000_config_collision_dist(struct e1000_hw *hw);
126 static int e1000_config_mac_to_phy(struct e1000_hw *hw);
127 static int e1000_config_fc_after_link_up(struct e1000_hw *hw);
128 static int e1000_check_for_link(struct e1000_hw *hw);
129 static int e1000_wait_autoneg(struct e1000_hw *hw);
130 static int e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t * speed,
132 static int e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
133 uint16_t * phy_data);
134 static int e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
136 static int32_t e1000_phy_hw_reset(struct e1000_hw *hw);
137 static int e1000_phy_reset(struct e1000_hw *hw);
138 static int e1000_detect_gig_phy(struct e1000_hw *hw);
139 static void e1000_set_media_type(struct e1000_hw *hw);
141 static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
142 static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
143 static int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
145 #ifndef CONFIG_E1000_NO_NVM
146 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
147 static int32_t e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
150 /******************************************************************************
151 * Raises the EEPROM's clock input.
153 * hw - Struct containing variables accessed by shared code
154 * eecd - EECD's current value
155 *****************************************************************************/
156 void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
158 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
159 * wait 50 microseconds.
161 *eecd = *eecd | E1000_EECD_SK;
162 E1000_WRITE_REG(hw, EECD, *eecd);
163 E1000_WRITE_FLUSH(hw);
167 /******************************************************************************
168 * Lowers the EEPROM's clock input.
170 * hw - Struct containing variables accessed by shared code
171 * eecd - EECD's current value
172 *****************************************************************************/
173 void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
175 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
176 * wait 50 microseconds.
178 *eecd = *eecd & ~E1000_EECD_SK;
179 E1000_WRITE_REG(hw, EECD, *eecd);
180 E1000_WRITE_FLUSH(hw);
184 /******************************************************************************
185 * Shift data bits out to the EEPROM.
187 * hw - Struct containing variables accessed by shared code
188 * data - data to send to the EEPROM
189 * count - number of bits to shift out
190 *****************************************************************************/
192 e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count)
197 /* We need to shift "count" bits out to the EEPROM. So, value in the
198 * "data" parameter will be shifted out to the EEPROM one bit at a time.
199 * In order to do this, "data" must be broken down into bits.
201 mask = 0x01 << (count - 1);
202 eecd = E1000_READ_REG(hw, EECD);
203 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
205 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
206 * and then raising and then lowering the clock (the SK bit controls
207 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
208 * by setting "DI" to "0" and then raising and then lowering the clock.
210 eecd &= ~E1000_EECD_DI;
213 eecd |= E1000_EECD_DI;
215 E1000_WRITE_REG(hw, EECD, eecd);
216 E1000_WRITE_FLUSH(hw);
220 e1000_raise_ee_clk(hw, &eecd);
221 e1000_lower_ee_clk(hw, &eecd);
227 /* We leave the "DI" bit set to "0" when we leave this routine. */
228 eecd &= ~E1000_EECD_DI;
229 E1000_WRITE_REG(hw, EECD, eecd);
232 /******************************************************************************
233 * Shift data bits in from the EEPROM
235 * hw - Struct containing variables accessed by shared code
236 *****************************************************************************/
238 e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count)
244 /* In order to read a register from the EEPROM, we need to shift 'count'
245 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
246 * input to the EEPROM (setting the SK bit), and then reading the
247 * value of the "DO" bit. During this "shifting in" process the
248 * "DI" bit should always be clear.
251 eecd = E1000_READ_REG(hw, EECD);
253 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
256 for (i = 0; i < count; i++) {
258 e1000_raise_ee_clk(hw, &eecd);
260 eecd = E1000_READ_REG(hw, EECD);
262 eecd &= ~(E1000_EECD_DI);
263 if (eecd & E1000_EECD_DO)
266 e1000_lower_ee_clk(hw, &eecd);
272 /******************************************************************************
273 * Returns EEPROM to a "standby" state
275 * hw - Struct containing variables accessed by shared code
276 *****************************************************************************/
277 void e1000_standby_eeprom(struct e1000_hw *hw)
279 struct e1000_eeprom_info *eeprom = &hw->eeprom;
282 eecd = E1000_READ_REG(hw, EECD);
284 if (eeprom->type == e1000_eeprom_microwire) {
285 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
286 E1000_WRITE_REG(hw, EECD, eecd);
287 E1000_WRITE_FLUSH(hw);
288 udelay(eeprom->delay_usec);
291 eecd |= E1000_EECD_SK;
292 E1000_WRITE_REG(hw, EECD, eecd);
293 E1000_WRITE_FLUSH(hw);
294 udelay(eeprom->delay_usec);
297 eecd |= E1000_EECD_CS;
298 E1000_WRITE_REG(hw, EECD, eecd);
299 E1000_WRITE_FLUSH(hw);
300 udelay(eeprom->delay_usec);
303 eecd &= ~E1000_EECD_SK;
304 E1000_WRITE_REG(hw, EECD, eecd);
305 E1000_WRITE_FLUSH(hw);
306 udelay(eeprom->delay_usec);
307 } else if (eeprom->type == e1000_eeprom_spi) {
308 /* Toggle CS to flush commands */
309 eecd |= E1000_EECD_CS;
310 E1000_WRITE_REG(hw, EECD, eecd);
311 E1000_WRITE_FLUSH(hw);
312 udelay(eeprom->delay_usec);
313 eecd &= ~E1000_EECD_CS;
314 E1000_WRITE_REG(hw, EECD, eecd);
315 E1000_WRITE_FLUSH(hw);
316 udelay(eeprom->delay_usec);
320 /***************************************************************************
321 * Description: Determines if the onboard NVM is FLASH or EEPROM.
323 * hw - Struct containing variables accessed by shared code
324 ****************************************************************************/
325 static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
331 if (hw->mac_type == e1000_ich8lan)
334 if (hw->mac_type == e1000_82573 || hw->mac_type == e1000_82574) {
335 eecd = E1000_READ_REG(hw, EECD);
337 /* Isolate bits 15 & 16 */
338 eecd = ((eecd >> 15) & 0x03);
340 /* If both bits are set, device is Flash type */
347 /******************************************************************************
348 * Prepares EEPROM for access
350 * hw - Struct containing variables accessed by shared code
352 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
353 * function should be called before issuing a command to the EEPROM.
354 *****************************************************************************/
355 int32_t e1000_acquire_eeprom(struct e1000_hw *hw)
357 struct e1000_eeprom_info *eeprom = &hw->eeprom;
358 uint32_t eecd, i = 0;
362 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
363 return -E1000_ERR_SWFW_SYNC;
364 eecd = E1000_READ_REG(hw, EECD);
366 if (hw->mac_type != e1000_82573 && hw->mac_type != e1000_82574) {
367 /* Request EEPROM Access */
368 if (hw->mac_type > e1000_82544) {
369 eecd |= E1000_EECD_REQ;
370 E1000_WRITE_REG(hw, EECD, eecd);
371 eecd = E1000_READ_REG(hw, EECD);
372 while ((!(eecd & E1000_EECD_GNT)) &&
373 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
376 eecd = E1000_READ_REG(hw, EECD);
378 if (!(eecd & E1000_EECD_GNT)) {
379 eecd &= ~E1000_EECD_REQ;
380 E1000_WRITE_REG(hw, EECD, eecd);
381 DEBUGOUT("Could not acquire EEPROM grant\n");
382 return -E1000_ERR_EEPROM;
387 /* Setup EEPROM for Read/Write */
389 if (eeprom->type == e1000_eeprom_microwire) {
390 /* Clear SK and DI */
391 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
392 E1000_WRITE_REG(hw, EECD, eecd);
395 eecd |= E1000_EECD_CS;
396 E1000_WRITE_REG(hw, EECD, eecd);
397 } else if (eeprom->type == e1000_eeprom_spi) {
398 /* Clear SK and CS */
399 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
400 E1000_WRITE_REG(hw, EECD, eecd);
404 return E1000_SUCCESS;
407 /******************************************************************************
408 * Sets up eeprom variables in the hw struct. Must be called after mac_type
409 * is configured. Additionally, if this is ICH8, the flash controller GbE
410 * registers must be mapped, or this will crash.
412 * hw - Struct containing variables accessed by shared code
413 *****************************************************************************/
414 static int32_t e1000_init_eeprom_params(struct e1000_hw *hw)
416 struct e1000_eeprom_info *eeprom = &hw->eeprom;
418 int32_t ret_val = E1000_SUCCESS;
419 uint16_t eeprom_size;
421 if (hw->mac_type == e1000_igb)
422 eecd = E1000_READ_REG(hw, I210_EECD);
424 eecd = E1000_READ_REG(hw, EECD);
428 switch (hw->mac_type) {
429 case e1000_82542_rev2_0:
430 case e1000_82542_rev2_1:
433 eeprom->type = e1000_eeprom_microwire;
434 eeprom->word_size = 64;
435 eeprom->opcode_bits = 3;
436 eeprom->address_bits = 6;
437 eeprom->delay_usec = 50;
438 eeprom->use_eerd = false;
439 eeprom->use_eewr = false;
443 case e1000_82545_rev_3:
445 case e1000_82546_rev_3:
446 eeprom->type = e1000_eeprom_microwire;
447 eeprom->opcode_bits = 3;
448 eeprom->delay_usec = 50;
449 if (eecd & E1000_EECD_SIZE) {
450 eeprom->word_size = 256;
451 eeprom->address_bits = 8;
453 eeprom->word_size = 64;
454 eeprom->address_bits = 6;
456 eeprom->use_eerd = false;
457 eeprom->use_eewr = false;
460 case e1000_82541_rev_2:
462 case e1000_82547_rev_2:
463 if (eecd & E1000_EECD_TYPE) {
464 eeprom->type = e1000_eeprom_spi;
465 eeprom->opcode_bits = 8;
466 eeprom->delay_usec = 1;
467 if (eecd & E1000_EECD_ADDR_BITS) {
468 eeprom->page_size = 32;
469 eeprom->address_bits = 16;
471 eeprom->page_size = 8;
472 eeprom->address_bits = 8;
475 eeprom->type = e1000_eeprom_microwire;
476 eeprom->opcode_bits = 3;
477 eeprom->delay_usec = 50;
478 if (eecd & E1000_EECD_ADDR_BITS) {
479 eeprom->word_size = 256;
480 eeprom->address_bits = 8;
482 eeprom->word_size = 64;
483 eeprom->address_bits = 6;
486 eeprom->use_eerd = false;
487 eeprom->use_eewr = false;
491 eeprom->type = e1000_eeprom_spi;
492 eeprom->opcode_bits = 8;
493 eeprom->delay_usec = 1;
494 if (eecd & E1000_EECD_ADDR_BITS) {
495 eeprom->page_size = 32;
496 eeprom->address_bits = 16;
498 eeprom->page_size = 8;
499 eeprom->address_bits = 8;
501 eeprom->use_eerd = false;
502 eeprom->use_eewr = false;
506 eeprom->type = e1000_eeprom_spi;
507 eeprom->opcode_bits = 8;
508 eeprom->delay_usec = 1;
509 if (eecd & E1000_EECD_ADDR_BITS) {
510 eeprom->page_size = 32;
511 eeprom->address_bits = 16;
513 eeprom->page_size = 8;
514 eeprom->address_bits = 8;
516 if (e1000_is_onboard_nvm_eeprom(hw) == false) {
517 eeprom->use_eerd = true;
518 eeprom->use_eewr = true;
520 eeprom->type = e1000_eeprom_flash;
521 eeprom->word_size = 2048;
523 /* Ensure that the Autonomous FLASH update bit is cleared due to
524 * Flash update issue on parts which use a FLASH for NVM. */
525 eecd &= ~E1000_EECD_AUPDEN;
526 E1000_WRITE_REG(hw, EECD, eecd);
529 case e1000_80003es2lan:
530 eeprom->type = e1000_eeprom_spi;
531 eeprom->opcode_bits = 8;
532 eeprom->delay_usec = 1;
533 if (eecd & E1000_EECD_ADDR_BITS) {
534 eeprom->page_size = 32;
535 eeprom->address_bits = 16;
537 eeprom->page_size = 8;
538 eeprom->address_bits = 8;
540 eeprom->use_eerd = true;
541 eeprom->use_eewr = false;
544 /* i210 has 4k of iNVM mapped as EEPROM */
545 eeprom->type = e1000_eeprom_invm;
546 eeprom->opcode_bits = 8;
547 eeprom->delay_usec = 1;
548 eeprom->page_size = 32;
549 eeprom->address_bits = 16;
550 eeprom->use_eerd = true;
551 eeprom->use_eewr = false;
554 /* ich8lan does not support currently. if needed, please
555 * add corresponding code and functions.
562 eeprom->type = e1000_eeprom_ich8;
563 eeprom->use_eerd = false;
564 eeprom->use_eewr = false;
565 eeprom->word_size = E1000_SHADOW_RAM_WORDS;
566 uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw,
568 /* Zero the shadow RAM structure. But don't load it from NVM
569 * so as to save time for driver init */
570 if (hw->eeprom_shadow_ram != NULL) {
571 for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
572 hw->eeprom_shadow_ram[i].modified = false;
573 hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
577 hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) *
578 ICH_FLASH_SECTOR_SIZE;
580 hw->flash_bank_size = ((flash_size >> 16)
581 & ICH_GFPREG_BASE_MASK) + 1;
582 hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK);
584 hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE;
586 hw->flash_bank_size /= 2 * sizeof(uint16_t);
594 if (eeprom->type == e1000_eeprom_spi ||
595 eeprom->type == e1000_eeprom_invm) {
596 /* eeprom_size will be an enum [0..8] that maps
597 * to eeprom sizes 128B to
598 * 32KB (incremented by powers of 2).
600 if (hw->mac_type <= e1000_82547_rev_2) {
601 /* Set to default value for initial eeprom read. */
602 eeprom->word_size = 64;
603 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1,
607 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK)
608 >> EEPROM_SIZE_SHIFT;
609 /* 256B eeprom size was not supported in earlier
610 * hardware, so we bump eeprom_size up one to
611 * ensure that "1" (which maps to 256B) is never
612 * the result used in the shifting logic below. */
616 eeprom_size = (uint16_t)((eecd &
617 E1000_EECD_SIZE_EX_MASK) >>
618 E1000_EECD_SIZE_EX_SHIFT);
621 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
626 /******************************************************************************
627 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
629 * hw - Struct containing variables accessed by shared code
630 *****************************************************************************/
632 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
634 uint32_t attempts = 100000;
636 int32_t done = E1000_ERR_EEPROM;
638 for (i = 0; i < attempts; i++) {
639 if (eerd == E1000_EEPROM_POLL_READ) {
640 if (hw->mac_type == e1000_igb)
641 reg = E1000_READ_REG(hw, I210_EERD);
643 reg = E1000_READ_REG(hw, EERD);
645 if (hw->mac_type == e1000_igb)
646 reg = E1000_READ_REG(hw, I210_EEWR);
648 reg = E1000_READ_REG(hw, EEWR);
651 if (reg & E1000_EEPROM_RW_REG_DONE) {
652 done = E1000_SUCCESS;
661 /******************************************************************************
662 * Reads a 16 bit word from the EEPROM using the EERD register.
664 * hw - Struct containing variables accessed by shared code
665 * offset - offset of word in the EEPROM to read
666 * data - word read from the EEPROM
667 * words - number of words to read
668 *****************************************************************************/
670 e1000_read_eeprom_eerd(struct e1000_hw *hw,
675 uint32_t i, eerd = 0;
678 for (i = 0; i < words; i++) {
679 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
680 E1000_EEPROM_RW_REG_START;
682 if (hw->mac_type == e1000_igb)
683 E1000_WRITE_REG(hw, I210_EERD, eerd);
685 E1000_WRITE_REG(hw, EERD, eerd);
687 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
692 if (hw->mac_type == e1000_igb) {
693 data[i] = (E1000_READ_REG(hw, I210_EERD) >>
694 E1000_EEPROM_RW_REG_DATA);
696 data[i] = (E1000_READ_REG(hw, EERD) >>
697 E1000_EEPROM_RW_REG_DATA);
705 void e1000_release_eeprom(struct e1000_hw *hw)
711 eecd = E1000_READ_REG(hw, EECD);
713 if (hw->eeprom.type == e1000_eeprom_spi) {
714 eecd |= E1000_EECD_CS; /* Pull CS high */
715 eecd &= ~E1000_EECD_SK; /* Lower SCK */
717 E1000_WRITE_REG(hw, EECD, eecd);
719 udelay(hw->eeprom.delay_usec);
720 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
723 /* CS on Microwire is active-high */
724 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
726 E1000_WRITE_REG(hw, EECD, eecd);
728 /* Rising edge of clock */
729 eecd |= E1000_EECD_SK;
730 E1000_WRITE_REG(hw, EECD, eecd);
731 E1000_WRITE_FLUSH(hw);
732 udelay(hw->eeprom.delay_usec);
734 /* Falling edge of clock */
735 eecd &= ~E1000_EECD_SK;
736 E1000_WRITE_REG(hw, EECD, eecd);
737 E1000_WRITE_FLUSH(hw);
738 udelay(hw->eeprom.delay_usec);
741 /* Stop requesting EEPROM access */
742 if (hw->mac_type > e1000_82544) {
743 eecd &= ~E1000_EECD_REQ;
744 E1000_WRITE_REG(hw, EECD, eecd);
747 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
750 /******************************************************************************
751 * Reads a 16 bit word from the EEPROM.
753 * hw - Struct containing variables accessed by shared code
754 *****************************************************************************/
756 e1000_spi_eeprom_ready(struct e1000_hw *hw)
758 uint16_t retry_count = 0;
759 uint8_t spi_stat_reg;
763 /* Read "Status Register" repeatedly until the LSB is cleared. The
764 * EEPROM will signal that the command has been completed by clearing
765 * bit 0 of the internal status register. If it's not cleared within
766 * 5 milliseconds, then error out.
770 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
771 hw->eeprom.opcode_bits);
772 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
773 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
779 e1000_standby_eeprom(hw);
780 } while (retry_count < EEPROM_MAX_RETRY_SPI);
782 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
783 * only 0-5mSec on 5V devices)
785 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
786 DEBUGOUT("SPI EEPROM Status error\n");
787 return -E1000_ERR_EEPROM;
790 return E1000_SUCCESS;
793 /******************************************************************************
794 * Reads a 16 bit word from the EEPROM.
796 * hw - Struct containing variables accessed by shared code
797 * offset - offset of word in the EEPROM to read
798 * data - word read from the EEPROM
799 *****************************************************************************/
801 e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
802 uint16_t words, uint16_t *data)
804 struct e1000_eeprom_info *eeprom = &hw->eeprom;
809 /* If eeprom is not yet detected, do so now */
810 if (eeprom->word_size == 0)
811 e1000_init_eeprom_params(hw);
813 /* A check for invalid values: offset too large, too many words,
814 * and not enough words.
816 if ((offset >= eeprom->word_size) ||
817 (words > eeprom->word_size - offset) ||
819 DEBUGOUT("\"words\" parameter out of bounds."
820 "Words = %d, size = %d\n", offset, eeprom->word_size);
821 return -E1000_ERR_EEPROM;
824 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
825 * directly. In this case, we need to acquire the EEPROM so that
826 * FW or other port software does not interrupt.
828 if (e1000_is_onboard_nvm_eeprom(hw) == true &&
829 hw->eeprom.use_eerd == false) {
831 /* Prepare the EEPROM for bit-bang reading */
832 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
833 return -E1000_ERR_EEPROM;
836 /* Eerd register EEPROM access requires no eeprom aquire/release */
837 if (eeprom->use_eerd == true)
838 return e1000_read_eeprom_eerd(hw, offset, words, data);
840 /* ich8lan does not support currently. if needed, please
841 * add corresponding code and functions.
844 /* ICH EEPROM access is done via the ICH flash controller */
845 if (eeprom->type == e1000_eeprom_ich8)
846 return e1000_read_eeprom_ich8(hw, offset, words, data);
848 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
849 * acquired the EEPROM at this point, so any returns should relase it */
850 if (eeprom->type == e1000_eeprom_spi) {
852 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
854 if (e1000_spi_eeprom_ready(hw)) {
855 e1000_release_eeprom(hw);
856 return -E1000_ERR_EEPROM;
859 e1000_standby_eeprom(hw);
861 /* Some SPI eeproms use the 8th address bit embedded in
863 if ((eeprom->address_bits == 8) && (offset >= 128))
864 read_opcode |= EEPROM_A8_OPCODE_SPI;
866 /* Send the READ command (opcode + addr) */
867 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
868 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2),
869 eeprom->address_bits);
871 /* Read the data. The address of the eeprom internally
872 * increments with each byte (spi) being read, saving on the
873 * overhead of eeprom setup and tear-down. The address
874 * counter will roll over if reading beyond the size of
875 * the eeprom, thus allowing the entire memory to be read
876 * starting from any offset. */
877 for (i = 0; i < words; i++) {
878 word_in = e1000_shift_in_ee_bits(hw, 16);
879 data[i] = (word_in >> 8) | (word_in << 8);
881 } else if (eeprom->type == e1000_eeprom_microwire) {
882 for (i = 0; i < words; i++) {
883 /* Send the READ command (opcode + addr) */
884 e1000_shift_out_ee_bits(hw,
885 EEPROM_READ_OPCODE_MICROWIRE,
886 eeprom->opcode_bits);
887 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
888 eeprom->address_bits);
890 /* Read the data. For microwire, each word requires
891 * the overhead of eeprom setup and tear-down. */
892 data[i] = e1000_shift_in_ee_bits(hw, 16);
893 e1000_standby_eeprom(hw);
897 /* End this read operation */
898 e1000_release_eeprom(hw);
900 return E1000_SUCCESS;
903 /******************************************************************************
904 * Verifies that the EEPROM has a valid checksum
906 * hw - Struct containing variables accessed by shared code
908 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
909 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
911 *****************************************************************************/
912 static int e1000_validate_eeprom_checksum(struct e1000_hw *hw)
914 uint16_t i, checksum, checksum_reg, *buf;
918 /* Allocate a temporary buffer */
919 buf = malloc(sizeof(buf[0]) * (EEPROM_CHECKSUM_REG + 1));
921 E1000_ERR(hw, "Unable to allocate EEPROM buffer!\n");
922 return -E1000_ERR_EEPROM;
925 /* Read the EEPROM */
926 if (e1000_read_eeprom(hw, 0, EEPROM_CHECKSUM_REG + 1, buf) < 0) {
927 E1000_ERR(hw, "Unable to read EEPROM!\n");
928 return -E1000_ERR_EEPROM;
931 /* Compute the checksum */
933 for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
935 checksum = ((uint16_t)EEPROM_SUM) - checksum;
936 checksum_reg = buf[i];
939 if (checksum == checksum_reg)
942 /* Hrm, verification failed, print an error */
943 E1000_ERR(hw, "EEPROM checksum is incorrect!\n");
944 E1000_ERR(hw, " ...register was 0x%04hx, calculated 0x%04hx\n",
945 checksum_reg, checksum);
947 return -E1000_ERR_EEPROM;
949 #endif /* CONFIG_E1000_NO_NVM */
951 /*****************************************************************************
952 * Set PHY to class A mode
953 * Assumes the following operations will follow to enable the new class mode.
954 * 1. Do a PHY soft reset
955 * 2. Restart auto-negotiation or force link.
957 * hw - Struct containing variables accessed by shared code
958 ****************************************************************************/
960 e1000_set_phy_mode(struct e1000_hw *hw)
962 #ifndef CONFIG_E1000_NO_NVM
964 uint16_t eeprom_data;
968 if ((hw->mac_type == e1000_82545_rev_3) &&
969 (hw->media_type == e1000_media_type_copper)) {
970 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD,
975 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
976 (eeprom_data & EEPROM_PHY_CLASS_A)) {
977 ret_val = e1000_write_phy_reg(hw,
978 M88E1000_PHY_PAGE_SELECT, 0x000B);
981 ret_val = e1000_write_phy_reg(hw,
982 M88E1000_PHY_GEN_CONTROL, 0x8104);
986 hw->phy_reset_disable = false;
990 return E1000_SUCCESS;
993 #ifndef CONFIG_E1000_NO_NVM
994 /***************************************************************************
996 * Obtaining software semaphore bit (SMBI) before resetting PHY.
998 * hw: Struct containing variables accessed by shared code
1000 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
1001 * E1000_SUCCESS at any other case.
1003 ***************************************************************************/
1005 e1000_get_software_semaphore(struct e1000_hw *hw)
1007 int32_t timeout = hw->eeprom.word_size + 1;
1012 if (hw->mac_type != e1000_80003es2lan)
1013 return E1000_SUCCESS;
1016 swsm = E1000_READ_REG(hw, SWSM);
1017 /* If SMBI bit cleared, it is now set and we hold
1019 if (!(swsm & E1000_SWSM_SMBI))
1026 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
1027 return -E1000_ERR_RESET;
1030 return E1000_SUCCESS;
1034 /***************************************************************************
1035 * This function clears HW semaphore bits.
1037 * hw: Struct containing variables accessed by shared code
1041 ***************************************************************************/
1043 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
1045 #ifndef CONFIG_E1000_NO_NVM
1050 if (!hw->eeprom_semaphore_present)
1053 swsm = E1000_READ_REG(hw, SWSM);
1054 if (hw->mac_type == e1000_80003es2lan) {
1055 /* Release both semaphores. */
1056 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1058 swsm &= ~(E1000_SWSM_SWESMBI);
1059 E1000_WRITE_REG(hw, SWSM, swsm);
1063 /***************************************************************************
1065 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
1066 * adapter or Eeprom access.
1068 * hw: Struct containing variables accessed by shared code
1070 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
1071 * E1000_SUCCESS at any other case.
1073 ***************************************************************************/
1075 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
1077 #ifndef CONFIG_E1000_NO_NVM
1083 if (!hw->eeprom_semaphore_present)
1084 return E1000_SUCCESS;
1086 if (hw->mac_type == e1000_80003es2lan) {
1087 /* Get the SW semaphore. */
1088 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
1089 return -E1000_ERR_EEPROM;
1092 /* Get the FW semaphore. */
1093 timeout = hw->eeprom.word_size + 1;
1095 swsm = E1000_READ_REG(hw, SWSM);
1096 swsm |= E1000_SWSM_SWESMBI;
1097 E1000_WRITE_REG(hw, SWSM, swsm);
1098 /* if we managed to set the bit we got the semaphore. */
1099 swsm = E1000_READ_REG(hw, SWSM);
1100 if (swsm & E1000_SWSM_SWESMBI)
1108 /* Release semaphores */
1109 e1000_put_hw_eeprom_semaphore(hw);
1110 DEBUGOUT("Driver can't access the Eeprom - "
1111 "SWESMBI bit is set.\n");
1112 return -E1000_ERR_EEPROM;
1115 return E1000_SUCCESS;
1118 /* Take ownership of the PHY */
1120 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
1122 uint32_t swfw_sync = 0;
1123 uint32_t swmask = mask;
1124 uint32_t fwmask = mask << 16;
1125 int32_t timeout = 200;
1129 if (e1000_get_hw_eeprom_semaphore(hw))
1130 return -E1000_ERR_SWFW_SYNC;
1132 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
1133 if (!(swfw_sync & (fwmask | swmask)))
1136 /* firmware currently using resource (fwmask) */
1137 /* or other software thread currently using resource (swmask) */
1138 e1000_put_hw_eeprom_semaphore(hw);
1144 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
1145 return -E1000_ERR_SWFW_SYNC;
1148 swfw_sync |= swmask;
1149 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
1151 e1000_put_hw_eeprom_semaphore(hw);
1152 return E1000_SUCCESS;
1155 static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
1157 uint32_t swfw_sync = 0;
1160 while (e1000_get_hw_eeprom_semaphore(hw))
1163 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
1165 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
1167 e1000_put_hw_eeprom_semaphore(hw);
1170 static bool e1000_is_second_port(struct e1000_hw *hw)
1172 switch (hw->mac_type) {
1173 case e1000_80003es2lan:
1176 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
1184 #ifndef CONFIG_E1000_NO_NVM
1185 /******************************************************************************
1186 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
1187 * second function of dual function devices
1189 * nic - Struct containing variables accessed by shared code
1190 *****************************************************************************/
1192 e1000_read_mac_addr(struct e1000_hw *hw, unsigned char enetaddr[6])
1195 uint16_t eeprom_data;
1196 uint32_t reg_data = 0;
1201 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
1203 if (hw->mac_type == e1000_igb) {
1204 /* i210 preloads MAC address into RAL/RAH registers */
1206 reg_data = E1000_READ_REG_ARRAY(hw, RA, 0);
1207 else if (offset == 1)
1209 else if (offset == 2)
1210 reg_data = E1000_READ_REG_ARRAY(hw, RA, 1);
1211 eeprom_data = reg_data & 0xffff;
1212 } else if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
1213 DEBUGOUT("EEPROM Read Error\n");
1214 return -E1000_ERR_EEPROM;
1216 enetaddr[i] = eeprom_data & 0xff;
1217 enetaddr[i + 1] = (eeprom_data >> 8) & 0xff;
1220 /* Invert the last bit if this is the second device */
1221 if (e1000_is_second_port(hw))
1228 /******************************************************************************
1229 * Initializes receive address filters.
1231 * hw - Struct containing variables accessed by shared code
1233 * Places the MAC address in receive address register 0 and clears the rest
1234 * of the receive addresss registers. Clears the multicast table. Assumes
1235 * the receiver is in reset when the routine is called.
1236 *****************************************************************************/
1238 e1000_init_rx_addrs(struct e1000_hw *hw, unsigned char enetaddr[6])
1246 /* Setup the receive address. */
1247 DEBUGOUT("Programming MAC Address into RAR[0]\n");
1248 addr_low = (enetaddr[0] |
1249 (enetaddr[1] << 8) |
1250 (enetaddr[2] << 16) | (enetaddr[3] << 24));
1252 addr_high = (enetaddr[4] | (enetaddr[5] << 8) | E1000_RAH_AV);
1254 E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
1255 E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
1257 /* Zero out the other 15 receive addresses. */
1258 DEBUGOUT("Clearing RAR[1-15]\n");
1259 for (i = 1; i < E1000_RAR_ENTRIES; i++) {
1260 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
1261 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
1265 /******************************************************************************
1266 * Clears the VLAN filer table
1268 * hw - Struct containing variables accessed by shared code
1269 *****************************************************************************/
1271 e1000_clear_vfta(struct e1000_hw *hw)
1275 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
1276 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
1279 /******************************************************************************
1280 * Set the mac type member in the hw struct.
1282 * hw - Struct containing variables accessed by shared code
1283 *****************************************************************************/
1285 e1000_set_mac_type(struct e1000_hw *hw)
1289 switch (hw->device_id) {
1290 case E1000_DEV_ID_82542:
1291 switch (hw->revision_id) {
1292 case E1000_82542_2_0_REV_ID:
1293 hw->mac_type = e1000_82542_rev2_0;
1295 case E1000_82542_2_1_REV_ID:
1296 hw->mac_type = e1000_82542_rev2_1;
1299 /* Invalid 82542 revision ID */
1300 return -E1000_ERR_MAC_TYPE;
1303 case E1000_DEV_ID_82543GC_FIBER:
1304 case E1000_DEV_ID_82543GC_COPPER:
1305 hw->mac_type = e1000_82543;
1307 case E1000_DEV_ID_82544EI_COPPER:
1308 case E1000_DEV_ID_82544EI_FIBER:
1309 case E1000_DEV_ID_82544GC_COPPER:
1310 case E1000_DEV_ID_82544GC_LOM:
1311 hw->mac_type = e1000_82544;
1313 case E1000_DEV_ID_82540EM:
1314 case E1000_DEV_ID_82540EM_LOM:
1315 case E1000_DEV_ID_82540EP:
1316 case E1000_DEV_ID_82540EP_LOM:
1317 case E1000_DEV_ID_82540EP_LP:
1318 hw->mac_type = e1000_82540;
1320 case E1000_DEV_ID_82545EM_COPPER:
1321 case E1000_DEV_ID_82545EM_FIBER:
1322 hw->mac_type = e1000_82545;
1324 case E1000_DEV_ID_82545GM_COPPER:
1325 case E1000_DEV_ID_82545GM_FIBER:
1326 case E1000_DEV_ID_82545GM_SERDES:
1327 hw->mac_type = e1000_82545_rev_3;
1329 case E1000_DEV_ID_82546EB_COPPER:
1330 case E1000_DEV_ID_82546EB_FIBER:
1331 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1332 hw->mac_type = e1000_82546;
1334 case E1000_DEV_ID_82546GB_COPPER:
1335 case E1000_DEV_ID_82546GB_FIBER:
1336 case E1000_DEV_ID_82546GB_SERDES:
1337 case E1000_DEV_ID_82546GB_PCIE:
1338 case E1000_DEV_ID_82546GB_QUAD_COPPER:
1339 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1340 hw->mac_type = e1000_82546_rev_3;
1342 case E1000_DEV_ID_82541EI:
1343 case E1000_DEV_ID_82541EI_MOBILE:
1344 case E1000_DEV_ID_82541ER_LOM:
1345 hw->mac_type = e1000_82541;
1347 case E1000_DEV_ID_82541ER:
1348 case E1000_DEV_ID_82541GI:
1349 case E1000_DEV_ID_82541GI_LF:
1350 case E1000_DEV_ID_82541GI_MOBILE:
1351 hw->mac_type = e1000_82541_rev_2;
1353 case E1000_DEV_ID_82547EI:
1354 case E1000_DEV_ID_82547EI_MOBILE:
1355 hw->mac_type = e1000_82547;
1357 case E1000_DEV_ID_82547GI:
1358 hw->mac_type = e1000_82547_rev_2;
1360 case E1000_DEV_ID_82571EB_COPPER:
1361 case E1000_DEV_ID_82571EB_FIBER:
1362 case E1000_DEV_ID_82571EB_SERDES:
1363 case E1000_DEV_ID_82571EB_SERDES_DUAL:
1364 case E1000_DEV_ID_82571EB_SERDES_QUAD:
1365 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1366 case E1000_DEV_ID_82571PT_QUAD_COPPER:
1367 case E1000_DEV_ID_82571EB_QUAD_FIBER:
1368 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1369 hw->mac_type = e1000_82571;
1371 case E1000_DEV_ID_82572EI_COPPER:
1372 case E1000_DEV_ID_82572EI_FIBER:
1373 case E1000_DEV_ID_82572EI_SERDES:
1374 case E1000_DEV_ID_82572EI:
1375 hw->mac_type = e1000_82572;
1377 case E1000_DEV_ID_82573E:
1378 case E1000_DEV_ID_82573E_IAMT:
1379 case E1000_DEV_ID_82573L:
1380 hw->mac_type = e1000_82573;
1382 case E1000_DEV_ID_82574L:
1383 hw->mac_type = e1000_82574;
1385 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
1386 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
1387 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
1388 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
1389 hw->mac_type = e1000_80003es2lan;
1391 case E1000_DEV_ID_ICH8_IGP_M_AMT:
1392 case E1000_DEV_ID_ICH8_IGP_AMT:
1393 case E1000_DEV_ID_ICH8_IGP_C:
1394 case E1000_DEV_ID_ICH8_IFE:
1395 case E1000_DEV_ID_ICH8_IFE_GT:
1396 case E1000_DEV_ID_ICH8_IFE_G:
1397 case E1000_DEV_ID_ICH8_IGP_M:
1398 hw->mac_type = e1000_ich8lan;
1400 case PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED:
1401 case PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED:
1402 case PCI_DEVICE_ID_INTEL_I210_COPPER:
1403 case PCI_DEVICE_ID_INTEL_I211_COPPER:
1404 case PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS:
1405 case PCI_DEVICE_ID_INTEL_I210_SERDES:
1406 case PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS:
1407 case PCI_DEVICE_ID_INTEL_I210_1000BASEKX:
1408 hw->mac_type = e1000_igb;
1411 /* Should never have loaded on this device */
1412 return -E1000_ERR_MAC_TYPE;
1414 return E1000_SUCCESS;
1417 /******************************************************************************
1418 * Reset the transmit and receive units; mask and clear all interrupts.
1420 * hw - Struct containing variables accessed by shared code
1421 *****************************************************************************/
1423 e1000_reset_hw(struct e1000_hw *hw)
1433 /* get the correct pba value for both PCI and PCIe*/
1434 if (hw->mac_type < e1000_82571)
1435 pba = E1000_DEFAULT_PCI_PBA;
1437 pba = E1000_DEFAULT_PCIE_PBA;
1439 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
1440 if (hw->mac_type == e1000_82542_rev2_0) {
1441 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1442 pci_write_config_word(hw->pdev, PCI_COMMAND,
1443 hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1446 /* Clear interrupt mask to stop board from generating interrupts */
1447 DEBUGOUT("Masking off all interrupts\n");
1448 if (hw->mac_type == e1000_igb)
1449 E1000_WRITE_REG(hw, I210_IAM, 0);
1450 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1452 /* Disable the Transmit and Receive units. Then delay to allow
1453 * any pending transactions to complete before we hit the MAC with
1456 E1000_WRITE_REG(hw, RCTL, 0);
1457 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
1458 E1000_WRITE_FLUSH(hw);
1460 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
1461 hw->tbi_compatibility_on = false;
1463 /* Delay to allow any outstanding PCI transactions to complete before
1464 * resetting the device
1468 /* Issue a global reset to the MAC. This will reset the chip's
1469 * transmit, receive, DMA, and link units. It will not effect
1470 * the current PCI configuration. The global reset bit is self-
1471 * clearing, and should clear within a microsecond.
1473 DEBUGOUT("Issuing a global reset to MAC\n");
1474 ctrl = E1000_READ_REG(hw, CTRL);
1476 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
1478 /* Force a reload from the EEPROM if necessary */
1479 if (hw->mac_type == e1000_igb) {
1481 reg = E1000_READ_REG(hw, STATUS);
1482 if (reg & E1000_STATUS_PF_RST_DONE)
1483 DEBUGOUT("PF OK\n");
1484 reg = E1000_READ_REG(hw, I210_EECD);
1485 if (reg & E1000_EECD_AUTO_RD)
1486 DEBUGOUT("EEC OK\n");
1487 } else if (hw->mac_type < e1000_82540) {
1488 /* Wait for reset to complete */
1490 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1491 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1492 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1493 E1000_WRITE_FLUSH(hw);
1494 /* Wait for EEPROM reload */
1497 /* Wait for EEPROM reload (it happens automatically) */
1499 /* Dissable HW ARPs on ASF enabled adapters */
1500 manc = E1000_READ_REG(hw, MANC);
1501 manc &= ~(E1000_MANC_ARP_EN);
1502 E1000_WRITE_REG(hw, MANC, manc);
1505 /* Clear interrupt mask to stop board from generating interrupts */
1506 DEBUGOUT("Masking off all interrupts\n");
1507 if (hw->mac_type == e1000_igb)
1508 E1000_WRITE_REG(hw, I210_IAM, 0);
1509 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1511 /* Clear any pending interrupt events. */
1512 E1000_READ_REG(hw, ICR);
1514 /* If MWI was previously enabled, reenable it. */
1515 if (hw->mac_type == e1000_82542_rev2_0) {
1516 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1518 if (hw->mac_type != e1000_igb)
1519 E1000_WRITE_REG(hw, PBA, pba);
1522 /******************************************************************************
1524 * Initialize a number of hardware-dependent bits
1526 * hw: Struct containing variables accessed by shared code
1528 * This function contains hardware limitation workarounds for PCI-E adapters
1530 *****************************************************************************/
1532 e1000_initialize_hardware_bits(struct e1000_hw *hw)
1534 if ((hw->mac_type >= e1000_82571) &&
1535 (!hw->initialize_hw_bits_disable)) {
1536 /* Settings common to all PCI-express silicon */
1537 uint32_t reg_ctrl, reg_ctrl_ext;
1538 uint32_t reg_tarc0, reg_tarc1;
1540 uint32_t reg_txdctl, reg_txdctl1;
1542 /* link autonegotiation/sync workarounds */
1543 reg_tarc0 = E1000_READ_REG(hw, TARC0);
1544 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
1546 /* Enable not-done TX descriptor counting */
1547 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
1548 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
1549 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
1551 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
1552 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
1553 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
1556 if (hw->mac_type == e1000_igb)
1559 switch (hw->mac_type) {
1562 /* Clear PHY TX compatible mode bits */
1563 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1564 reg_tarc1 &= ~((1 << 30)|(1 << 29));
1566 /* link autonegotiation/sync workarounds */
1567 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
1569 /* TX ring control fixes */
1570 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
1572 /* Multiple read bit is reversed polarity */
1573 reg_tctl = E1000_READ_REG(hw, TCTL);
1574 if (reg_tctl & E1000_TCTL_MULR)
1575 reg_tarc1 &= ~(1 << 28);
1577 reg_tarc1 |= (1 << 28);
1579 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1583 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1584 reg_ctrl_ext &= ~(1 << 23);
1585 reg_ctrl_ext |= (1 << 22);
1587 /* TX byte count fix */
1588 reg_ctrl = E1000_READ_REG(hw, CTRL);
1589 reg_ctrl &= ~(1 << 29);
1591 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1592 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
1594 case e1000_80003es2lan:
1595 /* improve small packet performace for fiber/serdes */
1596 if ((hw->media_type == e1000_media_type_fiber)
1597 || (hw->media_type ==
1598 e1000_media_type_internal_serdes)) {
1599 reg_tarc0 &= ~(1 << 20);
1602 /* Multiple read bit is reversed polarity */
1603 reg_tctl = E1000_READ_REG(hw, TCTL);
1604 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1605 if (reg_tctl & E1000_TCTL_MULR)
1606 reg_tarc1 &= ~(1 << 28);
1608 reg_tarc1 |= (1 << 28);
1610 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1613 /* Reduce concurrent DMA requests to 3 from 4 */
1614 if ((hw->revision_id < 3) ||
1615 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1616 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
1617 reg_tarc0 |= ((1 << 29)|(1 << 28));
1619 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1620 reg_ctrl_ext |= (1 << 22);
1621 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1623 /* workaround TX hang with TSO=on */
1624 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
1626 /* Multiple read bit is reversed polarity */
1627 reg_tctl = E1000_READ_REG(hw, TCTL);
1628 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1629 if (reg_tctl & E1000_TCTL_MULR)
1630 reg_tarc1 &= ~(1 << 28);
1632 reg_tarc1 |= (1 << 28);
1634 /* workaround TX hang with TSO=on */
1635 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
1637 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1643 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
1647 /******************************************************************************
1648 * Performs basic configuration of the adapter.
1650 * hw - Struct containing variables accessed by shared code
1652 * Assumes that the controller has previously been reset and is in a
1653 * post-reset uninitialized state. Initializes the receive address registers,
1654 * multicast table, and VLAN filter table. Calls routines to setup link
1655 * configuration and flow control settings. Clears all on-chip counters. Leaves
1656 * the transmit and receive units disabled and uninitialized.
1657 *****************************************************************************/
1659 e1000_init_hw(struct e1000_hw *hw, unsigned char enetaddr[6])
1664 uint16_t pcix_cmd_word;
1665 uint16_t pcix_stat_hi_word;
1667 uint16_t stat_mmrbc;
1672 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
1673 if ((hw->mac_type == e1000_ich8lan) &&
1674 ((hw->revision_id < 3) ||
1675 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1676 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
1677 reg_data = E1000_READ_REG(hw, STATUS);
1678 reg_data &= ~0x80000000;
1679 E1000_WRITE_REG(hw, STATUS, reg_data);
1681 /* Do not need initialize Identification LED */
1683 /* Set the media type and TBI compatibility */
1684 e1000_set_media_type(hw);
1686 /* Must be called after e1000_set_media_type
1687 * because media_type is used */
1688 e1000_initialize_hardware_bits(hw);
1690 /* Disabling VLAN filtering. */
1691 DEBUGOUT("Initializing the IEEE VLAN\n");
1692 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
1693 if (hw->mac_type != e1000_ich8lan) {
1694 if (hw->mac_type < e1000_82545_rev_3)
1695 E1000_WRITE_REG(hw, VET, 0);
1696 e1000_clear_vfta(hw);
1699 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
1700 if (hw->mac_type == e1000_82542_rev2_0) {
1701 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1702 pci_write_config_word(hw->pdev, PCI_COMMAND,
1704 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1705 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
1706 E1000_WRITE_FLUSH(hw);
1710 /* Setup the receive address. This involves initializing all of the Receive
1711 * Address Registers (RARs 0 - 15).
1713 e1000_init_rx_addrs(hw, enetaddr);
1715 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
1716 if (hw->mac_type == e1000_82542_rev2_0) {
1717 E1000_WRITE_REG(hw, RCTL, 0);
1718 E1000_WRITE_FLUSH(hw);
1720 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1723 /* Zero out the Multicast HASH table */
1724 DEBUGOUT("Zeroing the MTA\n");
1725 mta_size = E1000_MC_TBL_SIZE;
1726 if (hw->mac_type == e1000_ich8lan)
1727 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
1728 for (i = 0; i < mta_size; i++) {
1729 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
1730 /* use write flush to prevent Memory Write Block (MWB) from
1731 * occuring when accessing our register space */
1732 E1000_WRITE_FLUSH(hw);
1735 /* Set the PCI priority bit correctly in the CTRL register. This
1736 * determines if the adapter gives priority to receives, or if it
1737 * gives equal priority to transmits and receives. Valid only on
1738 * 82542 and 82543 silicon.
1740 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
1741 ctrl = E1000_READ_REG(hw, CTRL);
1742 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
1745 switch (hw->mac_type) {
1746 case e1000_82545_rev_3:
1747 case e1000_82546_rev_3:
1751 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
1752 if (hw->bus_type == e1000_bus_type_pcix) {
1753 pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
1755 pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI,
1756 &pcix_stat_hi_word);
1758 (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
1759 PCIX_COMMAND_MMRBC_SHIFT;
1761 (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
1762 PCIX_STATUS_HI_MMRBC_SHIFT;
1763 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
1764 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
1765 if (cmd_mmrbc > stat_mmrbc) {
1766 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
1767 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
1768 pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
1775 /* More time needed for PHY to initialize */
1776 if (hw->mac_type == e1000_ich8lan)
1778 if (hw->mac_type == e1000_igb)
1781 /* Call a subroutine to configure the link and setup flow control. */
1782 ret_val = e1000_setup_link(hw);
1784 /* Set the transmit descriptor write-back policy */
1785 if (hw->mac_type > e1000_82544) {
1786 ctrl = E1000_READ_REG(hw, TXDCTL);
1788 (ctrl & ~E1000_TXDCTL_WTHRESH) |
1789 E1000_TXDCTL_FULL_TX_DESC_WB;
1790 E1000_WRITE_REG(hw, TXDCTL, ctrl);
1793 /* Set the receive descriptor write back policy */
1794 if (hw->mac_type >= e1000_82571) {
1795 ctrl = E1000_READ_REG(hw, RXDCTL);
1797 (ctrl & ~E1000_RXDCTL_WTHRESH) |
1798 E1000_RXDCTL_FULL_RX_DESC_WB;
1799 E1000_WRITE_REG(hw, RXDCTL, ctrl);
1802 switch (hw->mac_type) {
1805 case e1000_80003es2lan:
1806 /* Enable retransmit on late collisions */
1807 reg_data = E1000_READ_REG(hw, TCTL);
1808 reg_data |= E1000_TCTL_RTLC;
1809 E1000_WRITE_REG(hw, TCTL, reg_data);
1811 /* Configure Gigabit Carry Extend Padding */
1812 reg_data = E1000_READ_REG(hw, TCTL_EXT);
1813 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
1814 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
1815 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1817 /* Configure Transmit Inter-Packet Gap */
1818 reg_data = E1000_READ_REG(hw, TIPG);
1819 reg_data &= ~E1000_TIPG_IPGT_MASK;
1820 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1821 E1000_WRITE_REG(hw, TIPG, reg_data);
1823 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1824 reg_data &= ~0x00100000;
1825 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1830 ctrl = E1000_READ_REG(hw, TXDCTL1);
1831 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH)
1832 | E1000_TXDCTL_FULL_TX_DESC_WB;
1833 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1837 reg_data = E1000_READ_REG(hw, GCR);
1838 reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1839 E1000_WRITE_REG(hw, GCR, reg_data);
1845 /* Clear all of the statistics registers (clear on read). It is
1846 * important that we do this after we have tried to establish link
1847 * because the symbol error count will increment wildly if there
1850 e1000_clear_hw_cntrs(hw);
1852 /* ICH8 No-snoop bits are opposite polarity.
1853 * Set to snoop by default after reset. */
1854 if (hw->mac_type == e1000_ich8lan)
1855 e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
1858 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1859 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1860 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1861 /* Relaxed ordering must be disabled to avoid a parity
1862 * error crash in a PCI slot. */
1863 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1864 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1870 /******************************************************************************
1871 * Configures flow control and link settings.
1873 * hw - Struct containing variables accessed by shared code
1875 * Determines which flow control settings to use. Calls the apropriate media-
1876 * specific link configuration function. Configures the flow control settings.
1877 * Assuming the adapter has a valid link partner, a valid link should be
1878 * established. Assumes the hardware has previously been reset and the
1879 * transmitter and receiver are not enabled.
1880 *****************************************************************************/
1882 e1000_setup_link(struct e1000_hw *hw)
1885 #ifndef CONFIG_E1000_NO_NVM
1887 uint16_t eeprom_data;
1892 /* In the case of the phy reset being blocked, we already have a link.
1893 * We do not have to set it up again. */
1894 if (e1000_check_phy_reset_block(hw))
1895 return E1000_SUCCESS;
1897 #ifndef CONFIG_E1000_NO_NVM
1898 /* Read and store word 0x0F of the EEPROM. This word contains bits
1899 * that determine the hardware's default PAUSE (flow control) mode,
1900 * a bit that determines whether the HW defaults to enabling or
1901 * disabling auto-negotiation, and the direction of the
1902 * SW defined pins. If there is no SW over-ride of the flow
1903 * control setting, then the variable hw->fc will
1904 * be initialized based on a value in the EEPROM.
1906 if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1,
1907 &eeprom_data) < 0) {
1908 DEBUGOUT("EEPROM Read Error\n");
1909 return -E1000_ERR_EEPROM;
1912 if (hw->fc == e1000_fc_default) {
1913 switch (hw->mac_type) {
1918 hw->fc = e1000_fc_full;
1921 #ifndef CONFIG_E1000_NO_NVM
1922 ret_val = e1000_read_eeprom(hw,
1923 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1925 DEBUGOUT("EEPROM Read Error\n");
1926 return -E1000_ERR_EEPROM;
1928 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1929 hw->fc = e1000_fc_none;
1930 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1931 EEPROM_WORD0F_ASM_DIR)
1932 hw->fc = e1000_fc_tx_pause;
1935 hw->fc = e1000_fc_full;
1940 /* We want to save off the original Flow Control configuration just
1941 * in case we get disconnected and then reconnected into a different
1942 * hub or switch with different Flow Control capabilities.
1944 if (hw->mac_type == e1000_82542_rev2_0)
1945 hw->fc &= (~e1000_fc_tx_pause);
1947 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
1948 hw->fc &= (~e1000_fc_rx_pause);
1950 hw->original_fc = hw->fc;
1952 DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc);
1954 #ifndef CONFIG_E1000_NO_NVM
1955 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1956 * polarity value for the SW controlled pins, and setup the
1957 * Extended Device Control reg with that info.
1958 * This is needed because one of the SW controlled pins is used for
1959 * signal detection. So this should be done before e1000_setup_pcs_link()
1960 * or e1000_phy_setup() is called.
1962 if (hw->mac_type == e1000_82543) {
1963 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1965 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1969 /* Call the necessary subroutine to configure the link. */
1970 ret_val = (hw->media_type == e1000_media_type_fiber) ?
1971 e1000_setup_fiber_link(hw) : e1000_setup_copper_link(hw);
1976 /* Initialize the flow control address, type, and PAUSE timer
1977 * registers to their default values. This is done even if flow
1978 * control is disabled, because it does not hurt anything to
1979 * initialize these registers.
1981 DEBUGOUT("Initializing the Flow Control address, type"
1982 "and timer regs\n");
1984 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1985 if (hw->mac_type != e1000_ich8lan) {
1986 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1987 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1988 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1991 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1993 /* Set the flow control receive threshold registers. Normally,
1994 * these registers will be set to a default threshold that may be
1995 * adjusted later by the driver's runtime code. However, if the
1996 * ability to transmit pause frames in not enabled, then these
1997 * registers will be set to 0.
1999 if (!(hw->fc & e1000_fc_tx_pause)) {
2000 E1000_WRITE_REG(hw, FCRTL, 0);
2001 E1000_WRITE_REG(hw, FCRTH, 0);
2003 /* We need to set up the Receive Threshold high and low water marks
2004 * as well as (optionally) enabling the transmission of XON frames.
2006 if (hw->fc_send_xon) {
2007 E1000_WRITE_REG(hw, FCRTL,
2008 (hw->fc_low_water | E1000_FCRTL_XONE));
2009 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
2011 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
2012 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
2018 /******************************************************************************
2019 * Sets up link for a fiber based adapter
2021 * hw - Struct containing variables accessed by shared code
2023 * Manipulates Physical Coding Sublayer functions in order to configure
2024 * link. Assumes the hardware has been previously reset and the transmitter
2025 * and receiver are not enabled.
2026 *****************************************************************************/
2028 e1000_setup_fiber_link(struct e1000_hw *hw)
2038 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
2039 * set when the optics detect a signal. On older adapters, it will be
2040 * cleared when there is a signal
2042 ctrl = E1000_READ_REG(hw, CTRL);
2043 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
2044 signal = E1000_CTRL_SWDPIN1;
2048 printf("signal for %s is %x (ctrl %08x)!!!!\n", hw->name, signal,
2050 /* Take the link out of reset */
2051 ctrl &= ~(E1000_CTRL_LRST);
2053 e1000_config_collision_dist(hw);
2055 /* Check for a software override of the flow control settings, and setup
2056 * the device accordingly. If auto-negotiation is enabled, then software
2057 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
2058 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
2059 * auto-negotiation is disabled, then software will have to manually
2060 * configure the two flow control enable bits in the CTRL register.
2062 * The possible values of the "fc" parameter are:
2063 * 0: Flow control is completely disabled
2064 * 1: Rx flow control is enabled (we can receive pause frames, but
2065 * not send pause frames).
2066 * 2: Tx flow control is enabled (we can send pause frames but we do
2067 * not support receiving pause frames).
2068 * 3: Both Rx and TX flow control (symmetric) are enabled.
2072 /* Flow control is completely disabled by a software over-ride. */
2073 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
2075 case e1000_fc_rx_pause:
2076 /* RX Flow control is enabled and TX Flow control is disabled by a
2077 * software over-ride. Since there really isn't a way to advertise
2078 * that we are capable of RX Pause ONLY, we will advertise that we
2079 * support both symmetric and asymmetric RX PAUSE. Later, we will
2080 * disable the adapter's ability to send PAUSE frames.
2082 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
2084 case e1000_fc_tx_pause:
2085 /* TX Flow control is enabled, and RX Flow control is disabled, by a
2086 * software over-ride.
2088 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
2091 /* Flow control (both RX and TX) is enabled by a software over-ride. */
2092 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
2095 DEBUGOUT("Flow control param set incorrectly\n");
2096 return -E1000_ERR_CONFIG;
2100 /* Since auto-negotiation is enabled, take the link out of reset (the link
2101 * will be in reset, because we previously reset the chip). This will
2102 * restart auto-negotiation. If auto-neogtiation is successful then the
2103 * link-up status bit will be set and the flow control enable bits (RFCE
2104 * and TFCE) will be set according to their negotiated value.
2106 DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw);
2108 E1000_WRITE_REG(hw, TXCW, txcw);
2109 E1000_WRITE_REG(hw, CTRL, ctrl);
2110 E1000_WRITE_FLUSH(hw);
2115 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
2116 * indication in the Device Status Register. Time-out if a link isn't
2117 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
2118 * less than 500 milliseconds even if the other end is doing it in SW).
2120 if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
2121 DEBUGOUT("Looking for Link\n");
2122 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
2124 status = E1000_READ_REG(hw, STATUS);
2125 if (status & E1000_STATUS_LU)
2128 if (i == (LINK_UP_TIMEOUT / 10)) {
2129 /* AutoNeg failed to achieve a link, so we'll call
2130 * e1000_check_for_link. This routine will force the link up if we
2131 * detect a signal. This will allow us to communicate with
2132 * non-autonegotiating link partners.
2134 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
2135 hw->autoneg_failed = 1;
2136 ret_val = e1000_check_for_link(hw);
2138 DEBUGOUT("Error while checking for link\n");
2141 hw->autoneg_failed = 0;
2143 hw->autoneg_failed = 0;
2144 DEBUGOUT("Valid Link Found\n");
2147 DEBUGOUT("No Signal Detected\n");
2148 return -E1000_ERR_NOLINK;
2153 /******************************************************************************
2154 * Make sure we have a valid PHY and change PHY mode before link setup.
2156 * hw - Struct containing variables accessed by shared code
2157 ******************************************************************************/
2159 e1000_copper_link_preconfig(struct e1000_hw *hw)
2167 ctrl = E1000_READ_REG(hw, CTRL);
2168 /* With 82543, we need to force speed and duplex on the MAC equal to what
2169 * the PHY speed and duplex configuration is. In addition, we need to
2170 * perform a hardware reset on the PHY to take it out of reset.
2172 if (hw->mac_type > e1000_82543) {
2173 ctrl |= E1000_CTRL_SLU;
2174 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2175 E1000_WRITE_REG(hw, CTRL, ctrl);
2177 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX
2179 E1000_WRITE_REG(hw, CTRL, ctrl);
2180 ret_val = e1000_phy_hw_reset(hw);
2185 /* Make sure we have a valid PHY */
2186 ret_val = e1000_detect_gig_phy(hw);
2188 DEBUGOUT("Error, did not detect valid phy.\n");
2191 DEBUGOUT("Phy ID = %x\n", hw->phy_id);
2193 /* Set PHY to class A mode (if necessary) */
2194 ret_val = e1000_set_phy_mode(hw);
2197 if ((hw->mac_type == e1000_82545_rev_3) ||
2198 (hw->mac_type == e1000_82546_rev_3)) {
2199 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2201 phy_data |= 0x00000008;
2202 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2206 if (hw->mac_type <= e1000_82543 ||
2207 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
2208 hw->mac_type == e1000_82541_rev_2
2209 || hw->mac_type == e1000_82547_rev_2)
2210 hw->phy_reset_disable = false;
2212 return E1000_SUCCESS;
2215 /*****************************************************************************
2217 * This function sets the lplu state according to the active flag. When
2218 * activating lplu this function also disables smart speed and vise versa.
2219 * lplu will not be activated unless the device autonegotiation advertisment
2220 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2221 * hw: Struct containing variables accessed by shared code
2222 * active - true to enable lplu false to disable lplu.
2224 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2225 * E1000_SUCCESS at any other case.
2227 ****************************************************************************/
2230 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
2232 uint32_t phy_ctrl = 0;
2237 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
2238 && hw->phy_type != e1000_phy_igp_3)
2239 return E1000_SUCCESS;
2241 /* During driver activity LPLU should not be used or it will attain link
2242 * from the lowest speeds starting from 10Mbps. The capability is used
2243 * for Dx transitions and states */
2244 if (hw->mac_type == e1000_82541_rev_2
2245 || hw->mac_type == e1000_82547_rev_2) {
2246 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
2250 } else if (hw->mac_type == e1000_ich8lan) {
2251 /* MAC writes into PHY register based on the state transition
2252 * and start auto-negotiation. SW driver can overwrite the
2253 * settings in CSR PHY power control E1000_PHY_CTRL register. */
2254 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
2256 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2263 if (hw->mac_type == e1000_82541_rev_2 ||
2264 hw->mac_type == e1000_82547_rev_2) {
2265 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
2266 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
2271 if (hw->mac_type == e1000_ich8lan) {
2272 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2273 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2275 phy_data &= ~IGP02E1000_PM_D3_LPLU;
2276 ret_val = e1000_write_phy_reg(hw,
2277 IGP02E1000_PHY_POWER_MGMT, phy_data);
2283 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2284 * Dx states where the power conservation is most important. During
2285 * driver activity we should enable SmartSpeed, so performance is
2287 if (hw->smart_speed == e1000_smart_speed_on) {
2288 ret_val = e1000_read_phy_reg(hw,
2289 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2293 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2294 ret_val = e1000_write_phy_reg(hw,
2295 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2298 } else if (hw->smart_speed == e1000_smart_speed_off) {
2299 ret_val = e1000_read_phy_reg(hw,
2300 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2304 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2305 ret_val = e1000_write_phy_reg(hw,
2306 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2311 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
2312 || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) ||
2313 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
2315 if (hw->mac_type == e1000_82541_rev_2 ||
2316 hw->mac_type == e1000_82547_rev_2) {
2317 phy_data |= IGP01E1000_GMII_FLEX_SPD;
2318 ret_val = e1000_write_phy_reg(hw,
2319 IGP01E1000_GMII_FIFO, phy_data);
2323 if (hw->mac_type == e1000_ich8lan) {
2324 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2325 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2327 phy_data |= IGP02E1000_PM_D3_LPLU;
2328 ret_val = e1000_write_phy_reg(hw,
2329 IGP02E1000_PHY_POWER_MGMT, phy_data);
2335 /* When LPLU is enabled we should disable SmartSpeed */
2336 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2341 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2342 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2347 return E1000_SUCCESS;
2350 /*****************************************************************************
2352 * This function sets the lplu d0 state according to the active flag. When
2353 * activating lplu this function also disables smart speed and vise versa.
2354 * lplu will not be activated unless the device autonegotiation advertisment
2355 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2356 * hw: Struct containing variables accessed by shared code
2357 * active - true to enable lplu false to disable lplu.
2359 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2360 * E1000_SUCCESS at any other case.
2362 ****************************************************************************/
2365 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
2367 uint32_t phy_ctrl = 0;
2372 if (hw->mac_type <= e1000_82547_rev_2)
2373 return E1000_SUCCESS;
2375 if (hw->mac_type == e1000_ich8lan) {
2376 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
2377 } else if (hw->mac_type == e1000_igb) {
2378 phy_ctrl = E1000_READ_REG(hw, I210_PHY_CTRL);
2380 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2387 if (hw->mac_type == e1000_ich8lan) {
2388 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2389 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2390 } else if (hw->mac_type == e1000_igb) {
2391 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2392 E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
2394 phy_data &= ~IGP02E1000_PM_D0_LPLU;
2395 ret_val = e1000_write_phy_reg(hw,
2396 IGP02E1000_PHY_POWER_MGMT, phy_data);
2401 if (hw->mac_type == e1000_igb)
2402 return E1000_SUCCESS;
2404 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2405 * Dx states where the power conservation is most important. During
2406 * driver activity we should enable SmartSpeed, so performance is
2408 if (hw->smart_speed == e1000_smart_speed_on) {
2409 ret_val = e1000_read_phy_reg(hw,
2410 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2414 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2415 ret_val = e1000_write_phy_reg(hw,
2416 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2419 } else if (hw->smart_speed == e1000_smart_speed_off) {
2420 ret_val = e1000_read_phy_reg(hw,
2421 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2425 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2426 ret_val = e1000_write_phy_reg(hw,
2427 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2435 if (hw->mac_type == e1000_ich8lan) {
2436 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2437 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2438 } else if (hw->mac_type == e1000_igb) {
2439 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2440 E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
2442 phy_data |= IGP02E1000_PM_D0_LPLU;
2443 ret_val = e1000_write_phy_reg(hw,
2444 IGP02E1000_PHY_POWER_MGMT, phy_data);
2449 if (hw->mac_type == e1000_igb)
2450 return E1000_SUCCESS;
2452 /* When LPLU is enabled we should disable SmartSpeed */
2453 ret_val = e1000_read_phy_reg(hw,
2454 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2458 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2459 ret_val = e1000_write_phy_reg(hw,
2460 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2465 return E1000_SUCCESS;
2468 /********************************************************************
2469 * Copper link setup for e1000_phy_igp series.
2471 * hw - Struct containing variables accessed by shared code
2472 *********************************************************************/
2474 e1000_copper_link_igp_setup(struct e1000_hw *hw)
2482 if (hw->phy_reset_disable)
2483 return E1000_SUCCESS;
2485 ret_val = e1000_phy_reset(hw);
2487 DEBUGOUT("Error Resetting the PHY\n");
2491 /* Wait 15ms for MAC to configure PHY from eeprom settings */
2493 if (hw->mac_type != e1000_ich8lan) {
2494 /* Configure activity LED after PHY reset */
2495 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2496 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2497 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2498 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2501 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
2502 if (hw->phy_type == e1000_phy_igp) {
2503 /* disable lplu d3 during driver init */
2504 ret_val = e1000_set_d3_lplu_state(hw, false);
2506 DEBUGOUT("Error Disabling LPLU D3\n");
2511 /* disable lplu d0 during driver init */
2512 ret_val = e1000_set_d0_lplu_state(hw, false);
2514 DEBUGOUT("Error Disabling LPLU D0\n");
2517 /* Configure mdi-mdix settings */
2518 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2522 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2523 hw->dsp_config_state = e1000_dsp_config_disabled;
2524 /* Force MDI for earlier revs of the IGP PHY */
2525 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX
2526 | IGP01E1000_PSCR_FORCE_MDI_MDIX);
2530 hw->dsp_config_state = e1000_dsp_config_enabled;
2531 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2535 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2538 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
2542 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
2546 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2550 /* set auto-master slave resolution settings */
2552 e1000_ms_type phy_ms_setting = hw->master_slave;
2554 if (hw->ffe_config_state == e1000_ffe_config_active)
2555 hw->ffe_config_state = e1000_ffe_config_enabled;
2557 if (hw->dsp_config_state == e1000_dsp_config_activated)
2558 hw->dsp_config_state = e1000_dsp_config_enabled;
2560 /* when autonegotiation advertisment is only 1000Mbps then we
2561 * should disable SmartSpeed and enable Auto MasterSlave
2562 * resolution as hardware default. */
2563 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
2564 /* Disable SmartSpeed */
2565 ret_val = e1000_read_phy_reg(hw,
2566 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2569 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2570 ret_val = e1000_write_phy_reg(hw,
2571 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2574 /* Set auto Master/Slave resolution process */
2575 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
2579 phy_data &= ~CR_1000T_MS_ENABLE;
2580 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
2586 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
2590 /* load defaults for future use */
2591 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
2592 ((phy_data & CR_1000T_MS_VALUE) ?
2593 e1000_ms_force_master :
2594 e1000_ms_force_slave) :
2597 switch (phy_ms_setting) {
2598 case e1000_ms_force_master:
2599 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
2601 case e1000_ms_force_slave:
2602 phy_data |= CR_1000T_MS_ENABLE;
2603 phy_data &= ~(CR_1000T_MS_VALUE);
2606 phy_data &= ~CR_1000T_MS_ENABLE;
2610 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
2615 return E1000_SUCCESS;
2618 /*****************************************************************************
2619 * This function checks the mode of the firmware.
2621 * returns - true when the mode is IAMT or false.
2622 ****************************************************************************/
2624 e1000_check_mng_mode(struct e1000_hw *hw)
2629 fwsm = E1000_READ_REG(hw, FWSM);
2631 if (hw->mac_type == e1000_ich8lan) {
2632 if ((fwsm & E1000_FWSM_MODE_MASK) ==
2633 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
2635 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
2636 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
2643 e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data)
2645 uint16_t swfw = E1000_SWFW_PHY0_SM;
2649 if (e1000_is_second_port(hw))
2650 swfw = E1000_SWFW_PHY1_SM;
2652 if (e1000_swfw_sync_acquire(hw, swfw))
2653 return -E1000_ERR_SWFW_SYNC;
2655 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT)
2656 & E1000_KUMCTRLSTA_OFFSET) | data;
2657 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2660 return E1000_SUCCESS;
2664 e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data)
2666 uint16_t swfw = E1000_SWFW_PHY0_SM;
2670 if (e1000_is_second_port(hw))
2671 swfw = E1000_SWFW_PHY1_SM;
2673 if (e1000_swfw_sync_acquire(hw, swfw)) {
2674 debug("%s[%i]\n", __func__, __LINE__);
2675 return -E1000_ERR_SWFW_SYNC;
2678 /* Write register address */
2679 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
2680 E1000_KUMCTRLSTA_OFFSET) | E1000_KUMCTRLSTA_REN;
2681 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2684 /* Read the data returned */
2685 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
2686 *data = (uint16_t)reg_val;
2688 return E1000_SUCCESS;
2691 /********************************************************************
2692 * Copper link setup for e1000_phy_gg82563 series.
2694 * hw - Struct containing variables accessed by shared code
2695 *********************************************************************/
2697 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
2705 if (!hw->phy_reset_disable) {
2706 /* Enable CRS on TX for half-duplex operation. */
2707 ret_val = e1000_read_phy_reg(hw,
2708 GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2712 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2713 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
2714 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
2716 ret_val = e1000_write_phy_reg(hw,
2717 GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2722 * MDI/MDI-X = 0 (default)
2723 * 0 - Auto for all speeds
2726 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
2728 ret_val = e1000_read_phy_reg(hw,
2729 GG82563_PHY_SPEC_CTRL, &phy_data);
2733 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
2737 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
2740 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
2744 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
2749 * disable_polarity_correction = 0 (default)
2750 * Automatic Correction for Reversed Cable Polarity
2754 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
2755 ret_val = e1000_write_phy_reg(hw,
2756 GG82563_PHY_SPEC_CTRL, phy_data);
2761 /* SW Reset the PHY so all changes take effect */
2762 ret_val = e1000_phy_reset(hw);
2764 DEBUGOUT("Error Resetting the PHY\n");
2767 } /* phy_reset_disable */
2769 if (hw->mac_type == e1000_80003es2lan) {
2770 /* Bypass RX and TX FIFO's */
2771 ret_val = e1000_write_kmrn_reg(hw,
2772 E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
2773 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS
2774 | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
2778 ret_val = e1000_read_phy_reg(hw,
2779 GG82563_PHY_SPEC_CTRL_2, &phy_data);
2783 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
2784 ret_val = e1000_write_phy_reg(hw,
2785 GG82563_PHY_SPEC_CTRL_2, phy_data);
2790 reg_data = E1000_READ_REG(hw, CTRL_EXT);
2791 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
2792 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
2794 ret_val = e1000_read_phy_reg(hw,
2795 GG82563_PHY_PWR_MGMT_CTRL, &phy_data);
2799 /* Do not init these registers when the HW is in IAMT mode, since the
2800 * firmware will have already initialized them. We only initialize
2801 * them if the HW is not in IAMT mode.
2803 if (e1000_check_mng_mode(hw) == false) {
2804 /* Enable Electrical Idle on the PHY */
2805 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
2806 ret_val = e1000_write_phy_reg(hw,
2807 GG82563_PHY_PWR_MGMT_CTRL, phy_data);
2811 ret_val = e1000_read_phy_reg(hw,
2812 GG82563_PHY_KMRN_MODE_CTRL, &phy_data);
2816 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2817 ret_val = e1000_write_phy_reg(hw,
2818 GG82563_PHY_KMRN_MODE_CTRL, phy_data);
2824 /* Workaround: Disable padding in Kumeran interface in the MAC
2825 * and in the PHY to avoid CRC errors.
2827 ret_val = e1000_read_phy_reg(hw,
2828 GG82563_PHY_INBAND_CTRL, &phy_data);
2831 phy_data |= GG82563_ICR_DIS_PADDING;
2832 ret_val = e1000_write_phy_reg(hw,
2833 GG82563_PHY_INBAND_CTRL, phy_data);
2837 return E1000_SUCCESS;
2840 /********************************************************************
2841 * Copper link setup for e1000_phy_m88 series.
2843 * hw - Struct containing variables accessed by shared code
2844 *********************************************************************/
2846 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
2853 if (hw->phy_reset_disable)
2854 return E1000_SUCCESS;
2856 /* Enable CRS on TX. This must be set for half-duplex operation. */
2857 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2861 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2864 * MDI/MDI-X = 0 (default)
2865 * 0 - Auto for all speeds
2868 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
2870 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2874 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
2877 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
2880 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
2884 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
2889 * disable_polarity_correction = 0 (default)
2890 * Automatic Correction for Reversed Cable Polarity
2894 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
2895 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2899 if (hw->phy_revision < M88E1011_I_REV_4) {
2900 /* Force TX_CLK in the Extended PHY Specific Control Register
2903 ret_val = e1000_read_phy_reg(hw,
2904 M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2908 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2910 if ((hw->phy_revision == E1000_REVISION_2) &&
2911 (hw->phy_id == M88E1111_I_PHY_ID)) {
2912 /* Vidalia Phy, set the downshift counter to 5x */
2913 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
2914 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
2915 ret_val = e1000_write_phy_reg(hw,
2916 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2920 /* Configure Master and Slave downshift values */
2921 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK
2922 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
2923 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X
2924 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
2925 ret_val = e1000_write_phy_reg(hw,
2926 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2932 /* SW Reset the PHY so all changes take effect */
2933 ret_val = e1000_phy_reset(hw);
2935 DEBUGOUT("Error Resetting the PHY\n");
2939 return E1000_SUCCESS;
2942 /********************************************************************
2943 * Setup auto-negotiation and flow control advertisements,
2944 * and then perform auto-negotiation.
2946 * hw - Struct containing variables accessed by shared code
2947 *********************************************************************/
2949 e1000_copper_link_autoneg(struct e1000_hw *hw)
2956 /* Perform some bounds checking on the hw->autoneg_advertised
2957 * parameter. If this variable is zero, then set it to the default.
2959 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
2961 /* If autoneg_advertised is zero, we assume it was not defaulted
2962 * by the calling code so we set to advertise full capability.
2964 if (hw->autoneg_advertised == 0)
2965 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
2967 /* IFE phy only supports 10/100 */
2968 if (hw->phy_type == e1000_phy_ife)
2969 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
2971 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
2972 ret_val = e1000_phy_setup_autoneg(hw);
2974 DEBUGOUT("Error Setting up Auto-Negotiation\n");
2977 DEBUGOUT("Restarting Auto-Neg\n");
2979 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
2980 * the Auto Neg Restart bit in the PHY control register.
2982 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2986 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
2987 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
2991 /* Does the user want to wait for Auto-Neg to complete here, or
2992 * check at a later time (for example, callback routine).
2994 /* If we do not wait for autonegtation to complete I
2995 * do not see a valid link status.
2996 * wait_autoneg_complete = 1 .
2998 if (hw->wait_autoneg_complete) {
2999 ret_val = e1000_wait_autoneg(hw);
3001 DEBUGOUT("Error while waiting for autoneg"
3007 hw->get_link_status = true;
3009 return E1000_SUCCESS;
3012 /******************************************************************************
3013 * Config the MAC and the PHY after link is up.
3014 * 1) Set up the MAC to the current PHY speed/duplex
3015 * if we are on 82543. If we
3016 * are on newer silicon, we only need to configure
3017 * collision distance in the Transmit Control Register.
3018 * 2) Set up flow control on the MAC to that established with
3020 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
3022 * hw - Struct containing variables accessed by shared code
3023 ******************************************************************************/
3025 e1000_copper_link_postconfig(struct e1000_hw *hw)
3030 if (hw->mac_type >= e1000_82544) {
3031 e1000_config_collision_dist(hw);
3033 ret_val = e1000_config_mac_to_phy(hw);
3035 DEBUGOUT("Error configuring MAC to PHY settings\n");
3039 ret_val = e1000_config_fc_after_link_up(hw);
3041 DEBUGOUT("Error Configuring Flow Control\n");
3044 return E1000_SUCCESS;
3047 /******************************************************************************
3048 * Detects which PHY is present and setup the speed and duplex
3050 * hw - Struct containing variables accessed by shared code
3051 ******************************************************************************/
3053 e1000_setup_copper_link(struct e1000_hw *hw)
3062 switch (hw->mac_type) {
3063 case e1000_80003es2lan:
3065 /* Set the mac to wait the maximum time between each
3066 * iteration and increase the max iterations when
3067 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
3068 ret_val = e1000_write_kmrn_reg(hw,
3069 GG82563_REG(0x34, 4), 0xFFFF);
3072 ret_val = e1000_read_kmrn_reg(hw,
3073 GG82563_REG(0x34, 9), ®_data);
3077 ret_val = e1000_write_kmrn_reg(hw,
3078 GG82563_REG(0x34, 9), reg_data);
3085 /* Check if it is a valid PHY and set PHY mode if necessary. */
3086 ret_val = e1000_copper_link_preconfig(hw);
3089 switch (hw->mac_type) {
3090 case e1000_80003es2lan:
3091 /* Kumeran registers are written-only */
3093 E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
3094 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
3095 ret_val = e1000_write_kmrn_reg(hw,
3096 E1000_KUMCTRLSTA_OFFSET_INB_CTRL, reg_data);
3104 if (hw->phy_type == e1000_phy_igp ||
3105 hw->phy_type == e1000_phy_igp_3 ||
3106 hw->phy_type == e1000_phy_igp_2) {
3107 ret_val = e1000_copper_link_igp_setup(hw);
3110 } else if (hw->phy_type == e1000_phy_m88 ||
3111 hw->phy_type == e1000_phy_igb) {
3112 ret_val = e1000_copper_link_mgp_setup(hw);
3115 } else if (hw->phy_type == e1000_phy_gg82563) {
3116 ret_val = e1000_copper_link_ggp_setup(hw);
3122 /* Setup autoneg and flow control advertisement
3123 * and perform autonegotiation */
3124 ret_val = e1000_copper_link_autoneg(hw);
3128 /* Check link status. Wait up to 100 microseconds for link to become
3131 for (i = 0; i < 10; i++) {
3132 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3135 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3139 if (phy_data & MII_SR_LINK_STATUS) {
3140 /* Config the MAC and PHY after link is up */
3141 ret_val = e1000_copper_link_postconfig(hw);
3145 DEBUGOUT("Valid link established!!!\n");
3146 return E1000_SUCCESS;
3151 DEBUGOUT("Unable to establish link!!!\n");
3152 return E1000_SUCCESS;
3155 /******************************************************************************
3156 * Configures PHY autoneg and flow control advertisement settings
3158 * hw - Struct containing variables accessed by shared code
3159 ******************************************************************************/
3161 e1000_phy_setup_autoneg(struct e1000_hw *hw)
3164 uint16_t mii_autoneg_adv_reg;
3165 uint16_t mii_1000t_ctrl_reg;
3169 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
3170 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
3174 if (hw->phy_type != e1000_phy_ife) {
3175 /* Read the MII 1000Base-T Control Register (Address 9). */
3176 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
3177 &mii_1000t_ctrl_reg);
3181 mii_1000t_ctrl_reg = 0;
3183 /* Need to parse both autoneg_advertised and fc and set up
3184 * the appropriate PHY registers. First we will parse for
3185 * autoneg_advertised software override. Since we can advertise
3186 * a plethora of combinations, we need to check each bit
3190 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
3191 * Advertisement Register (Address 4) and the 1000 mb speed bits in
3192 * the 1000Base-T Control Register (Address 9).
3194 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
3195 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
3197 DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised);
3199 /* Do we want to advertise 10 Mb Half Duplex? */
3200 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
3201 DEBUGOUT("Advertise 10mb Half duplex\n");
3202 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
3205 /* Do we want to advertise 10 Mb Full Duplex? */
3206 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
3207 DEBUGOUT("Advertise 10mb Full duplex\n");
3208 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
3211 /* Do we want to advertise 100 Mb Half Duplex? */
3212 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
3213 DEBUGOUT("Advertise 100mb Half duplex\n");
3214 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
3217 /* Do we want to advertise 100 Mb Full Duplex? */
3218 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
3219 DEBUGOUT("Advertise 100mb Full duplex\n");
3220 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
3223 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
3224 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
3226 ("Advertise 1000mb Half duplex requested, request denied!\n");
3229 /* Do we want to advertise 1000 Mb Full Duplex? */
3230 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
3231 DEBUGOUT("Advertise 1000mb Full duplex\n");
3232 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
3235 /* Check for a software override of the flow control settings, and
3236 * setup the PHY advertisement registers accordingly. If
3237 * auto-negotiation is enabled, then software will have to set the
3238 * "PAUSE" bits to the correct value in the Auto-Negotiation
3239 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
3241 * The possible values of the "fc" parameter are:
3242 * 0: Flow control is completely disabled
3243 * 1: Rx flow control is enabled (we can receive pause frames
3244 * but not send pause frames).
3245 * 2: Tx flow control is enabled (we can send pause frames
3246 * but we do not support receiving pause frames).
3247 * 3: Both Rx and TX flow control (symmetric) are enabled.
3248 * other: No software override. The flow control configuration
3249 * in the EEPROM is used.
3252 case e1000_fc_none: /* 0 */
3253 /* Flow control (RX & TX) is completely disabled by a
3254 * software over-ride.
3256 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3258 case e1000_fc_rx_pause: /* 1 */
3259 /* RX Flow control is enabled, and TX Flow control is
3260 * disabled, by a software over-ride.
3262 /* Since there really isn't a way to advertise that we are
3263 * capable of RX Pause ONLY, we will advertise that we
3264 * support both symmetric and asymmetric RX PAUSE. Later
3265 * (in e1000_config_fc_after_link_up) we will disable the
3266 *hw's ability to send PAUSE frames.
3268 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3270 case e1000_fc_tx_pause: /* 2 */
3271 /* TX Flow control is enabled, and RX Flow control is
3272 * disabled, by a software over-ride.
3274 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
3275 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
3277 case e1000_fc_full: /* 3 */
3278 /* Flow control (both RX and TX) is enabled by a software
3281 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3284 DEBUGOUT("Flow control param set incorrectly\n");
3285 return -E1000_ERR_CONFIG;
3288 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
3292 DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
3294 if (hw->phy_type != e1000_phy_ife) {
3295 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
3296 mii_1000t_ctrl_reg);
3301 return E1000_SUCCESS;
3304 /******************************************************************************
3305 * Sets the collision distance in the Transmit Control register
3307 * hw - Struct containing variables accessed by shared code
3309 * Link should have been established previously. Reads the speed and duplex
3310 * information from the Device Status register.
3311 ******************************************************************************/
3313 e1000_config_collision_dist(struct e1000_hw *hw)
3315 uint32_t tctl, coll_dist;
3319 if (hw->mac_type < e1000_82543)
3320 coll_dist = E1000_COLLISION_DISTANCE_82542;
3322 coll_dist = E1000_COLLISION_DISTANCE;
3324 tctl = E1000_READ_REG(hw, TCTL);
3326 tctl &= ~E1000_TCTL_COLD;
3327 tctl |= coll_dist << E1000_COLD_SHIFT;
3329 E1000_WRITE_REG(hw, TCTL, tctl);
3330 E1000_WRITE_FLUSH(hw);
3333 /******************************************************************************
3334 * Sets MAC speed and duplex settings to reflect the those in the PHY
3336 * hw - Struct containing variables accessed by shared code
3337 * mii_reg - data to write to the MII control register
3339 * The contents of the PHY register containing the needed information need to
3341 ******************************************************************************/
3343 e1000_config_mac_to_phy(struct e1000_hw *hw)
3350 /* Read the Device Control Register and set the bits to Force Speed
3353 ctrl = E1000_READ_REG(hw, CTRL);
3354 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3355 ctrl &= ~(E1000_CTRL_ILOS);
3356 ctrl |= (E1000_CTRL_SPD_SEL);
3358 /* Set up duplex in the Device Control and Transmit Control
3359 * registers depending on negotiated values.
3361 if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
3362 DEBUGOUT("PHY Read Error\n");
3363 return -E1000_ERR_PHY;
3365 if (phy_data & M88E1000_PSSR_DPLX)
3366 ctrl |= E1000_CTRL_FD;
3368 ctrl &= ~E1000_CTRL_FD;
3370 e1000_config_collision_dist(hw);
3372 /* Set up speed in the Device Control register depending on
3373 * negotiated values.
3375 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
3376 ctrl |= E1000_CTRL_SPD_1000;
3377 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
3378 ctrl |= E1000_CTRL_SPD_100;
3379 /* Write the configured values back to the Device Control Reg. */
3380 E1000_WRITE_REG(hw, CTRL, ctrl);
3384 /******************************************************************************
3385 * Forces the MAC's flow control settings.
3387 * hw - Struct containing variables accessed by shared code
3389 * Sets the TFCE and RFCE bits in the device control register to reflect
3390 * the adapter settings. TFCE and RFCE need to be explicitly set by
3391 * software when a Copper PHY is used because autonegotiation is managed
3392 * by the PHY rather than the MAC. Software must also configure these
3393 * bits when link is forced on a fiber connection.
3394 *****************************************************************************/
3396 e1000_force_mac_fc(struct e1000_hw *hw)
3402 /* Get the current configuration of the Device Control Register */
3403 ctrl = E1000_READ_REG(hw, CTRL);
3405 /* Because we didn't get link via the internal auto-negotiation
3406 * mechanism (we either forced link or we got link via PHY
3407 * auto-neg), we have to manually enable/disable transmit an
3408 * receive flow control.
3410 * The "Case" statement below enables/disable flow control
3411 * according to the "hw->fc" parameter.
3413 * The possible values of the "fc" parameter are:
3414 * 0: Flow control is completely disabled
3415 * 1: Rx flow control is enabled (we can receive pause
3416 * frames but not send pause frames).
3417 * 2: Tx flow control is enabled (we can send pause frames
3418 * frames but we do not receive pause frames).
3419 * 3: Both Rx and TX flow control (symmetric) is enabled.
3420 * other: No other values should be possible at this point.
3425 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
3427 case e1000_fc_rx_pause:
3428 ctrl &= (~E1000_CTRL_TFCE);
3429 ctrl |= E1000_CTRL_RFCE;
3431 case e1000_fc_tx_pause:
3432 ctrl &= (~E1000_CTRL_RFCE);
3433 ctrl |= E1000_CTRL_TFCE;
3436 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
3439 DEBUGOUT("Flow control param set incorrectly\n");
3440 return -E1000_ERR_CONFIG;
3443 /* Disable TX Flow Control for 82542 (rev 2.0) */
3444 if (hw->mac_type == e1000_82542_rev2_0)
3445 ctrl &= (~E1000_CTRL_TFCE);
3447 E1000_WRITE_REG(hw, CTRL, ctrl);
3451 /******************************************************************************
3452 * Configures flow control settings after link is established
3454 * hw - Struct containing variables accessed by shared code
3456 * Should be called immediately after a valid link has been established.
3457 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
3458 * and autonegotiation is enabled, the MAC flow control settings will be set
3459 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
3460 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
3461 *****************************************************************************/
3463 e1000_config_fc_after_link_up(struct e1000_hw *hw)
3466 uint16_t mii_status_reg;
3467 uint16_t mii_nway_adv_reg;
3468 uint16_t mii_nway_lp_ability_reg;
3474 /* Check for the case where we have fiber media and auto-neg failed
3475 * so we had to force link. In this case, we need to force the
3476 * configuration of the MAC to match the "fc" parameter.
3478 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
3479 || ((hw->media_type == e1000_media_type_internal_serdes)
3480 && (hw->autoneg_failed))
3481 || ((hw->media_type == e1000_media_type_copper)
3482 && (!hw->autoneg))) {
3483 ret_val = e1000_force_mac_fc(hw);
3485 DEBUGOUT("Error forcing flow control settings\n");
3490 /* Check for the case where we have copper media and auto-neg is
3491 * enabled. In this case, we need to check and see if Auto-Neg
3492 * has completed, and if so, how the PHY and link partner has
3493 * flow control configured.
3495 if (hw->media_type == e1000_media_type_copper) {
3496 /* Read the MII Status Register and check to see if AutoNeg
3497 * has completed. We read this twice because this reg has
3498 * some "sticky" (latched) bits.
3500 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3501 DEBUGOUT("PHY Read Error\n");
3502 return -E1000_ERR_PHY;
3504 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3505 DEBUGOUT("PHY Read Error\n");
3506 return -E1000_ERR_PHY;
3509 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
3510 /* The AutoNeg process has completed, so we now need to
3511 * read both the Auto Negotiation Advertisement Register
3512 * (Address 4) and the Auto_Negotiation Base Page Ability
3513 * Register (Address 5) to determine how flow control was
3516 if (e1000_read_phy_reg
3517 (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
3518 DEBUGOUT("PHY Read Error\n");
3519 return -E1000_ERR_PHY;
3521 if (e1000_read_phy_reg
3522 (hw, PHY_LP_ABILITY,
3523 &mii_nway_lp_ability_reg) < 0) {
3524 DEBUGOUT("PHY Read Error\n");
3525 return -E1000_ERR_PHY;
3528 /* Two bits in the Auto Negotiation Advertisement Register
3529 * (Address 4) and two bits in the Auto Negotiation Base
3530 * Page Ability Register (Address 5) determine flow control
3531 * for both the PHY and the link partner. The following
3532 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
3533 * 1999, describes these PAUSE resolution bits and how flow
3534 * control is determined based upon these settings.
3535 * NOTE: DC = Don't Care
3537 * LOCAL DEVICE | LINK PARTNER
3538 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
3539 *-------|---------|-------|---------|--------------------
3540 * 0 | 0 | DC | DC | e1000_fc_none
3541 * 0 | 1 | 0 | DC | e1000_fc_none
3542 * 0 | 1 | 1 | 0 | e1000_fc_none
3543 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
3544 * 1 | 0 | 0 | DC | e1000_fc_none
3545 * 1 | DC | 1 | DC | e1000_fc_full
3546 * 1 | 1 | 0 | 0 | e1000_fc_none
3547 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
3550 /* Are both PAUSE bits set to 1? If so, this implies
3551 * Symmetric Flow Control is enabled at both ends. The
3552 * ASM_DIR bits are irrelevant per the spec.
3554 * For Symmetric Flow Control:
3556 * LOCAL DEVICE | LINK PARTNER
3557 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3558 *-------|---------|-------|---------|--------------------
3559 * 1 | DC | 1 | DC | e1000_fc_full
3562 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3563 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
3564 /* Now we need to check if the user selected RX ONLY
3565 * of pause frames. In this case, we had to advertise
3566 * FULL flow control because we could not advertise RX
3567 * ONLY. Hence, we must now check to see if we need to
3568 * turn OFF the TRANSMISSION of PAUSE frames.
3570 if (hw->original_fc == e1000_fc_full) {
3571 hw->fc = e1000_fc_full;
3572 DEBUGOUT("Flow Control = FULL.\r\n");
3574 hw->fc = e1000_fc_rx_pause;
3576 ("Flow Control = RX PAUSE frames only.\r\n");
3579 /* For receiving PAUSE frames ONLY.
3581 * LOCAL DEVICE | LINK PARTNER
3582 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3583 *-------|---------|-------|---------|--------------------
3584 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
3587 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3588 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3589 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3590 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3592 hw->fc = e1000_fc_tx_pause;
3594 ("Flow Control = TX PAUSE frames only.\r\n");
3596 /* For transmitting PAUSE frames ONLY.
3598 * LOCAL DEVICE | LINK PARTNER
3599 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3600 *-------|---------|-------|---------|--------------------
3601 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
3604 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3605 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3606 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3607 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3609 hw->fc = e1000_fc_rx_pause;
3611 ("Flow Control = RX PAUSE frames only.\r\n");
3613 /* Per the IEEE spec, at this point flow control should be
3614 * disabled. However, we want to consider that we could
3615 * be connected to a legacy switch that doesn't advertise
3616 * desired flow control, but can be forced on the link
3617 * partner. So if we advertised no flow control, that is
3618 * what we will resolve to. If we advertised some kind of
3619 * receive capability (Rx Pause Only or Full Flow Control)
3620 * and the link partner advertised none, we will configure
3621 * ourselves to enable Rx Flow Control only. We can do
3622 * this safely for two reasons: If the link partner really
3623 * didn't want flow control enabled, and we enable Rx, no
3624 * harm done since we won't be receiving any PAUSE frames
3625 * anyway. If the intent on the link partner was to have
3626 * flow control enabled, then by us enabling RX only, we
3627 * can at least receive pause frames and process them.
3628 * This is a good idea because in most cases, since we are
3629 * predominantly a server NIC, more times than not we will
3630 * be asked to delay transmission of packets than asking
3631 * our link partner to pause transmission of frames.
3633 else if (hw->original_fc == e1000_fc_none ||
3634 hw->original_fc == e1000_fc_tx_pause) {
3635 hw->fc = e1000_fc_none;
3636 DEBUGOUT("Flow Control = NONE.\r\n");
3638 hw->fc = e1000_fc_rx_pause;
3640 ("Flow Control = RX PAUSE frames only.\r\n");
3643 /* Now we need to do one last check... If we auto-
3644 * negotiated to HALF DUPLEX, flow control should not be
3645 * enabled per IEEE 802.3 spec.
3647 e1000_get_speed_and_duplex(hw, &speed, &duplex);
3649 if (duplex == HALF_DUPLEX)
3650 hw->fc = e1000_fc_none;
3652 /* Now we call a subroutine to actually force the MAC
3653 * controller to use the correct flow control settings.
3655 ret_val = e1000_force_mac_fc(hw);
3658 ("Error forcing flow control settings\n");
3663 ("Copper PHY and Auto Neg has not completed.\r\n");
3666 return E1000_SUCCESS;
3669 /******************************************************************************
3670 * Checks to see if the link status of the hardware has changed.
3672 * hw - Struct containing variables accessed by shared code
3674 * Called by any function that needs to check the link status of the adapter.
3675 *****************************************************************************/
3677 e1000_check_for_link(struct e1000_hw *hw)
3686 uint16_t lp_capability;
3690 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
3691 * set when the optics detect a signal. On older adapters, it will be
3692 * cleared when there is a signal
3694 ctrl = E1000_READ_REG(hw, CTRL);
3695 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
3696 signal = E1000_CTRL_SWDPIN1;
3700 status = E1000_READ_REG(hw, STATUS);
3701 rxcw = E1000_READ_REG(hw, RXCW);
3702 DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw);
3704 /* If we have a copper PHY then we only want to go out to the PHY
3705 * registers to see if Auto-Neg has completed and/or if our link
3706 * status has changed. The get_link_status flag will be set if we
3707 * receive a Link Status Change interrupt or we have Rx Sequence
3710 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
3711 /* First we want to see if the MII Status Register reports
3712 * link. If so, then we want to get the current speed/duplex
3714 * Read the register twice since the link bit is sticky.
3716 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3717 DEBUGOUT("PHY Read Error\n");
3718 return -E1000_ERR_PHY;
3720 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3721 DEBUGOUT("PHY Read Error\n");
3722 return -E1000_ERR_PHY;
3725 if (phy_data & MII_SR_LINK_STATUS) {
3726 hw->get_link_status = false;
3728 /* No link detected */
3729 return -E1000_ERR_NOLINK;
3732 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
3733 * have Si on board that is 82544 or newer, Auto
3734 * Speed Detection takes care of MAC speed/duplex
3735 * configuration. So we only need to configure Collision
3736 * Distance in the MAC. Otherwise, we need to force
3737 * speed/duplex on the MAC to the current PHY speed/duplex
3740 if (hw->mac_type >= e1000_82544)
3741 e1000_config_collision_dist(hw);
3743 ret_val = e1000_config_mac_to_phy(hw);
3746 ("Error configuring MAC to PHY settings\n");
3751 /* Configure Flow Control now that Auto-Neg has completed. First, we
3752 * need to restore the desired flow control settings because we may
3753 * have had to re-autoneg with a different link partner.
3755 ret_val = e1000_config_fc_after_link_up(hw);
3757 DEBUGOUT("Error configuring flow control\n");
3761 /* At this point we know that we are on copper and we have
3762 * auto-negotiated link. These are conditions for checking the link
3763 * parter capability register. We use the link partner capability to
3764 * determine if TBI Compatibility needs to be turned on or off. If
3765 * the link partner advertises any speed in addition to Gigabit, then
3766 * we assume that they are GMII-based, and TBI compatibility is not
3767 * needed. If no other speeds are advertised, we assume the link
3768 * partner is TBI-based, and we turn on TBI Compatibility.
3770 if (hw->tbi_compatibility_en) {
3771 if (e1000_read_phy_reg
3772 (hw, PHY_LP_ABILITY, &lp_capability) < 0) {
3773 DEBUGOUT("PHY Read Error\n");
3774 return -E1000_ERR_PHY;
3776 if (lp_capability & (NWAY_LPAR_10T_HD_CAPS |
3777 NWAY_LPAR_10T_FD_CAPS |
3778 NWAY_LPAR_100TX_HD_CAPS |
3779 NWAY_LPAR_100TX_FD_CAPS |
3780 NWAY_LPAR_100T4_CAPS)) {
3781 /* If our link partner advertises anything in addition to
3782 * gigabit, we do not need to enable TBI compatibility.
3784 if (hw->tbi_compatibility_on) {
3785 /* If we previously were in the mode, turn it off. */
3786 rctl = E1000_READ_REG(hw, RCTL);
3787 rctl &= ~E1000_RCTL_SBP;
3788 E1000_WRITE_REG(hw, RCTL, rctl);
3789 hw->tbi_compatibility_on = false;
3792 /* If TBI compatibility is was previously off, turn it on. For
3793 * compatibility with a TBI link partner, we will store bad
3794 * packets. Some frames have an additional byte on the end and
3795 * will look like CRC errors to to the hardware.
3797 if (!hw->tbi_compatibility_on) {
3798 hw->tbi_compatibility_on = true;
3799 rctl = E1000_READ_REG(hw, RCTL);
3800 rctl |= E1000_RCTL_SBP;
3801 E1000_WRITE_REG(hw, RCTL, rctl);
3806 /* If we don't have link (auto-negotiation failed or link partner cannot
3807 * auto-negotiate), the cable is plugged in (we have signal), and our
3808 * link partner is not trying to auto-negotiate with us (we are receiving
3809 * idles or data), we need to force link up. We also need to give
3810 * auto-negotiation time to complete, in case the cable was just plugged
3811 * in. The autoneg_failed flag does this.
3813 else if ((hw->media_type == e1000_media_type_fiber) &&
3814 (!(status & E1000_STATUS_LU)) &&
3815 ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
3816 (!(rxcw & E1000_RXCW_C))) {
3817 if (hw->autoneg_failed == 0) {
3818 hw->autoneg_failed = 1;
3821 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
3823 /* Disable auto-negotiation in the TXCW register */
3824 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3826 /* Force link-up and also force full-duplex. */
3827 ctrl = E1000_READ_REG(hw, CTRL);
3828 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3829 E1000_WRITE_REG(hw, CTRL, ctrl);
3831 /* Configure Flow Control after forcing link up. */
3832 ret_val = e1000_config_fc_after_link_up(hw);
3834 DEBUGOUT("Error configuring flow control\n");
3838 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3839 * auto-negotiation in the TXCW register and disable forced link in the
3840 * Device Control register in an attempt to auto-negotiate with our link
3843 else if ((hw->media_type == e1000_media_type_fiber) &&
3844 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
3846 ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
3847 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3848 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3853 /******************************************************************************
3854 * Configure the MAC-to-PHY interface for 10/100Mbps
3856 * hw - Struct containing variables accessed by shared code
3857 ******************************************************************************/
3859 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
3861 int32_t ret_val = E1000_SUCCESS;
3867 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
3868 ret_val = e1000_write_kmrn_reg(hw,
3869 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
3873 /* Configure Transmit Inter-Packet Gap */
3874 tipg = E1000_READ_REG(hw, TIPG);
3875 tipg &= ~E1000_TIPG_IPGT_MASK;
3876 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
3877 E1000_WRITE_REG(hw, TIPG, tipg);
3879 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
3884 if (duplex == HALF_DUPLEX)
3885 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
3887 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
3889 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
3895 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
3897 int32_t ret_val = E1000_SUCCESS;
3903 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
3904 ret_val = e1000_write_kmrn_reg(hw,
3905 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
3909 /* Configure Transmit Inter-Packet Gap */
3910 tipg = E1000_READ_REG(hw, TIPG);
3911 tipg &= ~E1000_TIPG_IPGT_MASK;
3912 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
3913 E1000_WRITE_REG(hw, TIPG, tipg);
3915 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
3920 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
3921 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
3926 /******************************************************************************
3927 * Detects the current speed and duplex settings of the hardware.
3929 * hw - Struct containing variables accessed by shared code
3930 * speed - Speed of the connection
3931 * duplex - Duplex setting of the connection
3932 *****************************************************************************/
3934 e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed,
3943 if (hw->mac_type >= e1000_82543) {
3944 status = E1000_READ_REG(hw, STATUS);
3945 if (status & E1000_STATUS_SPEED_1000) {
3946 *speed = SPEED_1000;
3947 DEBUGOUT("1000 Mbs, ");
3948 } else if (status & E1000_STATUS_SPEED_100) {
3950 DEBUGOUT("100 Mbs, ");
3953 DEBUGOUT("10 Mbs, ");
3956 if (status & E1000_STATUS_FD) {
3957 *duplex = FULL_DUPLEX;
3958 DEBUGOUT("Full Duplex\r\n");
3960 *duplex = HALF_DUPLEX;
3961 DEBUGOUT(" Half Duplex\r\n");
3964 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
3965 *speed = SPEED_1000;
3966 *duplex = FULL_DUPLEX;
3969 /* IGP01 PHY may advertise full duplex operation after speed downgrade
3970 * even if it is operating at half duplex. Here we set the duplex
3971 * settings to match the duplex in the link partner's capabilities.
3973 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
3974 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
3978 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
3979 *duplex = HALF_DUPLEX;
3981 ret_val = e1000_read_phy_reg(hw,
3982 PHY_LP_ABILITY, &phy_data);
3985 if ((*speed == SPEED_100 &&
3986 !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
3987 || (*speed == SPEED_10
3988 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3989 *duplex = HALF_DUPLEX;
3993 if ((hw->mac_type == e1000_80003es2lan) &&
3994 (hw->media_type == e1000_media_type_copper)) {
3995 if (*speed == SPEED_1000)
3996 ret_val = e1000_configure_kmrn_for_1000(hw);
3998 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
4002 return E1000_SUCCESS;
4005 /******************************************************************************
4006 * Blocks until autoneg completes or times out (~4.5 seconds)
4008 * hw - Struct containing variables accessed by shared code
4009 ******************************************************************************/
4011 e1000_wait_autoneg(struct e1000_hw *hw)
4017 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
4019 /* We will wait for autoneg to complete or timeout to expire. */
4020 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
4021 /* Read the MII Status Register and wait for Auto-Neg
4022 * Complete bit to be set.
4024 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
4025 DEBUGOUT("PHY Read Error\n");
4026 return -E1000_ERR_PHY;
4028 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
4029 DEBUGOUT("PHY Read Error\n");
4030 return -E1000_ERR_PHY;
4032 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
4033 DEBUGOUT("Auto-Neg complete.\n");
4038 DEBUGOUT("Auto-Neg timedout.\n");
4039 return -E1000_ERR_TIMEOUT;
4042 /******************************************************************************
4043 * Raises the Management Data Clock
4045 * hw - Struct containing variables accessed by shared code
4046 * ctrl - Device control register's current value
4047 ******************************************************************************/
4049 e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
4051 /* Raise the clock input to the Management Data Clock (by setting the MDC
4052 * bit), and then delay 2 microseconds.
4054 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
4055 E1000_WRITE_FLUSH(hw);
4059 /******************************************************************************
4060 * Lowers the Management Data Clock
4062 * hw - Struct containing variables accessed by shared code
4063 * ctrl - Device control register's current value
4064 ******************************************************************************/
4066 e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
4068 /* Lower the clock input to the Management Data Clock (by clearing the MDC
4069 * bit), and then delay 2 microseconds.
4071 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
4072 E1000_WRITE_FLUSH(hw);
4076 /******************************************************************************
4077 * Shifts data bits out to the PHY
4079 * hw - Struct containing variables accessed by shared code
4080 * data - Data to send out to the PHY
4081 * count - Number of bits to shift out
4083 * Bits are shifted out in MSB to LSB order.
4084 ******************************************************************************/
4086 e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count)
4091 /* We need to shift "count" number of bits out to the PHY. So, the value
4092 * in the "data" parameter will be shifted out to the PHY one bit at a
4093 * time. In order to do this, "data" must be broken down into bits.
4096 mask <<= (count - 1);
4098 ctrl = E1000_READ_REG(hw, CTRL);
4100 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
4101 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
4104 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
4105 * then raising and lowering the Management Data Clock. A "0" is
4106 * shifted out to the PHY by setting the MDIO bit to "0" and then
4107 * raising and lowering the clock.
4110 ctrl |= E1000_CTRL_MDIO;
4112 ctrl &= ~E1000_CTRL_MDIO;
4114 E1000_WRITE_REG(hw, CTRL, ctrl);
4115 E1000_WRITE_FLUSH(hw);
4119 e1000_raise_mdi_clk(hw, &ctrl);
4120 e1000_lower_mdi_clk(hw, &ctrl);
4126 /******************************************************************************
4127 * Shifts data bits in from the PHY
4129 * hw - Struct containing variables accessed by shared code
4131 * Bits are shifted in in MSB to LSB order.
4132 ******************************************************************************/
4134 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
4140 /* In order to read a register from the PHY, we need to shift in a total
4141 * of 18 bits from the PHY. The first two bit (turnaround) times are used
4142 * to avoid contention on the MDIO pin when a read operation is performed.
4143 * These two bits are ignored by us and thrown away. Bits are "shifted in"
4144 * by raising the input to the Management Data Clock (setting the MDC bit),
4145 * and then reading the value of the MDIO bit.
4147 ctrl = E1000_READ_REG(hw, CTRL);
4149 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
4150 ctrl &= ~E1000_CTRL_MDIO_DIR;
4151 ctrl &= ~E1000_CTRL_MDIO;
4153 E1000_WRITE_REG(hw, CTRL, ctrl);
4154 E1000_WRITE_FLUSH(hw);
4156 /* Raise and Lower the clock before reading in the data. This accounts for
4157 * the turnaround bits. The first clock occurred when we clocked out the
4158 * last bit of the Register Address.
4160 e1000_raise_mdi_clk(hw, &ctrl);
4161 e1000_lower_mdi_clk(hw, &ctrl);
4163 for (data = 0, i = 0; i < 16; i++) {
4165 e1000_raise_mdi_clk(hw, &ctrl);
4166 ctrl = E1000_READ_REG(hw, CTRL);
4167 /* Check to see if we shifted in a "1". */
4168 if (ctrl & E1000_CTRL_MDIO)
4170 e1000_lower_mdi_clk(hw, &ctrl);
4173 e1000_raise_mdi_clk(hw, &ctrl);
4174 e1000_lower_mdi_clk(hw, &ctrl);
4179 /*****************************************************************************
4180 * Reads the value from a PHY register
4182 * hw - Struct containing variables accessed by shared code
4183 * reg_addr - address of the PHY register to read
4184 ******************************************************************************/
4186 e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data)
4190 const uint32_t phy_addr = 1;
4192 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4193 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4194 return -E1000_ERR_PARAM;
4197 if (hw->mac_type > e1000_82543) {
4198 /* Set up Op-code, Phy Address, and register address in the MDI
4199 * Control register. The MAC will take care of interfacing with the
4200 * PHY to retrieve the desired data.
4202 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
4203 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4204 (E1000_MDIC_OP_READ));
4206 E1000_WRITE_REG(hw, MDIC, mdic);
4208 /* Poll the ready bit to see if the MDI read completed */
4209 for (i = 0; i < 64; i++) {
4211 mdic = E1000_READ_REG(hw, MDIC);
4212 if (mdic & E1000_MDIC_READY)
4215 if (!(mdic & E1000_MDIC_READY)) {
4216 DEBUGOUT("MDI Read did not complete\n");
4217 return -E1000_ERR_PHY;
4219 if (mdic & E1000_MDIC_ERROR) {
4220 DEBUGOUT("MDI Error\n");
4221 return -E1000_ERR_PHY;
4223 *phy_data = (uint16_t) mdic;
4225 /* We must first send a preamble through the MDIO pin to signal the
4226 * beginning of an MII instruction. This is done by sending 32
4227 * consecutive "1" bits.
4229 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4231 /* Now combine the next few fields that are required for a read
4232 * operation. We use this method instead of calling the
4233 * e1000_shift_out_mdi_bits routine five different times. The format of
4234 * a MII read instruction consists of a shift out of 14 bits and is
4235 * defined as follows:
4236 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
4237 * followed by a shift in of 18 bits. This first two bits shifted in
4238 * are TurnAround bits used to avoid contention on the MDIO pin when a
4239 * READ operation is performed. These two bits are thrown away
4240 * followed by a shift in of 16 bits which contains the desired data.
4242 mdic = ((reg_addr) | (phy_addr << 5) |
4243 (PHY_OP_READ << 10) | (PHY_SOF << 12));
4245 e1000_shift_out_mdi_bits(hw, mdic, 14);
4247 /* Now that we've shifted out the read command to the MII, we need to
4248 * "shift in" the 16-bit value (18 total bits) of the requested PHY
4251 *phy_data = e1000_shift_in_mdi_bits(hw);
4256 /******************************************************************************
4257 * Writes a value to a PHY register
4259 * hw - Struct containing variables accessed by shared code
4260 * reg_addr - address of the PHY register to write
4261 * data - data to write to the PHY
4262 ******************************************************************************/
4264 e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data)
4268 const uint32_t phy_addr = 1;
4270 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4271 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4272 return -E1000_ERR_PARAM;
4275 if (hw->mac_type > e1000_82543) {
4276 /* Set up Op-code, Phy Address, register address, and data intended
4277 * for the PHY register in the MDI Control register. The MAC will take
4278 * care of interfacing with the PHY to send the desired data.
4280 mdic = (((uint32_t) phy_data) |
4281 (reg_addr << E1000_MDIC_REG_SHIFT) |
4282 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4283 (E1000_MDIC_OP_WRITE));
4285 E1000_WRITE_REG(hw, MDIC, mdic);
4287 /* Poll the ready bit to see if the MDI read completed */
4288 for (i = 0; i < 64; i++) {
4290 mdic = E1000_READ_REG(hw, MDIC);
4291 if (mdic & E1000_MDIC_READY)
4294 if (!(mdic & E1000_MDIC_READY)) {
4295 DEBUGOUT("MDI Write did not complete\n");
4296 return -E1000_ERR_PHY;
4299 /* We'll need to use the SW defined pins to shift the write command
4300 * out to the PHY. We first send a preamble to the PHY to signal the
4301 * beginning of the MII instruction. This is done by sending 32
4302 * consecutive "1" bits.
4304 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4306 /* Now combine the remaining required fields that will indicate a
4307 * write operation. We use this method instead of calling the
4308 * e1000_shift_out_mdi_bits routine for each field in the command. The
4309 * format of a MII write instruction is as follows:
4310 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
4312 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
4313 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
4315 mdic |= (uint32_t) phy_data;
4317 e1000_shift_out_mdi_bits(hw, mdic, 32);
4322 /******************************************************************************
4323 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
4324 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
4325 * the caller to figure out how to deal with it.
4327 * hw - Struct containing variables accessed by shared code
4329 * returns: - E1000_BLK_PHY_RESET
4332 *****************************************************************************/
4334 e1000_check_phy_reset_block(struct e1000_hw *hw)
4339 if (hw->mac_type == e1000_ich8lan) {
4340 fwsm = E1000_READ_REG(hw, FWSM);
4341 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
4342 : E1000_BLK_PHY_RESET;
4345 if (hw->mac_type > e1000_82547_rev_2)
4346 manc = E1000_READ_REG(hw, MANC);
4347 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
4348 E1000_BLK_PHY_RESET : E1000_SUCCESS;
4351 /***************************************************************************
4352 * Checks if the PHY configuration is done
4354 * hw: Struct containing variables accessed by shared code
4356 * returns: - E1000_ERR_RESET if fail to reset MAC
4357 * E1000_SUCCESS at any other case.
4359 ***************************************************************************/
4361 e1000_get_phy_cfg_done(struct e1000_hw *hw)
4363 int32_t timeout = PHY_CFG_TIMEOUT;
4364 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
4368 switch (hw->mac_type) {
4373 case e1000_80003es2lan:
4374 /* Separate *_CFG_DONE_* bit for each port */
4375 if (e1000_is_second_port(hw))
4376 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
4383 if (hw->mac_type == e1000_igb) {
4384 if (E1000_READ_REG(hw, I210_EEMNGCTL) & cfg_mask)
4387 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
4394 DEBUGOUT("MNG configuration cycle has not "
4396 return -E1000_ERR_RESET;
4401 return E1000_SUCCESS;
4404 /******************************************************************************
4405 * Returns the PHY to the power-on reset state
4407 * hw - Struct containing variables accessed by shared code
4408 ******************************************************************************/
4410 e1000_phy_hw_reset(struct e1000_hw *hw)
4412 uint16_t swfw = E1000_SWFW_PHY0_SM;
4413 uint32_t ctrl, ctrl_ext;
4419 /* In the case of the phy reset being blocked, it's not an error, we
4420 * simply return success without performing the reset. */
4421 ret_val = e1000_check_phy_reset_block(hw);
4423 return E1000_SUCCESS;
4425 DEBUGOUT("Resetting Phy...\n");
4427 if (hw->mac_type > e1000_82543) {
4428 if (e1000_is_second_port(hw))
4429 swfw = E1000_SWFW_PHY1_SM;
4431 if (e1000_swfw_sync_acquire(hw, swfw)) {
4432 DEBUGOUT("Unable to acquire swfw sync\n");
4433 return -E1000_ERR_SWFW_SYNC;
4436 /* Read the device control register and assert the E1000_CTRL_PHY_RST
4437 * bit. Then, take it out of reset.
4439 ctrl = E1000_READ_REG(hw, CTRL);
4440 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
4441 E1000_WRITE_FLUSH(hw);
4443 if (hw->mac_type < e1000_82571)
4448 E1000_WRITE_REG(hw, CTRL, ctrl);
4449 E1000_WRITE_FLUSH(hw);
4451 if (hw->mac_type >= e1000_82571)
4455 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
4456 * bit to put the PHY into reset. Then, take it out of reset.
4458 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
4459 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
4460 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
4461 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4462 E1000_WRITE_FLUSH(hw);
4464 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
4465 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4466 E1000_WRITE_FLUSH(hw);
4470 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
4471 /* Configure activity LED after PHY reset */
4472 led_ctrl = E1000_READ_REG(hw, LEDCTL);
4473 led_ctrl &= IGP_ACTIVITY_LED_MASK;
4474 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
4475 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
4478 e1000_swfw_sync_release(hw, swfw);
4480 /* Wait for FW to finish PHY configuration. */
4481 ret_val = e1000_get_phy_cfg_done(hw);
4482 if (ret_val != E1000_SUCCESS)
4488 /******************************************************************************
4489 * IGP phy init script - initializes the GbE PHY
4491 * hw - Struct containing variables accessed by shared code
4492 *****************************************************************************/
4494 e1000_phy_init_script(struct e1000_hw *hw)
4497 uint16_t phy_saved_data;
4500 if (hw->phy_init_script) {
4503 /* Save off the current value of register 0x2F5B to be
4504 * restored at the end of this routine. */
4505 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
4507 /* Disabled the PHY transmitter */
4508 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
4512 e1000_write_phy_reg(hw, 0x0000, 0x0140);
4516 switch (hw->mac_type) {
4519 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
4521 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
4523 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
4525 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
4527 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
4529 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
4531 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
4533 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
4535 e1000_write_phy_reg(hw, 0x2010, 0x0008);
4538 case e1000_82541_rev_2:
4539 case e1000_82547_rev_2:
4540 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
4546 e1000_write_phy_reg(hw, 0x0000, 0x3300);
4550 /* Now enable the transmitter */
4552 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
4554 if (hw->mac_type == e1000_82547) {
4555 uint16_t fused, fine, coarse;
4557 /* Move to analog registers page */
4558 e1000_read_phy_reg(hw,
4559 IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
4561 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
4562 e1000_read_phy_reg(hw,
4563 IGP01E1000_ANALOG_FUSE_STATUS, &fused);
4565 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
4567 & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
4570 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
4572 IGP01E1000_ANALOG_FUSE_COARSE_10;
4573 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
4575 == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
4576 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
4579 & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
4581 & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
4583 & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
4585 e1000_write_phy_reg(hw,
4586 IGP01E1000_ANALOG_FUSE_CONTROL, fused);
4587 e1000_write_phy_reg(hw,
4588 IGP01E1000_ANALOG_FUSE_BYPASS,
4589 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
4595 /******************************************************************************
4598 * hw - Struct containing variables accessed by shared code
4600 * Sets bit 15 of the MII Control register
4601 ******************************************************************************/
4603 e1000_phy_reset(struct e1000_hw *hw)
4610 /* In the case of the phy reset being blocked, it's not an error, we
4611 * simply return success without performing the reset. */
4612 ret_val = e1000_check_phy_reset_block(hw);
4614 return E1000_SUCCESS;
4616 switch (hw->phy_type) {
4618 case e1000_phy_igp_2:
4619 case e1000_phy_igp_3:
4622 ret_val = e1000_phy_hw_reset(hw);
4627 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
4631 phy_data |= MII_CR_RESET;
4632 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
4640 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
4641 e1000_phy_init_script(hw);
4643 return E1000_SUCCESS;
4646 static int e1000_set_phy_type (struct e1000_hw *hw)
4650 if (hw->mac_type == e1000_undefined)
4651 return -E1000_ERR_PHY_TYPE;
4653 switch (hw->phy_id) {
4654 case M88E1000_E_PHY_ID:
4655 case M88E1000_I_PHY_ID:
4656 case M88E1011_I_PHY_ID:
4657 case M88E1111_I_PHY_ID:
4658 hw->phy_type = e1000_phy_m88;
4660 case IGP01E1000_I_PHY_ID:
4661 if (hw->mac_type == e1000_82541 ||
4662 hw->mac_type == e1000_82541_rev_2 ||
4663 hw->mac_type == e1000_82547 ||
4664 hw->mac_type == e1000_82547_rev_2) {
4665 hw->phy_type = e1000_phy_igp;
4668 case IGP03E1000_E_PHY_ID:
4669 hw->phy_type = e1000_phy_igp_3;
4672 case IFE_PLUS_E_PHY_ID:
4673 case IFE_C_E_PHY_ID:
4674 hw->phy_type = e1000_phy_ife;
4676 case GG82563_E_PHY_ID:
4677 if (hw->mac_type == e1000_80003es2lan) {
4678 hw->phy_type = e1000_phy_gg82563;
4681 case BME1000_E_PHY_ID:
4682 hw->phy_type = e1000_phy_bm;
4685 hw->phy_type = e1000_phy_igb;
4689 /* Should never have loaded on this device */
4690 hw->phy_type = e1000_phy_undefined;
4691 return -E1000_ERR_PHY_TYPE;
4694 return E1000_SUCCESS;
4697 /******************************************************************************
4698 * Probes the expected PHY address for known PHY IDs
4700 * hw - Struct containing variables accessed by shared code
4701 ******************************************************************************/
4703 e1000_detect_gig_phy(struct e1000_hw *hw)
4705 int32_t phy_init_status, ret_val;
4706 uint16_t phy_id_high, phy_id_low;
4711 /* The 82571 firmware may still be configuring the PHY. In this
4712 * case, we cannot access the PHY until the configuration is done. So
4713 * we explicitly set the PHY values. */
4714 if (hw->mac_type == e1000_82571 ||
4715 hw->mac_type == e1000_82572) {
4716 hw->phy_id = IGP01E1000_I_PHY_ID;
4717 hw->phy_type = e1000_phy_igp_2;
4718 return E1000_SUCCESS;
4721 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a
4722 * work- around that forces PHY page 0 to be set or the reads fail.
4723 * The rest of the code in this routine uses e1000_read_phy_reg to
4724 * read the PHY ID. So for ESB-2 we need to have this set so our
4725 * reads won't fail. If the attached PHY is not a e1000_phy_gg82563,
4726 * the routines below will figure this out as well. */
4727 if (hw->mac_type == e1000_80003es2lan)
4728 hw->phy_type = e1000_phy_gg82563;
4730 /* Read the PHY ID Registers to identify which PHY is onboard. */
4731 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
4735 hw->phy_id = (uint32_t) (phy_id_high << 16);
4737 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
4741 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4742 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4744 switch (hw->mac_type) {
4746 if (hw->phy_id == M88E1000_E_PHY_ID)
4750 if (hw->phy_id == M88E1000_I_PHY_ID)
4755 case e1000_82545_rev_3:
4757 case e1000_82546_rev_3:
4758 if (hw->phy_id == M88E1011_I_PHY_ID)
4762 case e1000_82541_rev_2:
4764 case e1000_82547_rev_2:
4765 if(hw->phy_id == IGP01E1000_I_PHY_ID)
4770 if (hw->phy_id == M88E1111_I_PHY_ID)
4774 if (hw->phy_id == BME1000_E_PHY_ID)
4777 case e1000_80003es2lan:
4778 if (hw->phy_id == GG82563_E_PHY_ID)
4782 if (hw->phy_id == IGP03E1000_E_PHY_ID)
4784 if (hw->phy_id == IFE_E_PHY_ID)
4786 if (hw->phy_id == IFE_PLUS_E_PHY_ID)
4788 if (hw->phy_id == IFE_C_E_PHY_ID)
4792 if (hw->phy_id == I210_I_PHY_ID)
4796 DEBUGOUT("Invalid MAC type %d\n", hw->mac_type);
4797 return -E1000_ERR_CONFIG;
4800 phy_init_status = e1000_set_phy_type(hw);
4802 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4803 DEBUGOUT("PHY ID 0x%X detected\n", hw->phy_id);
4806 DEBUGOUT("Invalid PHY ID 0x%X\n", hw->phy_id);
4807 return -E1000_ERR_PHY;
4810 /*****************************************************************************
4811 * Set media type and TBI compatibility.
4813 * hw - Struct containing variables accessed by shared code
4814 * **************************************************************************/
4816 e1000_set_media_type(struct e1000_hw *hw)
4822 if (hw->mac_type != e1000_82543) {
4823 /* tbi_compatibility is only valid on 82543 */
4824 hw->tbi_compatibility_en = false;
4827 switch (hw->device_id) {
4828 case E1000_DEV_ID_82545GM_SERDES:
4829 case E1000_DEV_ID_82546GB_SERDES:
4830 case E1000_DEV_ID_82571EB_SERDES:
4831 case E1000_DEV_ID_82571EB_SERDES_DUAL:
4832 case E1000_DEV_ID_82571EB_SERDES_QUAD:
4833 case E1000_DEV_ID_82572EI_SERDES:
4834 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
4835 hw->media_type = e1000_media_type_internal_serdes;
4838 switch (hw->mac_type) {
4839 case e1000_82542_rev2_0:
4840 case e1000_82542_rev2_1:
4841 hw->media_type = e1000_media_type_fiber;
4847 /* The STATUS_TBIMODE bit is reserved or reused
4848 * for the this device.
4850 hw->media_type = e1000_media_type_copper;
4853 status = E1000_READ_REG(hw, STATUS);
4854 if (status & E1000_STATUS_TBIMODE) {
4855 hw->media_type = e1000_media_type_fiber;
4856 /* tbi_compatibility not valid on fiber */
4857 hw->tbi_compatibility_en = false;
4859 hw->media_type = e1000_media_type_copper;
4867 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4869 * e1000_sw_init initializes the Adapter private data structure.
4870 * Fields are initialized based on PCI device information and
4871 * OS network device settings (MTU size).
4875 e1000_sw_init(struct e1000_hw *hw)
4879 /* PCI config space info */
4880 pci_read_config_word(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
4881 pci_read_config_word(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
4882 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
4883 &hw->subsystem_vendor_id);
4884 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
4886 pci_read_config_byte(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
4887 pci_read_config_word(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
4889 /* identify the MAC */
4890 result = e1000_set_mac_type(hw);
4892 E1000_ERR(hw, "Unknown MAC Type\n");
4896 switch (hw->mac_type) {
4901 case e1000_82541_rev_2:
4902 case e1000_82547_rev_2:
4903 hw->phy_init_script = 1;
4907 /* flow control settings */
4908 hw->fc_high_water = E1000_FC_HIGH_THRESH;
4909 hw->fc_low_water = E1000_FC_LOW_THRESH;
4910 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
4911 hw->fc_send_xon = 1;
4913 /* Media type - copper or fiber */
4914 hw->tbi_compatibility_en = true;
4915 e1000_set_media_type(hw);
4917 if (hw->mac_type >= e1000_82543) {
4918 uint32_t status = E1000_READ_REG(hw, STATUS);
4920 if (status & E1000_STATUS_TBIMODE) {
4921 DEBUGOUT("fiber interface\n");
4922 hw->media_type = e1000_media_type_fiber;
4924 DEBUGOUT("copper interface\n");
4925 hw->media_type = e1000_media_type_copper;
4928 hw->media_type = e1000_media_type_fiber;
4931 hw->wait_autoneg_complete = true;
4932 if (hw->mac_type < e1000_82543)
4933 hw->report_tx_early = 0;
4935 hw->report_tx_early = 1;
4937 return E1000_SUCCESS;
4941 fill_rx(struct e1000_hw *hw)
4943 struct e1000_rx_desc *rd;
4944 unsigned long flush_start, flush_end;
4947 rd = rx_base + rx_tail;
4948 rx_tail = (rx_tail + 1) % 8;
4950 rd->buffer_addr = cpu_to_le64((unsigned long)packet);
4953 * Make sure there are no stale data in WB over this area, which
4954 * might get written into the memory while the e1000 also writes
4955 * into the same memory area.
4957 invalidate_dcache_range((unsigned long)packet,
4958 (unsigned long)packet + 4096);
4959 /* Dump the DMA descriptor into RAM. */
4960 flush_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
4961 flush_end = flush_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
4962 flush_dcache_range(flush_start, flush_end);
4964 E1000_WRITE_REG(hw, RDT, rx_tail);
4968 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
4969 * @adapter: board private structure
4971 * Configure the Tx unit of the MAC after a reset.
4975 e1000_configure_tx(struct e1000_hw *hw)
4978 unsigned long tipg, tarc;
4979 uint32_t ipgr1, ipgr2;
4981 E1000_WRITE_REG(hw, TDBAL, (unsigned long)tx_base & 0xffffffff);
4982 E1000_WRITE_REG(hw, TDBAH, (unsigned long)tx_base >> 32);
4984 E1000_WRITE_REG(hw, TDLEN, 128);
4986 /* Setup the HW Tx Head and Tail descriptor pointers */
4987 E1000_WRITE_REG(hw, TDH, 0);
4988 E1000_WRITE_REG(hw, TDT, 0);
4991 /* Set the default values for the Tx Inter Packet Gap timer */
4992 if (hw->mac_type <= e1000_82547_rev_2 &&
4993 (hw->media_type == e1000_media_type_fiber ||
4994 hw->media_type == e1000_media_type_internal_serdes))
4995 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
4997 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
4999 /* Set the default values for the Tx Inter Packet Gap timer */
5000 switch (hw->mac_type) {
5001 case e1000_82542_rev2_0:
5002 case e1000_82542_rev2_1:
5003 tipg = DEFAULT_82542_TIPG_IPGT;
5004 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
5005 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
5007 case e1000_80003es2lan:
5008 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
5009 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
5012 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
5013 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
5016 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
5017 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
5018 E1000_WRITE_REG(hw, TIPG, tipg);
5019 /* Program the Transmit Control Register */
5020 tctl = E1000_READ_REG(hw, TCTL);
5021 tctl &= ~E1000_TCTL_CT;
5022 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
5023 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
5025 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
5026 tarc = E1000_READ_REG(hw, TARC0);
5027 /* set the speed mode bit, we'll clear it if we're not at
5028 * gigabit link later */
5029 /* git bit can be set to 1*/
5030 } else if (hw->mac_type == e1000_80003es2lan) {
5031 tarc = E1000_READ_REG(hw, TARC0);
5033 E1000_WRITE_REG(hw, TARC0, tarc);
5034 tarc = E1000_READ_REG(hw, TARC1);
5036 E1000_WRITE_REG(hw, TARC1, tarc);
5040 e1000_config_collision_dist(hw);
5041 /* Setup Transmit Descriptor Settings for eop descriptor */
5042 hw->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
5044 /* Need to set up RS bit */
5045 if (hw->mac_type < e1000_82543)
5046 hw->txd_cmd |= E1000_TXD_CMD_RPS;
5048 hw->txd_cmd |= E1000_TXD_CMD_RS;
5051 if (hw->mac_type == e1000_igb) {
5052 E1000_WRITE_REG(hw, TCTL_EXT, 0x42 << 10);
5054 uint32_t reg_txdctl = E1000_READ_REG(hw, TXDCTL);
5055 reg_txdctl |= 1 << 25;
5056 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
5062 E1000_WRITE_REG(hw, TCTL, tctl);
5068 * e1000_setup_rctl - configure the receive control register
5069 * @adapter: Board private structure
5072 e1000_setup_rctl(struct e1000_hw *hw)
5076 rctl = E1000_READ_REG(hw, RCTL);
5078 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
5080 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO
5081 | E1000_RCTL_RDMTS_HALF; /* |
5082 (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */
5084 if (hw->tbi_compatibility_on == 1)
5085 rctl |= E1000_RCTL_SBP;
5087 rctl &= ~E1000_RCTL_SBP;
5089 rctl &= ~(E1000_RCTL_SZ_4096);
5090 rctl |= E1000_RCTL_SZ_2048;
5091 rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
5092 E1000_WRITE_REG(hw, RCTL, rctl);
5096 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
5097 * @adapter: board private structure
5099 * Configure the Rx unit of the MAC after a reset.
5102 e1000_configure_rx(struct e1000_hw *hw)
5104 unsigned long rctl, ctrl_ext;
5106 /* make sure receives are disabled while setting up the descriptors */
5107 rctl = E1000_READ_REG(hw, RCTL);
5108 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
5109 if (hw->mac_type >= e1000_82540) {
5110 /* Set the interrupt throttling rate. Value is calculated
5111 * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */
5112 #define MAX_INTS_PER_SEC 8000
5113 #define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
5114 E1000_WRITE_REG(hw, ITR, DEFAULT_ITR);
5117 if (hw->mac_type >= e1000_82571) {
5118 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5119 /* Reset delay timers after every interrupt */
5120 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
5121 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
5122 E1000_WRITE_FLUSH(hw);
5124 /* Setup the Base and Length of the Rx Descriptor Ring */
5125 E1000_WRITE_REG(hw, RDBAL, (unsigned long)rx_base & 0xffffffff);
5126 E1000_WRITE_REG(hw, RDBAH, (unsigned long)rx_base >> 32);
5128 E1000_WRITE_REG(hw, RDLEN, 128);
5130 /* Setup the HW Rx Head and Tail Descriptor Pointers */
5131 E1000_WRITE_REG(hw, RDH, 0);
5132 E1000_WRITE_REG(hw, RDT, 0);
5133 /* Enable Receives */
5135 if (hw->mac_type == e1000_igb) {
5137 uint32_t reg_rxdctl = E1000_READ_REG(hw, RXDCTL);
5138 reg_rxdctl |= 1 << 25;
5139 E1000_WRITE_REG(hw, RXDCTL, reg_rxdctl);
5143 E1000_WRITE_REG(hw, RCTL, rctl);
5148 /**************************************************************************
5149 POLL - Wait for a frame
5150 ***************************************************************************/
5152 _e1000_poll(struct e1000_hw *hw)
5154 struct e1000_rx_desc *rd;
5155 unsigned long inval_start, inval_end;
5158 /* return true if there's an ethernet packet ready to read */
5159 rd = rx_base + rx_last;
5161 /* Re-load the descriptor from RAM. */
5162 inval_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
5163 inval_end = inval_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
5164 invalidate_dcache_range(inval_start, inval_end);
5166 if (!(le32_to_cpu(rd->status)) & E1000_RXD_STAT_DD)
5168 /* DEBUGOUT("recv: packet len=%d\n", rd->length); */
5169 /* Packet received, make sure the data are re-loaded from RAM. */
5170 len = le32_to_cpu(rd->length);
5171 invalidate_dcache_range((unsigned long)packet,
5172 (unsigned long)packet +
5173 roundup(len, ARCH_DMA_MINALIGN));
5177 static int _e1000_transmit(struct e1000_hw *hw, void *txpacket, int length)
5179 void *nv_packet = (void *)txpacket;
5180 struct e1000_tx_desc *txp;
5182 unsigned long flush_start, flush_end;
5184 txp = tx_base + tx_tail;
5185 tx_tail = (tx_tail + 1) % 8;
5187 txp->buffer_addr = cpu_to_le64(virt_to_bus(hw->pdev, nv_packet));
5188 txp->lower.data = cpu_to_le32(hw->txd_cmd | length);
5189 txp->upper.data = 0;
5191 /* Dump the packet into RAM so e1000 can pick them. */
5192 flush_dcache_range((unsigned long)nv_packet,
5193 (unsigned long)nv_packet +
5194 roundup(length, ARCH_DMA_MINALIGN));
5195 /* Dump the descriptor into RAM as well. */
5196 flush_start = ((unsigned long)txp) & ~(ARCH_DMA_MINALIGN - 1);
5197 flush_end = flush_start + roundup(sizeof(*txp), ARCH_DMA_MINALIGN);
5198 flush_dcache_range(flush_start, flush_end);
5200 E1000_WRITE_REG(hw, TDT, tx_tail);
5202 E1000_WRITE_FLUSH(hw);
5204 invalidate_dcache_range(flush_start, flush_end);
5205 if (le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD)
5207 if (i++ > TOUT_LOOP) {
5208 DEBUGOUT("e1000: tx timeout\n");
5211 udelay(10); /* give the nic a chance to write to the register */
5217 _e1000_disable(struct e1000_hw *hw)
5219 /* Turn off the ethernet interface */
5220 E1000_WRITE_REG(hw, RCTL, 0);
5221 E1000_WRITE_REG(hw, TCTL, 0);
5223 /* Clear the transmit ring */
5224 E1000_WRITE_REG(hw, TDH, 0);
5225 E1000_WRITE_REG(hw, TDT, 0);
5227 /* Clear the receive ring */
5228 E1000_WRITE_REG(hw, RDH, 0);
5229 E1000_WRITE_REG(hw, RDT, 0);
5231 /* put the card in its initial state */
5233 E1000_WRITE_REG(hw, CTRL, E1000_CTRL_RST);
5240 e1000_reset(struct e1000_hw *hw, unsigned char enetaddr[6])
5243 if (hw->mac_type >= e1000_82544)
5244 E1000_WRITE_REG(hw, WUC, 0);
5246 return e1000_init_hw(hw, enetaddr);
5250 _e1000_init(struct e1000_hw *hw, unsigned char enetaddr[6])
5254 ret_val = e1000_reset(hw, enetaddr);
5256 if ((ret_val == -E1000_ERR_NOLINK) ||
5257 (ret_val == -E1000_ERR_TIMEOUT)) {
5258 E1000_ERR(hw, "Valid Link not detected: %d\n", ret_val);
5260 E1000_ERR(hw, "Hardware Initialization Failed\n");
5264 e1000_configure_tx(hw);
5265 e1000_setup_rctl(hw);
5266 e1000_configure_rx(hw);
5270 /******************************************************************************
5271 * Gets the current PCI bus type of hardware
5273 * hw - Struct containing variables accessed by shared code
5274 *****************************************************************************/
5275 void e1000_get_bus_type(struct e1000_hw *hw)
5279 switch (hw->mac_type) {
5280 case e1000_82542_rev2_0:
5281 case e1000_82542_rev2_1:
5282 hw->bus_type = e1000_bus_type_pci;
5288 case e1000_80003es2lan:
5291 hw->bus_type = e1000_bus_type_pci_express;
5294 status = E1000_READ_REG(hw, STATUS);
5295 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5296 e1000_bus_type_pcix : e1000_bus_type_pci;
5301 #ifndef CONFIG_DM_ETH
5302 /* A list of all registered e1000 devices */
5303 static LIST_HEAD(e1000_hw_list);
5306 static int e1000_init_one(struct e1000_hw *hw, int cardnum, pci_dev_t devno,
5307 unsigned char enetaddr[6])
5311 /* Assign the passed-in values */
5313 hw->cardnum = cardnum;
5315 /* Print a debug message with the IO base address */
5316 pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &val);
5317 E1000_DBG(hw, "iobase 0x%08x\n", val & 0xfffffff0);
5319 /* Try to enable I/O accesses and bus-mastering */
5320 val = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
5321 pci_write_config_dword(devno, PCI_COMMAND, val);
5323 /* Make sure it worked */
5324 pci_read_config_dword(devno, PCI_COMMAND, &val);
5325 if (!(val & PCI_COMMAND_MEMORY)) {
5326 E1000_ERR(hw, "Can't enable I/O memory\n");
5329 if (!(val & PCI_COMMAND_MASTER)) {
5330 E1000_ERR(hw, "Can't enable bus-mastering\n");
5334 /* Are these variables needed? */
5335 hw->fc = e1000_fc_default;
5336 hw->original_fc = e1000_fc_default;
5337 hw->autoneg_failed = 0;
5339 hw->get_link_status = true;
5340 #ifndef CONFIG_E1000_NO_NVM
5341 hw->eeprom_semaphore_present = true;
5343 hw->hw_addr = pci_map_bar(devno, PCI_BASE_ADDRESS_0,
5345 hw->mac_type = e1000_undefined;
5347 /* MAC and Phy settings */
5348 if (e1000_sw_init(hw) < 0) {
5349 E1000_ERR(hw, "Software init failed\n");
5352 if (e1000_check_phy_reset_block(hw))
5353 E1000_ERR(hw, "PHY Reset is blocked!\n");
5355 /* Basic init was OK, reset the hardware and allow SPI access */
5358 #ifndef CONFIG_E1000_NO_NVM
5359 /* Validate the EEPROM and get chipset information */
5360 #if !defined(CONFIG_MVBC_1G)
5361 if (e1000_init_eeprom_params(hw)) {
5362 E1000_ERR(hw, "EEPROM is invalid!\n");
5365 if ((E1000_READ_REG(hw, I210_EECD) & E1000_EECD_FLUPD) &&
5366 e1000_validate_eeprom_checksum(hw))
5369 e1000_read_mac_addr(hw, enetaddr);
5371 e1000_get_bus_type(hw);
5373 #ifndef CONFIG_E1000_NO_NVM
5374 printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n ",
5375 enetaddr[0], enetaddr[1], enetaddr[2],
5376 enetaddr[3], enetaddr[4], enetaddr[5]);
5378 memset(enetaddr, 0, 6);
5379 printf("e1000: no NVM\n");
5385 /* Put the name of a device in a string */
5386 static void e1000_name(char *str, int cardnum)
5388 sprintf(str, "e1000#%u", cardnum);
5391 #ifndef CONFIG_DM_ETH
5392 /**************************************************************************
5393 TRANSMIT - Transmit a frame
5394 ***************************************************************************/
5395 static int e1000_transmit(struct eth_device *nic, void *txpacket, int length)
5397 struct e1000_hw *hw = nic->priv;
5399 return _e1000_transmit(hw, txpacket, length);
5402 /**************************************************************************
5403 DISABLE - Turn off ethernet interface
5404 ***************************************************************************/
5406 e1000_disable(struct eth_device *nic)
5408 struct e1000_hw *hw = nic->priv;
5413 /**************************************************************************
5414 INIT - set up ethernet interface(s)
5415 ***************************************************************************/
5417 e1000_init(struct eth_device *nic, bd_t *bis)
5419 struct e1000_hw *hw = nic->priv;
5421 return _e1000_init(hw, nic->enetaddr);
5425 e1000_poll(struct eth_device *nic)
5427 struct e1000_hw *hw = nic->priv;
5430 len = _e1000_poll(hw);
5432 net_process_received_packet((uchar *)packet, len);
5439 /**************************************************************************
5440 PROBE - Look for an adapter, this routine's visible to the outside
5441 You should omit the last argument struct pci_device * for a non-PCI NIC
5442 ***************************************************************************/
5444 e1000_initialize(bd_t * bis)
5452 /* Find and probe all the matching PCI devices */
5453 for (i = 0; (devno = pci_find_devices(e1000_supported, i)) >= 0; i++) {
5455 * These will never get freed due to errors, this allows us to
5456 * perform SPI EEPROM programming from U-boot, for example.
5458 struct eth_device *nic = malloc(sizeof(*nic));
5459 struct e1000_hw *hw = malloc(sizeof(*hw));
5461 printf("e1000#%u: Out of Memory!\n", i);
5467 /* Make sure all of the fields are initially zeroed */
5468 memset(nic, 0, sizeof(*nic));
5469 memset(hw, 0, sizeof(*hw));
5472 /* Generate a card name */
5473 e1000_name(nic->name, i);
5474 hw->name = nic->name;
5476 ret = e1000_init_one(hw, i, devno, nic->enetaddr);
5479 list_add_tail(&hw->list_node, &e1000_hw_list);
5483 /* Set up the function pointers and register the device */
5484 nic->init = e1000_init;
5485 nic->recv = e1000_poll;
5486 nic->send = e1000_transmit;
5487 nic->halt = e1000_disable;
5494 struct e1000_hw *e1000_find_card(unsigned int cardnum)
5496 struct e1000_hw *hw;
5498 list_for_each_entry(hw, &e1000_hw_list, list_node)
5499 if (hw->cardnum == cardnum)
5504 #endif /* !CONFIG_DM_ETH */
5506 #ifdef CONFIG_CMD_E1000
5507 static int do_e1000(cmd_tbl_t *cmdtp, int flag,
5508 int argc, char * const argv[])
5510 unsigned char *mac = NULL;
5511 #ifdef CONFIG_DM_ETH
5512 struct eth_pdata *plat;
5513 struct udevice *dev;
5517 struct e1000_hw *hw;
5526 /* Make sure we can find the requested e1000 card */
5527 cardnum = simple_strtoul(argv[1], NULL, 10);
5528 #ifdef CONFIG_DM_ETH
5529 e1000_name(name, cardnum);
5530 ret = uclass_get_device_by_name(UCLASS_ETH, name, &dev);
5532 plat = dev_get_platdata(dev);
5533 mac = plat->enetaddr;
5536 hw = e1000_find_card(cardnum);
5538 mac = hw->nic->enetaddr;
5541 printf("e1000: ERROR: No such device: e1000#%s\n", argv[1]);
5545 if (!strcmp(argv[2], "print-mac-address")) {
5546 printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
5547 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
5551 #ifdef CONFIG_E1000_SPI
5552 /* Handle the "SPI" subcommand */
5553 if (!strcmp(argv[2], "spi"))
5554 return do_e1000_spi(cmdtp, hw, argc - 3, argv + 3);
5562 e1000, 7, 0, do_e1000,
5563 "Intel e1000 controller management",
5564 /* */"<card#> print-mac-address\n"
5565 #ifdef CONFIG_E1000_SPI
5566 "e1000 <card#> spi show [<offset> [<length>]]\n"
5567 "e1000 <card#> spi dump <addr> <offset> <length>\n"
5568 "e1000 <card#> spi program <addr> <offset> <length>\n"
5569 "e1000 <card#> spi checksum [update]\n"
5571 " - Manage the Intel E1000 PCI device"
5573 #endif /* not CONFIG_CMD_E1000 */
5575 #ifdef CONFIG_DM_ETH
5576 static int e1000_eth_start(struct udevice *dev)
5578 struct eth_pdata *plat = dev_get_platdata(dev);
5579 struct e1000_hw *hw = dev_get_priv(dev);
5581 return _e1000_init(hw, plat->enetaddr);
5584 static void e1000_eth_stop(struct udevice *dev)
5586 struct e1000_hw *hw = dev_get_priv(dev);
5591 static int e1000_eth_send(struct udevice *dev, void *packet, int length)
5593 struct e1000_hw *hw = dev_get_priv(dev);
5596 ret = _e1000_transmit(hw, packet, length);
5598 return ret ? 0 : -ETIMEDOUT;
5601 static int e1000_eth_recv(struct udevice *dev, int flags, uchar **packetp)
5603 struct e1000_hw *hw = dev_get_priv(dev);
5606 len = _e1000_poll(hw);
5610 return len ? len : -EAGAIN;
5613 static int e1000_free_pkt(struct udevice *dev, uchar *packet, int length)
5615 struct e1000_hw *hw = dev_get_priv(dev);
5622 static int e1000_eth_probe(struct udevice *dev)
5624 struct eth_pdata *plat = dev_get_platdata(dev);
5625 struct e1000_hw *hw = dev_get_priv(dev);
5628 hw->name = dev->name;
5629 ret = e1000_init_one(hw, trailing_strtol(dev->name), pci_get_bdf(dev),
5632 printf(pr_fmt("failed to initialize card: %d\n"), ret);
5639 static int e1000_eth_bind(struct udevice *dev)
5644 * A simple way to number the devices. When device tree is used this
5645 * is unnecessary, but when the device is just discovered on the PCI
5646 * bus we need a name. We could instead have the uclass figure out
5647 * which devices are different and number them.
5649 e1000_name(name, num_cards++);
5651 return device_set_name(dev, name);
5654 static const struct eth_ops e1000_eth_ops = {
5655 .start = e1000_eth_start,
5656 .send = e1000_eth_send,
5657 .recv = e1000_eth_recv,
5658 .stop = e1000_eth_stop,
5659 .free_pkt = e1000_free_pkt,
5662 static const struct udevice_id e1000_eth_ids[] = {
5663 { .compatible = "intel,e1000" },
5667 U_BOOT_DRIVER(eth_e1000) = {
5668 .name = "eth_e1000",
5670 .of_match = e1000_eth_ids,
5671 .bind = e1000_eth_bind,
5672 .probe = e1000_eth_probe,
5673 .ops = &e1000_eth_ops,
5674 .priv_auto_alloc_size = sizeof(struct e1000_hw),
5675 .platdata_auto_alloc_size = sizeof(struct eth_pdata),
5678 U_BOOT_PCI_DEVICE(eth_e1000, e1000_supported);