1 // SPDX-License-Identifier: GPL-2.0+
2 /**************************************************************************
3 Intel Pro 1000 for ppcboot/das-u-boot
4 Drivers are port from Intel's Linux driver e1000-4.3.15
5 and from Etherboot pro 1000 driver by mrakes at vivato dot net
6 tested on both gig copper and gig fiber boards
7 ***************************************************************************/
8 /*******************************************************************************
11 Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.
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.
42 #include <linux/delay.h>
44 #include <asm/cache.h>
46 #define TOUT_LOOP 100000
48 #define E1000_DEFAULT_PCI_PBA 0x00000030
49 #define E1000_DEFAULT_PCIE_PBA 0x000a0026
51 /* NIC specific static variables go here */
53 /* Intel i210 needs the DMA descriptor rings aligned to 128b */
54 #define E1000_BUFFER_ALIGN 128
57 * TODO(sjg@chromium.org): Even with driver model we share these buffers.
58 * Concurrent receiving on multiple active Ethernet devices will not work.
59 * Normally U-Boot does not support this anyway. To fix it in this driver,
60 * move these buffers and the tx/rx pointers to struct e1000_hw.
62 DEFINE_ALIGN_BUFFER(struct e1000_tx_desc, tx_base, 16, E1000_BUFFER_ALIGN);
63 DEFINE_ALIGN_BUFFER(struct e1000_rx_desc, rx_base, 16, E1000_BUFFER_ALIGN);
64 DEFINE_ALIGN_BUFFER(unsigned char, packet, 4096, E1000_BUFFER_ALIGN);
67 static int rx_tail, rx_last;
68 static int num_cards; /* Number of E1000 devices seen so far */
70 static struct pci_device_id e1000_supported[] = {
71 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82542) },
72 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_FIBER) },
73 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_COPPER) },
74 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_COPPER) },
75 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_FIBER) },
76 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_COPPER) },
77 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_LOM) },
78 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM) },
79 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_COPPER) },
80 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545GM_COPPER) },
81 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_COPPER) },
82 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_FIBER) },
83 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_FIBER) },
84 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_COPPER) },
85 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM_LOM) },
86 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541ER) },
87 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541GI_LF) },
89 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_COPPER) },
90 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_FIBER) },
91 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES) },
92 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER) },
93 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571PT_QUAD_COPPER) },
94 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_FIBER) },
95 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER_LOWPROFILE) },
96 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_DUAL) },
97 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_QUAD) },
98 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_COPPER) },
99 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_FIBER) },
100 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_SERDES) },
101 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI) },
102 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E) },
103 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E_IAMT) },
104 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573L) },
105 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82574L) },
106 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_QUAD_COPPER_KSP3) },
107 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_DPT) },
108 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_DPT) },
109 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_SPT) },
110 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_SPT) },
111 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED) },
112 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED) },
113 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER) },
114 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_COPPER) },
115 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS) },
116 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES) },
117 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS) },
118 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_1000BASEKX) },
123 /* Function forward declarations */
124 static int e1000_setup_link(struct e1000_hw *hw);
125 static int e1000_setup_fiber_link(struct e1000_hw *hw);
126 static int e1000_setup_copper_link(struct e1000_hw *hw);
127 static int e1000_phy_setup_autoneg(struct e1000_hw *hw);
128 static void e1000_config_collision_dist(struct e1000_hw *hw);
129 static int e1000_config_mac_to_phy(struct e1000_hw *hw);
130 static int e1000_config_fc_after_link_up(struct e1000_hw *hw);
131 static int e1000_check_for_link(struct e1000_hw *hw);
132 static int e1000_wait_autoneg(struct e1000_hw *hw);
133 static int e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t * speed,
135 static int e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
136 uint16_t * phy_data);
137 static int e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
139 static int32_t e1000_phy_hw_reset(struct e1000_hw *hw);
140 static int e1000_phy_reset(struct e1000_hw *hw);
141 static int e1000_detect_gig_phy(struct e1000_hw *hw);
142 static void e1000_set_media_type(struct e1000_hw *hw);
144 static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
145 static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
146 static int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
148 #ifndef CONFIG_E1000_NO_NVM
149 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
150 static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
151 static int32_t e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
154 /******************************************************************************
155 * Raises the EEPROM's clock input.
157 * hw - Struct containing variables accessed by shared code
158 * eecd - EECD's current value
159 *****************************************************************************/
160 void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
162 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
163 * wait 50 microseconds.
165 *eecd = *eecd | E1000_EECD_SK;
166 E1000_WRITE_REG(hw, EECD, *eecd);
167 E1000_WRITE_FLUSH(hw);
171 /******************************************************************************
172 * Lowers the EEPROM's clock input.
174 * hw - Struct containing variables accessed by shared code
175 * eecd - EECD's current value
176 *****************************************************************************/
177 void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
179 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
180 * wait 50 microseconds.
182 *eecd = *eecd & ~E1000_EECD_SK;
183 E1000_WRITE_REG(hw, EECD, *eecd);
184 E1000_WRITE_FLUSH(hw);
188 /******************************************************************************
189 * Shift data bits out to the EEPROM.
191 * hw - Struct containing variables accessed by shared code
192 * data - data to send to the EEPROM
193 * count - number of bits to shift out
194 *****************************************************************************/
196 e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count)
201 /* We need to shift "count" bits out to the EEPROM. So, value in the
202 * "data" parameter will be shifted out to the EEPROM one bit at a time.
203 * In order to do this, "data" must be broken down into bits.
205 mask = 0x01 << (count - 1);
206 eecd = E1000_READ_REG(hw, EECD);
207 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
209 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
210 * and then raising and then lowering the clock (the SK bit controls
211 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
212 * by setting "DI" to "0" and then raising and then lowering the clock.
214 eecd &= ~E1000_EECD_DI;
217 eecd |= E1000_EECD_DI;
219 E1000_WRITE_REG(hw, EECD, eecd);
220 E1000_WRITE_FLUSH(hw);
224 e1000_raise_ee_clk(hw, &eecd);
225 e1000_lower_ee_clk(hw, &eecd);
231 /* We leave the "DI" bit set to "0" when we leave this routine. */
232 eecd &= ~E1000_EECD_DI;
233 E1000_WRITE_REG(hw, EECD, eecd);
236 /******************************************************************************
237 * Shift data bits in from the EEPROM
239 * hw - Struct containing variables accessed by shared code
240 *****************************************************************************/
242 e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count)
248 /* In order to read a register from the EEPROM, we need to shift 'count'
249 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
250 * input to the EEPROM (setting the SK bit), and then reading the
251 * value of the "DO" bit. During this "shifting in" process the
252 * "DI" bit should always be clear.
255 eecd = E1000_READ_REG(hw, EECD);
257 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
260 for (i = 0; i < count; i++) {
262 e1000_raise_ee_clk(hw, &eecd);
264 eecd = E1000_READ_REG(hw, EECD);
266 eecd &= ~(E1000_EECD_DI);
267 if (eecd & E1000_EECD_DO)
270 e1000_lower_ee_clk(hw, &eecd);
276 /******************************************************************************
277 * Returns EEPROM to a "standby" state
279 * hw - Struct containing variables accessed by shared code
280 *****************************************************************************/
281 void e1000_standby_eeprom(struct e1000_hw *hw)
283 struct e1000_eeprom_info *eeprom = &hw->eeprom;
286 eecd = E1000_READ_REG(hw, EECD);
288 if (eeprom->type == e1000_eeprom_microwire) {
289 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
290 E1000_WRITE_REG(hw, EECD, eecd);
291 E1000_WRITE_FLUSH(hw);
292 udelay(eeprom->delay_usec);
295 eecd |= E1000_EECD_SK;
296 E1000_WRITE_REG(hw, EECD, eecd);
297 E1000_WRITE_FLUSH(hw);
298 udelay(eeprom->delay_usec);
301 eecd |= E1000_EECD_CS;
302 E1000_WRITE_REG(hw, EECD, eecd);
303 E1000_WRITE_FLUSH(hw);
304 udelay(eeprom->delay_usec);
307 eecd &= ~E1000_EECD_SK;
308 E1000_WRITE_REG(hw, EECD, eecd);
309 E1000_WRITE_FLUSH(hw);
310 udelay(eeprom->delay_usec);
311 } else if (eeprom->type == e1000_eeprom_spi) {
312 /* Toggle CS to flush commands */
313 eecd |= E1000_EECD_CS;
314 E1000_WRITE_REG(hw, EECD, eecd);
315 E1000_WRITE_FLUSH(hw);
316 udelay(eeprom->delay_usec);
317 eecd &= ~E1000_EECD_CS;
318 E1000_WRITE_REG(hw, EECD, eecd);
319 E1000_WRITE_FLUSH(hw);
320 udelay(eeprom->delay_usec);
324 /***************************************************************************
325 * Description: Determines if the onboard NVM is FLASH or EEPROM.
327 * hw - Struct containing variables accessed by shared code
328 ****************************************************************************/
329 static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
335 if (hw->mac_type == e1000_ich8lan)
338 if (hw->mac_type == e1000_82573 || hw->mac_type == e1000_82574) {
339 eecd = E1000_READ_REG(hw, EECD);
341 /* Isolate bits 15 & 16 */
342 eecd = ((eecd >> 15) & 0x03);
344 /* If both bits are set, device is Flash type */
351 /******************************************************************************
352 * Prepares EEPROM for access
354 * hw - Struct containing variables accessed by shared code
356 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
357 * function should be called before issuing a command to the EEPROM.
358 *****************************************************************************/
359 int32_t e1000_acquire_eeprom(struct e1000_hw *hw)
361 struct e1000_eeprom_info *eeprom = &hw->eeprom;
362 uint32_t eecd, i = 0;
366 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
367 return -E1000_ERR_SWFW_SYNC;
368 eecd = E1000_READ_REG(hw, EECD);
370 if (hw->mac_type != e1000_82573 && hw->mac_type != e1000_82574) {
371 /* Request EEPROM Access */
372 if (hw->mac_type > e1000_82544) {
373 eecd |= E1000_EECD_REQ;
374 E1000_WRITE_REG(hw, EECD, eecd);
375 eecd = E1000_READ_REG(hw, EECD);
376 while ((!(eecd & E1000_EECD_GNT)) &&
377 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
380 eecd = E1000_READ_REG(hw, EECD);
382 if (!(eecd & E1000_EECD_GNT)) {
383 eecd &= ~E1000_EECD_REQ;
384 E1000_WRITE_REG(hw, EECD, eecd);
385 DEBUGOUT("Could not acquire EEPROM grant\n");
386 return -E1000_ERR_EEPROM;
391 /* Setup EEPROM for Read/Write */
393 if (eeprom->type == e1000_eeprom_microwire) {
394 /* Clear SK and DI */
395 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
396 E1000_WRITE_REG(hw, EECD, eecd);
399 eecd |= E1000_EECD_CS;
400 E1000_WRITE_REG(hw, EECD, eecd);
401 } else if (eeprom->type == e1000_eeprom_spi) {
402 /* Clear SK and CS */
403 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
404 E1000_WRITE_REG(hw, EECD, eecd);
408 return E1000_SUCCESS;
411 /******************************************************************************
412 * Sets up eeprom variables in the hw struct. Must be called after mac_type
413 * is configured. Additionally, if this is ICH8, the flash controller GbE
414 * registers must be mapped, or this will crash.
416 * hw - Struct containing variables accessed by shared code
417 *****************************************************************************/
418 static int32_t e1000_init_eeprom_params(struct e1000_hw *hw)
420 struct e1000_eeprom_info *eeprom = &hw->eeprom;
422 int32_t ret_val = E1000_SUCCESS;
423 uint16_t eeprom_size;
425 if (hw->mac_type == e1000_igb)
426 eecd = E1000_READ_REG(hw, I210_EECD);
428 eecd = E1000_READ_REG(hw, EECD);
432 switch (hw->mac_type) {
433 case e1000_82542_rev2_0:
434 case e1000_82542_rev2_1:
437 eeprom->type = e1000_eeprom_microwire;
438 eeprom->word_size = 64;
439 eeprom->opcode_bits = 3;
440 eeprom->address_bits = 6;
441 eeprom->delay_usec = 50;
442 eeprom->use_eerd = false;
443 eeprom->use_eewr = false;
447 case e1000_82545_rev_3:
449 case e1000_82546_rev_3:
450 eeprom->type = e1000_eeprom_microwire;
451 eeprom->opcode_bits = 3;
452 eeprom->delay_usec = 50;
453 if (eecd & E1000_EECD_SIZE) {
454 eeprom->word_size = 256;
455 eeprom->address_bits = 8;
457 eeprom->word_size = 64;
458 eeprom->address_bits = 6;
460 eeprom->use_eerd = false;
461 eeprom->use_eewr = false;
464 case e1000_82541_rev_2:
466 case e1000_82547_rev_2:
467 if (eecd & E1000_EECD_TYPE) {
468 eeprom->type = e1000_eeprom_spi;
469 eeprom->opcode_bits = 8;
470 eeprom->delay_usec = 1;
471 if (eecd & E1000_EECD_ADDR_BITS) {
472 eeprom->page_size = 32;
473 eeprom->address_bits = 16;
475 eeprom->page_size = 8;
476 eeprom->address_bits = 8;
479 eeprom->type = e1000_eeprom_microwire;
480 eeprom->opcode_bits = 3;
481 eeprom->delay_usec = 50;
482 if (eecd & E1000_EECD_ADDR_BITS) {
483 eeprom->word_size = 256;
484 eeprom->address_bits = 8;
486 eeprom->word_size = 64;
487 eeprom->address_bits = 6;
490 eeprom->use_eerd = false;
491 eeprom->use_eewr = false;
495 eeprom->type = e1000_eeprom_spi;
496 eeprom->opcode_bits = 8;
497 eeprom->delay_usec = 1;
498 if (eecd & E1000_EECD_ADDR_BITS) {
499 eeprom->page_size = 32;
500 eeprom->address_bits = 16;
502 eeprom->page_size = 8;
503 eeprom->address_bits = 8;
505 eeprom->use_eerd = false;
506 eeprom->use_eewr = false;
510 eeprom->type = e1000_eeprom_spi;
511 eeprom->opcode_bits = 8;
512 eeprom->delay_usec = 1;
513 if (eecd & E1000_EECD_ADDR_BITS) {
514 eeprom->page_size = 32;
515 eeprom->address_bits = 16;
517 eeprom->page_size = 8;
518 eeprom->address_bits = 8;
520 if (e1000_is_onboard_nvm_eeprom(hw) == false) {
521 eeprom->use_eerd = true;
522 eeprom->use_eewr = true;
524 eeprom->type = e1000_eeprom_flash;
525 eeprom->word_size = 2048;
527 /* Ensure that the Autonomous FLASH update bit is cleared due to
528 * Flash update issue on parts which use a FLASH for NVM. */
529 eecd &= ~E1000_EECD_AUPDEN;
530 E1000_WRITE_REG(hw, EECD, eecd);
533 case e1000_80003es2lan:
534 eeprom->type = e1000_eeprom_spi;
535 eeprom->opcode_bits = 8;
536 eeprom->delay_usec = 1;
537 if (eecd & E1000_EECD_ADDR_BITS) {
538 eeprom->page_size = 32;
539 eeprom->address_bits = 16;
541 eeprom->page_size = 8;
542 eeprom->address_bits = 8;
544 eeprom->use_eerd = true;
545 eeprom->use_eewr = false;
548 /* i210 has 4k of iNVM mapped as EEPROM */
549 eeprom->type = e1000_eeprom_invm;
550 eeprom->opcode_bits = 8;
551 eeprom->delay_usec = 1;
552 eeprom->page_size = 32;
553 eeprom->address_bits = 16;
554 eeprom->use_eerd = true;
555 eeprom->use_eewr = false;
561 if (eeprom->type == e1000_eeprom_spi ||
562 eeprom->type == e1000_eeprom_invm) {
563 /* eeprom_size will be an enum [0..8] that maps
564 * to eeprom sizes 128B to
565 * 32KB (incremented by powers of 2).
567 if (hw->mac_type <= e1000_82547_rev_2) {
568 /* Set to default value for initial eeprom read. */
569 eeprom->word_size = 64;
570 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1,
574 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK)
575 >> EEPROM_SIZE_SHIFT;
576 /* 256B eeprom size was not supported in earlier
577 * hardware, so we bump eeprom_size up one to
578 * ensure that "1" (which maps to 256B) is never
579 * the result used in the shifting logic below. */
583 eeprom_size = (uint16_t)((eecd &
584 E1000_EECD_SIZE_EX_MASK) >>
585 E1000_EECD_SIZE_EX_SHIFT);
588 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
593 /******************************************************************************
594 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
596 * hw - Struct containing variables accessed by shared code
597 *****************************************************************************/
599 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
601 uint32_t attempts = 100000;
603 int32_t done = E1000_ERR_EEPROM;
605 for (i = 0; i < attempts; i++) {
606 if (eerd == E1000_EEPROM_POLL_READ) {
607 if (hw->mac_type == e1000_igb)
608 reg = E1000_READ_REG(hw, I210_EERD);
610 reg = E1000_READ_REG(hw, EERD);
612 if (hw->mac_type == e1000_igb)
613 reg = E1000_READ_REG(hw, I210_EEWR);
615 reg = E1000_READ_REG(hw, EEWR);
618 if (reg & E1000_EEPROM_RW_REG_DONE) {
619 done = E1000_SUCCESS;
628 /******************************************************************************
629 * Reads a 16 bit word from the EEPROM using the EERD register.
631 * hw - Struct containing variables accessed by shared code
632 * offset - offset of word in the EEPROM to read
633 * data - word read from the EEPROM
634 * words - number of words to read
635 *****************************************************************************/
637 e1000_read_eeprom_eerd(struct e1000_hw *hw,
642 uint32_t i, eerd = 0;
645 for (i = 0; i < words; i++) {
646 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
647 E1000_EEPROM_RW_REG_START;
649 if (hw->mac_type == e1000_igb)
650 E1000_WRITE_REG(hw, I210_EERD, eerd);
652 E1000_WRITE_REG(hw, EERD, eerd);
654 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
659 if (hw->mac_type == e1000_igb) {
660 data[i] = (E1000_READ_REG(hw, I210_EERD) >>
661 E1000_EEPROM_RW_REG_DATA);
663 data[i] = (E1000_READ_REG(hw, EERD) >>
664 E1000_EEPROM_RW_REG_DATA);
672 void e1000_release_eeprom(struct e1000_hw *hw)
678 eecd = E1000_READ_REG(hw, EECD);
680 if (hw->eeprom.type == e1000_eeprom_spi) {
681 eecd |= E1000_EECD_CS; /* Pull CS high */
682 eecd &= ~E1000_EECD_SK; /* Lower SCK */
684 E1000_WRITE_REG(hw, EECD, eecd);
686 udelay(hw->eeprom.delay_usec);
687 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
690 /* CS on Microwire is active-high */
691 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
693 E1000_WRITE_REG(hw, EECD, eecd);
695 /* Rising edge of clock */
696 eecd |= E1000_EECD_SK;
697 E1000_WRITE_REG(hw, EECD, eecd);
698 E1000_WRITE_FLUSH(hw);
699 udelay(hw->eeprom.delay_usec);
701 /* Falling edge of clock */
702 eecd &= ~E1000_EECD_SK;
703 E1000_WRITE_REG(hw, EECD, eecd);
704 E1000_WRITE_FLUSH(hw);
705 udelay(hw->eeprom.delay_usec);
708 /* Stop requesting EEPROM access */
709 if (hw->mac_type > e1000_82544) {
710 eecd &= ~E1000_EECD_REQ;
711 E1000_WRITE_REG(hw, EECD, eecd);
714 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
717 /******************************************************************************
718 * Reads a 16 bit word from the EEPROM.
720 * hw - Struct containing variables accessed by shared code
721 *****************************************************************************/
723 e1000_spi_eeprom_ready(struct e1000_hw *hw)
725 uint16_t retry_count = 0;
726 uint8_t spi_stat_reg;
730 /* Read "Status Register" repeatedly until the LSB is cleared. The
731 * EEPROM will signal that the command has been completed by clearing
732 * bit 0 of the internal status register. If it's not cleared within
733 * 5 milliseconds, then error out.
737 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
738 hw->eeprom.opcode_bits);
739 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
740 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
746 e1000_standby_eeprom(hw);
747 } while (retry_count < EEPROM_MAX_RETRY_SPI);
749 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
750 * only 0-5mSec on 5V devices)
752 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
753 DEBUGOUT("SPI EEPROM Status error\n");
754 return -E1000_ERR_EEPROM;
757 return E1000_SUCCESS;
760 /******************************************************************************
761 * Reads a 16 bit word from the EEPROM.
763 * hw - Struct containing variables accessed by shared code
764 * offset - offset of word in the EEPROM to read
765 * data - word read from the EEPROM
766 *****************************************************************************/
768 e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
769 uint16_t words, uint16_t *data)
771 struct e1000_eeprom_info *eeprom = &hw->eeprom;
776 /* If eeprom is not yet detected, do so now */
777 if (eeprom->word_size == 0)
778 e1000_init_eeprom_params(hw);
780 /* A check for invalid values: offset too large, too many words,
781 * and not enough words.
783 if ((offset >= eeprom->word_size) ||
784 (words > eeprom->word_size - offset) ||
786 DEBUGOUT("\"words\" parameter out of bounds."
787 "Words = %d, size = %d\n", offset, eeprom->word_size);
788 return -E1000_ERR_EEPROM;
791 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
792 * directly. In this case, we need to acquire the EEPROM so that
793 * FW or other port software does not interrupt.
795 if (e1000_is_onboard_nvm_eeprom(hw) == true &&
796 hw->eeprom.use_eerd == false) {
798 /* Prepare the EEPROM for bit-bang reading */
799 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
800 return -E1000_ERR_EEPROM;
803 /* Eerd register EEPROM access requires no eeprom aquire/release */
804 if (eeprom->use_eerd == true)
805 return e1000_read_eeprom_eerd(hw, offset, words, data);
807 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
808 * acquired the EEPROM at this point, so any returns should relase it */
809 if (eeprom->type == e1000_eeprom_spi) {
811 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
813 if (e1000_spi_eeprom_ready(hw)) {
814 e1000_release_eeprom(hw);
815 return -E1000_ERR_EEPROM;
818 e1000_standby_eeprom(hw);
820 /* Some SPI eeproms use the 8th address bit embedded in
822 if ((eeprom->address_bits == 8) && (offset >= 128))
823 read_opcode |= EEPROM_A8_OPCODE_SPI;
825 /* Send the READ command (opcode + addr) */
826 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
827 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2),
828 eeprom->address_bits);
830 /* Read the data. The address of the eeprom internally
831 * increments with each byte (spi) being read, saving on the
832 * overhead of eeprom setup and tear-down. The address
833 * counter will roll over if reading beyond the size of
834 * the eeprom, thus allowing the entire memory to be read
835 * starting from any offset. */
836 for (i = 0; i < words; i++) {
837 word_in = e1000_shift_in_ee_bits(hw, 16);
838 data[i] = (word_in >> 8) | (word_in << 8);
840 } else if (eeprom->type == e1000_eeprom_microwire) {
841 for (i = 0; i < words; i++) {
842 /* Send the READ command (opcode + addr) */
843 e1000_shift_out_ee_bits(hw,
844 EEPROM_READ_OPCODE_MICROWIRE,
845 eeprom->opcode_bits);
846 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
847 eeprom->address_bits);
849 /* Read the data. For microwire, each word requires
850 * the overhead of eeprom setup and tear-down. */
851 data[i] = e1000_shift_in_ee_bits(hw, 16);
852 e1000_standby_eeprom(hw);
856 /* End this read operation */
857 e1000_release_eeprom(hw);
859 return E1000_SUCCESS;
862 /******************************************************************************
863 * e1000_write_eeprom_srwr - Write to Shadow Ram using EEWR
864 * @hw: pointer to the HW structure
865 * @offset: offset within the Shadow Ram to be written to
866 * @words: number of words to write
867 * @data: 16 bit word(s) to be written to the Shadow Ram
869 * Writes data to Shadow Ram at offset using EEWR register.
871 * If e1000_update_eeprom_checksum_i210 is not called after this function, the
872 * Shadow Ram will most likely contain an invalid checksum.
873 *****************************************************************************/
874 static int32_t e1000_write_eeprom_srwr(struct e1000_hw *hw, uint16_t offset,
875 uint16_t words, uint16_t *data)
877 struct e1000_eeprom_info *eeprom = &hw->eeprom;
878 uint32_t i, k, eewr = 0;
879 uint32_t attempts = 100000;
882 /* A check for invalid values: offset too large, too many words,
883 * too many words for the offset, and not enough words.
885 if ((offset >= eeprom->word_size) ||
886 (words > (eeprom->word_size - offset)) || (words == 0)) {
887 DEBUGOUT("nvm parameter(s) out of bounds\n");
888 ret_val = -E1000_ERR_EEPROM;
892 for (i = 0; i < words; i++) {
893 eewr = ((offset + i) << E1000_EEPROM_RW_ADDR_SHIFT)
894 | (data[i] << E1000_EEPROM_RW_REG_DATA) |
895 E1000_EEPROM_RW_REG_START;
897 E1000_WRITE_REG(hw, I210_EEWR, eewr);
899 for (k = 0; k < attempts; k++) {
900 if (E1000_EEPROM_RW_REG_DONE &
901 E1000_READ_REG(hw, I210_EEWR)) {
909 DEBUGOUT("Shadow RAM write EEWR timed out\n");
918 /******************************************************************************
919 * e1000_pool_flash_update_done_i210 - Pool FLUDONE status.
920 * @hw: pointer to the HW structure
922 *****************************************************************************/
923 static int32_t e1000_pool_flash_update_done_i210(struct e1000_hw *hw)
925 int32_t ret_val = -E1000_ERR_EEPROM;
928 for (i = 0; i < E1000_FLUDONE_ATTEMPTS; i++) {
929 reg = E1000_READ_REG(hw, EECD);
930 if (reg & E1000_EECD_FLUDONE_I210) {
940 /******************************************************************************
941 * e1000_update_flash_i210 - Commit EEPROM to the flash
942 * @hw: pointer to the HW structure
944 *****************************************************************************/
945 static int32_t e1000_update_flash_i210(struct e1000_hw *hw)
950 ret_val = e1000_pool_flash_update_done_i210(hw);
951 if (ret_val == -E1000_ERR_EEPROM) {
952 DEBUGOUT("Flash update time out\n");
956 flup = E1000_READ_REG(hw, EECD) | E1000_EECD_FLUPD_I210;
957 E1000_WRITE_REG(hw, EECD, flup);
959 ret_val = e1000_pool_flash_update_done_i210(hw);
961 DEBUGOUT("Flash update time out\n");
963 DEBUGOUT("Flash update complete\n");
969 /******************************************************************************
970 * e1000_update_eeprom_checksum_i210 - Update EEPROM checksum
971 * @hw: pointer to the HW structure
973 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
974 * up to the checksum. Then calculates the EEPROM checksum and writes the
975 * value to the EEPROM. Next commit EEPROM data onto the Flash.
976 *****************************************************************************/
977 static int32_t e1000_update_eeprom_checksum_i210(struct e1000_hw *hw)
980 uint16_t checksum = 0;
981 uint16_t i, nvm_data;
983 /* Read the first word from the EEPROM. If this times out or fails, do
984 * not continue or we could be in for a very long wait while every
987 ret_val = e1000_read_eeprom_eerd(hw, 0, 1, &nvm_data);
989 DEBUGOUT("EEPROM read failed\n");
993 if (!(e1000_get_hw_eeprom_semaphore(hw))) {
994 /* Do not use hw->nvm.ops.write, hw->nvm.ops.read
995 * because we do not want to take the synchronization
996 * semaphores twice here.
999 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
1000 ret_val = e1000_read_eeprom_eerd(hw, i, 1, &nvm_data);
1002 e1000_put_hw_eeprom_semaphore(hw);
1003 DEBUGOUT("EEPROM Read Error while updating checksum.\n");
1006 checksum += nvm_data;
1008 checksum = (uint16_t)EEPROM_SUM - checksum;
1009 ret_val = e1000_write_eeprom_srwr(hw, EEPROM_CHECKSUM_REG, 1,
1012 e1000_put_hw_eeprom_semaphore(hw);
1013 DEBUGOUT("EEPROM Write Error while updating checksum.\n");
1017 e1000_put_hw_eeprom_semaphore(hw);
1019 ret_val = e1000_update_flash_i210(hw);
1021 ret_val = -E1000_ERR_SWFW_SYNC;
1028 /******************************************************************************
1029 * Verifies that the EEPROM has a valid checksum
1031 * hw - Struct containing variables accessed by shared code
1033 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
1034 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
1036 *****************************************************************************/
1037 static int e1000_validate_eeprom_checksum(struct e1000_hw *hw)
1039 uint16_t i, checksum, checksum_reg, *buf;
1043 /* Allocate a temporary buffer */
1044 buf = malloc(sizeof(buf[0]) * (EEPROM_CHECKSUM_REG + 1));
1046 E1000_ERR(hw, "Unable to allocate EEPROM buffer!\n");
1047 return -E1000_ERR_EEPROM;
1050 /* Read the EEPROM */
1051 if (e1000_read_eeprom(hw, 0, EEPROM_CHECKSUM_REG + 1, buf) < 0) {
1052 E1000_ERR(hw, "Unable to read EEPROM!\n");
1053 return -E1000_ERR_EEPROM;
1056 /* Compute the checksum */
1058 for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
1060 checksum = ((uint16_t)EEPROM_SUM) - checksum;
1061 checksum_reg = buf[i];
1064 if (checksum == checksum_reg)
1067 /* Hrm, verification failed, print an error */
1068 E1000_ERR(hw, "EEPROM checksum is incorrect!\n");
1069 E1000_ERR(hw, " ...register was 0x%04hx, calculated 0x%04hx\n",
1070 checksum_reg, checksum);
1072 return -E1000_ERR_EEPROM;
1074 #endif /* CONFIG_E1000_NO_NVM */
1076 /*****************************************************************************
1077 * Set PHY to class A mode
1078 * Assumes the following operations will follow to enable the new class mode.
1079 * 1. Do a PHY soft reset
1080 * 2. Restart auto-negotiation or force link.
1082 * hw - Struct containing variables accessed by shared code
1083 ****************************************************************************/
1085 e1000_set_phy_mode(struct e1000_hw *hw)
1087 #ifndef CONFIG_E1000_NO_NVM
1089 uint16_t eeprom_data;
1093 if ((hw->mac_type == e1000_82545_rev_3) &&
1094 (hw->media_type == e1000_media_type_copper)) {
1095 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD,
1100 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
1101 (eeprom_data & EEPROM_PHY_CLASS_A)) {
1102 ret_val = e1000_write_phy_reg(hw,
1103 M88E1000_PHY_PAGE_SELECT, 0x000B);
1106 ret_val = e1000_write_phy_reg(hw,
1107 M88E1000_PHY_GEN_CONTROL, 0x8104);
1111 hw->phy_reset_disable = false;
1115 return E1000_SUCCESS;
1118 #ifndef CONFIG_E1000_NO_NVM
1119 /***************************************************************************
1121 * Obtaining software semaphore bit (SMBI) before resetting PHY.
1123 * hw: Struct containing variables accessed by shared code
1125 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
1126 * E1000_SUCCESS at any other case.
1128 ***************************************************************************/
1130 e1000_get_software_semaphore(struct e1000_hw *hw)
1132 int32_t timeout = hw->eeprom.word_size + 1;
1137 if (hw->mac_type != e1000_80003es2lan && hw->mac_type != e1000_igb)
1138 return E1000_SUCCESS;
1141 swsm = E1000_READ_REG(hw, SWSM);
1142 /* If SMBI bit cleared, it is now set and we hold
1144 if (!(swsm & E1000_SWSM_SMBI))
1151 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
1152 return -E1000_ERR_RESET;
1155 return E1000_SUCCESS;
1159 /***************************************************************************
1160 * This function clears HW semaphore bits.
1162 * hw: Struct containing variables accessed by shared code
1166 ***************************************************************************/
1168 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
1170 #ifndef CONFIG_E1000_NO_NVM
1175 if (!hw->eeprom_semaphore_present)
1178 swsm = E1000_READ_REG(hw, SWSM);
1179 if (hw->mac_type == e1000_80003es2lan || hw->mac_type == e1000_igb) {
1180 /* Release both semaphores. */
1181 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1183 swsm &= ~(E1000_SWSM_SWESMBI);
1184 E1000_WRITE_REG(hw, SWSM, swsm);
1188 /***************************************************************************
1190 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
1191 * adapter or Eeprom access.
1193 * hw: Struct containing variables accessed by shared code
1195 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
1196 * E1000_SUCCESS at any other case.
1198 ***************************************************************************/
1200 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
1202 #ifndef CONFIG_E1000_NO_NVM
1208 if (!hw->eeprom_semaphore_present)
1209 return E1000_SUCCESS;
1211 if (hw->mac_type == e1000_80003es2lan || hw->mac_type == e1000_igb) {
1212 /* Get the SW semaphore. */
1213 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
1214 return -E1000_ERR_EEPROM;
1217 /* Get the FW semaphore. */
1218 timeout = hw->eeprom.word_size + 1;
1220 swsm = E1000_READ_REG(hw, SWSM);
1221 swsm |= E1000_SWSM_SWESMBI;
1222 E1000_WRITE_REG(hw, SWSM, swsm);
1223 /* if we managed to set the bit we got the semaphore. */
1224 swsm = E1000_READ_REG(hw, SWSM);
1225 if (swsm & E1000_SWSM_SWESMBI)
1233 /* Release semaphores */
1234 e1000_put_hw_eeprom_semaphore(hw);
1235 DEBUGOUT("Driver can't access the Eeprom - "
1236 "SWESMBI bit is set.\n");
1237 return -E1000_ERR_EEPROM;
1240 return E1000_SUCCESS;
1243 /* Take ownership of the PHY */
1245 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
1247 uint32_t swfw_sync = 0;
1248 uint32_t swmask = mask;
1249 uint32_t fwmask = mask << 16;
1250 int32_t timeout = 200;
1254 if (e1000_get_hw_eeprom_semaphore(hw))
1255 return -E1000_ERR_SWFW_SYNC;
1257 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
1258 if (!(swfw_sync & (fwmask | swmask)))
1261 /* firmware currently using resource (fwmask) */
1262 /* or other software thread currently using resource (swmask) */
1263 e1000_put_hw_eeprom_semaphore(hw);
1269 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
1270 return -E1000_ERR_SWFW_SYNC;
1273 swfw_sync |= swmask;
1274 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
1276 e1000_put_hw_eeprom_semaphore(hw);
1277 return E1000_SUCCESS;
1280 static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
1282 uint32_t swfw_sync = 0;
1285 while (e1000_get_hw_eeprom_semaphore(hw))
1288 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
1290 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
1292 e1000_put_hw_eeprom_semaphore(hw);
1295 static bool e1000_is_second_port(struct e1000_hw *hw)
1297 switch (hw->mac_type) {
1298 case e1000_80003es2lan:
1301 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
1309 #ifndef CONFIG_E1000_NO_NVM
1310 /******************************************************************************
1311 * Reads the adapter's MAC address from the EEPROM
1313 * hw - Struct containing variables accessed by shared code
1314 * enetaddr - buffering where the MAC address will be stored
1315 *****************************************************************************/
1316 static int e1000_read_mac_addr_from_eeprom(struct e1000_hw *hw,
1317 unsigned char enetaddr[6])
1320 uint16_t eeprom_data;
1323 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
1325 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
1326 DEBUGOUT("EEPROM Read Error\n");
1327 return -E1000_ERR_EEPROM;
1329 enetaddr[i] = eeprom_data & 0xff;
1330 enetaddr[i + 1] = (eeprom_data >> 8) & 0xff;
1336 /******************************************************************************
1337 * Reads the adapter's MAC address from the RAL/RAH registers
1339 * hw - Struct containing variables accessed by shared code
1340 * enetaddr - buffering where the MAC address will be stored
1341 *****************************************************************************/
1342 static int e1000_read_mac_addr_from_regs(struct e1000_hw *hw,
1343 unsigned char enetaddr[6])
1345 uint16_t offset, tmp;
1346 uint32_t reg_data = 0;
1349 if (hw->mac_type != e1000_igb)
1350 return -E1000_ERR_MAC_TYPE;
1352 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
1356 reg_data = E1000_READ_REG_ARRAY(hw, RA, 0);
1357 else if (offset == 1)
1359 else if (offset == 2)
1360 reg_data = E1000_READ_REG_ARRAY(hw, RA, 1);
1361 tmp = reg_data & 0xffff;
1363 enetaddr[i] = tmp & 0xff;
1364 enetaddr[i + 1] = (tmp >> 8) & 0xff;
1370 /******************************************************************************
1371 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
1372 * second function of dual function devices
1374 * hw - Struct containing variables accessed by shared code
1375 * enetaddr - buffering where the MAC address will be stored
1376 *****************************************************************************/
1377 static int e1000_read_mac_addr(struct e1000_hw *hw, unsigned char enetaddr[6])
1381 if (hw->mac_type == e1000_igb) {
1382 /* i210 preloads MAC address into RAL/RAH registers */
1383 ret_val = e1000_read_mac_addr_from_regs(hw, enetaddr);
1385 ret_val = e1000_read_mac_addr_from_eeprom(hw, enetaddr);
1390 /* Invert the last bit if this is the second device */
1391 if (e1000_is_second_port(hw))
1398 /******************************************************************************
1399 * Initializes receive address filters.
1401 * hw - Struct containing variables accessed by shared code
1403 * Places the MAC address in receive address register 0 and clears the rest
1404 * of the receive addresss registers. Clears the multicast table. Assumes
1405 * the receiver is in reset when the routine is called.
1406 *****************************************************************************/
1408 e1000_init_rx_addrs(struct e1000_hw *hw, unsigned char enetaddr[6])
1416 /* Setup the receive address. */
1417 DEBUGOUT("Programming MAC Address into RAR[0]\n");
1418 addr_low = (enetaddr[0] |
1419 (enetaddr[1] << 8) |
1420 (enetaddr[2] << 16) | (enetaddr[3] << 24));
1422 addr_high = (enetaddr[4] | (enetaddr[5] << 8) | E1000_RAH_AV);
1424 E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
1425 E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
1427 /* Zero out the other 15 receive addresses. */
1428 DEBUGOUT("Clearing RAR[1-15]\n");
1429 for (i = 1; i < E1000_RAR_ENTRIES; i++) {
1430 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
1431 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
1435 /******************************************************************************
1436 * Clears the VLAN filer table
1438 * hw - Struct containing variables accessed by shared code
1439 *****************************************************************************/
1441 e1000_clear_vfta(struct e1000_hw *hw)
1445 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
1446 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
1449 /******************************************************************************
1450 * Set the mac type member in the hw struct.
1452 * hw - Struct containing variables accessed by shared code
1453 *****************************************************************************/
1455 e1000_set_mac_type(struct e1000_hw *hw)
1459 switch (hw->device_id) {
1460 case E1000_DEV_ID_82542:
1461 switch (hw->revision_id) {
1462 case E1000_82542_2_0_REV_ID:
1463 hw->mac_type = e1000_82542_rev2_0;
1465 case E1000_82542_2_1_REV_ID:
1466 hw->mac_type = e1000_82542_rev2_1;
1469 /* Invalid 82542 revision ID */
1470 return -E1000_ERR_MAC_TYPE;
1473 case E1000_DEV_ID_82543GC_FIBER:
1474 case E1000_DEV_ID_82543GC_COPPER:
1475 hw->mac_type = e1000_82543;
1477 case E1000_DEV_ID_82544EI_COPPER:
1478 case E1000_DEV_ID_82544EI_FIBER:
1479 case E1000_DEV_ID_82544GC_COPPER:
1480 case E1000_DEV_ID_82544GC_LOM:
1481 hw->mac_type = e1000_82544;
1483 case E1000_DEV_ID_82540EM:
1484 case E1000_DEV_ID_82540EM_LOM:
1485 case E1000_DEV_ID_82540EP:
1486 case E1000_DEV_ID_82540EP_LOM:
1487 case E1000_DEV_ID_82540EP_LP:
1488 hw->mac_type = e1000_82540;
1490 case E1000_DEV_ID_82545EM_COPPER:
1491 case E1000_DEV_ID_82545EM_FIBER:
1492 hw->mac_type = e1000_82545;
1494 case E1000_DEV_ID_82545GM_COPPER:
1495 case E1000_DEV_ID_82545GM_FIBER:
1496 case E1000_DEV_ID_82545GM_SERDES:
1497 hw->mac_type = e1000_82545_rev_3;
1499 case E1000_DEV_ID_82546EB_COPPER:
1500 case E1000_DEV_ID_82546EB_FIBER:
1501 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1502 hw->mac_type = e1000_82546;
1504 case E1000_DEV_ID_82546GB_COPPER:
1505 case E1000_DEV_ID_82546GB_FIBER:
1506 case E1000_DEV_ID_82546GB_SERDES:
1507 case E1000_DEV_ID_82546GB_PCIE:
1508 case E1000_DEV_ID_82546GB_QUAD_COPPER:
1509 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1510 hw->mac_type = e1000_82546_rev_3;
1512 case E1000_DEV_ID_82541EI:
1513 case E1000_DEV_ID_82541EI_MOBILE:
1514 case E1000_DEV_ID_82541ER_LOM:
1515 hw->mac_type = e1000_82541;
1517 case E1000_DEV_ID_82541ER:
1518 case E1000_DEV_ID_82541GI:
1519 case E1000_DEV_ID_82541GI_LF:
1520 case E1000_DEV_ID_82541GI_MOBILE:
1521 hw->mac_type = e1000_82541_rev_2;
1523 case E1000_DEV_ID_82547EI:
1524 case E1000_DEV_ID_82547EI_MOBILE:
1525 hw->mac_type = e1000_82547;
1527 case E1000_DEV_ID_82547GI:
1528 hw->mac_type = e1000_82547_rev_2;
1530 case E1000_DEV_ID_82571EB_COPPER:
1531 case E1000_DEV_ID_82571EB_FIBER:
1532 case E1000_DEV_ID_82571EB_SERDES:
1533 case E1000_DEV_ID_82571EB_SERDES_DUAL:
1534 case E1000_DEV_ID_82571EB_SERDES_QUAD:
1535 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1536 case E1000_DEV_ID_82571PT_QUAD_COPPER:
1537 case E1000_DEV_ID_82571EB_QUAD_FIBER:
1538 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1539 hw->mac_type = e1000_82571;
1541 case E1000_DEV_ID_82572EI_COPPER:
1542 case E1000_DEV_ID_82572EI_FIBER:
1543 case E1000_DEV_ID_82572EI_SERDES:
1544 case E1000_DEV_ID_82572EI:
1545 hw->mac_type = e1000_82572;
1547 case E1000_DEV_ID_82573E:
1548 case E1000_DEV_ID_82573E_IAMT:
1549 case E1000_DEV_ID_82573L:
1550 hw->mac_type = e1000_82573;
1552 case E1000_DEV_ID_82574L:
1553 hw->mac_type = e1000_82574;
1555 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
1556 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
1557 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
1558 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
1559 hw->mac_type = e1000_80003es2lan;
1561 case E1000_DEV_ID_ICH8_IGP_M_AMT:
1562 case E1000_DEV_ID_ICH8_IGP_AMT:
1563 case E1000_DEV_ID_ICH8_IGP_C:
1564 case E1000_DEV_ID_ICH8_IFE:
1565 case E1000_DEV_ID_ICH8_IFE_GT:
1566 case E1000_DEV_ID_ICH8_IFE_G:
1567 case E1000_DEV_ID_ICH8_IGP_M:
1568 hw->mac_type = e1000_ich8lan;
1570 case PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED:
1571 case PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED:
1572 case PCI_DEVICE_ID_INTEL_I210_COPPER:
1573 case PCI_DEVICE_ID_INTEL_I211_COPPER:
1574 case PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS:
1575 case PCI_DEVICE_ID_INTEL_I210_SERDES:
1576 case PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS:
1577 case PCI_DEVICE_ID_INTEL_I210_1000BASEKX:
1578 hw->mac_type = e1000_igb;
1581 /* Should never have loaded on this device */
1582 return -E1000_ERR_MAC_TYPE;
1584 return E1000_SUCCESS;
1587 /******************************************************************************
1588 * Reset the transmit and receive units; mask and clear all interrupts.
1590 * hw - Struct containing variables accessed by shared code
1591 *****************************************************************************/
1593 e1000_reset_hw(struct e1000_hw *hw)
1603 /* get the correct pba value for both PCI and PCIe*/
1604 if (hw->mac_type < e1000_82571)
1605 pba = E1000_DEFAULT_PCI_PBA;
1607 pba = E1000_DEFAULT_PCIE_PBA;
1609 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
1610 if (hw->mac_type == e1000_82542_rev2_0) {
1611 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1612 dm_pci_write_config16(hw->pdev, PCI_COMMAND,
1613 hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1616 /* Clear interrupt mask to stop board from generating interrupts */
1617 DEBUGOUT("Masking off all interrupts\n");
1618 if (hw->mac_type == e1000_igb)
1619 E1000_WRITE_REG(hw, I210_IAM, 0);
1620 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1622 /* Disable the Transmit and Receive units. Then delay to allow
1623 * any pending transactions to complete before we hit the MAC with
1626 E1000_WRITE_REG(hw, RCTL, 0);
1627 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
1628 E1000_WRITE_FLUSH(hw);
1630 if (hw->mac_type == e1000_igb) {
1631 E1000_WRITE_REG(hw, RXPBS, I210_RXPBSIZE_DEFAULT);
1632 E1000_WRITE_REG(hw, TXPBS, I210_TXPBSIZE_DEFAULT);
1635 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
1636 hw->tbi_compatibility_on = false;
1638 /* Delay to allow any outstanding PCI transactions to complete before
1639 * resetting the device
1643 /* Issue a global reset to the MAC. This will reset the chip's
1644 * transmit, receive, DMA, and link units. It will not effect
1645 * the current PCI configuration. The global reset bit is self-
1646 * clearing, and should clear within a microsecond.
1648 DEBUGOUT("Issuing a global reset to MAC\n");
1649 ctrl = E1000_READ_REG(hw, CTRL);
1651 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
1653 /* Force a reload from the EEPROM if necessary */
1654 if (hw->mac_type == e1000_igb) {
1656 reg = E1000_READ_REG(hw, STATUS);
1657 if (reg & E1000_STATUS_PF_RST_DONE)
1658 DEBUGOUT("PF OK\n");
1659 reg = E1000_READ_REG(hw, I210_EECD);
1660 if (reg & E1000_EECD_AUTO_RD)
1661 DEBUGOUT("EEC OK\n");
1662 } else if (hw->mac_type < e1000_82540) {
1663 /* Wait for reset to complete */
1665 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1666 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1667 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1668 E1000_WRITE_FLUSH(hw);
1669 /* Wait for EEPROM reload */
1672 /* Wait for EEPROM reload (it happens automatically) */
1674 /* Dissable HW ARPs on ASF enabled adapters */
1675 manc = E1000_READ_REG(hw, MANC);
1676 manc &= ~(E1000_MANC_ARP_EN);
1677 E1000_WRITE_REG(hw, MANC, manc);
1680 /* Clear interrupt mask to stop board from generating interrupts */
1681 DEBUGOUT("Masking off all interrupts\n");
1682 if (hw->mac_type == e1000_igb)
1683 E1000_WRITE_REG(hw, I210_IAM, 0);
1684 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1686 /* Clear any pending interrupt events. */
1687 E1000_READ_REG(hw, ICR);
1689 /* If MWI was previously enabled, reenable it. */
1690 if (hw->mac_type == e1000_82542_rev2_0) {
1691 dm_pci_write_config16(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1693 if (hw->mac_type != e1000_igb)
1694 E1000_WRITE_REG(hw, PBA, pba);
1697 /******************************************************************************
1699 * Initialize a number of hardware-dependent bits
1701 * hw: Struct containing variables accessed by shared code
1703 * This function contains hardware limitation workarounds for PCI-E adapters
1705 *****************************************************************************/
1707 e1000_initialize_hardware_bits(struct e1000_hw *hw)
1709 if ((hw->mac_type >= e1000_82571) &&
1710 (!hw->initialize_hw_bits_disable)) {
1711 /* Settings common to all PCI-express silicon */
1712 uint32_t reg_ctrl, reg_ctrl_ext;
1713 uint32_t reg_tarc0, reg_tarc1;
1715 uint32_t reg_txdctl, reg_txdctl1;
1717 /* link autonegotiation/sync workarounds */
1718 reg_tarc0 = E1000_READ_REG(hw, TARC0);
1719 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
1721 /* Enable not-done TX descriptor counting */
1722 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
1723 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
1724 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
1726 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
1727 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
1728 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
1731 switch (hw->mac_type) {
1732 case e1000_igb: /* IGB is cool */
1736 /* Clear PHY TX compatible mode bits */
1737 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1738 reg_tarc1 &= ~((1 << 30)|(1 << 29));
1740 /* link autonegotiation/sync workarounds */
1741 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
1743 /* TX ring control fixes */
1744 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
1746 /* Multiple read bit is reversed polarity */
1747 reg_tctl = E1000_READ_REG(hw, TCTL);
1748 if (reg_tctl & E1000_TCTL_MULR)
1749 reg_tarc1 &= ~(1 << 28);
1751 reg_tarc1 |= (1 << 28);
1753 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1757 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1758 reg_ctrl_ext &= ~(1 << 23);
1759 reg_ctrl_ext |= (1 << 22);
1761 /* TX byte count fix */
1762 reg_ctrl = E1000_READ_REG(hw, CTRL);
1763 reg_ctrl &= ~(1 << 29);
1765 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1766 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
1768 case e1000_80003es2lan:
1769 /* improve small packet performace for fiber/serdes */
1770 if ((hw->media_type == e1000_media_type_fiber)
1771 || (hw->media_type ==
1772 e1000_media_type_internal_serdes)) {
1773 reg_tarc0 &= ~(1 << 20);
1776 /* Multiple read bit is reversed polarity */
1777 reg_tctl = E1000_READ_REG(hw, TCTL);
1778 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1779 if (reg_tctl & E1000_TCTL_MULR)
1780 reg_tarc1 &= ~(1 << 28);
1782 reg_tarc1 |= (1 << 28);
1784 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1787 /* Reduce concurrent DMA requests to 3 from 4 */
1788 if ((hw->revision_id < 3) ||
1789 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1790 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
1791 reg_tarc0 |= ((1 << 29)|(1 << 28));
1793 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1794 reg_ctrl_ext |= (1 << 22);
1795 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1797 /* workaround TX hang with TSO=on */
1798 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
1800 /* Multiple read bit is reversed polarity */
1801 reg_tctl = E1000_READ_REG(hw, TCTL);
1802 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1803 if (reg_tctl & E1000_TCTL_MULR)
1804 reg_tarc1 &= ~(1 << 28);
1806 reg_tarc1 |= (1 << 28);
1808 /* workaround TX hang with TSO=on */
1809 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
1811 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1817 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
1821 /******************************************************************************
1822 * Performs basic configuration of the adapter.
1824 * hw - Struct containing variables accessed by shared code
1826 * Assumes that the controller has previously been reset and is in a
1827 * post-reset uninitialized state. Initializes the receive address registers,
1828 * multicast table, and VLAN filter table. Calls routines to setup link
1829 * configuration and flow control settings. Clears all on-chip counters. Leaves
1830 * the transmit and receive units disabled and uninitialized.
1831 *****************************************************************************/
1833 e1000_init_hw(struct e1000_hw *hw, unsigned char enetaddr[6])
1838 uint16_t pcix_cmd_word;
1839 uint16_t pcix_stat_hi_word;
1841 uint16_t stat_mmrbc;
1846 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
1847 if ((hw->mac_type == e1000_ich8lan) &&
1848 ((hw->revision_id < 3) ||
1849 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1850 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
1851 reg_data = E1000_READ_REG(hw, STATUS);
1852 reg_data &= ~0x80000000;
1853 E1000_WRITE_REG(hw, STATUS, reg_data);
1855 /* Do not need initialize Identification LED */
1857 /* Set the media type and TBI compatibility */
1858 e1000_set_media_type(hw);
1860 /* Must be called after e1000_set_media_type
1861 * because media_type is used */
1862 e1000_initialize_hardware_bits(hw);
1864 /* Disabling VLAN filtering. */
1865 DEBUGOUT("Initializing the IEEE VLAN\n");
1866 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
1867 if (hw->mac_type != e1000_ich8lan) {
1868 if (hw->mac_type < e1000_82545_rev_3)
1869 E1000_WRITE_REG(hw, VET, 0);
1870 e1000_clear_vfta(hw);
1873 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
1874 if (hw->mac_type == e1000_82542_rev2_0) {
1875 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1876 dm_pci_write_config16(hw->pdev, PCI_COMMAND,
1878 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1879 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
1880 E1000_WRITE_FLUSH(hw);
1884 /* Setup the receive address. This involves initializing all of the Receive
1885 * Address Registers (RARs 0 - 15).
1887 e1000_init_rx_addrs(hw, enetaddr);
1889 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
1890 if (hw->mac_type == e1000_82542_rev2_0) {
1891 E1000_WRITE_REG(hw, RCTL, 0);
1892 E1000_WRITE_FLUSH(hw);
1894 dm_pci_write_config16(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1897 /* Zero out the Multicast HASH table */
1898 DEBUGOUT("Zeroing the MTA\n");
1899 mta_size = E1000_MC_TBL_SIZE;
1900 if (hw->mac_type == e1000_ich8lan)
1901 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
1902 for (i = 0; i < mta_size; i++) {
1903 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
1904 /* use write flush to prevent Memory Write Block (MWB) from
1905 * occuring when accessing our register space */
1906 E1000_WRITE_FLUSH(hw);
1909 switch (hw->mac_type) {
1910 case e1000_82545_rev_3:
1911 case e1000_82546_rev_3:
1915 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
1916 if (hw->bus_type == e1000_bus_type_pcix) {
1917 dm_pci_read_config16(hw->pdev, PCIX_COMMAND_REGISTER,
1919 dm_pci_read_config16(hw->pdev, PCIX_STATUS_REGISTER_HI,
1920 &pcix_stat_hi_word);
1922 (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
1923 PCIX_COMMAND_MMRBC_SHIFT;
1925 (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
1926 PCIX_STATUS_HI_MMRBC_SHIFT;
1927 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
1928 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
1929 if (cmd_mmrbc > stat_mmrbc) {
1930 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
1931 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
1932 dm_pci_write_config16(hw->pdev, PCIX_COMMAND_REGISTER,
1939 /* More time needed for PHY to initialize */
1940 if (hw->mac_type == e1000_ich8lan)
1942 if (hw->mac_type == e1000_igb)
1945 /* Call a subroutine to configure the link and setup flow control. */
1946 ret_val = e1000_setup_link(hw);
1948 /* Set the transmit descriptor write-back policy */
1949 if (hw->mac_type > e1000_82544) {
1950 ctrl = E1000_READ_REG(hw, TXDCTL);
1952 (ctrl & ~E1000_TXDCTL_WTHRESH) |
1953 E1000_TXDCTL_FULL_TX_DESC_WB;
1954 E1000_WRITE_REG(hw, TXDCTL, ctrl);
1957 /* Set the receive descriptor write back policy */
1958 if (hw->mac_type >= e1000_82571) {
1959 ctrl = E1000_READ_REG(hw, RXDCTL);
1961 (ctrl & ~E1000_RXDCTL_WTHRESH) |
1962 E1000_RXDCTL_FULL_RX_DESC_WB;
1963 E1000_WRITE_REG(hw, RXDCTL, ctrl);
1966 switch (hw->mac_type) {
1969 case e1000_80003es2lan:
1970 /* Enable retransmit on late collisions */
1971 reg_data = E1000_READ_REG(hw, TCTL);
1972 reg_data |= E1000_TCTL_RTLC;
1973 E1000_WRITE_REG(hw, TCTL, reg_data);
1975 /* Configure Gigabit Carry Extend Padding */
1976 reg_data = E1000_READ_REG(hw, TCTL_EXT);
1977 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
1978 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
1979 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1981 /* Configure Transmit Inter-Packet Gap */
1982 reg_data = E1000_READ_REG(hw, TIPG);
1983 reg_data &= ~E1000_TIPG_IPGT_MASK;
1984 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1985 E1000_WRITE_REG(hw, TIPG, reg_data);
1987 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1988 reg_data &= ~0x00100000;
1989 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1994 ctrl = E1000_READ_REG(hw, TXDCTL1);
1995 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH)
1996 | E1000_TXDCTL_FULL_TX_DESC_WB;
1997 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
2001 reg_data = E1000_READ_REG(hw, GCR);
2002 reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
2003 E1000_WRITE_REG(hw, GCR, reg_data);
2008 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
2009 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
2010 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2011 /* Relaxed ordering must be disabled to avoid a parity
2012 * error crash in a PCI slot. */
2013 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
2014 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2020 /******************************************************************************
2021 * Configures flow control and link settings.
2023 * hw - Struct containing variables accessed by shared code
2025 * Determines which flow control settings to use. Calls the apropriate media-
2026 * specific link configuration function. Configures the flow control settings.
2027 * Assuming the adapter has a valid link partner, a valid link should be
2028 * established. Assumes the hardware has previously been reset and the
2029 * transmitter and receiver are not enabled.
2030 *****************************************************************************/
2032 e1000_setup_link(struct e1000_hw *hw)
2035 #ifndef CONFIG_E1000_NO_NVM
2037 uint16_t eeprom_data;
2042 /* In the case of the phy reset being blocked, we already have a link.
2043 * We do not have to set it up again. */
2044 if (e1000_check_phy_reset_block(hw))
2045 return E1000_SUCCESS;
2047 #ifndef CONFIG_E1000_NO_NVM
2048 /* Read and store word 0x0F of the EEPROM. This word contains bits
2049 * that determine the hardware's default PAUSE (flow control) mode,
2050 * a bit that determines whether the HW defaults to enabling or
2051 * disabling auto-negotiation, and the direction of the
2052 * SW defined pins. If there is no SW over-ride of the flow
2053 * control setting, then the variable hw->fc will
2054 * be initialized based on a value in the EEPROM.
2056 if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1,
2057 &eeprom_data) < 0) {
2058 DEBUGOUT("EEPROM Read Error\n");
2059 return -E1000_ERR_EEPROM;
2062 if (hw->fc == e1000_fc_default) {
2063 switch (hw->mac_type) {
2068 hw->fc = e1000_fc_full;
2071 #ifndef CONFIG_E1000_NO_NVM
2072 ret_val = e1000_read_eeprom(hw,
2073 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
2075 DEBUGOUT("EEPROM Read Error\n");
2076 return -E1000_ERR_EEPROM;
2078 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
2079 hw->fc = e1000_fc_none;
2080 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
2081 EEPROM_WORD0F_ASM_DIR)
2082 hw->fc = e1000_fc_tx_pause;
2085 hw->fc = e1000_fc_full;
2090 /* We want to save off the original Flow Control configuration just
2091 * in case we get disconnected and then reconnected into a different
2092 * hub or switch with different Flow Control capabilities.
2094 if (hw->mac_type == e1000_82542_rev2_0)
2095 hw->fc &= (~e1000_fc_tx_pause);
2097 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
2098 hw->fc &= (~e1000_fc_rx_pause);
2100 hw->original_fc = hw->fc;
2102 DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc);
2104 #ifndef CONFIG_E1000_NO_NVM
2105 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
2106 * polarity value for the SW controlled pins, and setup the
2107 * Extended Device Control reg with that info.
2108 * This is needed because one of the SW controlled pins is used for
2109 * signal detection. So this should be done before e1000_setup_pcs_link()
2110 * or e1000_phy_setup() is called.
2112 if (hw->mac_type == e1000_82543) {
2113 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
2115 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2119 /* Call the necessary subroutine to configure the link. */
2120 ret_val = (hw->media_type == e1000_media_type_fiber) ?
2121 e1000_setup_fiber_link(hw) : e1000_setup_copper_link(hw);
2126 /* Initialize the flow control address, type, and PAUSE timer
2127 * registers to their default values. This is done even if flow
2128 * control is disabled, because it does not hurt anything to
2129 * initialize these registers.
2131 DEBUGOUT("Initializing the Flow Control address, type"
2132 "and timer regs\n");
2134 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
2135 if (hw->mac_type != e1000_ich8lan) {
2136 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
2137 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
2138 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
2141 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
2143 /* Set the flow control receive threshold registers. Normally,
2144 * these registers will be set to a default threshold that may be
2145 * adjusted later by the driver's runtime code. However, if the
2146 * ability to transmit pause frames in not enabled, then these
2147 * registers will be set to 0.
2149 if (!(hw->fc & e1000_fc_tx_pause)) {
2150 E1000_WRITE_REG(hw, FCRTL, 0);
2151 E1000_WRITE_REG(hw, FCRTH, 0);
2153 /* We need to set up the Receive Threshold high and low water marks
2154 * as well as (optionally) enabling the transmission of XON frames.
2156 if (hw->fc_send_xon) {
2157 E1000_WRITE_REG(hw, FCRTL,
2158 (hw->fc_low_water | E1000_FCRTL_XONE));
2159 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
2161 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
2162 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
2168 /******************************************************************************
2169 * Sets up link for a fiber based adapter
2171 * hw - Struct containing variables accessed by shared code
2173 * Manipulates Physical Coding Sublayer functions in order to configure
2174 * link. Assumes the hardware has been previously reset and the transmitter
2175 * and receiver are not enabled.
2176 *****************************************************************************/
2178 e1000_setup_fiber_link(struct e1000_hw *hw)
2188 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
2189 * set when the optics detect a signal. On older adapters, it will be
2190 * cleared when there is a signal
2192 ctrl = E1000_READ_REG(hw, CTRL);
2193 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
2194 signal = E1000_CTRL_SWDPIN1;
2198 printf("signal for %s is %x (ctrl %08x)!!!!\n", hw->name, signal,
2200 /* Take the link out of reset */
2201 ctrl &= ~(E1000_CTRL_LRST);
2203 e1000_config_collision_dist(hw);
2205 /* Check for a software override of the flow control settings, and setup
2206 * the device accordingly. If auto-negotiation is enabled, then software
2207 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
2208 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
2209 * auto-negotiation is disabled, then software will have to manually
2210 * configure the two flow control enable bits in the CTRL register.
2212 * The possible values of the "fc" parameter are:
2213 * 0: Flow control is completely disabled
2214 * 1: Rx flow control is enabled (we can receive pause frames, but
2215 * not send pause frames).
2216 * 2: Tx flow control is enabled (we can send pause frames but we do
2217 * not support receiving pause frames).
2218 * 3: Both Rx and TX flow control (symmetric) are enabled.
2222 /* Flow control is completely disabled by a software over-ride. */
2223 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
2225 case e1000_fc_rx_pause:
2226 /* RX Flow control is enabled and TX Flow control is disabled by a
2227 * software over-ride. Since there really isn't a way to advertise
2228 * that we are capable of RX Pause ONLY, we will advertise that we
2229 * support both symmetric and asymmetric RX PAUSE. Later, we will
2230 * disable the adapter's ability to send PAUSE frames.
2232 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
2234 case e1000_fc_tx_pause:
2235 /* TX Flow control is enabled, and RX Flow control is disabled, by a
2236 * software over-ride.
2238 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
2241 /* Flow control (both RX and TX) is enabled by a software over-ride. */
2242 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
2245 DEBUGOUT("Flow control param set incorrectly\n");
2246 return -E1000_ERR_CONFIG;
2250 /* Since auto-negotiation is enabled, take the link out of reset (the link
2251 * will be in reset, because we previously reset the chip). This will
2252 * restart auto-negotiation. If auto-neogtiation is successful then the
2253 * link-up status bit will be set and the flow control enable bits (RFCE
2254 * and TFCE) will be set according to their negotiated value.
2256 DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw);
2258 E1000_WRITE_REG(hw, TXCW, txcw);
2259 E1000_WRITE_REG(hw, CTRL, ctrl);
2260 E1000_WRITE_FLUSH(hw);
2265 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
2266 * indication in the Device Status Register. Time-out if a link isn't
2267 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
2268 * less than 500 milliseconds even if the other end is doing it in SW).
2270 if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
2271 DEBUGOUT("Looking for Link\n");
2272 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
2274 status = E1000_READ_REG(hw, STATUS);
2275 if (status & E1000_STATUS_LU)
2278 if (i == (LINK_UP_TIMEOUT / 10)) {
2279 /* AutoNeg failed to achieve a link, so we'll call
2280 * e1000_check_for_link. This routine will force the link up if we
2281 * detect a signal. This will allow us to communicate with
2282 * non-autonegotiating link partners.
2284 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
2285 hw->autoneg_failed = 1;
2286 ret_val = e1000_check_for_link(hw);
2288 DEBUGOUT("Error while checking for link\n");
2291 hw->autoneg_failed = 0;
2293 hw->autoneg_failed = 0;
2294 DEBUGOUT("Valid Link Found\n");
2297 DEBUGOUT("No Signal Detected\n");
2298 return -E1000_ERR_NOLINK;
2303 /******************************************************************************
2304 * Make sure we have a valid PHY and change PHY mode before link setup.
2306 * hw - Struct containing variables accessed by shared code
2307 ******************************************************************************/
2309 e1000_copper_link_preconfig(struct e1000_hw *hw)
2317 ctrl = E1000_READ_REG(hw, CTRL);
2318 /* With 82543, we need to force speed and duplex on the MAC equal to what
2319 * the PHY speed and duplex configuration is. In addition, we need to
2320 * perform a hardware reset on the PHY to take it out of reset.
2322 if (hw->mac_type > e1000_82543) {
2323 ctrl |= E1000_CTRL_SLU;
2324 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2325 E1000_WRITE_REG(hw, CTRL, ctrl);
2327 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX
2329 E1000_WRITE_REG(hw, CTRL, ctrl);
2330 ret_val = e1000_phy_hw_reset(hw);
2335 /* Make sure we have a valid PHY */
2336 ret_val = e1000_detect_gig_phy(hw);
2338 DEBUGOUT("Error, did not detect valid phy.\n");
2341 DEBUGOUT("Phy ID = %x\n", hw->phy_id);
2343 /* Set PHY to class A mode (if necessary) */
2344 ret_val = e1000_set_phy_mode(hw);
2347 if ((hw->mac_type == e1000_82545_rev_3) ||
2348 (hw->mac_type == e1000_82546_rev_3)) {
2349 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2351 phy_data |= 0x00000008;
2352 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2356 if (hw->mac_type <= e1000_82543 ||
2357 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
2358 hw->mac_type == e1000_82541_rev_2
2359 || hw->mac_type == e1000_82547_rev_2)
2360 hw->phy_reset_disable = false;
2362 return E1000_SUCCESS;
2365 /*****************************************************************************
2367 * This function sets the lplu state according to the active flag. When
2368 * activating lplu this function also disables smart speed and vise versa.
2369 * lplu will not be activated unless the device autonegotiation advertisment
2370 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2371 * hw: Struct containing variables accessed by shared code
2372 * active - true to enable lplu false to disable lplu.
2374 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2375 * E1000_SUCCESS at any other case.
2377 ****************************************************************************/
2380 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
2382 uint32_t phy_ctrl = 0;
2387 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
2388 && hw->phy_type != e1000_phy_igp_3)
2389 return E1000_SUCCESS;
2391 /* During driver activity LPLU should not be used or it will attain link
2392 * from the lowest speeds starting from 10Mbps. The capability is used
2393 * for Dx transitions and states */
2394 if (hw->mac_type == e1000_82541_rev_2
2395 || hw->mac_type == e1000_82547_rev_2) {
2396 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
2400 } else if (hw->mac_type == e1000_ich8lan) {
2401 /* MAC writes into PHY register based on the state transition
2402 * and start auto-negotiation. SW driver can overwrite the
2403 * settings in CSR PHY power control E1000_PHY_CTRL register. */
2404 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
2406 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2413 if (hw->mac_type == e1000_82541_rev_2 ||
2414 hw->mac_type == e1000_82547_rev_2) {
2415 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
2416 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
2421 if (hw->mac_type == e1000_ich8lan) {
2422 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2423 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2425 phy_data &= ~IGP02E1000_PM_D3_LPLU;
2426 ret_val = e1000_write_phy_reg(hw,
2427 IGP02E1000_PHY_POWER_MGMT, phy_data);
2433 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2434 * Dx states where the power conservation is most important. During
2435 * driver activity we should enable SmartSpeed, so performance is
2437 if (hw->smart_speed == e1000_smart_speed_on) {
2438 ret_val = e1000_read_phy_reg(hw,
2439 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2443 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2444 ret_val = e1000_write_phy_reg(hw,
2445 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2448 } else if (hw->smart_speed == e1000_smart_speed_off) {
2449 ret_val = e1000_read_phy_reg(hw,
2450 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2454 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2455 ret_val = e1000_write_phy_reg(hw,
2456 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2461 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
2462 || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) ||
2463 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
2465 if (hw->mac_type == e1000_82541_rev_2 ||
2466 hw->mac_type == e1000_82547_rev_2) {
2467 phy_data |= IGP01E1000_GMII_FLEX_SPD;
2468 ret_val = e1000_write_phy_reg(hw,
2469 IGP01E1000_GMII_FIFO, phy_data);
2473 if (hw->mac_type == e1000_ich8lan) {
2474 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2475 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2477 phy_data |= IGP02E1000_PM_D3_LPLU;
2478 ret_val = e1000_write_phy_reg(hw,
2479 IGP02E1000_PHY_POWER_MGMT, phy_data);
2485 /* When LPLU is enabled we should disable SmartSpeed */
2486 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2491 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2492 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2497 return E1000_SUCCESS;
2500 /*****************************************************************************
2502 * This function sets the lplu d0 state according to the active flag. When
2503 * activating lplu this function also disables smart speed and vise versa.
2504 * lplu will not be activated unless the device autonegotiation advertisment
2505 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2506 * hw: Struct containing variables accessed by shared code
2507 * active - true to enable lplu false to disable lplu.
2509 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2510 * E1000_SUCCESS at any other case.
2512 ****************************************************************************/
2515 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
2517 uint32_t phy_ctrl = 0;
2522 if (hw->mac_type <= e1000_82547_rev_2)
2523 return E1000_SUCCESS;
2525 if (hw->mac_type == e1000_ich8lan) {
2526 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
2527 } else if (hw->mac_type == e1000_igb) {
2528 phy_ctrl = E1000_READ_REG(hw, I210_PHY_CTRL);
2530 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2537 if (hw->mac_type == e1000_ich8lan) {
2538 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2539 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2540 } else if (hw->mac_type == e1000_igb) {
2541 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2542 E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
2544 phy_data &= ~IGP02E1000_PM_D0_LPLU;
2545 ret_val = e1000_write_phy_reg(hw,
2546 IGP02E1000_PHY_POWER_MGMT, phy_data);
2551 if (hw->mac_type == e1000_igb)
2552 return E1000_SUCCESS;
2554 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2555 * Dx states where the power conservation is most important. During
2556 * driver activity we should enable SmartSpeed, so performance is
2558 if (hw->smart_speed == e1000_smart_speed_on) {
2559 ret_val = e1000_read_phy_reg(hw,
2560 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2564 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2565 ret_val = e1000_write_phy_reg(hw,
2566 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2569 } else if (hw->smart_speed == e1000_smart_speed_off) {
2570 ret_val = e1000_read_phy_reg(hw,
2571 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2575 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2576 ret_val = e1000_write_phy_reg(hw,
2577 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2585 if (hw->mac_type == e1000_ich8lan) {
2586 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2587 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2588 } else if (hw->mac_type == e1000_igb) {
2589 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2590 E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
2592 phy_data |= IGP02E1000_PM_D0_LPLU;
2593 ret_val = e1000_write_phy_reg(hw,
2594 IGP02E1000_PHY_POWER_MGMT, phy_data);
2599 if (hw->mac_type == e1000_igb)
2600 return E1000_SUCCESS;
2602 /* When LPLU is enabled we should disable SmartSpeed */
2603 ret_val = e1000_read_phy_reg(hw,
2604 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2608 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2609 ret_val = e1000_write_phy_reg(hw,
2610 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2615 return E1000_SUCCESS;
2618 /********************************************************************
2619 * Copper link setup for e1000_phy_igp series.
2621 * hw - Struct containing variables accessed by shared code
2622 *********************************************************************/
2624 e1000_copper_link_igp_setup(struct e1000_hw *hw)
2632 if (hw->phy_reset_disable)
2633 return E1000_SUCCESS;
2635 ret_val = e1000_phy_reset(hw);
2637 DEBUGOUT("Error Resetting the PHY\n");
2641 /* Wait 15ms for MAC to configure PHY from eeprom settings */
2643 if (hw->mac_type != e1000_ich8lan) {
2644 /* Configure activity LED after PHY reset */
2645 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2646 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2647 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2648 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2651 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
2652 if (hw->phy_type == e1000_phy_igp) {
2653 /* disable lplu d3 during driver init */
2654 ret_val = e1000_set_d3_lplu_state(hw, false);
2656 DEBUGOUT("Error Disabling LPLU D3\n");
2661 /* disable lplu d0 during driver init */
2662 ret_val = e1000_set_d0_lplu_state(hw, false);
2664 DEBUGOUT("Error Disabling LPLU D0\n");
2667 /* Configure mdi-mdix settings */
2668 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2672 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2673 hw->dsp_config_state = e1000_dsp_config_disabled;
2674 /* Force MDI for earlier revs of the IGP PHY */
2675 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX
2676 | IGP01E1000_PSCR_FORCE_MDI_MDIX);
2680 hw->dsp_config_state = e1000_dsp_config_enabled;
2681 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2685 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2688 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
2692 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
2696 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2700 /* set auto-master slave resolution settings */
2702 e1000_ms_type phy_ms_setting = hw->master_slave;
2704 if (hw->ffe_config_state == e1000_ffe_config_active)
2705 hw->ffe_config_state = e1000_ffe_config_enabled;
2707 if (hw->dsp_config_state == e1000_dsp_config_activated)
2708 hw->dsp_config_state = e1000_dsp_config_enabled;
2710 /* when autonegotiation advertisment is only 1000Mbps then we
2711 * should disable SmartSpeed and enable Auto MasterSlave
2712 * resolution as hardware default. */
2713 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
2714 /* Disable SmartSpeed */
2715 ret_val = e1000_read_phy_reg(hw,
2716 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2719 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2720 ret_val = e1000_write_phy_reg(hw,
2721 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2724 /* Set auto Master/Slave resolution process */
2725 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
2729 phy_data &= ~CR_1000T_MS_ENABLE;
2730 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
2736 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
2740 /* load defaults for future use */
2741 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
2742 ((phy_data & CR_1000T_MS_VALUE) ?
2743 e1000_ms_force_master :
2744 e1000_ms_force_slave) :
2747 switch (phy_ms_setting) {
2748 case e1000_ms_force_master:
2749 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
2751 case e1000_ms_force_slave:
2752 phy_data |= CR_1000T_MS_ENABLE;
2753 phy_data &= ~(CR_1000T_MS_VALUE);
2756 phy_data &= ~CR_1000T_MS_ENABLE;
2760 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
2765 return E1000_SUCCESS;
2768 /*****************************************************************************
2769 * This function checks the mode of the firmware.
2771 * returns - true when the mode is IAMT or false.
2772 ****************************************************************************/
2774 e1000_check_mng_mode(struct e1000_hw *hw)
2779 fwsm = E1000_READ_REG(hw, FWSM);
2781 if (hw->mac_type == e1000_ich8lan) {
2782 if ((fwsm & E1000_FWSM_MODE_MASK) ==
2783 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
2785 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
2786 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
2793 e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data)
2795 uint16_t swfw = E1000_SWFW_PHY0_SM;
2799 if (e1000_is_second_port(hw))
2800 swfw = E1000_SWFW_PHY1_SM;
2802 if (e1000_swfw_sync_acquire(hw, swfw))
2803 return -E1000_ERR_SWFW_SYNC;
2805 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT)
2806 & E1000_KUMCTRLSTA_OFFSET) | data;
2807 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2810 return E1000_SUCCESS;
2814 e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data)
2816 uint16_t swfw = E1000_SWFW_PHY0_SM;
2820 if (e1000_is_second_port(hw))
2821 swfw = E1000_SWFW_PHY1_SM;
2823 if (e1000_swfw_sync_acquire(hw, swfw)) {
2824 debug("%s[%i]\n", __func__, __LINE__);
2825 return -E1000_ERR_SWFW_SYNC;
2828 /* Write register address */
2829 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
2830 E1000_KUMCTRLSTA_OFFSET) | E1000_KUMCTRLSTA_REN;
2831 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2834 /* Read the data returned */
2835 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
2836 *data = (uint16_t)reg_val;
2838 return E1000_SUCCESS;
2841 /********************************************************************
2842 * Copper link setup for e1000_phy_gg82563 series.
2844 * hw - Struct containing variables accessed by shared code
2845 *********************************************************************/
2847 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
2855 if (!hw->phy_reset_disable) {
2856 /* Enable CRS on TX for half-duplex operation. */
2857 ret_val = e1000_read_phy_reg(hw,
2858 GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2862 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2863 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
2864 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
2866 ret_val = e1000_write_phy_reg(hw,
2867 GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2872 * MDI/MDI-X = 0 (default)
2873 * 0 - Auto for all speeds
2876 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
2878 ret_val = e1000_read_phy_reg(hw,
2879 GG82563_PHY_SPEC_CTRL, &phy_data);
2883 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
2887 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
2890 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
2894 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
2899 * disable_polarity_correction = 0 (default)
2900 * Automatic Correction for Reversed Cable Polarity
2904 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
2905 ret_val = e1000_write_phy_reg(hw,
2906 GG82563_PHY_SPEC_CTRL, phy_data);
2911 /* SW Reset the PHY so all changes take effect */
2912 ret_val = e1000_phy_reset(hw);
2914 DEBUGOUT("Error Resetting the PHY\n");
2917 } /* phy_reset_disable */
2919 if (hw->mac_type == e1000_80003es2lan) {
2920 /* Bypass RX and TX FIFO's */
2921 ret_val = e1000_write_kmrn_reg(hw,
2922 E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
2923 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS
2924 | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
2928 ret_val = e1000_read_phy_reg(hw,
2929 GG82563_PHY_SPEC_CTRL_2, &phy_data);
2933 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
2934 ret_val = e1000_write_phy_reg(hw,
2935 GG82563_PHY_SPEC_CTRL_2, phy_data);
2940 reg_data = E1000_READ_REG(hw, CTRL_EXT);
2941 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
2942 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
2944 ret_val = e1000_read_phy_reg(hw,
2945 GG82563_PHY_PWR_MGMT_CTRL, &phy_data);
2949 /* Do not init these registers when the HW is in IAMT mode, since the
2950 * firmware will have already initialized them. We only initialize
2951 * them if the HW is not in IAMT mode.
2953 if (e1000_check_mng_mode(hw) == false) {
2954 /* Enable Electrical Idle on the PHY */
2955 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
2956 ret_val = e1000_write_phy_reg(hw,
2957 GG82563_PHY_PWR_MGMT_CTRL, phy_data);
2961 ret_val = e1000_read_phy_reg(hw,
2962 GG82563_PHY_KMRN_MODE_CTRL, &phy_data);
2966 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2967 ret_val = e1000_write_phy_reg(hw,
2968 GG82563_PHY_KMRN_MODE_CTRL, phy_data);
2974 /* Workaround: Disable padding in Kumeran interface in the MAC
2975 * and in the PHY to avoid CRC errors.
2977 ret_val = e1000_read_phy_reg(hw,
2978 GG82563_PHY_INBAND_CTRL, &phy_data);
2981 phy_data |= GG82563_ICR_DIS_PADDING;
2982 ret_val = e1000_write_phy_reg(hw,
2983 GG82563_PHY_INBAND_CTRL, phy_data);
2987 return E1000_SUCCESS;
2990 /********************************************************************
2991 * Copper link setup for e1000_phy_m88 series.
2993 * hw - Struct containing variables accessed by shared code
2994 *********************************************************************/
2996 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
3003 if (hw->phy_reset_disable)
3004 return E1000_SUCCESS;
3006 /* Enable CRS on TX. This must be set for half-duplex operation. */
3007 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3011 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
3014 * MDI/MDI-X = 0 (default)
3015 * 0 - Auto for all speeds
3018 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
3020 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
3024 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
3027 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
3030 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
3034 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
3039 * disable_polarity_correction = 0 (default)
3040 * Automatic Correction for Reversed Cable Polarity
3044 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
3045 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
3049 if (hw->phy_revision < M88E1011_I_REV_4) {
3050 /* Force TX_CLK in the Extended PHY Specific Control Register
3053 ret_val = e1000_read_phy_reg(hw,
3054 M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
3058 phy_data |= M88E1000_EPSCR_TX_CLK_25;
3060 if ((hw->phy_revision == E1000_REVISION_2) &&
3061 (hw->phy_id == M88E1111_I_PHY_ID)) {
3062 /* Vidalia Phy, set the downshift counter to 5x */
3063 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
3064 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
3065 ret_val = e1000_write_phy_reg(hw,
3066 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
3070 /* Configure Master and Slave downshift values */
3071 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK
3072 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
3073 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X
3074 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
3075 ret_val = e1000_write_phy_reg(hw,
3076 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
3082 /* SW Reset the PHY so all changes take effect */
3083 ret_val = e1000_phy_reset(hw);
3085 DEBUGOUT("Error Resetting the PHY\n");
3089 return E1000_SUCCESS;
3092 /********************************************************************
3093 * Setup auto-negotiation and flow control advertisements,
3094 * and then perform auto-negotiation.
3096 * hw - Struct containing variables accessed by shared code
3097 *********************************************************************/
3099 e1000_copper_link_autoneg(struct e1000_hw *hw)
3106 /* Perform some bounds checking on the hw->autoneg_advertised
3107 * parameter. If this variable is zero, then set it to the default.
3109 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
3111 /* If autoneg_advertised is zero, we assume it was not defaulted
3112 * by the calling code so we set to advertise full capability.
3114 if (hw->autoneg_advertised == 0)
3115 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
3117 /* IFE phy only supports 10/100 */
3118 if (hw->phy_type == e1000_phy_ife)
3119 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
3121 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
3122 ret_val = e1000_phy_setup_autoneg(hw);
3124 DEBUGOUT("Error Setting up Auto-Negotiation\n");
3127 DEBUGOUT("Restarting Auto-Neg\n");
3129 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
3130 * the Auto Neg Restart bit in the PHY control register.
3132 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3136 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
3137 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3141 /* Does the user want to wait for Auto-Neg to complete here, or
3142 * check at a later time (for example, callback routine).
3144 /* If we do not wait for autonegtation to complete I
3145 * do not see a valid link status.
3146 * wait_autoneg_complete = 1 .
3148 if (hw->wait_autoneg_complete) {
3149 ret_val = e1000_wait_autoneg(hw);
3151 DEBUGOUT("Error while waiting for autoneg"
3157 hw->get_link_status = true;
3159 return E1000_SUCCESS;
3162 /******************************************************************************
3163 * Config the MAC and the PHY after link is up.
3164 * 1) Set up the MAC to the current PHY speed/duplex
3165 * if we are on 82543. If we
3166 * are on newer silicon, we only need to configure
3167 * collision distance in the Transmit Control Register.
3168 * 2) Set up flow control on the MAC to that established with
3170 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
3172 * hw - Struct containing variables accessed by shared code
3173 ******************************************************************************/
3175 e1000_copper_link_postconfig(struct e1000_hw *hw)
3180 if (hw->mac_type >= e1000_82544) {
3181 e1000_config_collision_dist(hw);
3183 ret_val = e1000_config_mac_to_phy(hw);
3185 DEBUGOUT("Error configuring MAC to PHY settings\n");
3189 ret_val = e1000_config_fc_after_link_up(hw);
3191 DEBUGOUT("Error Configuring Flow Control\n");
3194 return E1000_SUCCESS;
3197 /******************************************************************************
3198 * Detects which PHY is present and setup the speed and duplex
3200 * hw - Struct containing variables accessed by shared code
3201 ******************************************************************************/
3203 e1000_setup_copper_link(struct e1000_hw *hw)
3212 switch (hw->mac_type) {
3213 case e1000_80003es2lan:
3215 /* Set the mac to wait the maximum time between each
3216 * iteration and increase the max iterations when
3217 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
3218 ret_val = e1000_write_kmrn_reg(hw,
3219 GG82563_REG(0x34, 4), 0xFFFF);
3222 ret_val = e1000_read_kmrn_reg(hw,
3223 GG82563_REG(0x34, 9), ®_data);
3227 ret_val = e1000_write_kmrn_reg(hw,
3228 GG82563_REG(0x34, 9), reg_data);
3235 /* Check if it is a valid PHY and set PHY mode if necessary. */
3236 ret_val = e1000_copper_link_preconfig(hw);
3239 switch (hw->mac_type) {
3240 case e1000_80003es2lan:
3241 /* Kumeran registers are written-only */
3243 E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
3244 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
3245 ret_val = e1000_write_kmrn_reg(hw,
3246 E1000_KUMCTRLSTA_OFFSET_INB_CTRL, reg_data);
3254 if (hw->phy_type == e1000_phy_igp ||
3255 hw->phy_type == e1000_phy_igp_3 ||
3256 hw->phy_type == e1000_phy_igp_2) {
3257 ret_val = e1000_copper_link_igp_setup(hw);
3260 } else if (hw->phy_type == e1000_phy_m88 ||
3261 hw->phy_type == e1000_phy_igb) {
3262 ret_val = e1000_copper_link_mgp_setup(hw);
3265 } else if (hw->phy_type == e1000_phy_gg82563) {
3266 ret_val = e1000_copper_link_ggp_setup(hw);
3272 /* Setup autoneg and flow control advertisement
3273 * and perform autonegotiation */
3274 ret_val = e1000_copper_link_autoneg(hw);
3278 /* Check link status. Wait up to 100 microseconds for link to become
3281 for (i = 0; i < 10; i++) {
3282 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3285 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3289 if (phy_data & MII_SR_LINK_STATUS) {
3290 /* Config the MAC and PHY after link is up */
3291 ret_val = e1000_copper_link_postconfig(hw);
3295 DEBUGOUT("Valid link established!!!\n");
3296 return E1000_SUCCESS;
3301 DEBUGOUT("Unable to establish link!!!\n");
3302 return E1000_SUCCESS;
3305 /******************************************************************************
3306 * Configures PHY autoneg and flow control advertisement settings
3308 * hw - Struct containing variables accessed by shared code
3309 ******************************************************************************/
3311 e1000_phy_setup_autoneg(struct e1000_hw *hw)
3314 uint16_t mii_autoneg_adv_reg;
3315 uint16_t mii_1000t_ctrl_reg;
3319 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
3320 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
3324 if (hw->phy_type != e1000_phy_ife) {
3325 /* Read the MII 1000Base-T Control Register (Address 9). */
3326 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
3327 &mii_1000t_ctrl_reg);
3331 mii_1000t_ctrl_reg = 0;
3333 /* Need to parse both autoneg_advertised and fc and set up
3334 * the appropriate PHY registers. First we will parse for
3335 * autoneg_advertised software override. Since we can advertise
3336 * a plethora of combinations, we need to check each bit
3340 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
3341 * Advertisement Register (Address 4) and the 1000 mb speed bits in
3342 * the 1000Base-T Control Register (Address 9).
3344 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
3345 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
3347 DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised);
3349 /* Do we want to advertise 10 Mb Half Duplex? */
3350 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
3351 DEBUGOUT("Advertise 10mb Half duplex\n");
3352 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
3355 /* Do we want to advertise 10 Mb Full Duplex? */
3356 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
3357 DEBUGOUT("Advertise 10mb Full duplex\n");
3358 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
3361 /* Do we want to advertise 100 Mb Half Duplex? */
3362 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
3363 DEBUGOUT("Advertise 100mb Half duplex\n");
3364 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
3367 /* Do we want to advertise 100 Mb Full Duplex? */
3368 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
3369 DEBUGOUT("Advertise 100mb Full duplex\n");
3370 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
3373 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
3374 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
3376 ("Advertise 1000mb Half duplex requested, request denied!\n");
3379 /* Do we want to advertise 1000 Mb Full Duplex? */
3380 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
3381 DEBUGOUT("Advertise 1000mb Full duplex\n");
3382 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
3385 /* Check for a software override of the flow control settings, and
3386 * setup the PHY advertisement registers accordingly. If
3387 * auto-negotiation is enabled, then software will have to set the
3388 * "PAUSE" bits to the correct value in the Auto-Negotiation
3389 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
3391 * The possible values of the "fc" parameter are:
3392 * 0: Flow control is completely disabled
3393 * 1: Rx flow control is enabled (we can receive pause frames
3394 * but not send pause frames).
3395 * 2: Tx flow control is enabled (we can send pause frames
3396 * but we do not support receiving pause frames).
3397 * 3: Both Rx and TX flow control (symmetric) are enabled.
3398 * other: No software override. The flow control configuration
3399 * in the EEPROM is used.
3402 case e1000_fc_none: /* 0 */
3403 /* Flow control (RX & TX) is completely disabled by a
3404 * software over-ride.
3406 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3408 case e1000_fc_rx_pause: /* 1 */
3409 /* RX Flow control is enabled, and TX Flow control is
3410 * disabled, by a software over-ride.
3412 /* Since there really isn't a way to advertise that we are
3413 * capable of RX Pause ONLY, we will advertise that we
3414 * support both symmetric and asymmetric RX PAUSE. Later
3415 * (in e1000_config_fc_after_link_up) we will disable the
3416 *hw's ability to send PAUSE frames.
3418 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3420 case e1000_fc_tx_pause: /* 2 */
3421 /* TX Flow control is enabled, and RX Flow control is
3422 * disabled, by a software over-ride.
3424 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
3425 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
3427 case e1000_fc_full: /* 3 */
3428 /* Flow control (both RX and TX) is enabled by a software
3431 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3434 DEBUGOUT("Flow control param set incorrectly\n");
3435 return -E1000_ERR_CONFIG;
3438 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
3442 DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
3444 if (hw->phy_type != e1000_phy_ife) {
3445 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
3446 mii_1000t_ctrl_reg);
3451 return E1000_SUCCESS;
3454 /******************************************************************************
3455 * Sets the collision distance in the Transmit Control register
3457 * hw - Struct containing variables accessed by shared code
3459 * Link should have been established previously. Reads the speed and duplex
3460 * information from the Device Status register.
3461 ******************************************************************************/
3463 e1000_config_collision_dist(struct e1000_hw *hw)
3465 uint32_t tctl, coll_dist;
3469 if (hw->mac_type < e1000_82543)
3470 coll_dist = E1000_COLLISION_DISTANCE_82542;
3472 coll_dist = E1000_COLLISION_DISTANCE;
3474 tctl = E1000_READ_REG(hw, TCTL);
3476 tctl &= ~E1000_TCTL_COLD;
3477 tctl |= coll_dist << E1000_COLD_SHIFT;
3479 E1000_WRITE_REG(hw, TCTL, tctl);
3480 E1000_WRITE_FLUSH(hw);
3483 /******************************************************************************
3484 * Sets MAC speed and duplex settings to reflect the those in the PHY
3486 * hw - Struct containing variables accessed by shared code
3487 * mii_reg - data to write to the MII control register
3489 * The contents of the PHY register containing the needed information need to
3491 ******************************************************************************/
3493 e1000_config_mac_to_phy(struct e1000_hw *hw)
3500 /* Read the Device Control Register and set the bits to Force Speed
3503 ctrl = E1000_READ_REG(hw, CTRL);
3504 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3505 ctrl &= ~(E1000_CTRL_ILOS);
3506 ctrl |= (E1000_CTRL_SPD_SEL);
3508 /* Set up duplex in the Device Control and Transmit Control
3509 * registers depending on negotiated values.
3511 if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
3512 DEBUGOUT("PHY Read Error\n");
3513 return -E1000_ERR_PHY;
3515 if (phy_data & M88E1000_PSSR_DPLX)
3516 ctrl |= E1000_CTRL_FD;
3518 ctrl &= ~E1000_CTRL_FD;
3520 e1000_config_collision_dist(hw);
3522 /* Set up speed in the Device Control register depending on
3523 * negotiated values.
3525 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
3526 ctrl |= E1000_CTRL_SPD_1000;
3527 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
3528 ctrl |= E1000_CTRL_SPD_100;
3529 /* Write the configured values back to the Device Control Reg. */
3530 E1000_WRITE_REG(hw, CTRL, ctrl);
3534 /******************************************************************************
3535 * Forces the MAC's flow control settings.
3537 * hw - Struct containing variables accessed by shared code
3539 * Sets the TFCE and RFCE bits in the device control register to reflect
3540 * the adapter settings. TFCE and RFCE need to be explicitly set by
3541 * software when a Copper PHY is used because autonegotiation is managed
3542 * by the PHY rather than the MAC. Software must also configure these
3543 * bits when link is forced on a fiber connection.
3544 *****************************************************************************/
3546 e1000_force_mac_fc(struct e1000_hw *hw)
3552 /* Get the current configuration of the Device Control Register */
3553 ctrl = E1000_READ_REG(hw, CTRL);
3555 /* Because we didn't get link via the internal auto-negotiation
3556 * mechanism (we either forced link or we got link via PHY
3557 * auto-neg), we have to manually enable/disable transmit an
3558 * receive flow control.
3560 * The "Case" statement below enables/disable flow control
3561 * according to the "hw->fc" parameter.
3563 * The possible values of the "fc" parameter are:
3564 * 0: Flow control is completely disabled
3565 * 1: Rx flow control is enabled (we can receive pause
3566 * frames but not send pause frames).
3567 * 2: Tx flow control is enabled (we can send pause frames
3568 * frames but we do not receive pause frames).
3569 * 3: Both Rx and TX flow control (symmetric) is enabled.
3570 * other: No other values should be possible at this point.
3575 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
3577 case e1000_fc_rx_pause:
3578 ctrl &= (~E1000_CTRL_TFCE);
3579 ctrl |= E1000_CTRL_RFCE;
3581 case e1000_fc_tx_pause:
3582 ctrl &= (~E1000_CTRL_RFCE);
3583 ctrl |= E1000_CTRL_TFCE;
3586 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
3589 DEBUGOUT("Flow control param set incorrectly\n");
3590 return -E1000_ERR_CONFIG;
3593 /* Disable TX Flow Control for 82542 (rev 2.0) */
3594 if (hw->mac_type == e1000_82542_rev2_0)
3595 ctrl &= (~E1000_CTRL_TFCE);
3597 E1000_WRITE_REG(hw, CTRL, ctrl);
3601 /******************************************************************************
3602 * Configures flow control settings after link is established
3604 * hw - Struct containing variables accessed by shared code
3606 * Should be called immediately after a valid link has been established.
3607 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
3608 * and autonegotiation is enabled, the MAC flow control settings will be set
3609 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
3610 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
3611 *****************************************************************************/
3613 e1000_config_fc_after_link_up(struct e1000_hw *hw)
3616 uint16_t mii_status_reg;
3617 uint16_t mii_nway_adv_reg;
3618 uint16_t mii_nway_lp_ability_reg;
3624 /* Check for the case where we have fiber media and auto-neg failed
3625 * so we had to force link. In this case, we need to force the
3626 * configuration of the MAC to match the "fc" parameter.
3628 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
3629 || ((hw->media_type == e1000_media_type_internal_serdes)
3630 && (hw->autoneg_failed))
3631 || ((hw->media_type == e1000_media_type_copper)
3632 && (!hw->autoneg))) {
3633 ret_val = e1000_force_mac_fc(hw);
3635 DEBUGOUT("Error forcing flow control settings\n");
3640 /* Check for the case where we have copper media and auto-neg is
3641 * enabled. In this case, we need to check and see if Auto-Neg
3642 * has completed, and if so, how the PHY and link partner has
3643 * flow control configured.
3645 if (hw->media_type == e1000_media_type_copper) {
3646 /* Read the MII Status Register and check to see if AutoNeg
3647 * has completed. We read this twice because this reg has
3648 * some "sticky" (latched) bits.
3650 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3651 DEBUGOUT("PHY Read Error\n");
3652 return -E1000_ERR_PHY;
3654 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3655 DEBUGOUT("PHY Read Error\n");
3656 return -E1000_ERR_PHY;
3659 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
3660 /* The AutoNeg process has completed, so we now need to
3661 * read both the Auto Negotiation Advertisement Register
3662 * (Address 4) and the Auto_Negotiation Base Page Ability
3663 * Register (Address 5) to determine how flow control was
3666 if (e1000_read_phy_reg
3667 (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
3668 DEBUGOUT("PHY Read Error\n");
3669 return -E1000_ERR_PHY;
3671 if (e1000_read_phy_reg
3672 (hw, PHY_LP_ABILITY,
3673 &mii_nway_lp_ability_reg) < 0) {
3674 DEBUGOUT("PHY Read Error\n");
3675 return -E1000_ERR_PHY;
3678 /* Two bits in the Auto Negotiation Advertisement Register
3679 * (Address 4) and two bits in the Auto Negotiation Base
3680 * Page Ability Register (Address 5) determine flow control
3681 * for both the PHY and the link partner. The following
3682 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
3683 * 1999, describes these PAUSE resolution bits and how flow
3684 * control is determined based upon these settings.
3685 * NOTE: DC = Don't Care
3687 * LOCAL DEVICE | LINK PARTNER
3688 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
3689 *-------|---------|-------|---------|--------------------
3690 * 0 | 0 | DC | DC | e1000_fc_none
3691 * 0 | 1 | 0 | DC | e1000_fc_none
3692 * 0 | 1 | 1 | 0 | e1000_fc_none
3693 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
3694 * 1 | 0 | 0 | DC | e1000_fc_none
3695 * 1 | DC | 1 | DC | e1000_fc_full
3696 * 1 | 1 | 0 | 0 | e1000_fc_none
3697 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
3700 /* Are both PAUSE bits set to 1? If so, this implies
3701 * Symmetric Flow Control is enabled at both ends. The
3702 * ASM_DIR bits are irrelevant per the spec.
3704 * For Symmetric Flow Control:
3706 * LOCAL DEVICE | LINK PARTNER
3707 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3708 *-------|---------|-------|---------|--------------------
3709 * 1 | DC | 1 | DC | e1000_fc_full
3712 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3713 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
3714 /* Now we need to check if the user selected RX ONLY
3715 * of pause frames. In this case, we had to advertise
3716 * FULL flow control because we could not advertise RX
3717 * ONLY. Hence, we must now check to see if we need to
3718 * turn OFF the TRANSMISSION of PAUSE frames.
3720 if (hw->original_fc == e1000_fc_full) {
3721 hw->fc = e1000_fc_full;
3722 DEBUGOUT("Flow Control = FULL.\r\n");
3724 hw->fc = e1000_fc_rx_pause;
3726 ("Flow Control = RX PAUSE frames only.\r\n");
3729 /* For receiving PAUSE frames ONLY.
3731 * LOCAL DEVICE | LINK PARTNER
3732 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3733 *-------|---------|-------|---------|--------------------
3734 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
3737 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3738 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3739 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3740 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3742 hw->fc = e1000_fc_tx_pause;
3744 ("Flow Control = TX PAUSE frames only.\r\n");
3746 /* For transmitting PAUSE frames ONLY.
3748 * LOCAL DEVICE | LINK PARTNER
3749 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3750 *-------|---------|-------|---------|--------------------
3751 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
3754 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3755 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3756 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3757 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3759 hw->fc = e1000_fc_rx_pause;
3761 ("Flow Control = RX PAUSE frames only.\r\n");
3763 /* Per the IEEE spec, at this point flow control should be
3764 * disabled. However, we want to consider that we could
3765 * be connected to a legacy switch that doesn't advertise
3766 * desired flow control, but can be forced on the link
3767 * partner. So if we advertised no flow control, that is
3768 * what we will resolve to. If we advertised some kind of
3769 * receive capability (Rx Pause Only or Full Flow Control)
3770 * and the link partner advertised none, we will configure
3771 * ourselves to enable Rx Flow Control only. We can do
3772 * this safely for two reasons: If the link partner really
3773 * didn't want flow control enabled, and we enable Rx, no
3774 * harm done since we won't be receiving any PAUSE frames
3775 * anyway. If the intent on the link partner was to have
3776 * flow control enabled, then by us enabling RX only, we
3777 * can at least receive pause frames and process them.
3778 * This is a good idea because in most cases, since we are
3779 * predominantly a server NIC, more times than not we will
3780 * be asked to delay transmission of packets than asking
3781 * our link partner to pause transmission of frames.
3783 else if (hw->original_fc == e1000_fc_none ||
3784 hw->original_fc == e1000_fc_tx_pause) {
3785 hw->fc = e1000_fc_none;
3786 DEBUGOUT("Flow Control = NONE.\r\n");
3788 hw->fc = e1000_fc_rx_pause;
3790 ("Flow Control = RX PAUSE frames only.\r\n");
3793 /* Now we need to do one last check... If we auto-
3794 * negotiated to HALF DUPLEX, flow control should not be
3795 * enabled per IEEE 802.3 spec.
3797 e1000_get_speed_and_duplex(hw, &speed, &duplex);
3799 if (duplex == HALF_DUPLEX)
3800 hw->fc = e1000_fc_none;
3802 /* Now we call a subroutine to actually force the MAC
3803 * controller to use the correct flow control settings.
3805 ret_val = e1000_force_mac_fc(hw);
3808 ("Error forcing flow control settings\n");
3813 ("Copper PHY and Auto Neg has not completed.\r\n");
3816 return E1000_SUCCESS;
3819 /******************************************************************************
3820 * Checks to see if the link status of the hardware has changed.
3822 * hw - Struct containing variables accessed by shared code
3824 * Called by any function that needs to check the link status of the adapter.
3825 *****************************************************************************/
3827 e1000_check_for_link(struct e1000_hw *hw)
3836 uint16_t lp_capability;
3840 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
3841 * set when the optics detect a signal. On older adapters, it will be
3842 * cleared when there is a signal
3844 ctrl = E1000_READ_REG(hw, CTRL);
3845 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
3846 signal = E1000_CTRL_SWDPIN1;
3850 status = E1000_READ_REG(hw, STATUS);
3851 rxcw = E1000_READ_REG(hw, RXCW);
3852 DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw);
3854 /* If we have a copper PHY then we only want to go out to the PHY
3855 * registers to see if Auto-Neg has completed and/or if our link
3856 * status has changed. The get_link_status flag will be set if we
3857 * receive a Link Status Change interrupt or we have Rx Sequence
3860 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
3861 /* First we want to see if the MII Status Register reports
3862 * link. If so, then we want to get the current speed/duplex
3864 * Read the register twice since the link bit is sticky.
3866 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3867 DEBUGOUT("PHY Read Error\n");
3868 return -E1000_ERR_PHY;
3870 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3871 DEBUGOUT("PHY Read Error\n");
3872 return -E1000_ERR_PHY;
3875 if (phy_data & MII_SR_LINK_STATUS) {
3876 hw->get_link_status = false;
3878 /* No link detected */
3879 return -E1000_ERR_NOLINK;
3882 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
3883 * have Si on board that is 82544 or newer, Auto
3884 * Speed Detection takes care of MAC speed/duplex
3885 * configuration. So we only need to configure Collision
3886 * Distance in the MAC. Otherwise, we need to force
3887 * speed/duplex on the MAC to the current PHY speed/duplex
3890 if (hw->mac_type >= e1000_82544)
3891 e1000_config_collision_dist(hw);
3893 ret_val = e1000_config_mac_to_phy(hw);
3896 ("Error configuring MAC to PHY settings\n");
3901 /* Configure Flow Control now that Auto-Neg has completed. First, we
3902 * need to restore the desired flow control settings because we may
3903 * have had to re-autoneg with a different link partner.
3905 ret_val = e1000_config_fc_after_link_up(hw);
3907 DEBUGOUT("Error configuring flow control\n");
3911 /* At this point we know that we are on copper and we have
3912 * auto-negotiated link. These are conditions for checking the link
3913 * parter capability register. We use the link partner capability to
3914 * determine if TBI Compatibility needs to be turned on or off. If
3915 * the link partner advertises any speed in addition to Gigabit, then
3916 * we assume that they are GMII-based, and TBI compatibility is not
3917 * needed. If no other speeds are advertised, we assume the link
3918 * partner is TBI-based, and we turn on TBI Compatibility.
3920 if (hw->tbi_compatibility_en) {
3921 if (e1000_read_phy_reg
3922 (hw, PHY_LP_ABILITY, &lp_capability) < 0) {
3923 DEBUGOUT("PHY Read Error\n");
3924 return -E1000_ERR_PHY;
3926 if (lp_capability & (NWAY_LPAR_10T_HD_CAPS |
3927 NWAY_LPAR_10T_FD_CAPS |
3928 NWAY_LPAR_100TX_HD_CAPS |
3929 NWAY_LPAR_100TX_FD_CAPS |
3930 NWAY_LPAR_100T4_CAPS)) {
3931 /* If our link partner advertises anything in addition to
3932 * gigabit, we do not need to enable TBI compatibility.
3934 if (hw->tbi_compatibility_on) {
3935 /* If we previously were in the mode, turn it off. */
3936 rctl = E1000_READ_REG(hw, RCTL);
3937 rctl &= ~E1000_RCTL_SBP;
3938 E1000_WRITE_REG(hw, RCTL, rctl);
3939 hw->tbi_compatibility_on = false;
3942 /* If TBI compatibility is was previously off, turn it on. For
3943 * compatibility with a TBI link partner, we will store bad
3944 * packets. Some frames have an additional byte on the end and
3945 * will look like CRC errors to to the hardware.
3947 if (!hw->tbi_compatibility_on) {
3948 hw->tbi_compatibility_on = true;
3949 rctl = E1000_READ_REG(hw, RCTL);
3950 rctl |= E1000_RCTL_SBP;
3951 E1000_WRITE_REG(hw, RCTL, rctl);
3956 /* If we don't have link (auto-negotiation failed or link partner cannot
3957 * auto-negotiate), the cable is plugged in (we have signal), and our
3958 * link partner is not trying to auto-negotiate with us (we are receiving
3959 * idles or data), we need to force link up. We also need to give
3960 * auto-negotiation time to complete, in case the cable was just plugged
3961 * in. The autoneg_failed flag does this.
3963 else if ((hw->media_type == e1000_media_type_fiber) &&
3964 (!(status & E1000_STATUS_LU)) &&
3965 ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
3966 (!(rxcw & E1000_RXCW_C))) {
3967 if (hw->autoneg_failed == 0) {
3968 hw->autoneg_failed = 1;
3971 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
3973 /* Disable auto-negotiation in the TXCW register */
3974 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3976 /* Force link-up and also force full-duplex. */
3977 ctrl = E1000_READ_REG(hw, CTRL);
3978 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3979 E1000_WRITE_REG(hw, CTRL, ctrl);
3981 /* Configure Flow Control after forcing link up. */
3982 ret_val = e1000_config_fc_after_link_up(hw);
3984 DEBUGOUT("Error configuring flow control\n");
3988 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3989 * auto-negotiation in the TXCW register and disable forced link in the
3990 * Device Control register in an attempt to auto-negotiate with our link
3993 else if ((hw->media_type == e1000_media_type_fiber) &&
3994 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
3996 ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
3997 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3998 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
4003 /******************************************************************************
4004 * Configure the MAC-to-PHY interface for 10/100Mbps
4006 * hw - Struct containing variables accessed by shared code
4007 ******************************************************************************/
4009 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
4011 int32_t ret_val = E1000_SUCCESS;
4017 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
4018 ret_val = e1000_write_kmrn_reg(hw,
4019 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
4023 /* Configure Transmit Inter-Packet Gap */
4024 tipg = E1000_READ_REG(hw, TIPG);
4025 tipg &= ~E1000_TIPG_IPGT_MASK;
4026 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
4027 E1000_WRITE_REG(hw, TIPG, tipg);
4029 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
4034 if (duplex == HALF_DUPLEX)
4035 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
4037 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
4039 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
4045 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
4047 int32_t ret_val = E1000_SUCCESS;
4053 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
4054 ret_val = e1000_write_kmrn_reg(hw,
4055 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
4059 /* Configure Transmit Inter-Packet Gap */
4060 tipg = E1000_READ_REG(hw, TIPG);
4061 tipg &= ~E1000_TIPG_IPGT_MASK;
4062 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
4063 E1000_WRITE_REG(hw, TIPG, tipg);
4065 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
4070 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
4071 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
4076 /******************************************************************************
4077 * Detects the current speed and duplex settings of the hardware.
4079 * hw - Struct containing variables accessed by shared code
4080 * speed - Speed of the connection
4081 * duplex - Duplex setting of the connection
4082 *****************************************************************************/
4084 e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed,
4093 if (hw->mac_type >= e1000_82543) {
4094 status = E1000_READ_REG(hw, STATUS);
4095 if (status & E1000_STATUS_SPEED_1000) {
4096 *speed = SPEED_1000;
4097 DEBUGOUT("1000 Mbs, ");
4098 } else if (status & E1000_STATUS_SPEED_100) {
4100 DEBUGOUT("100 Mbs, ");
4103 DEBUGOUT("10 Mbs, ");
4106 if (status & E1000_STATUS_FD) {
4107 *duplex = FULL_DUPLEX;
4108 DEBUGOUT("Full Duplex\r\n");
4110 *duplex = HALF_DUPLEX;
4111 DEBUGOUT(" Half Duplex\r\n");
4114 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
4115 *speed = SPEED_1000;
4116 *duplex = FULL_DUPLEX;
4119 /* IGP01 PHY may advertise full duplex operation after speed downgrade
4120 * even if it is operating at half duplex. Here we set the duplex
4121 * settings to match the duplex in the link partner's capabilities.
4123 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
4124 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
4128 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
4129 *duplex = HALF_DUPLEX;
4131 ret_val = e1000_read_phy_reg(hw,
4132 PHY_LP_ABILITY, &phy_data);
4135 if ((*speed == SPEED_100 &&
4136 !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
4137 || (*speed == SPEED_10
4138 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
4139 *duplex = HALF_DUPLEX;
4143 if ((hw->mac_type == e1000_80003es2lan) &&
4144 (hw->media_type == e1000_media_type_copper)) {
4145 if (*speed == SPEED_1000)
4146 ret_val = e1000_configure_kmrn_for_1000(hw);
4148 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
4152 return E1000_SUCCESS;
4155 /******************************************************************************
4156 * Blocks until autoneg completes or times out (~4.5 seconds)
4158 * hw - Struct containing variables accessed by shared code
4159 ******************************************************************************/
4161 e1000_wait_autoneg(struct e1000_hw *hw)
4167 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
4169 /* We will wait for autoneg to complete or timeout to expire. */
4170 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
4171 /* Read the MII Status Register and wait for Auto-Neg
4172 * Complete bit to be set.
4174 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
4175 DEBUGOUT("PHY Read Error\n");
4176 return -E1000_ERR_PHY;
4178 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
4179 DEBUGOUT("PHY Read Error\n");
4180 return -E1000_ERR_PHY;
4182 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
4183 DEBUGOUT("Auto-Neg complete.\n");
4188 DEBUGOUT("Auto-Neg timedout.\n");
4189 return -E1000_ERR_TIMEOUT;
4192 /******************************************************************************
4193 * Raises the Management Data Clock
4195 * hw - Struct containing variables accessed by shared code
4196 * ctrl - Device control register's current value
4197 ******************************************************************************/
4199 e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
4201 /* Raise the clock input to the Management Data Clock (by setting the MDC
4202 * bit), and then delay 2 microseconds.
4204 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
4205 E1000_WRITE_FLUSH(hw);
4209 /******************************************************************************
4210 * Lowers the Management Data Clock
4212 * hw - Struct containing variables accessed by shared code
4213 * ctrl - Device control register's current value
4214 ******************************************************************************/
4216 e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
4218 /* Lower the clock input to the Management Data Clock (by clearing the MDC
4219 * bit), and then delay 2 microseconds.
4221 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
4222 E1000_WRITE_FLUSH(hw);
4226 /******************************************************************************
4227 * Shifts data bits out to the PHY
4229 * hw - Struct containing variables accessed by shared code
4230 * data - Data to send out to the PHY
4231 * count - Number of bits to shift out
4233 * Bits are shifted out in MSB to LSB order.
4234 ******************************************************************************/
4236 e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count)
4241 /* We need to shift "count" number of bits out to the PHY. So, the value
4242 * in the "data" parameter will be shifted out to the PHY one bit at a
4243 * time. In order to do this, "data" must be broken down into bits.
4246 mask <<= (count - 1);
4248 ctrl = E1000_READ_REG(hw, CTRL);
4250 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
4251 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
4254 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
4255 * then raising and lowering the Management Data Clock. A "0" is
4256 * shifted out to the PHY by setting the MDIO bit to "0" and then
4257 * raising and lowering the clock.
4260 ctrl |= E1000_CTRL_MDIO;
4262 ctrl &= ~E1000_CTRL_MDIO;
4264 E1000_WRITE_REG(hw, CTRL, ctrl);
4265 E1000_WRITE_FLUSH(hw);
4269 e1000_raise_mdi_clk(hw, &ctrl);
4270 e1000_lower_mdi_clk(hw, &ctrl);
4276 /******************************************************************************
4277 * Shifts data bits in from the PHY
4279 * hw - Struct containing variables accessed by shared code
4281 * Bits are shifted in in MSB to LSB order.
4282 ******************************************************************************/
4284 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
4290 /* In order to read a register from the PHY, we need to shift in a total
4291 * of 18 bits from the PHY. The first two bit (turnaround) times are used
4292 * to avoid contention on the MDIO pin when a read operation is performed.
4293 * These two bits are ignored by us and thrown away. Bits are "shifted in"
4294 * by raising the input to the Management Data Clock (setting the MDC bit),
4295 * and then reading the value of the MDIO bit.
4297 ctrl = E1000_READ_REG(hw, CTRL);
4299 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
4300 ctrl &= ~E1000_CTRL_MDIO_DIR;
4301 ctrl &= ~E1000_CTRL_MDIO;
4303 E1000_WRITE_REG(hw, CTRL, ctrl);
4304 E1000_WRITE_FLUSH(hw);
4306 /* Raise and Lower the clock before reading in the data. This accounts for
4307 * the turnaround bits. The first clock occurred when we clocked out the
4308 * last bit of the Register Address.
4310 e1000_raise_mdi_clk(hw, &ctrl);
4311 e1000_lower_mdi_clk(hw, &ctrl);
4313 for (data = 0, i = 0; i < 16; i++) {
4315 e1000_raise_mdi_clk(hw, &ctrl);
4316 ctrl = E1000_READ_REG(hw, CTRL);
4317 /* Check to see if we shifted in a "1". */
4318 if (ctrl & E1000_CTRL_MDIO)
4320 e1000_lower_mdi_clk(hw, &ctrl);
4323 e1000_raise_mdi_clk(hw, &ctrl);
4324 e1000_lower_mdi_clk(hw, &ctrl);
4329 /*****************************************************************************
4330 * Reads the value from a PHY register
4332 * hw - Struct containing variables accessed by shared code
4333 * reg_addr - address of the PHY register to read
4334 ******************************************************************************/
4336 e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data)
4340 const uint32_t phy_addr = 1;
4342 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4343 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4344 return -E1000_ERR_PARAM;
4347 if (hw->mac_type > e1000_82543) {
4348 /* Set up Op-code, Phy Address, and register address in the MDI
4349 * Control register. The MAC will take care of interfacing with the
4350 * PHY to retrieve the desired data.
4352 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
4353 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4354 (E1000_MDIC_OP_READ));
4356 E1000_WRITE_REG(hw, MDIC, mdic);
4358 /* Poll the ready bit to see if the MDI read completed */
4359 for (i = 0; i < 64; i++) {
4361 mdic = E1000_READ_REG(hw, MDIC);
4362 if (mdic & E1000_MDIC_READY)
4365 if (!(mdic & E1000_MDIC_READY)) {
4366 DEBUGOUT("MDI Read did not complete\n");
4367 return -E1000_ERR_PHY;
4369 if (mdic & E1000_MDIC_ERROR) {
4370 DEBUGOUT("MDI Error\n");
4371 return -E1000_ERR_PHY;
4373 *phy_data = (uint16_t) mdic;
4375 /* We must first send a preamble through the MDIO pin to signal the
4376 * beginning of an MII instruction. This is done by sending 32
4377 * consecutive "1" bits.
4379 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4381 /* Now combine the next few fields that are required for a read
4382 * operation. We use this method instead of calling the
4383 * e1000_shift_out_mdi_bits routine five different times. The format of
4384 * a MII read instruction consists of a shift out of 14 bits and is
4385 * defined as follows:
4386 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
4387 * followed by a shift in of 18 bits. This first two bits shifted in
4388 * are TurnAround bits used to avoid contention on the MDIO pin when a
4389 * READ operation is performed. These two bits are thrown away
4390 * followed by a shift in of 16 bits which contains the desired data.
4392 mdic = ((reg_addr) | (phy_addr << 5) |
4393 (PHY_OP_READ << 10) | (PHY_SOF << 12));
4395 e1000_shift_out_mdi_bits(hw, mdic, 14);
4397 /* Now that we've shifted out the read command to the MII, we need to
4398 * "shift in" the 16-bit value (18 total bits) of the requested PHY
4401 *phy_data = e1000_shift_in_mdi_bits(hw);
4406 /******************************************************************************
4407 * Writes a value to a PHY register
4409 * hw - Struct containing variables accessed by shared code
4410 * reg_addr - address of the PHY register to write
4411 * data - data to write to the PHY
4412 ******************************************************************************/
4414 e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data)
4418 const uint32_t phy_addr = 1;
4420 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4421 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4422 return -E1000_ERR_PARAM;
4425 if (hw->mac_type > e1000_82543) {
4426 /* Set up Op-code, Phy Address, register address, and data intended
4427 * for the PHY register in the MDI Control register. The MAC will take
4428 * care of interfacing with the PHY to send the desired data.
4430 mdic = (((uint32_t) phy_data) |
4431 (reg_addr << E1000_MDIC_REG_SHIFT) |
4432 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4433 (E1000_MDIC_OP_WRITE));
4435 E1000_WRITE_REG(hw, MDIC, mdic);
4437 /* Poll the ready bit to see if the MDI read completed */
4438 for (i = 0; i < 64; i++) {
4440 mdic = E1000_READ_REG(hw, MDIC);
4441 if (mdic & E1000_MDIC_READY)
4444 if (!(mdic & E1000_MDIC_READY)) {
4445 DEBUGOUT("MDI Write did not complete\n");
4446 return -E1000_ERR_PHY;
4449 /* We'll need to use the SW defined pins to shift the write command
4450 * out to the PHY. We first send a preamble to the PHY to signal the
4451 * beginning of the MII instruction. This is done by sending 32
4452 * consecutive "1" bits.
4454 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4456 /* Now combine the remaining required fields that will indicate a
4457 * write operation. We use this method instead of calling the
4458 * e1000_shift_out_mdi_bits routine for each field in the command. The
4459 * format of a MII write instruction is as follows:
4460 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
4462 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
4463 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
4465 mdic |= (uint32_t) phy_data;
4467 e1000_shift_out_mdi_bits(hw, mdic, 32);
4472 /******************************************************************************
4473 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
4474 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
4475 * the caller to figure out how to deal with it.
4477 * hw - Struct containing variables accessed by shared code
4479 * returns: - E1000_BLK_PHY_RESET
4482 *****************************************************************************/
4484 e1000_check_phy_reset_block(struct e1000_hw *hw)
4489 if (hw->mac_type == e1000_ich8lan) {
4490 fwsm = E1000_READ_REG(hw, FWSM);
4491 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
4492 : E1000_BLK_PHY_RESET;
4495 if (hw->mac_type > e1000_82547_rev_2)
4496 manc = E1000_READ_REG(hw, MANC);
4497 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
4498 E1000_BLK_PHY_RESET : E1000_SUCCESS;
4501 /***************************************************************************
4502 * Checks if the PHY configuration is done
4504 * hw: Struct containing variables accessed by shared code
4506 * returns: - E1000_ERR_RESET if fail to reset MAC
4507 * E1000_SUCCESS at any other case.
4509 ***************************************************************************/
4511 e1000_get_phy_cfg_done(struct e1000_hw *hw)
4513 int32_t timeout = PHY_CFG_TIMEOUT;
4514 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
4518 switch (hw->mac_type) {
4523 case e1000_80003es2lan:
4524 /* Separate *_CFG_DONE_* bit for each port */
4525 if (e1000_is_second_port(hw))
4526 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
4533 if (hw->mac_type == e1000_igb) {
4534 if (E1000_READ_REG(hw, I210_EEMNGCTL) & cfg_mask)
4537 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
4544 DEBUGOUT("MNG configuration cycle has not "
4546 return -E1000_ERR_RESET;
4551 return E1000_SUCCESS;
4554 /******************************************************************************
4555 * Returns the PHY to the power-on reset state
4557 * hw - Struct containing variables accessed by shared code
4558 ******************************************************************************/
4560 e1000_phy_hw_reset(struct e1000_hw *hw)
4562 uint16_t swfw = E1000_SWFW_PHY0_SM;
4563 uint32_t ctrl, ctrl_ext;
4569 /* In the case of the phy reset being blocked, it's not an error, we
4570 * simply return success without performing the reset. */
4571 ret_val = e1000_check_phy_reset_block(hw);
4573 return E1000_SUCCESS;
4575 DEBUGOUT("Resetting Phy...\n");
4577 if (hw->mac_type > e1000_82543) {
4578 if (e1000_is_second_port(hw))
4579 swfw = E1000_SWFW_PHY1_SM;
4581 if (e1000_swfw_sync_acquire(hw, swfw)) {
4582 DEBUGOUT("Unable to acquire swfw sync\n");
4583 return -E1000_ERR_SWFW_SYNC;
4586 /* Read the device control register and assert the E1000_CTRL_PHY_RST
4587 * bit. Then, take it out of reset.
4589 ctrl = E1000_READ_REG(hw, CTRL);
4590 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
4591 E1000_WRITE_FLUSH(hw);
4593 if (hw->mac_type < e1000_82571)
4598 E1000_WRITE_REG(hw, CTRL, ctrl);
4599 E1000_WRITE_FLUSH(hw);
4601 if (hw->mac_type >= e1000_82571)
4605 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
4606 * bit to put the PHY into reset. Then, take it out of reset.
4608 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
4609 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
4610 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
4611 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4612 E1000_WRITE_FLUSH(hw);
4614 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
4615 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4616 E1000_WRITE_FLUSH(hw);
4620 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
4621 /* Configure activity LED after PHY reset */
4622 led_ctrl = E1000_READ_REG(hw, LEDCTL);
4623 led_ctrl &= IGP_ACTIVITY_LED_MASK;
4624 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
4625 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
4628 e1000_swfw_sync_release(hw, swfw);
4630 /* Wait for FW to finish PHY configuration. */
4631 ret_val = e1000_get_phy_cfg_done(hw);
4632 if (ret_val != E1000_SUCCESS)
4638 /******************************************************************************
4639 * IGP phy init script - initializes the GbE PHY
4641 * hw - Struct containing variables accessed by shared code
4642 *****************************************************************************/
4644 e1000_phy_init_script(struct e1000_hw *hw)
4647 uint16_t phy_saved_data;
4650 if (hw->phy_init_script) {
4653 /* Save off the current value of register 0x2F5B to be
4654 * restored at the end of this routine. */
4655 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
4657 /* Disabled the PHY transmitter */
4658 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
4662 e1000_write_phy_reg(hw, 0x0000, 0x0140);
4666 switch (hw->mac_type) {
4669 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
4671 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
4673 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
4675 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
4677 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
4679 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
4681 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
4683 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
4685 e1000_write_phy_reg(hw, 0x2010, 0x0008);
4688 case e1000_82541_rev_2:
4689 case e1000_82547_rev_2:
4690 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
4696 e1000_write_phy_reg(hw, 0x0000, 0x3300);
4700 /* Now enable the transmitter */
4702 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
4704 if (hw->mac_type == e1000_82547) {
4705 uint16_t fused, fine, coarse;
4707 /* Move to analog registers page */
4708 e1000_read_phy_reg(hw,
4709 IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
4711 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
4712 e1000_read_phy_reg(hw,
4713 IGP01E1000_ANALOG_FUSE_STATUS, &fused);
4715 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
4717 & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
4720 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
4722 IGP01E1000_ANALOG_FUSE_COARSE_10;
4723 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
4725 == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
4726 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
4729 & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
4731 & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
4733 & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
4735 e1000_write_phy_reg(hw,
4736 IGP01E1000_ANALOG_FUSE_CONTROL, fused);
4737 e1000_write_phy_reg(hw,
4738 IGP01E1000_ANALOG_FUSE_BYPASS,
4739 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
4745 /******************************************************************************
4748 * hw - Struct containing variables accessed by shared code
4750 * Sets bit 15 of the MII Control register
4751 ******************************************************************************/
4753 e1000_phy_reset(struct e1000_hw *hw)
4760 /* In the case of the phy reset being blocked, it's not an error, we
4761 * simply return success without performing the reset. */
4762 ret_val = e1000_check_phy_reset_block(hw);
4764 return E1000_SUCCESS;
4766 switch (hw->phy_type) {
4768 case e1000_phy_igp_2:
4769 case e1000_phy_igp_3:
4772 ret_val = e1000_phy_hw_reset(hw);
4777 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
4781 phy_data |= MII_CR_RESET;
4782 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
4790 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
4791 e1000_phy_init_script(hw);
4793 return E1000_SUCCESS;
4796 static int e1000_set_phy_type (struct e1000_hw *hw)
4800 if (hw->mac_type == e1000_undefined)
4801 return -E1000_ERR_PHY_TYPE;
4803 switch (hw->phy_id) {
4804 case M88E1000_E_PHY_ID:
4805 case M88E1000_I_PHY_ID:
4806 case M88E1011_I_PHY_ID:
4807 case M88E1111_I_PHY_ID:
4808 hw->phy_type = e1000_phy_m88;
4810 case IGP01E1000_I_PHY_ID:
4811 if (hw->mac_type == e1000_82541 ||
4812 hw->mac_type == e1000_82541_rev_2 ||
4813 hw->mac_type == e1000_82547 ||
4814 hw->mac_type == e1000_82547_rev_2) {
4815 hw->phy_type = e1000_phy_igp;
4818 case IGP03E1000_E_PHY_ID:
4819 hw->phy_type = e1000_phy_igp_3;
4822 case IFE_PLUS_E_PHY_ID:
4823 case IFE_C_E_PHY_ID:
4824 hw->phy_type = e1000_phy_ife;
4826 case GG82563_E_PHY_ID:
4827 if (hw->mac_type == e1000_80003es2lan) {
4828 hw->phy_type = e1000_phy_gg82563;
4831 case BME1000_E_PHY_ID:
4832 hw->phy_type = e1000_phy_bm;
4835 hw->phy_type = e1000_phy_igb;
4839 /* Should never have loaded on this device */
4840 hw->phy_type = e1000_phy_undefined;
4841 return -E1000_ERR_PHY_TYPE;
4844 return E1000_SUCCESS;
4847 /******************************************************************************
4848 * Probes the expected PHY address for known PHY IDs
4850 * hw - Struct containing variables accessed by shared code
4851 ******************************************************************************/
4853 e1000_detect_gig_phy(struct e1000_hw *hw)
4855 int32_t phy_init_status, ret_val;
4856 uint16_t phy_id_high, phy_id_low;
4861 /* The 82571 firmware may still be configuring the PHY. In this
4862 * case, we cannot access the PHY until the configuration is done. So
4863 * we explicitly set the PHY values. */
4864 if (hw->mac_type == e1000_82571 ||
4865 hw->mac_type == e1000_82572) {
4866 hw->phy_id = IGP01E1000_I_PHY_ID;
4867 hw->phy_type = e1000_phy_igp_2;
4868 return E1000_SUCCESS;
4871 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a
4872 * work- around that forces PHY page 0 to be set or the reads fail.
4873 * The rest of the code in this routine uses e1000_read_phy_reg to
4874 * read the PHY ID. So for ESB-2 we need to have this set so our
4875 * reads won't fail. If the attached PHY is not a e1000_phy_gg82563,
4876 * the routines below will figure this out as well. */
4877 if (hw->mac_type == e1000_80003es2lan)
4878 hw->phy_type = e1000_phy_gg82563;
4880 /* Read the PHY ID Registers to identify which PHY is onboard. */
4881 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
4885 hw->phy_id = (uint32_t) (phy_id_high << 16);
4887 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
4891 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4892 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4894 switch (hw->mac_type) {
4896 if (hw->phy_id == M88E1000_E_PHY_ID)
4900 if (hw->phy_id == M88E1000_I_PHY_ID)
4905 case e1000_82545_rev_3:
4907 case e1000_82546_rev_3:
4908 if (hw->phy_id == M88E1011_I_PHY_ID)
4912 case e1000_82541_rev_2:
4914 case e1000_82547_rev_2:
4915 if(hw->phy_id == IGP01E1000_I_PHY_ID)
4920 if (hw->phy_id == M88E1111_I_PHY_ID)
4924 if (hw->phy_id == BME1000_E_PHY_ID)
4927 case e1000_80003es2lan:
4928 if (hw->phy_id == GG82563_E_PHY_ID)
4932 if (hw->phy_id == IGP03E1000_E_PHY_ID)
4934 if (hw->phy_id == IFE_E_PHY_ID)
4936 if (hw->phy_id == IFE_PLUS_E_PHY_ID)
4938 if (hw->phy_id == IFE_C_E_PHY_ID)
4942 if (hw->phy_id == I210_I_PHY_ID)
4946 DEBUGOUT("Invalid MAC type %d\n", hw->mac_type);
4947 return -E1000_ERR_CONFIG;
4950 phy_init_status = e1000_set_phy_type(hw);
4952 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4953 DEBUGOUT("PHY ID 0x%X detected\n", hw->phy_id);
4956 DEBUGOUT("Invalid PHY ID 0x%X\n", hw->phy_id);
4957 return -E1000_ERR_PHY;
4960 /*****************************************************************************
4961 * Set media type and TBI compatibility.
4963 * hw - Struct containing variables accessed by shared code
4964 * **************************************************************************/
4966 e1000_set_media_type(struct e1000_hw *hw)
4972 if (hw->mac_type != e1000_82543) {
4973 /* tbi_compatibility is only valid on 82543 */
4974 hw->tbi_compatibility_en = false;
4977 switch (hw->device_id) {
4978 case E1000_DEV_ID_82545GM_SERDES:
4979 case E1000_DEV_ID_82546GB_SERDES:
4980 case E1000_DEV_ID_82571EB_SERDES:
4981 case E1000_DEV_ID_82571EB_SERDES_DUAL:
4982 case E1000_DEV_ID_82571EB_SERDES_QUAD:
4983 case E1000_DEV_ID_82572EI_SERDES:
4984 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
4985 hw->media_type = e1000_media_type_internal_serdes;
4988 switch (hw->mac_type) {
4989 case e1000_82542_rev2_0:
4990 case e1000_82542_rev2_1:
4991 hw->media_type = e1000_media_type_fiber;
4997 /* The STATUS_TBIMODE bit is reserved or reused
4998 * for the this device.
5000 hw->media_type = e1000_media_type_copper;
5003 status = E1000_READ_REG(hw, STATUS);
5004 if (status & E1000_STATUS_TBIMODE) {
5005 hw->media_type = e1000_media_type_fiber;
5006 /* tbi_compatibility not valid on fiber */
5007 hw->tbi_compatibility_en = false;
5009 hw->media_type = e1000_media_type_copper;
5017 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
5019 * e1000_sw_init initializes the Adapter private data structure.
5020 * Fields are initialized based on PCI device information and
5021 * OS network device settings (MTU size).
5025 e1000_sw_init(struct e1000_hw *hw)
5029 /* PCI config space info */
5030 dm_pci_read_config16(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
5031 dm_pci_read_config16(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
5032 dm_pci_read_config16(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
5033 &hw->subsystem_vendor_id);
5034 dm_pci_read_config16(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
5036 dm_pci_read_config8(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
5037 dm_pci_read_config16(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
5039 /* identify the MAC */
5040 result = e1000_set_mac_type(hw);
5042 E1000_ERR(hw, "Unknown MAC Type\n");
5046 switch (hw->mac_type) {
5051 case e1000_82541_rev_2:
5052 case e1000_82547_rev_2:
5053 hw->phy_init_script = 1;
5057 /* flow control settings */
5058 hw->fc_high_water = E1000_FC_HIGH_THRESH;
5059 hw->fc_low_water = E1000_FC_LOW_THRESH;
5060 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
5061 hw->fc_send_xon = 1;
5063 /* Media type - copper or fiber */
5064 hw->tbi_compatibility_en = true;
5065 e1000_set_media_type(hw);
5067 if (hw->mac_type >= e1000_82543) {
5068 uint32_t status = E1000_READ_REG(hw, STATUS);
5070 if (status & E1000_STATUS_TBIMODE) {
5071 DEBUGOUT("fiber interface\n");
5072 hw->media_type = e1000_media_type_fiber;
5074 DEBUGOUT("copper interface\n");
5075 hw->media_type = e1000_media_type_copper;
5078 hw->media_type = e1000_media_type_fiber;
5081 hw->wait_autoneg_complete = true;
5082 if (hw->mac_type < e1000_82543)
5083 hw->report_tx_early = 0;
5085 hw->report_tx_early = 1;
5087 return E1000_SUCCESS;
5091 fill_rx(struct e1000_hw *hw)
5093 struct e1000_rx_desc *rd;
5094 unsigned long flush_start, flush_end;
5097 rd = rx_base + rx_tail;
5098 rx_tail = (rx_tail + 1) % 8;
5100 rd->buffer_addr = cpu_to_le64(virt_to_phys(packet));
5103 * Make sure there are no stale data in WB over this area, which
5104 * might get written into the memory while the e1000 also writes
5105 * into the same memory area.
5107 invalidate_dcache_range((unsigned long)packet,
5108 (unsigned long)packet + 4096);
5109 /* Dump the DMA descriptor into RAM. */
5110 flush_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
5111 flush_end = flush_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
5112 flush_dcache_range(flush_start, flush_end);
5114 E1000_WRITE_REG(hw, RDT, rx_tail);
5118 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
5119 * @adapter: board private structure
5121 * Configure the Tx unit of the MAC after a reset.
5125 e1000_configure_tx(struct e1000_hw *hw)
5128 unsigned long tipg, tarc;
5129 uint32_t ipgr1, ipgr2;
5131 E1000_WRITE_REG(hw, TDBAL, lower_32_bits(virt_to_phys(tx_base)));
5132 E1000_WRITE_REG(hw, TDBAH, upper_32_bits(virt_to_phys(tx_base)));
5134 E1000_WRITE_REG(hw, TDLEN, 128);
5136 /* Setup the HW Tx Head and Tail descriptor pointers */
5137 E1000_WRITE_REG(hw, TDH, 0);
5138 E1000_WRITE_REG(hw, TDT, 0);
5141 /* Set the default values for the Tx Inter Packet Gap timer */
5142 if (hw->mac_type <= e1000_82547_rev_2 &&
5143 (hw->media_type == e1000_media_type_fiber ||
5144 hw->media_type == e1000_media_type_internal_serdes))
5145 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
5147 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
5149 /* Set the default values for the Tx Inter Packet Gap timer */
5150 switch (hw->mac_type) {
5151 case e1000_82542_rev2_0:
5152 case e1000_82542_rev2_1:
5153 tipg = DEFAULT_82542_TIPG_IPGT;
5154 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
5155 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
5157 case e1000_80003es2lan:
5158 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
5159 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
5162 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
5163 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
5166 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
5167 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
5168 E1000_WRITE_REG(hw, TIPG, tipg);
5169 /* Program the Transmit Control Register */
5170 tctl = E1000_READ_REG(hw, TCTL);
5171 tctl &= ~E1000_TCTL_CT;
5172 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
5173 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
5175 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
5176 tarc = E1000_READ_REG(hw, TARC0);
5177 /* set the speed mode bit, we'll clear it if we're not at
5178 * gigabit link later */
5179 /* git bit can be set to 1*/
5180 } else if (hw->mac_type == e1000_80003es2lan) {
5181 tarc = E1000_READ_REG(hw, TARC0);
5183 E1000_WRITE_REG(hw, TARC0, tarc);
5184 tarc = E1000_READ_REG(hw, TARC1);
5186 E1000_WRITE_REG(hw, TARC1, tarc);
5190 e1000_config_collision_dist(hw);
5191 /* Setup Transmit Descriptor Settings for eop descriptor */
5192 hw->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
5194 /* Need to set up RS bit */
5195 if (hw->mac_type < e1000_82543)
5196 hw->txd_cmd |= E1000_TXD_CMD_RPS;
5198 hw->txd_cmd |= E1000_TXD_CMD_RS;
5201 if (hw->mac_type == e1000_igb) {
5202 E1000_WRITE_REG(hw, TCTL_EXT, 0x42 << 10);
5204 uint32_t reg_txdctl = E1000_READ_REG(hw, TXDCTL);
5205 reg_txdctl |= 1 << 25;
5206 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
5210 E1000_WRITE_REG(hw, TCTL, tctl);
5214 * e1000_setup_rctl - configure the receive control register
5215 * @adapter: Board private structure
5218 e1000_setup_rctl(struct e1000_hw *hw)
5222 rctl = E1000_READ_REG(hw, RCTL);
5224 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
5226 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO
5227 | E1000_RCTL_RDMTS_HALF; /* |
5228 (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */
5230 if (hw->tbi_compatibility_on == 1)
5231 rctl |= E1000_RCTL_SBP;
5233 rctl &= ~E1000_RCTL_SBP;
5235 rctl &= ~(E1000_RCTL_SZ_4096);
5236 rctl |= E1000_RCTL_SZ_2048;
5237 rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
5238 E1000_WRITE_REG(hw, RCTL, rctl);
5242 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
5243 * @adapter: board private structure
5245 * Configure the Rx unit of the MAC after a reset.
5248 e1000_configure_rx(struct e1000_hw *hw)
5250 unsigned long rctl, ctrl_ext;
5253 /* make sure receives are disabled while setting up the descriptors */
5254 rctl = E1000_READ_REG(hw, RCTL);
5255 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
5256 if (hw->mac_type >= e1000_82540) {
5257 /* Set the interrupt throttling rate. Value is calculated
5258 * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */
5259 #define MAX_INTS_PER_SEC 8000
5260 #define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
5261 E1000_WRITE_REG(hw, ITR, DEFAULT_ITR);
5264 if (hw->mac_type >= e1000_82571) {
5265 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5266 /* Reset delay timers after every interrupt */
5267 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
5268 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
5269 E1000_WRITE_FLUSH(hw);
5271 /* Setup the Base and Length of the Rx Descriptor Ring */
5272 E1000_WRITE_REG(hw, RDBAL, lower_32_bits(virt_to_phys(rx_base)));
5273 E1000_WRITE_REG(hw, RDBAH, upper_32_bits(virt_to_phys(rx_base)));
5275 E1000_WRITE_REG(hw, RDLEN, 128);
5277 /* Setup the HW Rx Head and Tail Descriptor Pointers */
5278 E1000_WRITE_REG(hw, RDH, 0);
5279 E1000_WRITE_REG(hw, RDT, 0);
5280 /* Enable Receives */
5282 if (hw->mac_type == e1000_igb) {
5284 uint32_t reg_rxdctl = E1000_READ_REG(hw, RXDCTL);
5285 reg_rxdctl |= 1 << 25;
5286 E1000_WRITE_REG(hw, RXDCTL, reg_rxdctl);
5290 E1000_WRITE_REG(hw, RCTL, rctl);
5295 /**************************************************************************
5296 POLL - Wait for a frame
5297 ***************************************************************************/
5299 _e1000_poll(struct e1000_hw *hw)
5301 struct e1000_rx_desc *rd;
5302 unsigned long inval_start, inval_end;
5305 /* return true if there's an ethernet packet ready to read */
5306 rd = rx_base + rx_last;
5308 /* Re-load the descriptor from RAM. */
5309 inval_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
5310 inval_end = inval_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
5311 invalidate_dcache_range(inval_start, inval_end);
5313 if (!(rd->status & E1000_RXD_STAT_DD))
5315 /* DEBUGOUT("recv: packet len=%d\n", rd->length); */
5316 /* Packet received, make sure the data are re-loaded from RAM. */
5317 len = le16_to_cpu(rd->length);
5318 invalidate_dcache_range((unsigned long)packet,
5319 (unsigned long)packet +
5320 roundup(len, ARCH_DMA_MINALIGN));
5324 static int _e1000_transmit(struct e1000_hw *hw, void *txpacket, int length)
5326 void *nv_packet = (void *)txpacket;
5327 struct e1000_tx_desc *txp;
5329 unsigned long flush_start, flush_end;
5331 txp = tx_base + tx_tail;
5332 tx_tail = (tx_tail + 1) % 8;
5334 txp->buffer_addr = cpu_to_le64(virt_to_phys(nv_packet));
5335 txp->lower.data = cpu_to_le32(hw->txd_cmd | length);
5336 txp->upper.data = 0;
5338 /* Dump the packet into RAM so e1000 can pick them. */
5339 flush_dcache_range((unsigned long)nv_packet,
5340 (unsigned long)nv_packet +
5341 roundup(length, ARCH_DMA_MINALIGN));
5342 /* Dump the descriptor into RAM as well. */
5343 flush_start = ((unsigned long)txp) & ~(ARCH_DMA_MINALIGN - 1);
5344 flush_end = flush_start + roundup(sizeof(*txp), ARCH_DMA_MINALIGN);
5345 flush_dcache_range(flush_start, flush_end);
5347 E1000_WRITE_REG(hw, TDT, tx_tail);
5349 E1000_WRITE_FLUSH(hw);
5351 invalidate_dcache_range(flush_start, flush_end);
5352 if (le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD)
5354 if (i++ > TOUT_LOOP) {
5355 DEBUGOUT("e1000: tx timeout\n");
5358 udelay(10); /* give the nic a chance to write to the register */
5364 _e1000_disable(struct e1000_hw *hw)
5366 /* Turn off the ethernet interface */
5367 E1000_WRITE_REG(hw, RCTL, 0);
5368 E1000_WRITE_REG(hw, TCTL, 0);
5370 /* Clear the transmit ring */
5371 E1000_WRITE_REG(hw, TDH, 0);
5372 E1000_WRITE_REG(hw, TDT, 0);
5374 /* Clear the receive ring */
5375 E1000_WRITE_REG(hw, RDH, 0);
5376 E1000_WRITE_REG(hw, RDT, 0);
5383 e1000_reset(struct e1000_hw *hw, unsigned char enetaddr[6])
5386 if (hw->mac_type >= e1000_82544)
5387 E1000_WRITE_REG(hw, WUC, 0);
5389 return e1000_init_hw(hw, enetaddr);
5393 _e1000_init(struct e1000_hw *hw, unsigned char enetaddr[6])
5397 ret_val = e1000_reset(hw, enetaddr);
5399 if ((ret_val == -E1000_ERR_NOLINK) ||
5400 (ret_val == -E1000_ERR_TIMEOUT)) {
5401 E1000_ERR(hw, "Valid Link not detected: %d\n", ret_val);
5403 E1000_ERR(hw, "Hardware Initialization Failed\n");
5407 e1000_configure_tx(hw);
5408 e1000_setup_rctl(hw);
5409 e1000_configure_rx(hw);
5413 /******************************************************************************
5414 * Gets the current PCI bus type of hardware
5416 * hw - Struct containing variables accessed by shared code
5417 *****************************************************************************/
5418 void e1000_get_bus_type(struct e1000_hw *hw)
5422 switch (hw->mac_type) {
5423 case e1000_82542_rev2_0:
5424 case e1000_82542_rev2_1:
5425 hw->bus_type = e1000_bus_type_pci;
5431 case e1000_80003es2lan:
5434 hw->bus_type = e1000_bus_type_pci_express;
5437 status = E1000_READ_REG(hw, STATUS);
5438 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5439 e1000_bus_type_pcix : e1000_bus_type_pci;
5444 static int e1000_init_one(struct e1000_hw *hw, int cardnum,
5445 struct udevice *devno, unsigned char enetaddr[6])
5449 /* Assign the passed-in values */
5451 hw->cardnum = cardnum;
5453 /* Print a debug message with the IO base address */
5454 dm_pci_read_config32(devno, PCI_BASE_ADDRESS_0, &val);
5455 E1000_DBG(hw, "iobase 0x%08x\n", val & 0xfffffff0);
5457 /* Try to enable I/O accesses and bus-mastering */
5458 val = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
5459 dm_pci_write_config32(devno, PCI_COMMAND, val);
5461 /* Make sure it worked */
5462 dm_pci_read_config32(devno, PCI_COMMAND, &val);
5463 if (!(val & PCI_COMMAND_MEMORY)) {
5464 E1000_ERR(hw, "Can't enable I/O memory\n");
5467 if (!(val & PCI_COMMAND_MASTER)) {
5468 E1000_ERR(hw, "Can't enable bus-mastering\n");
5472 /* Are these variables needed? */
5473 hw->fc = e1000_fc_default;
5474 hw->original_fc = e1000_fc_default;
5475 hw->autoneg_failed = 0;
5477 hw->get_link_status = true;
5478 #ifndef CONFIG_E1000_NO_NVM
5479 hw->eeprom_semaphore_present = true;
5481 hw->hw_addr = dm_pci_map_bar(devno, PCI_BASE_ADDRESS_0, 0, 0,
5482 PCI_REGION_TYPE, PCI_REGION_MEM);
5483 hw->mac_type = e1000_undefined;
5485 /* MAC and Phy settings */
5486 if (e1000_sw_init(hw) < 0) {
5487 E1000_ERR(hw, "Software init failed\n");
5490 if (e1000_check_phy_reset_block(hw))
5491 E1000_ERR(hw, "PHY Reset is blocked!\n");
5493 /* Basic init was OK, reset the hardware and allow SPI access */
5496 #ifndef CONFIG_E1000_NO_NVM
5497 /* Validate the EEPROM and get chipset information */
5498 if (e1000_init_eeprom_params(hw)) {
5499 E1000_ERR(hw, "EEPROM is invalid!\n");
5502 if ((E1000_READ_REG(hw, I210_EECD) & E1000_EECD_FLUPD) &&
5503 e1000_validate_eeprom_checksum(hw))
5505 e1000_read_mac_addr(hw, enetaddr);
5507 e1000_get_bus_type(hw);
5509 #ifndef CONFIG_E1000_NO_NVM
5510 printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n ",
5511 enetaddr[0], enetaddr[1], enetaddr[2],
5512 enetaddr[3], enetaddr[4], enetaddr[5]);
5514 memset(enetaddr, 0, 6);
5515 printf("e1000: no NVM\n");
5521 /* Put the name of a device in a string */
5522 static void e1000_name(char *str, int cardnum)
5524 sprintf(str, "e1000#%u", cardnum);
5527 static int e1000_write_hwaddr(struct udevice *dev)
5529 #ifndef CONFIG_E1000_NO_NVM
5530 unsigned char current_mac[6];
5531 struct eth_pdata *plat = dev_get_plat(dev);
5532 struct e1000_hw *hw = dev_get_priv(dev);
5533 u8 *mac = plat->enetaddr;
5537 DEBUGOUT("%s: mac=%pM\n", __func__, mac);
5539 if ((hw->eeprom.type == e1000_eeprom_invm) &&
5540 !(E1000_READ_REG(hw, EECD) & E1000_EECD_FLASH_DETECTED_I210))
5543 memset(current_mac, 0, 6);
5545 /* Read from EEPROM, not from registers, to make sure
5546 * the address is persistently configured
5548 ret_val = e1000_read_mac_addr_from_eeprom(hw, current_mac);
5549 DEBUGOUT("%s: current mac=%pM\n", __func__, current_mac);
5551 /* Only write to EEPROM if the given address is different or
5552 * reading the current address failed
5554 if (!ret_val && memcmp(current_mac, mac, 6) == 0)
5557 for (i = 0; i < 3; ++i)
5558 data[i] = mac[i * 2 + 1] << 8 | mac[i * 2];
5560 ret_val = e1000_write_eeprom_srwr(hw, 0x0, 3, data);
5563 ret_val = e1000_update_eeprom_checksum_i210(hw);
5571 #ifdef CONFIG_CMD_E1000
5572 static int do_e1000(struct cmd_tbl *cmdtp, int flag, int argc,
5575 unsigned char *mac = NULL;
5576 struct eth_pdata *plat;
5577 struct udevice *dev;
5580 #if defined(CONFIG_E1000_SPI)
5581 struct e1000_hw *hw;
5590 /* Make sure we can find the requested e1000 card */
5591 cardnum = dectoul(argv[1], NULL);
5592 e1000_name(name, cardnum);
5593 ret = uclass_get_device_by_name(UCLASS_ETH, name, &dev);
5595 plat = dev_get_plat(dev);
5596 mac = plat->enetaddr;
5599 printf("e1000: ERROR: No such device: e1000#%s\n", argv[1]);
5603 if (!strcmp(argv[2], "print-mac-address")) {
5604 printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
5605 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
5609 #ifdef CONFIG_E1000_SPI
5610 hw = dev_get_priv(dev);
5611 /* Handle the "SPI" subcommand */
5612 if (!strcmp(argv[2], "spi"))
5613 return do_e1000_spi(cmdtp, hw, argc - 3, argv + 3);
5621 e1000, 7, 0, do_e1000,
5622 "Intel e1000 controller management",
5623 /* */"<card#> print-mac-address\n"
5624 #ifdef CONFIG_E1000_SPI
5625 "e1000 <card#> spi show [<offset> [<length>]]\n"
5626 "e1000 <card#> spi dump <addr> <offset> <length>\n"
5627 "e1000 <card#> spi program <addr> <offset> <length>\n"
5628 "e1000 <card#> spi checksum [update]\n"
5630 " - Manage the Intel E1000 PCI device"
5632 #endif /* not CONFIG_CMD_E1000 */
5634 static int e1000_eth_start(struct udevice *dev)
5636 struct eth_pdata *plat = dev_get_plat(dev);
5637 struct e1000_hw *hw = dev_get_priv(dev);
5639 return _e1000_init(hw, plat->enetaddr);
5642 static void e1000_eth_stop(struct udevice *dev)
5644 struct e1000_hw *hw = dev_get_priv(dev);
5649 static int e1000_eth_send(struct udevice *dev, void *packet, int length)
5651 struct e1000_hw *hw = dev_get_priv(dev);
5654 ret = _e1000_transmit(hw, packet, length);
5656 return ret ? 0 : -ETIMEDOUT;
5659 static int e1000_eth_recv(struct udevice *dev, int flags, uchar **packetp)
5661 struct e1000_hw *hw = dev_get_priv(dev);
5664 len = _e1000_poll(hw);
5668 return len ? len : -EAGAIN;
5671 static int e1000_free_pkt(struct udevice *dev, uchar *packet, int length)
5673 struct e1000_hw *hw = dev_get_priv(dev);
5680 static int e1000_eth_probe(struct udevice *dev)
5682 struct eth_pdata *plat = dev_get_plat(dev);
5683 struct e1000_hw *hw = dev_get_priv(dev);
5686 hw->name = dev->name;
5687 ret = e1000_init_one(hw, trailing_strtol(dev->name),
5688 dev, plat->enetaddr);
5690 printf(pr_fmt("failed to initialize card: %d\n"), ret);
5697 static int e1000_eth_bind(struct udevice *dev)
5702 * A simple way to number the devices. When device tree is used this
5703 * is unnecessary, but when the device is just discovered on the PCI
5704 * bus we need a name. We could instead have the uclass figure out
5705 * which devices are different and number them.
5707 e1000_name(name, num_cards++);
5709 return device_set_name(dev, name);
5712 static const struct eth_ops e1000_eth_ops = {
5713 .start = e1000_eth_start,
5714 .send = e1000_eth_send,
5715 .recv = e1000_eth_recv,
5716 .stop = e1000_eth_stop,
5717 .free_pkt = e1000_free_pkt,
5718 .write_hwaddr = e1000_write_hwaddr,
5721 static const struct udevice_id e1000_eth_ids[] = {
5722 { .compatible = "intel,e1000" },
5726 U_BOOT_DRIVER(eth_e1000) = {
5727 .name = "eth_e1000",
5729 .of_match = e1000_eth_ids,
5730 .bind = e1000_eth_bind,
5731 .probe = e1000_eth_probe,
5732 .ops = &e1000_eth_ops,
5733 .priv_auto = sizeof(struct e1000_hw),
5734 .plat_auto = sizeof(struct eth_pdata),
5737 U_BOOT_PCI_DEVICE(eth_e1000, e1000_supported);