1 /**************************************************************************
2 Intel Pro 1000 for ppcboot/das-u-boot
3 Drivers are port from Intel's Linux driver e1000-4.3.15
4 and from Etherboot pro 1000 driver by mrakes at vivato dot net
5 tested on both gig copper and gig fiber boards
6 ***************************************************************************/
7 /*******************************************************************************
10 Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.
12 * SPDX-License-Identifier: GPL-2.0+
15 Linux NICS <linux.nics@intel.com>
16 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
18 *******************************************************************************/
20 * Copyright (C) Archway Digital Solutions.
22 * written by Chrsitopher Li <cli at arcyway dot com> or <chrisl at gnuchina dot org>
25 * Copyright (C) Linux Networx.
26 * Massive upgrade to work with the new intel gigabit NICs.
27 * <ebiederman at lnxi dot com>
29 * Copyright 2011 Freescale Semiconductor, Inc.
39 #define TOUT_LOOP 100000
42 #define virt_to_bus(devno, v) dm_pci_virt_to_mem(devno, (void *) (v))
43 #define bus_to_phys(devno, a) dm_pci_mem_to_phys(devno, a)
45 #define virt_to_bus(devno, v) pci_virt_to_mem(devno, (void *) (v))
46 #define bus_to_phys(devno, a) pci_mem_to_phys(devno, a)
49 #define E1000_DEFAULT_PCI_PBA 0x00000030
50 #define E1000_DEFAULT_PCIE_PBA 0x000a0026
52 /* NIC specific static variables go here */
54 /* Intel i210 needs the DMA descriptor rings aligned to 128b */
55 #define E1000_BUFFER_ALIGN 128
58 * TODO(sjg@chromium.org): Even with driver model we share these buffers.
59 * Concurrent receiving on multiple active Ethernet devices will not work.
60 * Normally U-Boot does not support this anyway. To fix it in this driver,
61 * move these buffers and the tx/rx pointers to struct e1000_hw.
63 DEFINE_ALIGN_BUFFER(struct e1000_tx_desc, tx_base, 16, E1000_BUFFER_ALIGN);
64 DEFINE_ALIGN_BUFFER(struct e1000_rx_desc, rx_base, 16, E1000_BUFFER_ALIGN);
65 DEFINE_ALIGN_BUFFER(unsigned char, packet, 4096, E1000_BUFFER_ALIGN);
68 static int rx_tail, rx_last;
70 static int num_cards; /* Number of E1000 devices seen so far */
73 static struct pci_device_id e1000_supported[] = {
74 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82542) },
75 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_FIBER) },
76 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_COPPER) },
77 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_COPPER) },
78 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_FIBER) },
79 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_COPPER) },
80 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_LOM) },
81 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM) },
82 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_COPPER) },
83 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545GM_COPPER) },
84 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_COPPER) },
85 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_FIBER) },
86 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_FIBER) },
87 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_COPPER) },
88 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM_LOM) },
89 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541ER) },
90 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541GI_LF) },
92 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_COPPER) },
93 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_FIBER) },
94 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES) },
95 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER) },
96 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571PT_QUAD_COPPER) },
97 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_FIBER) },
98 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER_LOWPROFILE) },
99 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_DUAL) },
100 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_QUAD) },
101 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_COPPER) },
102 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_FIBER) },
103 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_SERDES) },
104 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI) },
105 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E) },
106 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E_IAMT) },
107 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573L) },
108 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82574L) },
109 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_QUAD_COPPER_KSP3) },
110 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_DPT) },
111 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_DPT) },
112 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_SPT) },
113 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_SPT) },
114 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED) },
115 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED) },
116 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER) },
117 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_COPPER) },
118 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS) },
119 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES) },
120 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS) },
121 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_1000BASEKX) },
126 /* Function forward declarations */
127 static int e1000_setup_link(struct e1000_hw *hw);
128 static int e1000_setup_fiber_link(struct e1000_hw *hw);
129 static int e1000_setup_copper_link(struct e1000_hw *hw);
130 static int e1000_phy_setup_autoneg(struct e1000_hw *hw);
131 static void e1000_config_collision_dist(struct e1000_hw *hw);
132 static int e1000_config_mac_to_phy(struct e1000_hw *hw);
133 static int e1000_config_fc_after_link_up(struct e1000_hw *hw);
134 static int e1000_check_for_link(struct e1000_hw *hw);
135 static int e1000_wait_autoneg(struct e1000_hw *hw);
136 static int e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t * speed,
138 static int e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
139 uint16_t * phy_data);
140 static int e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
142 static int32_t e1000_phy_hw_reset(struct e1000_hw *hw);
143 static int e1000_phy_reset(struct e1000_hw *hw);
144 static int e1000_detect_gig_phy(struct e1000_hw *hw);
145 static void e1000_set_media_type(struct e1000_hw *hw);
147 static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
148 static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
149 static int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
151 #ifndef CONFIG_E1000_NO_NVM
152 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
153 static int32_t e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
156 /******************************************************************************
157 * Raises the EEPROM's clock input.
159 * hw - Struct containing variables accessed by shared code
160 * eecd - EECD's current value
161 *****************************************************************************/
162 void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
164 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
165 * wait 50 microseconds.
167 *eecd = *eecd | E1000_EECD_SK;
168 E1000_WRITE_REG(hw, EECD, *eecd);
169 E1000_WRITE_FLUSH(hw);
173 /******************************************************************************
174 * Lowers the EEPROM's clock input.
176 * hw - Struct containing variables accessed by shared code
177 * eecd - EECD's current value
178 *****************************************************************************/
179 void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
181 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
182 * wait 50 microseconds.
184 *eecd = *eecd & ~E1000_EECD_SK;
185 E1000_WRITE_REG(hw, EECD, *eecd);
186 E1000_WRITE_FLUSH(hw);
190 /******************************************************************************
191 * Shift data bits out to the EEPROM.
193 * hw - Struct containing variables accessed by shared code
194 * data - data to send to the EEPROM
195 * count - number of bits to shift out
196 *****************************************************************************/
198 e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count)
203 /* We need to shift "count" bits out to the EEPROM. So, value in the
204 * "data" parameter will be shifted out to the EEPROM one bit at a time.
205 * In order to do this, "data" must be broken down into bits.
207 mask = 0x01 << (count - 1);
208 eecd = E1000_READ_REG(hw, EECD);
209 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
211 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
212 * and then raising and then lowering the clock (the SK bit controls
213 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
214 * by setting "DI" to "0" and then raising and then lowering the clock.
216 eecd &= ~E1000_EECD_DI;
219 eecd |= E1000_EECD_DI;
221 E1000_WRITE_REG(hw, EECD, eecd);
222 E1000_WRITE_FLUSH(hw);
226 e1000_raise_ee_clk(hw, &eecd);
227 e1000_lower_ee_clk(hw, &eecd);
233 /* We leave the "DI" bit set to "0" when we leave this routine. */
234 eecd &= ~E1000_EECD_DI;
235 E1000_WRITE_REG(hw, EECD, eecd);
238 /******************************************************************************
239 * Shift data bits in from the EEPROM
241 * hw - Struct containing variables accessed by shared code
242 *****************************************************************************/
244 e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count)
250 /* In order to read a register from the EEPROM, we need to shift 'count'
251 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
252 * input to the EEPROM (setting the SK bit), and then reading the
253 * value of the "DO" bit. During this "shifting in" process the
254 * "DI" bit should always be clear.
257 eecd = E1000_READ_REG(hw, EECD);
259 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
262 for (i = 0; i < count; i++) {
264 e1000_raise_ee_clk(hw, &eecd);
266 eecd = E1000_READ_REG(hw, EECD);
268 eecd &= ~(E1000_EECD_DI);
269 if (eecd & E1000_EECD_DO)
272 e1000_lower_ee_clk(hw, &eecd);
278 /******************************************************************************
279 * Returns EEPROM to a "standby" state
281 * hw - Struct containing variables accessed by shared code
282 *****************************************************************************/
283 void e1000_standby_eeprom(struct e1000_hw *hw)
285 struct e1000_eeprom_info *eeprom = &hw->eeprom;
288 eecd = E1000_READ_REG(hw, EECD);
290 if (eeprom->type == e1000_eeprom_microwire) {
291 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
292 E1000_WRITE_REG(hw, EECD, eecd);
293 E1000_WRITE_FLUSH(hw);
294 udelay(eeprom->delay_usec);
297 eecd |= E1000_EECD_SK;
298 E1000_WRITE_REG(hw, EECD, eecd);
299 E1000_WRITE_FLUSH(hw);
300 udelay(eeprom->delay_usec);
303 eecd |= E1000_EECD_CS;
304 E1000_WRITE_REG(hw, EECD, eecd);
305 E1000_WRITE_FLUSH(hw);
306 udelay(eeprom->delay_usec);
309 eecd &= ~E1000_EECD_SK;
310 E1000_WRITE_REG(hw, EECD, eecd);
311 E1000_WRITE_FLUSH(hw);
312 udelay(eeprom->delay_usec);
313 } else if (eeprom->type == e1000_eeprom_spi) {
314 /* Toggle CS to flush commands */
315 eecd |= E1000_EECD_CS;
316 E1000_WRITE_REG(hw, EECD, eecd);
317 E1000_WRITE_FLUSH(hw);
318 udelay(eeprom->delay_usec);
319 eecd &= ~E1000_EECD_CS;
320 E1000_WRITE_REG(hw, EECD, eecd);
321 E1000_WRITE_FLUSH(hw);
322 udelay(eeprom->delay_usec);
326 /***************************************************************************
327 * Description: Determines if the onboard NVM is FLASH or EEPROM.
329 * hw - Struct containing variables accessed by shared code
330 ****************************************************************************/
331 static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
337 if (hw->mac_type == e1000_ich8lan)
340 if (hw->mac_type == e1000_82573 || hw->mac_type == e1000_82574) {
341 eecd = E1000_READ_REG(hw, EECD);
343 /* Isolate bits 15 & 16 */
344 eecd = ((eecd >> 15) & 0x03);
346 /* If both bits are set, device is Flash type */
353 /******************************************************************************
354 * Prepares EEPROM for access
356 * hw - Struct containing variables accessed by shared code
358 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
359 * function should be called before issuing a command to the EEPROM.
360 *****************************************************************************/
361 int32_t e1000_acquire_eeprom(struct e1000_hw *hw)
363 struct e1000_eeprom_info *eeprom = &hw->eeprom;
364 uint32_t eecd, i = 0;
368 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
369 return -E1000_ERR_SWFW_SYNC;
370 eecd = E1000_READ_REG(hw, EECD);
372 if (hw->mac_type != e1000_82573 && hw->mac_type != e1000_82574) {
373 /* Request EEPROM Access */
374 if (hw->mac_type > e1000_82544) {
375 eecd |= E1000_EECD_REQ;
376 E1000_WRITE_REG(hw, EECD, eecd);
377 eecd = E1000_READ_REG(hw, EECD);
378 while ((!(eecd & E1000_EECD_GNT)) &&
379 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
382 eecd = E1000_READ_REG(hw, EECD);
384 if (!(eecd & E1000_EECD_GNT)) {
385 eecd &= ~E1000_EECD_REQ;
386 E1000_WRITE_REG(hw, EECD, eecd);
387 DEBUGOUT("Could not acquire EEPROM grant\n");
388 return -E1000_ERR_EEPROM;
393 /* Setup EEPROM for Read/Write */
395 if (eeprom->type == e1000_eeprom_microwire) {
396 /* Clear SK and DI */
397 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
398 E1000_WRITE_REG(hw, EECD, eecd);
401 eecd |= E1000_EECD_CS;
402 E1000_WRITE_REG(hw, EECD, eecd);
403 } else if (eeprom->type == e1000_eeprom_spi) {
404 /* Clear SK and CS */
405 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
406 E1000_WRITE_REG(hw, EECD, eecd);
410 return E1000_SUCCESS;
413 /******************************************************************************
414 * Sets up eeprom variables in the hw struct. Must be called after mac_type
415 * is configured. Additionally, if this is ICH8, the flash controller GbE
416 * registers must be mapped, or this will crash.
418 * hw - Struct containing variables accessed by shared code
419 *****************************************************************************/
420 static int32_t e1000_init_eeprom_params(struct e1000_hw *hw)
422 struct e1000_eeprom_info *eeprom = &hw->eeprom;
424 int32_t ret_val = E1000_SUCCESS;
425 uint16_t eeprom_size;
427 if (hw->mac_type == e1000_igb)
428 eecd = E1000_READ_REG(hw, I210_EECD);
430 eecd = E1000_READ_REG(hw, EECD);
434 switch (hw->mac_type) {
435 case e1000_82542_rev2_0:
436 case e1000_82542_rev2_1:
439 eeprom->type = e1000_eeprom_microwire;
440 eeprom->word_size = 64;
441 eeprom->opcode_bits = 3;
442 eeprom->address_bits = 6;
443 eeprom->delay_usec = 50;
444 eeprom->use_eerd = false;
445 eeprom->use_eewr = false;
449 case e1000_82545_rev_3:
451 case e1000_82546_rev_3:
452 eeprom->type = e1000_eeprom_microwire;
453 eeprom->opcode_bits = 3;
454 eeprom->delay_usec = 50;
455 if (eecd & E1000_EECD_SIZE) {
456 eeprom->word_size = 256;
457 eeprom->address_bits = 8;
459 eeprom->word_size = 64;
460 eeprom->address_bits = 6;
462 eeprom->use_eerd = false;
463 eeprom->use_eewr = false;
466 case e1000_82541_rev_2:
468 case e1000_82547_rev_2:
469 if (eecd & E1000_EECD_TYPE) {
470 eeprom->type = e1000_eeprom_spi;
471 eeprom->opcode_bits = 8;
472 eeprom->delay_usec = 1;
473 if (eecd & E1000_EECD_ADDR_BITS) {
474 eeprom->page_size = 32;
475 eeprom->address_bits = 16;
477 eeprom->page_size = 8;
478 eeprom->address_bits = 8;
481 eeprom->type = e1000_eeprom_microwire;
482 eeprom->opcode_bits = 3;
483 eeprom->delay_usec = 50;
484 if (eecd & E1000_EECD_ADDR_BITS) {
485 eeprom->word_size = 256;
486 eeprom->address_bits = 8;
488 eeprom->word_size = 64;
489 eeprom->address_bits = 6;
492 eeprom->use_eerd = false;
493 eeprom->use_eewr = false;
497 eeprom->type = e1000_eeprom_spi;
498 eeprom->opcode_bits = 8;
499 eeprom->delay_usec = 1;
500 if (eecd & E1000_EECD_ADDR_BITS) {
501 eeprom->page_size = 32;
502 eeprom->address_bits = 16;
504 eeprom->page_size = 8;
505 eeprom->address_bits = 8;
507 eeprom->use_eerd = false;
508 eeprom->use_eewr = false;
512 eeprom->type = e1000_eeprom_spi;
513 eeprom->opcode_bits = 8;
514 eeprom->delay_usec = 1;
515 if (eecd & E1000_EECD_ADDR_BITS) {
516 eeprom->page_size = 32;
517 eeprom->address_bits = 16;
519 eeprom->page_size = 8;
520 eeprom->address_bits = 8;
522 if (e1000_is_onboard_nvm_eeprom(hw) == false) {
523 eeprom->use_eerd = true;
524 eeprom->use_eewr = true;
526 eeprom->type = e1000_eeprom_flash;
527 eeprom->word_size = 2048;
529 /* Ensure that the Autonomous FLASH update bit is cleared due to
530 * Flash update issue on parts which use a FLASH for NVM. */
531 eecd &= ~E1000_EECD_AUPDEN;
532 E1000_WRITE_REG(hw, EECD, eecd);
535 case e1000_80003es2lan:
536 eeprom->type = e1000_eeprom_spi;
537 eeprom->opcode_bits = 8;
538 eeprom->delay_usec = 1;
539 if (eecd & E1000_EECD_ADDR_BITS) {
540 eeprom->page_size = 32;
541 eeprom->address_bits = 16;
543 eeprom->page_size = 8;
544 eeprom->address_bits = 8;
546 eeprom->use_eerd = true;
547 eeprom->use_eewr = false;
550 /* i210 has 4k of iNVM mapped as EEPROM */
551 eeprom->type = e1000_eeprom_invm;
552 eeprom->opcode_bits = 8;
553 eeprom->delay_usec = 1;
554 eeprom->page_size = 32;
555 eeprom->address_bits = 16;
556 eeprom->use_eerd = true;
557 eeprom->use_eewr = false;
563 if (eeprom->type == e1000_eeprom_spi ||
564 eeprom->type == e1000_eeprom_invm) {
565 /* eeprom_size will be an enum [0..8] that maps
566 * to eeprom sizes 128B to
567 * 32KB (incremented by powers of 2).
569 if (hw->mac_type <= e1000_82547_rev_2) {
570 /* Set to default value for initial eeprom read. */
571 eeprom->word_size = 64;
572 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1,
576 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK)
577 >> EEPROM_SIZE_SHIFT;
578 /* 256B eeprom size was not supported in earlier
579 * hardware, so we bump eeprom_size up one to
580 * ensure that "1" (which maps to 256B) is never
581 * the result used in the shifting logic below. */
585 eeprom_size = (uint16_t)((eecd &
586 E1000_EECD_SIZE_EX_MASK) >>
587 E1000_EECD_SIZE_EX_SHIFT);
590 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
595 /******************************************************************************
596 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
598 * hw - Struct containing variables accessed by shared code
599 *****************************************************************************/
601 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
603 uint32_t attempts = 100000;
605 int32_t done = E1000_ERR_EEPROM;
607 for (i = 0; i < attempts; i++) {
608 if (eerd == E1000_EEPROM_POLL_READ) {
609 if (hw->mac_type == e1000_igb)
610 reg = E1000_READ_REG(hw, I210_EERD);
612 reg = E1000_READ_REG(hw, EERD);
614 if (hw->mac_type == e1000_igb)
615 reg = E1000_READ_REG(hw, I210_EEWR);
617 reg = E1000_READ_REG(hw, EEWR);
620 if (reg & E1000_EEPROM_RW_REG_DONE) {
621 done = E1000_SUCCESS;
630 /******************************************************************************
631 * Reads a 16 bit word from the EEPROM using the EERD register.
633 * hw - Struct containing variables accessed by shared code
634 * offset - offset of word in the EEPROM to read
635 * data - word read from the EEPROM
636 * words - number of words to read
637 *****************************************************************************/
639 e1000_read_eeprom_eerd(struct e1000_hw *hw,
644 uint32_t i, eerd = 0;
647 for (i = 0; i < words; i++) {
648 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
649 E1000_EEPROM_RW_REG_START;
651 if (hw->mac_type == e1000_igb)
652 E1000_WRITE_REG(hw, I210_EERD, eerd);
654 E1000_WRITE_REG(hw, EERD, eerd);
656 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
661 if (hw->mac_type == e1000_igb) {
662 data[i] = (E1000_READ_REG(hw, I210_EERD) >>
663 E1000_EEPROM_RW_REG_DATA);
665 data[i] = (E1000_READ_REG(hw, EERD) >>
666 E1000_EEPROM_RW_REG_DATA);
674 void e1000_release_eeprom(struct e1000_hw *hw)
680 eecd = E1000_READ_REG(hw, EECD);
682 if (hw->eeprom.type == e1000_eeprom_spi) {
683 eecd |= E1000_EECD_CS; /* Pull CS high */
684 eecd &= ~E1000_EECD_SK; /* Lower SCK */
686 E1000_WRITE_REG(hw, EECD, eecd);
688 udelay(hw->eeprom.delay_usec);
689 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
692 /* CS on Microwire is active-high */
693 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
695 E1000_WRITE_REG(hw, EECD, eecd);
697 /* Rising edge of clock */
698 eecd |= E1000_EECD_SK;
699 E1000_WRITE_REG(hw, EECD, eecd);
700 E1000_WRITE_FLUSH(hw);
701 udelay(hw->eeprom.delay_usec);
703 /* Falling edge of clock */
704 eecd &= ~E1000_EECD_SK;
705 E1000_WRITE_REG(hw, EECD, eecd);
706 E1000_WRITE_FLUSH(hw);
707 udelay(hw->eeprom.delay_usec);
710 /* Stop requesting EEPROM access */
711 if (hw->mac_type > e1000_82544) {
712 eecd &= ~E1000_EECD_REQ;
713 E1000_WRITE_REG(hw, EECD, eecd);
716 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
719 /******************************************************************************
720 * Reads a 16 bit word from the EEPROM.
722 * hw - Struct containing variables accessed by shared code
723 *****************************************************************************/
725 e1000_spi_eeprom_ready(struct e1000_hw *hw)
727 uint16_t retry_count = 0;
728 uint8_t spi_stat_reg;
732 /* Read "Status Register" repeatedly until the LSB is cleared. The
733 * EEPROM will signal that the command has been completed by clearing
734 * bit 0 of the internal status register. If it's not cleared within
735 * 5 milliseconds, then error out.
739 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
740 hw->eeprom.opcode_bits);
741 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
742 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
748 e1000_standby_eeprom(hw);
749 } while (retry_count < EEPROM_MAX_RETRY_SPI);
751 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
752 * only 0-5mSec on 5V devices)
754 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
755 DEBUGOUT("SPI EEPROM Status error\n");
756 return -E1000_ERR_EEPROM;
759 return E1000_SUCCESS;
762 /******************************************************************************
763 * Reads a 16 bit word from the EEPROM.
765 * hw - Struct containing variables accessed by shared code
766 * offset - offset of word in the EEPROM to read
767 * data - word read from the EEPROM
768 *****************************************************************************/
770 e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
771 uint16_t words, uint16_t *data)
773 struct e1000_eeprom_info *eeprom = &hw->eeprom;
778 /* If eeprom is not yet detected, do so now */
779 if (eeprom->word_size == 0)
780 e1000_init_eeprom_params(hw);
782 /* A check for invalid values: offset too large, too many words,
783 * and not enough words.
785 if ((offset >= eeprom->word_size) ||
786 (words > eeprom->word_size - offset) ||
788 DEBUGOUT("\"words\" parameter out of bounds."
789 "Words = %d, size = %d\n", offset, eeprom->word_size);
790 return -E1000_ERR_EEPROM;
793 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
794 * directly. In this case, we need to acquire the EEPROM so that
795 * FW or other port software does not interrupt.
797 if (e1000_is_onboard_nvm_eeprom(hw) == true &&
798 hw->eeprom.use_eerd == false) {
800 /* Prepare the EEPROM for bit-bang reading */
801 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
802 return -E1000_ERR_EEPROM;
805 /* Eerd register EEPROM access requires no eeprom aquire/release */
806 if (eeprom->use_eerd == true)
807 return e1000_read_eeprom_eerd(hw, offset, words, data);
809 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
810 * acquired the EEPROM at this point, so any returns should relase it */
811 if (eeprom->type == e1000_eeprom_spi) {
813 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
815 if (e1000_spi_eeprom_ready(hw)) {
816 e1000_release_eeprom(hw);
817 return -E1000_ERR_EEPROM;
820 e1000_standby_eeprom(hw);
822 /* Some SPI eeproms use the 8th address bit embedded in
824 if ((eeprom->address_bits == 8) && (offset >= 128))
825 read_opcode |= EEPROM_A8_OPCODE_SPI;
827 /* Send the READ command (opcode + addr) */
828 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
829 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2),
830 eeprom->address_bits);
832 /* Read the data. The address of the eeprom internally
833 * increments with each byte (spi) being read, saving on the
834 * overhead of eeprom setup and tear-down. The address
835 * counter will roll over if reading beyond the size of
836 * the eeprom, thus allowing the entire memory to be read
837 * starting from any offset. */
838 for (i = 0; i < words; i++) {
839 word_in = e1000_shift_in_ee_bits(hw, 16);
840 data[i] = (word_in >> 8) | (word_in << 8);
842 } else if (eeprom->type == e1000_eeprom_microwire) {
843 for (i = 0; i < words; i++) {
844 /* Send the READ command (opcode + addr) */
845 e1000_shift_out_ee_bits(hw,
846 EEPROM_READ_OPCODE_MICROWIRE,
847 eeprom->opcode_bits);
848 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
849 eeprom->address_bits);
851 /* Read the data. For microwire, each word requires
852 * the overhead of eeprom setup and tear-down. */
853 data[i] = e1000_shift_in_ee_bits(hw, 16);
854 e1000_standby_eeprom(hw);
858 /* End this read operation */
859 e1000_release_eeprom(hw);
861 return E1000_SUCCESS;
864 /******************************************************************************
865 * Verifies that the EEPROM has a valid checksum
867 * hw - Struct containing variables accessed by shared code
869 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
870 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
872 *****************************************************************************/
873 static int e1000_validate_eeprom_checksum(struct e1000_hw *hw)
875 uint16_t i, checksum, checksum_reg, *buf;
879 /* Allocate a temporary buffer */
880 buf = malloc(sizeof(buf[0]) * (EEPROM_CHECKSUM_REG + 1));
882 E1000_ERR(hw, "Unable to allocate EEPROM buffer!\n");
883 return -E1000_ERR_EEPROM;
886 /* Read the EEPROM */
887 if (e1000_read_eeprom(hw, 0, EEPROM_CHECKSUM_REG + 1, buf) < 0) {
888 E1000_ERR(hw, "Unable to read EEPROM!\n");
889 return -E1000_ERR_EEPROM;
892 /* Compute the checksum */
894 for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
896 checksum = ((uint16_t)EEPROM_SUM) - checksum;
897 checksum_reg = buf[i];
900 if (checksum == checksum_reg)
903 /* Hrm, verification failed, print an error */
904 E1000_ERR(hw, "EEPROM checksum is incorrect!\n");
905 E1000_ERR(hw, " ...register was 0x%04hx, calculated 0x%04hx\n",
906 checksum_reg, checksum);
908 return -E1000_ERR_EEPROM;
910 #endif /* CONFIG_E1000_NO_NVM */
912 /*****************************************************************************
913 * Set PHY to class A mode
914 * Assumes the following operations will follow to enable the new class mode.
915 * 1. Do a PHY soft reset
916 * 2. Restart auto-negotiation or force link.
918 * hw - Struct containing variables accessed by shared code
919 ****************************************************************************/
921 e1000_set_phy_mode(struct e1000_hw *hw)
923 #ifndef CONFIG_E1000_NO_NVM
925 uint16_t eeprom_data;
929 if ((hw->mac_type == e1000_82545_rev_3) &&
930 (hw->media_type == e1000_media_type_copper)) {
931 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD,
936 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
937 (eeprom_data & EEPROM_PHY_CLASS_A)) {
938 ret_val = e1000_write_phy_reg(hw,
939 M88E1000_PHY_PAGE_SELECT, 0x000B);
942 ret_val = e1000_write_phy_reg(hw,
943 M88E1000_PHY_GEN_CONTROL, 0x8104);
947 hw->phy_reset_disable = false;
951 return E1000_SUCCESS;
954 #ifndef CONFIG_E1000_NO_NVM
955 /***************************************************************************
957 * Obtaining software semaphore bit (SMBI) before resetting PHY.
959 * hw: Struct containing variables accessed by shared code
961 * returns: - E1000_ERR_RESET if fail to obtain semaphore.
962 * E1000_SUCCESS at any other case.
964 ***************************************************************************/
966 e1000_get_software_semaphore(struct e1000_hw *hw)
968 int32_t timeout = hw->eeprom.word_size + 1;
973 if (hw->mac_type != e1000_80003es2lan)
974 return E1000_SUCCESS;
977 swsm = E1000_READ_REG(hw, SWSM);
978 /* If SMBI bit cleared, it is now set and we hold
980 if (!(swsm & E1000_SWSM_SMBI))
987 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
988 return -E1000_ERR_RESET;
991 return E1000_SUCCESS;
995 /***************************************************************************
996 * This function clears HW semaphore bits.
998 * hw: Struct containing variables accessed by shared code
1002 ***************************************************************************/
1004 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
1006 #ifndef CONFIG_E1000_NO_NVM
1011 if (!hw->eeprom_semaphore_present)
1014 swsm = E1000_READ_REG(hw, SWSM);
1015 if (hw->mac_type == e1000_80003es2lan) {
1016 /* Release both semaphores. */
1017 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1019 swsm &= ~(E1000_SWSM_SWESMBI);
1020 E1000_WRITE_REG(hw, SWSM, swsm);
1024 /***************************************************************************
1026 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
1027 * adapter or Eeprom access.
1029 * hw: Struct containing variables accessed by shared code
1031 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
1032 * E1000_SUCCESS at any other case.
1034 ***************************************************************************/
1036 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
1038 #ifndef CONFIG_E1000_NO_NVM
1044 if (!hw->eeprom_semaphore_present)
1045 return E1000_SUCCESS;
1047 if (hw->mac_type == e1000_80003es2lan) {
1048 /* Get the SW semaphore. */
1049 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
1050 return -E1000_ERR_EEPROM;
1053 /* Get the FW semaphore. */
1054 timeout = hw->eeprom.word_size + 1;
1056 swsm = E1000_READ_REG(hw, SWSM);
1057 swsm |= E1000_SWSM_SWESMBI;
1058 E1000_WRITE_REG(hw, SWSM, swsm);
1059 /* if we managed to set the bit we got the semaphore. */
1060 swsm = E1000_READ_REG(hw, SWSM);
1061 if (swsm & E1000_SWSM_SWESMBI)
1069 /* Release semaphores */
1070 e1000_put_hw_eeprom_semaphore(hw);
1071 DEBUGOUT("Driver can't access the Eeprom - "
1072 "SWESMBI bit is set.\n");
1073 return -E1000_ERR_EEPROM;
1076 return E1000_SUCCESS;
1079 /* Take ownership of the PHY */
1081 e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
1083 uint32_t swfw_sync = 0;
1084 uint32_t swmask = mask;
1085 uint32_t fwmask = mask << 16;
1086 int32_t timeout = 200;
1090 if (e1000_get_hw_eeprom_semaphore(hw))
1091 return -E1000_ERR_SWFW_SYNC;
1093 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
1094 if (!(swfw_sync & (fwmask | swmask)))
1097 /* firmware currently using resource (fwmask) */
1098 /* or other software thread currently using resource (swmask) */
1099 e1000_put_hw_eeprom_semaphore(hw);
1105 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
1106 return -E1000_ERR_SWFW_SYNC;
1109 swfw_sync |= swmask;
1110 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
1112 e1000_put_hw_eeprom_semaphore(hw);
1113 return E1000_SUCCESS;
1116 static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
1118 uint32_t swfw_sync = 0;
1121 while (e1000_get_hw_eeprom_semaphore(hw))
1124 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
1126 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
1128 e1000_put_hw_eeprom_semaphore(hw);
1131 static bool e1000_is_second_port(struct e1000_hw *hw)
1133 switch (hw->mac_type) {
1134 case e1000_80003es2lan:
1137 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
1145 #ifndef CONFIG_E1000_NO_NVM
1146 /******************************************************************************
1147 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
1148 * second function of dual function devices
1150 * nic - Struct containing variables accessed by shared code
1151 *****************************************************************************/
1153 e1000_read_mac_addr(struct e1000_hw *hw, unsigned char enetaddr[6])
1156 uint16_t eeprom_data;
1157 uint32_t reg_data = 0;
1162 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
1164 if (hw->mac_type == e1000_igb) {
1165 /* i210 preloads MAC address into RAL/RAH registers */
1167 reg_data = E1000_READ_REG_ARRAY(hw, RA, 0);
1168 else if (offset == 1)
1170 else if (offset == 2)
1171 reg_data = E1000_READ_REG_ARRAY(hw, RA, 1);
1172 eeprom_data = reg_data & 0xffff;
1173 } else if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
1174 DEBUGOUT("EEPROM Read Error\n");
1175 return -E1000_ERR_EEPROM;
1177 enetaddr[i] = eeprom_data & 0xff;
1178 enetaddr[i + 1] = (eeprom_data >> 8) & 0xff;
1181 /* Invert the last bit if this is the second device */
1182 if (e1000_is_second_port(hw))
1189 /******************************************************************************
1190 * Initializes receive address filters.
1192 * hw - Struct containing variables accessed by shared code
1194 * Places the MAC address in receive address register 0 and clears the rest
1195 * of the receive addresss registers. Clears the multicast table. Assumes
1196 * the receiver is in reset when the routine is called.
1197 *****************************************************************************/
1199 e1000_init_rx_addrs(struct e1000_hw *hw, unsigned char enetaddr[6])
1207 /* Setup the receive address. */
1208 DEBUGOUT("Programming MAC Address into RAR[0]\n");
1209 addr_low = (enetaddr[0] |
1210 (enetaddr[1] << 8) |
1211 (enetaddr[2] << 16) | (enetaddr[3] << 24));
1213 addr_high = (enetaddr[4] | (enetaddr[5] << 8) | E1000_RAH_AV);
1215 E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
1216 E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
1218 /* Zero out the other 15 receive addresses. */
1219 DEBUGOUT("Clearing RAR[1-15]\n");
1220 for (i = 1; i < E1000_RAR_ENTRIES; i++) {
1221 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
1222 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
1226 /******************************************************************************
1227 * Clears the VLAN filer table
1229 * hw - Struct containing variables accessed by shared code
1230 *****************************************************************************/
1232 e1000_clear_vfta(struct e1000_hw *hw)
1236 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
1237 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
1240 /******************************************************************************
1241 * Set the mac type member in the hw struct.
1243 * hw - Struct containing variables accessed by shared code
1244 *****************************************************************************/
1246 e1000_set_mac_type(struct e1000_hw *hw)
1250 switch (hw->device_id) {
1251 case E1000_DEV_ID_82542:
1252 switch (hw->revision_id) {
1253 case E1000_82542_2_0_REV_ID:
1254 hw->mac_type = e1000_82542_rev2_0;
1256 case E1000_82542_2_1_REV_ID:
1257 hw->mac_type = e1000_82542_rev2_1;
1260 /* Invalid 82542 revision ID */
1261 return -E1000_ERR_MAC_TYPE;
1264 case E1000_DEV_ID_82543GC_FIBER:
1265 case E1000_DEV_ID_82543GC_COPPER:
1266 hw->mac_type = e1000_82543;
1268 case E1000_DEV_ID_82544EI_COPPER:
1269 case E1000_DEV_ID_82544EI_FIBER:
1270 case E1000_DEV_ID_82544GC_COPPER:
1271 case E1000_DEV_ID_82544GC_LOM:
1272 hw->mac_type = e1000_82544;
1274 case E1000_DEV_ID_82540EM:
1275 case E1000_DEV_ID_82540EM_LOM:
1276 case E1000_DEV_ID_82540EP:
1277 case E1000_DEV_ID_82540EP_LOM:
1278 case E1000_DEV_ID_82540EP_LP:
1279 hw->mac_type = e1000_82540;
1281 case E1000_DEV_ID_82545EM_COPPER:
1282 case E1000_DEV_ID_82545EM_FIBER:
1283 hw->mac_type = e1000_82545;
1285 case E1000_DEV_ID_82545GM_COPPER:
1286 case E1000_DEV_ID_82545GM_FIBER:
1287 case E1000_DEV_ID_82545GM_SERDES:
1288 hw->mac_type = e1000_82545_rev_3;
1290 case E1000_DEV_ID_82546EB_COPPER:
1291 case E1000_DEV_ID_82546EB_FIBER:
1292 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1293 hw->mac_type = e1000_82546;
1295 case E1000_DEV_ID_82546GB_COPPER:
1296 case E1000_DEV_ID_82546GB_FIBER:
1297 case E1000_DEV_ID_82546GB_SERDES:
1298 case E1000_DEV_ID_82546GB_PCIE:
1299 case E1000_DEV_ID_82546GB_QUAD_COPPER:
1300 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1301 hw->mac_type = e1000_82546_rev_3;
1303 case E1000_DEV_ID_82541EI:
1304 case E1000_DEV_ID_82541EI_MOBILE:
1305 case E1000_DEV_ID_82541ER_LOM:
1306 hw->mac_type = e1000_82541;
1308 case E1000_DEV_ID_82541ER:
1309 case E1000_DEV_ID_82541GI:
1310 case E1000_DEV_ID_82541GI_LF:
1311 case E1000_DEV_ID_82541GI_MOBILE:
1312 hw->mac_type = e1000_82541_rev_2;
1314 case E1000_DEV_ID_82547EI:
1315 case E1000_DEV_ID_82547EI_MOBILE:
1316 hw->mac_type = e1000_82547;
1318 case E1000_DEV_ID_82547GI:
1319 hw->mac_type = e1000_82547_rev_2;
1321 case E1000_DEV_ID_82571EB_COPPER:
1322 case E1000_DEV_ID_82571EB_FIBER:
1323 case E1000_DEV_ID_82571EB_SERDES:
1324 case E1000_DEV_ID_82571EB_SERDES_DUAL:
1325 case E1000_DEV_ID_82571EB_SERDES_QUAD:
1326 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1327 case E1000_DEV_ID_82571PT_QUAD_COPPER:
1328 case E1000_DEV_ID_82571EB_QUAD_FIBER:
1329 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1330 hw->mac_type = e1000_82571;
1332 case E1000_DEV_ID_82572EI_COPPER:
1333 case E1000_DEV_ID_82572EI_FIBER:
1334 case E1000_DEV_ID_82572EI_SERDES:
1335 case E1000_DEV_ID_82572EI:
1336 hw->mac_type = e1000_82572;
1338 case E1000_DEV_ID_82573E:
1339 case E1000_DEV_ID_82573E_IAMT:
1340 case E1000_DEV_ID_82573L:
1341 hw->mac_type = e1000_82573;
1343 case E1000_DEV_ID_82574L:
1344 hw->mac_type = e1000_82574;
1346 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
1347 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
1348 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
1349 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
1350 hw->mac_type = e1000_80003es2lan;
1352 case E1000_DEV_ID_ICH8_IGP_M_AMT:
1353 case E1000_DEV_ID_ICH8_IGP_AMT:
1354 case E1000_DEV_ID_ICH8_IGP_C:
1355 case E1000_DEV_ID_ICH8_IFE:
1356 case E1000_DEV_ID_ICH8_IFE_GT:
1357 case E1000_DEV_ID_ICH8_IFE_G:
1358 case E1000_DEV_ID_ICH8_IGP_M:
1359 hw->mac_type = e1000_ich8lan;
1361 case PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED:
1362 case PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED:
1363 case PCI_DEVICE_ID_INTEL_I210_COPPER:
1364 case PCI_DEVICE_ID_INTEL_I211_COPPER:
1365 case PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS:
1366 case PCI_DEVICE_ID_INTEL_I210_SERDES:
1367 case PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS:
1368 case PCI_DEVICE_ID_INTEL_I210_1000BASEKX:
1369 hw->mac_type = e1000_igb;
1372 /* Should never have loaded on this device */
1373 return -E1000_ERR_MAC_TYPE;
1375 return E1000_SUCCESS;
1378 /******************************************************************************
1379 * Reset the transmit and receive units; mask and clear all interrupts.
1381 * hw - Struct containing variables accessed by shared code
1382 *****************************************************************************/
1384 e1000_reset_hw(struct e1000_hw *hw)
1394 /* get the correct pba value for both PCI and PCIe*/
1395 if (hw->mac_type < e1000_82571)
1396 pba = E1000_DEFAULT_PCI_PBA;
1398 pba = E1000_DEFAULT_PCIE_PBA;
1400 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
1401 if (hw->mac_type == e1000_82542_rev2_0) {
1402 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1403 #ifdef CONFIG_DM_ETH
1404 dm_pci_write_config16(hw->pdev, PCI_COMMAND,
1405 hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1407 pci_write_config_word(hw->pdev, PCI_COMMAND,
1408 hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1412 /* Clear interrupt mask to stop board from generating interrupts */
1413 DEBUGOUT("Masking off all interrupts\n");
1414 if (hw->mac_type == e1000_igb)
1415 E1000_WRITE_REG(hw, I210_IAM, 0);
1416 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1418 /* Disable the Transmit and Receive units. Then delay to allow
1419 * any pending transactions to complete before we hit the MAC with
1422 E1000_WRITE_REG(hw, RCTL, 0);
1423 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
1424 E1000_WRITE_FLUSH(hw);
1426 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
1427 hw->tbi_compatibility_on = false;
1429 /* Delay to allow any outstanding PCI transactions to complete before
1430 * resetting the device
1434 /* Issue a global reset to the MAC. This will reset the chip's
1435 * transmit, receive, DMA, and link units. It will not effect
1436 * the current PCI configuration. The global reset bit is self-
1437 * clearing, and should clear within a microsecond.
1439 DEBUGOUT("Issuing a global reset to MAC\n");
1440 ctrl = E1000_READ_REG(hw, CTRL);
1442 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
1444 /* Force a reload from the EEPROM if necessary */
1445 if (hw->mac_type == e1000_igb) {
1447 reg = E1000_READ_REG(hw, STATUS);
1448 if (reg & E1000_STATUS_PF_RST_DONE)
1449 DEBUGOUT("PF OK\n");
1450 reg = E1000_READ_REG(hw, I210_EECD);
1451 if (reg & E1000_EECD_AUTO_RD)
1452 DEBUGOUT("EEC OK\n");
1453 } else if (hw->mac_type < e1000_82540) {
1454 /* Wait for reset to complete */
1456 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1457 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1458 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1459 E1000_WRITE_FLUSH(hw);
1460 /* Wait for EEPROM reload */
1463 /* Wait for EEPROM reload (it happens automatically) */
1465 /* Dissable HW ARPs on ASF enabled adapters */
1466 manc = E1000_READ_REG(hw, MANC);
1467 manc &= ~(E1000_MANC_ARP_EN);
1468 E1000_WRITE_REG(hw, MANC, manc);
1471 /* Clear interrupt mask to stop board from generating interrupts */
1472 DEBUGOUT("Masking off all interrupts\n");
1473 if (hw->mac_type == e1000_igb)
1474 E1000_WRITE_REG(hw, I210_IAM, 0);
1475 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1477 /* Clear any pending interrupt events. */
1478 E1000_READ_REG(hw, ICR);
1480 /* If MWI was previously enabled, reenable it. */
1481 if (hw->mac_type == e1000_82542_rev2_0) {
1482 #ifdef CONFIG_DM_ETH
1483 dm_pci_write_config16(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1485 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1488 if (hw->mac_type != e1000_igb)
1489 E1000_WRITE_REG(hw, PBA, pba);
1492 /******************************************************************************
1494 * Initialize a number of hardware-dependent bits
1496 * hw: Struct containing variables accessed by shared code
1498 * This function contains hardware limitation workarounds for PCI-E adapters
1500 *****************************************************************************/
1502 e1000_initialize_hardware_bits(struct e1000_hw *hw)
1504 if ((hw->mac_type >= e1000_82571) &&
1505 (!hw->initialize_hw_bits_disable)) {
1506 /* Settings common to all PCI-express silicon */
1507 uint32_t reg_ctrl, reg_ctrl_ext;
1508 uint32_t reg_tarc0, reg_tarc1;
1510 uint32_t reg_txdctl, reg_txdctl1;
1512 /* link autonegotiation/sync workarounds */
1513 reg_tarc0 = E1000_READ_REG(hw, TARC0);
1514 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
1516 /* Enable not-done TX descriptor counting */
1517 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
1518 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
1519 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
1521 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
1522 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
1523 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
1526 switch (hw->mac_type) {
1527 case e1000_igb: /* IGB is cool */
1531 /* Clear PHY TX compatible mode bits */
1532 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1533 reg_tarc1 &= ~((1 << 30)|(1 << 29));
1535 /* link autonegotiation/sync workarounds */
1536 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
1538 /* TX ring control fixes */
1539 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
1541 /* Multiple read bit is reversed polarity */
1542 reg_tctl = E1000_READ_REG(hw, TCTL);
1543 if (reg_tctl & E1000_TCTL_MULR)
1544 reg_tarc1 &= ~(1 << 28);
1546 reg_tarc1 |= (1 << 28);
1548 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1552 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1553 reg_ctrl_ext &= ~(1 << 23);
1554 reg_ctrl_ext |= (1 << 22);
1556 /* TX byte count fix */
1557 reg_ctrl = E1000_READ_REG(hw, CTRL);
1558 reg_ctrl &= ~(1 << 29);
1560 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1561 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
1563 case e1000_80003es2lan:
1564 /* improve small packet performace for fiber/serdes */
1565 if ((hw->media_type == e1000_media_type_fiber)
1566 || (hw->media_type ==
1567 e1000_media_type_internal_serdes)) {
1568 reg_tarc0 &= ~(1 << 20);
1571 /* Multiple read bit is reversed polarity */
1572 reg_tctl = E1000_READ_REG(hw, TCTL);
1573 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1574 if (reg_tctl & E1000_TCTL_MULR)
1575 reg_tarc1 &= ~(1 << 28);
1577 reg_tarc1 |= (1 << 28);
1579 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1582 /* Reduce concurrent DMA requests to 3 from 4 */
1583 if ((hw->revision_id < 3) ||
1584 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1585 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
1586 reg_tarc0 |= ((1 << 29)|(1 << 28));
1588 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1589 reg_ctrl_ext |= (1 << 22);
1590 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1592 /* workaround TX hang with TSO=on */
1593 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
1595 /* Multiple read bit is reversed polarity */
1596 reg_tctl = E1000_READ_REG(hw, TCTL);
1597 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1598 if (reg_tctl & E1000_TCTL_MULR)
1599 reg_tarc1 &= ~(1 << 28);
1601 reg_tarc1 |= (1 << 28);
1603 /* workaround TX hang with TSO=on */
1604 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
1606 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1612 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
1616 /******************************************************************************
1617 * Performs basic configuration of the adapter.
1619 * hw - Struct containing variables accessed by shared code
1621 * Assumes that the controller has previously been reset and is in a
1622 * post-reset uninitialized state. Initializes the receive address registers,
1623 * multicast table, and VLAN filter table. Calls routines to setup link
1624 * configuration and flow control settings. Clears all on-chip counters. Leaves
1625 * the transmit and receive units disabled and uninitialized.
1626 *****************************************************************************/
1628 e1000_init_hw(struct e1000_hw *hw, unsigned char enetaddr[6])
1633 uint16_t pcix_cmd_word;
1634 uint16_t pcix_stat_hi_word;
1636 uint16_t stat_mmrbc;
1641 /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
1642 if ((hw->mac_type == e1000_ich8lan) &&
1643 ((hw->revision_id < 3) ||
1644 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1645 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
1646 reg_data = E1000_READ_REG(hw, STATUS);
1647 reg_data &= ~0x80000000;
1648 E1000_WRITE_REG(hw, STATUS, reg_data);
1650 /* Do not need initialize Identification LED */
1652 /* Set the media type and TBI compatibility */
1653 e1000_set_media_type(hw);
1655 /* Must be called after e1000_set_media_type
1656 * because media_type is used */
1657 e1000_initialize_hardware_bits(hw);
1659 /* Disabling VLAN filtering. */
1660 DEBUGOUT("Initializing the IEEE VLAN\n");
1661 /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
1662 if (hw->mac_type != e1000_ich8lan) {
1663 if (hw->mac_type < e1000_82545_rev_3)
1664 E1000_WRITE_REG(hw, VET, 0);
1665 e1000_clear_vfta(hw);
1668 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
1669 if (hw->mac_type == e1000_82542_rev2_0) {
1670 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1671 #ifdef CONFIG_DM_ETH
1672 dm_pci_write_config16(hw->pdev, PCI_COMMAND,
1674 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1676 pci_write_config_word(hw->pdev, PCI_COMMAND,
1678 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1680 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
1681 E1000_WRITE_FLUSH(hw);
1685 /* Setup the receive address. This involves initializing all of the Receive
1686 * Address Registers (RARs 0 - 15).
1688 e1000_init_rx_addrs(hw, enetaddr);
1690 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
1691 if (hw->mac_type == e1000_82542_rev2_0) {
1692 E1000_WRITE_REG(hw, RCTL, 0);
1693 E1000_WRITE_FLUSH(hw);
1695 #ifdef CONFIG_DM_ETH
1696 dm_pci_write_config16(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1698 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1702 /* Zero out the Multicast HASH table */
1703 DEBUGOUT("Zeroing the MTA\n");
1704 mta_size = E1000_MC_TBL_SIZE;
1705 if (hw->mac_type == e1000_ich8lan)
1706 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
1707 for (i = 0; i < mta_size; i++) {
1708 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
1709 /* use write flush to prevent Memory Write Block (MWB) from
1710 * occuring when accessing our register space */
1711 E1000_WRITE_FLUSH(hw);
1714 switch (hw->mac_type) {
1715 case e1000_82545_rev_3:
1716 case e1000_82546_rev_3:
1720 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
1721 if (hw->bus_type == e1000_bus_type_pcix) {
1722 #ifdef CONFIG_DM_ETH
1723 dm_pci_read_config16(hw->pdev, PCIX_COMMAND_REGISTER,
1725 dm_pci_read_config16(hw->pdev, PCIX_STATUS_REGISTER_HI,
1726 &pcix_stat_hi_word);
1728 pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
1730 pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI,
1731 &pcix_stat_hi_word);
1734 (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
1735 PCIX_COMMAND_MMRBC_SHIFT;
1737 (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
1738 PCIX_STATUS_HI_MMRBC_SHIFT;
1739 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
1740 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
1741 if (cmd_mmrbc > stat_mmrbc) {
1742 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
1743 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
1744 #ifdef CONFIG_DM_ETH
1745 dm_pci_write_config16(hw->pdev, PCIX_COMMAND_REGISTER,
1748 pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
1756 /* More time needed for PHY to initialize */
1757 if (hw->mac_type == e1000_ich8lan)
1759 if (hw->mac_type == e1000_igb)
1762 /* Call a subroutine to configure the link and setup flow control. */
1763 ret_val = e1000_setup_link(hw);
1765 /* Set the transmit descriptor write-back policy */
1766 if (hw->mac_type > e1000_82544) {
1767 ctrl = E1000_READ_REG(hw, TXDCTL);
1769 (ctrl & ~E1000_TXDCTL_WTHRESH) |
1770 E1000_TXDCTL_FULL_TX_DESC_WB;
1771 E1000_WRITE_REG(hw, TXDCTL, ctrl);
1774 /* Set the receive descriptor write back policy */
1775 if (hw->mac_type >= e1000_82571) {
1776 ctrl = E1000_READ_REG(hw, RXDCTL);
1778 (ctrl & ~E1000_RXDCTL_WTHRESH) |
1779 E1000_RXDCTL_FULL_RX_DESC_WB;
1780 E1000_WRITE_REG(hw, RXDCTL, ctrl);
1783 switch (hw->mac_type) {
1786 case e1000_80003es2lan:
1787 /* Enable retransmit on late collisions */
1788 reg_data = E1000_READ_REG(hw, TCTL);
1789 reg_data |= E1000_TCTL_RTLC;
1790 E1000_WRITE_REG(hw, TCTL, reg_data);
1792 /* Configure Gigabit Carry Extend Padding */
1793 reg_data = E1000_READ_REG(hw, TCTL_EXT);
1794 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
1795 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
1796 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
1798 /* Configure Transmit Inter-Packet Gap */
1799 reg_data = E1000_READ_REG(hw, TIPG);
1800 reg_data &= ~E1000_TIPG_IPGT_MASK;
1801 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
1802 E1000_WRITE_REG(hw, TIPG, reg_data);
1804 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
1805 reg_data &= ~0x00100000;
1806 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
1811 ctrl = E1000_READ_REG(hw, TXDCTL1);
1812 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH)
1813 | E1000_TXDCTL_FULL_TX_DESC_WB;
1814 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
1818 reg_data = E1000_READ_REG(hw, GCR);
1819 reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
1820 E1000_WRITE_REG(hw, GCR, reg_data);
1825 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
1826 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
1827 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1828 /* Relaxed ordering must be disabled to avoid a parity
1829 * error crash in a PCI slot. */
1830 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
1831 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1837 /******************************************************************************
1838 * Configures flow control and link settings.
1840 * hw - Struct containing variables accessed by shared code
1842 * Determines which flow control settings to use. Calls the apropriate media-
1843 * specific link configuration function. Configures the flow control settings.
1844 * Assuming the adapter has a valid link partner, a valid link should be
1845 * established. Assumes the hardware has previously been reset and the
1846 * transmitter and receiver are not enabled.
1847 *****************************************************************************/
1849 e1000_setup_link(struct e1000_hw *hw)
1852 #ifndef CONFIG_E1000_NO_NVM
1854 uint16_t eeprom_data;
1859 /* In the case of the phy reset being blocked, we already have a link.
1860 * We do not have to set it up again. */
1861 if (e1000_check_phy_reset_block(hw))
1862 return E1000_SUCCESS;
1864 #ifndef CONFIG_E1000_NO_NVM
1865 /* Read and store word 0x0F of the EEPROM. This word contains bits
1866 * that determine the hardware's default PAUSE (flow control) mode,
1867 * a bit that determines whether the HW defaults to enabling or
1868 * disabling auto-negotiation, and the direction of the
1869 * SW defined pins. If there is no SW over-ride of the flow
1870 * control setting, then the variable hw->fc will
1871 * be initialized based on a value in the EEPROM.
1873 if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1,
1874 &eeprom_data) < 0) {
1875 DEBUGOUT("EEPROM Read Error\n");
1876 return -E1000_ERR_EEPROM;
1879 if (hw->fc == e1000_fc_default) {
1880 switch (hw->mac_type) {
1885 hw->fc = e1000_fc_full;
1888 #ifndef CONFIG_E1000_NO_NVM
1889 ret_val = e1000_read_eeprom(hw,
1890 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1892 DEBUGOUT("EEPROM Read Error\n");
1893 return -E1000_ERR_EEPROM;
1895 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
1896 hw->fc = e1000_fc_none;
1897 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
1898 EEPROM_WORD0F_ASM_DIR)
1899 hw->fc = e1000_fc_tx_pause;
1902 hw->fc = e1000_fc_full;
1907 /* We want to save off the original Flow Control configuration just
1908 * in case we get disconnected and then reconnected into a different
1909 * hub or switch with different Flow Control capabilities.
1911 if (hw->mac_type == e1000_82542_rev2_0)
1912 hw->fc &= (~e1000_fc_tx_pause);
1914 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
1915 hw->fc &= (~e1000_fc_rx_pause);
1917 hw->original_fc = hw->fc;
1919 DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc);
1921 #ifndef CONFIG_E1000_NO_NVM
1922 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
1923 * polarity value for the SW controlled pins, and setup the
1924 * Extended Device Control reg with that info.
1925 * This is needed because one of the SW controlled pins is used for
1926 * signal detection. So this should be done before e1000_setup_pcs_link()
1927 * or e1000_phy_setup() is called.
1929 if (hw->mac_type == e1000_82543) {
1930 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
1932 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1936 /* Call the necessary subroutine to configure the link. */
1937 ret_val = (hw->media_type == e1000_media_type_fiber) ?
1938 e1000_setup_fiber_link(hw) : e1000_setup_copper_link(hw);
1943 /* Initialize the flow control address, type, and PAUSE timer
1944 * registers to their default values. This is done even if flow
1945 * control is disabled, because it does not hurt anything to
1946 * initialize these registers.
1948 DEBUGOUT("Initializing the Flow Control address, type"
1949 "and timer regs\n");
1951 /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
1952 if (hw->mac_type != e1000_ich8lan) {
1953 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
1954 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
1955 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
1958 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
1960 /* Set the flow control receive threshold registers. Normally,
1961 * these registers will be set to a default threshold that may be
1962 * adjusted later by the driver's runtime code. However, if the
1963 * ability to transmit pause frames in not enabled, then these
1964 * registers will be set to 0.
1966 if (!(hw->fc & e1000_fc_tx_pause)) {
1967 E1000_WRITE_REG(hw, FCRTL, 0);
1968 E1000_WRITE_REG(hw, FCRTH, 0);
1970 /* We need to set up the Receive Threshold high and low water marks
1971 * as well as (optionally) enabling the transmission of XON frames.
1973 if (hw->fc_send_xon) {
1974 E1000_WRITE_REG(hw, FCRTL,
1975 (hw->fc_low_water | E1000_FCRTL_XONE));
1976 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1978 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
1979 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
1985 /******************************************************************************
1986 * Sets up link for a fiber based adapter
1988 * hw - Struct containing variables accessed by shared code
1990 * Manipulates Physical Coding Sublayer functions in order to configure
1991 * link. Assumes the hardware has been previously reset and the transmitter
1992 * and receiver are not enabled.
1993 *****************************************************************************/
1995 e1000_setup_fiber_link(struct e1000_hw *hw)
2005 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
2006 * set when the optics detect a signal. On older adapters, it will be
2007 * cleared when there is a signal
2009 ctrl = E1000_READ_REG(hw, CTRL);
2010 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
2011 signal = E1000_CTRL_SWDPIN1;
2015 printf("signal for %s is %x (ctrl %08x)!!!!\n", hw->name, signal,
2017 /* Take the link out of reset */
2018 ctrl &= ~(E1000_CTRL_LRST);
2020 e1000_config_collision_dist(hw);
2022 /* Check for a software override of the flow control settings, and setup
2023 * the device accordingly. If auto-negotiation is enabled, then software
2024 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
2025 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
2026 * auto-negotiation is disabled, then software will have to manually
2027 * configure the two flow control enable bits in the CTRL register.
2029 * The possible values of the "fc" parameter are:
2030 * 0: Flow control is completely disabled
2031 * 1: Rx flow control is enabled (we can receive pause frames, but
2032 * not send pause frames).
2033 * 2: Tx flow control is enabled (we can send pause frames but we do
2034 * not support receiving pause frames).
2035 * 3: Both Rx and TX flow control (symmetric) are enabled.
2039 /* Flow control is completely disabled by a software over-ride. */
2040 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
2042 case e1000_fc_rx_pause:
2043 /* RX Flow control is enabled and TX Flow control is disabled by a
2044 * software over-ride. Since there really isn't a way to advertise
2045 * that we are capable of RX Pause ONLY, we will advertise that we
2046 * support both symmetric and asymmetric RX PAUSE. Later, we will
2047 * disable the adapter's ability to send PAUSE frames.
2049 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
2051 case e1000_fc_tx_pause:
2052 /* TX Flow control is enabled, and RX Flow control is disabled, by a
2053 * software over-ride.
2055 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
2058 /* Flow control (both RX and TX) is enabled by a software over-ride. */
2059 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
2062 DEBUGOUT("Flow control param set incorrectly\n");
2063 return -E1000_ERR_CONFIG;
2067 /* Since auto-negotiation is enabled, take the link out of reset (the link
2068 * will be in reset, because we previously reset the chip). This will
2069 * restart auto-negotiation. If auto-neogtiation is successful then the
2070 * link-up status bit will be set and the flow control enable bits (RFCE
2071 * and TFCE) will be set according to their negotiated value.
2073 DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw);
2075 E1000_WRITE_REG(hw, TXCW, txcw);
2076 E1000_WRITE_REG(hw, CTRL, ctrl);
2077 E1000_WRITE_FLUSH(hw);
2082 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
2083 * indication in the Device Status Register. Time-out if a link isn't
2084 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
2085 * less than 500 milliseconds even if the other end is doing it in SW).
2087 if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
2088 DEBUGOUT("Looking for Link\n");
2089 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
2091 status = E1000_READ_REG(hw, STATUS);
2092 if (status & E1000_STATUS_LU)
2095 if (i == (LINK_UP_TIMEOUT / 10)) {
2096 /* AutoNeg failed to achieve a link, so we'll call
2097 * e1000_check_for_link. This routine will force the link up if we
2098 * detect a signal. This will allow us to communicate with
2099 * non-autonegotiating link partners.
2101 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
2102 hw->autoneg_failed = 1;
2103 ret_val = e1000_check_for_link(hw);
2105 DEBUGOUT("Error while checking for link\n");
2108 hw->autoneg_failed = 0;
2110 hw->autoneg_failed = 0;
2111 DEBUGOUT("Valid Link Found\n");
2114 DEBUGOUT("No Signal Detected\n");
2115 return -E1000_ERR_NOLINK;
2120 /******************************************************************************
2121 * Make sure we have a valid PHY and change PHY mode before link setup.
2123 * hw - Struct containing variables accessed by shared code
2124 ******************************************************************************/
2126 e1000_copper_link_preconfig(struct e1000_hw *hw)
2134 ctrl = E1000_READ_REG(hw, CTRL);
2135 /* With 82543, we need to force speed and duplex on the MAC equal to what
2136 * the PHY speed and duplex configuration is. In addition, we need to
2137 * perform a hardware reset on the PHY to take it out of reset.
2139 if (hw->mac_type > e1000_82543) {
2140 ctrl |= E1000_CTRL_SLU;
2141 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2142 E1000_WRITE_REG(hw, CTRL, ctrl);
2144 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX
2146 E1000_WRITE_REG(hw, CTRL, ctrl);
2147 ret_val = e1000_phy_hw_reset(hw);
2152 /* Make sure we have a valid PHY */
2153 ret_val = e1000_detect_gig_phy(hw);
2155 DEBUGOUT("Error, did not detect valid phy.\n");
2158 DEBUGOUT("Phy ID = %x\n", hw->phy_id);
2160 /* Set PHY to class A mode (if necessary) */
2161 ret_val = e1000_set_phy_mode(hw);
2164 if ((hw->mac_type == e1000_82545_rev_3) ||
2165 (hw->mac_type == e1000_82546_rev_3)) {
2166 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2168 phy_data |= 0x00000008;
2169 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2173 if (hw->mac_type <= e1000_82543 ||
2174 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
2175 hw->mac_type == e1000_82541_rev_2
2176 || hw->mac_type == e1000_82547_rev_2)
2177 hw->phy_reset_disable = false;
2179 return E1000_SUCCESS;
2182 /*****************************************************************************
2184 * This function sets the lplu state according to the active flag. When
2185 * activating lplu this function also disables smart speed and vise versa.
2186 * lplu will not be activated unless the device autonegotiation advertisment
2187 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2188 * hw: Struct containing variables accessed by shared code
2189 * active - true to enable lplu false to disable lplu.
2191 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2192 * E1000_SUCCESS at any other case.
2194 ****************************************************************************/
2197 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
2199 uint32_t phy_ctrl = 0;
2204 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
2205 && hw->phy_type != e1000_phy_igp_3)
2206 return E1000_SUCCESS;
2208 /* During driver activity LPLU should not be used or it will attain link
2209 * from the lowest speeds starting from 10Mbps. The capability is used
2210 * for Dx transitions and states */
2211 if (hw->mac_type == e1000_82541_rev_2
2212 || hw->mac_type == e1000_82547_rev_2) {
2213 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
2217 } else if (hw->mac_type == e1000_ich8lan) {
2218 /* MAC writes into PHY register based on the state transition
2219 * and start auto-negotiation. SW driver can overwrite the
2220 * settings in CSR PHY power control E1000_PHY_CTRL register. */
2221 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
2223 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2230 if (hw->mac_type == e1000_82541_rev_2 ||
2231 hw->mac_type == e1000_82547_rev_2) {
2232 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
2233 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
2238 if (hw->mac_type == e1000_ich8lan) {
2239 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2240 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2242 phy_data &= ~IGP02E1000_PM_D3_LPLU;
2243 ret_val = e1000_write_phy_reg(hw,
2244 IGP02E1000_PHY_POWER_MGMT, phy_data);
2250 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2251 * Dx states where the power conservation is most important. During
2252 * driver activity we should enable SmartSpeed, so performance is
2254 if (hw->smart_speed == e1000_smart_speed_on) {
2255 ret_val = e1000_read_phy_reg(hw,
2256 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2260 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2261 ret_val = e1000_write_phy_reg(hw,
2262 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2265 } else if (hw->smart_speed == e1000_smart_speed_off) {
2266 ret_val = e1000_read_phy_reg(hw,
2267 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2271 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2272 ret_val = e1000_write_phy_reg(hw,
2273 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2278 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
2279 || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) ||
2280 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
2282 if (hw->mac_type == e1000_82541_rev_2 ||
2283 hw->mac_type == e1000_82547_rev_2) {
2284 phy_data |= IGP01E1000_GMII_FLEX_SPD;
2285 ret_val = e1000_write_phy_reg(hw,
2286 IGP01E1000_GMII_FIFO, phy_data);
2290 if (hw->mac_type == e1000_ich8lan) {
2291 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2292 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2294 phy_data |= IGP02E1000_PM_D3_LPLU;
2295 ret_val = e1000_write_phy_reg(hw,
2296 IGP02E1000_PHY_POWER_MGMT, phy_data);
2302 /* When LPLU is enabled we should disable SmartSpeed */
2303 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2308 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2309 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2314 return E1000_SUCCESS;
2317 /*****************************************************************************
2319 * This function sets the lplu d0 state according to the active flag. When
2320 * activating lplu this function also disables smart speed and vise versa.
2321 * lplu will not be activated unless the device autonegotiation advertisment
2322 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
2323 * hw: Struct containing variables accessed by shared code
2324 * active - true to enable lplu false to disable lplu.
2326 * returns: - E1000_ERR_PHY if fail to read/write the PHY
2327 * E1000_SUCCESS at any other case.
2329 ****************************************************************************/
2332 e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
2334 uint32_t phy_ctrl = 0;
2339 if (hw->mac_type <= e1000_82547_rev_2)
2340 return E1000_SUCCESS;
2342 if (hw->mac_type == e1000_ich8lan) {
2343 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
2344 } else if (hw->mac_type == e1000_igb) {
2345 phy_ctrl = E1000_READ_REG(hw, I210_PHY_CTRL);
2347 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2354 if (hw->mac_type == e1000_ich8lan) {
2355 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2356 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2357 } else if (hw->mac_type == e1000_igb) {
2358 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2359 E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
2361 phy_data &= ~IGP02E1000_PM_D0_LPLU;
2362 ret_val = e1000_write_phy_reg(hw,
2363 IGP02E1000_PHY_POWER_MGMT, phy_data);
2368 if (hw->mac_type == e1000_igb)
2369 return E1000_SUCCESS;
2371 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
2372 * Dx states where the power conservation is most important. During
2373 * driver activity we should enable SmartSpeed, so performance is
2375 if (hw->smart_speed == e1000_smart_speed_on) {
2376 ret_val = e1000_read_phy_reg(hw,
2377 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2381 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2382 ret_val = e1000_write_phy_reg(hw,
2383 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2386 } else if (hw->smart_speed == e1000_smart_speed_off) {
2387 ret_val = e1000_read_phy_reg(hw,
2388 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2392 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2393 ret_val = e1000_write_phy_reg(hw,
2394 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2402 if (hw->mac_type == e1000_ich8lan) {
2403 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2404 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2405 } else if (hw->mac_type == e1000_igb) {
2406 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2407 E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
2409 phy_data |= IGP02E1000_PM_D0_LPLU;
2410 ret_val = e1000_write_phy_reg(hw,
2411 IGP02E1000_PHY_POWER_MGMT, phy_data);
2416 if (hw->mac_type == e1000_igb)
2417 return E1000_SUCCESS;
2419 /* When LPLU is enabled we should disable SmartSpeed */
2420 ret_val = e1000_read_phy_reg(hw,
2421 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2425 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2426 ret_val = e1000_write_phy_reg(hw,
2427 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2432 return E1000_SUCCESS;
2435 /********************************************************************
2436 * Copper link setup for e1000_phy_igp series.
2438 * hw - Struct containing variables accessed by shared code
2439 *********************************************************************/
2441 e1000_copper_link_igp_setup(struct e1000_hw *hw)
2449 if (hw->phy_reset_disable)
2450 return E1000_SUCCESS;
2452 ret_val = e1000_phy_reset(hw);
2454 DEBUGOUT("Error Resetting the PHY\n");
2458 /* Wait 15ms for MAC to configure PHY from eeprom settings */
2460 if (hw->mac_type != e1000_ich8lan) {
2461 /* Configure activity LED after PHY reset */
2462 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2463 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2464 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2465 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2468 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
2469 if (hw->phy_type == e1000_phy_igp) {
2470 /* disable lplu d3 during driver init */
2471 ret_val = e1000_set_d3_lplu_state(hw, false);
2473 DEBUGOUT("Error Disabling LPLU D3\n");
2478 /* disable lplu d0 during driver init */
2479 ret_val = e1000_set_d0_lplu_state(hw, false);
2481 DEBUGOUT("Error Disabling LPLU D0\n");
2484 /* Configure mdi-mdix settings */
2485 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2489 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2490 hw->dsp_config_state = e1000_dsp_config_disabled;
2491 /* Force MDI for earlier revs of the IGP PHY */
2492 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX
2493 | IGP01E1000_PSCR_FORCE_MDI_MDIX);
2497 hw->dsp_config_state = e1000_dsp_config_enabled;
2498 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2502 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2505 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
2509 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
2513 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2517 /* set auto-master slave resolution settings */
2519 e1000_ms_type phy_ms_setting = hw->master_slave;
2521 if (hw->ffe_config_state == e1000_ffe_config_active)
2522 hw->ffe_config_state = e1000_ffe_config_enabled;
2524 if (hw->dsp_config_state == e1000_dsp_config_activated)
2525 hw->dsp_config_state = e1000_dsp_config_enabled;
2527 /* when autonegotiation advertisment is only 1000Mbps then we
2528 * should disable SmartSpeed and enable Auto MasterSlave
2529 * resolution as hardware default. */
2530 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
2531 /* Disable SmartSpeed */
2532 ret_val = e1000_read_phy_reg(hw,
2533 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2536 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2537 ret_val = e1000_write_phy_reg(hw,
2538 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2541 /* Set auto Master/Slave resolution process */
2542 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
2546 phy_data &= ~CR_1000T_MS_ENABLE;
2547 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
2553 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
2557 /* load defaults for future use */
2558 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
2559 ((phy_data & CR_1000T_MS_VALUE) ?
2560 e1000_ms_force_master :
2561 e1000_ms_force_slave) :
2564 switch (phy_ms_setting) {
2565 case e1000_ms_force_master:
2566 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
2568 case e1000_ms_force_slave:
2569 phy_data |= CR_1000T_MS_ENABLE;
2570 phy_data &= ~(CR_1000T_MS_VALUE);
2573 phy_data &= ~CR_1000T_MS_ENABLE;
2577 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
2582 return E1000_SUCCESS;
2585 /*****************************************************************************
2586 * This function checks the mode of the firmware.
2588 * returns - true when the mode is IAMT or false.
2589 ****************************************************************************/
2591 e1000_check_mng_mode(struct e1000_hw *hw)
2596 fwsm = E1000_READ_REG(hw, FWSM);
2598 if (hw->mac_type == e1000_ich8lan) {
2599 if ((fwsm & E1000_FWSM_MODE_MASK) ==
2600 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
2602 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
2603 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
2610 e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data)
2612 uint16_t swfw = E1000_SWFW_PHY0_SM;
2616 if (e1000_is_second_port(hw))
2617 swfw = E1000_SWFW_PHY1_SM;
2619 if (e1000_swfw_sync_acquire(hw, swfw))
2620 return -E1000_ERR_SWFW_SYNC;
2622 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT)
2623 & E1000_KUMCTRLSTA_OFFSET) | data;
2624 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2627 return E1000_SUCCESS;
2631 e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data)
2633 uint16_t swfw = E1000_SWFW_PHY0_SM;
2637 if (e1000_is_second_port(hw))
2638 swfw = E1000_SWFW_PHY1_SM;
2640 if (e1000_swfw_sync_acquire(hw, swfw)) {
2641 debug("%s[%i]\n", __func__, __LINE__);
2642 return -E1000_ERR_SWFW_SYNC;
2645 /* Write register address */
2646 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
2647 E1000_KUMCTRLSTA_OFFSET) | E1000_KUMCTRLSTA_REN;
2648 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2651 /* Read the data returned */
2652 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
2653 *data = (uint16_t)reg_val;
2655 return E1000_SUCCESS;
2658 /********************************************************************
2659 * Copper link setup for e1000_phy_gg82563 series.
2661 * hw - Struct containing variables accessed by shared code
2662 *********************************************************************/
2664 e1000_copper_link_ggp_setup(struct e1000_hw *hw)
2672 if (!hw->phy_reset_disable) {
2673 /* Enable CRS on TX for half-duplex operation. */
2674 ret_val = e1000_read_phy_reg(hw,
2675 GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2679 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2680 /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
2681 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
2683 ret_val = e1000_write_phy_reg(hw,
2684 GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2689 * MDI/MDI-X = 0 (default)
2690 * 0 - Auto for all speeds
2693 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
2695 ret_val = e1000_read_phy_reg(hw,
2696 GG82563_PHY_SPEC_CTRL, &phy_data);
2700 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
2704 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
2707 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
2711 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
2716 * disable_polarity_correction = 0 (default)
2717 * Automatic Correction for Reversed Cable Polarity
2721 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
2722 ret_val = e1000_write_phy_reg(hw,
2723 GG82563_PHY_SPEC_CTRL, phy_data);
2728 /* SW Reset the PHY so all changes take effect */
2729 ret_val = e1000_phy_reset(hw);
2731 DEBUGOUT("Error Resetting the PHY\n");
2734 } /* phy_reset_disable */
2736 if (hw->mac_type == e1000_80003es2lan) {
2737 /* Bypass RX and TX FIFO's */
2738 ret_val = e1000_write_kmrn_reg(hw,
2739 E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
2740 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS
2741 | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
2745 ret_val = e1000_read_phy_reg(hw,
2746 GG82563_PHY_SPEC_CTRL_2, &phy_data);
2750 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
2751 ret_val = e1000_write_phy_reg(hw,
2752 GG82563_PHY_SPEC_CTRL_2, phy_data);
2757 reg_data = E1000_READ_REG(hw, CTRL_EXT);
2758 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
2759 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
2761 ret_val = e1000_read_phy_reg(hw,
2762 GG82563_PHY_PWR_MGMT_CTRL, &phy_data);
2766 /* Do not init these registers when the HW is in IAMT mode, since the
2767 * firmware will have already initialized them. We only initialize
2768 * them if the HW is not in IAMT mode.
2770 if (e1000_check_mng_mode(hw) == false) {
2771 /* Enable Electrical Idle on the PHY */
2772 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
2773 ret_val = e1000_write_phy_reg(hw,
2774 GG82563_PHY_PWR_MGMT_CTRL, phy_data);
2778 ret_val = e1000_read_phy_reg(hw,
2779 GG82563_PHY_KMRN_MODE_CTRL, &phy_data);
2783 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2784 ret_val = e1000_write_phy_reg(hw,
2785 GG82563_PHY_KMRN_MODE_CTRL, phy_data);
2791 /* Workaround: Disable padding in Kumeran interface in the MAC
2792 * and in the PHY to avoid CRC errors.
2794 ret_val = e1000_read_phy_reg(hw,
2795 GG82563_PHY_INBAND_CTRL, &phy_data);
2798 phy_data |= GG82563_ICR_DIS_PADDING;
2799 ret_val = e1000_write_phy_reg(hw,
2800 GG82563_PHY_INBAND_CTRL, phy_data);
2804 return E1000_SUCCESS;
2807 /********************************************************************
2808 * Copper link setup for e1000_phy_m88 series.
2810 * hw - Struct containing variables accessed by shared code
2811 *********************************************************************/
2813 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
2820 if (hw->phy_reset_disable)
2821 return E1000_SUCCESS;
2823 /* Enable CRS on TX. This must be set for half-duplex operation. */
2824 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2828 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
2831 * MDI/MDI-X = 0 (default)
2832 * 0 - Auto for all speeds
2835 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
2837 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
2841 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
2844 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
2847 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
2851 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
2856 * disable_polarity_correction = 0 (default)
2857 * Automatic Correction for Reversed Cable Polarity
2861 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
2862 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
2866 if (hw->phy_revision < M88E1011_I_REV_4) {
2867 /* Force TX_CLK in the Extended PHY Specific Control Register
2870 ret_val = e1000_read_phy_reg(hw,
2871 M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
2875 phy_data |= M88E1000_EPSCR_TX_CLK_25;
2877 if ((hw->phy_revision == E1000_REVISION_2) &&
2878 (hw->phy_id == M88E1111_I_PHY_ID)) {
2879 /* Vidalia Phy, set the downshift counter to 5x */
2880 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
2881 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
2882 ret_val = e1000_write_phy_reg(hw,
2883 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2887 /* Configure Master and Slave downshift values */
2888 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK
2889 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
2890 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X
2891 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
2892 ret_val = e1000_write_phy_reg(hw,
2893 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
2899 /* SW Reset the PHY so all changes take effect */
2900 ret_val = e1000_phy_reset(hw);
2902 DEBUGOUT("Error Resetting the PHY\n");
2906 return E1000_SUCCESS;
2909 /********************************************************************
2910 * Setup auto-negotiation and flow control advertisements,
2911 * and then perform auto-negotiation.
2913 * hw - Struct containing variables accessed by shared code
2914 *********************************************************************/
2916 e1000_copper_link_autoneg(struct e1000_hw *hw)
2923 /* Perform some bounds checking on the hw->autoneg_advertised
2924 * parameter. If this variable is zero, then set it to the default.
2926 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
2928 /* If autoneg_advertised is zero, we assume it was not defaulted
2929 * by the calling code so we set to advertise full capability.
2931 if (hw->autoneg_advertised == 0)
2932 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
2934 /* IFE phy only supports 10/100 */
2935 if (hw->phy_type == e1000_phy_ife)
2936 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
2938 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
2939 ret_val = e1000_phy_setup_autoneg(hw);
2941 DEBUGOUT("Error Setting up Auto-Negotiation\n");
2944 DEBUGOUT("Restarting Auto-Neg\n");
2946 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
2947 * the Auto Neg Restart bit in the PHY control register.
2949 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2953 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
2954 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
2958 /* Does the user want to wait for Auto-Neg to complete here, or
2959 * check at a later time (for example, callback routine).
2961 /* If we do not wait for autonegtation to complete I
2962 * do not see a valid link status.
2963 * wait_autoneg_complete = 1 .
2965 if (hw->wait_autoneg_complete) {
2966 ret_val = e1000_wait_autoneg(hw);
2968 DEBUGOUT("Error while waiting for autoneg"
2974 hw->get_link_status = true;
2976 return E1000_SUCCESS;
2979 /******************************************************************************
2980 * Config the MAC and the PHY after link is up.
2981 * 1) Set up the MAC to the current PHY speed/duplex
2982 * if we are on 82543. If we
2983 * are on newer silicon, we only need to configure
2984 * collision distance in the Transmit Control Register.
2985 * 2) Set up flow control on the MAC to that established with
2987 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
2989 * hw - Struct containing variables accessed by shared code
2990 ******************************************************************************/
2992 e1000_copper_link_postconfig(struct e1000_hw *hw)
2997 if (hw->mac_type >= e1000_82544) {
2998 e1000_config_collision_dist(hw);
3000 ret_val = e1000_config_mac_to_phy(hw);
3002 DEBUGOUT("Error configuring MAC to PHY settings\n");
3006 ret_val = e1000_config_fc_after_link_up(hw);
3008 DEBUGOUT("Error Configuring Flow Control\n");
3011 return E1000_SUCCESS;
3014 /******************************************************************************
3015 * Detects which PHY is present and setup the speed and duplex
3017 * hw - Struct containing variables accessed by shared code
3018 ******************************************************************************/
3020 e1000_setup_copper_link(struct e1000_hw *hw)
3029 switch (hw->mac_type) {
3030 case e1000_80003es2lan:
3032 /* Set the mac to wait the maximum time between each
3033 * iteration and increase the max iterations when
3034 * polling the phy; this fixes erroneous timeouts at 10Mbps. */
3035 ret_val = e1000_write_kmrn_reg(hw,
3036 GG82563_REG(0x34, 4), 0xFFFF);
3039 ret_val = e1000_read_kmrn_reg(hw,
3040 GG82563_REG(0x34, 9), ®_data);
3044 ret_val = e1000_write_kmrn_reg(hw,
3045 GG82563_REG(0x34, 9), reg_data);
3052 /* Check if it is a valid PHY and set PHY mode if necessary. */
3053 ret_val = e1000_copper_link_preconfig(hw);
3056 switch (hw->mac_type) {
3057 case e1000_80003es2lan:
3058 /* Kumeran registers are written-only */
3060 E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
3061 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
3062 ret_val = e1000_write_kmrn_reg(hw,
3063 E1000_KUMCTRLSTA_OFFSET_INB_CTRL, reg_data);
3071 if (hw->phy_type == e1000_phy_igp ||
3072 hw->phy_type == e1000_phy_igp_3 ||
3073 hw->phy_type == e1000_phy_igp_2) {
3074 ret_val = e1000_copper_link_igp_setup(hw);
3077 } else if (hw->phy_type == e1000_phy_m88 ||
3078 hw->phy_type == e1000_phy_igb) {
3079 ret_val = e1000_copper_link_mgp_setup(hw);
3082 } else if (hw->phy_type == e1000_phy_gg82563) {
3083 ret_val = e1000_copper_link_ggp_setup(hw);
3089 /* Setup autoneg and flow control advertisement
3090 * and perform autonegotiation */
3091 ret_val = e1000_copper_link_autoneg(hw);
3095 /* Check link status. Wait up to 100 microseconds for link to become
3098 for (i = 0; i < 10; i++) {
3099 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3102 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3106 if (phy_data & MII_SR_LINK_STATUS) {
3107 /* Config the MAC and PHY after link is up */
3108 ret_val = e1000_copper_link_postconfig(hw);
3112 DEBUGOUT("Valid link established!!!\n");
3113 return E1000_SUCCESS;
3118 DEBUGOUT("Unable to establish link!!!\n");
3119 return E1000_SUCCESS;
3122 /******************************************************************************
3123 * Configures PHY autoneg and flow control advertisement settings
3125 * hw - Struct containing variables accessed by shared code
3126 ******************************************************************************/
3128 e1000_phy_setup_autoneg(struct e1000_hw *hw)
3131 uint16_t mii_autoneg_adv_reg;
3132 uint16_t mii_1000t_ctrl_reg;
3136 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
3137 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
3141 if (hw->phy_type != e1000_phy_ife) {
3142 /* Read the MII 1000Base-T Control Register (Address 9). */
3143 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
3144 &mii_1000t_ctrl_reg);
3148 mii_1000t_ctrl_reg = 0;
3150 /* Need to parse both autoneg_advertised and fc and set up
3151 * the appropriate PHY registers. First we will parse for
3152 * autoneg_advertised software override. Since we can advertise
3153 * a plethora of combinations, we need to check each bit
3157 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
3158 * Advertisement Register (Address 4) and the 1000 mb speed bits in
3159 * the 1000Base-T Control Register (Address 9).
3161 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
3162 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
3164 DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised);
3166 /* Do we want to advertise 10 Mb Half Duplex? */
3167 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
3168 DEBUGOUT("Advertise 10mb Half duplex\n");
3169 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
3172 /* Do we want to advertise 10 Mb Full Duplex? */
3173 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
3174 DEBUGOUT("Advertise 10mb Full duplex\n");
3175 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
3178 /* Do we want to advertise 100 Mb Half Duplex? */
3179 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
3180 DEBUGOUT("Advertise 100mb Half duplex\n");
3181 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
3184 /* Do we want to advertise 100 Mb Full Duplex? */
3185 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
3186 DEBUGOUT("Advertise 100mb Full duplex\n");
3187 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
3190 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
3191 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
3193 ("Advertise 1000mb Half duplex requested, request denied!\n");
3196 /* Do we want to advertise 1000 Mb Full Duplex? */
3197 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
3198 DEBUGOUT("Advertise 1000mb Full duplex\n");
3199 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
3202 /* Check for a software override of the flow control settings, and
3203 * setup the PHY advertisement registers accordingly. If
3204 * auto-negotiation is enabled, then software will have to set the
3205 * "PAUSE" bits to the correct value in the Auto-Negotiation
3206 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
3208 * The possible values of the "fc" parameter are:
3209 * 0: Flow control is completely disabled
3210 * 1: Rx flow control is enabled (we can receive pause frames
3211 * but not send pause frames).
3212 * 2: Tx flow control is enabled (we can send pause frames
3213 * but we do not support receiving pause frames).
3214 * 3: Both Rx and TX flow control (symmetric) are enabled.
3215 * other: No software override. The flow control configuration
3216 * in the EEPROM is used.
3219 case e1000_fc_none: /* 0 */
3220 /* Flow control (RX & TX) is completely disabled by a
3221 * software over-ride.
3223 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3225 case e1000_fc_rx_pause: /* 1 */
3226 /* RX Flow control is enabled, and TX Flow control is
3227 * disabled, by a software over-ride.
3229 /* Since there really isn't a way to advertise that we are
3230 * capable of RX Pause ONLY, we will advertise that we
3231 * support both symmetric and asymmetric RX PAUSE. Later
3232 * (in e1000_config_fc_after_link_up) we will disable the
3233 *hw's ability to send PAUSE frames.
3235 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3237 case e1000_fc_tx_pause: /* 2 */
3238 /* TX Flow control is enabled, and RX Flow control is
3239 * disabled, by a software over-ride.
3241 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
3242 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
3244 case e1000_fc_full: /* 3 */
3245 /* Flow control (both RX and TX) is enabled by a software
3248 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3251 DEBUGOUT("Flow control param set incorrectly\n");
3252 return -E1000_ERR_CONFIG;
3255 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
3259 DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
3261 if (hw->phy_type != e1000_phy_ife) {
3262 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
3263 mii_1000t_ctrl_reg);
3268 return E1000_SUCCESS;
3271 /******************************************************************************
3272 * Sets the collision distance in the Transmit Control register
3274 * hw - Struct containing variables accessed by shared code
3276 * Link should have been established previously. Reads the speed and duplex
3277 * information from the Device Status register.
3278 ******************************************************************************/
3280 e1000_config_collision_dist(struct e1000_hw *hw)
3282 uint32_t tctl, coll_dist;
3286 if (hw->mac_type < e1000_82543)
3287 coll_dist = E1000_COLLISION_DISTANCE_82542;
3289 coll_dist = E1000_COLLISION_DISTANCE;
3291 tctl = E1000_READ_REG(hw, TCTL);
3293 tctl &= ~E1000_TCTL_COLD;
3294 tctl |= coll_dist << E1000_COLD_SHIFT;
3296 E1000_WRITE_REG(hw, TCTL, tctl);
3297 E1000_WRITE_FLUSH(hw);
3300 /******************************************************************************
3301 * Sets MAC speed and duplex settings to reflect the those in the PHY
3303 * hw - Struct containing variables accessed by shared code
3304 * mii_reg - data to write to the MII control register
3306 * The contents of the PHY register containing the needed information need to
3308 ******************************************************************************/
3310 e1000_config_mac_to_phy(struct e1000_hw *hw)
3317 /* Read the Device Control Register and set the bits to Force Speed
3320 ctrl = E1000_READ_REG(hw, CTRL);
3321 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3322 ctrl &= ~(E1000_CTRL_ILOS);
3323 ctrl |= (E1000_CTRL_SPD_SEL);
3325 /* Set up duplex in the Device Control and Transmit Control
3326 * registers depending on negotiated values.
3328 if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
3329 DEBUGOUT("PHY Read Error\n");
3330 return -E1000_ERR_PHY;
3332 if (phy_data & M88E1000_PSSR_DPLX)
3333 ctrl |= E1000_CTRL_FD;
3335 ctrl &= ~E1000_CTRL_FD;
3337 e1000_config_collision_dist(hw);
3339 /* Set up speed in the Device Control register depending on
3340 * negotiated values.
3342 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
3343 ctrl |= E1000_CTRL_SPD_1000;
3344 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
3345 ctrl |= E1000_CTRL_SPD_100;
3346 /* Write the configured values back to the Device Control Reg. */
3347 E1000_WRITE_REG(hw, CTRL, ctrl);
3351 /******************************************************************************
3352 * Forces the MAC's flow control settings.
3354 * hw - Struct containing variables accessed by shared code
3356 * Sets the TFCE and RFCE bits in the device control register to reflect
3357 * the adapter settings. TFCE and RFCE need to be explicitly set by
3358 * software when a Copper PHY is used because autonegotiation is managed
3359 * by the PHY rather than the MAC. Software must also configure these
3360 * bits when link is forced on a fiber connection.
3361 *****************************************************************************/
3363 e1000_force_mac_fc(struct e1000_hw *hw)
3369 /* Get the current configuration of the Device Control Register */
3370 ctrl = E1000_READ_REG(hw, CTRL);
3372 /* Because we didn't get link via the internal auto-negotiation
3373 * mechanism (we either forced link or we got link via PHY
3374 * auto-neg), we have to manually enable/disable transmit an
3375 * receive flow control.
3377 * The "Case" statement below enables/disable flow control
3378 * according to the "hw->fc" parameter.
3380 * The possible values of the "fc" parameter are:
3381 * 0: Flow control is completely disabled
3382 * 1: Rx flow control is enabled (we can receive pause
3383 * frames but not send pause frames).
3384 * 2: Tx flow control is enabled (we can send pause frames
3385 * frames but we do not receive pause frames).
3386 * 3: Both Rx and TX flow control (symmetric) is enabled.
3387 * other: No other values should be possible at this point.
3392 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
3394 case e1000_fc_rx_pause:
3395 ctrl &= (~E1000_CTRL_TFCE);
3396 ctrl |= E1000_CTRL_RFCE;
3398 case e1000_fc_tx_pause:
3399 ctrl &= (~E1000_CTRL_RFCE);
3400 ctrl |= E1000_CTRL_TFCE;
3403 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
3406 DEBUGOUT("Flow control param set incorrectly\n");
3407 return -E1000_ERR_CONFIG;
3410 /* Disable TX Flow Control for 82542 (rev 2.0) */
3411 if (hw->mac_type == e1000_82542_rev2_0)
3412 ctrl &= (~E1000_CTRL_TFCE);
3414 E1000_WRITE_REG(hw, CTRL, ctrl);
3418 /******************************************************************************
3419 * Configures flow control settings after link is established
3421 * hw - Struct containing variables accessed by shared code
3423 * Should be called immediately after a valid link has been established.
3424 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
3425 * and autonegotiation is enabled, the MAC flow control settings will be set
3426 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
3427 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
3428 *****************************************************************************/
3430 e1000_config_fc_after_link_up(struct e1000_hw *hw)
3433 uint16_t mii_status_reg;
3434 uint16_t mii_nway_adv_reg;
3435 uint16_t mii_nway_lp_ability_reg;
3441 /* Check for the case where we have fiber media and auto-neg failed
3442 * so we had to force link. In this case, we need to force the
3443 * configuration of the MAC to match the "fc" parameter.
3445 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
3446 || ((hw->media_type == e1000_media_type_internal_serdes)
3447 && (hw->autoneg_failed))
3448 || ((hw->media_type == e1000_media_type_copper)
3449 && (!hw->autoneg))) {
3450 ret_val = e1000_force_mac_fc(hw);
3452 DEBUGOUT("Error forcing flow control settings\n");
3457 /* Check for the case where we have copper media and auto-neg is
3458 * enabled. In this case, we need to check and see if Auto-Neg
3459 * has completed, and if so, how the PHY and link partner has
3460 * flow control configured.
3462 if (hw->media_type == e1000_media_type_copper) {
3463 /* Read the MII Status Register and check to see if AutoNeg
3464 * has completed. We read this twice because this reg has
3465 * some "sticky" (latched) bits.
3467 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3468 DEBUGOUT("PHY Read Error\n");
3469 return -E1000_ERR_PHY;
3471 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3472 DEBUGOUT("PHY Read Error\n");
3473 return -E1000_ERR_PHY;
3476 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
3477 /* The AutoNeg process has completed, so we now need to
3478 * read both the Auto Negotiation Advertisement Register
3479 * (Address 4) and the Auto_Negotiation Base Page Ability
3480 * Register (Address 5) to determine how flow control was
3483 if (e1000_read_phy_reg
3484 (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
3485 DEBUGOUT("PHY Read Error\n");
3486 return -E1000_ERR_PHY;
3488 if (e1000_read_phy_reg
3489 (hw, PHY_LP_ABILITY,
3490 &mii_nway_lp_ability_reg) < 0) {
3491 DEBUGOUT("PHY Read Error\n");
3492 return -E1000_ERR_PHY;
3495 /* Two bits in the Auto Negotiation Advertisement Register
3496 * (Address 4) and two bits in the Auto Negotiation Base
3497 * Page Ability Register (Address 5) determine flow control
3498 * for both the PHY and the link partner. The following
3499 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
3500 * 1999, describes these PAUSE resolution bits and how flow
3501 * control is determined based upon these settings.
3502 * NOTE: DC = Don't Care
3504 * LOCAL DEVICE | LINK PARTNER
3505 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
3506 *-------|---------|-------|---------|--------------------
3507 * 0 | 0 | DC | DC | e1000_fc_none
3508 * 0 | 1 | 0 | DC | e1000_fc_none
3509 * 0 | 1 | 1 | 0 | e1000_fc_none
3510 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
3511 * 1 | 0 | 0 | DC | e1000_fc_none
3512 * 1 | DC | 1 | DC | e1000_fc_full
3513 * 1 | 1 | 0 | 0 | e1000_fc_none
3514 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
3517 /* Are both PAUSE bits set to 1? If so, this implies
3518 * Symmetric Flow Control is enabled at both ends. The
3519 * ASM_DIR bits are irrelevant per the spec.
3521 * For Symmetric Flow Control:
3523 * LOCAL DEVICE | LINK PARTNER
3524 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3525 *-------|---------|-------|---------|--------------------
3526 * 1 | DC | 1 | DC | e1000_fc_full
3529 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3530 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
3531 /* Now we need to check if the user selected RX ONLY
3532 * of pause frames. In this case, we had to advertise
3533 * FULL flow control because we could not advertise RX
3534 * ONLY. Hence, we must now check to see if we need to
3535 * turn OFF the TRANSMISSION of PAUSE frames.
3537 if (hw->original_fc == e1000_fc_full) {
3538 hw->fc = e1000_fc_full;
3539 DEBUGOUT("Flow Control = FULL.\r\n");
3541 hw->fc = e1000_fc_rx_pause;
3543 ("Flow Control = RX PAUSE frames only.\r\n");
3546 /* For receiving PAUSE frames ONLY.
3548 * LOCAL DEVICE | LINK PARTNER
3549 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3550 *-------|---------|-------|---------|--------------------
3551 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
3554 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3555 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3556 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3557 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3559 hw->fc = e1000_fc_tx_pause;
3561 ("Flow Control = TX PAUSE frames only.\r\n");
3563 /* For transmitting PAUSE frames ONLY.
3565 * LOCAL DEVICE | LINK PARTNER
3566 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
3567 *-------|---------|-------|---------|--------------------
3568 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
3571 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3572 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3573 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3574 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3576 hw->fc = e1000_fc_rx_pause;
3578 ("Flow Control = RX PAUSE frames only.\r\n");
3580 /* Per the IEEE spec, at this point flow control should be
3581 * disabled. However, we want to consider that we could
3582 * be connected to a legacy switch that doesn't advertise
3583 * desired flow control, but can be forced on the link
3584 * partner. So if we advertised no flow control, that is
3585 * what we will resolve to. If we advertised some kind of
3586 * receive capability (Rx Pause Only or Full Flow Control)
3587 * and the link partner advertised none, we will configure
3588 * ourselves to enable Rx Flow Control only. We can do
3589 * this safely for two reasons: If the link partner really
3590 * didn't want flow control enabled, and we enable Rx, no
3591 * harm done since we won't be receiving any PAUSE frames
3592 * anyway. If the intent on the link partner was to have
3593 * flow control enabled, then by us enabling RX only, we
3594 * can at least receive pause frames and process them.
3595 * This is a good idea because in most cases, since we are
3596 * predominantly a server NIC, more times than not we will
3597 * be asked to delay transmission of packets than asking
3598 * our link partner to pause transmission of frames.
3600 else if (hw->original_fc == e1000_fc_none ||
3601 hw->original_fc == e1000_fc_tx_pause) {
3602 hw->fc = e1000_fc_none;
3603 DEBUGOUT("Flow Control = NONE.\r\n");
3605 hw->fc = e1000_fc_rx_pause;
3607 ("Flow Control = RX PAUSE frames only.\r\n");
3610 /* Now we need to do one last check... If we auto-
3611 * negotiated to HALF DUPLEX, flow control should not be
3612 * enabled per IEEE 802.3 spec.
3614 e1000_get_speed_and_duplex(hw, &speed, &duplex);
3616 if (duplex == HALF_DUPLEX)
3617 hw->fc = e1000_fc_none;
3619 /* Now we call a subroutine to actually force the MAC
3620 * controller to use the correct flow control settings.
3622 ret_val = e1000_force_mac_fc(hw);
3625 ("Error forcing flow control settings\n");
3630 ("Copper PHY and Auto Neg has not completed.\r\n");
3633 return E1000_SUCCESS;
3636 /******************************************************************************
3637 * Checks to see if the link status of the hardware has changed.
3639 * hw - Struct containing variables accessed by shared code
3641 * Called by any function that needs to check the link status of the adapter.
3642 *****************************************************************************/
3644 e1000_check_for_link(struct e1000_hw *hw)
3653 uint16_t lp_capability;
3657 /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
3658 * set when the optics detect a signal. On older adapters, it will be
3659 * cleared when there is a signal
3661 ctrl = E1000_READ_REG(hw, CTRL);
3662 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
3663 signal = E1000_CTRL_SWDPIN1;
3667 status = E1000_READ_REG(hw, STATUS);
3668 rxcw = E1000_READ_REG(hw, RXCW);
3669 DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw);
3671 /* If we have a copper PHY then we only want to go out to the PHY
3672 * registers to see if Auto-Neg has completed and/or if our link
3673 * status has changed. The get_link_status flag will be set if we
3674 * receive a Link Status Change interrupt or we have Rx Sequence
3677 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
3678 /* First we want to see if the MII Status Register reports
3679 * link. If so, then we want to get the current speed/duplex
3681 * Read the register twice since the link bit is sticky.
3683 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3684 DEBUGOUT("PHY Read Error\n");
3685 return -E1000_ERR_PHY;
3687 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3688 DEBUGOUT("PHY Read Error\n");
3689 return -E1000_ERR_PHY;
3692 if (phy_data & MII_SR_LINK_STATUS) {
3693 hw->get_link_status = false;
3695 /* No link detected */
3696 return -E1000_ERR_NOLINK;
3699 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
3700 * have Si on board that is 82544 or newer, Auto
3701 * Speed Detection takes care of MAC speed/duplex
3702 * configuration. So we only need to configure Collision
3703 * Distance in the MAC. Otherwise, we need to force
3704 * speed/duplex on the MAC to the current PHY speed/duplex
3707 if (hw->mac_type >= e1000_82544)
3708 e1000_config_collision_dist(hw);
3710 ret_val = e1000_config_mac_to_phy(hw);
3713 ("Error configuring MAC to PHY settings\n");
3718 /* Configure Flow Control now that Auto-Neg has completed. First, we
3719 * need to restore the desired flow control settings because we may
3720 * have had to re-autoneg with a different link partner.
3722 ret_val = e1000_config_fc_after_link_up(hw);
3724 DEBUGOUT("Error configuring flow control\n");
3728 /* At this point we know that we are on copper and we have
3729 * auto-negotiated link. These are conditions for checking the link
3730 * parter capability register. We use the link partner capability to
3731 * determine if TBI Compatibility needs to be turned on or off. If
3732 * the link partner advertises any speed in addition to Gigabit, then
3733 * we assume that they are GMII-based, and TBI compatibility is not
3734 * needed. If no other speeds are advertised, we assume the link
3735 * partner is TBI-based, and we turn on TBI Compatibility.
3737 if (hw->tbi_compatibility_en) {
3738 if (e1000_read_phy_reg
3739 (hw, PHY_LP_ABILITY, &lp_capability) < 0) {
3740 DEBUGOUT("PHY Read Error\n");
3741 return -E1000_ERR_PHY;
3743 if (lp_capability & (NWAY_LPAR_10T_HD_CAPS |
3744 NWAY_LPAR_10T_FD_CAPS |
3745 NWAY_LPAR_100TX_HD_CAPS |
3746 NWAY_LPAR_100TX_FD_CAPS |
3747 NWAY_LPAR_100T4_CAPS)) {
3748 /* If our link partner advertises anything in addition to
3749 * gigabit, we do not need to enable TBI compatibility.
3751 if (hw->tbi_compatibility_on) {
3752 /* If we previously were in the mode, turn it off. */
3753 rctl = E1000_READ_REG(hw, RCTL);
3754 rctl &= ~E1000_RCTL_SBP;
3755 E1000_WRITE_REG(hw, RCTL, rctl);
3756 hw->tbi_compatibility_on = false;
3759 /* If TBI compatibility is was previously off, turn it on. For
3760 * compatibility with a TBI link partner, we will store bad
3761 * packets. Some frames have an additional byte on the end and
3762 * will look like CRC errors to to the hardware.
3764 if (!hw->tbi_compatibility_on) {
3765 hw->tbi_compatibility_on = true;
3766 rctl = E1000_READ_REG(hw, RCTL);
3767 rctl |= E1000_RCTL_SBP;
3768 E1000_WRITE_REG(hw, RCTL, rctl);
3773 /* If we don't have link (auto-negotiation failed or link partner cannot
3774 * auto-negotiate), the cable is plugged in (we have signal), and our
3775 * link partner is not trying to auto-negotiate with us (we are receiving
3776 * idles or data), we need to force link up. We also need to give
3777 * auto-negotiation time to complete, in case the cable was just plugged
3778 * in. The autoneg_failed flag does this.
3780 else if ((hw->media_type == e1000_media_type_fiber) &&
3781 (!(status & E1000_STATUS_LU)) &&
3782 ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
3783 (!(rxcw & E1000_RXCW_C))) {
3784 if (hw->autoneg_failed == 0) {
3785 hw->autoneg_failed = 1;
3788 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
3790 /* Disable auto-negotiation in the TXCW register */
3791 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
3793 /* Force link-up and also force full-duplex. */
3794 ctrl = E1000_READ_REG(hw, CTRL);
3795 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
3796 E1000_WRITE_REG(hw, CTRL, ctrl);
3798 /* Configure Flow Control after forcing link up. */
3799 ret_val = e1000_config_fc_after_link_up(hw);
3801 DEBUGOUT("Error configuring flow control\n");
3805 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
3806 * auto-negotiation in the TXCW register and disable forced link in the
3807 * Device Control register in an attempt to auto-negotiate with our link
3810 else if ((hw->media_type == e1000_media_type_fiber) &&
3811 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
3813 ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
3814 E1000_WRITE_REG(hw, TXCW, hw->txcw);
3815 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
3820 /******************************************************************************
3821 * Configure the MAC-to-PHY interface for 10/100Mbps
3823 * hw - Struct containing variables accessed by shared code
3824 ******************************************************************************/
3826 e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
3828 int32_t ret_val = E1000_SUCCESS;
3834 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
3835 ret_val = e1000_write_kmrn_reg(hw,
3836 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
3840 /* Configure Transmit Inter-Packet Gap */
3841 tipg = E1000_READ_REG(hw, TIPG);
3842 tipg &= ~E1000_TIPG_IPGT_MASK;
3843 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
3844 E1000_WRITE_REG(hw, TIPG, tipg);
3846 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
3851 if (duplex == HALF_DUPLEX)
3852 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
3854 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
3856 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
3862 e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
3864 int32_t ret_val = E1000_SUCCESS;
3870 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
3871 ret_val = e1000_write_kmrn_reg(hw,
3872 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
3876 /* Configure Transmit Inter-Packet Gap */
3877 tipg = E1000_READ_REG(hw, TIPG);
3878 tipg &= ~E1000_TIPG_IPGT_MASK;
3879 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
3880 E1000_WRITE_REG(hw, TIPG, tipg);
3882 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
3887 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
3888 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
3893 /******************************************************************************
3894 * Detects the current speed and duplex settings of the hardware.
3896 * hw - Struct containing variables accessed by shared code
3897 * speed - Speed of the connection
3898 * duplex - Duplex setting of the connection
3899 *****************************************************************************/
3901 e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed,
3910 if (hw->mac_type >= e1000_82543) {
3911 status = E1000_READ_REG(hw, STATUS);
3912 if (status & E1000_STATUS_SPEED_1000) {
3913 *speed = SPEED_1000;
3914 DEBUGOUT("1000 Mbs, ");
3915 } else if (status & E1000_STATUS_SPEED_100) {
3917 DEBUGOUT("100 Mbs, ");
3920 DEBUGOUT("10 Mbs, ");
3923 if (status & E1000_STATUS_FD) {
3924 *duplex = FULL_DUPLEX;
3925 DEBUGOUT("Full Duplex\r\n");
3927 *duplex = HALF_DUPLEX;
3928 DEBUGOUT(" Half Duplex\r\n");
3931 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
3932 *speed = SPEED_1000;
3933 *duplex = FULL_DUPLEX;
3936 /* IGP01 PHY may advertise full duplex operation after speed downgrade
3937 * even if it is operating at half duplex. Here we set the duplex
3938 * settings to match the duplex in the link partner's capabilities.
3940 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
3941 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
3945 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
3946 *duplex = HALF_DUPLEX;
3948 ret_val = e1000_read_phy_reg(hw,
3949 PHY_LP_ABILITY, &phy_data);
3952 if ((*speed == SPEED_100 &&
3953 !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
3954 || (*speed == SPEED_10
3955 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
3956 *duplex = HALF_DUPLEX;
3960 if ((hw->mac_type == e1000_80003es2lan) &&
3961 (hw->media_type == e1000_media_type_copper)) {
3962 if (*speed == SPEED_1000)
3963 ret_val = e1000_configure_kmrn_for_1000(hw);
3965 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
3969 return E1000_SUCCESS;
3972 /******************************************************************************
3973 * Blocks until autoneg completes or times out (~4.5 seconds)
3975 * hw - Struct containing variables accessed by shared code
3976 ******************************************************************************/
3978 e1000_wait_autoneg(struct e1000_hw *hw)
3984 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
3986 /* We will wait for autoneg to complete or timeout to expire. */
3987 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
3988 /* Read the MII Status Register and wait for Auto-Neg
3989 * Complete bit to be set.
3991 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3992 DEBUGOUT("PHY Read Error\n");
3993 return -E1000_ERR_PHY;
3995 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3996 DEBUGOUT("PHY Read Error\n");
3997 return -E1000_ERR_PHY;
3999 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
4000 DEBUGOUT("Auto-Neg complete.\n");
4005 DEBUGOUT("Auto-Neg timedout.\n");
4006 return -E1000_ERR_TIMEOUT;
4009 /******************************************************************************
4010 * Raises the Management Data Clock
4012 * hw - Struct containing variables accessed by shared code
4013 * ctrl - Device control register's current value
4014 ******************************************************************************/
4016 e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
4018 /* Raise the clock input to the Management Data Clock (by setting the MDC
4019 * bit), and then delay 2 microseconds.
4021 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
4022 E1000_WRITE_FLUSH(hw);
4026 /******************************************************************************
4027 * Lowers the Management Data Clock
4029 * hw - Struct containing variables accessed by shared code
4030 * ctrl - Device control register's current value
4031 ******************************************************************************/
4033 e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
4035 /* Lower the clock input to the Management Data Clock (by clearing the MDC
4036 * bit), and then delay 2 microseconds.
4038 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
4039 E1000_WRITE_FLUSH(hw);
4043 /******************************************************************************
4044 * Shifts data bits out to the PHY
4046 * hw - Struct containing variables accessed by shared code
4047 * data - Data to send out to the PHY
4048 * count - Number of bits to shift out
4050 * Bits are shifted out in MSB to LSB order.
4051 ******************************************************************************/
4053 e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count)
4058 /* We need to shift "count" number of bits out to the PHY. So, the value
4059 * in the "data" parameter will be shifted out to the PHY one bit at a
4060 * time. In order to do this, "data" must be broken down into bits.
4063 mask <<= (count - 1);
4065 ctrl = E1000_READ_REG(hw, CTRL);
4067 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
4068 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
4071 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
4072 * then raising and lowering the Management Data Clock. A "0" is
4073 * shifted out to the PHY by setting the MDIO bit to "0" and then
4074 * raising and lowering the clock.
4077 ctrl |= E1000_CTRL_MDIO;
4079 ctrl &= ~E1000_CTRL_MDIO;
4081 E1000_WRITE_REG(hw, CTRL, ctrl);
4082 E1000_WRITE_FLUSH(hw);
4086 e1000_raise_mdi_clk(hw, &ctrl);
4087 e1000_lower_mdi_clk(hw, &ctrl);
4093 /******************************************************************************
4094 * Shifts data bits in from the PHY
4096 * hw - Struct containing variables accessed by shared code
4098 * Bits are shifted in in MSB to LSB order.
4099 ******************************************************************************/
4101 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
4107 /* In order to read a register from the PHY, we need to shift in a total
4108 * of 18 bits from the PHY. The first two bit (turnaround) times are used
4109 * to avoid contention on the MDIO pin when a read operation is performed.
4110 * These two bits are ignored by us and thrown away. Bits are "shifted in"
4111 * by raising the input to the Management Data Clock (setting the MDC bit),
4112 * and then reading the value of the MDIO bit.
4114 ctrl = E1000_READ_REG(hw, CTRL);
4116 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
4117 ctrl &= ~E1000_CTRL_MDIO_DIR;
4118 ctrl &= ~E1000_CTRL_MDIO;
4120 E1000_WRITE_REG(hw, CTRL, ctrl);
4121 E1000_WRITE_FLUSH(hw);
4123 /* Raise and Lower the clock before reading in the data. This accounts for
4124 * the turnaround bits. The first clock occurred when we clocked out the
4125 * last bit of the Register Address.
4127 e1000_raise_mdi_clk(hw, &ctrl);
4128 e1000_lower_mdi_clk(hw, &ctrl);
4130 for (data = 0, i = 0; i < 16; i++) {
4132 e1000_raise_mdi_clk(hw, &ctrl);
4133 ctrl = E1000_READ_REG(hw, CTRL);
4134 /* Check to see if we shifted in a "1". */
4135 if (ctrl & E1000_CTRL_MDIO)
4137 e1000_lower_mdi_clk(hw, &ctrl);
4140 e1000_raise_mdi_clk(hw, &ctrl);
4141 e1000_lower_mdi_clk(hw, &ctrl);
4146 /*****************************************************************************
4147 * Reads the value from a PHY register
4149 * hw - Struct containing variables accessed by shared code
4150 * reg_addr - address of the PHY register to read
4151 ******************************************************************************/
4153 e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data)
4157 const uint32_t phy_addr = 1;
4159 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4160 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4161 return -E1000_ERR_PARAM;
4164 if (hw->mac_type > e1000_82543) {
4165 /* Set up Op-code, Phy Address, and register address in the MDI
4166 * Control register. The MAC will take care of interfacing with the
4167 * PHY to retrieve the desired data.
4169 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
4170 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4171 (E1000_MDIC_OP_READ));
4173 E1000_WRITE_REG(hw, MDIC, mdic);
4175 /* Poll the ready bit to see if the MDI read completed */
4176 for (i = 0; i < 64; i++) {
4178 mdic = E1000_READ_REG(hw, MDIC);
4179 if (mdic & E1000_MDIC_READY)
4182 if (!(mdic & E1000_MDIC_READY)) {
4183 DEBUGOUT("MDI Read did not complete\n");
4184 return -E1000_ERR_PHY;
4186 if (mdic & E1000_MDIC_ERROR) {
4187 DEBUGOUT("MDI Error\n");
4188 return -E1000_ERR_PHY;
4190 *phy_data = (uint16_t) mdic;
4192 /* We must first send a preamble through the MDIO pin to signal the
4193 * beginning of an MII instruction. This is done by sending 32
4194 * consecutive "1" bits.
4196 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4198 /* Now combine the next few fields that are required for a read
4199 * operation. We use this method instead of calling the
4200 * e1000_shift_out_mdi_bits routine five different times. The format of
4201 * a MII read instruction consists of a shift out of 14 bits and is
4202 * defined as follows:
4203 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
4204 * followed by a shift in of 18 bits. This first two bits shifted in
4205 * are TurnAround bits used to avoid contention on the MDIO pin when a
4206 * READ operation is performed. These two bits are thrown away
4207 * followed by a shift in of 16 bits which contains the desired data.
4209 mdic = ((reg_addr) | (phy_addr << 5) |
4210 (PHY_OP_READ << 10) | (PHY_SOF << 12));
4212 e1000_shift_out_mdi_bits(hw, mdic, 14);
4214 /* Now that we've shifted out the read command to the MII, we need to
4215 * "shift in" the 16-bit value (18 total bits) of the requested PHY
4218 *phy_data = e1000_shift_in_mdi_bits(hw);
4223 /******************************************************************************
4224 * Writes a value to a PHY register
4226 * hw - Struct containing variables accessed by shared code
4227 * reg_addr - address of the PHY register to write
4228 * data - data to write to the PHY
4229 ******************************************************************************/
4231 e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data)
4235 const uint32_t phy_addr = 1;
4237 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4238 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4239 return -E1000_ERR_PARAM;
4242 if (hw->mac_type > e1000_82543) {
4243 /* Set up Op-code, Phy Address, register address, and data intended
4244 * for the PHY register in the MDI Control register. The MAC will take
4245 * care of interfacing with the PHY to send the desired data.
4247 mdic = (((uint32_t) phy_data) |
4248 (reg_addr << E1000_MDIC_REG_SHIFT) |
4249 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4250 (E1000_MDIC_OP_WRITE));
4252 E1000_WRITE_REG(hw, MDIC, mdic);
4254 /* Poll the ready bit to see if the MDI read completed */
4255 for (i = 0; i < 64; i++) {
4257 mdic = E1000_READ_REG(hw, MDIC);
4258 if (mdic & E1000_MDIC_READY)
4261 if (!(mdic & E1000_MDIC_READY)) {
4262 DEBUGOUT("MDI Write did not complete\n");
4263 return -E1000_ERR_PHY;
4266 /* We'll need to use the SW defined pins to shift the write command
4267 * out to the PHY. We first send a preamble to the PHY to signal the
4268 * beginning of the MII instruction. This is done by sending 32
4269 * consecutive "1" bits.
4271 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4273 /* Now combine the remaining required fields that will indicate a
4274 * write operation. We use this method instead of calling the
4275 * e1000_shift_out_mdi_bits routine for each field in the command. The
4276 * format of a MII write instruction is as follows:
4277 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
4279 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
4280 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
4282 mdic |= (uint32_t) phy_data;
4284 e1000_shift_out_mdi_bits(hw, mdic, 32);
4289 /******************************************************************************
4290 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
4291 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
4292 * the caller to figure out how to deal with it.
4294 * hw - Struct containing variables accessed by shared code
4296 * returns: - E1000_BLK_PHY_RESET
4299 *****************************************************************************/
4301 e1000_check_phy_reset_block(struct e1000_hw *hw)
4306 if (hw->mac_type == e1000_ich8lan) {
4307 fwsm = E1000_READ_REG(hw, FWSM);
4308 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
4309 : E1000_BLK_PHY_RESET;
4312 if (hw->mac_type > e1000_82547_rev_2)
4313 manc = E1000_READ_REG(hw, MANC);
4314 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
4315 E1000_BLK_PHY_RESET : E1000_SUCCESS;
4318 /***************************************************************************
4319 * Checks if the PHY configuration is done
4321 * hw: Struct containing variables accessed by shared code
4323 * returns: - E1000_ERR_RESET if fail to reset MAC
4324 * E1000_SUCCESS at any other case.
4326 ***************************************************************************/
4328 e1000_get_phy_cfg_done(struct e1000_hw *hw)
4330 int32_t timeout = PHY_CFG_TIMEOUT;
4331 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
4335 switch (hw->mac_type) {
4340 case e1000_80003es2lan:
4341 /* Separate *_CFG_DONE_* bit for each port */
4342 if (e1000_is_second_port(hw))
4343 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
4350 if (hw->mac_type == e1000_igb) {
4351 if (E1000_READ_REG(hw, I210_EEMNGCTL) & cfg_mask)
4354 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
4361 DEBUGOUT("MNG configuration cycle has not "
4363 return -E1000_ERR_RESET;
4368 return E1000_SUCCESS;
4371 /******************************************************************************
4372 * Returns the PHY to the power-on reset state
4374 * hw - Struct containing variables accessed by shared code
4375 ******************************************************************************/
4377 e1000_phy_hw_reset(struct e1000_hw *hw)
4379 uint16_t swfw = E1000_SWFW_PHY0_SM;
4380 uint32_t ctrl, ctrl_ext;
4386 /* In the case of the phy reset being blocked, it's not an error, we
4387 * simply return success without performing the reset. */
4388 ret_val = e1000_check_phy_reset_block(hw);
4390 return E1000_SUCCESS;
4392 DEBUGOUT("Resetting Phy...\n");
4394 if (hw->mac_type > e1000_82543) {
4395 if (e1000_is_second_port(hw))
4396 swfw = E1000_SWFW_PHY1_SM;
4398 if (e1000_swfw_sync_acquire(hw, swfw)) {
4399 DEBUGOUT("Unable to acquire swfw sync\n");
4400 return -E1000_ERR_SWFW_SYNC;
4403 /* Read the device control register and assert the E1000_CTRL_PHY_RST
4404 * bit. Then, take it out of reset.
4406 ctrl = E1000_READ_REG(hw, CTRL);
4407 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
4408 E1000_WRITE_FLUSH(hw);
4410 if (hw->mac_type < e1000_82571)
4415 E1000_WRITE_REG(hw, CTRL, ctrl);
4416 E1000_WRITE_FLUSH(hw);
4418 if (hw->mac_type >= e1000_82571)
4422 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
4423 * bit to put the PHY into reset. Then, take it out of reset.
4425 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
4426 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
4427 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
4428 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4429 E1000_WRITE_FLUSH(hw);
4431 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
4432 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4433 E1000_WRITE_FLUSH(hw);
4437 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
4438 /* Configure activity LED after PHY reset */
4439 led_ctrl = E1000_READ_REG(hw, LEDCTL);
4440 led_ctrl &= IGP_ACTIVITY_LED_MASK;
4441 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
4442 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
4445 e1000_swfw_sync_release(hw, swfw);
4447 /* Wait for FW to finish PHY configuration. */
4448 ret_val = e1000_get_phy_cfg_done(hw);
4449 if (ret_val != E1000_SUCCESS)
4455 /******************************************************************************
4456 * IGP phy init script - initializes the GbE PHY
4458 * hw - Struct containing variables accessed by shared code
4459 *****************************************************************************/
4461 e1000_phy_init_script(struct e1000_hw *hw)
4464 uint16_t phy_saved_data;
4467 if (hw->phy_init_script) {
4470 /* Save off the current value of register 0x2F5B to be
4471 * restored at the end of this routine. */
4472 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
4474 /* Disabled the PHY transmitter */
4475 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
4479 e1000_write_phy_reg(hw, 0x0000, 0x0140);
4483 switch (hw->mac_type) {
4486 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
4488 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
4490 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
4492 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
4494 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
4496 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
4498 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
4500 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
4502 e1000_write_phy_reg(hw, 0x2010, 0x0008);
4505 case e1000_82541_rev_2:
4506 case e1000_82547_rev_2:
4507 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
4513 e1000_write_phy_reg(hw, 0x0000, 0x3300);
4517 /* Now enable the transmitter */
4519 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
4521 if (hw->mac_type == e1000_82547) {
4522 uint16_t fused, fine, coarse;
4524 /* Move to analog registers page */
4525 e1000_read_phy_reg(hw,
4526 IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
4528 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
4529 e1000_read_phy_reg(hw,
4530 IGP01E1000_ANALOG_FUSE_STATUS, &fused);
4532 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
4534 & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
4537 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
4539 IGP01E1000_ANALOG_FUSE_COARSE_10;
4540 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
4542 == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
4543 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
4546 & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
4548 & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
4550 & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
4552 e1000_write_phy_reg(hw,
4553 IGP01E1000_ANALOG_FUSE_CONTROL, fused);
4554 e1000_write_phy_reg(hw,
4555 IGP01E1000_ANALOG_FUSE_BYPASS,
4556 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
4562 /******************************************************************************
4565 * hw - Struct containing variables accessed by shared code
4567 * Sets bit 15 of the MII Control register
4568 ******************************************************************************/
4570 e1000_phy_reset(struct e1000_hw *hw)
4577 /* In the case of the phy reset being blocked, it's not an error, we
4578 * simply return success without performing the reset. */
4579 ret_val = e1000_check_phy_reset_block(hw);
4581 return E1000_SUCCESS;
4583 switch (hw->phy_type) {
4585 case e1000_phy_igp_2:
4586 case e1000_phy_igp_3:
4589 ret_val = e1000_phy_hw_reset(hw);
4594 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
4598 phy_data |= MII_CR_RESET;
4599 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
4607 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
4608 e1000_phy_init_script(hw);
4610 return E1000_SUCCESS;
4613 static int e1000_set_phy_type (struct e1000_hw *hw)
4617 if (hw->mac_type == e1000_undefined)
4618 return -E1000_ERR_PHY_TYPE;
4620 switch (hw->phy_id) {
4621 case M88E1000_E_PHY_ID:
4622 case M88E1000_I_PHY_ID:
4623 case M88E1011_I_PHY_ID:
4624 case M88E1111_I_PHY_ID:
4625 hw->phy_type = e1000_phy_m88;
4627 case IGP01E1000_I_PHY_ID:
4628 if (hw->mac_type == e1000_82541 ||
4629 hw->mac_type == e1000_82541_rev_2 ||
4630 hw->mac_type == e1000_82547 ||
4631 hw->mac_type == e1000_82547_rev_2) {
4632 hw->phy_type = e1000_phy_igp;
4635 case IGP03E1000_E_PHY_ID:
4636 hw->phy_type = e1000_phy_igp_3;
4639 case IFE_PLUS_E_PHY_ID:
4640 case IFE_C_E_PHY_ID:
4641 hw->phy_type = e1000_phy_ife;
4643 case GG82563_E_PHY_ID:
4644 if (hw->mac_type == e1000_80003es2lan) {
4645 hw->phy_type = e1000_phy_gg82563;
4648 case BME1000_E_PHY_ID:
4649 hw->phy_type = e1000_phy_bm;
4652 hw->phy_type = e1000_phy_igb;
4656 /* Should never have loaded on this device */
4657 hw->phy_type = e1000_phy_undefined;
4658 return -E1000_ERR_PHY_TYPE;
4661 return E1000_SUCCESS;
4664 /******************************************************************************
4665 * Probes the expected PHY address for known PHY IDs
4667 * hw - Struct containing variables accessed by shared code
4668 ******************************************************************************/
4670 e1000_detect_gig_phy(struct e1000_hw *hw)
4672 int32_t phy_init_status, ret_val;
4673 uint16_t phy_id_high, phy_id_low;
4678 /* The 82571 firmware may still be configuring the PHY. In this
4679 * case, we cannot access the PHY until the configuration is done. So
4680 * we explicitly set the PHY values. */
4681 if (hw->mac_type == e1000_82571 ||
4682 hw->mac_type == e1000_82572) {
4683 hw->phy_id = IGP01E1000_I_PHY_ID;
4684 hw->phy_type = e1000_phy_igp_2;
4685 return E1000_SUCCESS;
4688 /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a
4689 * work- around that forces PHY page 0 to be set or the reads fail.
4690 * The rest of the code in this routine uses e1000_read_phy_reg to
4691 * read the PHY ID. So for ESB-2 we need to have this set so our
4692 * reads won't fail. If the attached PHY is not a e1000_phy_gg82563,
4693 * the routines below will figure this out as well. */
4694 if (hw->mac_type == e1000_80003es2lan)
4695 hw->phy_type = e1000_phy_gg82563;
4697 /* Read the PHY ID Registers to identify which PHY is onboard. */
4698 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
4702 hw->phy_id = (uint32_t) (phy_id_high << 16);
4704 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
4708 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4709 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4711 switch (hw->mac_type) {
4713 if (hw->phy_id == M88E1000_E_PHY_ID)
4717 if (hw->phy_id == M88E1000_I_PHY_ID)
4722 case e1000_82545_rev_3:
4724 case e1000_82546_rev_3:
4725 if (hw->phy_id == M88E1011_I_PHY_ID)
4729 case e1000_82541_rev_2:
4731 case e1000_82547_rev_2:
4732 if(hw->phy_id == IGP01E1000_I_PHY_ID)
4737 if (hw->phy_id == M88E1111_I_PHY_ID)
4741 if (hw->phy_id == BME1000_E_PHY_ID)
4744 case e1000_80003es2lan:
4745 if (hw->phy_id == GG82563_E_PHY_ID)
4749 if (hw->phy_id == IGP03E1000_E_PHY_ID)
4751 if (hw->phy_id == IFE_E_PHY_ID)
4753 if (hw->phy_id == IFE_PLUS_E_PHY_ID)
4755 if (hw->phy_id == IFE_C_E_PHY_ID)
4759 if (hw->phy_id == I210_I_PHY_ID)
4763 DEBUGOUT("Invalid MAC type %d\n", hw->mac_type);
4764 return -E1000_ERR_CONFIG;
4767 phy_init_status = e1000_set_phy_type(hw);
4769 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4770 DEBUGOUT("PHY ID 0x%X detected\n", hw->phy_id);
4773 DEBUGOUT("Invalid PHY ID 0x%X\n", hw->phy_id);
4774 return -E1000_ERR_PHY;
4777 /*****************************************************************************
4778 * Set media type and TBI compatibility.
4780 * hw - Struct containing variables accessed by shared code
4781 * **************************************************************************/
4783 e1000_set_media_type(struct e1000_hw *hw)
4789 if (hw->mac_type != e1000_82543) {
4790 /* tbi_compatibility is only valid on 82543 */
4791 hw->tbi_compatibility_en = false;
4794 switch (hw->device_id) {
4795 case E1000_DEV_ID_82545GM_SERDES:
4796 case E1000_DEV_ID_82546GB_SERDES:
4797 case E1000_DEV_ID_82571EB_SERDES:
4798 case E1000_DEV_ID_82571EB_SERDES_DUAL:
4799 case E1000_DEV_ID_82571EB_SERDES_QUAD:
4800 case E1000_DEV_ID_82572EI_SERDES:
4801 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
4802 hw->media_type = e1000_media_type_internal_serdes;
4805 switch (hw->mac_type) {
4806 case e1000_82542_rev2_0:
4807 case e1000_82542_rev2_1:
4808 hw->media_type = e1000_media_type_fiber;
4814 /* The STATUS_TBIMODE bit is reserved or reused
4815 * for the this device.
4817 hw->media_type = e1000_media_type_copper;
4820 status = E1000_READ_REG(hw, STATUS);
4821 if (status & E1000_STATUS_TBIMODE) {
4822 hw->media_type = e1000_media_type_fiber;
4823 /* tbi_compatibility not valid on fiber */
4824 hw->tbi_compatibility_en = false;
4826 hw->media_type = e1000_media_type_copper;
4834 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
4836 * e1000_sw_init initializes the Adapter private data structure.
4837 * Fields are initialized based on PCI device information and
4838 * OS network device settings (MTU size).
4842 e1000_sw_init(struct e1000_hw *hw)
4846 /* PCI config space info */
4847 #ifdef CONFIG_DM_ETH
4848 dm_pci_read_config16(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
4849 dm_pci_read_config16(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
4850 dm_pci_read_config16(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
4851 &hw->subsystem_vendor_id);
4852 dm_pci_read_config16(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
4854 dm_pci_read_config8(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
4855 dm_pci_read_config16(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
4857 pci_read_config_word(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
4858 pci_read_config_word(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
4859 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
4860 &hw->subsystem_vendor_id);
4861 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
4863 pci_read_config_byte(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
4864 pci_read_config_word(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
4867 /* identify the MAC */
4868 result = e1000_set_mac_type(hw);
4870 E1000_ERR(hw, "Unknown MAC Type\n");
4874 switch (hw->mac_type) {
4879 case e1000_82541_rev_2:
4880 case e1000_82547_rev_2:
4881 hw->phy_init_script = 1;
4885 /* flow control settings */
4886 hw->fc_high_water = E1000_FC_HIGH_THRESH;
4887 hw->fc_low_water = E1000_FC_LOW_THRESH;
4888 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
4889 hw->fc_send_xon = 1;
4891 /* Media type - copper or fiber */
4892 hw->tbi_compatibility_en = true;
4893 e1000_set_media_type(hw);
4895 if (hw->mac_type >= e1000_82543) {
4896 uint32_t status = E1000_READ_REG(hw, STATUS);
4898 if (status & E1000_STATUS_TBIMODE) {
4899 DEBUGOUT("fiber interface\n");
4900 hw->media_type = e1000_media_type_fiber;
4902 DEBUGOUT("copper interface\n");
4903 hw->media_type = e1000_media_type_copper;
4906 hw->media_type = e1000_media_type_fiber;
4909 hw->wait_autoneg_complete = true;
4910 if (hw->mac_type < e1000_82543)
4911 hw->report_tx_early = 0;
4913 hw->report_tx_early = 1;
4915 return E1000_SUCCESS;
4919 fill_rx(struct e1000_hw *hw)
4921 struct e1000_rx_desc *rd;
4922 unsigned long flush_start, flush_end;
4925 rd = rx_base + rx_tail;
4926 rx_tail = (rx_tail + 1) % 8;
4928 rd->buffer_addr = cpu_to_le64((unsigned long)packet);
4931 * Make sure there are no stale data in WB over this area, which
4932 * might get written into the memory while the e1000 also writes
4933 * into the same memory area.
4935 invalidate_dcache_range((unsigned long)packet,
4936 (unsigned long)packet + 4096);
4937 /* Dump the DMA descriptor into RAM. */
4938 flush_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
4939 flush_end = flush_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
4940 flush_dcache_range(flush_start, flush_end);
4942 E1000_WRITE_REG(hw, RDT, rx_tail);
4946 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
4947 * @adapter: board private structure
4949 * Configure the Tx unit of the MAC after a reset.
4953 e1000_configure_tx(struct e1000_hw *hw)
4956 unsigned long tipg, tarc;
4957 uint32_t ipgr1, ipgr2;
4959 E1000_WRITE_REG(hw, TDBAL, lower_32_bits((unsigned long)tx_base));
4960 E1000_WRITE_REG(hw, TDBAH, upper_32_bits((unsigned long)tx_base));
4962 E1000_WRITE_REG(hw, TDLEN, 128);
4964 /* Setup the HW Tx Head and Tail descriptor pointers */
4965 E1000_WRITE_REG(hw, TDH, 0);
4966 E1000_WRITE_REG(hw, TDT, 0);
4969 /* Set the default values for the Tx Inter Packet Gap timer */
4970 if (hw->mac_type <= e1000_82547_rev_2 &&
4971 (hw->media_type == e1000_media_type_fiber ||
4972 hw->media_type == e1000_media_type_internal_serdes))
4973 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
4975 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
4977 /* Set the default values for the Tx Inter Packet Gap timer */
4978 switch (hw->mac_type) {
4979 case e1000_82542_rev2_0:
4980 case e1000_82542_rev2_1:
4981 tipg = DEFAULT_82542_TIPG_IPGT;
4982 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
4983 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
4985 case e1000_80003es2lan:
4986 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
4987 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
4990 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
4991 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
4994 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
4995 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
4996 E1000_WRITE_REG(hw, TIPG, tipg);
4997 /* Program the Transmit Control Register */
4998 tctl = E1000_READ_REG(hw, TCTL);
4999 tctl &= ~E1000_TCTL_CT;
5000 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
5001 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
5003 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
5004 tarc = E1000_READ_REG(hw, TARC0);
5005 /* set the speed mode bit, we'll clear it if we're not at
5006 * gigabit link later */
5007 /* git bit can be set to 1*/
5008 } else if (hw->mac_type == e1000_80003es2lan) {
5009 tarc = E1000_READ_REG(hw, TARC0);
5011 E1000_WRITE_REG(hw, TARC0, tarc);
5012 tarc = E1000_READ_REG(hw, TARC1);
5014 E1000_WRITE_REG(hw, TARC1, tarc);
5018 e1000_config_collision_dist(hw);
5019 /* Setup Transmit Descriptor Settings for eop descriptor */
5020 hw->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
5022 /* Need to set up RS bit */
5023 if (hw->mac_type < e1000_82543)
5024 hw->txd_cmd |= E1000_TXD_CMD_RPS;
5026 hw->txd_cmd |= E1000_TXD_CMD_RS;
5029 if (hw->mac_type == e1000_igb) {
5030 E1000_WRITE_REG(hw, TCTL_EXT, 0x42 << 10);
5032 uint32_t reg_txdctl = E1000_READ_REG(hw, TXDCTL);
5033 reg_txdctl |= 1 << 25;
5034 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
5040 E1000_WRITE_REG(hw, TCTL, tctl);
5046 * e1000_setup_rctl - configure the receive control register
5047 * @adapter: Board private structure
5050 e1000_setup_rctl(struct e1000_hw *hw)
5054 rctl = E1000_READ_REG(hw, RCTL);
5056 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
5058 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO
5059 | E1000_RCTL_RDMTS_HALF; /* |
5060 (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */
5062 if (hw->tbi_compatibility_on == 1)
5063 rctl |= E1000_RCTL_SBP;
5065 rctl &= ~E1000_RCTL_SBP;
5067 rctl &= ~(E1000_RCTL_SZ_4096);
5068 rctl |= E1000_RCTL_SZ_2048;
5069 rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
5070 E1000_WRITE_REG(hw, RCTL, rctl);
5074 * e1000_configure_rx - Configure 8254x Receive Unit after Reset
5075 * @adapter: board private structure
5077 * Configure the Rx unit of the MAC after a reset.
5080 e1000_configure_rx(struct e1000_hw *hw)
5082 unsigned long rctl, ctrl_ext;
5085 /* make sure receives are disabled while setting up the descriptors */
5086 rctl = E1000_READ_REG(hw, RCTL);
5087 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
5088 if (hw->mac_type >= e1000_82540) {
5089 /* Set the interrupt throttling rate. Value is calculated
5090 * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */
5091 #define MAX_INTS_PER_SEC 8000
5092 #define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
5093 E1000_WRITE_REG(hw, ITR, DEFAULT_ITR);
5096 if (hw->mac_type >= e1000_82571) {
5097 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5098 /* Reset delay timers after every interrupt */
5099 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
5100 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
5101 E1000_WRITE_FLUSH(hw);
5103 /* Setup the Base and Length of the Rx Descriptor Ring */
5104 E1000_WRITE_REG(hw, RDBAL, lower_32_bits((unsigned long)rx_base));
5105 E1000_WRITE_REG(hw, RDBAH, upper_32_bits((unsigned long)rx_base));
5107 E1000_WRITE_REG(hw, RDLEN, 128);
5109 /* Setup the HW Rx Head and Tail Descriptor Pointers */
5110 E1000_WRITE_REG(hw, RDH, 0);
5111 E1000_WRITE_REG(hw, RDT, 0);
5112 /* Enable Receives */
5114 if (hw->mac_type == e1000_igb) {
5116 uint32_t reg_rxdctl = E1000_READ_REG(hw, RXDCTL);
5117 reg_rxdctl |= 1 << 25;
5118 E1000_WRITE_REG(hw, RXDCTL, reg_rxdctl);
5122 E1000_WRITE_REG(hw, RCTL, rctl);
5127 /**************************************************************************
5128 POLL - Wait for a frame
5129 ***************************************************************************/
5131 _e1000_poll(struct e1000_hw *hw)
5133 struct e1000_rx_desc *rd;
5134 unsigned long inval_start, inval_end;
5137 /* return true if there's an ethernet packet ready to read */
5138 rd = rx_base + rx_last;
5140 /* Re-load the descriptor from RAM. */
5141 inval_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
5142 inval_end = inval_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
5143 invalidate_dcache_range(inval_start, inval_end);
5145 if (!(rd->status & E1000_RXD_STAT_DD))
5147 /* DEBUGOUT("recv: packet len=%d\n", rd->length); */
5148 /* Packet received, make sure the data are re-loaded from RAM. */
5149 len = le16_to_cpu(rd->length);
5150 invalidate_dcache_range((unsigned long)packet,
5151 (unsigned long)packet +
5152 roundup(len, ARCH_DMA_MINALIGN));
5156 static int _e1000_transmit(struct e1000_hw *hw, void *txpacket, int length)
5158 void *nv_packet = (void *)txpacket;
5159 struct e1000_tx_desc *txp;
5161 unsigned long flush_start, flush_end;
5163 txp = tx_base + tx_tail;
5164 tx_tail = (tx_tail + 1) % 8;
5166 txp->buffer_addr = cpu_to_le64(virt_to_bus(hw->pdev, nv_packet));
5167 txp->lower.data = cpu_to_le32(hw->txd_cmd | length);
5168 txp->upper.data = 0;
5170 /* Dump the packet into RAM so e1000 can pick them. */
5171 flush_dcache_range((unsigned long)nv_packet,
5172 (unsigned long)nv_packet +
5173 roundup(length, ARCH_DMA_MINALIGN));
5174 /* Dump the descriptor into RAM as well. */
5175 flush_start = ((unsigned long)txp) & ~(ARCH_DMA_MINALIGN - 1);
5176 flush_end = flush_start + roundup(sizeof(*txp), ARCH_DMA_MINALIGN);
5177 flush_dcache_range(flush_start, flush_end);
5179 E1000_WRITE_REG(hw, TDT, tx_tail);
5181 E1000_WRITE_FLUSH(hw);
5183 invalidate_dcache_range(flush_start, flush_end);
5184 if (le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD)
5186 if (i++ > TOUT_LOOP) {
5187 DEBUGOUT("e1000: tx timeout\n");
5190 udelay(10); /* give the nic a chance to write to the register */
5196 _e1000_disable(struct e1000_hw *hw)
5198 /* Turn off the ethernet interface */
5199 E1000_WRITE_REG(hw, RCTL, 0);
5200 E1000_WRITE_REG(hw, TCTL, 0);
5202 /* Clear the transmit ring */
5203 E1000_WRITE_REG(hw, TDH, 0);
5204 E1000_WRITE_REG(hw, TDT, 0);
5206 /* Clear the receive ring */
5207 E1000_WRITE_REG(hw, RDH, 0);
5208 E1000_WRITE_REG(hw, RDT, 0);
5215 e1000_reset(struct e1000_hw *hw, unsigned char enetaddr[6])
5218 if (hw->mac_type >= e1000_82544)
5219 E1000_WRITE_REG(hw, WUC, 0);
5221 return e1000_init_hw(hw, enetaddr);
5225 _e1000_init(struct e1000_hw *hw, unsigned char enetaddr[6])
5229 ret_val = e1000_reset(hw, enetaddr);
5231 if ((ret_val == -E1000_ERR_NOLINK) ||
5232 (ret_val == -E1000_ERR_TIMEOUT)) {
5233 E1000_ERR(hw, "Valid Link not detected: %d\n", ret_val);
5235 E1000_ERR(hw, "Hardware Initialization Failed\n");
5239 e1000_configure_tx(hw);
5240 e1000_setup_rctl(hw);
5241 e1000_configure_rx(hw);
5245 /******************************************************************************
5246 * Gets the current PCI bus type of hardware
5248 * hw - Struct containing variables accessed by shared code
5249 *****************************************************************************/
5250 void e1000_get_bus_type(struct e1000_hw *hw)
5254 switch (hw->mac_type) {
5255 case e1000_82542_rev2_0:
5256 case e1000_82542_rev2_1:
5257 hw->bus_type = e1000_bus_type_pci;
5263 case e1000_80003es2lan:
5266 hw->bus_type = e1000_bus_type_pci_express;
5269 status = E1000_READ_REG(hw, STATUS);
5270 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5271 e1000_bus_type_pcix : e1000_bus_type_pci;
5276 #ifndef CONFIG_DM_ETH
5277 /* A list of all registered e1000 devices */
5278 static LIST_HEAD(e1000_hw_list);
5281 #ifdef CONFIG_DM_ETH
5282 static int e1000_init_one(struct e1000_hw *hw, int cardnum,
5283 struct udevice *devno, unsigned char enetaddr[6])
5285 static int e1000_init_one(struct e1000_hw *hw, int cardnum, pci_dev_t devno,
5286 unsigned char enetaddr[6])
5291 /* Assign the passed-in values */
5292 #ifdef CONFIG_DM_ETH
5297 hw->cardnum = cardnum;
5299 /* Print a debug message with the IO base address */
5300 #ifdef CONFIG_DM_ETH
5301 dm_pci_read_config32(devno, PCI_BASE_ADDRESS_0, &val);
5303 pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &val);
5305 E1000_DBG(hw, "iobase 0x%08x\n", val & 0xfffffff0);
5307 /* Try to enable I/O accesses and bus-mastering */
5308 val = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
5309 #ifdef CONFIG_DM_ETH
5310 dm_pci_write_config32(devno, PCI_COMMAND, val);
5312 pci_write_config_dword(devno, PCI_COMMAND, val);
5315 /* Make sure it worked */
5316 #ifdef CONFIG_DM_ETH
5317 dm_pci_read_config32(devno, PCI_COMMAND, &val);
5319 pci_read_config_dword(devno, PCI_COMMAND, &val);
5321 if (!(val & PCI_COMMAND_MEMORY)) {
5322 E1000_ERR(hw, "Can't enable I/O memory\n");
5325 if (!(val & PCI_COMMAND_MASTER)) {
5326 E1000_ERR(hw, "Can't enable bus-mastering\n");
5330 /* Are these variables needed? */
5331 hw->fc = e1000_fc_default;
5332 hw->original_fc = e1000_fc_default;
5333 hw->autoneg_failed = 0;
5335 hw->get_link_status = true;
5336 #ifndef CONFIG_E1000_NO_NVM
5337 hw->eeprom_semaphore_present = true;
5339 #ifdef CONFIG_DM_ETH
5340 hw->hw_addr = dm_pci_map_bar(devno, PCI_BASE_ADDRESS_0,
5343 hw->hw_addr = pci_map_bar(devno, PCI_BASE_ADDRESS_0,
5346 hw->mac_type = e1000_undefined;
5348 /* MAC and Phy settings */
5349 if (e1000_sw_init(hw) < 0) {
5350 E1000_ERR(hw, "Software init failed\n");
5353 if (e1000_check_phy_reset_block(hw))
5354 E1000_ERR(hw, "PHY Reset is blocked!\n");
5356 /* Basic init was OK, reset the hardware and allow SPI access */
5359 #ifndef CONFIG_E1000_NO_NVM
5360 /* Validate the EEPROM and get chipset information */
5361 if (e1000_init_eeprom_params(hw)) {
5362 E1000_ERR(hw, "EEPROM is invalid!\n");
5365 if ((E1000_READ_REG(hw, I210_EECD) & E1000_EECD_FLUPD) &&
5366 e1000_validate_eeprom_checksum(hw))
5368 e1000_read_mac_addr(hw, enetaddr);
5370 e1000_get_bus_type(hw);
5372 #ifndef CONFIG_E1000_NO_NVM
5373 printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n ",
5374 enetaddr[0], enetaddr[1], enetaddr[2],
5375 enetaddr[3], enetaddr[4], enetaddr[5]);
5377 memset(enetaddr, 0, 6);
5378 printf("e1000: no NVM\n");
5384 /* Put the name of a device in a string */
5385 static void e1000_name(char *str, int cardnum)
5387 sprintf(str, "e1000#%u", cardnum);
5390 #ifndef CONFIG_DM_ETH
5391 /**************************************************************************
5392 TRANSMIT - Transmit a frame
5393 ***************************************************************************/
5394 static int e1000_transmit(struct eth_device *nic, void *txpacket, int length)
5396 struct e1000_hw *hw = nic->priv;
5398 return _e1000_transmit(hw, txpacket, length);
5401 /**************************************************************************
5402 DISABLE - Turn off ethernet interface
5403 ***************************************************************************/
5405 e1000_disable(struct eth_device *nic)
5407 struct e1000_hw *hw = nic->priv;
5412 /**************************************************************************
5413 INIT - set up ethernet interface(s)
5414 ***************************************************************************/
5416 e1000_init(struct eth_device *nic, bd_t *bis)
5418 struct e1000_hw *hw = nic->priv;
5420 return _e1000_init(hw, nic->enetaddr);
5424 e1000_poll(struct eth_device *nic)
5426 struct e1000_hw *hw = nic->priv;
5429 len = _e1000_poll(hw);
5431 net_process_received_packet((uchar *)packet, len);
5438 /**************************************************************************
5439 PROBE - Look for an adapter, this routine's visible to the outside
5440 You should omit the last argument struct pci_device * for a non-PCI NIC
5441 ***************************************************************************/
5443 e1000_initialize(bd_t * bis)
5451 /* Find and probe all the matching PCI devices */
5452 for (i = 0; (devno = pci_find_devices(e1000_supported, i)) >= 0; i++) {
5454 * These will never get freed due to errors, this allows us to
5455 * perform SPI EEPROM programming from U-Boot, for example.
5457 struct eth_device *nic = malloc(sizeof(*nic));
5458 struct e1000_hw *hw = malloc(sizeof(*hw));
5460 printf("e1000#%u: Out of Memory!\n", i);
5466 /* Make sure all of the fields are initially zeroed */
5467 memset(nic, 0, sizeof(*nic));
5468 memset(hw, 0, sizeof(*hw));
5471 /* Generate a card name */
5472 e1000_name(nic->name, i);
5473 hw->name = nic->name;
5475 ret = e1000_init_one(hw, i, devno, nic->enetaddr);
5478 list_add_tail(&hw->list_node, &e1000_hw_list);
5482 /* Set up the function pointers and register the device */
5483 nic->init = e1000_init;
5484 nic->recv = e1000_poll;
5485 nic->send = e1000_transmit;
5486 nic->halt = e1000_disable;
5493 struct e1000_hw *e1000_find_card(unsigned int cardnum)
5495 struct e1000_hw *hw;
5497 list_for_each_entry(hw, &e1000_hw_list, list_node)
5498 if (hw->cardnum == cardnum)
5503 #endif /* !CONFIG_DM_ETH */
5505 #ifdef CONFIG_CMD_E1000
5506 static int do_e1000(cmd_tbl_t *cmdtp, int flag,
5507 int argc, char * const argv[])
5509 unsigned char *mac = NULL;
5510 #ifdef CONFIG_DM_ETH
5511 struct eth_pdata *plat;
5512 struct udevice *dev;
5516 #if !defined(CONFIG_DM_ETH) || defined(CONFIG_E1000_SPI)
5517 struct e1000_hw *hw;
5526 /* Make sure we can find the requested e1000 card */
5527 cardnum = simple_strtoul(argv[1], NULL, 10);
5528 #ifdef CONFIG_DM_ETH
5529 e1000_name(name, cardnum);
5530 ret = uclass_get_device_by_name(UCLASS_ETH, name, &dev);
5532 plat = dev_get_platdata(dev);
5533 mac = plat->enetaddr;
5536 hw = e1000_find_card(cardnum);
5538 mac = hw->nic->enetaddr;
5541 printf("e1000: ERROR: No such device: e1000#%s\n", argv[1]);
5545 if (!strcmp(argv[2], "print-mac-address")) {
5546 printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
5547 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
5551 #ifdef CONFIG_E1000_SPI
5552 #ifdef CONFIG_DM_ETH
5553 hw = dev_get_priv(dev);
5555 /* Handle the "SPI" subcommand */
5556 if (!strcmp(argv[2], "spi"))
5557 return do_e1000_spi(cmdtp, hw, argc - 3, argv + 3);
5565 e1000, 7, 0, do_e1000,
5566 "Intel e1000 controller management",
5567 /* */"<card#> print-mac-address\n"
5568 #ifdef CONFIG_E1000_SPI
5569 "e1000 <card#> spi show [<offset> [<length>]]\n"
5570 "e1000 <card#> spi dump <addr> <offset> <length>\n"
5571 "e1000 <card#> spi program <addr> <offset> <length>\n"
5572 "e1000 <card#> spi checksum [update]\n"
5574 " - Manage the Intel E1000 PCI device"
5576 #endif /* not CONFIG_CMD_E1000 */
5578 #ifdef CONFIG_DM_ETH
5579 static int e1000_eth_start(struct udevice *dev)
5581 struct eth_pdata *plat = dev_get_platdata(dev);
5582 struct e1000_hw *hw = dev_get_priv(dev);
5584 return _e1000_init(hw, plat->enetaddr);
5587 static void e1000_eth_stop(struct udevice *dev)
5589 struct e1000_hw *hw = dev_get_priv(dev);
5594 static int e1000_eth_send(struct udevice *dev, void *packet, int length)
5596 struct e1000_hw *hw = dev_get_priv(dev);
5599 ret = _e1000_transmit(hw, packet, length);
5601 return ret ? 0 : -ETIMEDOUT;
5604 static int e1000_eth_recv(struct udevice *dev, int flags, uchar **packetp)
5606 struct e1000_hw *hw = dev_get_priv(dev);
5609 len = _e1000_poll(hw);
5613 return len ? len : -EAGAIN;
5616 static int e1000_free_pkt(struct udevice *dev, uchar *packet, int length)
5618 struct e1000_hw *hw = dev_get_priv(dev);
5625 static int e1000_eth_probe(struct udevice *dev)
5627 struct eth_pdata *plat = dev_get_platdata(dev);
5628 struct e1000_hw *hw = dev_get_priv(dev);
5631 hw->name = dev->name;
5632 ret = e1000_init_one(hw, trailing_strtol(dev->name),
5633 dev, plat->enetaddr);
5635 printf(pr_fmt("failed to initialize card: %d\n"), ret);
5642 static int e1000_eth_bind(struct udevice *dev)
5647 * A simple way to number the devices. When device tree is used this
5648 * is unnecessary, but when the device is just discovered on the PCI
5649 * bus we need a name. We could instead have the uclass figure out
5650 * which devices are different and number them.
5652 e1000_name(name, num_cards++);
5654 return device_set_name(dev, name);
5657 static const struct eth_ops e1000_eth_ops = {
5658 .start = e1000_eth_start,
5659 .send = e1000_eth_send,
5660 .recv = e1000_eth_recv,
5661 .stop = e1000_eth_stop,
5662 .free_pkt = e1000_free_pkt,
5665 static const struct udevice_id e1000_eth_ids[] = {
5666 { .compatible = "intel,e1000" },
5670 U_BOOT_DRIVER(eth_e1000) = {
5671 .name = "eth_e1000",
5673 .of_match = e1000_eth_ids,
5674 .bind = e1000_eth_bind,
5675 .probe = e1000_eth_probe,
5676 .ops = &e1000_eth_ops,
5677 .priv_auto_alloc_size = sizeof(struct e1000_hw),
5678 .platdata_auto_alloc_size = sizeof(struct eth_pdata),
5681 U_BOOT_PCI_DEVICE(eth_e1000, e1000_supported);