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.
39 #define TOUT_LOOP 100000
42 #define virt_to_bus(devno, v) dm_pci_virt_to_mem(devno, (void *) (v))
43 #define bus_to_phys(devno, a) dm_pci_mem_to_phys(devno, a)
45 #define virt_to_bus(devno, v) pci_virt_to_mem(devno, (void *) (v))
46 #define bus_to_phys(devno, a) pci_mem_to_phys(devno, a)
49 #define E1000_DEFAULT_PCI_PBA 0x00000030
50 #define E1000_DEFAULT_PCIE_PBA 0x000a0026
52 /* NIC specific static variables go here */
54 /* Intel i210 needs the DMA descriptor rings aligned to 128b */
55 #define E1000_BUFFER_ALIGN 128
58 * TODO(sjg@chromium.org): Even with driver model we share these buffers.
59 * Concurrent receiving on multiple active Ethernet devices will not work.
60 * Normally U-Boot does not support this anyway. To fix it in this driver,
61 * move these buffers and the tx/rx pointers to struct e1000_hw.
63 DEFINE_ALIGN_BUFFER(struct e1000_tx_desc, tx_base, 16, E1000_BUFFER_ALIGN);
64 DEFINE_ALIGN_BUFFER(struct e1000_rx_desc, rx_base, 16, E1000_BUFFER_ALIGN);
65 DEFINE_ALIGN_BUFFER(unsigned char, packet, 4096, E1000_BUFFER_ALIGN);
68 static int rx_tail, rx_last;
70 static int num_cards; /* Number of E1000 devices seen so far */
73 static struct pci_device_id e1000_supported[] = {
74 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82542) },
75 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_FIBER) },
76 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_COPPER) },
77 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_COPPER) },
78 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_FIBER) },
79 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_COPPER) },
80 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_LOM) },
81 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM) },
82 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_COPPER) },
83 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545GM_COPPER) },
84 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_COPPER) },
85 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_FIBER) },
86 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_FIBER) },
87 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_COPPER) },
88 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM_LOM) },
89 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541ER) },
90 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541GI_LF) },
92 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_COPPER) },
93 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_FIBER) },
94 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES) },
95 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER) },
96 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571PT_QUAD_COPPER) },
97 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_FIBER) },
98 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER_LOWPROFILE) },
99 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_DUAL) },
100 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_QUAD) },
101 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_COPPER) },
102 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_FIBER) },
103 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_SERDES) },
104 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI) },
105 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E) },
106 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E_IAMT) },
107 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573L) },
108 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82574L) },
109 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_QUAD_COPPER_KSP3) },
110 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_DPT) },
111 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_DPT) },
112 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_SPT) },
113 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_SPT) },
114 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED) },
115 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED) },
116 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER) },
117 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_COPPER) },
118 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS) },
119 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES) },
120 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS) },
121 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_1000BASEKX) },
126 /* Function forward declarations */
127 static int e1000_setup_link(struct e1000_hw *hw);
128 static int e1000_setup_fiber_link(struct e1000_hw *hw);
129 static int e1000_setup_copper_link(struct e1000_hw *hw);
130 static int e1000_phy_setup_autoneg(struct e1000_hw *hw);
131 static void e1000_config_collision_dist(struct e1000_hw *hw);
132 static int e1000_config_mac_to_phy(struct e1000_hw *hw);
133 static int e1000_config_fc_after_link_up(struct e1000_hw *hw);
134 static int e1000_check_for_link(struct e1000_hw *hw);
135 static int e1000_wait_autoneg(struct e1000_hw *hw);
136 static int e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t * speed,
138 static int e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
139 uint16_t * phy_data);
140 static int e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
142 static int32_t e1000_phy_hw_reset(struct e1000_hw *hw);
143 static int e1000_phy_reset(struct e1000_hw *hw);
144 static int e1000_detect_gig_phy(struct e1000_hw *hw);
145 static void e1000_set_media_type(struct e1000_hw *hw);
147 static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
148 static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
149 static int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
151 #ifndef CONFIG_E1000_NO_NVM
152 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
153 static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
154 static int32_t e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
157 /******************************************************************************
158 * Raises the EEPROM's clock input.
160 * hw - Struct containing variables accessed by shared code
161 * eecd - EECD's current value
162 *****************************************************************************/
163 void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
165 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
166 * wait 50 microseconds.
168 *eecd = *eecd | E1000_EECD_SK;
169 E1000_WRITE_REG(hw, EECD, *eecd);
170 E1000_WRITE_FLUSH(hw);
174 /******************************************************************************
175 * Lowers the EEPROM's clock input.
177 * hw - Struct containing variables accessed by shared code
178 * eecd - EECD's current value
179 *****************************************************************************/
180 void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
182 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
183 * wait 50 microseconds.
185 *eecd = *eecd & ~E1000_EECD_SK;
186 E1000_WRITE_REG(hw, EECD, *eecd);
187 E1000_WRITE_FLUSH(hw);
191 /******************************************************************************
192 * Shift data bits out to the EEPROM.
194 * hw - Struct containing variables accessed by shared code
195 * data - data to send to the EEPROM
196 * count - number of bits to shift out
197 *****************************************************************************/
199 e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count)
204 /* We need to shift "count" bits out to the EEPROM. So, value in the
205 * "data" parameter will be shifted out to the EEPROM one bit at a time.
206 * In order to do this, "data" must be broken down into bits.
208 mask = 0x01 << (count - 1);
209 eecd = E1000_READ_REG(hw, EECD);
210 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
212 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
213 * and then raising and then lowering the clock (the SK bit controls
214 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
215 * by setting "DI" to "0" and then raising and then lowering the clock.
217 eecd &= ~E1000_EECD_DI;
220 eecd |= E1000_EECD_DI;
222 E1000_WRITE_REG(hw, EECD, eecd);
223 E1000_WRITE_FLUSH(hw);
227 e1000_raise_ee_clk(hw, &eecd);
228 e1000_lower_ee_clk(hw, &eecd);
234 /* We leave the "DI" bit set to "0" when we leave this routine. */
235 eecd &= ~E1000_EECD_DI;
236 E1000_WRITE_REG(hw, EECD, eecd);
239 /******************************************************************************
240 * Shift data bits in from the EEPROM
242 * hw - Struct containing variables accessed by shared code
243 *****************************************************************************/
245 e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count)
251 /* In order to read a register from the EEPROM, we need to shift 'count'
252 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
253 * input to the EEPROM (setting the SK bit), and then reading the
254 * value of the "DO" bit. During this "shifting in" process the
255 * "DI" bit should always be clear.
258 eecd = E1000_READ_REG(hw, EECD);
260 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
263 for (i = 0; i < count; i++) {
265 e1000_raise_ee_clk(hw, &eecd);
267 eecd = E1000_READ_REG(hw, EECD);
269 eecd &= ~(E1000_EECD_DI);
270 if (eecd & E1000_EECD_DO)
273 e1000_lower_ee_clk(hw, &eecd);
279 /******************************************************************************
280 * Returns EEPROM to a "standby" state
282 * hw - Struct containing variables accessed by shared code
283 *****************************************************************************/
284 void e1000_standby_eeprom(struct e1000_hw *hw)
286 struct e1000_eeprom_info *eeprom = &hw->eeprom;
289 eecd = E1000_READ_REG(hw, EECD);
291 if (eeprom->type == e1000_eeprom_microwire) {
292 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
293 E1000_WRITE_REG(hw, EECD, eecd);
294 E1000_WRITE_FLUSH(hw);
295 udelay(eeprom->delay_usec);
298 eecd |= E1000_EECD_SK;
299 E1000_WRITE_REG(hw, EECD, eecd);
300 E1000_WRITE_FLUSH(hw);
301 udelay(eeprom->delay_usec);
304 eecd |= E1000_EECD_CS;
305 E1000_WRITE_REG(hw, EECD, eecd);
306 E1000_WRITE_FLUSH(hw);
307 udelay(eeprom->delay_usec);
310 eecd &= ~E1000_EECD_SK;
311 E1000_WRITE_REG(hw, EECD, eecd);
312 E1000_WRITE_FLUSH(hw);
313 udelay(eeprom->delay_usec);
314 } else if (eeprom->type == e1000_eeprom_spi) {
315 /* Toggle CS to flush commands */
316 eecd |= E1000_EECD_CS;
317 E1000_WRITE_REG(hw, EECD, eecd);
318 E1000_WRITE_FLUSH(hw);
319 udelay(eeprom->delay_usec);
320 eecd &= ~E1000_EECD_CS;
321 E1000_WRITE_REG(hw, EECD, eecd);
322 E1000_WRITE_FLUSH(hw);
323 udelay(eeprom->delay_usec);
327 /***************************************************************************
328 * Description: Determines if the onboard NVM is FLASH or EEPROM.
330 * hw - Struct containing variables accessed by shared code
331 ****************************************************************************/
332 static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
338 if (hw->mac_type == e1000_ich8lan)
341 if (hw->mac_type == e1000_82573 || hw->mac_type == e1000_82574) {
342 eecd = E1000_READ_REG(hw, EECD);
344 /* Isolate bits 15 & 16 */
345 eecd = ((eecd >> 15) & 0x03);
347 /* If both bits are set, device is Flash type */
354 /******************************************************************************
355 * Prepares EEPROM for access
357 * hw - Struct containing variables accessed by shared code
359 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
360 * function should be called before issuing a command to the EEPROM.
361 *****************************************************************************/
362 int32_t e1000_acquire_eeprom(struct e1000_hw *hw)
364 struct e1000_eeprom_info *eeprom = &hw->eeprom;
365 uint32_t eecd, i = 0;
369 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
370 return -E1000_ERR_SWFW_SYNC;
371 eecd = E1000_READ_REG(hw, EECD);
373 if (hw->mac_type != e1000_82573 && hw->mac_type != e1000_82574) {
374 /* Request EEPROM Access */
375 if (hw->mac_type > e1000_82544) {
376 eecd |= E1000_EECD_REQ;
377 E1000_WRITE_REG(hw, EECD, eecd);
378 eecd = E1000_READ_REG(hw, EECD);
379 while ((!(eecd & E1000_EECD_GNT)) &&
380 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
383 eecd = E1000_READ_REG(hw, EECD);
385 if (!(eecd & E1000_EECD_GNT)) {
386 eecd &= ~E1000_EECD_REQ;
387 E1000_WRITE_REG(hw, EECD, eecd);
388 DEBUGOUT("Could not acquire EEPROM grant\n");
389 return -E1000_ERR_EEPROM;
394 /* Setup EEPROM for Read/Write */
396 if (eeprom->type == e1000_eeprom_microwire) {
397 /* Clear SK and DI */
398 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
399 E1000_WRITE_REG(hw, EECD, eecd);
402 eecd |= E1000_EECD_CS;
403 E1000_WRITE_REG(hw, EECD, eecd);
404 } else if (eeprom->type == e1000_eeprom_spi) {
405 /* Clear SK and CS */
406 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
407 E1000_WRITE_REG(hw, EECD, eecd);
411 return E1000_SUCCESS;
414 /******************************************************************************
415 * Sets up eeprom variables in the hw struct. Must be called after mac_type
416 * is configured. Additionally, if this is ICH8, the flash controller GbE
417 * registers must be mapped, or this will crash.
419 * hw - Struct containing variables accessed by shared code
420 *****************************************************************************/
421 static int32_t e1000_init_eeprom_params(struct e1000_hw *hw)
423 struct e1000_eeprom_info *eeprom = &hw->eeprom;
425 int32_t ret_val = E1000_SUCCESS;
426 uint16_t eeprom_size;
428 if (hw->mac_type == e1000_igb)
429 eecd = E1000_READ_REG(hw, I210_EECD);
431 eecd = E1000_READ_REG(hw, EECD);
435 switch (hw->mac_type) {
436 case e1000_82542_rev2_0:
437 case e1000_82542_rev2_1:
440 eeprom->type = e1000_eeprom_microwire;
441 eeprom->word_size = 64;
442 eeprom->opcode_bits = 3;
443 eeprom->address_bits = 6;
444 eeprom->delay_usec = 50;
445 eeprom->use_eerd = false;
446 eeprom->use_eewr = false;
450 case e1000_82545_rev_3:
452 case e1000_82546_rev_3:
453 eeprom->type = e1000_eeprom_microwire;
454 eeprom->opcode_bits = 3;
455 eeprom->delay_usec = 50;
456 if (eecd & E1000_EECD_SIZE) {
457 eeprom->word_size = 256;
458 eeprom->address_bits = 8;
460 eeprom->word_size = 64;
461 eeprom->address_bits = 6;
463 eeprom->use_eerd = false;
464 eeprom->use_eewr = false;
467 case e1000_82541_rev_2:
469 case e1000_82547_rev_2:
470 if (eecd & E1000_EECD_TYPE) {
471 eeprom->type = e1000_eeprom_spi;
472 eeprom->opcode_bits = 8;
473 eeprom->delay_usec = 1;
474 if (eecd & E1000_EECD_ADDR_BITS) {
475 eeprom->page_size = 32;
476 eeprom->address_bits = 16;
478 eeprom->page_size = 8;
479 eeprom->address_bits = 8;
482 eeprom->type = e1000_eeprom_microwire;
483 eeprom->opcode_bits = 3;
484 eeprom->delay_usec = 50;
485 if (eecd & E1000_EECD_ADDR_BITS) {
486 eeprom->word_size = 256;
487 eeprom->address_bits = 8;
489 eeprom->word_size = 64;
490 eeprom->address_bits = 6;
493 eeprom->use_eerd = false;
494 eeprom->use_eewr = false;
498 eeprom->type = e1000_eeprom_spi;
499 eeprom->opcode_bits = 8;
500 eeprom->delay_usec = 1;
501 if (eecd & E1000_EECD_ADDR_BITS) {
502 eeprom->page_size = 32;
503 eeprom->address_bits = 16;
505 eeprom->page_size = 8;
506 eeprom->address_bits = 8;
508 eeprom->use_eerd = false;
509 eeprom->use_eewr = false;
513 eeprom->type = e1000_eeprom_spi;
514 eeprom->opcode_bits = 8;
515 eeprom->delay_usec = 1;
516 if (eecd & E1000_EECD_ADDR_BITS) {
517 eeprom->page_size = 32;
518 eeprom->address_bits = 16;
520 eeprom->page_size = 8;
521 eeprom->address_bits = 8;
523 if (e1000_is_onboard_nvm_eeprom(hw) == false) {
524 eeprom->use_eerd = true;
525 eeprom->use_eewr = true;
527 eeprom->type = e1000_eeprom_flash;
528 eeprom->word_size = 2048;
530 /* Ensure that the Autonomous FLASH update bit is cleared due to
531 * Flash update issue on parts which use a FLASH for NVM. */
532 eecd &= ~E1000_EECD_AUPDEN;
533 E1000_WRITE_REG(hw, EECD, eecd);
536 case e1000_80003es2lan:
537 eeprom->type = e1000_eeprom_spi;
538 eeprom->opcode_bits = 8;
539 eeprom->delay_usec = 1;
540 if (eecd & E1000_EECD_ADDR_BITS) {
541 eeprom->page_size = 32;
542 eeprom->address_bits = 16;
544 eeprom->page_size = 8;
545 eeprom->address_bits = 8;
547 eeprom->use_eerd = true;
548 eeprom->use_eewr = false;
551 /* i210 has 4k of iNVM mapped as EEPROM */
552 eeprom->type = e1000_eeprom_invm;
553 eeprom->opcode_bits = 8;
554 eeprom->delay_usec = 1;
555 eeprom->page_size = 32;
556 eeprom->address_bits = 16;
557 eeprom->use_eerd = true;
558 eeprom->use_eewr = false;
564 if (eeprom->type == e1000_eeprom_spi ||
565 eeprom->type == e1000_eeprom_invm) {
566 /* eeprom_size will be an enum [0..8] that maps
567 * to eeprom sizes 128B to
568 * 32KB (incremented by powers of 2).
570 if (hw->mac_type <= e1000_82547_rev_2) {
571 /* Set to default value for initial eeprom read. */
572 eeprom->word_size = 64;
573 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1,
577 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK)
578 >> EEPROM_SIZE_SHIFT;
579 /* 256B eeprom size was not supported in earlier
580 * hardware, so we bump eeprom_size up one to
581 * ensure that "1" (which maps to 256B) is never
582 * the result used in the shifting logic below. */
586 eeprom_size = (uint16_t)((eecd &
587 E1000_EECD_SIZE_EX_MASK) >>
588 E1000_EECD_SIZE_EX_SHIFT);
591 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
596 /******************************************************************************
597 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
599 * hw - Struct containing variables accessed by shared code
600 *****************************************************************************/
602 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
604 uint32_t attempts = 100000;
606 int32_t done = E1000_ERR_EEPROM;
608 for (i = 0; i < attempts; i++) {
609 if (eerd == E1000_EEPROM_POLL_READ) {
610 if (hw->mac_type == e1000_igb)
611 reg = E1000_READ_REG(hw, I210_EERD);
613 reg = E1000_READ_REG(hw, EERD);
615 if (hw->mac_type == e1000_igb)
616 reg = E1000_READ_REG(hw, I210_EEWR);
618 reg = E1000_READ_REG(hw, EEWR);
621 if (reg & E1000_EEPROM_RW_REG_DONE) {
622 done = E1000_SUCCESS;
631 /******************************************************************************
632 * Reads a 16 bit word from the EEPROM using the EERD register.
634 * hw - Struct containing variables accessed by shared code
635 * offset - offset of word in the EEPROM to read
636 * data - word read from the EEPROM
637 * words - number of words to read
638 *****************************************************************************/
640 e1000_read_eeprom_eerd(struct e1000_hw *hw,
645 uint32_t i, eerd = 0;
648 for (i = 0; i < words; i++) {
649 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
650 E1000_EEPROM_RW_REG_START;
652 if (hw->mac_type == e1000_igb)
653 E1000_WRITE_REG(hw, I210_EERD, eerd);
655 E1000_WRITE_REG(hw, EERD, eerd);
657 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
662 if (hw->mac_type == e1000_igb) {
663 data[i] = (E1000_READ_REG(hw, I210_EERD) >>
664 E1000_EEPROM_RW_REG_DATA);
666 data[i] = (E1000_READ_REG(hw, EERD) >>
667 E1000_EEPROM_RW_REG_DATA);
675 void e1000_release_eeprom(struct e1000_hw *hw)
681 eecd = E1000_READ_REG(hw, EECD);
683 if (hw->eeprom.type == e1000_eeprom_spi) {
684 eecd |= E1000_EECD_CS; /* Pull CS high */
685 eecd &= ~E1000_EECD_SK; /* Lower SCK */
687 E1000_WRITE_REG(hw, EECD, eecd);
689 udelay(hw->eeprom.delay_usec);
690 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
693 /* CS on Microwire is active-high */
694 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
696 E1000_WRITE_REG(hw, EECD, eecd);
698 /* Rising edge of clock */
699 eecd |= E1000_EECD_SK;
700 E1000_WRITE_REG(hw, EECD, eecd);
701 E1000_WRITE_FLUSH(hw);
702 udelay(hw->eeprom.delay_usec);
704 /* Falling edge of clock */
705 eecd &= ~E1000_EECD_SK;
706 E1000_WRITE_REG(hw, EECD, eecd);
707 E1000_WRITE_FLUSH(hw);
708 udelay(hw->eeprom.delay_usec);
711 /* Stop requesting EEPROM access */
712 if (hw->mac_type > e1000_82544) {
713 eecd &= ~E1000_EECD_REQ;
714 E1000_WRITE_REG(hw, EECD, eecd);
717 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
720 /******************************************************************************
721 * Reads a 16 bit word from the EEPROM.
723 * hw - Struct containing variables accessed by shared code
724 *****************************************************************************/
726 e1000_spi_eeprom_ready(struct e1000_hw *hw)
728 uint16_t retry_count = 0;
729 uint8_t spi_stat_reg;
733 /* Read "Status Register" repeatedly until the LSB is cleared. The
734 * EEPROM will signal that the command has been completed by clearing
735 * bit 0 of the internal status register. If it's not cleared within
736 * 5 milliseconds, then error out.
740 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
741 hw->eeprom.opcode_bits);
742 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
743 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
749 e1000_standby_eeprom(hw);
750 } while (retry_count < EEPROM_MAX_RETRY_SPI);
752 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
753 * only 0-5mSec on 5V devices)
755 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
756 DEBUGOUT("SPI EEPROM Status error\n");
757 return -E1000_ERR_EEPROM;
760 return E1000_SUCCESS;
763 /******************************************************************************
764 * Reads a 16 bit word from the EEPROM.
766 * hw - Struct containing variables accessed by shared code
767 * offset - offset of word in the EEPROM to read
768 * data - word read from the EEPROM
769 *****************************************************************************/
771 e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
772 uint16_t words, uint16_t *data)
774 struct e1000_eeprom_info *eeprom = &hw->eeprom;
779 /* If eeprom is not yet detected, do so now */
780 if (eeprom->word_size == 0)
781 e1000_init_eeprom_params(hw);
783 /* A check for invalid values: offset too large, too many words,
784 * and not enough words.
786 if ((offset >= eeprom->word_size) ||
787 (words > eeprom->word_size - offset) ||
789 DEBUGOUT("\"words\" parameter out of bounds."
790 "Words = %d, size = %d\n", offset, eeprom->word_size);
791 return -E1000_ERR_EEPROM;
794 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
795 * directly. In this case, we need to acquire the EEPROM so that
796 * FW or other port software does not interrupt.
798 if (e1000_is_onboard_nvm_eeprom(hw) == true &&
799 hw->eeprom.use_eerd == false) {
801 /* Prepare the EEPROM for bit-bang reading */
802 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
803 return -E1000_ERR_EEPROM;
806 /* Eerd register EEPROM access requires no eeprom aquire/release */
807 if (eeprom->use_eerd == true)
808 return e1000_read_eeprom_eerd(hw, offset, words, data);
810 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
811 * acquired the EEPROM at this point, so any returns should relase it */
812 if (eeprom->type == e1000_eeprom_spi) {
814 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
816 if (e1000_spi_eeprom_ready(hw)) {
817 e1000_release_eeprom(hw);
818 return -E1000_ERR_EEPROM;
821 e1000_standby_eeprom(hw);
823 /* Some SPI eeproms use the 8th address bit embedded in
825 if ((eeprom->address_bits == 8) && (offset >= 128))
826 read_opcode |= EEPROM_A8_OPCODE_SPI;
828 /* Send the READ command (opcode + addr) */
829 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
830 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2),
831 eeprom->address_bits);
833 /* Read the data. The address of the eeprom internally
834 * increments with each byte (spi) being read, saving on the
835 * overhead of eeprom setup and tear-down. The address
836 * counter will roll over if reading beyond the size of
837 * the eeprom, thus allowing the entire memory to be read
838 * starting from any offset. */
839 for (i = 0; i < words; i++) {
840 word_in = e1000_shift_in_ee_bits(hw, 16);
841 data[i] = (word_in >> 8) | (word_in << 8);
843 } else if (eeprom->type == e1000_eeprom_microwire) {
844 for (i = 0; i < words; i++) {
845 /* Send the READ command (opcode + addr) */
846 e1000_shift_out_ee_bits(hw,
847 EEPROM_READ_OPCODE_MICROWIRE,
848 eeprom->opcode_bits);
849 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
850 eeprom->address_bits);
852 /* Read the data. For microwire, each word requires
853 * the overhead of eeprom setup and tear-down. */
854 data[i] = e1000_shift_in_ee_bits(hw, 16);
855 e1000_standby_eeprom(hw);
859 /* End this read operation */
860 e1000_release_eeprom(hw);
862 return E1000_SUCCESS;
865 #ifndef CONFIG_DM_ETH
866 /******************************************************************************
867 * e1000_write_eeprom_srwr - Write to Shadow Ram using EEWR
868 * @hw: pointer to the HW structure
869 * @offset: offset within the Shadow Ram to be written to
870 * @words: number of words to write
871 * @data: 16 bit word(s) to be written to the Shadow Ram
873 * Writes data to Shadow Ram at offset using EEWR register.
875 * If e1000_update_eeprom_checksum_i210 is not called after this function, the
876 * Shadow Ram will most likely contain an invalid checksum.
877 *****************************************************************************/
878 static int32_t e1000_write_eeprom_srwr(struct e1000_hw *hw, uint16_t offset,
879 uint16_t words, uint16_t *data)
881 struct e1000_eeprom_info *eeprom = &hw->eeprom;
882 uint32_t i, k, eewr = 0;
883 uint32_t attempts = 100000;
886 /* A check for invalid values: offset too large, too many words,
887 * too many words for the offset, and not enough words.
889 if ((offset >= eeprom->word_size) ||
890 (words > (eeprom->word_size - offset)) || (words == 0)) {
891 DEBUGOUT("nvm parameter(s) out of bounds\n");
892 ret_val = -E1000_ERR_EEPROM;
896 for (i = 0; i < words; i++) {
897 eewr = ((offset + i) << E1000_EEPROM_RW_ADDR_SHIFT)
898 | (data[i] << E1000_EEPROM_RW_REG_DATA) |
899 E1000_EEPROM_RW_REG_START;
901 E1000_WRITE_REG(hw, I210_EEWR, eewr);
903 for (k = 0; k < attempts; k++) {
904 if (E1000_EEPROM_RW_REG_DONE &
905 E1000_READ_REG(hw, I210_EEWR)) {
913 DEBUGOUT("Shadow RAM write EEWR timed out\n");
922 /******************************************************************************
923 * e1000_pool_flash_update_done_i210 - Pool FLUDONE status.
924 * @hw: pointer to the HW structure
926 *****************************************************************************/
927 static int32_t e1000_pool_flash_update_done_i210(struct e1000_hw *hw)
929 int32_t ret_val = -E1000_ERR_EEPROM;
932 for (i = 0; i < E1000_FLUDONE_ATTEMPTS; i++) {
933 reg = E1000_READ_REG(hw, EECD);
934 if (reg & E1000_EECD_FLUDONE_I210) {
944 /******************************************************************************
945 * e1000_update_flash_i210 - Commit EEPROM to the flash
946 * @hw: pointer to the HW structure
948 *****************************************************************************/
949 static int32_t e1000_update_flash_i210(struct e1000_hw *hw)
954 ret_val = e1000_pool_flash_update_done_i210(hw);
955 if (ret_val == -E1000_ERR_EEPROM) {
956 DEBUGOUT("Flash update time out\n");
960 flup = E1000_READ_REG(hw, EECD) | E1000_EECD_FLUPD_I210;
961 E1000_WRITE_REG(hw, EECD, flup);
963 ret_val = e1000_pool_flash_update_done_i210(hw);
965 DEBUGOUT("Flash update time out\n");
967 DEBUGOUT("Flash update complete\n");
973 /******************************************************************************
974 * e1000_update_eeprom_checksum_i210 - Update EEPROM checksum
975 * @hw: pointer to the HW structure
977 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
978 * up to the checksum. Then calculates the EEPROM checksum and writes the
979 * value to the EEPROM. Next commit EEPROM data onto the Flash.
980 *****************************************************************************/
981 static int32_t e1000_update_eeprom_checksum_i210(struct e1000_hw *hw)
984 uint16_t checksum = 0;
985 uint16_t i, nvm_data;
987 /* Read the first word from the EEPROM. If this times out or fails, do
988 * not continue or we could be in for a very long wait while every
991 ret_val = e1000_read_eeprom_eerd(hw, 0, 1, &nvm_data);
993 DEBUGOUT("EEPROM read failed\n");
997 if (!(e1000_get_hw_eeprom_semaphore(hw))) {
998 /* Do not use hw->nvm.ops.write, hw->nvm.ops.read
999 * because we do not want to take the synchronization
1000 * semaphores twice here.
1003 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
1004 ret_val = e1000_read_eeprom_eerd(hw, i, 1, &nvm_data);
1006 e1000_put_hw_eeprom_semaphore(hw);
1007 DEBUGOUT("EEPROM Read Error while updating checksum.\n");
1010 checksum += nvm_data;
1012 checksum = (uint16_t)EEPROM_SUM - checksum;
1013 ret_val = e1000_write_eeprom_srwr(hw, EEPROM_CHECKSUM_REG, 1,
1016 e1000_put_hw_eeprom_semaphore(hw);
1017 DEBUGOUT("EEPROM Write Error while updating checksum.\n");
1021 e1000_put_hw_eeprom_semaphore(hw);
1023 ret_val = e1000_update_flash_i210(hw);
1025 ret_val = -E1000_ERR_SWFW_SYNC;
1033 /******************************************************************************
1034 * Verifies that the EEPROM has a valid checksum
1036 * hw - Struct containing variables accessed by shared code
1038 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
1039 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
1041 *****************************************************************************/
1042 static int e1000_validate_eeprom_checksum(struct e1000_hw *hw)
1044 uint16_t i, checksum, checksum_reg, *buf;
1048 /* Allocate a temporary buffer */
1049 buf = malloc(sizeof(buf[0]) * (EEPROM_CHECKSUM_REG + 1));
1051 E1000_ERR(hw, "Unable to allocate EEPROM buffer!\n");
1052 return -E1000_ERR_EEPROM;
1055 /* Read the EEPROM */
1056 if (e1000_read_eeprom(hw, 0, EEPROM_CHECKSUM_REG + 1, buf) < 0) {
1057 E1000_ERR(hw, "Unable to read EEPROM!\n");
1058 return -E1000_ERR_EEPROM;
1061 /* Compute the checksum */
1063 for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
1065 checksum = ((uint16_t)EEPROM_SUM) - checksum;
1066 checksum_reg = buf[i];
1069 if (checksum == checksum_reg)
1072 /* Hrm, verification failed, print an error */
1073 E1000_ERR(hw, "EEPROM checksum is incorrect!\n");
1074 E1000_ERR(hw, " ...register was 0x%04hx, calculated 0x%04hx\n",
1075 checksum_reg, checksum);
1077 return -E1000_ERR_EEPROM;
1079 #endif /* CONFIG_E1000_NO_NVM */
1081 /*****************************************************************************
1082 * Set PHY to class A mode
1083 * Assumes the following operations will follow to enable the new class mode.
1084 * 1. Do a PHY soft reset
1085 * 2. Restart auto-negotiation or force link.
1087 * hw - Struct containing variables accessed by shared code
1088 ****************************************************************************/
1090 e1000_set_phy_mode(struct e1000_hw *hw)
1092 #ifndef CONFIG_E1000_NO_NVM
1094 uint16_t eeprom_data;
1098 if ((hw->mac_type == e1000_82545_rev_3) &&
1099 (hw->media_type == e1000_media_type_copper)) {
1100 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD,
1105 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
1106 (eeprom_data & EEPROM_PHY_CLASS_A)) {
1107 ret_val = e1000_write_phy_reg(hw,
1108 M88E1000_PHY_PAGE_SELECT, 0x000B);
1111 ret_val = e1000_write_phy_reg(hw,
1112 M88E1000_PHY_GEN_CONTROL, 0x8104);
1116 hw->phy_reset_disable = false;
1120 return E1000_SUCCESS;
1123 #ifndef CONFIG_E1000_NO_NVM
1124 /***************************************************************************
1126 * Obtaining software semaphore bit (SMBI) before resetting PHY.
1128 * hw: Struct containing variables accessed by shared code
1130 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
1131 * E1000_SUCCESS at any other case.
1133 ***************************************************************************/
1135 e1000_get_software_semaphore(struct e1000_hw *hw)
1137 int32_t timeout = hw->eeprom.word_size + 1;
1142 if (hw->mac_type != e1000_80003es2lan && hw->mac_type != e1000_igb)
1143 return E1000_SUCCESS;
1146 swsm = E1000_READ_REG(hw, SWSM);
1147 /* If SMBI bit cleared, it is now set and we hold
1149 if (!(swsm & E1000_SWSM_SMBI))
1156 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
1157 return -E1000_ERR_RESET;
1160 return E1000_SUCCESS;
1164 /***************************************************************************
1165 * This function clears HW semaphore bits.
1167 * hw: Struct containing variables accessed by shared code
1171 ***************************************************************************/
1173 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
1175 #ifndef CONFIG_E1000_NO_NVM
1180 if (!hw->eeprom_semaphore_present)
1183 swsm = E1000_READ_REG(hw, SWSM);
1184 if (hw->mac_type == e1000_80003es2lan) {
1185 /* Release both semaphores. */
1186 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1188 swsm &= ~(E1000_SWSM_SWESMBI);
1189 E1000_WRITE_REG(hw, SWSM, swsm);
1193 /***************************************************************************
1195 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
1196 * adapter or Eeprom access.
1198 * hw: Struct containing variables accessed by shared code
1200 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
1201 * E1000_SUCCESS at any other case.
1203 ***************************************************************************/
1205 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
1207 #ifndef CONFIG_E1000_NO_NVM
1213 if (!hw->eeprom_semaphore_present)
1214 return E1000_SUCCESS;
1216 if (hw->mac_type == e1000_80003es2lan || hw->mac_type == e1000_igb) {
1217 /* Get the SW semaphore. */
1218 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
1219 return -E1000_ERR_EEPROM;
1222 /* Get the FW semaphore. */
1223 timeout = hw->eeprom.word_size + 1;
1225 swsm = E1000_READ_REG(hw, SWSM);
1226 swsm |= E1000_SWSM_SWESMBI;
1227 E1000_WRITE_REG(hw, SWSM, swsm);
1228 /* if we managed to set the bit we got the semaphore. */
1229 swsm = E1000_READ_REG(hw, SWSM);
1230 if (swsm & E1000_SWSM_SWESMBI)
1238 /* Release semaphores */
1239 e1000_put_hw_eeprom_semaphore(hw);
1240 DEBUGOUT("Driver can't access the Eeprom - "
1241 "SWESMBI bit is set.\n");
1242 return -E1000_ERR_EEPROM;
1245 return E1000_SUCCESS;
1248 /* Take ownership of the PHY */
1250 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
1252 uint32_t swfw_sync = 0;
1253 uint32_t swmask = mask;
1254 uint32_t fwmask = mask << 16;
1255 int32_t timeout = 200;
1259 if (e1000_get_hw_eeprom_semaphore(hw))
1260 return -E1000_ERR_SWFW_SYNC;
1262 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
1263 if (!(swfw_sync & (fwmask | swmask)))
1266 /* firmware currently using resource (fwmask) */
1267 /* or other software thread currently using resource (swmask) */
1268 e1000_put_hw_eeprom_semaphore(hw);
1274 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
1275 return -E1000_ERR_SWFW_SYNC;
1278 swfw_sync |= swmask;
1279 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
1281 e1000_put_hw_eeprom_semaphore(hw);
1282 return E1000_SUCCESS;
1285 static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
1287 uint32_t swfw_sync = 0;
1290 while (e1000_get_hw_eeprom_semaphore(hw))
1293 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
1295 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
1297 e1000_put_hw_eeprom_semaphore(hw);
1300 static bool e1000_is_second_port(struct e1000_hw *hw)
1302 switch (hw->mac_type) {
1303 case e1000_80003es2lan:
1306 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
1314 #ifndef CONFIG_E1000_NO_NVM
1315 /******************************************************************************
1316 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
1317 * second function of dual function devices
1319 * nic - Struct containing variables accessed by shared code
1320 *****************************************************************************/
1322 e1000_read_mac_addr(struct e1000_hw *hw, unsigned char enetaddr[6])
1325 uint16_t eeprom_data;
1326 uint32_t reg_data = 0;
1331 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
1333 if (hw->mac_type == e1000_igb) {
1334 /* i210 preloads MAC address into RAL/RAH registers */
1336 reg_data = E1000_READ_REG_ARRAY(hw, RA, 0);
1337 else if (offset == 1)
1339 else if (offset == 2)
1340 reg_data = E1000_READ_REG_ARRAY(hw, RA, 1);
1341 eeprom_data = reg_data & 0xffff;
1342 } else if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
1343 DEBUGOUT("EEPROM Read Error\n");
1344 return -E1000_ERR_EEPROM;
1346 enetaddr[i] = eeprom_data & 0xff;
1347 enetaddr[i + 1] = (eeprom_data >> 8) & 0xff;
1350 /* Invert the last bit if this is the second device */
1351 if (e1000_is_second_port(hw))
1358 /******************************************************************************
1359 * Initializes receive address filters.
1361 * hw - Struct containing variables accessed by shared code
1363 * Places the MAC address in receive address register 0 and clears the rest
1364 * of the receive addresss registers. Clears the multicast table. Assumes
1365 * the receiver is in reset when the routine is called.
1366 *****************************************************************************/
1368 e1000_init_rx_addrs(struct e1000_hw *hw, unsigned char enetaddr[6])
1376 /* Setup the receive address. */
1377 DEBUGOUT("Programming MAC Address into RAR[0]\n");
1378 addr_low = (enetaddr[0] |
1379 (enetaddr[1] << 8) |
1380 (enetaddr[2] << 16) | (enetaddr[3] << 24));
1382 addr_high = (enetaddr[4] | (enetaddr[5] << 8) | E1000_RAH_AV);
1384 E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
1385 E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
1387 /* Zero out the other 15 receive addresses. */
1388 DEBUGOUT("Clearing RAR[1-15]\n");
1389 for (i = 1; i < E1000_RAR_ENTRIES; i++) {
1390 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
1391 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
1395 /******************************************************************************
1396 * Clears the VLAN filer table
1398 * hw - Struct containing variables accessed by shared code
1399 *****************************************************************************/
1401 e1000_clear_vfta(struct e1000_hw *hw)
1405 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
1406 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
1409 /******************************************************************************
1410 * Set the mac type member in the hw struct.
1412 * hw - Struct containing variables accessed by shared code
1413 *****************************************************************************/
1415 e1000_set_mac_type(struct e1000_hw *hw)
1419 switch (hw->device_id) {
1420 case E1000_DEV_ID_82542:
1421 switch (hw->revision_id) {
1422 case E1000_82542_2_0_REV_ID:
1423 hw->mac_type = e1000_82542_rev2_0;
1425 case E1000_82542_2_1_REV_ID:
1426 hw->mac_type = e1000_82542_rev2_1;
1429 /* Invalid 82542 revision ID */
1430 return -E1000_ERR_MAC_TYPE;
1433 case E1000_DEV_ID_82543GC_FIBER:
1434 case E1000_DEV_ID_82543GC_COPPER:
1435 hw->mac_type = e1000_82543;
1437 case E1000_DEV_ID_82544EI_COPPER:
1438 case E1000_DEV_ID_82544EI_FIBER:
1439 case E1000_DEV_ID_82544GC_COPPER:
1440 case E1000_DEV_ID_82544GC_LOM:
1441 hw->mac_type = e1000_82544;
1443 case E1000_DEV_ID_82540EM:
1444 case E1000_DEV_ID_82540EM_LOM:
1445 case E1000_DEV_ID_82540EP:
1446 case E1000_DEV_ID_82540EP_LOM:
1447 case E1000_DEV_ID_82540EP_LP:
1448 hw->mac_type = e1000_82540;
1450 case E1000_DEV_ID_82545EM_COPPER:
1451 case E1000_DEV_ID_82545EM_FIBER:
1452 hw->mac_type = e1000_82545;
1454 case E1000_DEV_ID_82545GM_COPPER:
1455 case E1000_DEV_ID_82545GM_FIBER:
1456 case E1000_DEV_ID_82545GM_SERDES:
1457 hw->mac_type = e1000_82545_rev_3;
1459 case E1000_DEV_ID_82546EB_COPPER:
1460 case E1000_DEV_ID_82546EB_FIBER:
1461 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1462 hw->mac_type = e1000_82546;
1464 case E1000_DEV_ID_82546GB_COPPER:
1465 case E1000_DEV_ID_82546GB_FIBER:
1466 case E1000_DEV_ID_82546GB_SERDES:
1467 case E1000_DEV_ID_82546GB_PCIE:
1468 case E1000_DEV_ID_82546GB_QUAD_COPPER:
1469 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1470 hw->mac_type = e1000_82546_rev_3;
1472 case E1000_DEV_ID_82541EI:
1473 case E1000_DEV_ID_82541EI_MOBILE:
1474 case E1000_DEV_ID_82541ER_LOM:
1475 hw->mac_type = e1000_82541;
1477 case E1000_DEV_ID_82541ER:
1478 case E1000_DEV_ID_82541GI:
1479 case E1000_DEV_ID_82541GI_LF:
1480 case E1000_DEV_ID_82541GI_MOBILE:
1481 hw->mac_type = e1000_82541_rev_2;
1483 case E1000_DEV_ID_82547EI:
1484 case E1000_DEV_ID_82547EI_MOBILE:
1485 hw->mac_type = e1000_82547;
1487 case E1000_DEV_ID_82547GI:
1488 hw->mac_type = e1000_82547_rev_2;
1490 case E1000_DEV_ID_82571EB_COPPER:
1491 case E1000_DEV_ID_82571EB_FIBER:
1492 case E1000_DEV_ID_82571EB_SERDES:
1493 case E1000_DEV_ID_82571EB_SERDES_DUAL:
1494 case E1000_DEV_ID_82571EB_SERDES_QUAD:
1495 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1496 case E1000_DEV_ID_82571PT_QUAD_COPPER:
1497 case E1000_DEV_ID_82571EB_QUAD_FIBER:
1498 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1499 hw->mac_type = e1000_82571;
1501 case E1000_DEV_ID_82572EI_COPPER:
1502 case E1000_DEV_ID_82572EI_FIBER:
1503 case E1000_DEV_ID_82572EI_SERDES:
1504 case E1000_DEV_ID_82572EI:
1505 hw->mac_type = e1000_82572;
1507 case E1000_DEV_ID_82573E:
1508 case E1000_DEV_ID_82573E_IAMT:
1509 case E1000_DEV_ID_82573L:
1510 hw->mac_type = e1000_82573;
1512 case E1000_DEV_ID_82574L:
1513 hw->mac_type = e1000_82574;
1515 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
1516 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
1517 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
1518 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
1519 hw->mac_type = e1000_80003es2lan;
1521 case E1000_DEV_ID_ICH8_IGP_M_AMT:
1522 case E1000_DEV_ID_ICH8_IGP_AMT:
1523 case E1000_DEV_ID_ICH8_IGP_C:
1524 case E1000_DEV_ID_ICH8_IFE:
1525 case E1000_DEV_ID_ICH8_IFE_GT:
1526 case E1000_DEV_ID_ICH8_IFE_G:
1527 case E1000_DEV_ID_ICH8_IGP_M:
1528 hw->mac_type = e1000_ich8lan;
1530 case PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED:
1531 case PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED:
1532 case PCI_DEVICE_ID_INTEL_I210_COPPER:
1533 case PCI_DEVICE_ID_INTEL_I211_COPPER:
1534 case PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS:
1535 case PCI_DEVICE_ID_INTEL_I210_SERDES:
1536 case PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS:
1537 case PCI_DEVICE_ID_INTEL_I210_1000BASEKX:
1538 hw->mac_type = e1000_igb;
1541 /* Should never have loaded on this device */
1542 return -E1000_ERR_MAC_TYPE;
1544 return E1000_SUCCESS;
1547 /******************************************************************************
1548 * Reset the transmit and receive units; mask and clear all interrupts.
1550 * hw - Struct containing variables accessed by shared code
1551 *****************************************************************************/
1553 e1000_reset_hw(struct e1000_hw *hw)
1563 /* get the correct pba value for both PCI and PCIe*/
1564 if (hw->mac_type < e1000_82571)
1565 pba = E1000_DEFAULT_PCI_PBA;
1567 pba = E1000_DEFAULT_PCIE_PBA;
1569 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
1570 if (hw->mac_type == e1000_82542_rev2_0) {
1571 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1572 #ifdef CONFIG_DM_ETH
1573 dm_pci_write_config16(hw->pdev, PCI_COMMAND,
1574 hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1576 pci_write_config_word(hw->pdev, PCI_COMMAND,
1577 hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1581 /* Clear interrupt mask to stop board from generating interrupts */
1582 DEBUGOUT("Masking off all interrupts\n");
1583 if (hw->mac_type == e1000_igb)
1584 E1000_WRITE_REG(hw, I210_IAM, 0);
1585 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1587 /* Disable the Transmit and Receive units. Then delay to allow
1588 * any pending transactions to complete before we hit the MAC with
1591 E1000_WRITE_REG(hw, RCTL, 0);
1592 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
1593 E1000_WRITE_FLUSH(hw);
1595 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
1596 hw->tbi_compatibility_on = false;
1598 /* Delay to allow any outstanding PCI transactions to complete before
1599 * resetting the device
1603 /* Issue a global reset to the MAC. This will reset the chip's
1604 * transmit, receive, DMA, and link units. It will not effect
1605 * the current PCI configuration. The global reset bit is self-
1606 * clearing, and should clear within a microsecond.
1608 DEBUGOUT("Issuing a global reset to MAC\n");
1609 ctrl = E1000_READ_REG(hw, CTRL);
1611 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
1613 /* Force a reload from the EEPROM if necessary */
1614 if (hw->mac_type == e1000_igb) {
1616 reg = E1000_READ_REG(hw, STATUS);
1617 if (reg & E1000_STATUS_PF_RST_DONE)
1618 DEBUGOUT("PF OK\n");
1619 reg = E1000_READ_REG(hw, I210_EECD);
1620 if (reg & E1000_EECD_AUTO_RD)
1621 DEBUGOUT("EEC OK\n");
1622 } else if (hw->mac_type < e1000_82540) {
1623 /* Wait for reset to complete */
1625 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1626 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1627 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1628 E1000_WRITE_FLUSH(hw);
1629 /* Wait for EEPROM reload */
1632 /* Wait for EEPROM reload (it happens automatically) */
1634 /* Dissable HW ARPs on ASF enabled adapters */
1635 manc = E1000_READ_REG(hw, MANC);
1636 manc &= ~(E1000_MANC_ARP_EN);
1637 E1000_WRITE_REG(hw, MANC, manc);
1640 /* Clear interrupt mask to stop board from generating interrupts */
1641 DEBUGOUT("Masking off all interrupts\n");
1642 if (hw->mac_type == e1000_igb)
1643 E1000_WRITE_REG(hw, I210_IAM, 0);
1644 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1646 /* Clear any pending interrupt events. */
1647 E1000_READ_REG(hw, ICR);
1649 /* If MWI was previously enabled, reenable it. */
1650 if (hw->mac_type == e1000_82542_rev2_0) {
1651 #ifdef CONFIG_DM_ETH
1652 dm_pci_write_config16(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1654 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1657 if (hw->mac_type != e1000_igb)
1658 E1000_WRITE_REG(hw, PBA, pba);
1661 /******************************************************************************
1663 * Initialize a number of hardware-dependent bits
1665 * hw: Struct containing variables accessed by shared code
1667 * This function contains hardware limitation workarounds for PCI-E adapters
1669 *****************************************************************************/
1671 e1000_initialize_hardware_bits(struct e1000_hw *hw)
1673 if ((hw->mac_type >= e1000_82571) &&
1674 (!hw->initialize_hw_bits_disable)) {
1675 /* Settings common to all PCI-express silicon */
1676 uint32_t reg_ctrl, reg_ctrl_ext;
1677 uint32_t reg_tarc0, reg_tarc1;
1679 uint32_t reg_txdctl, reg_txdctl1;
1681 /* link autonegotiation/sync workarounds */
1682 reg_tarc0 = E1000_READ_REG(hw, TARC0);
1683 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
1685 /* Enable not-done TX descriptor counting */
1686 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
1687 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
1688 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
1690 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
1691 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
1692 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
1695 switch (hw->mac_type) {
1696 case e1000_igb: /* IGB is cool */
1700 /* Clear PHY TX compatible mode bits */
1701 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1702 reg_tarc1 &= ~((1 << 30)|(1 << 29));
1704 /* link autonegotiation/sync workarounds */
1705 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
1707 /* TX ring control fixes */
1708 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
1710 /* Multiple read bit is reversed polarity */
1711 reg_tctl = E1000_READ_REG(hw, TCTL);
1712 if (reg_tctl & E1000_TCTL_MULR)
1713 reg_tarc1 &= ~(1 << 28);
1715 reg_tarc1 |= (1 << 28);
1717 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1721 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1722 reg_ctrl_ext &= ~(1 << 23);
1723 reg_ctrl_ext |= (1 << 22);
1725 /* TX byte count fix */
1726 reg_ctrl = E1000_READ_REG(hw, CTRL);
1727 reg_ctrl &= ~(1 << 29);
1729 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1730 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
1732 case e1000_80003es2lan:
1733 /* improve small packet performace for fiber/serdes */
1734 if ((hw->media_type == e1000_media_type_fiber)
1735 || (hw->media_type ==
1736 e1000_media_type_internal_serdes)) {
1737 reg_tarc0 &= ~(1 << 20);
1740 /* Multiple read bit is reversed polarity */
1741 reg_tctl = E1000_READ_REG(hw, TCTL);
1742 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1743 if (reg_tctl & E1000_TCTL_MULR)
1744 reg_tarc1 &= ~(1 << 28);
1746 reg_tarc1 |= (1 << 28);
1748 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1751 /* Reduce concurrent DMA requests to 3 from 4 */
1752 if ((hw->revision_id < 3) ||
1753 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1754 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
1755 reg_tarc0 |= ((1 << 29)|(1 << 28));
1757 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1758 reg_ctrl_ext |= (1 << 22);
1759 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1761 /* workaround TX hang with TSO=on */
1762 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
1764 /* Multiple read bit is reversed polarity */
1765 reg_tctl = E1000_READ_REG(hw, TCTL);
1766 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1767 if (reg_tctl & E1000_TCTL_MULR)
1768 reg_tarc1 &= ~(1 << 28);
1770 reg_tarc1 |= (1 << 28);
1772 /* workaround TX hang with TSO=on */
1773 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
1775 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1781 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
1785 /******************************************************************************
1786 * Performs basic configuration of the adapter.
1788 * hw - Struct containing variables accessed by shared code
1790 * Assumes that the controller has previously been reset and is in a
1791 * post-reset uninitialized state. Initializes the receive address registers,
1792 * multicast table, and VLAN filter table. Calls routines to setup link
1793 * configuration and flow control settings. Clears all on-chip counters. Leaves
1794 * the transmit and receive units disabled and uninitialized.
1795 *****************************************************************************/
1797 e1000_init_hw(struct e1000_hw *hw, unsigned char enetaddr[6])
1802 uint16_t pcix_cmd_word;
1803 uint16_t pcix_stat_hi_word;
1805 uint16_t stat_mmrbc;
1810 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
1811 if ((hw->mac_type == e1000_ich8lan) &&
1812 ((hw->revision_id < 3) ||
1813 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1814 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
1815 reg_data = E1000_READ_REG(hw, STATUS);
1816 reg_data &= ~0x80000000;
1817 E1000_WRITE_REG(hw, STATUS, reg_data);
1819 /* Do not need initialize Identification LED */
1821 /* Set the media type and TBI compatibility */
1822 e1000_set_media_type(hw);
1824 /* Must be called after e1000_set_media_type
1825 * because media_type is used */
1826 e1000_initialize_hardware_bits(hw);
1828 /* Disabling VLAN filtering. */
1829 DEBUGOUT("Initializing the IEEE VLAN\n");
1830 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
1831 if (hw->mac_type != e1000_ich8lan) {
1832 if (hw->mac_type < e1000_82545_rev_3)
1833 E1000_WRITE_REG(hw, VET, 0);
1834 e1000_clear_vfta(hw);
1837 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
1838 if (hw->mac_type == e1000_82542_rev2_0) {
1839 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1840 #ifdef CONFIG_DM_ETH
1841 dm_pci_write_config16(hw->pdev, PCI_COMMAND,
1843 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1845 pci_write_config_word(hw->pdev, PCI_COMMAND,
1847 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1849 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
1850 E1000_WRITE_FLUSH(hw);
1854 /* Setup the receive address. This involves initializing all of the Receive
1855 * Address Registers (RARs 0 - 15).
1857 e1000_init_rx_addrs(hw, enetaddr);
1859 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
1860 if (hw->mac_type == e1000_82542_rev2_0) {
1861 E1000_WRITE_REG(hw, RCTL, 0);
1862 E1000_WRITE_FLUSH(hw);
1864 #ifdef CONFIG_DM_ETH
1865 dm_pci_write_config16(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1867 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1871 /* Zero out the Multicast HASH table */
1872 DEBUGOUT("Zeroing the MTA\n");
1873 mta_size = E1000_MC_TBL_SIZE;
1874 if (hw->mac_type == e1000_ich8lan)
1875 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
1876 for (i = 0; i < mta_size; i++) {
1877 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
1878 /* use write flush to prevent Memory Write Block (MWB) from
1879 * occuring when accessing our register space */
1880 E1000_WRITE_FLUSH(hw);
1883 switch (hw->mac_type) {
1884 case e1000_82545_rev_3:
1885 case e1000_82546_rev_3:
1889 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
1890 if (hw->bus_type == e1000_bus_type_pcix) {
1891 #ifdef CONFIG_DM_ETH
1892 dm_pci_read_config16(hw->pdev, PCIX_COMMAND_REGISTER,
1894 dm_pci_read_config16(hw->pdev, PCIX_STATUS_REGISTER_HI,
1895 &pcix_stat_hi_word);
1897 pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
1899 pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI,
1900 &pcix_stat_hi_word);
1903 (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
1904 PCIX_COMMAND_MMRBC_SHIFT;
1906 (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
1907 PCIX_STATUS_HI_MMRBC_SHIFT;
1908 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
1909 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
1910 if (cmd_mmrbc > stat_mmrbc) {
1911 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
1912 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
1913 #ifdef CONFIG_DM_ETH
1914 dm_pci_write_config16(hw->pdev, PCIX_COMMAND_REGISTER,
1917 pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
1925 /* More time needed for PHY to initialize */
1926 if (hw->mac_type == e1000_ich8lan)
1928 if (hw->mac_type == e1000_igb)
1931 /* Call a subroutine to configure the link and setup flow control. */
1932 ret_val = e1000_setup_link(hw);
1934 /* Set the transmit descriptor write-back policy */
1935 if (hw->mac_type > e1000_82544) {
1936 ctrl = E1000_READ_REG(hw, TXDCTL);
1938 (ctrl & ~E1000_TXDCTL_WTHRESH) |
1939 E1000_TXDCTL_FULL_TX_DESC_WB;
1940 E1000_WRITE_REG(hw, TXDCTL, ctrl);
1943 /* Set the receive descriptor write back policy */
1944 if (hw->mac_type >= e1000_82571) {
1945 ctrl = E1000_READ_REG(hw, RXDCTL);
1947 (ctrl & ~E1000_RXDCTL_WTHRESH) |
1948 E1000_RXDCTL_FULL_RX_DESC_WB;
1949 E1000_WRITE_REG(hw, RXDCTL, ctrl);
1952 switch (hw->mac_type) {
1955 case e1000_80003es2lan:
1956 /* Enable retransmit on late collisions */
1957 reg_data = E1000_READ_REG(hw, TCTL);
1958 reg_data |= E1000_TCTL_RTLC;
1959 E1000_WRITE_REG(hw, TCTL, reg_data);
1961 /* Configure Gigabit Carry Extend Padding */
1962 reg_data = E1000_READ_REG(hw, TCTL_EXT);
1963 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
1964 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
1965 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1967 /* Configure Transmit Inter-Packet Gap */
1968 reg_data = E1000_READ_REG(hw, TIPG);
1969 reg_data &= ~E1000_TIPG_IPGT_MASK;
1970 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1971 E1000_WRITE_REG(hw, TIPG, reg_data);
1973 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1974 reg_data &= ~0x00100000;
1975 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1980 ctrl = E1000_READ_REG(hw, TXDCTL1);
1981 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH)
1982 | E1000_TXDCTL_FULL_TX_DESC_WB;
1983 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1987 reg_data = E1000_READ_REG(hw, GCR);
1988 reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1989 E1000_WRITE_REG(hw, GCR, reg_data);
1994 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1995 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1996 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1997 /* Relaxed ordering must be disabled to avoid a parity
1998 * error crash in a PCI slot. */
1999 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
2000 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2006 /******************************************************************************
2007 * Configures flow control and link settings.
2009 * hw - Struct containing variables accessed by shared code
2011 * Determines which flow control settings to use. Calls the apropriate media-
2012 * specific link configuration function. Configures the flow control settings.
2013 * Assuming the adapter has a valid link partner, a valid link should be
2014 * established. Assumes the hardware has previously been reset and the
2015 * transmitter and receiver are not enabled.
2016 *****************************************************************************/
2018 e1000_setup_link(struct e1000_hw *hw)
2021 #ifndef CONFIG_E1000_NO_NVM
2023 uint16_t eeprom_data;
2028 /* In the case of the phy reset being blocked, we already have a link.
2029 * We do not have to set it up again. */
2030 if (e1000_check_phy_reset_block(hw))
2031 return E1000_SUCCESS;
2033 #ifndef CONFIG_E1000_NO_NVM
2034 /* Read and store word 0x0F of the EEPROM. This word contains bits
2035 * that determine the hardware's default PAUSE (flow control) mode,
2036 * a bit that determines whether the HW defaults to enabling or
2037 * disabling auto-negotiation, and the direction of the
2038 * SW defined pins. If there is no SW over-ride of the flow
2039 * control setting, then the variable hw->fc will
2040 * be initialized based on a value in the EEPROM.
2042 if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1,
2043 &eeprom_data) < 0) {
2044 DEBUGOUT("EEPROM Read Error\n");
2045 return -E1000_ERR_EEPROM;
2048 if (hw->fc == e1000_fc_default) {
2049 switch (hw->mac_type) {
2054 hw->fc = e1000_fc_full;
2057 #ifndef CONFIG_E1000_NO_NVM
2058 ret_val = e1000_read_eeprom(hw,
2059 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
2061 DEBUGOUT("EEPROM Read Error\n");
2062 return -E1000_ERR_EEPROM;
2064 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
2065 hw->fc = e1000_fc_none;
2066 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
2067 EEPROM_WORD0F_ASM_DIR)
2068 hw->fc = e1000_fc_tx_pause;
2071 hw->fc = e1000_fc_full;
2076 /* We want to save off the original Flow Control configuration just
2077 * in case we get disconnected and then reconnected into a different
2078 * hub or switch with different Flow Control capabilities.
2080 if (hw->mac_type == e1000_82542_rev2_0)
2081 hw->fc &= (~e1000_fc_tx_pause);
2083 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
2084 hw->fc &= (~e1000_fc_rx_pause);
2086 hw->original_fc = hw->fc;
2088 DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc);
2090 #ifndef CONFIG_E1000_NO_NVM
2091 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
2092 * polarity value for the SW controlled pins, and setup the
2093 * Extended Device Control reg with that info.
2094 * This is needed because one of the SW controlled pins is used for
2095 * signal detection. So this should be done before e1000_setup_pcs_link()
2096 * or e1000_phy_setup() is called.
2098 if (hw->mac_type == e1000_82543) {
2099 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
2101 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2105 /* Call the necessary subroutine to configure the link. */
2106 ret_val = (hw->media_type == e1000_media_type_fiber) ?
2107 e1000_setup_fiber_link(hw) : e1000_setup_copper_link(hw);
2112 /* Initialize the flow control address, type, and PAUSE timer
2113 * registers to their default values. This is done even if flow
2114 * control is disabled, because it does not hurt anything to
2115 * initialize these registers.
2117 DEBUGOUT("Initializing the Flow Control address, type"
2118 "and timer regs\n");
2120 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
2121 if (hw->mac_type != e1000_ich8lan) {
2122 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
2123 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
2124 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
2127 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
2129 /* Set the flow control receive threshold registers. Normally,
2130 * these registers will be set to a default threshold that may be
2131 * adjusted later by the driver's runtime code. However, if the
2132 * ability to transmit pause frames in not enabled, then these
2133 * registers will be set to 0.
2135 if (!(hw->fc & e1000_fc_tx_pause)) {
2136 E1000_WRITE_REG(hw, FCRTL, 0);
2137 E1000_WRITE_REG(hw, FCRTH, 0);
2139 /* We need to set up the Receive Threshold high and low water marks
2140 * as well as (optionally) enabling the transmission of XON frames.
2142 if (hw->fc_send_xon) {
2143 E1000_WRITE_REG(hw, FCRTL,
2144 (hw->fc_low_water | E1000_FCRTL_XONE));
2145 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
2147 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
2148 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
2154 /******************************************************************************
2155 * Sets up link for a fiber based adapter
2157 * hw - Struct containing variables accessed by shared code
2159 * Manipulates Physical Coding Sublayer functions in order to configure
2160 * link. Assumes the hardware has been previously reset and the transmitter
2161 * and receiver are not enabled.
2162 *****************************************************************************/
2164 e1000_setup_fiber_link(struct e1000_hw *hw)
2174 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
2175 * set when the optics detect a signal. On older adapters, it will be
2176 * cleared when there is a signal
2178 ctrl = E1000_READ_REG(hw, CTRL);
2179 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
2180 signal = E1000_CTRL_SWDPIN1;
2184 printf("signal for %s is %x (ctrl %08x)!!!!\n", hw->name, signal,
2186 /* Take the link out of reset */
2187 ctrl &= ~(E1000_CTRL_LRST);
2189 e1000_config_collision_dist(hw);
2191 /* Check for a software override of the flow control settings, and setup
2192 * the device accordingly. If auto-negotiation is enabled, then software
2193 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
2194 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
2195 * auto-negotiation is disabled, then software will have to manually
2196 * configure the two flow control enable bits in the CTRL register.
2198 * The possible values of the "fc" parameter are:
2199 * 0: Flow control is completely disabled
2200 * 1: Rx flow control is enabled (we can receive pause frames, but
2201 * not send pause frames).
2202 * 2: Tx flow control is enabled (we can send pause frames but we do
2203 * not support receiving pause frames).
2204 * 3: Both Rx and TX flow control (symmetric) are enabled.
2208 /* Flow control is completely disabled by a software over-ride. */
2209 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
2211 case e1000_fc_rx_pause:
2212 /* RX Flow control is enabled and TX Flow control is disabled by a
2213 * software over-ride. Since there really isn't a way to advertise
2214 * that we are capable of RX Pause ONLY, we will advertise that we
2215 * support both symmetric and asymmetric RX PAUSE. Later, we will
2216 * disable the adapter's ability to send PAUSE frames.
2218 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
2220 case e1000_fc_tx_pause:
2221 /* TX Flow control is enabled, and RX Flow control is disabled, by a
2222 * software over-ride.
2224 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
2227 /* Flow control (both RX and TX) is enabled by a software over-ride. */
2228 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
2231 DEBUGOUT("Flow control param set incorrectly\n");
2232 return -E1000_ERR_CONFIG;
2236 /* Since auto-negotiation is enabled, take the link out of reset (the link
2237 * will be in reset, because we previously reset the chip). This will
2238 * restart auto-negotiation. If auto-neogtiation is successful then the
2239 * link-up status bit will be set and the flow control enable bits (RFCE
2240 * and TFCE) will be set according to their negotiated value.
2242 DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw);
2244 E1000_WRITE_REG(hw, TXCW, txcw);
2245 E1000_WRITE_REG(hw, CTRL, ctrl);
2246 E1000_WRITE_FLUSH(hw);
2251 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
2252 * indication in the Device Status Register. Time-out if a link isn't
2253 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
2254 * less than 500 milliseconds even if the other end is doing it in SW).
2256 if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
2257 DEBUGOUT("Looking for Link\n");
2258 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
2260 status = E1000_READ_REG(hw, STATUS);
2261 if (status & E1000_STATUS_LU)
2264 if (i == (LINK_UP_TIMEOUT / 10)) {
2265 /* AutoNeg failed to achieve a link, so we'll call
2266 * e1000_check_for_link. This routine will force the link up if we
2267 * detect a signal. This will allow us to communicate with
2268 * non-autonegotiating link partners.
2270 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
2271 hw->autoneg_failed = 1;
2272 ret_val = e1000_check_for_link(hw);
2274 DEBUGOUT("Error while checking for link\n");
2277 hw->autoneg_failed = 0;
2279 hw->autoneg_failed = 0;
2280 DEBUGOUT("Valid Link Found\n");
2283 DEBUGOUT("No Signal Detected\n");
2284 return -E1000_ERR_NOLINK;
2289 /******************************************************************************
2290 * Make sure we have a valid PHY and change PHY mode before link setup.
2292 * hw - Struct containing variables accessed by shared code
2293 ******************************************************************************/
2295 e1000_copper_link_preconfig(struct e1000_hw *hw)
2303 ctrl = E1000_READ_REG(hw, CTRL);
2304 /* With 82543, we need to force speed and duplex on the MAC equal to what
2305 * the PHY speed and duplex configuration is. In addition, we need to
2306 * perform a hardware reset on the PHY to take it out of reset.
2308 if (hw->mac_type > e1000_82543) {
2309 ctrl |= E1000_CTRL_SLU;
2310 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2311 E1000_WRITE_REG(hw, CTRL, ctrl);
2313 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX
2315 E1000_WRITE_REG(hw, CTRL, ctrl);
2316 ret_val = e1000_phy_hw_reset(hw);
2321 /* Make sure we have a valid PHY */
2322 ret_val = e1000_detect_gig_phy(hw);
2324 DEBUGOUT("Error, did not detect valid phy.\n");
2327 DEBUGOUT("Phy ID = %x\n", hw->phy_id);
2329 /* Set PHY to class A mode (if necessary) */
2330 ret_val = e1000_set_phy_mode(hw);
2333 if ((hw->mac_type == e1000_82545_rev_3) ||
2334 (hw->mac_type == e1000_82546_rev_3)) {
2335 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2337 phy_data |= 0x00000008;
2338 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2342 if (hw->mac_type <= e1000_82543 ||
2343 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
2344 hw->mac_type == e1000_82541_rev_2
2345 || hw->mac_type == e1000_82547_rev_2)
2346 hw->phy_reset_disable = false;
2348 return E1000_SUCCESS;
2351 /*****************************************************************************
2353 * This function sets the lplu state according to the active flag. When
2354 * activating lplu this function also disables smart speed and vise versa.
2355 * lplu will not be activated unless the device autonegotiation advertisment
2356 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2357 * hw: Struct containing variables accessed by shared code
2358 * active - true to enable lplu false to disable lplu.
2360 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2361 * E1000_SUCCESS at any other case.
2363 ****************************************************************************/
2366 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
2368 uint32_t phy_ctrl = 0;
2373 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
2374 && hw->phy_type != e1000_phy_igp_3)
2375 return E1000_SUCCESS;
2377 /* During driver activity LPLU should not be used or it will attain link
2378 * from the lowest speeds starting from 10Mbps. The capability is used
2379 * for Dx transitions and states */
2380 if (hw->mac_type == e1000_82541_rev_2
2381 || hw->mac_type == e1000_82547_rev_2) {
2382 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
2386 } else if (hw->mac_type == e1000_ich8lan) {
2387 /* MAC writes into PHY register based on the state transition
2388 * and start auto-negotiation. SW driver can overwrite the
2389 * settings in CSR PHY power control E1000_PHY_CTRL register. */
2390 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
2392 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2399 if (hw->mac_type == e1000_82541_rev_2 ||
2400 hw->mac_type == e1000_82547_rev_2) {
2401 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
2402 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
2407 if (hw->mac_type == e1000_ich8lan) {
2408 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2409 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2411 phy_data &= ~IGP02E1000_PM_D3_LPLU;
2412 ret_val = e1000_write_phy_reg(hw,
2413 IGP02E1000_PHY_POWER_MGMT, phy_data);
2419 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2420 * Dx states where the power conservation is most important. During
2421 * driver activity we should enable SmartSpeed, so performance is
2423 if (hw->smart_speed == e1000_smart_speed_on) {
2424 ret_val = e1000_read_phy_reg(hw,
2425 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2429 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2430 ret_val = e1000_write_phy_reg(hw,
2431 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2434 } else if (hw->smart_speed == e1000_smart_speed_off) {
2435 ret_val = e1000_read_phy_reg(hw,
2436 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2440 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2441 ret_val = e1000_write_phy_reg(hw,
2442 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2447 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
2448 || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) ||
2449 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
2451 if (hw->mac_type == e1000_82541_rev_2 ||
2452 hw->mac_type == e1000_82547_rev_2) {
2453 phy_data |= IGP01E1000_GMII_FLEX_SPD;
2454 ret_val = e1000_write_phy_reg(hw,
2455 IGP01E1000_GMII_FIFO, phy_data);
2459 if (hw->mac_type == e1000_ich8lan) {
2460 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2461 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2463 phy_data |= IGP02E1000_PM_D3_LPLU;
2464 ret_val = e1000_write_phy_reg(hw,
2465 IGP02E1000_PHY_POWER_MGMT, phy_data);
2471 /* When LPLU is enabled we should disable SmartSpeed */
2472 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2477 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2478 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2483 return E1000_SUCCESS;
2486 /*****************************************************************************
2488 * This function sets the lplu d0 state according to the active flag. When
2489 * activating lplu this function also disables smart speed and vise versa.
2490 * lplu will not be activated unless the device autonegotiation advertisment
2491 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2492 * hw: Struct containing variables accessed by shared code
2493 * active - true to enable lplu false to disable lplu.
2495 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2496 * E1000_SUCCESS at any other case.
2498 ****************************************************************************/
2501 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
2503 uint32_t phy_ctrl = 0;
2508 if (hw->mac_type <= e1000_82547_rev_2)
2509 return E1000_SUCCESS;
2511 if (hw->mac_type == e1000_ich8lan) {
2512 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
2513 } else if (hw->mac_type == e1000_igb) {
2514 phy_ctrl = E1000_READ_REG(hw, I210_PHY_CTRL);
2516 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2523 if (hw->mac_type == e1000_ich8lan) {
2524 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2525 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2526 } else if (hw->mac_type == e1000_igb) {
2527 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2528 E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
2530 phy_data &= ~IGP02E1000_PM_D0_LPLU;
2531 ret_val = e1000_write_phy_reg(hw,
2532 IGP02E1000_PHY_POWER_MGMT, phy_data);
2537 if (hw->mac_type == e1000_igb)
2538 return E1000_SUCCESS;
2540 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2541 * Dx states where the power conservation is most important. During
2542 * driver activity we should enable SmartSpeed, so performance is
2544 if (hw->smart_speed == e1000_smart_speed_on) {
2545 ret_val = e1000_read_phy_reg(hw,
2546 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2550 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2551 ret_val = e1000_write_phy_reg(hw,
2552 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2555 } else if (hw->smart_speed == e1000_smart_speed_off) {
2556 ret_val = e1000_read_phy_reg(hw,
2557 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2561 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2562 ret_val = e1000_write_phy_reg(hw,
2563 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2571 if (hw->mac_type == e1000_ich8lan) {
2572 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2573 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2574 } else if (hw->mac_type == e1000_igb) {
2575 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2576 E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
2578 phy_data |= IGP02E1000_PM_D0_LPLU;
2579 ret_val = e1000_write_phy_reg(hw,
2580 IGP02E1000_PHY_POWER_MGMT, phy_data);
2585 if (hw->mac_type == e1000_igb)
2586 return E1000_SUCCESS;
2588 /* When LPLU is enabled we should disable SmartSpeed */
2589 ret_val = e1000_read_phy_reg(hw,
2590 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2594 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2595 ret_val = e1000_write_phy_reg(hw,
2596 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2601 return E1000_SUCCESS;
2604 /********************************************************************
2605 * Copper link setup for e1000_phy_igp series.
2607 * hw - Struct containing variables accessed by shared code
2608 *********************************************************************/
2610 e1000_copper_link_igp_setup(struct e1000_hw *hw)
2618 if (hw->phy_reset_disable)
2619 return E1000_SUCCESS;
2621 ret_val = e1000_phy_reset(hw);
2623 DEBUGOUT("Error Resetting the PHY\n");
2627 /* Wait 15ms for MAC to configure PHY from eeprom settings */
2629 if (hw->mac_type != e1000_ich8lan) {
2630 /* Configure activity LED after PHY reset */
2631 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2632 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2633 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2634 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2637 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
2638 if (hw->phy_type == e1000_phy_igp) {
2639 /* disable lplu d3 during driver init */
2640 ret_val = e1000_set_d3_lplu_state(hw, false);
2642 DEBUGOUT("Error Disabling LPLU D3\n");
2647 /* disable lplu d0 during driver init */
2648 ret_val = e1000_set_d0_lplu_state(hw, false);
2650 DEBUGOUT("Error Disabling LPLU D0\n");
2653 /* Configure mdi-mdix settings */
2654 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2658 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2659 hw->dsp_config_state = e1000_dsp_config_disabled;
2660 /* Force MDI for earlier revs of the IGP PHY */
2661 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX
2662 | IGP01E1000_PSCR_FORCE_MDI_MDIX);
2666 hw->dsp_config_state = e1000_dsp_config_enabled;
2667 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2671 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2674 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
2678 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
2682 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2686 /* set auto-master slave resolution settings */
2688 e1000_ms_type phy_ms_setting = hw->master_slave;
2690 if (hw->ffe_config_state == e1000_ffe_config_active)
2691 hw->ffe_config_state = e1000_ffe_config_enabled;
2693 if (hw->dsp_config_state == e1000_dsp_config_activated)
2694 hw->dsp_config_state = e1000_dsp_config_enabled;
2696 /* when autonegotiation advertisment is only 1000Mbps then we
2697 * should disable SmartSpeed and enable Auto MasterSlave
2698 * resolution as hardware default. */
2699 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
2700 /* Disable SmartSpeed */
2701 ret_val = e1000_read_phy_reg(hw,
2702 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2705 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2706 ret_val = e1000_write_phy_reg(hw,
2707 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2710 /* Set auto Master/Slave resolution process */
2711 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
2715 phy_data &= ~CR_1000T_MS_ENABLE;
2716 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
2722 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
2726 /* load defaults for future use */
2727 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
2728 ((phy_data & CR_1000T_MS_VALUE) ?
2729 e1000_ms_force_master :
2730 e1000_ms_force_slave) :
2733 switch (phy_ms_setting) {
2734 case e1000_ms_force_master:
2735 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
2737 case e1000_ms_force_slave:
2738 phy_data |= CR_1000T_MS_ENABLE;
2739 phy_data &= ~(CR_1000T_MS_VALUE);
2742 phy_data &= ~CR_1000T_MS_ENABLE;
2746 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
2751 return E1000_SUCCESS;
2754 /*****************************************************************************
2755 * This function checks the mode of the firmware.
2757 * returns - true when the mode is IAMT or false.
2758 ****************************************************************************/
2760 e1000_check_mng_mode(struct e1000_hw *hw)
2765 fwsm = E1000_READ_REG(hw, FWSM);
2767 if (hw->mac_type == e1000_ich8lan) {
2768 if ((fwsm & E1000_FWSM_MODE_MASK) ==
2769 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
2771 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
2772 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
2779 e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data)
2781 uint16_t swfw = E1000_SWFW_PHY0_SM;
2785 if (e1000_is_second_port(hw))
2786 swfw = E1000_SWFW_PHY1_SM;
2788 if (e1000_swfw_sync_acquire(hw, swfw))
2789 return -E1000_ERR_SWFW_SYNC;
2791 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT)
2792 & E1000_KUMCTRLSTA_OFFSET) | data;
2793 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2796 return E1000_SUCCESS;
2800 e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data)
2802 uint16_t swfw = E1000_SWFW_PHY0_SM;
2806 if (e1000_is_second_port(hw))
2807 swfw = E1000_SWFW_PHY1_SM;
2809 if (e1000_swfw_sync_acquire(hw, swfw)) {
2810 debug("%s[%i]\n", __func__, __LINE__);
2811 return -E1000_ERR_SWFW_SYNC;
2814 /* Write register address */
2815 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
2816 E1000_KUMCTRLSTA_OFFSET) | E1000_KUMCTRLSTA_REN;
2817 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2820 /* Read the data returned */
2821 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
2822 *data = (uint16_t)reg_val;
2824 return E1000_SUCCESS;
2827 /********************************************************************
2828 * Copper link setup for e1000_phy_gg82563 series.
2830 * hw - Struct containing variables accessed by shared code
2831 *********************************************************************/
2833 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
2841 if (!hw->phy_reset_disable) {
2842 /* Enable CRS on TX for half-duplex operation. */
2843 ret_val = e1000_read_phy_reg(hw,
2844 GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2848 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2849 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
2850 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
2852 ret_val = e1000_write_phy_reg(hw,
2853 GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2858 * MDI/MDI-X = 0 (default)
2859 * 0 - Auto for all speeds
2862 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
2864 ret_val = e1000_read_phy_reg(hw,
2865 GG82563_PHY_SPEC_CTRL, &phy_data);
2869 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
2873 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
2876 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
2880 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
2885 * disable_polarity_correction = 0 (default)
2886 * Automatic Correction for Reversed Cable Polarity
2890 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
2891 ret_val = e1000_write_phy_reg(hw,
2892 GG82563_PHY_SPEC_CTRL, phy_data);
2897 /* SW Reset the PHY so all changes take effect */
2898 ret_val = e1000_phy_reset(hw);
2900 DEBUGOUT("Error Resetting the PHY\n");
2903 } /* phy_reset_disable */
2905 if (hw->mac_type == e1000_80003es2lan) {
2906 /* Bypass RX and TX FIFO's */
2907 ret_val = e1000_write_kmrn_reg(hw,
2908 E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
2909 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS
2910 | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
2914 ret_val = e1000_read_phy_reg(hw,
2915 GG82563_PHY_SPEC_CTRL_2, &phy_data);
2919 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
2920 ret_val = e1000_write_phy_reg(hw,
2921 GG82563_PHY_SPEC_CTRL_2, phy_data);
2926 reg_data = E1000_READ_REG(hw, CTRL_EXT);
2927 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
2928 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
2930 ret_val = e1000_read_phy_reg(hw,
2931 GG82563_PHY_PWR_MGMT_CTRL, &phy_data);
2935 /* Do not init these registers when the HW is in IAMT mode, since the
2936 * firmware will have already initialized them. We only initialize
2937 * them if the HW is not in IAMT mode.
2939 if (e1000_check_mng_mode(hw) == false) {
2940 /* Enable Electrical Idle on the PHY */
2941 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
2942 ret_val = e1000_write_phy_reg(hw,
2943 GG82563_PHY_PWR_MGMT_CTRL, phy_data);
2947 ret_val = e1000_read_phy_reg(hw,
2948 GG82563_PHY_KMRN_MODE_CTRL, &phy_data);
2952 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2953 ret_val = e1000_write_phy_reg(hw,
2954 GG82563_PHY_KMRN_MODE_CTRL, phy_data);
2960 /* Workaround: Disable padding in Kumeran interface in the MAC
2961 * and in the PHY to avoid CRC errors.
2963 ret_val = e1000_read_phy_reg(hw,
2964 GG82563_PHY_INBAND_CTRL, &phy_data);
2967 phy_data |= GG82563_ICR_DIS_PADDING;
2968 ret_val = e1000_write_phy_reg(hw,
2969 GG82563_PHY_INBAND_CTRL, phy_data);
2973 return E1000_SUCCESS;
2976 /********************************************************************
2977 * Copper link setup for e1000_phy_m88 series.
2979 * hw - Struct containing variables accessed by shared code
2980 *********************************************************************/
2982 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
2989 if (hw->phy_reset_disable)
2990 return E1000_SUCCESS;
2992 /* Enable CRS on TX. This must be set for half-duplex operation. */
2993 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2997 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
3000 * MDI/MDI-X = 0 (default)
3001 * 0 - Auto for all speeds
3004 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
3006 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
3010 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
3013 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
3016 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
3020 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
3025 * disable_polarity_correction = 0 (default)
3026 * Automatic Correction for Reversed Cable Polarity
3030 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
3031 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
3035 if (hw->phy_revision < M88E1011_I_REV_4) {
3036 /* Force TX_CLK in the Extended PHY Specific Control Register
3039 ret_val = e1000_read_phy_reg(hw,
3040 M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
3044 phy_data |= M88E1000_EPSCR_TX_CLK_25;
3046 if ((hw->phy_revision == E1000_REVISION_2) &&
3047 (hw->phy_id == M88E1111_I_PHY_ID)) {
3048 /* Vidalia Phy, set the downshift counter to 5x */
3049 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
3050 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
3051 ret_val = e1000_write_phy_reg(hw,
3052 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
3056 /* Configure Master and Slave downshift values */
3057 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK
3058 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
3059 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X
3060 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
3061 ret_val = e1000_write_phy_reg(hw,
3062 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
3068 /* SW Reset the PHY so all changes take effect */
3069 ret_val = e1000_phy_reset(hw);
3071 DEBUGOUT("Error Resetting the PHY\n");
3075 return E1000_SUCCESS;
3078 /********************************************************************
3079 * Setup auto-negotiation and flow control advertisements,
3080 * and then perform auto-negotiation.
3082 * hw - Struct containing variables accessed by shared code
3083 *********************************************************************/
3085 e1000_copper_link_autoneg(struct e1000_hw *hw)
3092 /* Perform some bounds checking on the hw->autoneg_advertised
3093 * parameter. If this variable is zero, then set it to the default.
3095 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
3097 /* If autoneg_advertised is zero, we assume it was not defaulted
3098 * by the calling code so we set to advertise full capability.
3100 if (hw->autoneg_advertised == 0)
3101 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
3103 /* IFE phy only supports 10/100 */
3104 if (hw->phy_type == e1000_phy_ife)
3105 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
3107 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
3108 ret_val = e1000_phy_setup_autoneg(hw);
3110 DEBUGOUT("Error Setting up Auto-Negotiation\n");
3113 DEBUGOUT("Restarting Auto-Neg\n");
3115 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
3116 * the Auto Neg Restart bit in the PHY control register.
3118 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3122 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
3123 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3127 /* Does the user want to wait for Auto-Neg to complete here, or
3128 * check at a later time (for example, callback routine).
3130 /* If we do not wait for autonegtation to complete I
3131 * do not see a valid link status.
3132 * wait_autoneg_complete = 1 .
3134 if (hw->wait_autoneg_complete) {
3135 ret_val = e1000_wait_autoneg(hw);
3137 DEBUGOUT("Error while waiting for autoneg"
3143 hw->get_link_status = true;
3145 return E1000_SUCCESS;
3148 /******************************************************************************
3149 * Config the MAC and the PHY after link is up.
3150 * 1) Set up the MAC to the current PHY speed/duplex
3151 * if we are on 82543. If we
3152 * are on newer silicon, we only need to configure
3153 * collision distance in the Transmit Control Register.
3154 * 2) Set up flow control on the MAC to that established with
3156 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
3158 * hw - Struct containing variables accessed by shared code
3159 ******************************************************************************/
3161 e1000_copper_link_postconfig(struct e1000_hw *hw)
3166 if (hw->mac_type >= e1000_82544) {
3167 e1000_config_collision_dist(hw);
3169 ret_val = e1000_config_mac_to_phy(hw);
3171 DEBUGOUT("Error configuring MAC to PHY settings\n");
3175 ret_val = e1000_config_fc_after_link_up(hw);
3177 DEBUGOUT("Error Configuring Flow Control\n");
3180 return E1000_SUCCESS;
3183 /******************************************************************************
3184 * Detects which PHY is present and setup the speed and duplex
3186 * hw - Struct containing variables accessed by shared code
3187 ******************************************************************************/
3189 e1000_setup_copper_link(struct e1000_hw *hw)
3198 switch (hw->mac_type) {
3199 case e1000_80003es2lan:
3201 /* Set the mac to wait the maximum time between each
3202 * iteration and increase the max iterations when
3203 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
3204 ret_val = e1000_write_kmrn_reg(hw,
3205 GG82563_REG(0x34, 4), 0xFFFF);
3208 ret_val = e1000_read_kmrn_reg(hw,
3209 GG82563_REG(0x34, 9), ®_data);
3213 ret_val = e1000_write_kmrn_reg(hw,
3214 GG82563_REG(0x34, 9), reg_data);
3221 /* Check if it is a valid PHY and set PHY mode if necessary. */
3222 ret_val = e1000_copper_link_preconfig(hw);
3225 switch (hw->mac_type) {
3226 case e1000_80003es2lan:
3227 /* Kumeran registers are written-only */
3229 E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
3230 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
3231 ret_val = e1000_write_kmrn_reg(hw,
3232 E1000_KUMCTRLSTA_OFFSET_INB_CTRL, reg_data);
3240 if (hw->phy_type == e1000_phy_igp ||
3241 hw->phy_type == e1000_phy_igp_3 ||
3242 hw->phy_type == e1000_phy_igp_2) {
3243 ret_val = e1000_copper_link_igp_setup(hw);
3246 } else if (hw->phy_type == e1000_phy_m88 ||
3247 hw->phy_type == e1000_phy_igb) {
3248 ret_val = e1000_copper_link_mgp_setup(hw);
3251 } else if (hw->phy_type == e1000_phy_gg82563) {
3252 ret_val = e1000_copper_link_ggp_setup(hw);
3258 /* Setup autoneg and flow control advertisement
3259 * and perform autonegotiation */
3260 ret_val = e1000_copper_link_autoneg(hw);
3264 /* Check link status. Wait up to 100 microseconds for link to become
3267 for (i = 0; i < 10; i++) {
3268 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3271 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3275 if (phy_data & MII_SR_LINK_STATUS) {
3276 /* Config the MAC and PHY after link is up */
3277 ret_val = e1000_copper_link_postconfig(hw);
3281 DEBUGOUT("Valid link established!!!\n");
3282 return E1000_SUCCESS;
3287 DEBUGOUT("Unable to establish link!!!\n");
3288 return E1000_SUCCESS;
3291 /******************************************************************************
3292 * Configures PHY autoneg and flow control advertisement settings
3294 * hw - Struct containing variables accessed by shared code
3295 ******************************************************************************/
3297 e1000_phy_setup_autoneg(struct e1000_hw *hw)
3300 uint16_t mii_autoneg_adv_reg;
3301 uint16_t mii_1000t_ctrl_reg;
3305 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
3306 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
3310 if (hw->phy_type != e1000_phy_ife) {
3311 /* Read the MII 1000Base-T Control Register (Address 9). */
3312 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
3313 &mii_1000t_ctrl_reg);
3317 mii_1000t_ctrl_reg = 0;
3319 /* Need to parse both autoneg_advertised and fc and set up
3320 * the appropriate PHY registers. First we will parse for
3321 * autoneg_advertised software override. Since we can advertise
3322 * a plethora of combinations, we need to check each bit
3326 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
3327 * Advertisement Register (Address 4) and the 1000 mb speed bits in
3328 * the 1000Base-T Control Register (Address 9).
3330 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
3331 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
3333 DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised);
3335 /* Do we want to advertise 10 Mb Half Duplex? */
3336 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
3337 DEBUGOUT("Advertise 10mb Half duplex\n");
3338 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
3341 /* Do we want to advertise 10 Mb Full Duplex? */
3342 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
3343 DEBUGOUT("Advertise 10mb Full duplex\n");
3344 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
3347 /* Do we want to advertise 100 Mb Half Duplex? */
3348 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
3349 DEBUGOUT("Advertise 100mb Half duplex\n");
3350 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
3353 /* Do we want to advertise 100 Mb Full Duplex? */
3354 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
3355 DEBUGOUT("Advertise 100mb Full duplex\n");
3356 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
3359 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
3360 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
3362 ("Advertise 1000mb Half duplex requested, request denied!\n");
3365 /* Do we want to advertise 1000 Mb Full Duplex? */
3366 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
3367 DEBUGOUT("Advertise 1000mb Full duplex\n");
3368 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
3371 /* Check for a software override of the flow control settings, and
3372 * setup the PHY advertisement registers accordingly. If
3373 * auto-negotiation is enabled, then software will have to set the
3374 * "PAUSE" bits to the correct value in the Auto-Negotiation
3375 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
3377 * The possible values of the "fc" parameter are:
3378 * 0: Flow control is completely disabled
3379 * 1: Rx flow control is enabled (we can receive pause frames
3380 * but not send pause frames).
3381 * 2: Tx flow control is enabled (we can send pause frames
3382 * but we do not support receiving pause frames).
3383 * 3: Both Rx and TX flow control (symmetric) are enabled.
3384 * other: No software override. The flow control configuration
3385 * in the EEPROM is used.
3388 case e1000_fc_none: /* 0 */
3389 /* Flow control (RX & TX) is completely disabled by a
3390 * software over-ride.
3392 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3394 case e1000_fc_rx_pause: /* 1 */
3395 /* RX Flow control is enabled, and TX Flow control is
3396 * disabled, by a software over-ride.
3398 /* Since there really isn't a way to advertise that we are
3399 * capable of RX Pause ONLY, we will advertise that we
3400 * support both symmetric and asymmetric RX PAUSE. Later
3401 * (in e1000_config_fc_after_link_up) we will disable the
3402 *hw's ability to send PAUSE frames.
3404 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3406 case e1000_fc_tx_pause: /* 2 */
3407 /* TX Flow control is enabled, and RX Flow control is
3408 * disabled, by a software over-ride.
3410 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
3411 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
3413 case e1000_fc_full: /* 3 */
3414 /* Flow control (both RX and TX) is enabled by a software
3417 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3420 DEBUGOUT("Flow control param set incorrectly\n");
3421 return -E1000_ERR_CONFIG;
3424 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
3428 DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
3430 if (hw->phy_type != e1000_phy_ife) {
3431 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
3432 mii_1000t_ctrl_reg);
3437 return E1000_SUCCESS;
3440 /******************************************************************************
3441 * Sets the collision distance in the Transmit Control register
3443 * hw - Struct containing variables accessed by shared code
3445 * Link should have been established previously. Reads the speed and duplex
3446 * information from the Device Status register.
3447 ******************************************************************************/
3449 e1000_config_collision_dist(struct e1000_hw *hw)
3451 uint32_t tctl, coll_dist;
3455 if (hw->mac_type < e1000_82543)
3456 coll_dist = E1000_COLLISION_DISTANCE_82542;
3458 coll_dist = E1000_COLLISION_DISTANCE;
3460 tctl = E1000_READ_REG(hw, TCTL);
3462 tctl &= ~E1000_TCTL_COLD;
3463 tctl |= coll_dist << E1000_COLD_SHIFT;
3465 E1000_WRITE_REG(hw, TCTL, tctl);
3466 E1000_WRITE_FLUSH(hw);
3469 /******************************************************************************
3470 * Sets MAC speed and duplex settings to reflect the those in the PHY
3472 * hw - Struct containing variables accessed by shared code
3473 * mii_reg - data to write to the MII control register
3475 * The contents of the PHY register containing the needed information need to
3477 ******************************************************************************/
3479 e1000_config_mac_to_phy(struct e1000_hw *hw)
3486 /* Read the Device Control Register and set the bits to Force Speed
3489 ctrl = E1000_READ_REG(hw, CTRL);
3490 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3491 ctrl &= ~(E1000_CTRL_ILOS);
3492 ctrl |= (E1000_CTRL_SPD_SEL);
3494 /* Set up duplex in the Device Control and Transmit Control
3495 * registers depending on negotiated values.
3497 if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
3498 DEBUGOUT("PHY Read Error\n");
3499 return -E1000_ERR_PHY;
3501 if (phy_data & M88E1000_PSSR_DPLX)
3502 ctrl |= E1000_CTRL_FD;
3504 ctrl &= ~E1000_CTRL_FD;
3506 e1000_config_collision_dist(hw);
3508 /* Set up speed in the Device Control register depending on
3509 * negotiated values.
3511 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
3512 ctrl |= E1000_CTRL_SPD_1000;
3513 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
3514 ctrl |= E1000_CTRL_SPD_100;
3515 /* Write the configured values back to the Device Control Reg. */
3516 E1000_WRITE_REG(hw, CTRL, ctrl);
3520 /******************************************************************************
3521 * Forces the MAC's flow control settings.
3523 * hw - Struct containing variables accessed by shared code
3525 * Sets the TFCE and RFCE bits in the device control register to reflect
3526 * the adapter settings. TFCE and RFCE need to be explicitly set by
3527 * software when a Copper PHY is used because autonegotiation is managed
3528 * by the PHY rather than the MAC. Software must also configure these
3529 * bits when link is forced on a fiber connection.
3530 *****************************************************************************/
3532 e1000_force_mac_fc(struct e1000_hw *hw)
3538 /* Get the current configuration of the Device Control Register */
3539 ctrl = E1000_READ_REG(hw, CTRL);
3541 /* Because we didn't get link via the internal auto-negotiation
3542 * mechanism (we either forced link or we got link via PHY
3543 * auto-neg), we have to manually enable/disable transmit an
3544 * receive flow control.
3546 * The "Case" statement below enables/disable flow control
3547 * according to the "hw->fc" parameter.
3549 * The possible values of the "fc" parameter are:
3550 * 0: Flow control is completely disabled
3551 * 1: Rx flow control is enabled (we can receive pause
3552 * frames but not send pause frames).
3553 * 2: Tx flow control is enabled (we can send pause frames
3554 * frames but we do not receive pause frames).
3555 * 3: Both Rx and TX flow control (symmetric) is enabled.
3556 * other: No other values should be possible at this point.
3561 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
3563 case e1000_fc_rx_pause:
3564 ctrl &= (~E1000_CTRL_TFCE);
3565 ctrl |= E1000_CTRL_RFCE;
3567 case e1000_fc_tx_pause:
3568 ctrl &= (~E1000_CTRL_RFCE);
3569 ctrl |= E1000_CTRL_TFCE;
3572 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
3575 DEBUGOUT("Flow control param set incorrectly\n");
3576 return -E1000_ERR_CONFIG;
3579 /* Disable TX Flow Control for 82542 (rev 2.0) */
3580 if (hw->mac_type == e1000_82542_rev2_0)
3581 ctrl &= (~E1000_CTRL_TFCE);
3583 E1000_WRITE_REG(hw, CTRL, ctrl);
3587 /******************************************************************************
3588 * Configures flow control settings after link is established
3590 * hw - Struct containing variables accessed by shared code
3592 * Should be called immediately after a valid link has been established.
3593 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
3594 * and autonegotiation is enabled, the MAC flow control settings will be set
3595 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
3596 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
3597 *****************************************************************************/
3599 e1000_config_fc_after_link_up(struct e1000_hw *hw)
3602 uint16_t mii_status_reg;
3603 uint16_t mii_nway_adv_reg;
3604 uint16_t mii_nway_lp_ability_reg;
3610 /* Check for the case where we have fiber media and auto-neg failed
3611 * so we had to force link. In this case, we need to force the
3612 * configuration of the MAC to match the "fc" parameter.
3614 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
3615 || ((hw->media_type == e1000_media_type_internal_serdes)
3616 && (hw->autoneg_failed))
3617 || ((hw->media_type == e1000_media_type_copper)
3618 && (!hw->autoneg))) {
3619 ret_val = e1000_force_mac_fc(hw);
3621 DEBUGOUT("Error forcing flow control settings\n");
3626 /* Check for the case where we have copper media and auto-neg is
3627 * enabled. In this case, we need to check and see if Auto-Neg
3628 * has completed, and if so, how the PHY and link partner has
3629 * flow control configured.
3631 if (hw->media_type == e1000_media_type_copper) {
3632 /* Read the MII Status Register and check to see if AutoNeg
3633 * has completed. We read this twice because this reg has
3634 * some "sticky" (latched) bits.
3636 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3637 DEBUGOUT("PHY Read Error\n");
3638 return -E1000_ERR_PHY;
3640 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3641 DEBUGOUT("PHY Read Error\n");
3642 return -E1000_ERR_PHY;
3645 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
3646 /* The AutoNeg process has completed, so we now need to
3647 * read both the Auto Negotiation Advertisement Register
3648 * (Address 4) and the Auto_Negotiation Base Page Ability
3649 * Register (Address 5) to determine how flow control was
3652 if (e1000_read_phy_reg
3653 (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
3654 DEBUGOUT("PHY Read Error\n");
3655 return -E1000_ERR_PHY;
3657 if (e1000_read_phy_reg
3658 (hw, PHY_LP_ABILITY,
3659 &mii_nway_lp_ability_reg) < 0) {
3660 DEBUGOUT("PHY Read Error\n");
3661 return -E1000_ERR_PHY;
3664 /* Two bits in the Auto Negotiation Advertisement Register
3665 * (Address 4) and two bits in the Auto Negotiation Base
3666 * Page Ability Register (Address 5) determine flow control
3667 * for both the PHY and the link partner. The following
3668 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
3669 * 1999, describes these PAUSE resolution bits and how flow
3670 * control is determined based upon these settings.
3671 * NOTE: DC = Don't Care
3673 * LOCAL DEVICE | LINK PARTNER
3674 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
3675 *-------|---------|-------|---------|--------------------
3676 * 0 | 0 | DC | DC | e1000_fc_none
3677 * 0 | 1 | 0 | DC | e1000_fc_none
3678 * 0 | 1 | 1 | 0 | e1000_fc_none
3679 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
3680 * 1 | 0 | 0 | DC | e1000_fc_none
3681 * 1 | DC | 1 | DC | e1000_fc_full
3682 * 1 | 1 | 0 | 0 | e1000_fc_none
3683 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
3686 /* Are both PAUSE bits set to 1? If so, this implies
3687 * Symmetric Flow Control is enabled at both ends. The
3688 * ASM_DIR bits are irrelevant per the spec.
3690 * For Symmetric Flow Control:
3692 * LOCAL DEVICE | LINK PARTNER
3693 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3694 *-------|---------|-------|---------|--------------------
3695 * 1 | DC | 1 | DC | e1000_fc_full
3698 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3699 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
3700 /* Now we need to check if the user selected RX ONLY
3701 * of pause frames. In this case, we had to advertise
3702 * FULL flow control because we could not advertise RX
3703 * ONLY. Hence, we must now check to see if we need to
3704 * turn OFF the TRANSMISSION of PAUSE frames.
3706 if (hw->original_fc == e1000_fc_full) {
3707 hw->fc = e1000_fc_full;
3708 DEBUGOUT("Flow Control = FULL.\r\n");
3710 hw->fc = e1000_fc_rx_pause;
3712 ("Flow Control = RX PAUSE frames only.\r\n");
3715 /* For receiving PAUSE frames ONLY.
3717 * LOCAL DEVICE | LINK PARTNER
3718 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3719 *-------|---------|-------|---------|--------------------
3720 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
3723 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3724 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3725 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3726 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3728 hw->fc = e1000_fc_tx_pause;
3730 ("Flow Control = TX PAUSE frames only.\r\n");
3732 /* For transmitting PAUSE frames ONLY.
3734 * LOCAL DEVICE | LINK PARTNER
3735 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3736 *-------|---------|-------|---------|--------------------
3737 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
3740 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3741 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3742 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3743 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3745 hw->fc = e1000_fc_rx_pause;
3747 ("Flow Control = RX PAUSE frames only.\r\n");
3749 /* Per the IEEE spec, at this point flow control should be
3750 * disabled. However, we want to consider that we could
3751 * be connected to a legacy switch that doesn't advertise
3752 * desired flow control, but can be forced on the link
3753 * partner. So if we advertised no flow control, that is
3754 * what we will resolve to. If we advertised some kind of
3755 * receive capability (Rx Pause Only or Full Flow Control)
3756 * and the link partner advertised none, we will configure
3757 * ourselves to enable Rx Flow Control only. We can do
3758 * this safely for two reasons: If the link partner really
3759 * didn't want flow control enabled, and we enable Rx, no
3760 * harm done since we won't be receiving any PAUSE frames
3761 * anyway. If the intent on the link partner was to have
3762 * flow control enabled, then by us enabling RX only, we
3763 * can at least receive pause frames and process them.
3764 * This is a good idea because in most cases, since we are
3765 * predominantly a server NIC, more times than not we will
3766 * be asked to delay transmission of packets than asking
3767 * our link partner to pause transmission of frames.
3769 else if (hw->original_fc == e1000_fc_none ||
3770 hw->original_fc == e1000_fc_tx_pause) {
3771 hw->fc = e1000_fc_none;
3772 DEBUGOUT("Flow Control = NONE.\r\n");
3774 hw->fc = e1000_fc_rx_pause;
3776 ("Flow Control = RX PAUSE frames only.\r\n");
3779 /* Now we need to do one last check... If we auto-
3780 * negotiated to HALF DUPLEX, flow control should not be
3781 * enabled per IEEE 802.3 spec.
3783 e1000_get_speed_and_duplex(hw, &speed, &duplex);
3785 if (duplex == HALF_DUPLEX)
3786 hw->fc = e1000_fc_none;
3788 /* Now we call a subroutine to actually force the MAC
3789 * controller to use the correct flow control settings.
3791 ret_val = e1000_force_mac_fc(hw);
3794 ("Error forcing flow control settings\n");
3799 ("Copper PHY and Auto Neg has not completed.\r\n");
3802 return E1000_SUCCESS;
3805 /******************************************************************************
3806 * Checks to see if the link status of the hardware has changed.
3808 * hw - Struct containing variables accessed by shared code
3810 * Called by any function that needs to check the link status of the adapter.
3811 *****************************************************************************/
3813 e1000_check_for_link(struct e1000_hw *hw)
3822 uint16_t lp_capability;
3826 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
3827 * set when the optics detect a signal. On older adapters, it will be
3828 * cleared when there is a signal
3830 ctrl = E1000_READ_REG(hw, CTRL);
3831 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
3832 signal = E1000_CTRL_SWDPIN1;
3836 status = E1000_READ_REG(hw, STATUS);
3837 rxcw = E1000_READ_REG(hw, RXCW);
3838 DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw);
3840 /* If we have a copper PHY then we only want to go out to the PHY
3841 * registers to see if Auto-Neg has completed and/or if our link
3842 * status has changed. The get_link_status flag will be set if we
3843 * receive a Link Status Change interrupt or we have Rx Sequence
3846 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
3847 /* First we want to see if the MII Status Register reports
3848 * link. If so, then we want to get the current speed/duplex
3850 * Read the register twice since the link bit is sticky.
3852 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3853 DEBUGOUT("PHY Read Error\n");
3854 return -E1000_ERR_PHY;
3856 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3857 DEBUGOUT("PHY Read Error\n");
3858 return -E1000_ERR_PHY;
3861 if (phy_data & MII_SR_LINK_STATUS) {
3862 hw->get_link_status = false;
3864 /* No link detected */
3865 return -E1000_ERR_NOLINK;
3868 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
3869 * have Si on board that is 82544 or newer, Auto
3870 * Speed Detection takes care of MAC speed/duplex
3871 * configuration. So we only need to configure Collision
3872 * Distance in the MAC. Otherwise, we need to force
3873 * speed/duplex on the MAC to the current PHY speed/duplex
3876 if (hw->mac_type >= e1000_82544)
3877 e1000_config_collision_dist(hw);
3879 ret_val = e1000_config_mac_to_phy(hw);
3882 ("Error configuring MAC to PHY settings\n");
3887 /* Configure Flow Control now that Auto-Neg has completed. First, we
3888 * need to restore the desired flow control settings because we may
3889 * have had to re-autoneg with a different link partner.
3891 ret_val = e1000_config_fc_after_link_up(hw);
3893 DEBUGOUT("Error configuring flow control\n");
3897 /* At this point we know that we are on copper and we have
3898 * auto-negotiated link. These are conditions for checking the link
3899 * parter capability register. We use the link partner capability to
3900 * determine if TBI Compatibility needs to be turned on or off. If
3901 * the link partner advertises any speed in addition to Gigabit, then
3902 * we assume that they are GMII-based, and TBI compatibility is not
3903 * needed. If no other speeds are advertised, we assume the link
3904 * partner is TBI-based, and we turn on TBI Compatibility.
3906 if (hw->tbi_compatibility_en) {
3907 if (e1000_read_phy_reg
3908 (hw, PHY_LP_ABILITY, &lp_capability) < 0) {
3909 DEBUGOUT("PHY Read Error\n");
3910 return -E1000_ERR_PHY;
3912 if (lp_capability & (NWAY_LPAR_10T_HD_CAPS |
3913 NWAY_LPAR_10T_FD_CAPS |
3914 NWAY_LPAR_100TX_HD_CAPS |
3915 NWAY_LPAR_100TX_FD_CAPS |
3916 NWAY_LPAR_100T4_CAPS)) {
3917 /* If our link partner advertises anything in addition to
3918 * gigabit, we do not need to enable TBI compatibility.
3920 if (hw->tbi_compatibility_on) {
3921 /* If we previously were in the mode, turn it off. */
3922 rctl = E1000_READ_REG(hw, RCTL);
3923 rctl &= ~E1000_RCTL_SBP;
3924 E1000_WRITE_REG(hw, RCTL, rctl);
3925 hw->tbi_compatibility_on = false;
3928 /* If TBI compatibility is was previously off, turn it on. For
3929 * compatibility with a TBI link partner, we will store bad
3930 * packets. Some frames have an additional byte on the end and
3931 * will look like CRC errors to to the hardware.
3933 if (!hw->tbi_compatibility_on) {
3934 hw->tbi_compatibility_on = true;
3935 rctl = E1000_READ_REG(hw, RCTL);
3936 rctl |= E1000_RCTL_SBP;
3937 E1000_WRITE_REG(hw, RCTL, rctl);
3942 /* If we don't have link (auto-negotiation failed or link partner cannot
3943 * auto-negotiate), the cable is plugged in (we have signal), and our
3944 * link partner is not trying to auto-negotiate with us (we are receiving
3945 * idles or data), we need to force link up. We also need to give
3946 * auto-negotiation time to complete, in case the cable was just plugged
3947 * in. The autoneg_failed flag does this.
3949 else if ((hw->media_type == e1000_media_type_fiber) &&
3950 (!(status & E1000_STATUS_LU)) &&
3951 ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
3952 (!(rxcw & E1000_RXCW_C))) {
3953 if (hw->autoneg_failed == 0) {
3954 hw->autoneg_failed = 1;
3957 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
3959 /* Disable auto-negotiation in the TXCW register */
3960 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3962 /* Force link-up and also force full-duplex. */
3963 ctrl = E1000_READ_REG(hw, CTRL);
3964 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3965 E1000_WRITE_REG(hw, CTRL, ctrl);
3967 /* Configure Flow Control after forcing link up. */
3968 ret_val = e1000_config_fc_after_link_up(hw);
3970 DEBUGOUT("Error configuring flow control\n");
3974 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3975 * auto-negotiation in the TXCW register and disable forced link in the
3976 * Device Control register in an attempt to auto-negotiate with our link
3979 else if ((hw->media_type == e1000_media_type_fiber) &&
3980 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
3982 ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
3983 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3984 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3989 /******************************************************************************
3990 * Configure the MAC-to-PHY interface for 10/100Mbps
3992 * hw - Struct containing variables accessed by shared code
3993 ******************************************************************************/
3995 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
3997 int32_t ret_val = E1000_SUCCESS;
4003 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
4004 ret_val = e1000_write_kmrn_reg(hw,
4005 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
4009 /* Configure Transmit Inter-Packet Gap */
4010 tipg = E1000_READ_REG(hw, TIPG);
4011 tipg &= ~E1000_TIPG_IPGT_MASK;
4012 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
4013 E1000_WRITE_REG(hw, TIPG, tipg);
4015 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
4020 if (duplex == HALF_DUPLEX)
4021 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
4023 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
4025 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
4031 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
4033 int32_t ret_val = E1000_SUCCESS;
4039 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
4040 ret_val = e1000_write_kmrn_reg(hw,
4041 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
4045 /* Configure Transmit Inter-Packet Gap */
4046 tipg = E1000_READ_REG(hw, TIPG);
4047 tipg &= ~E1000_TIPG_IPGT_MASK;
4048 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
4049 E1000_WRITE_REG(hw, TIPG, tipg);
4051 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
4056 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
4057 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
4062 /******************************************************************************
4063 * Detects the current speed and duplex settings of the hardware.
4065 * hw - Struct containing variables accessed by shared code
4066 * speed - Speed of the connection
4067 * duplex - Duplex setting of the connection
4068 *****************************************************************************/
4070 e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed,
4079 if (hw->mac_type >= e1000_82543) {
4080 status = E1000_READ_REG(hw, STATUS);
4081 if (status & E1000_STATUS_SPEED_1000) {
4082 *speed = SPEED_1000;
4083 DEBUGOUT("1000 Mbs, ");
4084 } else if (status & E1000_STATUS_SPEED_100) {
4086 DEBUGOUT("100 Mbs, ");
4089 DEBUGOUT("10 Mbs, ");
4092 if (status & E1000_STATUS_FD) {
4093 *duplex = FULL_DUPLEX;
4094 DEBUGOUT("Full Duplex\r\n");
4096 *duplex = HALF_DUPLEX;
4097 DEBUGOUT(" Half Duplex\r\n");
4100 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
4101 *speed = SPEED_1000;
4102 *duplex = FULL_DUPLEX;
4105 /* IGP01 PHY may advertise full duplex operation after speed downgrade
4106 * even if it is operating at half duplex. Here we set the duplex
4107 * settings to match the duplex in the link partner's capabilities.
4109 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
4110 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
4114 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
4115 *duplex = HALF_DUPLEX;
4117 ret_val = e1000_read_phy_reg(hw,
4118 PHY_LP_ABILITY, &phy_data);
4121 if ((*speed == SPEED_100 &&
4122 !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
4123 || (*speed == SPEED_10
4124 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
4125 *duplex = HALF_DUPLEX;
4129 if ((hw->mac_type == e1000_80003es2lan) &&
4130 (hw->media_type == e1000_media_type_copper)) {
4131 if (*speed == SPEED_1000)
4132 ret_val = e1000_configure_kmrn_for_1000(hw);
4134 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
4138 return E1000_SUCCESS;
4141 /******************************************************************************
4142 * Blocks until autoneg completes or times out (~4.5 seconds)
4144 * hw - Struct containing variables accessed by shared code
4145 ******************************************************************************/
4147 e1000_wait_autoneg(struct e1000_hw *hw)
4153 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
4155 /* We will wait for autoneg to complete or timeout to expire. */
4156 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
4157 /* Read the MII Status Register and wait for Auto-Neg
4158 * Complete bit to be set.
4160 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
4161 DEBUGOUT("PHY Read Error\n");
4162 return -E1000_ERR_PHY;
4164 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
4165 DEBUGOUT("PHY Read Error\n");
4166 return -E1000_ERR_PHY;
4168 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
4169 DEBUGOUT("Auto-Neg complete.\n");
4174 DEBUGOUT("Auto-Neg timedout.\n");
4175 return -E1000_ERR_TIMEOUT;
4178 /******************************************************************************
4179 * Raises the Management Data Clock
4181 * hw - Struct containing variables accessed by shared code
4182 * ctrl - Device control register's current value
4183 ******************************************************************************/
4185 e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
4187 /* Raise the clock input to the Management Data Clock (by setting the MDC
4188 * bit), and then delay 2 microseconds.
4190 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
4191 E1000_WRITE_FLUSH(hw);
4195 /******************************************************************************
4196 * Lowers the Management Data Clock
4198 * hw - Struct containing variables accessed by shared code
4199 * ctrl - Device control register's current value
4200 ******************************************************************************/
4202 e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
4204 /* Lower the clock input to the Management Data Clock (by clearing the MDC
4205 * bit), and then delay 2 microseconds.
4207 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
4208 E1000_WRITE_FLUSH(hw);
4212 /******************************************************************************
4213 * Shifts data bits out to the PHY
4215 * hw - Struct containing variables accessed by shared code
4216 * data - Data to send out to the PHY
4217 * count - Number of bits to shift out
4219 * Bits are shifted out in MSB to LSB order.
4220 ******************************************************************************/
4222 e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count)
4227 /* We need to shift "count" number of bits out to the PHY. So, the value
4228 * in the "data" parameter will be shifted out to the PHY one bit at a
4229 * time. In order to do this, "data" must be broken down into bits.
4232 mask <<= (count - 1);
4234 ctrl = E1000_READ_REG(hw, CTRL);
4236 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
4237 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
4240 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
4241 * then raising and lowering the Management Data Clock. A "0" is
4242 * shifted out to the PHY by setting the MDIO bit to "0" and then
4243 * raising and lowering the clock.
4246 ctrl |= E1000_CTRL_MDIO;
4248 ctrl &= ~E1000_CTRL_MDIO;
4250 E1000_WRITE_REG(hw, CTRL, ctrl);
4251 E1000_WRITE_FLUSH(hw);
4255 e1000_raise_mdi_clk(hw, &ctrl);
4256 e1000_lower_mdi_clk(hw, &ctrl);
4262 /******************************************************************************
4263 * Shifts data bits in from the PHY
4265 * hw - Struct containing variables accessed by shared code
4267 * Bits are shifted in in MSB to LSB order.
4268 ******************************************************************************/
4270 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
4276 /* In order to read a register from the PHY, we need to shift in a total
4277 * of 18 bits from the PHY. The first two bit (turnaround) times are used
4278 * to avoid contention on the MDIO pin when a read operation is performed.
4279 * These two bits are ignored by us and thrown away. Bits are "shifted in"
4280 * by raising the input to the Management Data Clock (setting the MDC bit),
4281 * and then reading the value of the MDIO bit.
4283 ctrl = E1000_READ_REG(hw, CTRL);
4285 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
4286 ctrl &= ~E1000_CTRL_MDIO_DIR;
4287 ctrl &= ~E1000_CTRL_MDIO;
4289 E1000_WRITE_REG(hw, CTRL, ctrl);
4290 E1000_WRITE_FLUSH(hw);
4292 /* Raise and Lower the clock before reading in the data. This accounts for
4293 * the turnaround bits. The first clock occurred when we clocked out the
4294 * last bit of the Register Address.
4296 e1000_raise_mdi_clk(hw, &ctrl);
4297 e1000_lower_mdi_clk(hw, &ctrl);
4299 for (data = 0, i = 0; i < 16; i++) {
4301 e1000_raise_mdi_clk(hw, &ctrl);
4302 ctrl = E1000_READ_REG(hw, CTRL);
4303 /* Check to see if we shifted in a "1". */
4304 if (ctrl & E1000_CTRL_MDIO)
4306 e1000_lower_mdi_clk(hw, &ctrl);
4309 e1000_raise_mdi_clk(hw, &ctrl);
4310 e1000_lower_mdi_clk(hw, &ctrl);
4315 /*****************************************************************************
4316 * Reads the value from a PHY register
4318 * hw - Struct containing variables accessed by shared code
4319 * reg_addr - address of the PHY register to read
4320 ******************************************************************************/
4322 e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data)
4326 const uint32_t phy_addr = 1;
4328 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4329 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4330 return -E1000_ERR_PARAM;
4333 if (hw->mac_type > e1000_82543) {
4334 /* Set up Op-code, Phy Address, and register address in the MDI
4335 * Control register. The MAC will take care of interfacing with the
4336 * PHY to retrieve the desired data.
4338 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
4339 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4340 (E1000_MDIC_OP_READ));
4342 E1000_WRITE_REG(hw, MDIC, mdic);
4344 /* Poll the ready bit to see if the MDI read completed */
4345 for (i = 0; i < 64; i++) {
4347 mdic = E1000_READ_REG(hw, MDIC);
4348 if (mdic & E1000_MDIC_READY)
4351 if (!(mdic & E1000_MDIC_READY)) {
4352 DEBUGOUT("MDI Read did not complete\n");
4353 return -E1000_ERR_PHY;
4355 if (mdic & E1000_MDIC_ERROR) {
4356 DEBUGOUT("MDI Error\n");
4357 return -E1000_ERR_PHY;
4359 *phy_data = (uint16_t) mdic;
4361 /* We must first send a preamble through the MDIO pin to signal the
4362 * beginning of an MII instruction. This is done by sending 32
4363 * consecutive "1" bits.
4365 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4367 /* Now combine the next few fields that are required for a read
4368 * operation. We use this method instead of calling the
4369 * e1000_shift_out_mdi_bits routine five different times. The format of
4370 * a MII read instruction consists of a shift out of 14 bits and is
4371 * defined as follows:
4372 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
4373 * followed by a shift in of 18 bits. This first two bits shifted in
4374 * are TurnAround bits used to avoid contention on the MDIO pin when a
4375 * READ operation is performed. These two bits are thrown away
4376 * followed by a shift in of 16 bits which contains the desired data.
4378 mdic = ((reg_addr) | (phy_addr << 5) |
4379 (PHY_OP_READ << 10) | (PHY_SOF << 12));
4381 e1000_shift_out_mdi_bits(hw, mdic, 14);
4383 /* Now that we've shifted out the read command to the MII, we need to
4384 * "shift in" the 16-bit value (18 total bits) of the requested PHY
4387 *phy_data = e1000_shift_in_mdi_bits(hw);
4392 /******************************************************************************
4393 * Writes a value to a PHY register
4395 * hw - Struct containing variables accessed by shared code
4396 * reg_addr - address of the PHY register to write
4397 * data - data to write to the PHY
4398 ******************************************************************************/
4400 e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data)
4404 const uint32_t phy_addr = 1;
4406 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4407 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4408 return -E1000_ERR_PARAM;
4411 if (hw->mac_type > e1000_82543) {
4412 /* Set up Op-code, Phy Address, register address, and data intended
4413 * for the PHY register in the MDI Control register. The MAC will take
4414 * care of interfacing with the PHY to send the desired data.
4416 mdic = (((uint32_t) phy_data) |
4417 (reg_addr << E1000_MDIC_REG_SHIFT) |
4418 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4419 (E1000_MDIC_OP_WRITE));
4421 E1000_WRITE_REG(hw, MDIC, mdic);
4423 /* Poll the ready bit to see if the MDI read completed */
4424 for (i = 0; i < 64; i++) {
4426 mdic = E1000_READ_REG(hw, MDIC);
4427 if (mdic & E1000_MDIC_READY)
4430 if (!(mdic & E1000_MDIC_READY)) {
4431 DEBUGOUT("MDI Write did not complete\n");
4432 return -E1000_ERR_PHY;
4435 /* We'll need to use the SW defined pins to shift the write command
4436 * out to the PHY. We first send a preamble to the PHY to signal the
4437 * beginning of the MII instruction. This is done by sending 32
4438 * consecutive "1" bits.
4440 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4442 /* Now combine the remaining required fields that will indicate a
4443 * write operation. We use this method instead of calling the
4444 * e1000_shift_out_mdi_bits routine for each field in the command. The
4445 * format of a MII write instruction is as follows:
4446 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
4448 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
4449 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
4451 mdic |= (uint32_t) phy_data;
4453 e1000_shift_out_mdi_bits(hw, mdic, 32);
4458 /******************************************************************************
4459 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
4460 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
4461 * the caller to figure out how to deal with it.
4463 * hw - Struct containing variables accessed by shared code
4465 * returns: - E1000_BLK_PHY_RESET
4468 *****************************************************************************/
4470 e1000_check_phy_reset_block(struct e1000_hw *hw)
4475 if (hw->mac_type == e1000_ich8lan) {
4476 fwsm = E1000_READ_REG(hw, FWSM);
4477 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
4478 : E1000_BLK_PHY_RESET;
4481 if (hw->mac_type > e1000_82547_rev_2)
4482 manc = E1000_READ_REG(hw, MANC);
4483 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
4484 E1000_BLK_PHY_RESET : E1000_SUCCESS;
4487 /***************************************************************************
4488 * Checks if the PHY configuration is done
4490 * hw: Struct containing variables accessed by shared code
4492 * returns: - E1000_ERR_RESET if fail to reset MAC
4493 * E1000_SUCCESS at any other case.
4495 ***************************************************************************/
4497 e1000_get_phy_cfg_done(struct e1000_hw *hw)
4499 int32_t timeout = PHY_CFG_TIMEOUT;
4500 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
4504 switch (hw->mac_type) {
4509 case e1000_80003es2lan:
4510 /* Separate *_CFG_DONE_* bit for each port */
4511 if (e1000_is_second_port(hw))
4512 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
4519 if (hw->mac_type == e1000_igb) {
4520 if (E1000_READ_REG(hw, I210_EEMNGCTL) & cfg_mask)
4523 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
4530 DEBUGOUT("MNG configuration cycle has not "
4532 return -E1000_ERR_RESET;
4537 return E1000_SUCCESS;
4540 /******************************************************************************
4541 * Returns the PHY to the power-on reset state
4543 * hw - Struct containing variables accessed by shared code
4544 ******************************************************************************/
4546 e1000_phy_hw_reset(struct e1000_hw *hw)
4548 uint16_t swfw = E1000_SWFW_PHY0_SM;
4549 uint32_t ctrl, ctrl_ext;
4555 /* In the case of the phy reset being blocked, it's not an error, we
4556 * simply return success without performing the reset. */
4557 ret_val = e1000_check_phy_reset_block(hw);
4559 return E1000_SUCCESS;
4561 DEBUGOUT("Resetting Phy...\n");
4563 if (hw->mac_type > e1000_82543) {
4564 if (e1000_is_second_port(hw))
4565 swfw = E1000_SWFW_PHY1_SM;
4567 if (e1000_swfw_sync_acquire(hw, swfw)) {
4568 DEBUGOUT("Unable to acquire swfw sync\n");
4569 return -E1000_ERR_SWFW_SYNC;
4572 /* Read the device control register and assert the E1000_CTRL_PHY_RST
4573 * bit. Then, take it out of reset.
4575 ctrl = E1000_READ_REG(hw, CTRL);
4576 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
4577 E1000_WRITE_FLUSH(hw);
4579 if (hw->mac_type < e1000_82571)
4584 E1000_WRITE_REG(hw, CTRL, ctrl);
4585 E1000_WRITE_FLUSH(hw);
4587 if (hw->mac_type >= e1000_82571)
4591 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
4592 * bit to put the PHY into reset. Then, take it out of reset.
4594 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
4595 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
4596 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
4597 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4598 E1000_WRITE_FLUSH(hw);
4600 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
4601 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4602 E1000_WRITE_FLUSH(hw);
4606 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
4607 /* Configure activity LED after PHY reset */
4608 led_ctrl = E1000_READ_REG(hw, LEDCTL);
4609 led_ctrl &= IGP_ACTIVITY_LED_MASK;
4610 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
4611 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
4614 e1000_swfw_sync_release(hw, swfw);
4616 /* Wait for FW to finish PHY configuration. */
4617 ret_val = e1000_get_phy_cfg_done(hw);
4618 if (ret_val != E1000_SUCCESS)
4624 /******************************************************************************
4625 * IGP phy init script - initializes the GbE PHY
4627 * hw - Struct containing variables accessed by shared code
4628 *****************************************************************************/
4630 e1000_phy_init_script(struct e1000_hw *hw)
4633 uint16_t phy_saved_data;
4636 if (hw->phy_init_script) {
4639 /* Save off the current value of register 0x2F5B to be
4640 * restored at the end of this routine. */
4641 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
4643 /* Disabled the PHY transmitter */
4644 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
4648 e1000_write_phy_reg(hw, 0x0000, 0x0140);
4652 switch (hw->mac_type) {
4655 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
4657 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
4659 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
4661 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
4663 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
4665 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
4667 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
4669 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
4671 e1000_write_phy_reg(hw, 0x2010, 0x0008);
4674 case e1000_82541_rev_2:
4675 case e1000_82547_rev_2:
4676 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
4682 e1000_write_phy_reg(hw, 0x0000, 0x3300);
4686 /* Now enable the transmitter */
4688 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
4690 if (hw->mac_type == e1000_82547) {
4691 uint16_t fused, fine, coarse;
4693 /* Move to analog registers page */
4694 e1000_read_phy_reg(hw,
4695 IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
4697 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
4698 e1000_read_phy_reg(hw,
4699 IGP01E1000_ANALOG_FUSE_STATUS, &fused);
4701 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
4703 & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
4706 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
4708 IGP01E1000_ANALOG_FUSE_COARSE_10;
4709 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
4711 == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
4712 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
4715 & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
4717 & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
4719 & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
4721 e1000_write_phy_reg(hw,
4722 IGP01E1000_ANALOG_FUSE_CONTROL, fused);
4723 e1000_write_phy_reg(hw,
4724 IGP01E1000_ANALOG_FUSE_BYPASS,
4725 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
4731 /******************************************************************************
4734 * hw - Struct containing variables accessed by shared code
4736 * Sets bit 15 of the MII Control register
4737 ******************************************************************************/
4739 e1000_phy_reset(struct e1000_hw *hw)
4746 /* In the case of the phy reset being blocked, it's not an error, we
4747 * simply return success without performing the reset. */
4748 ret_val = e1000_check_phy_reset_block(hw);
4750 return E1000_SUCCESS;
4752 switch (hw->phy_type) {
4754 case e1000_phy_igp_2:
4755 case e1000_phy_igp_3:
4758 ret_val = e1000_phy_hw_reset(hw);
4763 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
4767 phy_data |= MII_CR_RESET;
4768 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
4776 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
4777 e1000_phy_init_script(hw);
4779 return E1000_SUCCESS;
4782 static int e1000_set_phy_type (struct e1000_hw *hw)
4786 if (hw->mac_type == e1000_undefined)
4787 return -E1000_ERR_PHY_TYPE;
4789 switch (hw->phy_id) {
4790 case M88E1000_E_PHY_ID:
4791 case M88E1000_I_PHY_ID:
4792 case M88E1011_I_PHY_ID:
4793 case M88E1111_I_PHY_ID:
4794 hw->phy_type = e1000_phy_m88;
4796 case IGP01E1000_I_PHY_ID:
4797 if (hw->mac_type == e1000_82541 ||
4798 hw->mac_type == e1000_82541_rev_2 ||
4799 hw->mac_type == e1000_82547 ||
4800 hw->mac_type == e1000_82547_rev_2) {
4801 hw->phy_type = e1000_phy_igp;
4804 case IGP03E1000_E_PHY_ID:
4805 hw->phy_type = e1000_phy_igp_3;
4808 case IFE_PLUS_E_PHY_ID:
4809 case IFE_C_E_PHY_ID:
4810 hw->phy_type = e1000_phy_ife;
4812 case GG82563_E_PHY_ID:
4813 if (hw->mac_type == e1000_80003es2lan) {
4814 hw->phy_type = e1000_phy_gg82563;
4817 case BME1000_E_PHY_ID:
4818 hw->phy_type = e1000_phy_bm;
4821 hw->phy_type = e1000_phy_igb;
4825 /* Should never have loaded on this device */
4826 hw->phy_type = e1000_phy_undefined;
4827 return -E1000_ERR_PHY_TYPE;
4830 return E1000_SUCCESS;
4833 /******************************************************************************
4834 * Probes the expected PHY address for known PHY IDs
4836 * hw - Struct containing variables accessed by shared code
4837 ******************************************************************************/
4839 e1000_detect_gig_phy(struct e1000_hw *hw)
4841 int32_t phy_init_status, ret_val;
4842 uint16_t phy_id_high, phy_id_low;
4847 /* The 82571 firmware may still be configuring the PHY. In this
4848 * case, we cannot access the PHY until the configuration is done. So
4849 * we explicitly set the PHY values. */
4850 if (hw->mac_type == e1000_82571 ||
4851 hw->mac_type == e1000_82572) {
4852 hw->phy_id = IGP01E1000_I_PHY_ID;
4853 hw->phy_type = e1000_phy_igp_2;
4854 return E1000_SUCCESS;
4857 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a
4858 * work- around that forces PHY page 0 to be set or the reads fail.
4859 * The rest of the code in this routine uses e1000_read_phy_reg to
4860 * read the PHY ID. So for ESB-2 we need to have this set so our
4861 * reads won't fail. If the attached PHY is not a e1000_phy_gg82563,
4862 * the routines below will figure this out as well. */
4863 if (hw->mac_type == e1000_80003es2lan)
4864 hw->phy_type = e1000_phy_gg82563;
4866 /* Read the PHY ID Registers to identify which PHY is onboard. */
4867 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
4871 hw->phy_id = (uint32_t) (phy_id_high << 16);
4873 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
4877 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4878 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4880 switch (hw->mac_type) {
4882 if (hw->phy_id == M88E1000_E_PHY_ID)
4886 if (hw->phy_id == M88E1000_I_PHY_ID)
4891 case e1000_82545_rev_3:
4893 case e1000_82546_rev_3:
4894 if (hw->phy_id == M88E1011_I_PHY_ID)
4898 case e1000_82541_rev_2:
4900 case e1000_82547_rev_2:
4901 if(hw->phy_id == IGP01E1000_I_PHY_ID)
4906 if (hw->phy_id == M88E1111_I_PHY_ID)
4910 if (hw->phy_id == BME1000_E_PHY_ID)
4913 case e1000_80003es2lan:
4914 if (hw->phy_id == GG82563_E_PHY_ID)
4918 if (hw->phy_id == IGP03E1000_E_PHY_ID)
4920 if (hw->phy_id == IFE_E_PHY_ID)
4922 if (hw->phy_id == IFE_PLUS_E_PHY_ID)
4924 if (hw->phy_id == IFE_C_E_PHY_ID)
4928 if (hw->phy_id == I210_I_PHY_ID)
4932 DEBUGOUT("Invalid MAC type %d\n", hw->mac_type);
4933 return -E1000_ERR_CONFIG;
4936 phy_init_status = e1000_set_phy_type(hw);
4938 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4939 DEBUGOUT("PHY ID 0x%X detected\n", hw->phy_id);
4942 DEBUGOUT("Invalid PHY ID 0x%X\n", hw->phy_id);
4943 return -E1000_ERR_PHY;
4946 /*****************************************************************************
4947 * Set media type and TBI compatibility.
4949 * hw - Struct containing variables accessed by shared code
4950 * **************************************************************************/
4952 e1000_set_media_type(struct e1000_hw *hw)
4958 if (hw->mac_type != e1000_82543) {
4959 /* tbi_compatibility is only valid on 82543 */
4960 hw->tbi_compatibility_en = false;
4963 switch (hw->device_id) {
4964 case E1000_DEV_ID_82545GM_SERDES:
4965 case E1000_DEV_ID_82546GB_SERDES:
4966 case E1000_DEV_ID_82571EB_SERDES:
4967 case E1000_DEV_ID_82571EB_SERDES_DUAL:
4968 case E1000_DEV_ID_82571EB_SERDES_QUAD:
4969 case E1000_DEV_ID_82572EI_SERDES:
4970 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
4971 hw->media_type = e1000_media_type_internal_serdes;
4974 switch (hw->mac_type) {
4975 case e1000_82542_rev2_0:
4976 case e1000_82542_rev2_1:
4977 hw->media_type = e1000_media_type_fiber;
4983 /* The STATUS_TBIMODE bit is reserved or reused
4984 * for the this device.
4986 hw->media_type = e1000_media_type_copper;
4989 status = E1000_READ_REG(hw, STATUS);
4990 if (status & E1000_STATUS_TBIMODE) {
4991 hw->media_type = e1000_media_type_fiber;
4992 /* tbi_compatibility not valid on fiber */
4993 hw->tbi_compatibility_en = false;
4995 hw->media_type = e1000_media_type_copper;
5003 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
5005 * e1000_sw_init initializes the Adapter private data structure.
5006 * Fields are initialized based on PCI device information and
5007 * OS network device settings (MTU size).
5011 e1000_sw_init(struct e1000_hw *hw)
5015 /* PCI config space info */
5016 #ifdef CONFIG_DM_ETH
5017 dm_pci_read_config16(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
5018 dm_pci_read_config16(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
5019 dm_pci_read_config16(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
5020 &hw->subsystem_vendor_id);
5021 dm_pci_read_config16(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
5023 dm_pci_read_config8(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
5024 dm_pci_read_config16(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
5026 pci_read_config_word(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
5027 pci_read_config_word(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
5028 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
5029 &hw->subsystem_vendor_id);
5030 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
5032 pci_read_config_byte(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
5033 pci_read_config_word(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
5036 /* identify the MAC */
5037 result = e1000_set_mac_type(hw);
5039 E1000_ERR(hw, "Unknown MAC Type\n");
5043 switch (hw->mac_type) {
5048 case e1000_82541_rev_2:
5049 case e1000_82547_rev_2:
5050 hw->phy_init_script = 1;
5054 /* flow control settings */
5055 hw->fc_high_water = E1000_FC_HIGH_THRESH;
5056 hw->fc_low_water = E1000_FC_LOW_THRESH;
5057 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
5058 hw->fc_send_xon = 1;
5060 /* Media type - copper or fiber */
5061 hw->tbi_compatibility_en = true;
5062 e1000_set_media_type(hw);
5064 if (hw->mac_type >= e1000_82543) {
5065 uint32_t status = E1000_READ_REG(hw, STATUS);
5067 if (status & E1000_STATUS_TBIMODE) {
5068 DEBUGOUT("fiber interface\n");
5069 hw->media_type = e1000_media_type_fiber;
5071 DEBUGOUT("copper interface\n");
5072 hw->media_type = e1000_media_type_copper;
5075 hw->media_type = e1000_media_type_fiber;
5078 hw->wait_autoneg_complete = true;
5079 if (hw->mac_type < e1000_82543)
5080 hw->report_tx_early = 0;
5082 hw->report_tx_early = 1;
5084 return E1000_SUCCESS;
5088 fill_rx(struct e1000_hw *hw)
5090 struct e1000_rx_desc *rd;
5091 unsigned long flush_start, flush_end;
5094 rd = rx_base + rx_tail;
5095 rx_tail = (rx_tail + 1) % 8;
5097 rd->buffer_addr = cpu_to_le64((unsigned long)packet);
5100 * Make sure there are no stale data in WB over this area, which
5101 * might get written into the memory while the e1000 also writes
5102 * into the same memory area.
5104 invalidate_dcache_range((unsigned long)packet,
5105 (unsigned long)packet + 4096);
5106 /* Dump the DMA descriptor into RAM. */
5107 flush_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
5108 flush_end = flush_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
5109 flush_dcache_range(flush_start, flush_end);
5111 E1000_WRITE_REG(hw, RDT, rx_tail);
5115 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
5116 * @adapter: board private structure
5118 * Configure the Tx unit of the MAC after a reset.
5122 e1000_configure_tx(struct e1000_hw *hw)
5125 unsigned long tipg, tarc;
5126 uint32_t ipgr1, ipgr2;
5128 E1000_WRITE_REG(hw, TDBAL, lower_32_bits((unsigned long)tx_base));
5129 E1000_WRITE_REG(hw, TDBAH, upper_32_bits((unsigned long)tx_base));
5131 E1000_WRITE_REG(hw, TDLEN, 128);
5133 /* Setup the HW Tx Head and Tail descriptor pointers */
5134 E1000_WRITE_REG(hw, TDH, 0);
5135 E1000_WRITE_REG(hw, TDT, 0);
5138 /* Set the default values for the Tx Inter Packet Gap timer */
5139 if (hw->mac_type <= e1000_82547_rev_2 &&
5140 (hw->media_type == e1000_media_type_fiber ||
5141 hw->media_type == e1000_media_type_internal_serdes))
5142 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
5144 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
5146 /* Set the default values for the Tx Inter Packet Gap timer */
5147 switch (hw->mac_type) {
5148 case e1000_82542_rev2_0:
5149 case e1000_82542_rev2_1:
5150 tipg = DEFAULT_82542_TIPG_IPGT;
5151 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
5152 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
5154 case e1000_80003es2lan:
5155 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
5156 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
5159 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
5160 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
5163 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
5164 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
5165 E1000_WRITE_REG(hw, TIPG, tipg);
5166 /* Program the Transmit Control Register */
5167 tctl = E1000_READ_REG(hw, TCTL);
5168 tctl &= ~E1000_TCTL_CT;
5169 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
5170 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
5172 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
5173 tarc = E1000_READ_REG(hw, TARC0);
5174 /* set the speed mode bit, we'll clear it if we're not at
5175 * gigabit link later */
5176 /* git bit can be set to 1*/
5177 } else if (hw->mac_type == e1000_80003es2lan) {
5178 tarc = E1000_READ_REG(hw, TARC0);
5180 E1000_WRITE_REG(hw, TARC0, tarc);
5181 tarc = E1000_READ_REG(hw, TARC1);
5183 E1000_WRITE_REG(hw, TARC1, tarc);
5187 e1000_config_collision_dist(hw);
5188 /* Setup Transmit Descriptor Settings for eop descriptor */
5189 hw->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
5191 /* Need to set up RS bit */
5192 if (hw->mac_type < e1000_82543)
5193 hw->txd_cmd |= E1000_TXD_CMD_RPS;
5195 hw->txd_cmd |= E1000_TXD_CMD_RS;
5198 if (hw->mac_type == e1000_igb) {
5199 E1000_WRITE_REG(hw, TCTL_EXT, 0x42 << 10);
5201 uint32_t reg_txdctl = E1000_READ_REG(hw, TXDCTL);
5202 reg_txdctl |= 1 << 25;
5203 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
5209 E1000_WRITE_REG(hw, TCTL, tctl);
5215 * e1000_setup_rctl - configure the receive control register
5216 * @adapter: Board private structure
5219 e1000_setup_rctl(struct e1000_hw *hw)
5223 rctl = E1000_READ_REG(hw, RCTL);
5225 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
5227 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO
5228 | E1000_RCTL_RDMTS_HALF; /* |
5229 (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */
5231 if (hw->tbi_compatibility_on == 1)
5232 rctl |= E1000_RCTL_SBP;
5234 rctl &= ~E1000_RCTL_SBP;
5236 rctl &= ~(E1000_RCTL_SZ_4096);
5237 rctl |= E1000_RCTL_SZ_2048;
5238 rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
5239 E1000_WRITE_REG(hw, RCTL, rctl);
5243 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
5244 * @adapter: board private structure
5246 * Configure the Rx unit of the MAC after a reset.
5249 e1000_configure_rx(struct e1000_hw *hw)
5251 unsigned long rctl, ctrl_ext;
5254 /* make sure receives are disabled while setting up the descriptors */
5255 rctl = E1000_READ_REG(hw, RCTL);
5256 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
5257 if (hw->mac_type >= e1000_82540) {
5258 /* Set the interrupt throttling rate. Value is calculated
5259 * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */
5260 #define MAX_INTS_PER_SEC 8000
5261 #define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
5262 E1000_WRITE_REG(hw, ITR, DEFAULT_ITR);
5265 if (hw->mac_type >= e1000_82571) {
5266 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5267 /* Reset delay timers after every interrupt */
5268 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
5269 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
5270 E1000_WRITE_FLUSH(hw);
5272 /* Setup the Base and Length of the Rx Descriptor Ring */
5273 E1000_WRITE_REG(hw, RDBAL, lower_32_bits((unsigned long)rx_base));
5274 E1000_WRITE_REG(hw, RDBAH, upper_32_bits((unsigned long)rx_base));
5276 E1000_WRITE_REG(hw, RDLEN, 128);
5278 /* Setup the HW Rx Head and Tail Descriptor Pointers */
5279 E1000_WRITE_REG(hw, RDH, 0);
5280 E1000_WRITE_REG(hw, RDT, 0);
5281 /* Enable Receives */
5283 if (hw->mac_type == e1000_igb) {
5285 uint32_t reg_rxdctl = E1000_READ_REG(hw, RXDCTL);
5286 reg_rxdctl |= 1 << 25;
5287 E1000_WRITE_REG(hw, RXDCTL, reg_rxdctl);
5291 E1000_WRITE_REG(hw, RCTL, rctl);
5296 /**************************************************************************
5297 POLL - Wait for a frame
5298 ***************************************************************************/
5300 _e1000_poll(struct e1000_hw *hw)
5302 struct e1000_rx_desc *rd;
5303 unsigned long inval_start, inval_end;
5306 /* return true if there's an ethernet packet ready to read */
5307 rd = rx_base + rx_last;
5309 /* Re-load the descriptor from RAM. */
5310 inval_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
5311 inval_end = inval_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
5312 invalidate_dcache_range(inval_start, inval_end);
5314 if (!(rd->status & E1000_RXD_STAT_DD))
5316 /* DEBUGOUT("recv: packet len=%d\n", rd->length); */
5317 /* Packet received, make sure the data are re-loaded from RAM. */
5318 len = le16_to_cpu(rd->length);
5319 invalidate_dcache_range((unsigned long)packet,
5320 (unsigned long)packet +
5321 roundup(len, ARCH_DMA_MINALIGN));
5325 static int _e1000_transmit(struct e1000_hw *hw, void *txpacket, int length)
5327 void *nv_packet = (void *)txpacket;
5328 struct e1000_tx_desc *txp;
5330 unsigned long flush_start, flush_end;
5332 txp = tx_base + tx_tail;
5333 tx_tail = (tx_tail + 1) % 8;
5335 txp->buffer_addr = cpu_to_le64(virt_to_bus(hw->pdev, nv_packet));
5336 txp->lower.data = cpu_to_le32(hw->txd_cmd | length);
5337 txp->upper.data = 0;
5339 /* Dump the packet into RAM so e1000 can pick them. */
5340 flush_dcache_range((unsigned long)nv_packet,
5341 (unsigned long)nv_packet +
5342 roundup(length, ARCH_DMA_MINALIGN));
5343 /* Dump the descriptor into RAM as well. */
5344 flush_start = ((unsigned long)txp) & ~(ARCH_DMA_MINALIGN - 1);
5345 flush_end = flush_start + roundup(sizeof(*txp), ARCH_DMA_MINALIGN);
5346 flush_dcache_range(flush_start, flush_end);
5348 E1000_WRITE_REG(hw, TDT, tx_tail);
5350 E1000_WRITE_FLUSH(hw);
5352 invalidate_dcache_range(flush_start, flush_end);
5353 if (le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD)
5355 if (i++ > TOUT_LOOP) {
5356 DEBUGOUT("e1000: tx timeout\n");
5359 udelay(10); /* give the nic a chance to write to the register */
5365 _e1000_disable(struct e1000_hw *hw)
5367 /* Turn off the ethernet interface */
5368 E1000_WRITE_REG(hw, RCTL, 0);
5369 E1000_WRITE_REG(hw, TCTL, 0);
5371 /* Clear the transmit ring */
5372 E1000_WRITE_REG(hw, TDH, 0);
5373 E1000_WRITE_REG(hw, TDT, 0);
5375 /* Clear the receive ring */
5376 E1000_WRITE_REG(hw, RDH, 0);
5377 E1000_WRITE_REG(hw, RDT, 0);
5384 e1000_reset(struct e1000_hw *hw, unsigned char enetaddr[6])
5387 if (hw->mac_type >= e1000_82544)
5388 E1000_WRITE_REG(hw, WUC, 0);
5390 return e1000_init_hw(hw, enetaddr);
5394 _e1000_init(struct e1000_hw *hw, unsigned char enetaddr[6])
5398 ret_val = e1000_reset(hw, enetaddr);
5400 if ((ret_val == -E1000_ERR_NOLINK) ||
5401 (ret_val == -E1000_ERR_TIMEOUT)) {
5402 E1000_ERR(hw, "Valid Link not detected: %d\n", ret_val);
5404 E1000_ERR(hw, "Hardware Initialization Failed\n");
5408 e1000_configure_tx(hw);
5409 e1000_setup_rctl(hw);
5410 e1000_configure_rx(hw);
5414 /******************************************************************************
5415 * Gets the current PCI bus type of hardware
5417 * hw - Struct containing variables accessed by shared code
5418 *****************************************************************************/
5419 void e1000_get_bus_type(struct e1000_hw *hw)
5423 switch (hw->mac_type) {
5424 case e1000_82542_rev2_0:
5425 case e1000_82542_rev2_1:
5426 hw->bus_type = e1000_bus_type_pci;
5432 case e1000_80003es2lan:
5435 hw->bus_type = e1000_bus_type_pci_express;
5438 status = E1000_READ_REG(hw, STATUS);
5439 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5440 e1000_bus_type_pcix : e1000_bus_type_pci;
5445 #ifndef CONFIG_DM_ETH
5446 /* A list of all registered e1000 devices */
5447 static LIST_HEAD(e1000_hw_list);
5450 #ifdef CONFIG_DM_ETH
5451 static int e1000_init_one(struct e1000_hw *hw, int cardnum,
5452 struct udevice *devno, unsigned char enetaddr[6])
5454 static int e1000_init_one(struct e1000_hw *hw, int cardnum, pci_dev_t devno,
5455 unsigned char enetaddr[6])
5460 /* Assign the passed-in values */
5461 #ifdef CONFIG_DM_ETH
5466 hw->cardnum = cardnum;
5468 /* Print a debug message with the IO base address */
5469 #ifdef CONFIG_DM_ETH
5470 dm_pci_read_config32(devno, PCI_BASE_ADDRESS_0, &val);
5472 pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &val);
5474 E1000_DBG(hw, "iobase 0x%08x\n", val & 0xfffffff0);
5476 /* Try to enable I/O accesses and bus-mastering */
5477 val = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
5478 #ifdef CONFIG_DM_ETH
5479 dm_pci_write_config32(devno, PCI_COMMAND, val);
5481 pci_write_config_dword(devno, PCI_COMMAND, val);
5484 /* Make sure it worked */
5485 #ifdef CONFIG_DM_ETH
5486 dm_pci_read_config32(devno, PCI_COMMAND, &val);
5488 pci_read_config_dword(devno, PCI_COMMAND, &val);
5490 if (!(val & PCI_COMMAND_MEMORY)) {
5491 E1000_ERR(hw, "Can't enable I/O memory\n");
5494 if (!(val & PCI_COMMAND_MASTER)) {
5495 E1000_ERR(hw, "Can't enable bus-mastering\n");
5499 /* Are these variables needed? */
5500 hw->fc = e1000_fc_default;
5501 hw->original_fc = e1000_fc_default;
5502 hw->autoneg_failed = 0;
5504 hw->get_link_status = true;
5505 #ifndef CONFIG_E1000_NO_NVM
5506 hw->eeprom_semaphore_present = true;
5508 #ifdef CONFIG_DM_ETH
5509 hw->hw_addr = dm_pci_map_bar(devno, PCI_BASE_ADDRESS_0,
5512 hw->hw_addr = pci_map_bar(devno, PCI_BASE_ADDRESS_0,
5515 hw->mac_type = e1000_undefined;
5517 /* MAC and Phy settings */
5518 if (e1000_sw_init(hw) < 0) {
5519 E1000_ERR(hw, "Software init failed\n");
5522 if (e1000_check_phy_reset_block(hw))
5523 E1000_ERR(hw, "PHY Reset is blocked!\n");
5525 /* Basic init was OK, reset the hardware and allow SPI access */
5528 #ifndef CONFIG_E1000_NO_NVM
5529 /* Validate the EEPROM and get chipset information */
5530 if (e1000_init_eeprom_params(hw)) {
5531 E1000_ERR(hw, "EEPROM is invalid!\n");
5534 if ((E1000_READ_REG(hw, I210_EECD) & E1000_EECD_FLUPD) &&
5535 e1000_validate_eeprom_checksum(hw))
5537 e1000_read_mac_addr(hw, enetaddr);
5539 e1000_get_bus_type(hw);
5541 #ifndef CONFIG_E1000_NO_NVM
5542 printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n ",
5543 enetaddr[0], enetaddr[1], enetaddr[2],
5544 enetaddr[3], enetaddr[4], enetaddr[5]);
5546 memset(enetaddr, 0, 6);
5547 printf("e1000: no NVM\n");
5553 /* Put the name of a device in a string */
5554 static void e1000_name(char *str, int cardnum)
5556 sprintf(str, "e1000#%u", cardnum);
5559 #ifndef CONFIG_DM_ETH
5560 /**************************************************************************
5561 TRANSMIT - Transmit a frame
5562 ***************************************************************************/
5563 static int e1000_transmit(struct eth_device *nic, void *txpacket, int length)
5565 struct e1000_hw *hw = nic->priv;
5567 return _e1000_transmit(hw, txpacket, length);
5570 /**************************************************************************
5571 DISABLE - Turn off ethernet interface
5572 ***************************************************************************/
5574 e1000_disable(struct eth_device *nic)
5576 struct e1000_hw *hw = nic->priv;
5581 /**************************************************************************
5582 INIT - set up ethernet interface(s)
5583 ***************************************************************************/
5585 e1000_init(struct eth_device *nic, bd_t *bis)
5587 struct e1000_hw *hw = nic->priv;
5589 return _e1000_init(hw, nic->enetaddr);
5593 e1000_poll(struct eth_device *nic)
5595 struct e1000_hw *hw = nic->priv;
5598 len = _e1000_poll(hw);
5600 net_process_received_packet((uchar *)packet, len);
5607 /**************************************************************************
5608 PROBE - Look for an adapter, this routine's visible to the outside
5609 You should omit the last argument struct pci_device * for a non-PCI NIC
5610 ***************************************************************************/
5612 e1000_initialize(bd_t * bis)
5620 /* Find and probe all the matching PCI devices */
5621 for (i = 0; (devno = pci_find_devices(e1000_supported, i)) >= 0; i++) {
5623 * These will never get freed due to errors, this allows us to
5624 * perform SPI EEPROM programming from U-Boot, for example.
5626 struct eth_device *nic = malloc(sizeof(*nic));
5627 struct e1000_hw *hw = malloc(sizeof(*hw));
5629 printf("e1000#%u: Out of Memory!\n", i);
5635 /* Make sure all of the fields are initially zeroed */
5636 memset(nic, 0, sizeof(*nic));
5637 memset(hw, 0, sizeof(*hw));
5640 /* Generate a card name */
5641 e1000_name(nic->name, i);
5642 hw->name = nic->name;
5644 ret = e1000_init_one(hw, i, devno, nic->enetaddr);
5647 list_add_tail(&hw->list_node, &e1000_hw_list);
5651 /* Set up the function pointers and register the device */
5652 nic->init = e1000_init;
5653 nic->recv = e1000_poll;
5654 nic->send = e1000_transmit;
5655 nic->halt = e1000_disable;
5662 struct e1000_hw *e1000_find_card(unsigned int cardnum)
5664 struct e1000_hw *hw;
5666 list_for_each_entry(hw, &e1000_hw_list, list_node)
5667 if (hw->cardnum == cardnum)
5672 #endif /* !CONFIG_DM_ETH */
5674 #ifdef CONFIG_CMD_E1000
5675 static int do_e1000(cmd_tbl_t *cmdtp, int flag,
5676 int argc, char * const argv[])
5678 unsigned char *mac = NULL;
5679 #ifdef CONFIG_DM_ETH
5680 struct eth_pdata *plat;
5681 struct udevice *dev;
5685 #if !defined(CONFIG_DM_ETH) || defined(CONFIG_E1000_SPI)
5686 struct e1000_hw *hw;
5695 /* Make sure we can find the requested e1000 card */
5696 cardnum = simple_strtoul(argv[1], NULL, 10);
5697 #ifdef CONFIG_DM_ETH
5698 e1000_name(name, cardnum);
5699 ret = uclass_get_device_by_name(UCLASS_ETH, name, &dev);
5701 plat = dev_get_platdata(dev);
5702 mac = plat->enetaddr;
5705 hw = e1000_find_card(cardnum);
5707 mac = hw->nic->enetaddr;
5710 printf("e1000: ERROR: No such device: e1000#%s\n", argv[1]);
5714 if (!strcmp(argv[2], "print-mac-address")) {
5715 printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
5716 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
5720 #ifdef CONFIG_E1000_SPI
5721 #ifdef CONFIG_DM_ETH
5722 hw = dev_get_priv(dev);
5724 /* Handle the "SPI" subcommand */
5725 if (!strcmp(argv[2], "spi"))
5726 return do_e1000_spi(cmdtp, hw, argc - 3, argv + 3);
5734 e1000, 7, 0, do_e1000,
5735 "Intel e1000 controller management",
5736 /* */"<card#> print-mac-address\n"
5737 #ifdef CONFIG_E1000_SPI
5738 "e1000 <card#> spi show [<offset> [<length>]]\n"
5739 "e1000 <card#> spi dump <addr> <offset> <length>\n"
5740 "e1000 <card#> spi program <addr> <offset> <length>\n"
5741 "e1000 <card#> spi checksum [update]\n"
5743 " - Manage the Intel E1000 PCI device"
5745 #endif /* not CONFIG_CMD_E1000 */
5747 #ifdef CONFIG_DM_ETH
5748 static int e1000_eth_start(struct udevice *dev)
5750 struct eth_pdata *plat = dev_get_platdata(dev);
5751 struct e1000_hw *hw = dev_get_priv(dev);
5753 return _e1000_init(hw, plat->enetaddr);
5756 static void e1000_eth_stop(struct udevice *dev)
5758 struct e1000_hw *hw = dev_get_priv(dev);
5763 static int e1000_eth_send(struct udevice *dev, void *packet, int length)
5765 struct e1000_hw *hw = dev_get_priv(dev);
5768 ret = _e1000_transmit(hw, packet, length);
5770 return ret ? 0 : -ETIMEDOUT;
5773 static int e1000_eth_recv(struct udevice *dev, int flags, uchar **packetp)
5775 struct e1000_hw *hw = dev_get_priv(dev);
5778 len = _e1000_poll(hw);
5782 return len ? len : -EAGAIN;
5785 static int e1000_free_pkt(struct udevice *dev, uchar *packet, int length)
5787 struct e1000_hw *hw = dev_get_priv(dev);
5794 static int e1000_eth_probe(struct udevice *dev)
5796 struct eth_pdata *plat = dev_get_platdata(dev);
5797 struct e1000_hw *hw = dev_get_priv(dev);
5800 hw->name = dev->name;
5801 ret = e1000_init_one(hw, trailing_strtol(dev->name),
5802 dev, plat->enetaddr);
5804 printf(pr_fmt("failed to initialize card: %d\n"), ret);
5811 static int e1000_eth_bind(struct udevice *dev)
5816 * A simple way to number the devices. When device tree is used this
5817 * is unnecessary, but when the device is just discovered on the PCI
5818 * bus we need a name. We could instead have the uclass figure out
5819 * which devices are different and number them.
5821 e1000_name(name, num_cards++);
5823 return device_set_name(dev, name);
5826 static const struct eth_ops e1000_eth_ops = {
5827 .start = e1000_eth_start,
5828 .send = e1000_eth_send,
5829 .recv = e1000_eth_recv,
5830 .stop = e1000_eth_stop,
5831 .free_pkt = e1000_free_pkt,
5834 static const struct udevice_id e1000_eth_ids[] = {
5835 { .compatible = "intel,e1000" },
5839 U_BOOT_DRIVER(eth_e1000) = {
5840 .name = "eth_e1000",
5842 .of_match = e1000_eth_ids,
5843 .bind = e1000_eth_bind,
5844 .probe = e1000_eth_probe,
5845 .ops = &e1000_eth_ops,
5846 .priv_auto_alloc_size = sizeof(struct e1000_hw),
5847 .platdata_auto_alloc_size = sizeof(struct eth_pdata),
5850 U_BOOT_PCI_DEVICE(eth_e1000, e1000_supported);